All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v1 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests
@ 2024-04-01  9:47 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2024-04-01  9:47 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20240321215954.177730-3-david@redhat.com>
References: <20240321215954.177730-3-david@redhat.com>
TO: David Hildenbrand <david@redhat.com>

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvms390/next]
[also build test WARNING on s390/features linus/master v6.9-rc2]
[cannot apply to akpm-mm/mm-everything next-20240328]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Hildenbrand/mm-userfaultfd-don-t-place-zeropages-when-zeropages-are-disallowed/20240322-060251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git next
patch link:    https://lore.kernel.org/r/20240321215954.177730-3-david%40redhat.com
patch subject: [PATCH v1 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests
:::::: branch date: 11 days ago
:::::: commit date: 11 days ago
config: s390-randconfig-r071-20240325 (https://download.01.org/0day-ci/archive/20240401/202404011730.2TEIocud-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 23de3862dce582ce91c1aa914467d982cb1a73b4)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202404011730.2TEIocud-lkp@intel.com/

smatch warnings:
arch/s390/mm/gmap.c:2656 __s390_unshare_zeropages() error: uninitialized symbol 'rc'.

vim +/rc +2656 arch/s390/mm/gmap.c

9a7a43a7ce9759 David Hildenbrand 2024-03-21  2598  
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2599  /*
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2600   * Unshare all shared zeropages, replacing them by anonymous pages. Note that
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2601   * we cannot simply zap all shared zeropages, because this could later
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2602   * trigger unexpected userfaultfd missing events.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2603   *
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2604   * This must be called after mm->context.allow_cow_sharing was
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2605   * set to 0, to avoid future mappings of shared zeropages.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2606   *
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2607   * mm contracts with s390, that even if mm were to remove a page table,
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2608   * and racing with walk_page_range_vma() calling pte_offset_map_lock()
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2609   * would fail, it will never insert a page table containing empty zero
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2610   * pages once mm_forbids_zeropage(mm) i.e.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2611   * mm->context.allow_cow_sharing is set to 0.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2612   */
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2613  static int __s390_unshare_zeropages(struct mm_struct *mm)
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2614  {
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2615  	struct vm_area_struct *vma;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2616  	VMA_ITERATOR(vmi, mm, 0);
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2617  	unsigned long addr;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2618  	int rc;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2619  
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2620  	for_each_vma(vmi, vma) {
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2621  		/*
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2622  		 * We could only look at COW mappings, but it's more future
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2623  		 * proof to catch unexpected zeropages in other mappings and
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2624  		 * fail.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2625  		 */
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2626  		if ((vma->vm_flags & VM_PFNMAP) || is_vm_hugetlb_page(vma))
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2627  			continue;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2628  		addr = vma->vm_start;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2629  
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2630  retry:
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2631  		rc = walk_page_range_vma(vma, addr, vma->vm_end,
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2632  					 &find_zeropage_ops, &addr);
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2633  		if (rc <= 0)
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2634  			continue;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2635  
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2636  		/* addr was updated by find_zeropage_pte_entry() */
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2637  		rc = handle_mm_fault(vma, addr,
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2638  				     FAULT_FLAG_UNSHARE | FAULT_FLAG_REMOTE,
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2639  				     NULL);
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2640  		if (rc & VM_FAULT_OOM)
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2641  			return -ENOMEM;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2642  		/*
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2643  		 * See break_ksm(): even after handle_mm_fault() returned 0, we
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2644  		 * must start the lookup from the current address, because
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2645  		 * handle_mm_fault() may back out if there's any difficulty.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2646  		 *
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2647  		 * VM_FAULT_SIGBUS and VM_FAULT_SIGSEGV are unexpected but
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2648  		 * maybe they could trigger in the future on concurrent
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2649  		 * truncation. In that case, the shared zeropage would be gone
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2650  		 * and we can simply retry and make progress.
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2651  		 */
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2652  		cond_resched();
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2653  		goto retry;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2654  	}
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2655  
9a7a43a7ce9759 David Hildenbrand 2024-03-21 @2656  	return rc;
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2657  }
9a7a43a7ce9759 David Hildenbrand 2024-03-21  2658  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH v1 0/2] s390/mm: shared zeropage + KVM fix and optimization
@ 2024-03-21 21:59 David Hildenbrand
  2024-03-21 21:59 ` [PATCH v1 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests David Hildenbrand
  0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2024-03-21 21:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Christian Borntraeger, Janosch Frank,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik, Andrew Morton,
	Peter Xu, Alexander Gordeev, Sven Schnelle, Gerald Schaefer,
	Andrea Arcangeli, kvm, linux-s390

This series fixes one issue with uffd + shared zeropages on s390x and
optimizes "ordinary" KVM guests to make use of shared zeropages again.

userfaultfd could currently end up mapping shared zeropages into processes
that forbid shared zeropages. This only apples to s390x, relevant for
handling PV guests and guests that use storage kets correctly. Fix it
by placing a zeroed folio instead of the shared zeropage during
UFFDIO_ZEROPAGE instead.

I stumbled over this issue while looking into a customer scenario that
is using:

(1) Memory ballooning for dynamic resizing. Start a VM with, say, 100 GiB
    and inflate the balloon during boot to 60 GiB. The VM has ~40 GiB
    available and additional memory can be "fake hotplugged" to the VM
    later on demand by deflating the balloon. Actual memory overcommit is
    not desired, so physical memory would only be moved between VMs.

(2) Live migration of VMs between sites to evacuate servers in case of
    emergency.

Without the shared zeropage, during (2), the VM would suddenly consume
100 GiB on the migration source and destination. On the migration source,
where we don't excpect memory overcommit, we could easilt end up crashing
the VM during migration.

Independent of that, memory handed back to the hypervisor using "free page
reporting" would end up consuming actual memory after the migration on the
destination, not getting freed up until reused+freed again.

While there might be ways to optimize parts of this in QEMU, we really
should just support the shared zeropage again for ordinary VMs.

We only expect legcy guests to make use of storage keys, so let's handle
zeropages again when enabling storage keys or when enabling PV. To not
break userfaultfd like we did in the past, don't zap the shared zeropages,
but instead trigger unsharing faults, just like we do for unsharing
KSM pages in break_ksm().

Unsharing faults will simply replace the shared zeropage by a zeroed
anonymous folio. We can already trigger the same fault path using GUP,
when trying to long-term pin a shared zeropage, but also when unmerging
a KSM-placed zeropages, so this is nothing new.

Patch #1 tested on 86-64 by forcing mm_forbids_zeropage() to be 1, and
running the uffd selftests.

Patch #2 tested on s390x: the live migration scenario now works as
expected, and kvm-unit-tests that trigger usage of skeys work well, whereby
I can see detection and unsharing of shared zeropages.

Based on current mm-unstable. Maybe at least the second patch should
go via the s390x tree, I think patch #1 could go that route as well.

Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org

David Hildenbrand (2):
  mm/userfaultfd: don't place zeropages when zeropages are disallowed
  s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests

 arch/s390/include/asm/gmap.h        |   2 +-
 arch/s390/include/asm/mmu.h         |   5 +
 arch/s390/include/asm/mmu_context.h |   1 +
 arch/s390/include/asm/pgtable.h     |  15 ++-
 arch/s390/kvm/kvm-s390.c            |   4 +-
 arch/s390/mm/gmap.c                 | 163 +++++++++++++++++++++-------
 mm/userfaultfd.c                    |  35 ++++++
 7 files changed, 178 insertions(+), 47 deletions(-)

-- 
2.43.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-01  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01  9:47 [PATCH v1 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2024-03-21 21:59 [PATCH v1 0/2] s390/mm: shared zeropage + KVM fix and optimization David Hildenbrand
2024-03-21 21:59 ` [PATCH v1 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests David Hildenbrand
2024-03-22 10:22   ` Christian Borntraeger
2024-03-22 17:08     ` David Hildenbrand

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.