* refs/heads/tmp-26c8156: Linux 4.4.49 drm/i915: fix use-after-free in page_flip_completed() ALSA: seq: Don't handle loop timeout at snd_seq_pool_done() ALSA: seq: Fix race at creating a queue xen-netfront: Delete rx_refill_timer in xennet_disconnect_backend() scsi: mpt3sas: disable ASPM for MPI2 controllers scsi: aacraid: Fix INTx/MSI-x issue with older controllers scsi: zfcp: fix use-after-free by not tracing WKA port open/close on failed send netvsc: Set maximum GSO size in the right place mac80211: Fix adding of mesh vendor IEs ARM: 8642/1: LPAE: catch pending imprecise abort on unmask target: Fix COMPARE_AND_WRITE ref leak for non GOOD status target: Fix early transport_generic_handle_tmr abort scenario target: Use correct SCSI status during EXTENDED_COPY exception target: Don't BUG_ON during NodeACL dynamic -> explicit conversion ARM: 8643/3: arm/ptrace: Preserve previous registers for short regset write hns: avoid stack overflow with CONFIG_KASAN cpumask: use nr_cpumask_bits for parsing functions Revert "x86/ioapic: Restore IO-APIC irq_chip retrigger callback" selinux: fix off-by-one in setprocattr ARC: [arcompact] brown paper bag bug in unaligned access delay slot fixup Linux 4.4.48 base/memory, hotplug: fix a kernel oops in show_valid_zones() x86/irq: Make irq activate operations symmetric USB: serial: option: add device ID for HP lt2523 (Novatel E371) usb: gadget: f_fs: Assorted buffer overflow checks. USB: Add quirk for WORLDE easykey.25 MIDI keyboard USB: serial: pl2303: add ATEN device ID USB: serial: qcserial: add Dell DW5570 QDL KVM: x86: do not save guest-unsupported XSAVE state HID: wacom: Fix poor prox handling in 'wacom_pl_irq' percpu-refcount: fix reference leak during percpu-atomic transition mmc: sdhci: Ignore unexpected CARD_INT interrupts can: bcm: fix hrtimer/tasklet termination in bcm op removal mm, fs: check for fatal signals in do_generic_file_read() mm/memory_hotplug.c: check start_pfn in test_pages_in_a_zone() cifs: initialize file_info_lock zswap: disable changing params if init fails svcrpc: fix oops in absence of krb5 module NFSD: Fix a null reference case in find_or_create_lock_stateid() powerpc: Add missing error check to prom_find_boot_cpu() powerpc/eeh: Fix wrong flag passed to eeh_unfreeze_pe() libata: apply MAX_SEC_1024 to all CX1-JB*-HP devices ata: sata_mv:- Handle return value of devm_ioremap. perf/core: Fix PERF_RECORD_MMAP2 prot/flags for anonymous memory crypto: arm64/aes-blk - honour iv_out requirement in CBC and CTR modes crypto: api - Clear CRYPTO_ALG_DEAD bit before registering an alg drm/nouveau/nv1a,nv1f/disp: fix memory clock rate retrieval drm/nouveau/disp/gt215: Fix HDA ELD handling (thus, HDMI audio) on gt215 ext4: validate s_first_meta_bg at mount time PCI/ASPM: Handle PCI-to-PCIe bridges as roots of PCIe hierarchies ANDROID: security: export security_path_chown() Linux 4.4.47 net: dsa: Bring back device detaching in dsa_slave_suspend() qmi_wwan/cdc_ether: add device ID for HP lt2523 (Novatel E371) WWAN card af_unix: move unix_mknod() out of bindlock r8152: don't execute runtime suspend if the tx is not empty bridge: netlink: call br_changelink() during br_dev_newlink() tcp: initialize max window for a new fastopen socket ipv6: addrconf: Avoid addrconf_disable_change() using RCU read-side lock net: phy: bcm63xx: Utilize correct config_intr function net: fix harmonize_features() vs NETIF_F_HIGHDMA ax25: Fix segfault after sock connection timeout ravb: do not use zero-length alignment DMA descriptor openvswitch: maintain correct checksum state in conntrack actions tcp: fix tcp_fastopen unaligned access complaints on sparc net: systemport: Decouple flow control from __bcm_sysport_tx_reclaim net: ipv4: fix table id in getroute response net: lwtunnel: Handle lwtunnel_fill_encap failure mlxsw: pci: Fix EQE structure definition mlxsw: switchx2: Fix memory leak at skb reallocation mlxsw: spectrum: Fix memory leak at skb reallocation r8152: fix the sw rx checksum is unavailable ANDROID: sdcardfs: Switch strcasecmp for internal call ANDROID: sdcardfs: switch to full_name_hash and qstr ANDROID: sdcardfs: Add GID Derivation to sdcardfs ANDROID: sdcardfs: Remove redundant operation ANDROID: sdcardfs: add support for user permission isolation ANDROID: sdcardfs: Refactor configfs interface ANDROID: sdcardfs: Allow non-owners to touch ANDROID: binder: fix format specifier for type binder_size_t ANDROID: fs: Export vfs_rmdir2 ANDROID: fs: Export free_fs_struct and set_fs_pwd ANDROID: mnt: remount should propagate to slaves of slaves ANDROID: sdcardfs: Switch ->d_inode to d_inode() ANDROID: sdcardfs: Fix locking issue with permision fix up ANDROID: sdcardfs: Change magic value ANDROID: sdcardfs: Use per mount permissions ANDROID: sdcardfs: Add gid and mask to private mount data ANDROID: sdcardfs: User new permission2 functions ANDROID: vfs: Add setattr2 for filesystems with per mount permissions ANDROID: vfs: Add permission2 for filesystems with per mount permissions ANDROID: vfs: Allow filesystems to access their private mount data ANDROID: mnt: Add filesystem private data to mount points ANDROID: sdcardfs: Move directory unlock before touch ANDROID: sdcardfs: fix external storage exporting incorrect uid ANDROID: sdcardfs: Added top to sdcardfs_inode_info ANDROID: sdcardfs: Switch package list to RCU ANDROID: sdcardfs: Fix locking for permission fix up ANDROID: sdcardfs: Check for other cases on path lookup ANDROID: sdcardfs: override umask on mkdir and create Linux 4.4.46 mm, memcg: do not retry precharge charges platform/x86: intel_mid_powerbtn: Set IRQ_ONESHOT pinctrl: broxton: Use correct PADCFGLOCK offset s5k4ecgx: select CRC32 helper IB/umem: Release pid in error and ODP flow IB/ipoib: move back IB LL address into the hard header drm/i915: Don't leak edid in intel_crt_detect_ddc() SUNRPC: cleanup ida information when removing sunrpc module NFSv4.0: always send mode in SETATTR after EXCLUSIVE4 nfs: Don't increment lock sequence ID after NFS4ERR_MOVED parisc: Don't use BITS_PER_LONG in userspace-exported swab.h header ARC: [arcompact] handle unaligned access delay slot corner case ARC: udelay: fix inline assembler by adding LP_COUNT to clobber list can: ti_hecc: add missing prepare and unprepare of the clock can: c_can_pci: fix null-pointer-deref in c_can_start() - set device pointer s390/ptrace: Preserve previous registers for short regset write RDMA/cma: Fix unknown symbol when CONFIG_IPV6 is not enabled ISDN: eicon: silence misleading array-bounds warning sysctl: fix proc_doulongvec_ms_jiffies_minmax() mm/mempolicy.c: do not put mempolicy before using its nodemask drm: Fix broken VT switch with video=1366x768 option tile/ptrace: Preserve previous registers for short regset write fbdev: color map copying bounds checking Linux 4.4.45 arm64: avoid returning from bad_mode selftest/powerpc: Wrong PMC initialized in pmc56_overflow test dmaengine: pl330: Fix runtime PM support for terminated transfers ite-cir: initialize use_demodulator before using it blackfin: check devm_pinctrl_get() for errors ARM: 8613/1: Fix the uaccess crash on PB11MPCore ARM: ux500: fix prcmu_is_cpu_in_wfi() calculation ARM: dts: imx6qdl-nitrogen6_max: fix sgtl5000 pinctrl init arm64/ptrace: Reject attempts to set incomplete hardware breakpoint fields arm64/ptrace: Avoid uninitialised struct padding in fpr_set() arm64/ptrace: Preserve previous registers for short regset write - 3 arm64/ptrace: Preserve previous registers for short regset write - 2 arm64/ptrace: Preserve previous registers for short regset write ARM: dts: da850-evm: fix read access to SPI flash ceph: fix bad endianness handling in parse_reply_info_extra ARM: 8634/1: hw_breakpoint: blacklist Scorpion CPUs svcrdma: avoid duplicate dma unmapping during error recovery clocksource/exynos_mct: Clear interrupt when cpu is shut down ubifs: Fix journal replay wrt. xattr nodes qla2xxx: Fix crash due to null pointer access x86/ioapic: Restore IO-APIC irq_chip retrigger callback mtd: nand: xway: disable module support ieee802154: atusb: do not use the stack for buffers to make them DMA able mmc: mxs-mmc: Fix additional cycles after transmission stop HID: corsair: fix control-transfer error handling HID: corsair: fix DMA buffers on stack PCI: Enumerate switches below PCI-to-PCIe bridges fuse: clear FR_PENDING flag when moving requests out of pending queue svcrpc: don't leak contexts on PROC_DESTROY x86/PCI: Ignore _CRS on Supermicro X8DTH-i/6/iF/6F tmpfs: clear S_ISGID when setting posix ACLs ARM: dts: imx31: fix AVIC base address ARM: dts: imx31: move CCM device node to AIPS2 bus devices ARM: dts: imx31: fix clock control module interrupts description perf scripting: Avoid leaking the scripting_context variable IB/IPoIB: Remove can't use GFP_NOIO warning IB/mlx4: When no DMFS for IPoIB, don't allow NET_IF QPs IB/mlx4: Fix port query for 56Gb Ethernet links IB/mlx4: Fix out-of-range array index in destroy qp flow IB/mlx4: Set traffic class in AH IB/mlx5: Wait for all async command completions to complete ftrace/x86: Set ftrace_stub to weak to prevent gcc from using short jumps to it Linux 4.4.44 pinctrl: sh-pfc: Do not unconditionally support PIN_CONFIG_BIAS_DISABLE powerpc/ibmebus: Fix device reference leaks in sysfs interface powerpc/ibmebus: Fix further device reference leaks bus: vexpress-config: fix device reference leak blk-mq: Always schedule hctx->next_cpu ACPI / APEI: Fix NMI notification handling block: cfq_cpd_alloc() should use @gfp cpufreq: powernv: Disable preemption while checking CPU throttling state NFSv4.1: nfs4_fl_prepare_ds must be careful about reporting success. NFS: Fix a performance regression in readdir pNFS: Fix race in pnfs_wait_on_layoutreturn pinctrl: meson: fix gpio request disabling other modes btrfs: fix error handling when run_delayed_extent_op fails btrfs: fix locking when we put back a delayed ref that's too new x86/cpu: Fix bootup crashes by sanitizing the argument of the 'clearcpuid=' command-line option USB: serial: ch341: fix modem-control and B0 handling USB: serial: ch341: fix resume after reset drm/radeon: drop verde dpm quirks sysctl: Drop reference added by grab_header in proc_sys_readdir sysrq: attach sysrq handler correctly for 32-bit kernel tty/serial: atmel_serial: BUG: stop DMA from transmitting in stop_tx mnt: Protect the mountpoint hashtable with mount_lock vme: Fix wrong pointer utilization in ca91cx42_slave_get xhci: fix deadlock at host remove by running watchdog correctly i2c: fix kernel memory disclosure in dev interface i2c: print correct device invalid address Input: elants_i2c - avoid divide by 0 errors on bad touchscreen data USB: serial: ch341: fix open and resume after B0 USB: serial: ch341: fix control-message error handling USB: serial: ch341: fix open error handling USB: serial: ch341: fix initial modem-control state USB: serial: kl5kusb105: fix line-state error handling nl80211: fix sched scan netlink socket owner destruction KVM: x86: Introduce segmented_write_std KVM: x86: emulate FXSAVE and FXRSTOR KVM: x86: add asm_safe wrapper KVM: x86: add Align16 instruction flag KVM: x86: flush pending lapic jump label updates on module unload jump_labels: API for flushing deferred jump label updates KVM: eventfd: fix NULL deref irqbypass consumer KVM: x86: fix emulation of "MOV SS, null selector" mm/hugetlb.c: fix reservation race when freeing surplus pages ocfs2: fix crash caused by stale lvb with fsdlm plugin mm: fix devm_memremap_pages crash, use mem_hotplug_{begin, done} selftests: do not require bash for the generated test selftests: do not require bash to run netsocktests testcase Input: i8042 - add Pegatron touchpad to noloop table Input: xpad - use correct product id for x360w controllers DEBUG: sched/fair: Fix sched_load_avg_cpu events for task_groups DEBUG: sched/fair: Fix missing sched_load_avg_cpu events net: socket: don't set sk_uid to garbage value in ->setattr() ANDROID: configs: CONFIG_ARM64_SW_TTBR0_PAN=y UPSTREAM: arm64: Disable PAN on uaccess_enable() UPSTREAM: arm64: Enable CONFIG_ARM64_SW_TTBR0_PAN UPSTREAM: arm64: xen: Enable user access before a privcmd hvc call UPSTREAM: arm64: Handle faults caused by inadvertent user access with PAN enabled BACKPORT: arm64: Disable TTBR0_EL1 during normal kernel execution BACKPORT: arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1 BACKPORT: arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro BACKPORT: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros UPSTREAM: arm64: alternative: add auto-nop infrastructure UPSTREAM: arm64: barriers: introduce nops and __nops macros for NOP sequences Revert "FROMLIST: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros" Revert "FROMLIST: arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro" Revert "FROMLIST: arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1" Revert "FROMLIST: arm64: Disable TTBR0_EL1 during normal kernel execution" Revert "FROMLIST: arm64: Handle faults caused by inadvertent user access with PAN enabled" Revert "FROMLIST: arm64: xen: Enable user access before a privcmd hvc call" Revert "FROMLIST: arm64: Enable CONFIG_ARM64_SW_TTBR0_PAN" ANDROID: sched/walt: fix build failure if FAIR_GROUP_SCHED=n Linux 4.4.43 mm/init: fix zone boundary creation ALSA: usb-audio: Add a quirk for Plantronics BT600 spi: mvebu: fix baudrate calculation for armada variant ARM: OMAP4+: Fix bad fallthrough for cpuidle ARM: zynq: Reserve correct amount of non-DMA RAM powerpc: Fix build warning on 32-bit PPC ALSA: firewire-tascam: Fix to handle error from initialization of stream data HID: hid-cypress: validate length of report net: vrf: do not allow table id 0 net: ipv4: Fix multipath selection with vrf gro: Disable frag0 optimization on IPv6 ext headers gro: use min_t() in skb_gro_reset_offset() gro: Enter slow-path if there is no tailroom r8152: fix rx issue for runtime suspend r8152: split rtl8152_suspend function ipv4: Do not allow MAIN to be alias for new LOCAL w/ custom rules igmp: Make igmp group member RFC 3376 compliant drop_monitor: consider inserted data in genlmsg_end drop_monitor: add missing call to genlmsg_end net/mlx5: Avoid shadowing numa_node net/mlx5: Check FW limitations on log_max_qp before setting it net: stmmac: Fix race between stmmac_drv_probe and stmmac_open net, sched: fix soft lockup in tc_classify ipv6: handle -EFAULT from skb_copy_bits net: vrf: Drop conntrack data after pass through VRF device on Tx ser_gigaset: return -ENOMEM on error instead of success netvsc: reduce maximum GSO size Linux 4.4.42 usb: gadget: composite: always set ep->mult to a sensible value Revert "usb: gadget: composite: always set ep->mult to a sensible value" tick/broadcast: Prevent NULL pointer dereference drm/radeon: Always store CRTC relative radeon_crtc->cursor_x/y values cx23885-dvb: move initialization of a8293_pdata net: vxge: avoid unused function warnings net: ti: cpmac: Fix compiler warning due to type confusion cred/userns: define current_user_ns() as a function staging: comedi: dt282x: tidy up register bit defines powerpc/pci/rpadlpar: Fix device reference leaks md: MD_RECOVERY_NEEDED is set for mddev->recovery crypto: arm64/aes-ce - fix for big endian crypto: arm64/aes-xts-ce: fix for big endian crypto: arm64/sha1-ce - fix for big endian crypto: arm64/aes-neon - fix for big endian crypto: arm64/aes-ccm-ce: fix for big endian crypto: arm/aes-ce - fix for big endian crypto: arm64/ghash-ce - fix for big endian crypto: arm64/sha2-ce - fix for big endian s390/crypto: unlock on error in prng_tdes_read() mmc: mmc_test: Uninitialized return value PM / wakeirq: Fix dedicated wakeirq for drivers not using autosuspend irqchip/bcm7038-l1: Implement irq_cpu_offline() callback target/iscsi: Fix double free in lio_target_tiqn_addtpg() scsi: mvsas: fix command_active typo ASoC: samsung: i2s: Fixup last IRQ unsafe spin lock call iommu/vt-d: Flush old iommu caches for kdump when the device gets context mapped iommu/vt-d: Fix pasid table size encoding iommu/amd: Fix the left value check of cmd buffer iommu/amd: Missing error code in amd_iommu_init_device() clk: imx31: fix rewritten input argument of mx31_clocks_init() clk: clk-wm831x: fix a logic error hwmon: (g762) Fix overflows and crash seen when writing limit attributes hwmon: (nct7802) Fix overflows seen when writing into limit attributes hwmon: (ds620) Fix overflows seen when writing temperature limits hwmon: (amc6821) sign extension temperature hwmon: (scpi) Fix module autoload cris: Only build flash rescue image if CONFIG_ETRAX_AXISFLASHMAP is selected ath10k: use the right length of "background" stable-fixup: hotplug: fix unused function warning usb: dwc3: ep0: explicitly call dwc3_ep0_prepare_one_trb() usb: dwc3: ep0: add dwc3_ep0_prepare_one_trb() usb: dwc3: gadget: always unmap EP0 requests staging: iio: ad7606: fix improper setting of oversampling pins mei: bus: fix mei_cldev_enable KDoc USB: serial: io_ti: bind to interface after fw download USB: phy: am335x-control: fix device and of_node leaks ARM: dts: r8a7794: Correct hsusb parent clock USB: serial: kl5kusb105: abort on open exception path ALSA: usb-audio: Fix bogus error return in snd_usb_create_stream() usb: musb: blackfin: add bfin_fifo_offset in bfin_ops usb: hub: Move hub_port_disable() to fix warning if PM is disabled usb: musb: Fix trying to free already-free IRQ 4 usb: dwc3: pci: add Intel Gemini Lake PCI ID xhci: Fix race related to abort operation xhci: Use delayed_work instead of timer for command timeout usb: xhci-mem: use passed in GFP flags instead of GFP_KERNEL USB: serial: mos7720: fix parallel probe USB: serial: mos7720: fix parport use-after-free on probe errors USB: serial: mos7720: fix use-after-free on probe errors USB: serial: mos7720: fix NULL-deref at open USB: serial: mos7840: fix NULL-deref at open USB: serial: kobil_sct: fix NULL-deref in write USB: serial: cyberjack: fix NULL-deref at open USB: serial: oti6858: fix NULL-deref at open USB: serial: io_edgeport: fix NULL-deref at open USB: serial: ti_usb_3410_5052: fix NULL-deref at open USB: serial: garmin_gps: fix memory leak on failed URB submit USB: serial: iuu_phoenix: fix NULL-deref at open USB: serial: io_ti: fix I/O after disconnect USB: serial: io_ti: fix another NULL-deref at open USB: serial: io_ti: fix NULL-deref at open USB: serial: spcp8x5: fix NULL-deref at open USB: serial: keyspan_pda: verify endpoints at probe USB: serial: pl2303: fix NULL-deref at open USB: serial: quatech2: fix sleep-while-atomic in close USB: serial: omninet: fix NULL-derefs at open and disconnect usb: xhci: hold lock over xhci_abort_cmd_ring() xhci: Handle command completion and timeout race usb: host: xhci: Fix possible wild pointer when handling abort command usb: xhci: fix return value of xhci_setup_device() xhci: free xhci virtual devices with leaf nodes first usb: xhci: apply XHCI_PME_STUCK_QUIRK to Intel Apollo Lake xhci: workaround for hosts missing CAS bit usb: xhci: fix possible wild pointer usb: dwc3: core: avoid Overflow events usb: gadget: composite: Test get_alt() presence instead of set_alt() USB: dummy-hcd: fix bug in stop_activity (handle ep0) USB: fix problems with duplicate endpoint addresses USB: gadgetfs: fix checks of wTotalLength in config descriptors USB: gadgetfs: fix use-after-free bug USB: gadgetfs: fix unbounded memory allocation bug usb: gadgetfs: restrict upper bound on device configuration size usb: storage: unusual_uas: Add JMicron JMS56x to unusual device usb: musb: dsps: implement clear_ep_rxintr() callback usb: musb: core: add clear_ep_rxintr() to musb_platform_ops KVM: MIPS: Flush KVM entry code from icache globally KVM: x86: reset MMU on KVM_SET_VCPU_EVENTS mac80211: initialize fast-xmit 'info' later ARM: davinci: da850: don't add emac clock to lookup table twice ALSA: usb-audio: Fix irq/process data synchronization ALSA: hda - Apply asus-mode8 fixup to ASUS X71SL ALSA: hda - Fix up GPIO for ASUS ROG Ranger Linux 4.4.41 net: mvpp2: fix dma unmapping of TX buffers for fragments sg_write()/bsg_write() is not fit to be called under KERNEL_DS kconfig/nconf: Fix hang when editing symbol with a long prompt target/user: Fix use-after-free of tcmu_cmds if they are expired powerpc: Convert cmp to cmpd in idle enter sequence powerpc/ps3: Fix system hang with GCC 5 builds nfs_write_end(): fix handling of short copies libceph: verify authorize reply on connect PCI: Check for PME in targeted sleep state Input: drv260x - fix input device's parent assignment media: solo6x10: fix lockup by avoiding delayed register write IB/cma: Fix a race condition in iboe_addr_get_sgid() IB/multicast: Check ib_find_pkey() return value IPoIB: Avoid reading an uninitialized member variable IB/mad: Fix an array index check fgraph: Handle a case where a tracer ignores set_graph_notrace platform/x86: asus-nb-wmi.c: Add X45U quirk ftrace/x86_32: Set ftrace_stub to weak to prevent gcc from using short jumps to it kvm: nVMX: Allow L1 to intercept software exceptions (#BP and #OF) KVM: PPC: Book3S HV: Don't lose hardware R/C bit updates in H_PROTECT KVM: PPC: Book3S HV: Save/restore XER in checkpointed register state md/raid5: limit request size according to implementation limits sc16is7xx: Drop bogus use of IRQF_ONESHOT s390/vmlogrdr: fix IUCV buffer allocation firmware: fix usermode helper fallback loading ARC: mm: arc700: Don't assume 2 colours for aliasing VIPT dcache scsi: avoid a permanent stop of the scsi device's request queue scsi: zfcp: fix rport unblock race with LUN recovery scsi: zfcp: do not trace pure benign residual HBA responses at default level scsi: zfcp: fix use-after-"free" in FC ingress path after TMF scsi: megaraid_sas: Do not set MPI2_TYPE_CUDA for JBOD FP path for FW which does not support JBOD sequence map scsi: megaraid_sas: For SRIOV enabled firmware, ensure VF driver waits for 30secs before reset vt: fix Scroll Lock LED trigger name block: protect iterate_bdevs() against concurrent close mei: request async autosuspend at the end of enumeration drivers/gpu/drm/ast: Fix infinite loop if read fails drm/gma500: Add compat ioctl drm/radeon: add additional pci revision to dpm workaround drm/radeon: Hide the HW cursor while it's out of bounds drm/radeon: Also call cursor_move_locked when the cursor size changes drm/nouveau/i2c/gk110b,gm10x: use the correct implementation drm/nouveau/fifo/gf100-: protect channel preempt with subdev mutex drm/nouveau/ltc: protect clearing of comptags with mutex drm/nouveau/bios: require checksum to match for fast acpi shadow method drm/nouveau/kms: lvds panel strap moved again on maxwell ACPI / video: Add force_native quirk for HP Pavilion dv6 ACPI / video: Add force_native quirk for Dell XPS 17 L702X staging: comedi: ni_mio_common: fix E series ni_ai_insn_read() data staging: comedi: ni_mio_common: fix M Series ni_ai_insn_read() data mask thermal: hwmon: Properly report critical temperature in sysfs clk: bcm2835: Avoid overwriting the div info when disabling a pll_div clk timekeeping_Force_unsigned_clocksource_to_nanoseconds_conversion regulator: stw481x-vmmc: fix ages old enable error mmc: sdhci: Fix recovery from tuning timeout ath9k: Really fix LED polarity for some Mini PCI AR9220 MB92 cards. cfg80211/mac80211: fix BSS leaks when abandoning assoc attempts rtlwifi: Fix enter/exit power_save ssb: Fix error routine when fallback SPROM fails Linux 4.4.40 ppp: defer netns reference release for ppp channel driver core: fix race between creating/querying glue dir and its cleanup xfs: set AGI buffer type in xlog_recover_clear_agi_bucket arm/xen: Use alloc_percpu rather than __alloc_percpu xen/gntdev: Use VM_MIXEDMAP instead of VM_IO to avoid NUMA balancing tpm xen: Remove bogus tpm_chip_unregister kernel/debug/debug_core.c: more properly delay for secondary CPUs kernel/watchdog: use nmi registers snapshot in hardlockup handler CIFS: Fix a possible memory corruption in push locks CIFS: Fix missing nls unload in smb2_reconnect() CIFS: Fix a possible memory corruption during reconnect ASoC: intel: Fix crash at suspend/resume without card registration dm space map metadata: fix 'struct sm_metadata' leak on failed create dm crypt: mark key as invalid until properly loaded dm flakey: return -EINVAL on interval bounds error in flakey_ctr() blk-mq: Do not invoke .queue_rq() for a stopped queue usb: gadget: composite: always set ep->mult to a sensible value exec: Ensure mm->user_ns contains the execed files fs: exec: apply CLOEXEC before changing dumpable task flags mm/vmscan.c: set correct defer count for shrinker loop: return proper error from loop_queue_rq() f2fs: set ->owner for debugfs status file's file_operations ext4: do not perform data journaling when data is encrypted ext4: return -ENOMEM instead of success ext4: reject inodes with negative size ext4: add sanity checking to count_overhead() ext4: fix in-superblock mount options processing ext4: use more strict checks for inodes_per_block on mount ext4: fix stack memory corruption with 64k block size ext4: fix mballoc breakage with 64k block size crypto: caam - fix AEAD givenc descriptors ptrace: Capture the ptracer's creds not PT_PTRACE_CAP mm: Add a user_ns owner to mm_struct and fix ptrace permission checks block_dev: don't test bdev->bd_contains when it is not stable btrfs: make file clone aware of fatal signals Btrfs: don't BUG() during drop snapshot Btrfs: fix memory leak in do_walk_down Btrfs: don't leak reloc root nodes on error Btrfs: return gracefully from balance if fs tree is corrupted Btrfs: bail out if block group has different mixed flag Btrfs: fix memory leak in reading btree blocks clk: ti: omap36xx: Work around sprz319 advisory 2.1 ALSA: hda: when comparing pin configurations, ignore assoc in addition to seq ALSA: hda - Gate the mic jack on HP Z1 Gen3 AiO ALSA: hda - fix headset-mic problem on a Dell laptop ALSA: hda - ignore the assoc and seq when comparing pin configurations ALSA: hda/ca0132 - Add quirk for Alienware 15 R2 2016 ALSA: hiface: Fix M2Tech hiFace driver sampling rate change ALSA: usb-audio: Add QuickCam Communicate Deluxe/S7500 to volume_control_quirks USB: UHCI: report non-PME wakeup signalling for Intel hardware usb: gadget: composite: correctly initialize ep->maxpacket usb: gadget: f_uac2: fix error handling at afunc_bind usb: hub: Fix auto-remount of safely removed or ejected USB-3 devices USB: cdc-acm: add device id for GW Instek AFG-125 USB: serial: kl5kusb105: fix open error path USB: serial: option: add dlink dwm-158 USB: serial: option: add support for Telit LE922A PIDs 0x1040, 0x1041 Btrfs: fix qgroup rescan worker initialization btrfs: store and load values of stripes_min/stripes_max in balance status item Btrfs: fix tree search logic when replaying directory entry deletes btrfs: limit async_work allocation and worker func duration ANDROID: trace: net: use %pK for kernel pointers ANDROID: android-base: Enable QUOTA related configs net: ipv4: Don't crash if passing a null sk to ip_rt_update_pmtu. net: inet: Support UID-based routing in IP protocols. Revert "net: ipv6: fix virtual tunneling build" net: core: add UID to flows, rules, and routes net: core: Add a UID field to struct sock. Revert "net: core: Support UID-based routing." Revert "net: core: Handle 'sk' being NULL in UID-based routing" Revert "ANDROID: net: fix 'const' warnings" Revert "ANDROID: net: fib: remove duplicate assignment" Revert "ANDROID: net: core: fix UID-based routing" UPSTREAM: efi/arm64: Don't apply MEMBLOCK_NOMAP to UEFI memory map mapping UPSTREAM: arm64: enable CONFIG_DEBUG_RODATA by default goldfish: enable CONFIG_INET_DIAG_DESTROY sched/walt: kill {min,max}_capacity sched: fix wrong truncation of walt_avg ANDROID: dm verity: add minimum prefetch size Linux 4.4.39 crypto: rsa - Add Makefile dependencies to fix parallel builds hotplug: Make register and unregister notifier API symmetric batman-adv: Check for alloc errors when preparing TT local data m68k: Fix ndelay() macro arm64: futex.h: Add missing PAN toggling can: peak: fix bad memory access and free sequence can: raw: raw_setsockopt: limit number of can_filter that can be set crypto: mcryptd - Check mcryptd algorithm compatibility perf/x86: Fix full width counter, counter overflow locking/rtmutex: Use READ_ONCE() in rt_mutex_owner() locking/rtmutex: Prevent dequeue vs. unlock race zram: restrict add/remove attributes to root only parisc: Fix TLB related boot crash on SMP machines parisc: Remove unnecessary TLB purges from flush_dcache_page_asm and flush_icache_page_asm parisc: Purge TLB before setting PTE powerpc/eeh: Fix deadlock when PE frozen state can't be cleared Conflicts: arch/arm64/kernel/traps.c drivers/usb/dwc3/core.h drivers/usb/dwc3/ep0.c drivers/usb/gadget/function/f_fs.c drivers/usb/host/xhci-mem.c drivers/usb/host/xhci-ring.c drivers/usb/host/xhci.c drivers/video/fbdev/core/fbcmap.c include/trace/events/sched.h mm/vmscan.c Change-Id: I3faa0010ecb98972cd8e6470377a493b56d95f89 Signed-off-by: Blagovest Kolenichev <bkolenichev@codeaurora.org> Signed-off-by: Runmin Wang <runminw@codeaurora.org>
2338 lines
53 KiB
C
2338 lines
53 KiB
C
/*
|
|
FUSE: Filesystem in Userspace
|
|
Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
|
|
|
|
This program can be distributed under the terms of the GNU GPL.
|
|
See the file COPYING.
|
|
*/
|
|
|
|
#include "fuse_i.h"
|
|
#include "fuse_passthrough.h"
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/poll.h>
|
|
#include <linux/uio.h>
|
|
#include <linux/miscdevice.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/file.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/pipe_fs_i.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/splice.h>
|
|
#include <linux/freezer.h>
|
|
|
|
MODULE_ALIAS_MISCDEV(FUSE_MINOR);
|
|
MODULE_ALIAS("devname:fuse");
|
|
|
|
static struct kmem_cache *fuse_req_cachep;
|
|
|
|
static struct fuse_dev *fuse_get_dev(struct file *file)
|
|
{
|
|
/*
|
|
* Lockless access is OK, because file->private data is set
|
|
* once during mount and is valid until the file is released.
|
|
*/
|
|
return ACCESS_ONCE(file->private_data);
|
|
}
|
|
|
|
static void fuse_request_init(struct fuse_req *req, struct page **pages,
|
|
struct fuse_page_desc *page_descs,
|
|
unsigned npages)
|
|
{
|
|
memset(req, 0, sizeof(*req));
|
|
memset(pages, 0, sizeof(*pages) * npages);
|
|
memset(page_descs, 0, sizeof(*page_descs) * npages);
|
|
INIT_LIST_HEAD(&req->list);
|
|
INIT_LIST_HEAD(&req->intr_entry);
|
|
init_waitqueue_head(&req->waitq);
|
|
atomic_set(&req->count, 1);
|
|
req->pages = pages;
|
|
req->page_descs = page_descs;
|
|
req->max_pages = npages;
|
|
__set_bit(FR_PENDING, &req->flags);
|
|
}
|
|
|
|
static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
|
|
{
|
|
struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, flags);
|
|
if (req) {
|
|
struct page **pages;
|
|
struct fuse_page_desc *page_descs;
|
|
|
|
if (npages <= FUSE_REQ_INLINE_PAGES) {
|
|
pages = req->inline_pages;
|
|
page_descs = req->inline_page_descs;
|
|
} else {
|
|
pages = kmalloc(sizeof(struct page *) * npages, flags);
|
|
page_descs = kmalloc(sizeof(struct fuse_page_desc) *
|
|
npages, flags);
|
|
}
|
|
|
|
if (!pages || !page_descs) {
|
|
kfree(pages);
|
|
kfree(page_descs);
|
|
kmem_cache_free(fuse_req_cachep, req);
|
|
return NULL;
|
|
}
|
|
|
|
fuse_request_init(req, pages, page_descs, npages);
|
|
}
|
|
return req;
|
|
}
|
|
|
|
struct fuse_req *fuse_request_alloc(unsigned npages)
|
|
{
|
|
return __fuse_request_alloc(npages, GFP_KERNEL);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_request_alloc);
|
|
|
|
struct fuse_req *fuse_request_alloc_nofs(unsigned npages)
|
|
{
|
|
return __fuse_request_alloc(npages, GFP_NOFS);
|
|
}
|
|
|
|
void fuse_request_free(struct fuse_req *req)
|
|
{
|
|
if (req->pages != req->inline_pages) {
|
|
kfree(req->pages);
|
|
kfree(req->page_descs);
|
|
}
|
|
kmem_cache_free(fuse_req_cachep, req);
|
|
}
|
|
|
|
static void block_sigs(sigset_t *oldset)
|
|
{
|
|
sigset_t mask;
|
|
|
|
siginitsetinv(&mask, sigmask(SIGKILL));
|
|
sigprocmask(SIG_BLOCK, &mask, oldset);
|
|
}
|
|
|
|
static void restore_sigs(sigset_t *oldset)
|
|
{
|
|
sigprocmask(SIG_SETMASK, oldset, NULL);
|
|
}
|
|
|
|
void __fuse_get_request(struct fuse_req *req)
|
|
{
|
|
atomic_inc(&req->count);
|
|
}
|
|
|
|
/* Must be called with > 1 refcount */
|
|
static void __fuse_put_request(struct fuse_req *req)
|
|
{
|
|
BUG_ON(atomic_read(&req->count) < 2);
|
|
atomic_dec(&req->count);
|
|
}
|
|
|
|
static void fuse_req_init_context(struct fuse_req *req)
|
|
{
|
|
req->in.h.uid = from_kuid_munged(&init_user_ns, current_fsuid());
|
|
req->in.h.gid = from_kgid_munged(&init_user_ns, current_fsgid());
|
|
req->in.h.pid = current->pid;
|
|
}
|
|
|
|
void fuse_set_initialized(struct fuse_conn *fc)
|
|
{
|
|
/* Make sure stores before this are seen on another CPU */
|
|
smp_wmb();
|
|
fc->initialized = 1;
|
|
}
|
|
|
|
static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
|
|
{
|
|
return !fc->initialized || (for_background && fc->blocked);
|
|
}
|
|
|
|
static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
|
|
bool for_background)
|
|
{
|
|
struct fuse_req *req;
|
|
int err;
|
|
atomic_inc(&fc->num_waiting);
|
|
|
|
if (fuse_block_alloc(fc, for_background)) {
|
|
sigset_t oldset;
|
|
int intr;
|
|
|
|
block_sigs(&oldset);
|
|
intr = wait_event_interruptible_exclusive(fc->blocked_waitq,
|
|
!fuse_block_alloc(fc, for_background));
|
|
restore_sigs(&oldset);
|
|
err = -EINTR;
|
|
if (intr)
|
|
goto out;
|
|
}
|
|
/* Matches smp_wmb() in fuse_set_initialized() */
|
|
smp_rmb();
|
|
|
|
err = -ENOTCONN;
|
|
if (!fc->connected)
|
|
goto out;
|
|
|
|
err = -ECONNREFUSED;
|
|
if (fc->conn_error)
|
|
goto out;
|
|
|
|
req = fuse_request_alloc(npages);
|
|
err = -ENOMEM;
|
|
if (!req) {
|
|
if (for_background)
|
|
wake_up(&fc->blocked_waitq);
|
|
goto out;
|
|
}
|
|
|
|
fuse_req_init_context(req);
|
|
__set_bit(FR_WAITING, &req->flags);
|
|
if (for_background)
|
|
__set_bit(FR_BACKGROUND, &req->flags);
|
|
|
|
return req;
|
|
|
|
out:
|
|
atomic_dec(&fc->num_waiting);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages)
|
|
{
|
|
return __fuse_get_req(fc, npages, false);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_get_req);
|
|
|
|
struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
|
|
unsigned npages)
|
|
{
|
|
return __fuse_get_req(fc, npages, true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_get_req_for_background);
|
|
|
|
/*
|
|
* Return request in fuse_file->reserved_req. However that may
|
|
* currently be in use. If that is the case, wait for it to become
|
|
* available.
|
|
*/
|
|
static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
|
|
struct file *file)
|
|
{
|
|
struct fuse_req *req = NULL;
|
|
struct fuse_file *ff = file->private_data;
|
|
|
|
do {
|
|
wait_event(fc->reserved_req_waitq, ff->reserved_req);
|
|
spin_lock(&fc->lock);
|
|
if (ff->reserved_req) {
|
|
req = ff->reserved_req;
|
|
ff->reserved_req = NULL;
|
|
req->stolen_file = get_file(file);
|
|
}
|
|
spin_unlock(&fc->lock);
|
|
} while (!req);
|
|
|
|
return req;
|
|
}
|
|
|
|
/*
|
|
* Put stolen request back into fuse_file->reserved_req
|
|
*/
|
|
static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
struct file *file = req->stolen_file;
|
|
struct fuse_file *ff = file->private_data;
|
|
|
|
spin_lock(&fc->lock);
|
|
fuse_request_init(req, req->pages, req->page_descs, req->max_pages);
|
|
BUG_ON(ff->reserved_req);
|
|
ff->reserved_req = req;
|
|
wake_up_all(&fc->reserved_req_waitq);
|
|
spin_unlock(&fc->lock);
|
|
fput(file);
|
|
}
|
|
|
|
/*
|
|
* Gets a requests for a file operation, always succeeds
|
|
*
|
|
* This is used for sending the FLUSH request, which must get to
|
|
* userspace, due to POSIX locks which may need to be unlocked.
|
|
*
|
|
* If allocation fails due to OOM, use the reserved request in
|
|
* fuse_file.
|
|
*
|
|
* This is very unlikely to deadlock accidentally, since the
|
|
* filesystem should not have it's own file open. If deadlock is
|
|
* intentional, it can still be broken by "aborting" the filesystem.
|
|
*/
|
|
struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
|
|
struct file *file)
|
|
{
|
|
struct fuse_req *req;
|
|
|
|
atomic_inc(&fc->num_waiting);
|
|
wait_event(fc->blocked_waitq, fc->initialized);
|
|
/* Matches smp_wmb() in fuse_set_initialized() */
|
|
smp_rmb();
|
|
req = fuse_request_alloc(0);
|
|
if (!req)
|
|
req = get_reserved_req(fc, file);
|
|
|
|
fuse_req_init_context(req);
|
|
__set_bit(FR_WAITING, &req->flags);
|
|
__clear_bit(FR_BACKGROUND, &req->flags);
|
|
return req;
|
|
}
|
|
|
|
void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
if (atomic_dec_and_test(&req->count)) {
|
|
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
|
/*
|
|
* We get here in the unlikely case that a background
|
|
* request was allocated but not sent
|
|
*/
|
|
spin_lock(&fc->lock);
|
|
if (!fc->blocked)
|
|
wake_up(&fc->blocked_waitq);
|
|
spin_unlock(&fc->lock);
|
|
}
|
|
|
|
if (test_bit(FR_WAITING, &req->flags)) {
|
|
__clear_bit(FR_WAITING, &req->flags);
|
|
atomic_dec(&fc->num_waiting);
|
|
}
|
|
|
|
if (req->stolen_file)
|
|
put_reserved_req(fc, req);
|
|
else
|
|
fuse_request_free(req);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_put_request);
|
|
|
|
static unsigned len_args(unsigned numargs, struct fuse_arg *args)
|
|
{
|
|
unsigned nbytes = 0;
|
|
unsigned i;
|
|
|
|
for (i = 0; i < numargs; i++)
|
|
nbytes += args[i].size;
|
|
|
|
return nbytes;
|
|
}
|
|
|
|
static u64 fuse_get_unique(struct fuse_iqueue *fiq)
|
|
{
|
|
return ++fiq->reqctr;
|
|
}
|
|
|
|
static void queue_request(struct fuse_iqueue *fiq, struct fuse_req *req)
|
|
{
|
|
req->in.h.len = sizeof(struct fuse_in_header) +
|
|
len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
|
|
list_add_tail(&req->list, &fiq->pending);
|
|
wake_up_locked(&fiq->waitq);
|
|
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
|
|
}
|
|
|
|
void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
|
|
u64 nodeid, u64 nlookup)
|
|
{
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
forget->forget_one.nodeid = nodeid;
|
|
forget->forget_one.nlookup = nlookup;
|
|
|
|
spin_lock(&fiq->waitq.lock);
|
|
if (fiq->connected) {
|
|
fiq->forget_list_tail->next = forget;
|
|
fiq->forget_list_tail = forget;
|
|
wake_up_locked(&fiq->waitq);
|
|
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
|
|
} else {
|
|
kfree(forget);
|
|
}
|
|
spin_unlock(&fiq->waitq.lock);
|
|
}
|
|
|
|
static void flush_bg_queue(struct fuse_conn *fc)
|
|
{
|
|
while (fc->active_background < fc->max_background &&
|
|
!list_empty(&fc->bg_queue)) {
|
|
struct fuse_req *req;
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
req = list_entry(fc->bg_queue.next, struct fuse_req, list);
|
|
list_del(&req->list);
|
|
fc->active_background++;
|
|
spin_lock(&fiq->waitq.lock);
|
|
req->in.h.unique = fuse_get_unique(fiq);
|
|
queue_request(fiq, req);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This function is called when a request is finished. Either a reply
|
|
* has arrived or it was aborted (and not yet sent) or some error
|
|
* occurred during communication with userspace, or the device file
|
|
* was closed. The requester thread is woken up (if still waiting),
|
|
* the 'end' callback is called if given, else the reference to the
|
|
* request is released
|
|
*/
|
|
static void request_end(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
if (test_and_set_bit(FR_FINISHED, &req->flags))
|
|
return;
|
|
|
|
spin_lock(&fiq->waitq.lock);
|
|
list_del_init(&req->intr_entry);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
WARN_ON(test_bit(FR_PENDING, &req->flags));
|
|
WARN_ON(test_bit(FR_SENT, &req->flags));
|
|
if (test_bit(FR_BACKGROUND, &req->flags)) {
|
|
spin_lock(&fc->lock);
|
|
clear_bit(FR_BACKGROUND, &req->flags);
|
|
if (fc->num_background == fc->max_background)
|
|
fc->blocked = 0;
|
|
|
|
/* Wake up next waiter, if any */
|
|
if (!fc->blocked && waitqueue_active(&fc->blocked_waitq))
|
|
wake_up(&fc->blocked_waitq);
|
|
|
|
if (fc->num_background == fc->congestion_threshold &&
|
|
fc->connected && fc->bdi_initialized) {
|
|
clear_bdi_congested(&fc->bdi, BLK_RW_SYNC);
|
|
clear_bdi_congested(&fc->bdi, BLK_RW_ASYNC);
|
|
}
|
|
fc->num_background--;
|
|
fc->active_background--;
|
|
flush_bg_queue(fc);
|
|
spin_unlock(&fc->lock);
|
|
}
|
|
wake_up(&req->waitq);
|
|
if (req->end)
|
|
req->end(fc, req);
|
|
fuse_put_request(fc, req);
|
|
}
|
|
|
|
static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
|
|
{
|
|
spin_lock(&fiq->waitq.lock);
|
|
if (test_bit(FR_FINISHED, &req->flags)) {
|
|
spin_unlock(&fiq->waitq.lock);
|
|
return;
|
|
}
|
|
if (list_empty(&req->intr_entry)) {
|
|
list_add_tail(&req->intr_entry, &fiq->interrupts);
|
|
wake_up_locked(&fiq->waitq);
|
|
}
|
|
spin_unlock(&fiq->waitq.lock);
|
|
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
|
|
}
|
|
|
|
static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
int err;
|
|
|
|
if (!fc->no_interrupt) {
|
|
/* Any signal may interrupt this */
|
|
err = wait_event_interruptible(req->waitq,
|
|
test_bit(FR_FINISHED, &req->flags));
|
|
if (!err)
|
|
return;
|
|
|
|
set_bit(FR_INTERRUPTED, &req->flags);
|
|
/* matches barrier in fuse_dev_do_read() */
|
|
smp_mb__after_atomic();
|
|
if (test_bit(FR_SENT, &req->flags))
|
|
queue_interrupt(fiq, req);
|
|
}
|
|
|
|
if (!test_bit(FR_FORCE, &req->flags)) {
|
|
sigset_t oldset;
|
|
|
|
/* Only fatal signals may interrupt this */
|
|
block_sigs(&oldset);
|
|
err = wait_event_interruptible(req->waitq,
|
|
test_bit(FR_FINISHED, &req->flags));
|
|
restore_sigs(&oldset);
|
|
|
|
if (!err)
|
|
return;
|
|
|
|
spin_lock(&fiq->waitq.lock);
|
|
/* Request is not yet in userspace, bail out */
|
|
if (test_bit(FR_PENDING, &req->flags)) {
|
|
list_del(&req->list);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
__fuse_put_request(req);
|
|
req->out.h.error = -EINTR;
|
|
return;
|
|
}
|
|
spin_unlock(&fiq->waitq.lock);
|
|
}
|
|
|
|
/*
|
|
* Either request is already in userspace, or it was forced.
|
|
* Wait it out.
|
|
*/
|
|
while (!test_bit(FR_FINISHED, &req->flags))
|
|
wait_event_freezable(req->waitq,
|
|
test_bit(FR_FINISHED, &req->flags));
|
|
}
|
|
|
|
static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
BUG_ON(test_bit(FR_BACKGROUND, &req->flags));
|
|
spin_lock(&fiq->waitq.lock);
|
|
if (!fiq->connected) {
|
|
spin_unlock(&fiq->waitq.lock);
|
|
req->out.h.error = -ENOTCONN;
|
|
} else {
|
|
req->in.h.unique = fuse_get_unique(fiq);
|
|
queue_request(fiq, req);
|
|
/* acquire extra reference, since request is still needed
|
|
after request_end() */
|
|
__fuse_get_request(req);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
|
|
request_wait_answer(fc, req);
|
|
/* Pairs with smp_wmb() in request_end() */
|
|
smp_rmb();
|
|
}
|
|
}
|
|
|
|
void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
__set_bit(FR_ISREPLY, &req->flags);
|
|
if (!test_bit(FR_WAITING, &req->flags)) {
|
|
__set_bit(FR_WAITING, &req->flags);
|
|
atomic_inc(&fc->num_waiting);
|
|
}
|
|
__fuse_request_send(fc, req);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_request_send);
|
|
|
|
static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)
|
|
{
|
|
if (fc->minor < 4 && args->in.h.opcode == FUSE_STATFS)
|
|
args->out.args[0].size = FUSE_COMPAT_STATFS_SIZE;
|
|
|
|
if (fc->minor < 9) {
|
|
switch (args->in.h.opcode) {
|
|
case FUSE_LOOKUP:
|
|
case FUSE_CREATE:
|
|
case FUSE_MKNOD:
|
|
case FUSE_MKDIR:
|
|
case FUSE_SYMLINK:
|
|
case FUSE_LINK:
|
|
args->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
|
|
break;
|
|
case FUSE_GETATTR:
|
|
case FUSE_SETATTR:
|
|
args->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
|
|
break;
|
|
}
|
|
}
|
|
if (fc->minor < 12) {
|
|
switch (args->in.h.opcode) {
|
|
case FUSE_CREATE:
|
|
args->in.args[0].size = sizeof(struct fuse_open_in);
|
|
break;
|
|
case FUSE_MKNOD:
|
|
args->in.args[0].size = FUSE_COMPAT_MKNOD_IN_SIZE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
|
|
{
|
|
struct fuse_req *req;
|
|
ssize_t ret;
|
|
|
|
req = fuse_get_req(fc, 0);
|
|
if (IS_ERR(req))
|
|
return PTR_ERR(req);
|
|
|
|
/* Needs to be done after fuse_get_req() so that fc->minor is valid */
|
|
fuse_adjust_compat(fc, args);
|
|
|
|
req->in.h.opcode = args->in.h.opcode;
|
|
req->in.h.nodeid = args->in.h.nodeid;
|
|
req->in.numargs = args->in.numargs;
|
|
memcpy(req->in.args, args->in.args,
|
|
args->in.numargs * sizeof(struct fuse_in_arg));
|
|
req->out.argvar = args->out.argvar;
|
|
req->out.numargs = args->out.numargs;
|
|
memcpy(req->out.args, args->out.args,
|
|
args->out.numargs * sizeof(struct fuse_arg));
|
|
fuse_request_send(fc, req);
|
|
ret = req->out.h.error;
|
|
if (!ret) {
|
|
if (args->out.argvar) {
|
|
BUG_ON(args->out.numargs != 1);
|
|
ret = req->out.args[0].size;
|
|
}
|
|
|
|
if (req->passthrough_filp != NULL)
|
|
args->out.passthrough_filp = req->passthrough_filp;
|
|
}
|
|
fuse_put_request(fc, req);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Called under fc->lock
|
|
*
|
|
* fc->connected must have been checked previously
|
|
*/
|
|
void fuse_request_send_background_locked(struct fuse_conn *fc,
|
|
struct fuse_req *req)
|
|
{
|
|
BUG_ON(!test_bit(FR_BACKGROUND, &req->flags));
|
|
if (!test_bit(FR_WAITING, &req->flags)) {
|
|
__set_bit(FR_WAITING, &req->flags);
|
|
atomic_inc(&fc->num_waiting);
|
|
}
|
|
__set_bit(FR_ISREPLY, &req->flags);
|
|
fc->num_background++;
|
|
if (fc->num_background == fc->max_background)
|
|
fc->blocked = 1;
|
|
if (fc->num_background == fc->congestion_threshold &&
|
|
fc->bdi_initialized) {
|
|
set_bdi_congested(&fc->bdi, BLK_RW_SYNC);
|
|
set_bdi_congested(&fc->bdi, BLK_RW_ASYNC);
|
|
}
|
|
list_add_tail(&req->list, &fc->bg_queue);
|
|
flush_bg_queue(fc);
|
|
}
|
|
|
|
void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
BUG_ON(!req->end);
|
|
spin_lock(&fc->lock);
|
|
if (fc->connected) {
|
|
fuse_request_send_background_locked(fc, req);
|
|
spin_unlock(&fc->lock);
|
|
} else {
|
|
spin_unlock(&fc->lock);
|
|
req->out.h.error = -ENOTCONN;
|
|
req->end(fc, req);
|
|
fuse_put_request(fc, req);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_request_send_background);
|
|
|
|
static int fuse_request_send_notify_reply(struct fuse_conn *fc,
|
|
struct fuse_req *req, u64 unique)
|
|
{
|
|
int err = -ENODEV;
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
__clear_bit(FR_ISREPLY, &req->flags);
|
|
req->in.h.unique = unique;
|
|
spin_lock(&fiq->waitq.lock);
|
|
if (fiq->connected) {
|
|
queue_request(fiq, req);
|
|
err = 0;
|
|
}
|
|
spin_unlock(&fiq->waitq.lock);
|
|
|
|
return err;
|
|
}
|
|
|
|
void fuse_force_forget(struct file *file, u64 nodeid)
|
|
{
|
|
struct inode *inode = file_inode(file);
|
|
struct fuse_conn *fc = get_fuse_conn(inode);
|
|
struct fuse_req *req;
|
|
struct fuse_forget_in inarg;
|
|
|
|
memset(&inarg, 0, sizeof(inarg));
|
|
inarg.nlookup = 1;
|
|
req = fuse_get_req_nofail_nopages(fc, file);
|
|
req->in.h.opcode = FUSE_FORGET;
|
|
req->in.h.nodeid = nodeid;
|
|
req->in.numargs = 1;
|
|
req->in.args[0].size = sizeof(inarg);
|
|
req->in.args[0].value = &inarg;
|
|
__clear_bit(FR_ISREPLY, &req->flags);
|
|
__fuse_request_send(fc, req);
|
|
/* ignore errors */
|
|
fuse_put_request(fc, req);
|
|
}
|
|
|
|
/*
|
|
* Lock the request. Up to the next unlock_request() there mustn't be
|
|
* anything that could cause a page-fault. If the request was already
|
|
* aborted bail out.
|
|
*/
|
|
static int lock_request(struct fuse_req *req)
|
|
{
|
|
int err = 0;
|
|
if (req) {
|
|
spin_lock(&req->waitq.lock);
|
|
if (test_bit(FR_ABORTED, &req->flags))
|
|
err = -ENOENT;
|
|
else
|
|
set_bit(FR_LOCKED, &req->flags);
|
|
spin_unlock(&req->waitq.lock);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Unlock request. If it was aborted while locked, caller is responsible
|
|
* for unlocking and ending the request.
|
|
*/
|
|
static int unlock_request(struct fuse_req *req)
|
|
{
|
|
int err = 0;
|
|
if (req) {
|
|
spin_lock(&req->waitq.lock);
|
|
if (test_bit(FR_ABORTED, &req->flags))
|
|
err = -ENOENT;
|
|
else
|
|
clear_bit(FR_LOCKED, &req->flags);
|
|
spin_unlock(&req->waitq.lock);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
struct fuse_copy_state {
|
|
int write;
|
|
struct fuse_req *req;
|
|
struct iov_iter *iter;
|
|
struct pipe_buffer *pipebufs;
|
|
struct pipe_buffer *currbuf;
|
|
struct pipe_inode_info *pipe;
|
|
unsigned long nr_segs;
|
|
struct page *pg;
|
|
unsigned len;
|
|
unsigned offset;
|
|
unsigned move_pages:1;
|
|
};
|
|
|
|
static void fuse_copy_init(struct fuse_copy_state *cs, int write,
|
|
struct iov_iter *iter)
|
|
{
|
|
memset(cs, 0, sizeof(*cs));
|
|
cs->write = write;
|
|
cs->iter = iter;
|
|
}
|
|
|
|
/* Unmap and put previous page of userspace buffer */
|
|
static void fuse_copy_finish(struct fuse_copy_state *cs)
|
|
{
|
|
if (cs->currbuf) {
|
|
struct pipe_buffer *buf = cs->currbuf;
|
|
|
|
if (cs->write)
|
|
buf->len = PAGE_SIZE - cs->len;
|
|
cs->currbuf = NULL;
|
|
} else if (cs->pg) {
|
|
if (cs->write) {
|
|
flush_dcache_page(cs->pg);
|
|
set_page_dirty_lock(cs->pg);
|
|
}
|
|
put_page(cs->pg);
|
|
}
|
|
cs->pg = NULL;
|
|
}
|
|
|
|
/*
|
|
* Get another pagefull of userspace buffer, and map it to kernel
|
|
* address space, and lock request
|
|
*/
|
|
static int fuse_copy_fill(struct fuse_copy_state *cs)
|
|
{
|
|
struct page *page;
|
|
int err;
|
|
|
|
err = unlock_request(cs->req);
|
|
if (err)
|
|
return err;
|
|
|
|
fuse_copy_finish(cs);
|
|
if (cs->pipebufs) {
|
|
struct pipe_buffer *buf = cs->pipebufs;
|
|
|
|
if (!cs->write) {
|
|
err = buf->ops->confirm(cs->pipe, buf);
|
|
if (err)
|
|
return err;
|
|
|
|
BUG_ON(!cs->nr_segs);
|
|
cs->currbuf = buf;
|
|
cs->pg = buf->page;
|
|
cs->offset = buf->offset;
|
|
cs->len = buf->len;
|
|
cs->pipebufs++;
|
|
cs->nr_segs--;
|
|
} else {
|
|
if (cs->nr_segs == cs->pipe->buffers)
|
|
return -EIO;
|
|
|
|
page = alloc_page(GFP_HIGHUSER);
|
|
if (!page)
|
|
return -ENOMEM;
|
|
|
|
buf->page = page;
|
|
buf->offset = 0;
|
|
buf->len = 0;
|
|
|
|
cs->currbuf = buf;
|
|
cs->pg = page;
|
|
cs->offset = 0;
|
|
cs->len = PAGE_SIZE;
|
|
cs->pipebufs++;
|
|
cs->nr_segs++;
|
|
}
|
|
} else {
|
|
size_t off;
|
|
err = iov_iter_get_pages(cs->iter, &page, PAGE_SIZE, 1, &off);
|
|
if (err < 0)
|
|
return err;
|
|
BUG_ON(!err);
|
|
cs->len = err;
|
|
cs->offset = off;
|
|
cs->pg = page;
|
|
cs->offset = off;
|
|
iov_iter_advance(cs->iter, err);
|
|
}
|
|
|
|
return lock_request(cs->req);
|
|
}
|
|
|
|
/* Do as much copy to/from userspace buffer as we can */
|
|
static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size)
|
|
{
|
|
unsigned ncpy = min(*size, cs->len);
|
|
if (val) {
|
|
void *pgaddr = kmap_atomic(cs->pg);
|
|
void *buf = pgaddr + cs->offset;
|
|
|
|
if (cs->write)
|
|
memcpy(buf, *val, ncpy);
|
|
else
|
|
memcpy(*val, buf, ncpy);
|
|
|
|
kunmap_atomic(pgaddr);
|
|
*val += ncpy;
|
|
}
|
|
*size -= ncpy;
|
|
cs->len -= ncpy;
|
|
cs->offset += ncpy;
|
|
return ncpy;
|
|
}
|
|
|
|
static int fuse_check_page(struct page *page)
|
|
{
|
|
if (page_mapcount(page) ||
|
|
page->mapping != NULL ||
|
|
page_count(page) != 1 ||
|
|
(page->flags & PAGE_FLAGS_CHECK_AT_PREP &
|
|
~(1 << PG_locked |
|
|
1 << PG_referenced |
|
|
1 << PG_uptodate |
|
|
1 << PG_lru |
|
|
1 << PG_active |
|
|
1 << PG_reclaim))) {
|
|
printk(KERN_WARNING "fuse: trying to steal weird page\n");
|
|
printk(KERN_WARNING " page=%p index=%li flags=%08lx, count=%i, mapcount=%i, mapping=%p\n", page, page->index, page->flags, page_count(page), page_mapcount(page), page->mapping);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
|
|
{
|
|
int err;
|
|
struct page *oldpage = *pagep;
|
|
struct page *newpage;
|
|
struct pipe_buffer *buf = cs->pipebufs;
|
|
|
|
err = unlock_request(cs->req);
|
|
if (err)
|
|
return err;
|
|
|
|
fuse_copy_finish(cs);
|
|
|
|
err = buf->ops->confirm(cs->pipe, buf);
|
|
if (err)
|
|
return err;
|
|
|
|
BUG_ON(!cs->nr_segs);
|
|
cs->currbuf = buf;
|
|
cs->len = buf->len;
|
|
cs->pipebufs++;
|
|
cs->nr_segs--;
|
|
|
|
if (cs->len != PAGE_SIZE)
|
|
goto out_fallback;
|
|
|
|
if (buf->ops->steal(cs->pipe, buf) != 0)
|
|
goto out_fallback;
|
|
|
|
newpage = buf->page;
|
|
|
|
if (!PageUptodate(newpage))
|
|
SetPageUptodate(newpage);
|
|
|
|
ClearPageMappedToDisk(newpage);
|
|
|
|
if (fuse_check_page(newpage) != 0)
|
|
goto out_fallback_unlock;
|
|
|
|
/*
|
|
* This is a new and locked page, it shouldn't be mapped or
|
|
* have any special flags on it
|
|
*/
|
|
if (WARN_ON(page_mapped(oldpage)))
|
|
goto out_fallback_unlock;
|
|
if (WARN_ON(page_has_private(oldpage)))
|
|
goto out_fallback_unlock;
|
|
if (WARN_ON(PageDirty(oldpage) || PageWriteback(oldpage)))
|
|
goto out_fallback_unlock;
|
|
if (WARN_ON(PageMlocked(oldpage)))
|
|
goto out_fallback_unlock;
|
|
|
|
err = replace_page_cache_page(oldpage, newpage, GFP_KERNEL);
|
|
if (err) {
|
|
unlock_page(newpage);
|
|
return err;
|
|
}
|
|
|
|
page_cache_get(newpage);
|
|
|
|
if (!(buf->flags & PIPE_BUF_FLAG_LRU))
|
|
lru_cache_add_file(newpage);
|
|
|
|
err = 0;
|
|
spin_lock(&cs->req->waitq.lock);
|
|
if (test_bit(FR_ABORTED, &cs->req->flags))
|
|
err = -ENOENT;
|
|
else
|
|
*pagep = newpage;
|
|
spin_unlock(&cs->req->waitq.lock);
|
|
|
|
if (err) {
|
|
unlock_page(newpage);
|
|
page_cache_release(newpage);
|
|
return err;
|
|
}
|
|
|
|
unlock_page(oldpage);
|
|
page_cache_release(oldpage);
|
|
cs->len = 0;
|
|
|
|
return 0;
|
|
|
|
out_fallback_unlock:
|
|
unlock_page(newpage);
|
|
out_fallback:
|
|
cs->pg = buf->page;
|
|
cs->offset = buf->offset;
|
|
|
|
err = lock_request(cs->req);
|
|
if (err)
|
|
return err;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page,
|
|
unsigned offset, unsigned count)
|
|
{
|
|
struct pipe_buffer *buf;
|
|
int err;
|
|
|
|
if (cs->nr_segs == cs->pipe->buffers)
|
|
return -EIO;
|
|
|
|
err = unlock_request(cs->req);
|
|
if (err)
|
|
return err;
|
|
|
|
fuse_copy_finish(cs);
|
|
|
|
buf = cs->pipebufs;
|
|
page_cache_get(page);
|
|
buf->page = page;
|
|
buf->offset = offset;
|
|
buf->len = count;
|
|
|
|
cs->pipebufs++;
|
|
cs->nr_segs++;
|
|
cs->len = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Copy a page in the request to/from the userspace buffer. Must be
|
|
* done atomically
|
|
*/
|
|
static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep,
|
|
unsigned offset, unsigned count, int zeroing)
|
|
{
|
|
int err;
|
|
struct page *page = *pagep;
|
|
|
|
if (page && zeroing && count < PAGE_SIZE)
|
|
clear_highpage(page);
|
|
|
|
while (count) {
|
|
if (cs->write && cs->pipebufs && page) {
|
|
return fuse_ref_page(cs, page, offset, count);
|
|
} else if (!cs->len) {
|
|
if (cs->move_pages && page &&
|
|
offset == 0 && count == PAGE_SIZE) {
|
|
err = fuse_try_move_page(cs, pagep);
|
|
if (err <= 0)
|
|
return err;
|
|
} else {
|
|
err = fuse_copy_fill(cs);
|
|
if (err)
|
|
return err;
|
|
}
|
|
}
|
|
if (page) {
|
|
void *mapaddr = kmap_atomic(page);
|
|
void *buf = mapaddr + offset;
|
|
offset += fuse_copy_do(cs, &buf, &count);
|
|
kunmap_atomic(mapaddr);
|
|
} else
|
|
offset += fuse_copy_do(cs, NULL, &count);
|
|
}
|
|
if (page && !cs->write)
|
|
flush_dcache_page(page);
|
|
return 0;
|
|
}
|
|
|
|
/* Copy pages in the request to/from userspace buffer */
|
|
static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
|
|
int zeroing)
|
|
{
|
|
unsigned i;
|
|
struct fuse_req *req = cs->req;
|
|
|
|
for (i = 0; i < req->num_pages && (nbytes || zeroing); i++) {
|
|
int err;
|
|
unsigned offset = req->page_descs[i].offset;
|
|
unsigned count = min(nbytes, req->page_descs[i].length);
|
|
|
|
err = fuse_copy_page(cs, &req->pages[i], offset, count,
|
|
zeroing);
|
|
if (err)
|
|
return err;
|
|
|
|
nbytes -= count;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Copy a single argument in the request to/from userspace buffer */
|
|
static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
|
|
{
|
|
while (size) {
|
|
if (!cs->len) {
|
|
int err = fuse_copy_fill(cs);
|
|
if (err)
|
|
return err;
|
|
}
|
|
fuse_copy_do(cs, &val, &size);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Copy request arguments to/from userspace buffer */
|
|
static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,
|
|
unsigned argpages, struct fuse_arg *args,
|
|
int zeroing)
|
|
{
|
|
int err = 0;
|
|
unsigned i;
|
|
|
|
for (i = 0; !err && i < numargs; i++) {
|
|
struct fuse_arg *arg = &args[i];
|
|
if (i == numargs - 1 && argpages)
|
|
err = fuse_copy_pages(cs, arg->size, zeroing);
|
|
else
|
|
err = fuse_copy_one(cs, arg->value, arg->size);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int forget_pending(struct fuse_iqueue *fiq)
|
|
{
|
|
return fiq->forget_list_head.next != NULL;
|
|
}
|
|
|
|
static int request_pending(struct fuse_iqueue *fiq)
|
|
{
|
|
return !list_empty(&fiq->pending) || !list_empty(&fiq->interrupts) ||
|
|
forget_pending(fiq);
|
|
}
|
|
|
|
/*
|
|
* Transfer an interrupt request to userspace
|
|
*
|
|
* Unlike other requests this is assembled on demand, without a need
|
|
* to allocate a separate fuse_req structure.
|
|
*
|
|
* Called with fiq->waitq.lock held, releases it
|
|
*/
|
|
static int fuse_read_interrupt(struct fuse_iqueue *fiq,
|
|
struct fuse_copy_state *cs,
|
|
size_t nbytes, struct fuse_req *req)
|
|
__releases(fiq->waitq.lock)
|
|
{
|
|
struct fuse_in_header ih;
|
|
struct fuse_interrupt_in arg;
|
|
unsigned reqsize = sizeof(ih) + sizeof(arg);
|
|
int err;
|
|
|
|
list_del_init(&req->intr_entry);
|
|
req->intr_unique = fuse_get_unique(fiq);
|
|
memset(&ih, 0, sizeof(ih));
|
|
memset(&arg, 0, sizeof(arg));
|
|
ih.len = reqsize;
|
|
ih.opcode = FUSE_INTERRUPT;
|
|
ih.unique = req->intr_unique;
|
|
arg.unique = req->in.h.unique;
|
|
|
|
spin_unlock(&fiq->waitq.lock);
|
|
if (nbytes < reqsize)
|
|
return -EINVAL;
|
|
|
|
err = fuse_copy_one(cs, &ih, sizeof(ih));
|
|
if (!err)
|
|
err = fuse_copy_one(cs, &arg, sizeof(arg));
|
|
fuse_copy_finish(cs);
|
|
|
|
return err ? err : reqsize;
|
|
}
|
|
|
|
static struct fuse_forget_link *dequeue_forget(struct fuse_iqueue *fiq,
|
|
unsigned max,
|
|
unsigned *countp)
|
|
{
|
|
struct fuse_forget_link *head = fiq->forget_list_head.next;
|
|
struct fuse_forget_link **newhead = &head;
|
|
unsigned count;
|
|
|
|
for (count = 0; *newhead != NULL && count < max; count++)
|
|
newhead = &(*newhead)->next;
|
|
|
|
fiq->forget_list_head.next = *newhead;
|
|
*newhead = NULL;
|
|
if (fiq->forget_list_head.next == NULL)
|
|
fiq->forget_list_tail = &fiq->forget_list_head;
|
|
|
|
if (countp != NULL)
|
|
*countp = count;
|
|
|
|
return head;
|
|
}
|
|
|
|
static int fuse_read_single_forget(struct fuse_iqueue *fiq,
|
|
struct fuse_copy_state *cs,
|
|
size_t nbytes)
|
|
__releases(fiq->waitq.lock)
|
|
{
|
|
int err;
|
|
struct fuse_forget_link *forget = dequeue_forget(fiq, 1, NULL);
|
|
struct fuse_forget_in arg = {
|
|
.nlookup = forget->forget_one.nlookup,
|
|
};
|
|
struct fuse_in_header ih = {
|
|
.opcode = FUSE_FORGET,
|
|
.nodeid = forget->forget_one.nodeid,
|
|
.unique = fuse_get_unique(fiq),
|
|
.len = sizeof(ih) + sizeof(arg),
|
|
};
|
|
|
|
spin_unlock(&fiq->waitq.lock);
|
|
kfree(forget);
|
|
if (nbytes < ih.len)
|
|
return -EINVAL;
|
|
|
|
err = fuse_copy_one(cs, &ih, sizeof(ih));
|
|
if (!err)
|
|
err = fuse_copy_one(cs, &arg, sizeof(arg));
|
|
fuse_copy_finish(cs);
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
return ih.len;
|
|
}
|
|
|
|
static int fuse_read_batch_forget(struct fuse_iqueue *fiq,
|
|
struct fuse_copy_state *cs, size_t nbytes)
|
|
__releases(fiq->waitq.lock)
|
|
{
|
|
int err;
|
|
unsigned max_forgets;
|
|
unsigned count;
|
|
struct fuse_forget_link *head;
|
|
struct fuse_batch_forget_in arg = { .count = 0 };
|
|
struct fuse_in_header ih = {
|
|
.opcode = FUSE_BATCH_FORGET,
|
|
.unique = fuse_get_unique(fiq),
|
|
.len = sizeof(ih) + sizeof(arg),
|
|
};
|
|
|
|
if (nbytes < ih.len) {
|
|
spin_unlock(&fiq->waitq.lock);
|
|
return -EINVAL;
|
|
}
|
|
|
|
max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one);
|
|
head = dequeue_forget(fiq, max_forgets, &count);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
|
|
arg.count = count;
|
|
ih.len += count * sizeof(struct fuse_forget_one);
|
|
err = fuse_copy_one(cs, &ih, sizeof(ih));
|
|
if (!err)
|
|
err = fuse_copy_one(cs, &arg, sizeof(arg));
|
|
|
|
while (head) {
|
|
struct fuse_forget_link *forget = head;
|
|
|
|
if (!err) {
|
|
err = fuse_copy_one(cs, &forget->forget_one,
|
|
sizeof(forget->forget_one));
|
|
}
|
|
head = forget->next;
|
|
kfree(forget);
|
|
}
|
|
|
|
fuse_copy_finish(cs);
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
return ih.len;
|
|
}
|
|
|
|
static int fuse_read_forget(struct fuse_conn *fc, struct fuse_iqueue *fiq,
|
|
struct fuse_copy_state *cs,
|
|
size_t nbytes)
|
|
__releases(fiq->waitq.lock)
|
|
{
|
|
if (fc->minor < 16 || fiq->forget_list_head.next->next == NULL)
|
|
return fuse_read_single_forget(fiq, cs, nbytes);
|
|
else
|
|
return fuse_read_batch_forget(fiq, cs, nbytes);
|
|
}
|
|
|
|
/*
|
|
* Read a single request into the userspace filesystem's buffer. This
|
|
* function waits until a request is available, then removes it from
|
|
* the pending list and copies request data to userspace buffer. If
|
|
* no reply is needed (FORGET) or request has been aborted or there
|
|
* was an error during the copying then it's finished by calling
|
|
* request_end(). Otherwise add it to the processing list, and set
|
|
* the 'sent' flag.
|
|
*/
|
|
static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
|
|
struct fuse_copy_state *cs, size_t nbytes)
|
|
{
|
|
ssize_t err;
|
|
struct fuse_conn *fc = fud->fc;
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
struct fuse_pqueue *fpq = &fud->pq;
|
|
struct fuse_req *req;
|
|
struct fuse_in *in;
|
|
unsigned reqsize;
|
|
|
|
restart:
|
|
spin_lock(&fiq->waitq.lock);
|
|
err = -EAGAIN;
|
|
if ((file->f_flags & O_NONBLOCK) && fiq->connected &&
|
|
!request_pending(fiq))
|
|
goto err_unlock;
|
|
|
|
err = wait_event_interruptible_exclusive_locked(fiq->waitq,
|
|
!fiq->connected || request_pending(fiq));
|
|
if (err)
|
|
goto err_unlock;
|
|
|
|
err = -ENODEV;
|
|
if (!fiq->connected)
|
|
goto err_unlock;
|
|
|
|
if (!list_empty(&fiq->interrupts)) {
|
|
req = list_entry(fiq->interrupts.next, struct fuse_req,
|
|
intr_entry);
|
|
return fuse_read_interrupt(fiq, cs, nbytes, req);
|
|
}
|
|
|
|
if (forget_pending(fiq)) {
|
|
if (list_empty(&fiq->pending) || fiq->forget_batch-- > 0)
|
|
return fuse_read_forget(fc, fiq, cs, nbytes);
|
|
|
|
if (fiq->forget_batch <= -8)
|
|
fiq->forget_batch = 16;
|
|
}
|
|
|
|
req = list_entry(fiq->pending.next, struct fuse_req, list);
|
|
clear_bit(FR_PENDING, &req->flags);
|
|
list_del_init(&req->list);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
|
|
in = &req->in;
|
|
reqsize = in->h.len;
|
|
/* If request is too large, reply with an error and restart the read */
|
|
if (nbytes < reqsize) {
|
|
req->out.h.error = -EIO;
|
|
/* SETXATTR is special, since it may contain too large data */
|
|
if (in->h.opcode == FUSE_SETXATTR)
|
|
req->out.h.error = -E2BIG;
|
|
request_end(fc, req);
|
|
goto restart;
|
|
}
|
|
spin_lock(&fpq->lock);
|
|
list_add(&req->list, &fpq->io);
|
|
spin_unlock(&fpq->lock);
|
|
cs->req = req;
|
|
err = fuse_copy_one(cs, &in->h, sizeof(in->h));
|
|
if (!err)
|
|
err = fuse_copy_args(cs, in->numargs, in->argpages,
|
|
(struct fuse_arg *) in->args, 0);
|
|
fuse_copy_finish(cs);
|
|
spin_lock(&fpq->lock);
|
|
clear_bit(FR_LOCKED, &req->flags);
|
|
if (!fpq->connected) {
|
|
err = -ENODEV;
|
|
goto out_end;
|
|
}
|
|
if (err) {
|
|
req->out.h.error = -EIO;
|
|
goto out_end;
|
|
}
|
|
if (!test_bit(FR_ISREPLY, &req->flags)) {
|
|
err = reqsize;
|
|
goto out_end;
|
|
}
|
|
list_move_tail(&req->list, &fpq->processing);
|
|
spin_unlock(&fpq->lock);
|
|
set_bit(FR_SENT, &req->flags);
|
|
/* matches barrier in request_wait_answer() */
|
|
smp_mb__after_atomic();
|
|
if (test_bit(FR_INTERRUPTED, &req->flags))
|
|
queue_interrupt(fiq, req);
|
|
|
|
return reqsize;
|
|
|
|
out_end:
|
|
if (!test_bit(FR_PRIVATE, &req->flags))
|
|
list_del_init(&req->list);
|
|
spin_unlock(&fpq->lock);
|
|
request_end(fc, req);
|
|
return err;
|
|
|
|
err_unlock:
|
|
spin_unlock(&fiq->waitq.lock);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_dev_open(struct inode *inode, struct file *file)
|
|
{
|
|
/*
|
|
* The fuse device's file's private_data is used to hold
|
|
* the fuse_conn(ection) when it is mounted, and is used to
|
|
* keep track of whether the file has been mounted already.
|
|
*/
|
|
file->private_data = NULL;
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t fuse_dev_read(struct kiocb *iocb, struct iov_iter *to)
|
|
{
|
|
struct fuse_copy_state cs;
|
|
struct file *file = iocb->ki_filp;
|
|
struct fuse_dev *fud = fuse_get_dev(file);
|
|
|
|
if (!fud)
|
|
return -EPERM;
|
|
|
|
if (!iter_is_iovec(to))
|
|
return -EINVAL;
|
|
|
|
fuse_copy_init(&cs, 1, to);
|
|
|
|
return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to));
|
|
}
|
|
|
|
static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
|
|
struct pipe_inode_info *pipe,
|
|
size_t len, unsigned int flags)
|
|
{
|
|
int ret;
|
|
int page_nr = 0;
|
|
int do_wakeup = 0;
|
|
struct pipe_buffer *bufs;
|
|
struct fuse_copy_state cs;
|
|
struct fuse_dev *fud = fuse_get_dev(in);
|
|
|
|
if (!fud)
|
|
return -EPERM;
|
|
|
|
bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
|
|
if (!bufs)
|
|
return -ENOMEM;
|
|
|
|
fuse_copy_init(&cs, 1, NULL);
|
|
cs.pipebufs = bufs;
|
|
cs.pipe = pipe;
|
|
ret = fuse_dev_do_read(fud, in, &cs, len);
|
|
if (ret < 0)
|
|
goto out;
|
|
|
|
ret = 0;
|
|
pipe_lock(pipe);
|
|
|
|
if (!pipe->readers) {
|
|
send_sig(SIGPIPE, current, 0);
|
|
if (!ret)
|
|
ret = -EPIPE;
|
|
goto out_unlock;
|
|
}
|
|
|
|
if (pipe->nrbufs + cs.nr_segs > pipe->buffers) {
|
|
ret = -EIO;
|
|
goto out_unlock;
|
|
}
|
|
|
|
while (page_nr < cs.nr_segs) {
|
|
int newbuf = (pipe->curbuf + pipe->nrbufs) & (pipe->buffers - 1);
|
|
struct pipe_buffer *buf = pipe->bufs + newbuf;
|
|
|
|
buf->page = bufs[page_nr].page;
|
|
buf->offset = bufs[page_nr].offset;
|
|
buf->len = bufs[page_nr].len;
|
|
/*
|
|
* Need to be careful about this. Having buf->ops in module
|
|
* code can Oops if the buffer persists after module unload.
|
|
*/
|
|
buf->ops = &nosteal_pipe_buf_ops;
|
|
|
|
pipe->nrbufs++;
|
|
page_nr++;
|
|
ret += buf->len;
|
|
|
|
if (pipe->files)
|
|
do_wakeup = 1;
|
|
}
|
|
|
|
out_unlock:
|
|
pipe_unlock(pipe);
|
|
|
|
if (do_wakeup) {
|
|
smp_mb();
|
|
if (waitqueue_active(&pipe->wait))
|
|
wake_up_interruptible(&pipe->wait);
|
|
kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
|
|
}
|
|
|
|
out:
|
|
for (; page_nr < cs.nr_segs; page_nr++)
|
|
page_cache_release(bufs[page_nr].page);
|
|
|
|
kfree(bufs);
|
|
return ret;
|
|
}
|
|
|
|
static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_poll_wakeup_out outarg;
|
|
int err = -EINVAL;
|
|
|
|
if (size != sizeof(outarg))
|
|
goto err;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto err;
|
|
|
|
fuse_copy_finish(cs);
|
|
return fuse_notify_poll_wakeup(fc, &outarg);
|
|
|
|
err:
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_inval_inode_out outarg;
|
|
int err = -EINVAL;
|
|
|
|
if (size != sizeof(outarg))
|
|
goto err;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto err;
|
|
fuse_copy_finish(cs);
|
|
|
|
down_read(&fc->killsb);
|
|
err = -ENOENT;
|
|
if (fc->sb) {
|
|
err = fuse_reverse_inval_inode(fc->sb, outarg.ino,
|
|
outarg.off, outarg.len);
|
|
}
|
|
up_read(&fc->killsb);
|
|
return err;
|
|
|
|
err:
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_inval_entry_out outarg;
|
|
int err = -ENOMEM;
|
|
char *buf;
|
|
struct qstr name;
|
|
|
|
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
|
|
if (!buf)
|
|
goto err;
|
|
|
|
err = -EINVAL;
|
|
if (size < sizeof(outarg))
|
|
goto err;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto err;
|
|
|
|
err = -ENAMETOOLONG;
|
|
if (outarg.namelen > FUSE_NAME_MAX)
|
|
goto err;
|
|
|
|
err = -EINVAL;
|
|
if (size != sizeof(outarg) + outarg.namelen + 1)
|
|
goto err;
|
|
|
|
name.name = buf;
|
|
name.len = outarg.namelen;
|
|
err = fuse_copy_one(cs, buf, outarg.namelen + 1);
|
|
if (err)
|
|
goto err;
|
|
fuse_copy_finish(cs);
|
|
buf[outarg.namelen] = 0;
|
|
name.hash = full_name_hash(name.name, name.len);
|
|
|
|
down_read(&fc->killsb);
|
|
err = -ENOENT;
|
|
if (fc->sb)
|
|
err = fuse_reverse_inval_entry(fc->sb, outarg.parent, 0, &name);
|
|
up_read(&fc->killsb);
|
|
kfree(buf);
|
|
return err;
|
|
|
|
err:
|
|
kfree(buf);
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_delete_out outarg;
|
|
int err = -ENOMEM;
|
|
char *buf;
|
|
struct qstr name;
|
|
|
|
buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
|
|
if (!buf)
|
|
goto err;
|
|
|
|
err = -EINVAL;
|
|
if (size < sizeof(outarg))
|
|
goto err;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto err;
|
|
|
|
err = -ENAMETOOLONG;
|
|
if (outarg.namelen > FUSE_NAME_MAX)
|
|
goto err;
|
|
|
|
err = -EINVAL;
|
|
if (size != sizeof(outarg) + outarg.namelen + 1)
|
|
goto err;
|
|
|
|
name.name = buf;
|
|
name.len = outarg.namelen;
|
|
err = fuse_copy_one(cs, buf, outarg.namelen + 1);
|
|
if (err)
|
|
goto err;
|
|
fuse_copy_finish(cs);
|
|
buf[outarg.namelen] = 0;
|
|
name.hash = full_name_hash(name.name, name.len);
|
|
|
|
down_read(&fc->killsb);
|
|
err = -ENOENT;
|
|
if (fc->sb)
|
|
err = fuse_reverse_inval_entry(fc->sb, outarg.parent,
|
|
outarg.child, &name);
|
|
up_read(&fc->killsb);
|
|
kfree(buf);
|
|
return err;
|
|
|
|
err:
|
|
kfree(buf);
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_store_out outarg;
|
|
struct inode *inode;
|
|
struct address_space *mapping;
|
|
u64 nodeid;
|
|
int err;
|
|
pgoff_t index;
|
|
unsigned int offset;
|
|
unsigned int num;
|
|
loff_t file_size;
|
|
loff_t end;
|
|
|
|
err = -EINVAL;
|
|
if (size < sizeof(outarg))
|
|
goto out_finish;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto out_finish;
|
|
|
|
err = -EINVAL;
|
|
if (size - sizeof(outarg) != outarg.size)
|
|
goto out_finish;
|
|
|
|
nodeid = outarg.nodeid;
|
|
|
|
down_read(&fc->killsb);
|
|
|
|
err = -ENOENT;
|
|
if (!fc->sb)
|
|
goto out_up_killsb;
|
|
|
|
inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid);
|
|
if (!inode)
|
|
goto out_up_killsb;
|
|
|
|
mapping = inode->i_mapping;
|
|
index = outarg.offset >> PAGE_CACHE_SHIFT;
|
|
offset = outarg.offset & ~PAGE_CACHE_MASK;
|
|
file_size = i_size_read(inode);
|
|
end = outarg.offset + outarg.size;
|
|
if (end > file_size) {
|
|
file_size = end;
|
|
fuse_write_update_size(inode, file_size);
|
|
}
|
|
|
|
num = outarg.size;
|
|
while (num) {
|
|
struct page *page;
|
|
unsigned int this_num;
|
|
|
|
err = -ENOMEM;
|
|
page = find_or_create_page(mapping, index,
|
|
mapping_gfp_mask(mapping));
|
|
if (!page)
|
|
goto out_iput;
|
|
|
|
this_num = min_t(unsigned, num, PAGE_CACHE_SIZE - offset);
|
|
err = fuse_copy_page(cs, &page, offset, this_num, 0);
|
|
if (!err && offset == 0 &&
|
|
(this_num == PAGE_CACHE_SIZE || file_size == end))
|
|
SetPageUptodate(page);
|
|
unlock_page(page);
|
|
page_cache_release(page);
|
|
|
|
if (err)
|
|
goto out_iput;
|
|
|
|
num -= this_num;
|
|
offset = 0;
|
|
index++;
|
|
}
|
|
|
|
err = 0;
|
|
|
|
out_iput:
|
|
iput(inode);
|
|
out_up_killsb:
|
|
up_read(&fc->killsb);
|
|
out_finish:
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static void fuse_retrieve_end(struct fuse_conn *fc, struct fuse_req *req)
|
|
{
|
|
release_pages(req->pages, req->num_pages, false);
|
|
}
|
|
|
|
static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode,
|
|
struct fuse_notify_retrieve_out *outarg)
|
|
{
|
|
int err;
|
|
struct address_space *mapping = inode->i_mapping;
|
|
struct fuse_req *req;
|
|
pgoff_t index;
|
|
loff_t file_size;
|
|
unsigned int num;
|
|
unsigned int offset;
|
|
size_t total_len = 0;
|
|
int num_pages;
|
|
|
|
offset = outarg->offset & ~PAGE_CACHE_MASK;
|
|
file_size = i_size_read(inode);
|
|
|
|
num = outarg->size;
|
|
if (outarg->offset > file_size)
|
|
num = 0;
|
|
else if (outarg->offset + num > file_size)
|
|
num = file_size - outarg->offset;
|
|
|
|
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
|
|
|
|
req = fuse_get_req(fc, num_pages);
|
|
if (IS_ERR(req))
|
|
return PTR_ERR(req);
|
|
|
|
req->in.h.opcode = FUSE_NOTIFY_REPLY;
|
|
req->in.h.nodeid = outarg->nodeid;
|
|
req->in.numargs = 2;
|
|
req->in.argpages = 1;
|
|
req->page_descs[0].offset = offset;
|
|
req->end = fuse_retrieve_end;
|
|
|
|
index = outarg->offset >> PAGE_CACHE_SHIFT;
|
|
|
|
while (num && req->num_pages < num_pages) {
|
|
struct page *page;
|
|
unsigned int this_num;
|
|
|
|
page = find_get_page(mapping, index);
|
|
if (!page)
|
|
break;
|
|
|
|
this_num = min_t(unsigned, num, PAGE_CACHE_SIZE - offset);
|
|
req->pages[req->num_pages] = page;
|
|
req->page_descs[req->num_pages].length = this_num;
|
|
req->num_pages++;
|
|
|
|
offset = 0;
|
|
num -= this_num;
|
|
total_len += this_num;
|
|
index++;
|
|
}
|
|
req->misc.retrieve_in.offset = outarg->offset;
|
|
req->misc.retrieve_in.size = total_len;
|
|
req->in.args[0].size = sizeof(req->misc.retrieve_in);
|
|
req->in.args[0].value = &req->misc.retrieve_in;
|
|
req->in.args[1].size = total_len;
|
|
|
|
err = fuse_request_send_notify_reply(fc, req, outarg->notify_unique);
|
|
if (err)
|
|
fuse_retrieve_end(fc, req);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
|
|
struct fuse_copy_state *cs)
|
|
{
|
|
struct fuse_notify_retrieve_out outarg;
|
|
struct inode *inode;
|
|
int err;
|
|
|
|
err = -EINVAL;
|
|
if (size != sizeof(outarg))
|
|
goto copy_finish;
|
|
|
|
err = fuse_copy_one(cs, &outarg, sizeof(outarg));
|
|
if (err)
|
|
goto copy_finish;
|
|
|
|
fuse_copy_finish(cs);
|
|
|
|
down_read(&fc->killsb);
|
|
err = -ENOENT;
|
|
if (fc->sb) {
|
|
u64 nodeid = outarg.nodeid;
|
|
|
|
inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid);
|
|
if (inode) {
|
|
err = fuse_retrieve(fc, inode, &outarg);
|
|
iput(inode);
|
|
}
|
|
}
|
|
up_read(&fc->killsb);
|
|
|
|
return err;
|
|
|
|
copy_finish:
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
|
|
unsigned int size, struct fuse_copy_state *cs)
|
|
{
|
|
/* Don't try to move pages (yet) */
|
|
cs->move_pages = 0;
|
|
|
|
switch (code) {
|
|
case FUSE_NOTIFY_POLL:
|
|
return fuse_notify_poll(fc, size, cs);
|
|
|
|
case FUSE_NOTIFY_INVAL_INODE:
|
|
return fuse_notify_inval_inode(fc, size, cs);
|
|
|
|
case FUSE_NOTIFY_INVAL_ENTRY:
|
|
return fuse_notify_inval_entry(fc, size, cs);
|
|
|
|
case FUSE_NOTIFY_STORE:
|
|
return fuse_notify_store(fc, size, cs);
|
|
|
|
case FUSE_NOTIFY_RETRIEVE:
|
|
return fuse_notify_retrieve(fc, size, cs);
|
|
|
|
case FUSE_NOTIFY_DELETE:
|
|
return fuse_notify_delete(fc, size, cs);
|
|
|
|
default:
|
|
fuse_copy_finish(cs);
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
/* Look up request on processing list by unique ID */
|
|
static struct fuse_req *request_find(struct fuse_pqueue *fpq, u64 unique)
|
|
{
|
|
struct fuse_req *req;
|
|
|
|
list_for_each_entry(req, &fpq->processing, list) {
|
|
if (req->in.h.unique == unique || req->intr_unique == unique)
|
|
return req;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out,
|
|
unsigned nbytes)
|
|
{
|
|
unsigned reqsize = sizeof(struct fuse_out_header);
|
|
|
|
if (out->h.error)
|
|
return nbytes != reqsize ? -EINVAL : 0;
|
|
|
|
reqsize += len_args(out->numargs, out->args);
|
|
|
|
if (reqsize < nbytes || (reqsize > nbytes && !out->argvar))
|
|
return -EINVAL;
|
|
else if (reqsize > nbytes) {
|
|
struct fuse_arg *lastarg = &out->args[out->numargs-1];
|
|
unsigned diffsize = reqsize - nbytes;
|
|
if (diffsize > lastarg->size)
|
|
return -EINVAL;
|
|
lastarg->size -= diffsize;
|
|
}
|
|
return fuse_copy_args(cs, out->numargs, out->argpages, out->args,
|
|
out->page_zeroing);
|
|
}
|
|
|
|
/*
|
|
* Write a single reply to a request. First the header is copied from
|
|
* the write buffer. The request is then searched on the processing
|
|
* list by the unique ID found in the header. If found, then remove
|
|
* it from the list and copy the rest of the buffer to the request.
|
|
* The request is finished by calling request_end()
|
|
*/
|
|
static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
|
|
struct fuse_copy_state *cs, size_t nbytes)
|
|
{
|
|
int err;
|
|
struct fuse_conn *fc = fud->fc;
|
|
struct fuse_pqueue *fpq = &fud->pq;
|
|
struct fuse_req *req;
|
|
struct fuse_out_header oh;
|
|
|
|
if (nbytes < sizeof(struct fuse_out_header))
|
|
return -EINVAL;
|
|
|
|
err = fuse_copy_one(cs, &oh, sizeof(oh));
|
|
if (err)
|
|
goto err_finish;
|
|
|
|
err = -EINVAL;
|
|
if (oh.len != nbytes)
|
|
goto err_finish;
|
|
|
|
/*
|
|
* Zero oh.unique indicates unsolicited notification message
|
|
* and error contains notification code.
|
|
*/
|
|
if (!oh.unique) {
|
|
err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
|
|
return err ? err : nbytes;
|
|
}
|
|
|
|
err = -EINVAL;
|
|
if (oh.error <= -1000 || oh.error > 0)
|
|
goto err_finish;
|
|
|
|
spin_lock(&fpq->lock);
|
|
err = -ENOENT;
|
|
if (!fpq->connected)
|
|
goto err_unlock_pq;
|
|
|
|
req = request_find(fpq, oh.unique);
|
|
if (!req)
|
|
goto err_unlock_pq;
|
|
|
|
/* Is it an interrupt reply? */
|
|
if (req->intr_unique == oh.unique) {
|
|
spin_unlock(&fpq->lock);
|
|
|
|
err = -EINVAL;
|
|
if (nbytes != sizeof(struct fuse_out_header))
|
|
goto err_finish;
|
|
|
|
if (oh.error == -ENOSYS)
|
|
fc->no_interrupt = 1;
|
|
else if (oh.error == -EAGAIN)
|
|
queue_interrupt(&fc->iq, req);
|
|
|
|
fuse_copy_finish(cs);
|
|
return nbytes;
|
|
}
|
|
|
|
clear_bit(FR_SENT, &req->flags);
|
|
list_move(&req->list, &fpq->io);
|
|
req->out.h = oh;
|
|
set_bit(FR_LOCKED, &req->flags);
|
|
spin_unlock(&fpq->lock);
|
|
cs->req = req;
|
|
if (!req->out.page_replace)
|
|
cs->move_pages = 0;
|
|
|
|
err = copy_out_args(cs, &req->out, nbytes);
|
|
if (req->in.h.opcode == FUSE_CANONICAL_PATH) {
|
|
req->out.h.error = kern_path((char *)req->out.args[0].value, 0,
|
|
req->canonical_path);
|
|
}
|
|
fuse_copy_finish(cs);
|
|
|
|
fuse_setup_passthrough(fc, req);
|
|
spin_lock(&fpq->lock);
|
|
clear_bit(FR_LOCKED, &req->flags);
|
|
if (!fpq->connected)
|
|
err = -ENOENT;
|
|
else if (err)
|
|
req->out.h.error = -EIO;
|
|
if (!test_bit(FR_PRIVATE, &req->flags))
|
|
list_del_init(&req->list);
|
|
spin_unlock(&fpq->lock);
|
|
|
|
request_end(fc, req);
|
|
|
|
return err ? err : nbytes;
|
|
|
|
err_unlock_pq:
|
|
spin_unlock(&fpq->lock);
|
|
err_finish:
|
|
fuse_copy_finish(cs);
|
|
return err;
|
|
}
|
|
|
|
static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from)
|
|
{
|
|
struct fuse_copy_state cs;
|
|
struct fuse_dev *fud = fuse_get_dev(iocb->ki_filp);
|
|
|
|
if (!fud)
|
|
return -EPERM;
|
|
|
|
if (!iter_is_iovec(from))
|
|
return -EINVAL;
|
|
|
|
fuse_copy_init(&cs, 0, from);
|
|
|
|
return fuse_dev_do_write(fud, &cs, iov_iter_count(from));
|
|
}
|
|
|
|
static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
|
|
struct file *out, loff_t *ppos,
|
|
size_t len, unsigned int flags)
|
|
{
|
|
unsigned nbuf;
|
|
unsigned idx;
|
|
struct pipe_buffer *bufs;
|
|
struct fuse_copy_state cs;
|
|
struct fuse_dev *fud;
|
|
size_t rem;
|
|
ssize_t ret;
|
|
|
|
fud = fuse_get_dev(out);
|
|
if (!fud)
|
|
return -EPERM;
|
|
|
|
bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
|
|
if (!bufs)
|
|
return -ENOMEM;
|
|
|
|
pipe_lock(pipe);
|
|
nbuf = 0;
|
|
rem = 0;
|
|
for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)
|
|
rem += pipe->bufs[(pipe->curbuf + idx) & (pipe->buffers - 1)].len;
|
|
|
|
ret = -EINVAL;
|
|
if (rem < len) {
|
|
pipe_unlock(pipe);
|
|
goto out;
|
|
}
|
|
|
|
rem = len;
|
|
while (rem) {
|
|
struct pipe_buffer *ibuf;
|
|
struct pipe_buffer *obuf;
|
|
|
|
BUG_ON(nbuf >= pipe->buffers);
|
|
BUG_ON(!pipe->nrbufs);
|
|
ibuf = &pipe->bufs[pipe->curbuf];
|
|
obuf = &bufs[nbuf];
|
|
|
|
if (rem >= ibuf->len) {
|
|
*obuf = *ibuf;
|
|
ibuf->ops = NULL;
|
|
pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
|
|
pipe->nrbufs--;
|
|
} else {
|
|
ibuf->ops->get(pipe, ibuf);
|
|
*obuf = *ibuf;
|
|
obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
|
|
obuf->len = rem;
|
|
ibuf->offset += obuf->len;
|
|
ibuf->len -= obuf->len;
|
|
}
|
|
nbuf++;
|
|
rem -= obuf->len;
|
|
}
|
|
pipe_unlock(pipe);
|
|
|
|
fuse_copy_init(&cs, 0, NULL);
|
|
cs.pipebufs = bufs;
|
|
cs.nr_segs = nbuf;
|
|
cs.pipe = pipe;
|
|
|
|
if (flags & SPLICE_F_MOVE)
|
|
cs.move_pages = 1;
|
|
|
|
ret = fuse_dev_do_write(fud, &cs, len);
|
|
|
|
for (idx = 0; idx < nbuf; idx++) {
|
|
struct pipe_buffer *buf = &bufs[idx];
|
|
buf->ops->release(pipe, buf);
|
|
}
|
|
out:
|
|
kfree(bufs);
|
|
return ret;
|
|
}
|
|
|
|
static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
|
|
{
|
|
unsigned mask = POLLOUT | POLLWRNORM;
|
|
struct fuse_iqueue *fiq;
|
|
struct fuse_dev *fud = fuse_get_dev(file);
|
|
|
|
if (!fud)
|
|
return POLLERR;
|
|
|
|
fiq = &fud->fc->iq;
|
|
poll_wait(file, &fiq->waitq, wait);
|
|
|
|
spin_lock(&fiq->waitq.lock);
|
|
if (!fiq->connected)
|
|
mask = POLLERR;
|
|
else if (request_pending(fiq))
|
|
mask |= POLLIN | POLLRDNORM;
|
|
spin_unlock(&fiq->waitq.lock);
|
|
|
|
return mask;
|
|
}
|
|
|
|
/*
|
|
* Abort all requests on the given list (pending or processing)
|
|
*
|
|
* This function releases and reacquires fc->lock
|
|
*/
|
|
static void end_requests(struct fuse_conn *fc, struct list_head *head)
|
|
{
|
|
while (!list_empty(head)) {
|
|
struct fuse_req *req;
|
|
req = list_entry(head->next, struct fuse_req, list);
|
|
req->out.h.error = -ECONNABORTED;
|
|
clear_bit(FR_SENT, &req->flags);
|
|
list_del_init(&req->list);
|
|
request_end(fc, req);
|
|
}
|
|
}
|
|
|
|
static void end_polls(struct fuse_conn *fc)
|
|
{
|
|
struct rb_node *p;
|
|
|
|
p = rb_first(&fc->polled_files);
|
|
|
|
while (p) {
|
|
struct fuse_file *ff;
|
|
ff = rb_entry(p, struct fuse_file, polled_node);
|
|
wake_up_interruptible_all(&ff->poll_wait);
|
|
|
|
p = rb_next(p);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Abort all requests.
|
|
*
|
|
* Emergency exit in case of a malicious or accidental deadlock, or just a hung
|
|
* filesystem.
|
|
*
|
|
* The same effect is usually achievable through killing the filesystem daemon
|
|
* and all users of the filesystem. The exception is the combination of an
|
|
* asynchronous request and the tricky deadlock (see
|
|
* Documentation/filesystems/fuse.txt).
|
|
*
|
|
* Aborting requests under I/O goes as follows: 1: Separate out unlocked
|
|
* requests, they should be finished off immediately. Locked requests will be
|
|
* finished after unlock; see unlock_request(). 2: Finish off the unlocked
|
|
* requests. It is possible that some request will finish before we can. This
|
|
* is OK, the request will in that case be removed from the list before we touch
|
|
* it.
|
|
*/
|
|
void fuse_abort_conn(struct fuse_conn *fc)
|
|
{
|
|
struct fuse_iqueue *fiq = &fc->iq;
|
|
|
|
spin_lock(&fc->lock);
|
|
if (fc->connected) {
|
|
struct fuse_dev *fud;
|
|
struct fuse_req *req, *next;
|
|
LIST_HEAD(to_end1);
|
|
LIST_HEAD(to_end2);
|
|
|
|
fc->connected = 0;
|
|
fc->blocked = 0;
|
|
fuse_set_initialized(fc);
|
|
list_for_each_entry(fud, &fc->devices, entry) {
|
|
struct fuse_pqueue *fpq = &fud->pq;
|
|
|
|
spin_lock(&fpq->lock);
|
|
fpq->connected = 0;
|
|
list_for_each_entry_safe(req, next, &fpq->io, list) {
|
|
req->out.h.error = -ECONNABORTED;
|
|
spin_lock(&req->waitq.lock);
|
|
set_bit(FR_ABORTED, &req->flags);
|
|
if (!test_bit(FR_LOCKED, &req->flags)) {
|
|
set_bit(FR_PRIVATE, &req->flags);
|
|
list_move(&req->list, &to_end1);
|
|
}
|
|
spin_unlock(&req->waitq.lock);
|
|
}
|
|
list_splice_init(&fpq->processing, &to_end2);
|
|
spin_unlock(&fpq->lock);
|
|
}
|
|
fc->max_background = UINT_MAX;
|
|
flush_bg_queue(fc);
|
|
|
|
spin_lock(&fiq->waitq.lock);
|
|
fiq->connected = 0;
|
|
list_splice_init(&fiq->pending, &to_end2);
|
|
list_for_each_entry(req, &to_end2, list)
|
|
clear_bit(FR_PENDING, &req->flags);
|
|
while (forget_pending(fiq))
|
|
kfree(dequeue_forget(fiq, 1, NULL));
|
|
wake_up_all_locked(&fiq->waitq);
|
|
spin_unlock(&fiq->waitq.lock);
|
|
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
|
|
end_polls(fc);
|
|
wake_up_all(&fc->blocked_waitq);
|
|
spin_unlock(&fc->lock);
|
|
|
|
while (!list_empty(&to_end1)) {
|
|
req = list_first_entry(&to_end1, struct fuse_req, list);
|
|
__fuse_get_request(req);
|
|
list_del_init(&req->list);
|
|
request_end(fc, req);
|
|
}
|
|
end_requests(fc, &to_end2);
|
|
} else {
|
|
spin_unlock(&fc->lock);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_abort_conn);
|
|
|
|
int fuse_dev_release(struct inode *inode, struct file *file)
|
|
{
|
|
struct fuse_dev *fud = fuse_get_dev(file);
|
|
|
|
if (fud) {
|
|
struct fuse_conn *fc = fud->fc;
|
|
struct fuse_pqueue *fpq = &fud->pq;
|
|
|
|
WARN_ON(!list_empty(&fpq->io));
|
|
end_requests(fc, &fpq->processing);
|
|
/* Are we the last open device? */
|
|
if (atomic_dec_and_test(&fc->dev_count)) {
|
|
WARN_ON(fc->iq.fasync != NULL);
|
|
fuse_abort_conn(fc);
|
|
}
|
|
fuse_dev_free(fud);
|
|
}
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fuse_dev_release);
|
|
|
|
static int fuse_dev_fasync(int fd, struct file *file, int on)
|
|
{
|
|
struct fuse_dev *fud = fuse_get_dev(file);
|
|
|
|
if (!fud)
|
|
return -EPERM;
|
|
|
|
/* No locking - fasync_helper does its own locking */
|
|
return fasync_helper(fd, file, on, &fud->fc->iq.fasync);
|
|
}
|
|
|
|
static int fuse_device_clone(struct fuse_conn *fc, struct file *new)
|
|
{
|
|
struct fuse_dev *fud;
|
|
|
|
if (new->private_data)
|
|
return -EINVAL;
|
|
|
|
fud = fuse_dev_alloc(fc);
|
|
if (!fud)
|
|
return -ENOMEM;
|
|
|
|
new->private_data = fud;
|
|
atomic_inc(&fc->dev_count);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
|
|
unsigned long arg)
|
|
{
|
|
int err = -ENOTTY;
|
|
|
|
if (cmd == FUSE_DEV_IOC_CLONE) {
|
|
int oldfd;
|
|
|
|
err = -EFAULT;
|
|
if (!get_user(oldfd, (__u32 __user *) arg)) {
|
|
struct file *old = fget(oldfd);
|
|
|
|
err = -EINVAL;
|
|
if (old) {
|
|
struct fuse_dev *fud = NULL;
|
|
|
|
/*
|
|
* Check against file->f_op because CUSE
|
|
* uses the same ioctl handler.
|
|
*/
|
|
if (old->f_op == file->f_op &&
|
|
old->f_cred->user_ns == file->f_cred->user_ns)
|
|
fud = fuse_get_dev(old);
|
|
|
|
if (fud) {
|
|
mutex_lock(&fuse_mutex);
|
|
err = fuse_device_clone(fud->fc, file);
|
|
mutex_unlock(&fuse_mutex);
|
|
}
|
|
fput(old);
|
|
}
|
|
}
|
|
}
|
|
return err;
|
|
}
|
|
|
|
const struct file_operations fuse_dev_operations = {
|
|
.owner = THIS_MODULE,
|
|
.open = fuse_dev_open,
|
|
.llseek = no_llseek,
|
|
.read_iter = fuse_dev_read,
|
|
.splice_read = fuse_dev_splice_read,
|
|
.write_iter = fuse_dev_write,
|
|
.splice_write = fuse_dev_splice_write,
|
|
.poll = fuse_dev_poll,
|
|
.release = fuse_dev_release,
|
|
.fasync = fuse_dev_fasync,
|
|
.unlocked_ioctl = fuse_dev_ioctl,
|
|
.compat_ioctl = fuse_dev_ioctl,
|
|
};
|
|
EXPORT_SYMBOL_GPL(fuse_dev_operations);
|
|
|
|
static struct miscdevice fuse_miscdevice = {
|
|
.minor = FUSE_MINOR,
|
|
.name = "fuse",
|
|
.fops = &fuse_dev_operations,
|
|
};
|
|
|
|
int __init fuse_dev_init(void)
|
|
{
|
|
int err = -ENOMEM;
|
|
fuse_req_cachep = kmem_cache_create("fuse_request",
|
|
sizeof(struct fuse_req),
|
|
0, 0, NULL);
|
|
if (!fuse_req_cachep)
|
|
goto out;
|
|
|
|
err = misc_register(&fuse_miscdevice);
|
|
if (err)
|
|
goto out_cache_clean;
|
|
|
|
return 0;
|
|
|
|
out_cache_clean:
|
|
kmem_cache_destroy(fuse_req_cachep);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
void fuse_dev_cleanup(void)
|
|
{
|
|
misc_deregister(&fuse_miscdevice);
|
|
kmem_cache_destroy(fuse_req_cachep);
|
|
}
|