mm-device-exclusive-memory-access.patch removed from -mm tree
The patch titled
Subject: mm: device exclusive memory access
has been removed from the -mm tree. Its filename was
mm-device-exclusive-memory-access.patch
This patch was dropped because it was merged into mainline or a subsystem tree
------------------------------------------------------
From: Alistair Popple <[email protected]>
Subject: mm: device exclusive memory access
Some devices require exclusive write access to shared virtual memory (SVM) ranges to perform atomic operations on that memory. This requires CPU page tables to be updated to deny access whilst atomic operations are occurring.
In order to do this introduce a new swap entry type (SWP_DEVICE_EXCLUSIVE). When a SVM range needs to be marked for exclusive access by a device all page table mappings for the particular range are replaced with device exclusive swap entries. This causes any CPU access to the page to result in a fault.
Faults are resovled by replacing the faulting entry with the original mapping. This results in MMU notifiers being called which a driver uses to update access permissions such as revoking atomic access. After notifiers have been called the device will no longer have exclusive access to the region.
Walking of the page tables to find the target pages is handled by get_user_pages() rather than a direct page table walk. A direct page table walk similar to what migrate_vma_collect()/unmap() does could also have been utilised. However this resulted in more code similar in functionality to what get_user_pages() provides as page faulting is required to make the PTEs present and to break COW.
---
Documentation/vm/hmm.rst | 17 +++ include/linux/mmu_notifier.h | 6 + include/linux/rmap.h | 4 include/linux/swap.h | 9 + include/linux/swapops.h | 44 +++++++ mm/hmm.c | 5 mm/memory.c | 127 +++++++++++++++++++++- mm/mprotect.c | 8 + mm/page_vma_mapped.c | 9 + mm/rmap.c | 186 +++++++++++++++++++++++++++++++++ 10 files changed, 405 insertions(+), 10 deletions(-)
Documentation/vm/hmm.rst renamed from Documentation/vm/hmm.rst~mm-device-exclusive-memory-access +17 -0
@@ -405,6 +405,23 @@ between device driver specific code and The lock can now be released. +Exclusive access memory +======================= + +Some devices have features such as atomic PTE bits that can be used to implement +atomic access to system memory. To support atomic operations to a shared virtual +memory page such a device needs access to that page which is exclusive of any +userspace access from the CPU. The ``make_device_exclusive_range()`` function +can be used to make a memory range inaccessible from userspace. + +This replaces all mappings for pages in the given range with special swap +entries. Any attempt to access the swap entry results in a fault which is +resovled by replacing the entry with the original mapping. A driver gets +notified that the mapping has been changed by MMU notifiers, after which point +it will no longer have exclusive access to the page. Exclusive access is +guranteed to last until the driver drops the page lock and page reference, at +which point any CPU faults on the page may proceed as described. + Memory cgroup (memcg) and rss accounting ========================================
include/linux/mmu_notifier.h renamed from include/linux/mmu_notifier.h~mm-device-exclusive-memory-access +6 -0
@@ -42,6 +42,11 @@ struct mmu_interval_notifier;* @MMU_NOTIFY_MIGRATE: used during migrate_vma_collect() invalidate to signal * a device driver to possibly ignore the invalidation if the * owner field matches the driver's device private pgmap owner. +* +* @MMU_NOTIFY_EXCLUSIVE: to signal a device driver that the device will no +* longer have exclusive access to the page. When sent during creation of an +* exclusive range the owner will be initialised to the value provided by the +* caller of make_device_exclusive_range(), otherwise the owner will be NULL. */ enum mmu_notifier_event {MMU_NOTIFY_UNMAP =0 ,
@@ -51,6 +56,7 @@ enum mmu_notifier_event {MMU_NOTIFY_SOFT_DIRTY ,MMU_NOTIFY_RELEASE ,MMU_NOTIFY_MIGRATE , + MMU_NOTIFY_EXCLUSIVE, };#define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0)
include/linux/rmap.h renamed from include/linux/rmap.h~mm-device-exclusive-memory-access +4 -0
@@ -194,6 +194,10 @@ int page_referenced(struct page *, int ivoid try_to_migrate (struct page *page,enum ttu_flags flags);void try_to_unmap (struct page *,enum ttu_flags flags); +int make_device_exclusive_range (struct mm_struct *mm,unsigned long start, +unsigned long end,struct page **pages, +void *arg); +/* Avoid racy checks */ #define PVMW_SYNC (1 << 0)/* Look for migarion entries rather than present PTEs */
include/linux/swap.h renamed from include/linux/swap.h~mm-device-exclusive-memory-access +7 -2
@@ -62,12 +62,17 @@ static inline int current_is_kswapd(void* migrate part of a process memory to device memory. * * When a page is migrated from CPU to device, we set the CPU page table entry -* to a special SWP_DEVICE_* entry. +* to a special SWP_DEVICE_{READ|WRITE} entry. +* +* When a page is mapped by the device for exclusive access we set the CPU page +* table entries to special SWP_DEVICE_EXCLUSIVE_* entries. */ #ifdef CONFIG_DEVICE_PRIVATE -#define SWP_DEVICE_NUM 2 +#define SWP_DEVICE_NUM 4#define SWP_DEVICE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM)#define SWP_DEVICE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+1) +#define SWP_DEVICE_EXCLUSIVE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2) +#define SWP_DEVICE_EXCLUSIVE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+3)#else #define SWP_DEVICE_NUM 0#endif
include/linux/swapops.h renamed from include/linux/swapops.h~mm-device-exclusive-memory-access +43 -1
62 lines not on this page · raw message
mm/hmm.c renamed from mm/hmm.c~mm-device-exclusive-memory-access +5 -0
@@ -26,6 +26,8 @@#include <linux/mmu_notifier.h> #include <linux/memory_hotplug.h> +#include "internal.h" +struct hmm_vma_walk {struct hmm_range *range;unsigned long last;
@@ -271,6 +273,9 @@ static int hmm_vma_handle_pte(struct mm_if (!non_swap_entry (entry)) goto fault; +if (is_device_exclusive_entry (entry)) + goto fault; +if (is_migration_entry (entry)) {pte_unmap (ptep); hmm_vma_walk->last = addr;
mm/memory.c renamed from mm/memory.c~mm-device-exclusive-memory-access +123 -4
176 lines not on this page · raw message
mm/mprotect.c renamed from mm/mprotect.c~mm-device-exclusive-memory-access +8 -0
@@ -165,6 +165,14 @@ static unsigned long change_pte_range(st newpte =swp_entry_to_pte (entry);if (pte_swp_uffd_wp (oldpte)) newpte =pte_swp_mkuffd_wp (newpte); + }else if (is_writable_device_exclusive_entry (entry)) { + entry =make_readable_device_exclusive_entry ( +swp_offset (entry)); + newpte =swp_entry_to_pte (entry); +if (pte_swp_soft_dirty (oldpte)) + newpte =pte_swp_mksoft_dirty (newpte); +if (pte_swp_uffd_wp (oldpte)) + newpte =pte_swp_mkuffd_wp (newpte); }else { newpte = oldpte; }
mm/page_vma_mapped.c renamed from mm/page_vma_mapped.c~mm-device-exclusive-memory-access +6 -3
@@ -41,7 +41,8 @@ static bool map_pte(struct page_vma_mapp/* Handle un-addressable ZONE_DEVICE memory */ entry =pte_to_swp_entry (*pvmw->pte); -if (!is_device_private_entry (entry)) +if (!is_device_private_entry (entry) && + !is_device_exclusive_entry (entry))return false; }else if (!pte_present (*pvmw->pte))return false;
@@ -93,7 +94,8 @@ static bool check_pte(struct page_vma_mareturn false; entry =pte_to_swp_entry (*pvmw->pte); -if (!is_migration_entry (entry)) +if (!is_migration_entry (entry) && + !is_device_exclusive_entry (entry))return false; pfn =swp_offset (entry);
@@ -102,7 +104,8 @@ static bool check_pte(struct page_vma_ma/* Handle un-addressable ZONE_DEVICE memory */ entry =pte_to_swp_entry (*pvmw->pte); -if (!is_device_private_entry (entry)) +if (!is_device_private_entry (entry) && + !is_device_exclusive_entry (entry))return false; pfn =swp_offset (entry);
mm/rmap.c renamed from mm/rmap.c~mm-device-exclusive-memory-access +186 -0
192 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are