Changes in 5.10.27 mm/memcg: rename mem_cgroup_split_huge_fixup to split_page_memcg and add nr_pages argument mm/memcg: set memcg when splitting page mt76: fix tx skb error handling in mt76_dma_tx_queue_skb net: stmmac: fix dma physical address of descriptor when display ring net: fec: ptp: avoid register access when ipg clock is disabled powerpc/4xx: Fix build errors from mfdcr() atm: eni: dont release is never initialized atm: lanai: dont run lanai_dev_close if not open Revert "r8152: adjust the settings about MAC clock speed down for RTL8153" ALSA: hda: ignore invalid NHLT table ixgbe: Fix memleak in ixgbe_configure_clsu32 scsi: ufs: ufs-qcom: Disable interrupt in reset path blk-cgroup: Fix the recursive blkg rwstat net: tehuti: fix error return code in bdx_probe() net: intel: iavf: fix error return code of iavf_init_get_resources() sun/niu: fix wrong RXMAC_BC_FRM_CNT_COUNT count gianfar: fix jumbo packets+napi+rx overrun crash cifs: ask for more credit on async read/write code paths gfs2: fix use-after-free in trans_drain cpufreq: blacklist Arm Vexpress platforms in cpufreq-dt-platdev gpiolib: acpi: Add missing IRQF_ONESHOT nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default NFS: Correct size calculation for create reply length net: hisilicon: hns: fix error return code of hns_nic_clear_all_rx_fetch() net: wan: fix error return code of uhdlc_init() net: davicom: Use platform_get_irq_optional() net: enetc: set MAC RX FIFO to recommended value atm: uPD98402: fix incorrect allocation atm: idt77252: fix null-ptr-dereference cifs: change noisy error message to FYI irqchip/ingenic: Add support for the JZ4760 kbuild: add image_name to no-sync-config-targets kbuild: dummy-tools: fix inverted tests for gcc umem: fix error return code in mm_pci_probe() sparc64: Fix opcode filtering in handling of no fault loads habanalabs: Call put_pid() when releasing control device staging: rtl8192e: fix kconfig dependency on CRYPTO u64_stats,lockdep: Fix u64_stats_init() vs lockdep kselftest: arm64: Fix exit code of sve-ptrace regulator: qcom-rpmh: Correct the pmic5_hfsmps515 buck block: Fix REQ_OP_ZONE_RESET_ALL handling drm/amd/display: Revert dram_clock_change_latency for DCN2.1 drm/amdgpu: fb BO should be ttm_bo_type_device drm/radeon: fix AGP dependency nvme: simplify error logic in nvme_validate_ns() nvme: add NVME_REQ_CANCELLED flag in nvme_cancel_request() nvme-fc: set NVME_REQ_CANCELLED in nvme_fc_terminate_exchange() nvme-fc: return NVME_SC_HOST_ABORTED_CMD when a command has been aborted nvme-core: check ctrl css before setting up zns nvme-rdma: Fix a use after free in nvmet_rdma_write_data_done nvme-pci: add the DISABLE_WRITE_ZEROES quirk for a Samsung PM1725a nfs: we don't support removing system.nfs4_acl block: Suppress uevent for hidden device when removed mm/fork: clear PASID for new mm ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign static_call: Pull some static_call declarations to the type headers static_call: Allow module use without exposing static_call_key static_call: Fix the module key fixup static_call: Fix static_call_set_init() KVM: x86: Protect userspace MSR filter with SRCU, and set atomically-ish btrfs: fix sleep while in non-sleep context during qgroup removal selinux: don't log MAC_POLICY_LOAD record on failed policy load selinux: fix variable scope issue in live sidtab conversion netsec: restore phy power state after controller reset platform/x86: intel-vbtn: Stop reporting SW_DOCK events psample: Fix user API breakage z3fold: prevent reclaim/free race for headless pages squashfs: fix inode lookup sanity checks squashfs: fix xattr id and id lookup sanity checks hugetlb_cgroup: fix imbalanced css_get and css_put pair for shared mappings kasan: fix per-page tags for non-page_alloc pages gcov: fix clang-11+ support ACPI: video: Add missing callback back for Sony VPCEH3U1E ACPICA: Always create namespace nodes using acpi_ns_create_node() arm64: stacktrace: don't trace arch_stack_walk() arm64: dts: ls1046a: mark crypto engine dma coherent arm64: dts: ls1012a: mark crypto engine dma coherent arm64: dts: ls1043a: mark crypto engine dma coherent ARM: dts: at91: sam9x60: fix mux-mask for PA7 so it can be set to A, B and C ARM: dts: at91: sam9x60: fix mux-mask to match product's datasheet ARM: dts: at91-sama5d27_som1: fix phy address to 7 integrity: double check iint_cache was initialized drm/etnaviv: Use FOLL_FORCE for userptr drm/amd/pm: workaround for audio noise issue drm/amdgpu/display: restore AUX_DPHY_TX_CONTROL for DCN2.x drm/amdgpu: Add additional Sienna Cichlid PCI ID drm/i915: Fix the GT fence revocation runtime PM logic dm verity: fix DM_VERITY_OPTS_MAX value dm ioctl: fix out of bounds array access when no devices bus: omap_l3_noc: mark l3 irqs as IRQF_NO_THREAD ARM: OMAP2+: Fix smartreflex init regression after dropping legacy data soc: ti: omap-prm: Fix occasional abort on reset deassert for dra7 iva veth: Store queue_mapping independently of XDP prog presence bpf: Change inode_storage's lookup_elem return value from NULL to -EBADF libbpf: Fix INSTALL flag order net/mlx5e: RX, Mind the MPWQE gaps when calculating offsets net/mlx5e: When changing XDP program without reset, take refs for XSK RQs net/mlx5e: Don't match on Geneve options in case option masks are all zero ipv6: fix suspecious RCU usage warning drop_monitor: Perform cleanup upon probe registration failure macvlan: macvlan_count_rx() needs to be aware of preemption net: sched: validate stab values net: dsa: bcm_sf2: Qualify phydev->dev_flags based on port igc: reinit_locked() should be called with rtnl_lock igc: Fix Pause Frame Advertising igc: Fix Supported Pause Frame Link Setting igc: Fix igc_ptp_rx_pktstamp() e1000e: add rtnl_lock() to e1000_reset_task e1000e: Fix error handling in e1000_set_d0_lplu_state_82571 net/qlcnic: Fix a use after free in qlcnic_83xx_get_minidump_template net: phy: broadcom: Add power down exit reset state delay ftgmac100: Restart MAC HW once clk: qcom: gcc-sc7180: Use floor ops for the correct sdcc1 clk net: ipa: terminate message handler arrays net: qrtr: fix a kernel-infoleak in qrtr_recvmsg() flow_dissector: fix byteorder of dissected ICMP ID selftests/bpf: Set gopt opt_class to 0 if get tunnel opt failed netfilter: ctnetlink: fix dump of the expect mask attribute net: hdlc_x25: Prevent racing between "x25_close" and "x25_xmit"/"x25_rx" net: phylink: Fix phylink_err() function name error in phylink_major_config tipc: better validate user input in tipc_nl_retrieve_key() tcp: relookup sock for RST+ACK packets handled by obsolete req sock can: isotp: isotp_setsockopt(): only allow to set low level TX flags for CAN-FD can: isotp: TX-path: ensure that CAN frame flags are initialized can: peak_usb: add forgotten supported devices can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate can: kvaser_pciefd: Always disable bus load reporting can: c_can_pci: c_can_pci_remove(): fix use-after-free can: c_can: move runtime PM enable/disable to c_can_platform can: m_can: m_can_do_rx_poll(): fix extraneous msg loss warning can: m_can: m_can_rx_peripheral(): fix RX being blocked by errors mac80211: fix rate mask reset mac80211: Allow HE operation to be longer than expected. selftests/net: fix warnings on reuseaddr_ports_exhausted nfp: flower: fix unsupported pre_tunnel flows nfp: flower: add ipv6 bit to pre_tunnel control message nfp: flower: fix pre_tun mask id allocation ftrace: Fix modify_ftrace_direct. drm/msm/dsi: fix check-before-set in the 7nm dsi_pll code ionic: linearize tso skb with too many frags net/sched: cls_flower: fix only mask bit check in the validate_ct_state netfilter: nftables: report EOPNOTSUPP on unsupported flowtable flags netfilter: nftables: allow to update flowtable flags netfilter: flowtable: Make sure GC works periodically in idle system libbpf: Fix error path in bpf_object__elf_init() libbpf: Use SOCK_CLOEXEC when opening the netlink socket ARM: dts: imx6ull: fix ubi filesystem mount failed ipv6: weaken the v4mapped source check octeontx2-af: Formatting debugfs entry rsrc_alloc. octeontx2-af: Modify default KEX profile to extract TX packet fields octeontx2-af: Remove TOS field from MKEX TX octeontx2-af: Fix irq free in rvu teardown octeontx2-pf: Clear RSS enable flag on interace down octeontx2-af: fix infinite loop in unmapping NPC counter net: check all name nodes in __dev_alloc_name net: cdc-phonet: fix data-interface release on probe failure igb: check timestamp validity r8152: limit the RX buffer size of RTL8153A for USB 2.0 net: stmmac: dwmac-sun8i: Provide TX and RX fifo sizes selinux: vsock: Set SID for socket returned by accept() selftests: forwarding: vxlan_bridge_1d: Fix vxlan ecn decapsulate value libbpf: Fix BTF dump of pointer-to-array-of-struct bpf: Fix umd memory leak in copy_process() can: isotp: tx-path: zero initialize outgoing CAN frames drm/msm: fix shutdown hook in case GPU components failed to bind drm/msm: Fix suspend/resume on i.MX5 arm64: kdump: update ppos when reading elfcorehdr PM: runtime: Defer suspending suppliers net/mlx5: Add back multicast stats for uplink representor net/mlx5e: Allow to match on MPLS parameters only for MPLS over UDP net/mlx5e: Offload tuple rewrite for non-CT flows net/mlx5e: Fix error path for ethtool set-priv-flag PM: EM: postpone creating the debugfs dir till fs_initcall net: bridge: don't notify switchdev for local FDB addresses octeontx2-af: Fix memory leak of object buf xen/x86: make XEN_BALLOON_MEMORY_HOTPLUG_LIMIT depend on MEMORY_HOTPLUG RDMA/cxgb4: Fix adapter LE hash errors while destroying ipv6 listening server bpf: Don't do bpf_cgroup_storage_set() for kuprobe/tp programs net: Consolidate common blackhole dst ops net, bpf: Fix ip6ip6 crash with collect_md populated skbs igb: avoid premature Rx buffer reuse net: axienet: Properly handle PCS/PMA PHY for 1000BaseX mode net: axienet: Fix probe error cleanup net: phy: introduce phydev->port net: phy: broadcom: Avoid forward for bcm54xx_config_clock_delay() net: phy: broadcom: Set proper 1000BaseX/SGMII interface mode for BCM54616S net: phy: broadcom: Fix RGMII delays for BCM50160 and BCM50610M Revert "netfilter: x_tables: Switch synchronization to RCU" netfilter: x_tables: Use correct memory barriers. dm table: Fix zoned model check and zone sectors check mm/mmu_notifiers: ensure range_end() is paired with range_start() Revert "netfilter: x_tables: Update remaining dereference to RCU" ACPI: scan: Rearrange memory allocation in acpi_device_add() ACPI: scan: Use unique number for instance_no perf auxtrace: Fix auxtrace queue conflict perf synthetic events: Avoid write of uninitialized memory when generating PERF_RECORD_MMAP* records io_uring: fix provide_buffers sign extension block: recalculate segment count for multi-segment discards correctly scsi: Revert "qla2xxx: Make sure that aborted commands are freed" scsi: qedi: Fix error return code of qedi_alloc_global_queues() scsi: mpt3sas: Fix error return code of mpt3sas_base_attach() smb3: fix cached file size problems in duplicate extents (reflink) cifs: Adjust key sizes and key generation routines for AES256 encryption locking/mutex: Fix non debug version of mutex_lock_io_nested() x86/mem_encrypt: Correct physical address calculation in __set_clr_pte_enc() mm/memcg: fix 5.10 backport of splitting page memcg fs/cachefiles: Remove wait_bit_key layout dependency ch_ktls: fix enum-conversion warning can: dev: Move device back to init netns on owning netns delete r8169: fix DMA being used after buffer free if WoL is enabled net: dsa: b53: VLAN filtering is global to all users mac80211: fix double free in ibss_leave ext4: add reclaim checks to xattr code fs/ext4: fix integer overflow in s_log_groups_per_flex Revert "xen: fix p2m size in dom0 for disabled memory hotplug case" Revert "net: bonding: fix error return code of bond_neigh_init()" nvme: fix the nsid value to print in nvme_validate_or_alloc_ns can: peak_usb: Revert "can: peak_usb: add forgotten supported devices" xen-blkback: don't leak persistent grants from xen_blkbk_map() Linux 5.10.27 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I7eafe976fd6bf33db6db4adb8ebf2ff087294a23
756 lines
24 KiB
C
756 lines
24 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_MMU_NOTIFIER_H
|
|
#define _LINUX_MMU_NOTIFIER_H
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/mm_types.h>
|
|
#include <linux/mmap_lock.h>
|
|
#include <linux/srcu.h>
|
|
#include <linux/interval_tree.h>
|
|
#include <linux/android_kabi.h>
|
|
|
|
struct mmu_notifier_subscriptions;
|
|
struct mmu_notifier;
|
|
struct mmu_notifier_range;
|
|
struct mmu_interval_notifier;
|
|
|
|
/**
|
|
* enum mmu_notifier_event - reason for the mmu notifier callback
|
|
* @MMU_NOTIFY_UNMAP: either munmap() that unmap the range or a mremap() that
|
|
* move the range
|
|
*
|
|
* @MMU_NOTIFY_CLEAR: clear page table entry (many reasons for this like
|
|
* madvise() or replacing a page by another one, ...).
|
|
*
|
|
* @MMU_NOTIFY_PROTECTION_VMA: update is due to protection change for the range
|
|
* ie using the vma access permission (vm_page_prot) to update the whole range
|
|
* is enough no need to inspect changes to the CPU page table (mprotect()
|
|
* syscall)
|
|
*
|
|
* @MMU_NOTIFY_PROTECTION_PAGE: update is due to change in read/write flag for
|
|
* pages in the range so to mirror those changes the user must inspect the CPU
|
|
* page table (from the end callback).
|
|
*
|
|
* @MMU_NOTIFY_SOFT_DIRTY: soft dirty accounting (still same page and same
|
|
* access flags). User should soft dirty the page in the end callback to make
|
|
* sure that anyone relying on soft dirtyness catch pages that might be written
|
|
* through non CPU mappings.
|
|
*
|
|
* @MMU_NOTIFY_RELEASE: used during mmu_interval_notifier invalidate to signal
|
|
* that the mm refcount is zero and the range is no longer accessible.
|
|
*
|
|
* @MMU_NOTIFY_MIGRATE: used during migrate_vma_collect() invalidate to signal
|
|
* a device driver to possibly ignore the invalidation if the
|
|
* migrate_pgmap_owner field matches the driver's device private pgmap owner.
|
|
*/
|
|
enum mmu_notifier_event {
|
|
MMU_NOTIFY_UNMAP = 0,
|
|
MMU_NOTIFY_CLEAR,
|
|
MMU_NOTIFY_PROTECTION_VMA,
|
|
MMU_NOTIFY_PROTECTION_PAGE,
|
|
MMU_NOTIFY_SOFT_DIRTY,
|
|
MMU_NOTIFY_RELEASE,
|
|
MMU_NOTIFY_MIGRATE,
|
|
};
|
|
|
|
#define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0)
|
|
|
|
struct mmu_notifier_ops {
|
|
/*
|
|
* Called either by mmu_notifier_unregister or when the mm is
|
|
* being destroyed by exit_mmap, always before all pages are
|
|
* freed. This can run concurrently with other mmu notifier
|
|
* methods (the ones invoked outside the mm context) and it
|
|
* should tear down all secondary mmu mappings and freeze the
|
|
* secondary mmu. If this method isn't implemented you've to
|
|
* be sure that nothing could possibly write to the pages
|
|
* through the secondary mmu by the time the last thread with
|
|
* tsk->mm == mm exits.
|
|
*
|
|
* As side note: the pages freed after ->release returns could
|
|
* be immediately reallocated by the gart at an alias physical
|
|
* address with a different cache model, so if ->release isn't
|
|
* implemented because all _software_ driven memory accesses
|
|
* through the secondary mmu are terminated by the time the
|
|
* last thread of this mm quits, you've also to be sure that
|
|
* speculative _hardware_ operations can't allocate dirty
|
|
* cachelines in the cpu that could not be snooped and made
|
|
* coherent with the other read and write operations happening
|
|
* through the gart alias address, so leading to memory
|
|
* corruption.
|
|
*/
|
|
void (*release)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm);
|
|
|
|
/*
|
|
* clear_flush_young is called after the VM is
|
|
* test-and-clearing the young/accessed bitflag in the
|
|
* pte. This way the VM will provide proper aging to the
|
|
* accesses to the page through the secondary MMUs and not
|
|
* only to the ones through the Linux pte.
|
|
* Start-end is necessary in case the secondary MMU is mapping the page
|
|
* at a smaller granularity than the primary MMU.
|
|
*/
|
|
int (*clear_flush_young)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end);
|
|
|
|
/*
|
|
* clear_young is a lightweight version of clear_flush_young. Like the
|
|
* latter, it is supposed to test-and-clear the young/accessed bitflag
|
|
* in the secondary pte, but it may omit flushing the secondary tlb.
|
|
*/
|
|
int (*clear_young)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end);
|
|
|
|
/*
|
|
* test_young is called to check the young/accessed bitflag in
|
|
* the secondary pte. This is used to know if the page is
|
|
* frequently used without actually clearing the flag or tearing
|
|
* down the secondary mapping on the page.
|
|
*/
|
|
int (*test_young)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm,
|
|
unsigned long address);
|
|
|
|
/*
|
|
* change_pte is called in cases that pte mapping to page is changed:
|
|
* for example, when ksm remaps pte to point to a new shared page.
|
|
*/
|
|
void (*change_pte)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm,
|
|
unsigned long address,
|
|
pte_t pte);
|
|
|
|
/*
|
|
* invalidate_range_start() and invalidate_range_end() must be
|
|
* paired and are called only when the mmap_lock and/or the
|
|
* locks protecting the reverse maps are held. If the subsystem
|
|
* can't guarantee that no additional references are taken to
|
|
* the pages in the range, it has to implement the
|
|
* invalidate_range() notifier to remove any references taken
|
|
* after invalidate_range_start().
|
|
*
|
|
* Invalidation of multiple concurrent ranges may be
|
|
* optionally permitted by the driver. Either way the
|
|
* establishment of sptes is forbidden in the range passed to
|
|
* invalidate_range_begin/end for the whole duration of the
|
|
* invalidate_range_begin/end critical section.
|
|
*
|
|
* invalidate_range_start() is called when all pages in the
|
|
* range are still mapped and have at least a refcount of one.
|
|
*
|
|
* invalidate_range_end() is called when all pages in the
|
|
* range have been unmapped and the pages have been freed by
|
|
* the VM.
|
|
*
|
|
* The VM will remove the page table entries and potentially
|
|
* the page between invalidate_range_start() and
|
|
* invalidate_range_end(). If the page must not be freed
|
|
* because of pending I/O or other circumstances then the
|
|
* invalidate_range_start() callback (or the initial mapping
|
|
* by the driver) must make sure that the refcount is kept
|
|
* elevated.
|
|
*
|
|
* If the driver increases the refcount when the pages are
|
|
* initially mapped into an address space then either
|
|
* invalidate_range_start() or invalidate_range_end() may
|
|
* decrease the refcount. If the refcount is decreased on
|
|
* invalidate_range_start() then the VM can free pages as page
|
|
* table entries are removed. If the refcount is only
|
|
* droppped on invalidate_range_end() then the driver itself
|
|
* will drop the last refcount but it must take care to flush
|
|
* any secondary tlb before doing the final free on the
|
|
* page. Pages will no longer be referenced by the linux
|
|
* address space but may still be referenced by sptes until
|
|
* the last refcount is dropped.
|
|
*
|
|
* If blockable argument is set to false then the callback cannot
|
|
* sleep and has to return with -EAGAIN if sleeping would be required.
|
|
* 0 should be returned otherwise. Please note that notifiers that can
|
|
* fail invalidate_range_start are not allowed to implement
|
|
* invalidate_range_end, as there is no mechanism for informing the
|
|
* notifier that its start failed.
|
|
*/
|
|
int (*invalidate_range_start)(struct mmu_notifier *subscription,
|
|
const struct mmu_notifier_range *range);
|
|
void (*invalidate_range_end)(struct mmu_notifier *subscription,
|
|
const struct mmu_notifier_range *range);
|
|
|
|
/*
|
|
* invalidate_range() is either called between
|
|
* invalidate_range_start() and invalidate_range_end() when the
|
|
* VM has to free pages that where unmapped, but before the
|
|
* pages are actually freed, or outside of _start()/_end() when
|
|
* a (remote) TLB is necessary.
|
|
*
|
|
* If invalidate_range() is used to manage a non-CPU TLB with
|
|
* shared page-tables, it not necessary to implement the
|
|
* invalidate_range_start()/end() notifiers, as
|
|
* invalidate_range() alread catches the points in time when an
|
|
* external TLB range needs to be flushed. For more in depth
|
|
* discussion on this see Documentation/vm/mmu_notifier.rst
|
|
*
|
|
* Note that this function might be called with just a sub-range
|
|
* of what was passed to invalidate_range_start()/end(), if
|
|
* called between those functions.
|
|
*/
|
|
void (*invalidate_range)(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end);
|
|
|
|
/*
|
|
* These callbacks are used with the get/put interface to manage the
|
|
* lifetime of the mmu_notifier memory. alloc_notifier() returns a new
|
|
* notifier for use with the mm.
|
|
*
|
|
* free_notifier() is only called after the mmu_notifier has been
|
|
* fully put, calls to any ops callback are prevented and no ops
|
|
* callbacks are currently running. It is called from a SRCU callback
|
|
* and cannot sleep.
|
|
*/
|
|
struct mmu_notifier *(*alloc_notifier)(struct mm_struct *mm);
|
|
void (*free_notifier)(struct mmu_notifier *subscription);
|
|
|
|
ANDROID_KABI_RESERVE(1);
|
|
ANDROID_KABI_RESERVE(2);
|
|
ANDROID_KABI_RESERVE(3);
|
|
ANDROID_KABI_RESERVE(4);
|
|
};
|
|
|
|
/*
|
|
* The notifier chains are protected by mmap_lock and/or the reverse map
|
|
* semaphores. Notifier chains are only changed when all reverse maps and
|
|
* the mmap_lock locks are taken.
|
|
*
|
|
* Therefore notifier chains can only be traversed when either
|
|
*
|
|
* 1. mmap_lock is held.
|
|
* 2. One of the reverse map locks is held (i_mmap_rwsem or anon_vma->rwsem).
|
|
* 3. No other concurrent thread can access the list (release)
|
|
*/
|
|
struct mmu_notifier {
|
|
struct hlist_node hlist;
|
|
const struct mmu_notifier_ops *ops;
|
|
struct mm_struct *mm;
|
|
struct rcu_head rcu;
|
|
unsigned int users;
|
|
|
|
ANDROID_KABI_RESERVE(1);
|
|
ANDROID_KABI_RESERVE(2);
|
|
};
|
|
|
|
/**
|
|
* struct mmu_interval_notifier_ops
|
|
* @invalidate: Upon return the caller must stop using any SPTEs within this
|
|
* range. This function can sleep. Return false only if sleeping
|
|
* was required but mmu_notifier_range_blockable(range) is false.
|
|
*/
|
|
struct mmu_interval_notifier_ops {
|
|
bool (*invalidate)(struct mmu_interval_notifier *interval_sub,
|
|
const struct mmu_notifier_range *range,
|
|
unsigned long cur_seq);
|
|
};
|
|
|
|
struct mmu_interval_notifier {
|
|
struct interval_tree_node interval_tree;
|
|
const struct mmu_interval_notifier_ops *ops;
|
|
struct mm_struct *mm;
|
|
struct hlist_node deferred_item;
|
|
unsigned long invalidate_seq;
|
|
};
|
|
|
|
#ifdef CONFIG_MMU_NOTIFIER
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
|
extern struct lockdep_map __mmu_notifier_invalidate_range_start_map;
|
|
#endif
|
|
|
|
struct mmu_notifier_range {
|
|
struct vm_area_struct *vma;
|
|
struct mm_struct *mm;
|
|
unsigned long start;
|
|
unsigned long end;
|
|
unsigned flags;
|
|
enum mmu_notifier_event event;
|
|
void *migrate_pgmap_owner;
|
|
};
|
|
|
|
static inline int mm_has_notifiers(struct mm_struct *mm)
|
|
{
|
|
return unlikely(mm->notifier_subscriptions);
|
|
}
|
|
|
|
struct mmu_notifier *mmu_notifier_get_locked(const struct mmu_notifier_ops *ops,
|
|
struct mm_struct *mm);
|
|
static inline struct mmu_notifier *
|
|
mmu_notifier_get(const struct mmu_notifier_ops *ops, struct mm_struct *mm)
|
|
{
|
|
struct mmu_notifier *ret;
|
|
|
|
mmap_write_lock(mm);
|
|
ret = mmu_notifier_get_locked(ops, mm);
|
|
mmap_write_unlock(mm);
|
|
return ret;
|
|
}
|
|
void mmu_notifier_put(struct mmu_notifier *subscription);
|
|
void mmu_notifier_synchronize(void);
|
|
|
|
extern int mmu_notifier_register(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm);
|
|
extern int __mmu_notifier_register(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm);
|
|
extern void mmu_notifier_unregister(struct mmu_notifier *subscription,
|
|
struct mm_struct *mm);
|
|
|
|
unsigned long
|
|
mmu_interval_read_begin(struct mmu_interval_notifier *interval_sub);
|
|
int mmu_interval_notifier_insert(struct mmu_interval_notifier *interval_sub,
|
|
struct mm_struct *mm, unsigned long start,
|
|
unsigned long length,
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
int mmu_interval_notifier_insert_locked(
|
|
struct mmu_interval_notifier *interval_sub, struct mm_struct *mm,
|
|
unsigned long start, unsigned long length,
|
|
const struct mmu_interval_notifier_ops *ops);
|
|
void mmu_interval_notifier_remove(struct mmu_interval_notifier *interval_sub);
|
|
|
|
/**
|
|
* mmu_interval_set_seq - Save the invalidation sequence
|
|
* @interval_sub - The subscription passed to invalidate
|
|
* @cur_seq - The cur_seq passed to the invalidate() callback
|
|
*
|
|
* This must be called unconditionally from the invalidate callback of a
|
|
* struct mmu_interval_notifier_ops under the same lock that is used to call
|
|
* mmu_interval_read_retry(). It updates the sequence number for later use by
|
|
* mmu_interval_read_retry(). The provided cur_seq will always be odd.
|
|
*
|
|
* If the caller does not call mmu_interval_read_begin() or
|
|
* mmu_interval_read_retry() then this call is not required.
|
|
*/
|
|
static inline void
|
|
mmu_interval_set_seq(struct mmu_interval_notifier *interval_sub,
|
|
unsigned long cur_seq)
|
|
{
|
|
WRITE_ONCE(interval_sub->invalidate_seq, cur_seq);
|
|
}
|
|
|
|
/**
|
|
* mmu_interval_read_retry - End a read side critical section against a VA range
|
|
* interval_sub: The subscription
|
|
* seq: The return of the paired mmu_interval_read_begin()
|
|
*
|
|
* This MUST be called under a user provided lock that is also held
|
|
* unconditionally by op->invalidate() when it calls mmu_interval_set_seq().
|
|
*
|
|
* Each call should be paired with a single mmu_interval_read_begin() and
|
|
* should be used to conclude the read side.
|
|
*
|
|
* Returns true if an invalidation collided with this critical section, and
|
|
* the caller should retry.
|
|
*/
|
|
static inline bool
|
|
mmu_interval_read_retry(struct mmu_interval_notifier *interval_sub,
|
|
unsigned long seq)
|
|
{
|
|
return interval_sub->invalidate_seq != seq;
|
|
}
|
|
|
|
/**
|
|
* mmu_interval_check_retry - Test if a collision has occurred
|
|
* interval_sub: The subscription
|
|
* seq: The return of the matching mmu_interval_read_begin()
|
|
*
|
|
* This can be used in the critical section between mmu_interval_read_begin()
|
|
* and mmu_interval_read_retry(). A return of true indicates an invalidation
|
|
* has collided with this critical region and a future
|
|
* mmu_interval_read_retry() will return true.
|
|
*
|
|
* False is not reliable and only suggests a collision may not have
|
|
* occured. It can be called many times and does not have to hold the user
|
|
* provided lock.
|
|
*
|
|
* This call can be used as part of loops and other expensive operations to
|
|
* expedite a retry.
|
|
*/
|
|
static inline bool
|
|
mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub,
|
|
unsigned long seq)
|
|
{
|
|
/* Pairs with the WRITE_ONCE in mmu_interval_set_seq() */
|
|
return READ_ONCE(interval_sub->invalidate_seq) != seq;
|
|
}
|
|
|
|
extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
|
|
extern void __mmu_notifier_release(struct mm_struct *mm);
|
|
extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end);
|
|
extern int __mmu_notifier_clear_young(struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end);
|
|
extern int __mmu_notifier_test_young(struct mm_struct *mm,
|
|
unsigned long address);
|
|
extern void __mmu_notifier_change_pte(struct mm_struct *mm,
|
|
unsigned long address, pte_t pte);
|
|
extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r);
|
|
extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r,
|
|
bool only_end);
|
|
extern void __mmu_notifier_invalidate_range(struct mm_struct *mm,
|
|
unsigned long start, unsigned long end);
|
|
extern bool
|
|
mmu_notifier_range_update_to_read_only(const struct mmu_notifier_range *range);
|
|
|
|
static inline bool
|
|
mmu_notifier_range_blockable(const struct mmu_notifier_range *range)
|
|
{
|
|
return (range->flags & MMU_NOTIFIER_RANGE_BLOCKABLE);
|
|
}
|
|
|
|
static inline void mmu_notifier_release(struct mm_struct *mm)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
__mmu_notifier_release(mm);
|
|
}
|
|
|
|
static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
return __mmu_notifier_clear_flush_young(mm, start, end);
|
|
return 0;
|
|
}
|
|
|
|
static inline int mmu_notifier_clear_young(struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
return __mmu_notifier_clear_young(mm, start, end);
|
|
return 0;
|
|
}
|
|
|
|
static inline int mmu_notifier_test_young(struct mm_struct *mm,
|
|
unsigned long address)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
return __mmu_notifier_test_young(mm, address);
|
|
return 0;
|
|
}
|
|
|
|
static inline void mmu_notifier_change_pte(struct mm_struct *mm,
|
|
unsigned long address, pte_t pte)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
__mmu_notifier_change_pte(mm, address, pte);
|
|
}
|
|
|
|
static inline void
|
|
mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)
|
|
{
|
|
might_sleep();
|
|
|
|
lock_map_acquire(&__mmu_notifier_invalidate_range_start_map);
|
|
if (mm_has_notifiers(range->mm)) {
|
|
range->flags |= MMU_NOTIFIER_RANGE_BLOCKABLE;
|
|
__mmu_notifier_invalidate_range_start(range);
|
|
}
|
|
lock_map_release(&__mmu_notifier_invalidate_range_start_map);
|
|
}
|
|
|
|
static inline int
|
|
mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range)
|
|
{
|
|
int ret = 0;
|
|
|
|
lock_map_acquire(&__mmu_notifier_invalidate_range_start_map);
|
|
if (mm_has_notifiers(range->mm)) {
|
|
range->flags &= ~MMU_NOTIFIER_RANGE_BLOCKABLE;
|
|
ret = __mmu_notifier_invalidate_range_start(range);
|
|
}
|
|
lock_map_release(&__mmu_notifier_invalidate_range_start_map);
|
|
return ret;
|
|
}
|
|
|
|
static inline void
|
|
mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range)
|
|
{
|
|
if (mmu_notifier_range_blockable(range))
|
|
might_sleep();
|
|
|
|
if (mm_has_notifiers(range->mm))
|
|
__mmu_notifier_invalidate_range_end(range, false);
|
|
}
|
|
|
|
static inline void
|
|
mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range)
|
|
{
|
|
if (mm_has_notifiers(range->mm))
|
|
__mmu_notifier_invalidate_range_end(range, true);
|
|
}
|
|
|
|
static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
__mmu_notifier_invalidate_range(mm, start, end);
|
|
}
|
|
|
|
static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
|
|
{
|
|
mm->notifier_subscriptions = NULL;
|
|
}
|
|
|
|
static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
|
|
{
|
|
if (mm_has_notifiers(mm))
|
|
__mmu_notifier_subscriptions_destroy(mm);
|
|
}
|
|
|
|
|
|
static inline void mmu_notifier_range_init(struct mmu_notifier_range *range,
|
|
enum mmu_notifier_event event,
|
|
unsigned flags,
|
|
struct vm_area_struct *vma,
|
|
struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
range->vma = vma;
|
|
range->event = event;
|
|
range->mm = mm;
|
|
range->start = start;
|
|
range->end = end;
|
|
range->flags = flags;
|
|
}
|
|
|
|
static inline void mmu_notifier_range_init_migrate(
|
|
struct mmu_notifier_range *range, unsigned int flags,
|
|
struct vm_area_struct *vma, struct mm_struct *mm,
|
|
unsigned long start, unsigned long end, void *pgmap)
|
|
{
|
|
mmu_notifier_range_init(range, MMU_NOTIFY_MIGRATE, flags, vma, mm,
|
|
start, end);
|
|
range->migrate_pgmap_owner = pgmap;
|
|
}
|
|
|
|
#define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
|
|
({ \
|
|
int __young; \
|
|
struct vm_area_struct *___vma = __vma; \
|
|
unsigned long ___address = __address; \
|
|
__young = ptep_clear_flush_young(___vma, ___address, __ptep); \
|
|
__young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \
|
|
___address, \
|
|
___address + \
|
|
PAGE_SIZE); \
|
|
__young; \
|
|
})
|
|
|
|
#define pmdp_clear_flush_young_notify(__vma, __address, __pmdp) \
|
|
({ \
|
|
int __young; \
|
|
struct vm_area_struct *___vma = __vma; \
|
|
unsigned long ___address = __address; \
|
|
__young = pmdp_clear_flush_young(___vma, ___address, __pmdp); \
|
|
__young |= mmu_notifier_clear_flush_young(___vma->vm_mm, \
|
|
___address, \
|
|
___address + \
|
|
PMD_SIZE); \
|
|
__young; \
|
|
})
|
|
|
|
#define ptep_clear_young_notify(__vma, __address, __ptep) \
|
|
({ \
|
|
int __young; \
|
|
struct vm_area_struct *___vma = __vma; \
|
|
unsigned long ___address = __address; \
|
|
__young = ptep_test_and_clear_young(___vma, ___address, __ptep);\
|
|
__young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \
|
|
___address + PAGE_SIZE); \
|
|
__young; \
|
|
})
|
|
|
|
#define pmdp_clear_young_notify(__vma, __address, __pmdp) \
|
|
({ \
|
|
int __young; \
|
|
struct vm_area_struct *___vma = __vma; \
|
|
unsigned long ___address = __address; \
|
|
__young = pmdp_test_and_clear_young(___vma, ___address, __pmdp);\
|
|
__young |= mmu_notifier_clear_young(___vma->vm_mm, ___address, \
|
|
___address + PMD_SIZE); \
|
|
__young; \
|
|
})
|
|
|
|
#define ptep_clear_flush_notify(__vma, __address, __ptep) \
|
|
({ \
|
|
unsigned long ___addr = __address & PAGE_MASK; \
|
|
struct mm_struct *___mm = (__vma)->vm_mm; \
|
|
pte_t ___pte; \
|
|
\
|
|
___pte = ptep_clear_flush(__vma, __address, __ptep); \
|
|
mmu_notifier_invalidate_range(___mm, ___addr, \
|
|
___addr + PAGE_SIZE); \
|
|
\
|
|
___pte; \
|
|
})
|
|
|
|
#define pmdp_huge_clear_flush_notify(__vma, __haddr, __pmd) \
|
|
({ \
|
|
unsigned long ___haddr = __haddr & HPAGE_PMD_MASK; \
|
|
struct mm_struct *___mm = (__vma)->vm_mm; \
|
|
pmd_t ___pmd; \
|
|
\
|
|
___pmd = pmdp_huge_clear_flush(__vma, __haddr, __pmd); \
|
|
mmu_notifier_invalidate_range(___mm, ___haddr, \
|
|
___haddr + HPAGE_PMD_SIZE); \
|
|
\
|
|
___pmd; \
|
|
})
|
|
|
|
#define pudp_huge_clear_flush_notify(__vma, __haddr, __pud) \
|
|
({ \
|
|
unsigned long ___haddr = __haddr & HPAGE_PUD_MASK; \
|
|
struct mm_struct *___mm = (__vma)->vm_mm; \
|
|
pud_t ___pud; \
|
|
\
|
|
___pud = pudp_huge_clear_flush(__vma, __haddr, __pud); \
|
|
mmu_notifier_invalidate_range(___mm, ___haddr, \
|
|
___haddr + HPAGE_PUD_SIZE); \
|
|
\
|
|
___pud; \
|
|
})
|
|
|
|
/*
|
|
* set_pte_at_notify() sets the pte _after_ running the notifier.
|
|
* This is safe to start by updating the secondary MMUs, because the primary MMU
|
|
* pte invalidate must have already happened with a ptep_clear_flush() before
|
|
* set_pte_at_notify() has been invoked. Updating the secondary MMUs first is
|
|
* required when we change both the protection of the mapping from read-only to
|
|
* read-write and the pfn (like during copy on write page faults). Otherwise the
|
|
* old page would remain mapped readonly in the secondary MMUs after the new
|
|
* page is already writable by some CPU through the primary MMU.
|
|
*/
|
|
#define set_pte_at_notify(__mm, __address, __ptep, __pte) \
|
|
({ \
|
|
struct mm_struct *___mm = __mm; \
|
|
unsigned long ___address = __address; \
|
|
pte_t ___pte = __pte; \
|
|
\
|
|
mmu_notifier_change_pte(___mm, ___address, ___pte); \
|
|
set_pte_at(___mm, ___address, __ptep, ___pte); \
|
|
})
|
|
|
|
#else /* CONFIG_MMU_NOTIFIER */
|
|
|
|
struct mmu_notifier_range {
|
|
unsigned long start;
|
|
unsigned long end;
|
|
};
|
|
|
|
static inline void _mmu_notifier_range_init(struct mmu_notifier_range *range,
|
|
unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
range->start = start;
|
|
range->end = end;
|
|
}
|
|
|
|
#define mmu_notifier_range_init(range,event,flags,vma,mm,start,end) \
|
|
_mmu_notifier_range_init(range, start, end)
|
|
#define mmu_notifier_range_init_migrate(range, flags, vma, mm, start, end, \
|
|
pgmap) \
|
|
_mmu_notifier_range_init(range, start, end)
|
|
|
|
static inline bool
|
|
mmu_notifier_range_blockable(const struct mmu_notifier_range *range)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static inline int mm_has_notifiers(struct mm_struct *mm)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void mmu_notifier_release(struct mm_struct *mm)
|
|
{
|
|
}
|
|
|
|
static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
|
|
unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int mmu_notifier_test_young(struct mm_struct *mm,
|
|
unsigned long address)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void mmu_notifier_change_pte(struct mm_struct *mm,
|
|
unsigned long address, pte_t pte)
|
|
{
|
|
}
|
|
|
|
static inline void
|
|
mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range)
|
|
{
|
|
}
|
|
|
|
static inline int
|
|
mmu_notifier_invalidate_range_start_nonblock(struct mmu_notifier_range *range)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
void mmu_notifier_invalidate_range_end(struct mmu_notifier_range *range)
|
|
{
|
|
}
|
|
|
|
static inline void
|
|
mmu_notifier_invalidate_range_only_end(struct mmu_notifier_range *range)
|
|
{
|
|
}
|
|
|
|
static inline void mmu_notifier_invalidate_range(struct mm_struct *mm,
|
|
unsigned long start, unsigned long end)
|
|
{
|
|
}
|
|
|
|
static inline void mmu_notifier_subscriptions_init(struct mm_struct *mm)
|
|
{
|
|
}
|
|
|
|
static inline void mmu_notifier_subscriptions_destroy(struct mm_struct *mm)
|
|
{
|
|
}
|
|
|
|
#define mmu_notifier_range_update_to_read_only(r) false
|
|
|
|
#define ptep_clear_flush_young_notify ptep_clear_flush_young
|
|
#define pmdp_clear_flush_young_notify pmdp_clear_flush_young
|
|
#define ptep_clear_young_notify ptep_test_and_clear_young
|
|
#define pmdp_clear_young_notify pmdp_test_and_clear_young
|
|
#define ptep_clear_flush_notify ptep_clear_flush
|
|
#define pmdp_huge_clear_flush_notify pmdp_huge_clear_flush
|
|
#define pudp_huge_clear_flush_notify pudp_huge_clear_flush
|
|
#define set_pte_at_notify set_pte_at
|
|
|
|
static inline void mmu_notifier_synchronize(void)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_MMU_NOTIFIER */
|
|
|
|
#endif /* _LINUX_MMU_NOTIFIER_H */
|