Merge tag 'mm-stable-2025-05-31-14-50' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull MM updates from Andrew Morton: - "Add folio_mk_pte()" from Matthew Wilcox simplifies the act of creating a pte which addresses the first page in a folio and reduces the amount of plumbing which architecture must implement to provide this. - "Misc folio patches for 6.16" from Matthew Wilcox is a shower of largely unrelated folio infrastructure changes which clean things up and better prepare us for future work. - "memory,x86,acpi: hotplug memory alignment advisement" from Gregory Price adds early-init code to prevent x86 from leaving physical memory unused when physical address regions are not aligned to memory block size. - "mm/compaction: allow more aggressive proactive compaction" from Michal Clapinski provides some tuning of the (sadly, hard-coded (more sadly, not auto-tuned)) thresholds for our invokation of proactive compaction. In a simple test case, the reduction of a guest VM's memory consumption was dramatic. - "Minor cleanups and improvements to swap freeing code" from Kemeng Shi provides some code cleaups and a small efficiency improvement to this part of our swap handling code. - "ptrace: introduce PTRACE_SET_SYSCALL_INFO API" from Dmitry Levin adds the ability for a ptracer to modify syscalls arguments. At this time we can alter only "system call information that are used by strace system call tampering, namely, syscall number, syscall arguments, and syscall return value. This series should have been incorporated into mm.git's "non-MM" branch, but I goofed. - "fs/proc: extend the PAGEMAP_SCAN ioctl to report guard regions" from Andrei Vagin extends the info returned by the PAGEMAP_SCAN ioctl against /proc/pid/pagemap. This permits CRIU to more efficiently get at the info about guard regions. - "Fix parameter passed to page_mapcount_is_type()" from Gavin Shan implements that fix. No runtime effect is expected because validate_page_before_insert() happens to fix up this error. - "kernel/events/uprobes: uprobe_write_opcode() rewrite" from David Hildenbrand basically brings uprobe text poking into the current decade. Remove a bunch of hand-rolled implementation in favor of using more current facilities. - "mm/ptdump: Drop assumption that pxd_val() is u64" from Anshuman Khandual provides enhancements and generalizations to the pte dumping code. This might be needed when 128-bit Page Table Descriptors are enabled for ARM. - "Always call constructor for kernel page tables" from Kevin Brodsky ensures that the ctor/dtor is always called for kernel pgtables, as it already is for user pgtables. This permits the addition of more functionality such as "insert hooks to protect page tables". This change does result in various architectures performing unnecesary work, but this is fixed up where it is anticipated to occur. - "Rust support for mm_struct, vm_area_struct, and mmap" from Alice Ryhl adds plumbing to permit Rust access to core MM structures. - "fix incorrectly disallowed anonymous VMA merges" from Lorenzo Stoakes takes advantage of some VMA merging opportunities which we've been missing for 15 years. - "mm/madvise: batch tlb flushes for MADV_DONTNEED and MADV_FREE" from SeongJae Park optimizes process_madvise()'s TLB flushing. Instead of flushing each address range in the provided iovec, we batch the flushing across all the iovec entries. The syscall's cost was approximately halved with a microbenchmark which was designed to load this particular operation. - "Track node vacancy to reduce worst case allocation counts" from Sidhartha Kumar makes the maple tree smarter about its node preallocation. stress-ng mmap performance increased by single-digit percentages and the amount of unnecessarily preallocated memory was dramaticelly reduced. - "mm/gup: Minor fix, cleanup and improvements" from Baoquan He removes a few unnecessary things which Baoquan noted when reading the code. - ""Enhance sysfs handling for memory hotplug in weighted interleave" from Rakie Kim "enhances the weighted interleave policy in the memory management subsystem by improving sysfs handling, fixing memory leaks, and introducing dynamic sysfs updates for memory hotplug support". Fixes things on error paths which we are unlikely to hit. - "mm/damon: auto-tune DAMOS for NUMA setups including tiered memory" from SeongJae Park introduces new DAMOS quota goal metrics which eliminate the manual tuning which is required when utilizing DAMON for memory tiering. - "mm/vmalloc.c: code cleanup and improvements" from Baoquan He provides cleanups and small efficiency improvements which Baoquan found via code inspection. - "vmscan: enforce mems_effective during demotion" from Gregory Price changes reclaim to respect cpuset.mems_effective during demotion when possible. because presently, reclaim explicitly ignores cpuset.mems_effective when demoting, which may cause the cpuset settings to violated. This is useful for isolating workloads on a multi-tenant system from certain classes of memory more consistently. - "Clean up split_huge_pmd_locked() and remove unnecessary folio pointers" from Gavin Guo provides minor cleanups and efficiency gains in in the huge page splitting and migrating code. - "Use kmem_cache for memcg alloc" from Huan Yang creates a slab cache for `struct mem_cgroup', yielding improved memory utilization. - "add max arg to swappiness in memory.reclaim and lru_gen" from Zhongkun He adds a new "max" argument to the "swappiness=" argument for memory.reclaim MGLRU's lru_gen. This directs proactive reclaim to reclaim from only anon folios rather than file-backed folios. - "kexec: introduce Kexec HandOver (KHO)" from Mike Rapoport is the first step on the path to permitting the kernel to maintain existing VMs while replacing the host kernel via file-based kexec. At this time only memblock's reserve_mem is preserved. - "mm: Introduce for_each_valid_pfn()" from David Woodhouse provides and uses a smarter way of looping over a pfn range. By skipping ranges of invalid pfns. - "sched/numa: Skip VMA scanning on memory pinned to one NUMA node via cpuset.mems" from Libo Chen removes a lot of pointless VMA scanning when a task is pinned a single NUMA mode. Dramatic performance benefits were seen in some real world cases. - "JFS: Implement migrate_folio for jfs_metapage_aops" from Shivank Garg addresses a warning which occurs during memory compaction when using JFS. - "move all VMA allocation, freeing and duplication logic to mm" from Lorenzo Stoakes moves some VMA code from kernel/fork.c into the more appropriate mm/vma.c. - "mm, swap: clean up swap cache mapping helper" from Kairui Song provides code consolidation and cleanups related to the folio_index() function. - "mm/gup: Cleanup memfd_pin_folios()" from Vishal Moola does that. - "memcg: Fix test_memcg_min/low test failures" from Waiman Long addresses some bogus failures which are being reported by the test_memcontrol selftest. - "eliminate mmap() retry merge, add .mmap_prepare hook" from Lorenzo Stoakes commences the deprecation of file_operations.mmap() in favor of the new file_operations.mmap_prepare(). The latter is more restrictive and prevents drivers from messing with things in ways which, amongst other problems, may defeat VMA merging. - "memcg: decouple memcg and objcg stocks"" from Shakeel Butt decouples the per-cpu memcg charge cache from the objcg's one. This is a step along the way to making memcg and objcg charging NMI-safe, which is a BPF requirement. - "mm/damon: minor fixups and improvements for code, tests, and documents" from SeongJae Park is yet another batch of miscellaneous DAMON changes. Fix and improve minor problems in code, tests and documents. - "memcg: make memcg stats irq safe" from Shakeel Butt converts memcg stats to be irq safe. Another step along the way to making memcg charging and stats updates NMI-safe, a BPF requirement. - "Let unmap_hugepage_range() and several related functions take folio instead of page" from Fan Ni provides folio conversions in the hugetlb code. * tag 'mm-stable-2025-05-31-14-50' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (285 commits) mm: pcp: increase pcp->free_count threshold to trigger free_high mm/hugetlb: convert use of struct page to folio in __unmap_hugepage_range() mm/hugetlb: refactor __unmap_hugepage_range() to take folio instead of page mm/hugetlb: refactor unmap_hugepage_range() to take folio instead of page mm/hugetlb: pass folio instead of page to unmap_ref_private() memcg: objcg stock trylock without irq disabling memcg: no stock lock for cpu hot-unplug memcg: make __mod_memcg_lruvec_state re-entrant safe against irqs memcg: make count_memcg_events re-entrant safe against irqs memcg: make mod_memcg_state re-entrant safe against irqs memcg: move preempt disable to callers of memcg_rstat_updated memcg: memcg_rstat_updated re-entrant safe against irqs mm: khugepaged: decouple SHMEM and file folios' collapse selftests/eventfd: correct test name and improve messages alloc_tag: check mem_profiling_support in alloc_tag_init Docs/damon: update titles and brief introductions to explain DAMOS selftests/damon/_damon_sysfs: read tried regions directories in order mm/damon/tests/core-kunit: add a test for damos_set_filters_default_reject() mm/damon/paddr: remove unused variable, folio_list, in damon_pa_stat() mm/damon/sysfs-schemes: fix wrong comment on damons_sysfs_quota_goal_metric_strs ...
This commit is contained in:
@@ -95,6 +95,20 @@ config KEXEC_JUMP
|
||||
Jump between original kernel and kexeced kernel and invoke
|
||||
code in physical address mode via KEXEC
|
||||
|
||||
config KEXEC_HANDOVER
|
||||
bool "kexec handover"
|
||||
depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE
|
||||
select MEMBLOCK_KHO_SCRATCH
|
||||
select KEXEC_FILE
|
||||
select DEBUG_FS
|
||||
select LIBFDT
|
||||
select CMA
|
||||
help
|
||||
Allow kexec to hand over state across kernels by generating and
|
||||
passing additional metadata to the target kernel. This is useful
|
||||
to keep data or state alive across the kexec. For this to work,
|
||||
both source and target kernels need to have this option enabled.
|
||||
|
||||
config CRASH_DUMP
|
||||
bool "kernel crash dumps"
|
||||
default ARCH_DEFAULT_CRASH_DUMP
|
||||
|
||||
@@ -80,6 +80,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_core.o
|
||||
obj-$(CONFIG_KEXEC) += kexec.o
|
||||
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o
|
||||
obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o
|
||||
obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o
|
||||
obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
|
||||
obj-$(CONFIG_COMPAT) += compat.o
|
||||
obj-$(CONFIG_CGROUPS) += cgroup/
|
||||
|
||||
@@ -579,7 +579,7 @@ static bool can_alloc_pages(void)
|
||||
static struct page *__bpf_alloc_page(int nid)
|
||||
{
|
||||
if (!can_alloc_pages())
|
||||
return try_alloc_pages(nid, 0);
|
||||
return alloc_pages_nolock(nid, 0);
|
||||
|
||||
return alloc_pages_node(nid,
|
||||
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
|
||||
|
||||
+38
-2
@@ -4202,7 +4202,7 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs)
|
||||
}
|
||||
|
||||
/*
|
||||
* cpuset_node_allowed - Can we allocate on a memory node?
|
||||
* cpuset_current_node_allowed - Can current task allocate on a memory node?
|
||||
* @node: is this an allowed node?
|
||||
* @gfp_mask: memory allocation flags
|
||||
*
|
||||
@@ -4241,7 +4241,7 @@ static struct cpuset *nearest_hardwall_ancestor(struct cpuset *cs)
|
||||
* GFP_KERNEL - any node in enclosing hardwalled cpuset ok
|
||||
* GFP_USER - only nodes in current tasks mems allowed ok.
|
||||
*/
|
||||
bool cpuset_node_allowed(int node, gfp_t gfp_mask)
|
||||
bool cpuset_current_node_allowed(int node, gfp_t gfp_mask)
|
||||
{
|
||||
struct cpuset *cs; /* current cpuset ancestors */
|
||||
bool allowed; /* is allocation in zone z allowed? */
|
||||
@@ -4275,6 +4275,42 @@ bool cpuset_node_allowed(int node, gfp_t gfp_mask)
|
||||
return allowed;
|
||||
}
|
||||
|
||||
bool cpuset_node_allowed(struct cgroup *cgroup, int nid)
|
||||
{
|
||||
struct cgroup_subsys_state *css;
|
||||
struct cpuset *cs;
|
||||
bool allowed;
|
||||
|
||||
/*
|
||||
* In v1, mem_cgroup and cpuset are unlikely in the same hierarchy
|
||||
* and mems_allowed is likely to be empty even if we could get to it,
|
||||
* so return true to avoid taking a global lock on the empty check.
|
||||
*/
|
||||
if (!cpuset_v2())
|
||||
return true;
|
||||
|
||||
css = cgroup_get_e_css(cgroup, &cpuset_cgrp_subsys);
|
||||
if (!css)
|
||||
return true;
|
||||
|
||||
/*
|
||||
* Normally, accessing effective_mems would require the cpuset_mutex
|
||||
* or callback_lock - but node_isset is atomic and the reference
|
||||
* taken via cgroup_get_e_css is sufficient to protect css.
|
||||
*
|
||||
* Since this interface is intended for use by migration paths, we
|
||||
* relax locking here to avoid taking global locks - while accepting
|
||||
* there may be rare scenarios where the result may be innaccurate.
|
||||
*
|
||||
* Reclaim and migration are subject to these same race conditions, and
|
||||
* cannot make strong isolation guarantees, so this is acceptable.
|
||||
*/
|
||||
cs = container_of(css, struct cpuset, css);
|
||||
allowed = node_isset(nid, cs->effective_mems);
|
||||
css_put(css);
|
||||
return allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* cpuset_spread_node() - On which node to begin search for a page
|
||||
* @rotor: round robin rotor
|
||||
|
||||
+184
-177
@@ -29,6 +29,7 @@
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/srcu.h>
|
||||
#include <linux/oom.h> /* check_stable_address_space */
|
||||
#include <linux/pagewalk.h>
|
||||
|
||||
#include <linux/uprobes.h>
|
||||
|
||||
@@ -151,91 +152,6 @@ static loff_t vaddr_to_offset(struct vm_area_struct *vma, unsigned long vaddr)
|
||||
return ((loff_t)vma->vm_pgoff << PAGE_SHIFT) + (vaddr - vma->vm_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* __replace_page - replace page in vma by new page.
|
||||
* based on replace_page in mm/ksm.c
|
||||
*
|
||||
* @vma: vma that holds the pte pointing to page
|
||||
* @addr: address the old @page is mapped at
|
||||
* @old_page: the page we are replacing by new_page
|
||||
* @new_page: the modified page we replace page by
|
||||
*
|
||||
* If @new_page is NULL, only unmap @old_page.
|
||||
*
|
||||
* Returns 0 on success, negative error code otherwise.
|
||||
*/
|
||||
static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
|
||||
struct page *old_page, struct page *new_page)
|
||||
{
|
||||
struct folio *old_folio = page_folio(old_page);
|
||||
struct folio *new_folio;
|
||||
struct mm_struct *mm = vma->vm_mm;
|
||||
DEFINE_FOLIO_VMA_WALK(pvmw, old_folio, vma, addr, 0);
|
||||
int err;
|
||||
struct mmu_notifier_range range;
|
||||
pte_t pte;
|
||||
|
||||
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, addr,
|
||||
addr + PAGE_SIZE);
|
||||
|
||||
if (new_page) {
|
||||
new_folio = page_folio(new_page);
|
||||
err = mem_cgroup_charge(new_folio, vma->vm_mm, GFP_KERNEL);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* For folio_free_swap() below */
|
||||
folio_lock(old_folio);
|
||||
|
||||
mmu_notifier_invalidate_range_start(&range);
|
||||
err = -EAGAIN;
|
||||
if (!page_vma_mapped_walk(&pvmw))
|
||||
goto unlock;
|
||||
VM_BUG_ON_PAGE(addr != pvmw.address, old_page);
|
||||
pte = ptep_get(pvmw.pte);
|
||||
|
||||
/*
|
||||
* Handle PFN swap PTES, such as device-exclusive ones, that actually
|
||||
* map pages: simply trigger GUP again to fix it up.
|
||||
*/
|
||||
if (unlikely(!pte_present(pte))) {
|
||||
page_vma_mapped_walk_done(&pvmw);
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
if (new_page) {
|
||||
folio_get(new_folio);
|
||||
folio_add_new_anon_rmap(new_folio, vma, addr, RMAP_EXCLUSIVE);
|
||||
folio_add_lru_vma(new_folio, vma);
|
||||
} else
|
||||
/* no new page, just dec_mm_counter for old_page */
|
||||
dec_mm_counter(mm, MM_ANONPAGES);
|
||||
|
||||
if (!folio_test_anon(old_folio)) {
|
||||
dec_mm_counter(mm, mm_counter_file(old_folio));
|
||||
inc_mm_counter(mm, MM_ANONPAGES);
|
||||
}
|
||||
|
||||
flush_cache_page(vma, addr, pte_pfn(pte));
|
||||
ptep_clear_flush(vma, addr, pvmw.pte);
|
||||
if (new_page)
|
||||
set_pte_at(mm, addr, pvmw.pte,
|
||||
mk_pte(new_page, vma->vm_page_prot));
|
||||
|
||||
folio_remove_rmap_pte(old_folio, old_page, vma);
|
||||
if (!folio_mapped(old_folio))
|
||||
folio_free_swap(old_folio);
|
||||
page_vma_mapped_walk_done(&pvmw);
|
||||
folio_put(old_folio);
|
||||
|
||||
err = 0;
|
||||
unlock:
|
||||
mmu_notifier_invalidate_range_end(&range);
|
||||
folio_unlock(old_folio);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* is_swbp_insn - check if instruction is breakpoint instruction.
|
||||
* @insn: instruction to be checked.
|
||||
@@ -463,6 +379,95 @@ static int update_ref_ctr(struct uprobe *uprobe, struct mm_struct *mm,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool orig_page_is_identical(struct vm_area_struct *vma,
|
||||
unsigned long vaddr, struct page *page, bool *pmd_mappable)
|
||||
{
|
||||
const pgoff_t index = vaddr_to_offset(vma, vaddr) >> PAGE_SHIFT;
|
||||
struct folio *orig_folio = filemap_get_folio(vma->vm_file->f_mapping,
|
||||
index);
|
||||
struct page *orig_page;
|
||||
bool identical;
|
||||
|
||||
if (IS_ERR(orig_folio))
|
||||
return false;
|
||||
orig_page = folio_file_page(orig_folio, index);
|
||||
|
||||
*pmd_mappable = folio_test_pmd_mappable(orig_folio);
|
||||
identical = folio_test_uptodate(orig_folio) &&
|
||||
pages_identical(page, orig_page);
|
||||
folio_put(orig_folio);
|
||||
return identical;
|
||||
}
|
||||
|
||||
static int __uprobe_write_opcode(struct vm_area_struct *vma,
|
||||
struct folio_walk *fw, struct folio *folio,
|
||||
unsigned long opcode_vaddr, uprobe_opcode_t opcode)
|
||||
{
|
||||
const unsigned long vaddr = opcode_vaddr & PAGE_MASK;
|
||||
const bool is_register = !!is_swbp_insn(&opcode);
|
||||
bool pmd_mappable;
|
||||
|
||||
/* For now, we'll only handle PTE-mapped folios. */
|
||||
if (fw->level != FW_LEVEL_PTE)
|
||||
return -EFAULT;
|
||||
|
||||
/*
|
||||
* See can_follow_write_pte(): we'd actually prefer a writable PTE here,
|
||||
* but the VMA might not be writable.
|
||||
*/
|
||||
if (!pte_write(fw->pte)) {
|
||||
if (!PageAnonExclusive(fw->page))
|
||||
return -EFAULT;
|
||||
if (unlikely(userfaultfd_pte_wp(vma, fw->pte)))
|
||||
return -EFAULT;
|
||||
/* SOFTDIRTY is handled via pte_mkdirty() below. */
|
||||
}
|
||||
|
||||
/*
|
||||
* We'll temporarily unmap the page and flush the TLB, such that we can
|
||||
* modify the page atomically.
|
||||
*/
|
||||
flush_cache_page(vma, vaddr, pte_pfn(fw->pte));
|
||||
fw->pte = ptep_clear_flush(vma, vaddr, fw->ptep);
|
||||
copy_to_page(fw->page, opcode_vaddr, &opcode, UPROBE_SWBP_INSN_SIZE);
|
||||
|
||||
/*
|
||||
* When unregistering, we may only zap a PTE if uffd is disabled and
|
||||
* there are no unexpected folio references ...
|
||||
*/
|
||||
if (is_register || userfaultfd_missing(vma) ||
|
||||
(folio_ref_count(folio) != folio_mapcount(folio) + 1 +
|
||||
folio_test_swapcache(folio) * folio_nr_pages(folio)))
|
||||
goto remap;
|
||||
|
||||
/*
|
||||
* ... and the mapped page is identical to the original page that
|
||||
* would get faulted in on next access.
|
||||
*/
|
||||
if (!orig_page_is_identical(vma, vaddr, fw->page, &pmd_mappable))
|
||||
goto remap;
|
||||
|
||||
dec_mm_counter(vma->vm_mm, MM_ANONPAGES);
|
||||
folio_remove_rmap_pte(folio, fw->page, vma);
|
||||
if (!folio_mapped(folio) && folio_test_swapcache(folio) &&
|
||||
folio_trylock(folio)) {
|
||||
folio_free_swap(folio);
|
||||
folio_unlock(folio);
|
||||
}
|
||||
folio_put(folio);
|
||||
|
||||
return pmd_mappable;
|
||||
remap:
|
||||
/*
|
||||
* Make sure that our copy_to_page() changes become visible before the
|
||||
* set_pte_at() write.
|
||||
*/
|
||||
smp_wmb();
|
||||
/* We modified the page. Make sure to mark the PTE dirty. */
|
||||
set_pte_at(vma->vm_mm, vaddr, fw->ptep, pte_mkdirty(fw->pte));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE:
|
||||
* Expect the breakpoint instruction to be the smallest size instruction for
|
||||
@@ -474,146 +479,146 @@ static int update_ref_ctr(struct uprobe *uprobe, struct mm_struct *mm,
|
||||
*
|
||||
* uprobe_write_opcode - write the opcode at a given virtual address.
|
||||
* @auprobe: arch specific probepoint information.
|
||||
* @mm: the probed process address space.
|
||||
* @vaddr: the virtual address to store the opcode.
|
||||
* @opcode: opcode to be written at @vaddr.
|
||||
* @vma: the probed virtual memory area.
|
||||
* @opcode_vaddr: the virtual address to store the opcode.
|
||||
* @opcode: opcode to be written at @opcode_vaddr.
|
||||
*
|
||||
* Called with mm->mmap_lock held for read or write.
|
||||
* Return 0 (success) or a negative errno.
|
||||
*/
|
||||
int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
|
||||
unsigned long vaddr, uprobe_opcode_t opcode)
|
||||
int uprobe_write_opcode(struct arch_uprobe *auprobe, struct vm_area_struct *vma,
|
||||
const unsigned long opcode_vaddr, uprobe_opcode_t opcode)
|
||||
{
|
||||
const unsigned long vaddr = opcode_vaddr & PAGE_MASK;
|
||||
struct mm_struct *mm = vma->vm_mm;
|
||||
struct uprobe *uprobe;
|
||||
struct page *old_page, *new_page;
|
||||
struct vm_area_struct *vma;
|
||||
int ret, is_register, ref_ctr_updated = 0;
|
||||
bool orig_page_huge = false;
|
||||
unsigned int gup_flags = FOLL_FORCE;
|
||||
struct mmu_notifier_range range;
|
||||
struct folio_walk fw;
|
||||
struct folio *folio;
|
||||
struct page *page;
|
||||
|
||||
is_register = is_swbp_insn(&opcode);
|
||||
uprobe = container_of(auprobe, struct uprobe, arch);
|
||||
|
||||
retry:
|
||||
if (WARN_ON_ONCE(!is_cow_mapping(vma->vm_flags)))
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* When registering, we have to break COW to get an exclusive anonymous
|
||||
* page that we can safely modify. Use FOLL_WRITE to trigger a write
|
||||
* fault if required. When unregistering, we might be lucky and the
|
||||
* anon page is already gone. So defer write faults until really
|
||||
* required. Use FOLL_SPLIT_PMD, because __uprobe_write_opcode()
|
||||
* cannot deal with PMDs yet.
|
||||
*/
|
||||
if (is_register)
|
||||
gup_flags |= FOLL_SPLIT_PMD;
|
||||
/* Read the page with vaddr into memory */
|
||||
old_page = get_user_page_vma_remote(mm, vaddr, gup_flags, &vma);
|
||||
if (IS_ERR(old_page))
|
||||
return PTR_ERR(old_page);
|
||||
gup_flags |= FOLL_WRITE | FOLL_SPLIT_PMD;
|
||||
|
||||
ret = verify_opcode(old_page, vaddr, &opcode);
|
||||
retry:
|
||||
ret = get_user_pages_remote(mm, vaddr, 1, gup_flags, &page, NULL);
|
||||
if (ret <= 0)
|
||||
goto put_old;
|
||||
goto out;
|
||||
folio = page_folio(page);
|
||||
|
||||
if (is_zero_page(old_page)) {
|
||||
ret = -EINVAL;
|
||||
goto put_old;
|
||||
}
|
||||
|
||||
if (WARN(!is_register && PageCompound(old_page),
|
||||
"uprobe unregister should never work on compound page\n")) {
|
||||
ret = -EINVAL;
|
||||
goto put_old;
|
||||
ret = verify_opcode(page, opcode_vaddr, &opcode);
|
||||
if (ret <= 0) {
|
||||
folio_put(folio);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* We are going to replace instruction, update ref_ctr. */
|
||||
if (!ref_ctr_updated && uprobe->ref_ctr_offset) {
|
||||
ret = update_ref_ctr(uprobe, mm, is_register ? 1 : -1);
|
||||
if (ret)
|
||||
goto put_old;
|
||||
if (ret) {
|
||||
folio_put(folio);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ref_ctr_updated = 1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
if (!is_register && !PageAnon(old_page))
|
||||
goto put_old;
|
||||
|
||||
ret = anon_vma_prepare(vma);
|
||||
if (ret)
|
||||
goto put_old;
|
||||
|
||||
ret = -ENOMEM;
|
||||
new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vaddr);
|
||||
if (!new_page)
|
||||
goto put_old;
|
||||
|
||||
__SetPageUptodate(new_page);
|
||||
copy_highpage(new_page, old_page);
|
||||
copy_to_page(new_page, vaddr, &opcode, UPROBE_SWBP_INSN_SIZE);
|
||||
|
||||
if (!is_register) {
|
||||
struct page *orig_page;
|
||||
pgoff_t index;
|
||||
|
||||
VM_BUG_ON_PAGE(!PageAnon(old_page), old_page);
|
||||
|
||||
index = vaddr_to_offset(vma, vaddr & PAGE_MASK) >> PAGE_SHIFT;
|
||||
orig_page = find_get_page(vma->vm_file->f_inode->i_mapping,
|
||||
index);
|
||||
|
||||
if (orig_page) {
|
||||
if (PageUptodate(orig_page) &&
|
||||
pages_identical(new_page, orig_page)) {
|
||||
/* let go new_page */
|
||||
put_page(new_page);
|
||||
new_page = NULL;
|
||||
|
||||
if (PageCompound(orig_page))
|
||||
orig_page_huge = true;
|
||||
}
|
||||
put_page(orig_page);
|
||||
}
|
||||
if (unlikely(!folio_test_anon(folio))) {
|
||||
VM_WARN_ON_ONCE(is_register);
|
||||
folio_put(folio);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = __replace_page(vma, vaddr & PAGE_MASK, old_page, new_page);
|
||||
if (new_page)
|
||||
put_page(new_page);
|
||||
put_old:
|
||||
put_page(old_page);
|
||||
if (!is_register) {
|
||||
/*
|
||||
* In the common case, we'll be able to zap the page when
|
||||
* unregistering. So trigger MMU notifiers now, as we won't
|
||||
* be able to do it under PTL.
|
||||
*/
|
||||
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm,
|
||||
vaddr, vaddr + PAGE_SIZE);
|
||||
mmu_notifier_invalidate_range_start(&range);
|
||||
}
|
||||
|
||||
if (unlikely(ret == -EAGAIN))
|
||||
ret = -EAGAIN;
|
||||
/* Walk the page tables again, to perform the actual update. */
|
||||
if (folio_walk_start(&fw, vma, vaddr, 0)) {
|
||||
if (fw.page == page)
|
||||
ret = __uprobe_write_opcode(vma, &fw, folio, opcode_vaddr, opcode);
|
||||
folio_walk_end(&fw, vma);
|
||||
}
|
||||
|
||||
if (!is_register)
|
||||
mmu_notifier_invalidate_range_end(&range);
|
||||
|
||||
folio_put(folio);
|
||||
switch (ret) {
|
||||
case -EFAULT:
|
||||
gup_flags |= FOLL_WRITE | FOLL_SPLIT_PMD;
|
||||
fallthrough;
|
||||
case -EAGAIN:
|
||||
goto retry;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
/* Revert back reference counter if instruction update failed. */
|
||||
if (ret && is_register && ref_ctr_updated)
|
||||
if (ret < 0 && is_register && ref_ctr_updated)
|
||||
update_ref_ctr(uprobe, mm, -1);
|
||||
|
||||
/* try collapse pmd for compound page */
|
||||
if (!ret && orig_page_huge)
|
||||
if (ret > 0)
|
||||
collapse_pte_mapped_thp(mm, vaddr, false);
|
||||
|
||||
return ret;
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* set_swbp - store breakpoint at a given address.
|
||||
* @auprobe: arch specific probepoint information.
|
||||
* @mm: the probed process address space.
|
||||
* @vma: the probed virtual memory area.
|
||||
* @vaddr: the virtual address to insert the opcode.
|
||||
*
|
||||
* For mm @mm, store the breakpoint instruction at @vaddr.
|
||||
* Return 0 (success) or a negative errno.
|
||||
*/
|
||||
int __weak set_swbp(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
|
||||
int __weak set_swbp(struct arch_uprobe *auprobe, struct vm_area_struct *vma,
|
||||
unsigned long vaddr)
|
||||
{
|
||||
return uprobe_write_opcode(auprobe, mm, vaddr, UPROBE_SWBP_INSN);
|
||||
return uprobe_write_opcode(auprobe, vma, vaddr, UPROBE_SWBP_INSN);
|
||||
}
|
||||
|
||||
/**
|
||||
* set_orig_insn - Restore the original instruction.
|
||||
* @mm: the probed process address space.
|
||||
* @vma: the probed virtual memory area.
|
||||
* @auprobe: arch specific probepoint information.
|
||||
* @vaddr: the virtual address to insert the opcode.
|
||||
*
|
||||
* For mm @mm, restore the original opcode (opcode) at @vaddr.
|
||||
* Return 0 (success) or a negative errno.
|
||||
*/
|
||||
int __weak
|
||||
set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr)
|
||||
int __weak set_orig_insn(struct arch_uprobe *auprobe,
|
||||
struct vm_area_struct *vma, unsigned long vaddr)
|
||||
{
|
||||
return uprobe_write_opcode(auprobe, mm, vaddr,
|
||||
return uprobe_write_opcode(auprobe, vma, vaddr,
|
||||
*(uprobe_opcode_t *)&auprobe->insn);
|
||||
}
|
||||
|
||||
@@ -1134,10 +1139,10 @@ static bool filter_chain(struct uprobe *uprobe, struct mm_struct *mm)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
|
||||
struct vm_area_struct *vma, unsigned long vaddr)
|
||||
static int install_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma,
|
||||
unsigned long vaddr)
|
||||
{
|
||||
struct mm_struct *mm = vma->vm_mm;
|
||||
bool first_uprobe;
|
||||
int ret;
|
||||
|
||||
@@ -1153,7 +1158,7 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
|
||||
if (first_uprobe)
|
||||
set_bit(MMF_HAS_UPROBES, &mm->flags);
|
||||
|
||||
ret = set_swbp(&uprobe->arch, mm, vaddr);
|
||||
ret = set_swbp(&uprobe->arch, vma, vaddr);
|
||||
if (!ret)
|
||||
clear_bit(MMF_RECALC_UPROBES, &mm->flags);
|
||||
else if (first_uprobe)
|
||||
@@ -1162,11 +1167,13 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
remove_breakpoint(struct uprobe *uprobe, struct mm_struct *mm, unsigned long vaddr)
|
||||
static int remove_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma,
|
||||
unsigned long vaddr)
|
||||
{
|
||||
struct mm_struct *mm = vma->vm_mm;
|
||||
|
||||
set_bit(MMF_RECALC_UPROBES, &mm->flags);
|
||||
return set_orig_insn(&uprobe->arch, mm, vaddr);
|
||||
return set_orig_insn(&uprobe->arch, vma, vaddr);
|
||||
}
|
||||
|
||||
struct map_info {
|
||||
@@ -1296,10 +1303,10 @@ register_for_each_vma(struct uprobe *uprobe, struct uprobe_consumer *new)
|
||||
if (is_register) {
|
||||
/* consult only the "caller", new consumer. */
|
||||
if (consumer_filter(new, mm))
|
||||
err = install_breakpoint(uprobe, mm, vma, info->vaddr);
|
||||
err = install_breakpoint(uprobe, vma, info->vaddr);
|
||||
} else if (test_bit(MMF_HAS_UPROBES, &mm->flags)) {
|
||||
if (!filter_chain(uprobe, mm))
|
||||
err |= remove_breakpoint(uprobe, mm, info->vaddr);
|
||||
err |= remove_breakpoint(uprobe, vma, info->vaddr);
|
||||
}
|
||||
|
||||
unlock:
|
||||
@@ -1472,7 +1479,7 @@ static int unapply_uprobe(struct uprobe *uprobe, struct mm_struct *mm)
|
||||
continue;
|
||||
|
||||
vaddr = offset_to_vaddr(vma, uprobe->offset);
|
||||
err |= remove_breakpoint(uprobe, mm, vaddr);
|
||||
err |= remove_breakpoint(uprobe, vma, vaddr);
|
||||
}
|
||||
mmap_read_unlock(mm);
|
||||
|
||||
@@ -1610,7 +1617,7 @@ int uprobe_mmap(struct vm_area_struct *vma)
|
||||
if (!fatal_signal_pending(current) &&
|
||||
filter_chain(uprobe, vma->vm_mm)) {
|
||||
unsigned long vaddr = offset_to_vaddr(vma, uprobe->offset);
|
||||
install_breakpoint(uprobe, vma->vm_mm, vma, vaddr);
|
||||
install_breakpoint(uprobe, vma, vaddr);
|
||||
}
|
||||
put_uprobe(uprobe);
|
||||
}
|
||||
|
||||
+4
-273
@@ -112,6 +112,9 @@
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/tlbflush.h>
|
||||
|
||||
/* For dup_mmap(). */
|
||||
#include "../mm/internal.h"
|
||||
|
||||
#include <trace/events/sched.h>
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
@@ -428,88 +431,9 @@ struct kmem_cache *files_cachep;
|
||||
/* SLAB cache for fs_struct structures (tsk->fs) */
|
||||
struct kmem_cache *fs_cachep;
|
||||
|
||||
/* SLAB cache for vm_area_struct structures */
|
||||
static struct kmem_cache *vm_area_cachep;
|
||||
|
||||
/* SLAB cache for mm_struct structures (tsk->mm) */
|
||||
static struct kmem_cache *mm_cachep;
|
||||
|
||||
struct vm_area_struct *vm_area_alloc(struct mm_struct *mm)
|
||||
{
|
||||
struct vm_area_struct *vma;
|
||||
|
||||
vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
|
||||
if (!vma)
|
||||
return NULL;
|
||||
|
||||
vma_init(vma, mm);
|
||||
|
||||
return vma;
|
||||
}
|
||||
|
||||
static void vm_area_init_from(const struct vm_area_struct *src,
|
||||
struct vm_area_struct *dest)
|
||||
{
|
||||
dest->vm_mm = src->vm_mm;
|
||||
dest->vm_ops = src->vm_ops;
|
||||
dest->vm_start = src->vm_start;
|
||||
dest->vm_end = src->vm_end;
|
||||
dest->anon_vma = src->anon_vma;
|
||||
dest->vm_pgoff = src->vm_pgoff;
|
||||
dest->vm_file = src->vm_file;
|
||||
dest->vm_private_data = src->vm_private_data;
|
||||
vm_flags_init(dest, src->vm_flags);
|
||||
memcpy(&dest->vm_page_prot, &src->vm_page_prot,
|
||||
sizeof(dest->vm_page_prot));
|
||||
/*
|
||||
* src->shared.rb may be modified concurrently when called from
|
||||
* dup_mmap(), but the clone will reinitialize it.
|
||||
*/
|
||||
data_race(memcpy(&dest->shared, &src->shared, sizeof(dest->shared)));
|
||||
memcpy(&dest->vm_userfaultfd_ctx, &src->vm_userfaultfd_ctx,
|
||||
sizeof(dest->vm_userfaultfd_ctx));
|
||||
#ifdef CONFIG_ANON_VMA_NAME
|
||||
dest->anon_name = src->anon_name;
|
||||
#endif
|
||||
#ifdef CONFIG_SWAP
|
||||
memcpy(&dest->swap_readahead_info, &src->swap_readahead_info,
|
||||
sizeof(dest->swap_readahead_info));
|
||||
#endif
|
||||
#ifndef CONFIG_MMU
|
||||
dest->vm_region = src->vm_region;
|
||||
#endif
|
||||
#ifdef CONFIG_NUMA
|
||||
dest->vm_policy = src->vm_policy;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
|
||||
{
|
||||
struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
|
||||
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
ASSERT_EXCLUSIVE_WRITER(orig->vm_flags);
|
||||
ASSERT_EXCLUSIVE_WRITER(orig->vm_file);
|
||||
vm_area_init_from(orig, new);
|
||||
vma_lock_init(new, true);
|
||||
INIT_LIST_HEAD(&new->anon_vma_chain);
|
||||
vma_numab_state_init(new);
|
||||
dup_anon_vma_name(orig, new);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
void vm_area_free(struct vm_area_struct *vma)
|
||||
{
|
||||
/* The vma should be detached while being destroyed. */
|
||||
vma_assert_detached(vma);
|
||||
vma_numab_state_free(vma);
|
||||
free_anon_vma_name(vma);
|
||||
kmem_cache_free(vm_area_cachep, vma);
|
||||
}
|
||||
|
||||
static void account_kernel_stack(struct task_struct *tsk, int account)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_VMAP_STACK)) {
|
||||
@@ -589,7 +513,7 @@ void free_task(struct task_struct *tsk)
|
||||
}
|
||||
EXPORT_SYMBOL(free_task);
|
||||
|
||||
static void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||
void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||
{
|
||||
struct file *exe_file;
|
||||
|
||||
@@ -604,183 +528,6 @@ static void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
static __latent_entropy int dup_mmap(struct mm_struct *mm,
|
||||
struct mm_struct *oldmm)
|
||||
{
|
||||
struct vm_area_struct *mpnt, *tmp;
|
||||
int retval;
|
||||
unsigned long charge = 0;
|
||||
LIST_HEAD(uf);
|
||||
VMA_ITERATOR(vmi, mm, 0);
|
||||
|
||||
if (mmap_write_lock_killable(oldmm))
|
||||
return -EINTR;
|
||||
flush_cache_dup_mm(oldmm);
|
||||
uprobe_dup_mmap(oldmm, mm);
|
||||
/*
|
||||
* Not linked in yet - no deadlock potential:
|
||||
*/
|
||||
mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING);
|
||||
|
||||
/* No ordering required: file already has been exposed. */
|
||||
dup_mm_exe_file(mm, oldmm);
|
||||
|
||||
mm->total_vm = oldmm->total_vm;
|
||||
mm->data_vm = oldmm->data_vm;
|
||||
mm->exec_vm = oldmm->exec_vm;
|
||||
mm->stack_vm = oldmm->stack_vm;
|
||||
|
||||
/* Use __mt_dup() to efficiently build an identical maple tree. */
|
||||
retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL);
|
||||
if (unlikely(retval))
|
||||
goto out;
|
||||
|
||||
mt_clear_in_rcu(vmi.mas.tree);
|
||||
for_each_vma(vmi, mpnt) {
|
||||
struct file *file;
|
||||
|
||||
vma_start_write(mpnt);
|
||||
if (mpnt->vm_flags & VM_DONTCOPY) {
|
||||
retval = vma_iter_clear_gfp(&vmi, mpnt->vm_start,
|
||||
mpnt->vm_end, GFP_KERNEL);
|
||||
if (retval)
|
||||
goto loop_out;
|
||||
|
||||
vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt));
|
||||
continue;
|
||||
}
|
||||
charge = 0;
|
||||
/*
|
||||
* Don't duplicate many vmas if we've been oom-killed (for
|
||||
* example)
|
||||
*/
|
||||
if (fatal_signal_pending(current)) {
|
||||
retval = -EINTR;
|
||||
goto loop_out;
|
||||
}
|
||||
if (mpnt->vm_flags & VM_ACCOUNT) {
|
||||
unsigned long len = vma_pages(mpnt);
|
||||
|
||||
if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
|
||||
goto fail_nomem;
|
||||
charge = len;
|
||||
}
|
||||
tmp = vm_area_dup(mpnt);
|
||||
if (!tmp)
|
||||
goto fail_nomem;
|
||||
|
||||
/* track_pfn_copy() will later take care of copying internal state. */
|
||||
if (unlikely(tmp->vm_flags & VM_PFNMAP))
|
||||
untrack_pfn_clear(tmp);
|
||||
|
||||
retval = vma_dup_policy(mpnt, tmp);
|
||||
if (retval)
|
||||
goto fail_nomem_policy;
|
||||
tmp->vm_mm = mm;
|
||||
retval = dup_userfaultfd(tmp, &uf);
|
||||
if (retval)
|
||||
goto fail_nomem_anon_vma_fork;
|
||||
if (tmp->vm_flags & VM_WIPEONFORK) {
|
||||
/*
|
||||
* VM_WIPEONFORK gets a clean slate in the child.
|
||||
* Don't prepare anon_vma until fault since we don't
|
||||
* copy page for current vma.
|
||||
*/
|
||||
tmp->anon_vma = NULL;
|
||||
} else if (anon_vma_fork(tmp, mpnt))
|
||||
goto fail_nomem_anon_vma_fork;
|
||||
vm_flags_clear(tmp, VM_LOCKED_MASK);
|
||||
/*
|
||||
* Copy/update hugetlb private vma information.
|
||||
*/
|
||||
if (is_vm_hugetlb_page(tmp))
|
||||
hugetlb_dup_vma_private(tmp);
|
||||
|
||||
/*
|
||||
* Link the vma into the MT. After using __mt_dup(), memory
|
||||
* allocation is not necessary here, so it cannot fail.
|
||||
*/
|
||||
vma_iter_bulk_store(&vmi, tmp);
|
||||
|
||||
mm->map_count++;
|
||||
|
||||
if (tmp->vm_ops && tmp->vm_ops->open)
|
||||
tmp->vm_ops->open(tmp);
|
||||
|
||||
file = tmp->vm_file;
|
||||
if (file) {
|
||||
struct address_space *mapping = file->f_mapping;
|
||||
|
||||
get_file(file);
|
||||
i_mmap_lock_write(mapping);
|
||||
if (vma_is_shared_maywrite(tmp))
|
||||
mapping_allow_writable(mapping);
|
||||
flush_dcache_mmap_lock(mapping);
|
||||
/* insert tmp into the share list, just after mpnt */
|
||||
vma_interval_tree_insert_after(tmp, mpnt,
|
||||
&mapping->i_mmap);
|
||||
flush_dcache_mmap_unlock(mapping);
|
||||
i_mmap_unlock_write(mapping);
|
||||
}
|
||||
|
||||
if (!(tmp->vm_flags & VM_WIPEONFORK))
|
||||
retval = copy_page_range(tmp, mpnt);
|
||||
|
||||
if (retval) {
|
||||
mpnt = vma_next(&vmi);
|
||||
goto loop_out;
|
||||
}
|
||||
}
|
||||
/* a new mm has just been created */
|
||||
retval = arch_dup_mmap(oldmm, mm);
|
||||
loop_out:
|
||||
vma_iter_free(&vmi);
|
||||
if (!retval) {
|
||||
mt_set_in_rcu(vmi.mas.tree);
|
||||
ksm_fork(mm, oldmm);
|
||||
khugepaged_fork(mm, oldmm);
|
||||
} else {
|
||||
|
||||
/*
|
||||
* The entire maple tree has already been duplicated. If the
|
||||
* mmap duplication fails, mark the failure point with
|
||||
* XA_ZERO_ENTRY. In exit_mmap(), if this marker is encountered,
|
||||
* stop releasing VMAs that have not been duplicated after this
|
||||
* point.
|
||||
*/
|
||||
if (mpnt) {
|
||||
mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1);
|
||||
mas_store(&vmi.mas, XA_ZERO_ENTRY);
|
||||
/* Avoid OOM iterating a broken tree */
|
||||
set_bit(MMF_OOM_SKIP, &mm->flags);
|
||||
}
|
||||
/*
|
||||
* The mm_struct is going to exit, but the locks will be dropped
|
||||
* first. Set the mm_struct as unstable is advisable as it is
|
||||
* not fully initialised.
|
||||
*/
|
||||
set_bit(MMF_UNSTABLE, &mm->flags);
|
||||
}
|
||||
out:
|
||||
mmap_write_unlock(mm);
|
||||
flush_tlb_mm(oldmm);
|
||||
mmap_write_unlock(oldmm);
|
||||
if (!retval)
|
||||
dup_userfaultfd_complete(&uf);
|
||||
else
|
||||
dup_userfaultfd_fail(&uf);
|
||||
return retval;
|
||||
|
||||
fail_nomem_anon_vma_fork:
|
||||
mpol_put(vma_policy(tmp));
|
||||
fail_nomem_policy:
|
||||
vm_area_free(tmp);
|
||||
fail_nomem:
|
||||
retval = -ENOMEM;
|
||||
vm_unacct_memory(charge);
|
||||
goto loop_out;
|
||||
}
|
||||
|
||||
static inline int mm_alloc_pgd(struct mm_struct *mm)
|
||||
{
|
||||
mm->pgd = pgd_alloc(mm);
|
||||
@@ -794,13 +541,6 @@ static inline void mm_free_pgd(struct mm_struct *mm)
|
||||
pgd_free(mm, mm->pgd);
|
||||
}
|
||||
#else
|
||||
static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
|
||||
{
|
||||
mmap_write_lock(oldmm);
|
||||
dup_mm_exe_file(mm, oldmm);
|
||||
mmap_write_unlock(oldmm);
|
||||
return 0;
|
||||
}
|
||||
#define mm_alloc_pgd(mm) (0)
|
||||
#define mm_free_pgd(mm)
|
||||
#endif /* CONFIG_MMU */
|
||||
@@ -3228,11 +2968,6 @@ void __init mm_cache_init(void)
|
||||
|
||||
void __init proc_caches_init(void)
|
||||
{
|
||||
struct kmem_cache_args args = {
|
||||
.use_freeptr_offset = true,
|
||||
.freeptr_offset = offsetof(struct vm_area_struct, vm_freeptr),
|
||||
};
|
||||
|
||||
sighand_cachep = kmem_cache_create("sighand_cache",
|
||||
sizeof(struct sighand_struct), 0,
|
||||
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU|
|
||||
@@ -3249,10 +2984,6 @@ void __init proc_caches_init(void)
|
||||
sizeof(struct fs_struct), 0,
|
||||
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
|
||||
NULL);
|
||||
vm_area_cachep = kmem_cache_create("vm_area_struct",
|
||||
sizeof(struct vm_area_struct), &args,
|
||||
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU|
|
||||
SLAB_ACCOUNT);
|
||||
mmap_init();
|
||||
nsproxy_cache_init();
|
||||
}
|
||||
|
||||
@@ -277,6 +277,11 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
|
||||
/* IMA needs to pass the measurement list to the next kernel. */
|
||||
ima_add_kexec_buffer(image);
|
||||
|
||||
/* If KHO is active, add its images to the list */
|
||||
ret = kho_fill_kimage(image);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
/* Call image load handler */
|
||||
ldata = kexec_image_load_default(image);
|
||||
|
||||
@@ -672,6 +677,14 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
|
||||
if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If KHO is active, only use KHO scratch memory. All other memory
|
||||
* could potentially be handed over.
|
||||
*/
|
||||
ret = kho_locate_mem_hole(kbuf, locate_mem_hole_callback);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
|
||||
ret = kexec_walk_resources(kbuf, locate_mem_hole_callback);
|
||||
else
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,4 +39,20 @@ extern size_t kexec_purgatory_size;
|
||||
#else /* CONFIG_KEXEC_FILE */
|
||||
static inline void kimage_file_post_load_cleanup(struct kimage *image) { }
|
||||
#endif /* CONFIG_KEXEC_FILE */
|
||||
|
||||
struct kexec_buf;
|
||||
|
||||
#ifdef CONFIG_KEXEC_HANDOVER
|
||||
int kho_locate_mem_hole(struct kexec_buf *kbuf,
|
||||
int (*func)(struct resource *, void *));
|
||||
int kho_fill_kimage(struct kimage *image);
|
||||
#else
|
||||
static inline int kho_locate_mem_hole(struct kexec_buf *kbuf,
|
||||
int (*func)(struct resource *, void *))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int kho_fill_kimage(struct kimage *image) { return 0; }
|
||||
#endif /* CONFIG_KEXEC_HANDOVER */
|
||||
#endif /* LINUX_KEXEC_INTERNAL_H */
|
||||
|
||||
+21
-23
@@ -1094,16 +1094,15 @@ static void mark_nosave_pages(struct memory_bitmap *bm)
|
||||
((unsigned long long) region->end_pfn << PAGE_SHIFT)
|
||||
- 1);
|
||||
|
||||
for (pfn = region->start_pfn; pfn < region->end_pfn; pfn++)
|
||||
if (pfn_valid(pfn)) {
|
||||
/*
|
||||
* It is safe to ignore the result of
|
||||
* mem_bm_set_bit_check() here, since we won't
|
||||
* touch the PFNs for which the error is
|
||||
* returned anyway.
|
||||
*/
|
||||
mem_bm_set_bit_check(bm, pfn);
|
||||
}
|
||||
for_each_valid_pfn(pfn, region->start_pfn, region->end_pfn) {
|
||||
/*
|
||||
* It is safe to ignore the result of
|
||||
* mem_bm_set_bit_check() here, since we won't
|
||||
* touch the PFNs for which the error is
|
||||
* returned anyway.
|
||||
*/
|
||||
mem_bm_set_bit_check(bm, pfn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1255,22 +1254,21 @@ static void mark_free_pages(struct zone *zone)
|
||||
spin_lock_irqsave(&zone->lock, flags);
|
||||
|
||||
max_zone_pfn = zone_end_pfn(zone);
|
||||
for (pfn = zone->zone_start_pfn; pfn < max_zone_pfn; pfn++)
|
||||
if (pfn_valid(pfn)) {
|
||||
page = pfn_to_page(pfn);
|
||||
for_each_valid_pfn(pfn, zone->zone_start_pfn, max_zone_pfn) {
|
||||
page = pfn_to_page(pfn);
|
||||
|
||||
if (!--page_count) {
|
||||
touch_nmi_watchdog();
|
||||
page_count = WD_PAGE_COUNT;
|
||||
}
|
||||
|
||||
if (page_zone(page) != zone)
|
||||
continue;
|
||||
|
||||
if (!swsusp_page_is_forbidden(page))
|
||||
swsusp_unset_page_free(page);
|
||||
if (!--page_count) {
|
||||
touch_nmi_watchdog();
|
||||
page_count = WD_PAGE_COUNT;
|
||||
}
|
||||
|
||||
if (page_zone(page) != zone)
|
||||
continue;
|
||||
|
||||
if (!swsusp_page_is_forbidden(page))
|
||||
swsusp_unset_page_free(page);
|
||||
}
|
||||
|
||||
for_each_migratetype_order(order, t) {
|
||||
list_for_each_entry(page,
|
||||
&zone->free_area[order].free_list[t], buddy_list) {
|
||||
|
||||
+154
-25
@@ -921,7 +921,6 @@ ptrace_get_syscall_info_entry(struct task_struct *child, struct pt_regs *regs,
|
||||
unsigned long args[ARRAY_SIZE(info->entry.args)];
|
||||
int i;
|
||||
|
||||
info->op = PTRACE_SYSCALL_INFO_ENTRY;
|
||||
info->entry.nr = syscall_get_nr(child, regs);
|
||||
syscall_get_arguments(child, regs, args);
|
||||
for (i = 0; i < ARRAY_SIZE(args); i++)
|
||||
@@ -943,10 +942,12 @@ ptrace_get_syscall_info_seccomp(struct task_struct *child, struct pt_regs *regs,
|
||||
* diverge significantly enough.
|
||||
*/
|
||||
ptrace_get_syscall_info_entry(child, regs, info);
|
||||
info->op = PTRACE_SYSCALL_INFO_SECCOMP;
|
||||
info->seccomp.ret_data = child->ptrace_message;
|
||||
|
||||
/* ret_data is the last field in struct ptrace_syscall_info.seccomp */
|
||||
/*
|
||||
* ret_data is the last non-reserved field
|
||||
* in struct ptrace_syscall_info.seccomp
|
||||
*/
|
||||
return offsetofend(struct ptrace_syscall_info, seccomp.ret_data);
|
||||
}
|
||||
|
||||
@@ -954,7 +955,6 @@ static unsigned long
|
||||
ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
|
||||
struct ptrace_syscall_info *info)
|
||||
{
|
||||
info->op = PTRACE_SYSCALL_INFO_EXIT;
|
||||
info->exit.rval = syscall_get_error(child, regs);
|
||||
info->exit.is_error = !!info->exit.rval;
|
||||
if (!info->exit.is_error)
|
||||
@@ -965,19 +965,8 @@ ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
|
||||
void __user *datavp)
|
||||
ptrace_get_syscall_info_op(struct task_struct *child)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(child);
|
||||
struct ptrace_syscall_info info = {
|
||||
.op = PTRACE_SYSCALL_INFO_NONE,
|
||||
.arch = syscall_get_arch(child),
|
||||
.instruction_pointer = instruction_pointer(regs),
|
||||
.stack_pointer = user_stack_pointer(regs),
|
||||
};
|
||||
unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
|
||||
unsigned long write_size;
|
||||
|
||||
/*
|
||||
* This does not need lock_task_sighand() to access
|
||||
* child->last_siginfo because ptrace_freeze_traced()
|
||||
@@ -988,24 +977,160 @@ ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
|
||||
case SIGTRAP | 0x80:
|
||||
switch (child->ptrace_message) {
|
||||
case PTRACE_EVENTMSG_SYSCALL_ENTRY:
|
||||
actual_size = ptrace_get_syscall_info_entry(child, regs,
|
||||
&info);
|
||||
break;
|
||||
return PTRACE_SYSCALL_INFO_ENTRY;
|
||||
case PTRACE_EVENTMSG_SYSCALL_EXIT:
|
||||
actual_size = ptrace_get_syscall_info_exit(child, regs,
|
||||
&info);
|
||||
break;
|
||||
return PTRACE_SYSCALL_INFO_EXIT;
|
||||
default:
|
||||
return PTRACE_SYSCALL_INFO_NONE;
|
||||
}
|
||||
break;
|
||||
case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
|
||||
actual_size = ptrace_get_syscall_info_seccomp(child, regs,
|
||||
&info);
|
||||
return PTRACE_SYSCALL_INFO_SECCOMP;
|
||||
default:
|
||||
return PTRACE_SYSCALL_INFO_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
|
||||
void __user *datavp)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(child);
|
||||
struct ptrace_syscall_info info = {
|
||||
.op = ptrace_get_syscall_info_op(child),
|
||||
.arch = syscall_get_arch(child),
|
||||
.instruction_pointer = instruction_pointer(regs),
|
||||
.stack_pointer = user_stack_pointer(regs),
|
||||
};
|
||||
unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
|
||||
unsigned long write_size;
|
||||
|
||||
switch (info.op) {
|
||||
case PTRACE_SYSCALL_INFO_ENTRY:
|
||||
actual_size = ptrace_get_syscall_info_entry(child, regs, &info);
|
||||
break;
|
||||
case PTRACE_SYSCALL_INFO_EXIT:
|
||||
actual_size = ptrace_get_syscall_info_exit(child, regs, &info);
|
||||
break;
|
||||
case PTRACE_SYSCALL_INFO_SECCOMP:
|
||||
actual_size = ptrace_get_syscall_info_seccomp(child, regs, &info);
|
||||
break;
|
||||
}
|
||||
|
||||
write_size = min(actual_size, user_size);
|
||||
return copy_to_user(datavp, &info, write_size) ? -EFAULT : actual_size;
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_set_syscall_info_entry(struct task_struct *child, struct pt_regs *regs,
|
||||
struct ptrace_syscall_info *info)
|
||||
{
|
||||
unsigned long args[ARRAY_SIZE(info->entry.args)];
|
||||
int nr = info->entry.nr;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Check that the syscall number specified in info->entry.nr
|
||||
* is either a value of type "int" or a sign-extended value
|
||||
* of type "int".
|
||||
*/
|
||||
if (nr != info->entry.nr)
|
||||
return -ERANGE;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(args); i++) {
|
||||
args[i] = info->entry.args[i];
|
||||
/*
|
||||
* Check that the syscall argument specified in
|
||||
* info->entry.args[i] is either a value of type
|
||||
* "unsigned long" or a sign-extended value of type "long".
|
||||
*/
|
||||
if (args[i] != info->entry.args[i])
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
syscall_set_nr(child, regs, nr);
|
||||
/*
|
||||
* If the syscall number is set to -1, setting syscall arguments is not
|
||||
* just pointless, it would also clobber the syscall return value on
|
||||
* those architectures that share the same register both for the first
|
||||
* argument of syscall and its return value.
|
||||
*/
|
||||
if (nr != -1)
|
||||
syscall_set_arguments(child, regs, args);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_set_syscall_info_seccomp(struct task_struct *child, struct pt_regs *regs,
|
||||
struct ptrace_syscall_info *info)
|
||||
{
|
||||
/*
|
||||
* info->entry is currently a subset of info->seccomp,
|
||||
* info->seccomp.ret_data is currently ignored.
|
||||
*/
|
||||
return ptrace_set_syscall_info_entry(child, regs, info);
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
|
||||
struct ptrace_syscall_info *info)
|
||||
{
|
||||
long rval = info->exit.rval;
|
||||
|
||||
/*
|
||||
* Check that the return value specified in info->exit.rval
|
||||
* is either a value of type "long" or a sign-extended value
|
||||
* of type "long".
|
||||
*/
|
||||
if (rval != info->exit.rval)
|
||||
return -ERANGE;
|
||||
|
||||
if (info->exit.is_error)
|
||||
syscall_set_return_value(child, regs, rval, 0);
|
||||
else
|
||||
syscall_set_return_value(child, regs, 0, rval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
|
||||
const void __user *datavp)
|
||||
{
|
||||
struct pt_regs *regs = task_pt_regs(child);
|
||||
struct ptrace_syscall_info info;
|
||||
|
||||
if (user_size < sizeof(info))
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* The compatibility is tracked by info.op and info.flags: if user-space
|
||||
* does not instruct us to use unknown extra bits from future versions
|
||||
* of ptrace_syscall_info, we are not going to read them either.
|
||||
*/
|
||||
if (copy_from_user(&info, datavp, sizeof(info)))
|
||||
return -EFAULT;
|
||||
|
||||
/* Reserved for future use. */
|
||||
if (info.flags || info.reserved)
|
||||
return -EINVAL;
|
||||
|
||||
/* Changing the type of the system call stop is not supported yet. */
|
||||
if (ptrace_get_syscall_info_op(child) != info.op)
|
||||
return -EINVAL;
|
||||
|
||||
switch (info.op) {
|
||||
case PTRACE_SYSCALL_INFO_ENTRY:
|
||||
return ptrace_set_syscall_info_entry(child, regs, &info);
|
||||
case PTRACE_SYSCALL_INFO_EXIT:
|
||||
return ptrace_set_syscall_info_exit(child, regs, &info);
|
||||
case PTRACE_SYSCALL_INFO_SECCOMP:
|
||||
return ptrace_set_syscall_info_seccomp(child, regs, &info);
|
||||
default:
|
||||
/* Other types of system call stops are not supported yet. */
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_HAVE_ARCH_TRACEHOOK */
|
||||
|
||||
int ptrace_request(struct task_struct *child, long request,
|
||||
@@ -1224,6 +1349,10 @@ int ptrace_request(struct task_struct *child, long request,
|
||||
case PTRACE_GET_SYSCALL_INFO:
|
||||
ret = ptrace_get_syscall_info(child, addr, datavp);
|
||||
break;
|
||||
|
||||
case PTRACE_SET_SYSCALL_INFO:
|
||||
ret = ptrace_set_syscall_info(child, addr, datavp);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PTRACE_SECCOMP_GET_FILTER:
|
||||
|
||||
@@ -3329,6 +3329,15 @@ static void task_numa_work(struct callback_head *work)
|
||||
if (p->flags & PF_EXITING)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Memory is pinned to only one NUMA node via cpuset.mems, naturally
|
||||
* no page can be migrated.
|
||||
*/
|
||||
if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1) {
|
||||
trace_sched_skip_cpuset_numa(current, &cpuset_current_mems_allowed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mm->numa_next_scan) {
|
||||
mm->numa_next_scan = now +
|
||||
msecs_to_jiffies(sysctl_numa_balancing_scan_delay);
|
||||
|
||||
Reference in New Issue
Block a user