Skip to contentSkip to conversation

KVM: s390: some cleanup and small fixes

PATCH Superseded Claudio Imbrenda 3 participants 7 messages May 23, 2025 – May 27, 2025

Subsystems (5)
KVM s390 s390 MM KVM s390 +1 more subsystems

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

v4 cover KVM: s390: some cleanup and small fixes

This series has some cleanups and small fixes in preparation of the upcoming series that will finally completely move all guest page table handling into kvm. The cleaups and fixes in this series are good enough on their own, hence why they are being sent now.

v3->v4
* remove orphaned find_zeropage_ops and find_zeropage_pte_entry() from mm/gmap.c (thanks kernel test robot)
* add missing #include <linux/swapops.h> to mm/gmap_helpers.c (thanks kernel test robot)

v2->v3 (mainly addresses Nina's and Heiko's comments)
* drop patch 3 - it was just an attempt to clean up the code a little and make it more readable, but there were too many issues to address
* remove all dead code from s390/mm/gmap.c that is being replaced by code in s390/mm/gmap_helpers.c
* remove a couple of unused functions from s390/mm/gmap_helpers.c, some of them will be introduced again in a later series when they are actually needed
* added documentation to the functions in s390/mm/gmap_helpers.c
* general readability improvements

v1->v2
* remove uneeded "gmap.h" include from gaccess.c (thanks Christph)
* use a custom helper instead of u64_replace_bits() (thanks Nina)
* new helper functions in priv.c to increase readability (thanks Nina)
* add lockdep assertion in handle_essa() (thanks Nina)
* gmap_helper_disable_cow_sharing() will not take the mmap lock, and must now be called while already holding the mmap lock in write mode

Claudio Imbrenda (4):
s390: remove unneeded includes
KVM: s390: remove unneeded srcu lock
KVM: s390: refactor and split some gmap helpers
KVM: s390: simplify and move pv code

 MAINTAINERS                          |   2 +
 arch/s390/include/asm/gmap.h         |   2 -
 arch/s390/include/asm/gmap_helpers.h |  15 ++
 arch/s390/include/asm/tlb.h          |   1 +
 arch/s390/include/asm/uv.h           |   1 -
 arch/s390/kernel/uv.c                |  12 +-
 arch/s390/kvm/Makefile               |   2 +-
 arch/s390/kvm/diag.c                 |  13 +-
 arch/s390/kvm/gaccess.c              |   3 +-
 arch/s390/kvm/gmap-vsie.c            |   1 -
 arch/s390/kvm/gmap.c                 | 121 ---------------
 arch/s390/kvm/gmap.h                 |  39 -----
 arch/s390/kvm/intercept.c            |   9 +-
 arch/s390/kvm/kvm-s390.c             |  10 +-
 arch/s390/kvm/kvm-s390.h             |  42 +++++
 arch/s390/kvm/priv.c                 |   6 +-
 arch/s390/kvm/pv.c                   |  61 +++++++-
 arch/s390/kvm/vsie.c                 |  19 ++-
 arch/s390/mm/Makefile                |   2 +
 arch/s390/mm/fault.c                 |   1 -
 arch/s390/mm/gmap.c                  | 185 +---------------------
 arch/s390/mm/gmap_helpers.c          | 224 +++++++++++++++++++++++++++
 arch/s390/mm/init.c                  |   1 -
 arch/s390/mm/pgalloc.c               |   2 -
 arch/s390/mm/pgtable.c               |   1 -
 25 files changed, 396 insertions(+), 379 deletions(-)
 create mode 100644 arch/s390/include/asm/gmap_helpers.h
 delete mode 100644 arch/s390/kvm/gmap.c
 delete mode 100644 arch/s390/kvm/gmap.h
 create mode 100644 arch/s390/mm/gmap_helpers.c
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v4 1/4 s390: remove unneeded includes

Many files don't need to include asm/tlb.h or asm/gmap.h. On the other hand, asm/tlb.h does need to include asm/gmap.h.

Remove all unneeded includes so that asm/tlb.h is not directly used by s390 arch code anymore. Remove asm/gmap.h from a few other files as well, so that now only KVM code, mm/gmap.c, and asm/tlb.h include it.

---
 arch/s390/include/asm/tlb.h | 1 +
 arch/s390/include/asm/uv.h  | 1 -
 arch/s390/kvm/intercept.c   | 1 +
 arch/s390/mm/fault.c        | 1 -
 arch/s390/mm/gmap.c         | 1 -
 arch/s390/mm/init.c         | 1 -
 arch/s390/mm/pgalloc.c      | 2 --
 arch/s390/mm/pgtable.c      | 1 -
 8 files changed, 2 insertions(+), 7 deletions(-)
arch/s390/include/asm/tlb.h +1 -0
index f20601995bb0..56d5f9e0eb2e 100644
@@ -36,6 +36,7 @@ static inline bool __tlb_remove_folio_pages(struct mmu_gather *tlb,
 
 #include <asm/tlbflush.h>
 #include <asm-generic/tlb.h>
+#include <asm/gmap.h>
 
 /*
  * Release the page cache reference for a pte removed by
arch/s390/include/asm/uv.h +0 -1
index 46fb0ef6f984..eeb2db4783e6 100644
@@ -16,7 +16,6 @@
 #include <linux/bug.h>
 #include <linux/sched.h>
 #include <asm/page.h>
-#include <asm/gmap.h>
 #include <asm/asm.h>
 
 #define UVC_CC_OK	0
arch/s390/kvm/intercept.c +1 -0
index a06a000f196c..b4834bd4d216 100644
@@ -16,6 +16,7 @@
 #include <asm/irq.h>
 #include <asm/sysinfo.h>
 #include <asm/uv.h>
+#include <asm/gmap.h>
 
 #include "kvm-s390.h"
 #include "gaccess.h"
arch/s390/mm/fault.c +0 -1
index da84ff6770de..3829521450dd 100644
@@ -40,7 +40,6 @@
 #include <asm/ptrace.h>
 #include <asm/fault.h>
 #include <asm/diag.h>
-#include <asm/gmap.h>
 #include <asm/irq.h>
 #include <asm/facility.h>
 #include <asm/uv.h>
arch/s390/mm/gmap.c +0 -1
index a94bd4870c65..4869555ff403 100644
@@ -24,7 +24,6 @@
 #include <asm/machine.h>
 #include <asm/gmap.h>
 #include <asm/page.h>
-#include <asm/tlb.h>
 
 /*
  * The address is saved in a radix tree directly; NULL would be ambiguous,
arch/s390/mm/init.c +0 -1
index afa085e8186c..074bf4fb4ce2 100644
@@ -40,7 +40,6 @@
 #include <asm/kfence.h>
 #include <asm/dma.h>
 #include <asm/abs_lowcore.h>
-#include <asm/tlb.h>
 #include <asm/tlbflush.h>
 #include <asm/sections.h>
 #include <asm/sclp.h>
arch/s390/mm/pgalloc.c +0 -2
index e3a6f8ae156c..ddab36875370 100644
@@ -12,8 +12,6 @@
 #include <asm/mmu_context.h>
 #include <asm/page-states.h>
 #include <asm/pgalloc.h>
-#include <asm/gmap.h>
-#include <asm/tlb.h>
 #include <asm/tlbflush.h>
 
 unsigned long *crst_table_alloc(struct mm_struct *mm)
arch/s390/mm/pgtable.c +0 -1
index 9901934284ec..7df70cd8f739 100644
@@ -20,7 +20,6 @@
 #include <linux/ksm.h>
 #include <linux/mman.h>
 
-#include <asm/tlb.h>
 #include <asm/tlbflush.h>
 #include <asm/mmu_context.h>
 #include <asm/page-states.h>
Signature · 1 line
2.49.0
maintainer Acked-by on v4 1/4
#2 lore raw

Re: [PATCH v4 1/4] s390: remove unneeded includes

Quoted 10 lines · Claudio Imbrenda

Many files don't need to include asm/tlb.h or asm/gmap.h. On the other hand, asm/tlb.h does need to include asm/gmap.h.

Remove all unneeded includes so that asm/tlb.h is not directly used by s390 arch code anymore. Remove asm/gmap.h from a few other files as well, so that now only KVM code, mm/gmap.c, and asm/tlb.h include it.

Quoted 10 lines
---
 arch/s390/include/asm/tlb.h | 1 +
 arch/s390/include/asm/uv.h  | 1 -
 arch/s390/kvm/intercept.c   | 1 +
 arch/s390/mm/fault.c        | 1 -
 arch/s390/mm/gmap.c         | 1 -
 arch/s390/mm/init.c         | 1 -
 arch/s390/mm/pgalloc.c      | 2 --
 arch/s390/mm/pgtable.c      | 1 -
 8 files changed, 2 insertions(+), 7 deletions(-)

Please change the subject so the first character after "s390: " is an upper case character, like it is supposed to be the case for all s390 related patches. For "KVM: s390:" there seems to be no consistent rule, but that's your playground.

Anyway:

author maintainer
#3 lore raw

PATCH v4 2/4 KVM: s390: remove unneeded srcu lock

In reply to Claudio Imbrenda

All paths leading to handle_essa() already hold the kvm->srcu. Remove unneeded srcu locking from handle_essa().
Add lockdep assertion to make sure we will always be holding kvm->srcu when entering handle_essa().

---
 arch/s390/kvm/priv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/s390/kvm/priv.c +2 -4
index 1a49b89706f8..9253c70897a8 100644
@@ -1248,6 +1248,8 @@ static inline int __do_essa(struct kvm_vcpu *vcpu, const int orc)
 
 static int handle_essa(struct kvm_vcpu *vcpu)
 {
+	lockdep_assert_held(&vcpu->kvm->srcu);
+
 	/* entries expected to be 1FF */
 	int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3;
 	unsigned long *cbrlo;
@@ -1297,12 +1299,8 @@ static int handle_essa(struct kvm_vcpu *vcpu)
 		/* Retry the ESSA instruction */
 		kvm_s390_retry_instr(vcpu);
 	} else {
-		int srcu_idx;
-
 		mmap_read_lock(vcpu->kvm->mm);
-		srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
 		i = __do_essa(vcpu, orc);
-		srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
 		mmap_read_unlock(vcpu->kvm->mm);
 		if (i < 0)
 			return i;
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH v4 3/4 KVM: s390: refactor and split some gmap helpers

In reply to Claudio Imbrenda

Refactor some gmap functions; move the implementation into a separate file with only helper functions. The new helper functions work on vm addresses, leaving all gmap logic in the gmap functions, which mostly become just wrappers.

The whole gmap handling is going to be moved inside KVM soon, but the helper functions need to touch core mm functions, and thus need to stay in the core of kernel.

---
 MAINTAINERS                          |   2 +
 arch/s390/include/asm/gmap.h         |   2 -
 arch/s390/include/asm/gmap_helpers.h |  15 ++
 arch/s390/kvm/diag.c                 |  13 +-
 arch/s390/kvm/kvm-s390.c             |   5 +-
 arch/s390/mm/Makefile                |   2 +
 arch/s390/mm/gmap.c                  | 184 +---------------------
 arch/s390/mm/gmap_helpers.c          | 224 +++++++++++++++++++++++++++
 8 files changed, 260 insertions(+), 187 deletions(-)
 create mode 100644 arch/s390/include/asm/gmap_helpers.h
 create mode 100644 arch/s390/mm/gmap_helpers.c
MAINTAINERS +2 -0
index f21f1dabb5fe..b0a8fb5a254c 100644
@@ -13093,12 +13093,14 @@ S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git
 F:	Documentation/virt/kvm/s390*
 F:	arch/s390/include/asm/gmap.h
+F:	arch/s390/include/asm/gmap_helpers.h
 F:	arch/s390/include/asm/kvm*
 F:	arch/s390/include/uapi/asm/kvm*
 F:	arch/s390/include/uapi/asm/uvdevice.h
 F:	arch/s390/kernel/uv.c
 F:	arch/s390/kvm/
 F:	arch/s390/mm/gmap.c
+F:	arch/s390/mm/gmap_helpers.c
 F:	drivers/s390/char/uvdevice.c
 F:	tools/testing/selftests/drivers/s390x/uvdevice/
 F:	tools/testing/selftests/kvm/*/s390/
arch/s390/include/asm/gmap.h +0 -2
index 9f2814d0e1e9..66c5808fd011 100644
@@ -110,7 +110,6 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from,
 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
 unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
 int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
-void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
 void __gmap_zap(struct gmap *, unsigned long gaddr);
 void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
 
@@ -134,7 +133,6 @@ int gmap_protect_one(struct gmap *gmap, unsigned long gaddr, int prot, unsigned
 
 void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4],
 			     unsigned long gaddr, unsigned long vmaddr);
-int s390_disable_cow_sharing(void);
 int s390_replace_asce(struct gmap *gmap);
 void s390_uv_destroy_pfns(unsigned long count, unsigned long *pfns);
 int __s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,
arch/s390/include/asm/gmap_helpers.h new file +15 -0
new file mode 100644
index 000000000000..5356446a61c4
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *  Helper functions for KVM guest address space mapping code
+ *
+ *    Copyright IBM Corp. 2025
+ */
+
+#ifndef _ASM_S390_GMAP_HELPERS_H
+#define _ASM_S390_GMAP_HELPERS_H
+
+void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr);
+void gmap_helper_discard(struct mm_struct *mm, unsigned long vmaddr, unsigned long end);
+int gmap_helper_disable_cow_sharing(void);
+
+#endif /* _ASM_S390_GMAP_HELPERS_H */
arch/s390/kvm/diag.c +8 -5
index 74f73141f9b9..5faa5af56d9a 100644
@@ -11,6 +11,7 @@
 #include <linux/kvm.h>
 #include <linux/kvm_host.h>
 #include <asm/gmap.h>
+#include <asm/gmap_helpers.h>
 #include <asm/virtio-ccw.h>
 #include "kvm-s390.h"
 #include "trace.h"
@@ -32,12 +33,13 @@ static int diag_release_pages(struct kvm_vcpu *vcpu)
 
 	VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
 
+	mmap_read_lock(vcpu->kvm->mm);
 	/*
 	 * We checked for start >= end above, so lets check for the
 	 * fast path (no prefix swap page involved)
 	 */
 	if (end <= prefix || start >= prefix + 2 * PAGE_SIZE) {
-		gmap_discard(vcpu->arch.gmap, start, end);
+		gmap_helper_discard(vcpu->kvm->mm, start, end);
 	} else {
 		/*
 		 * This is slow path.  gmap_discard will check for start
@@ -45,13 +47,14 @@ static int diag_release_pages(struct kvm_vcpu *vcpu)
 		 * prefix and let gmap_discard make some of these calls
 		 * NOPs.
 		 */
-		gmap_discard(vcpu->arch.gmap, start, prefix);
+		gmap_helper_discard(vcpu->kvm->mm, start, prefix);
 		if (start <= prefix)
-			gmap_discard(vcpu->arch.gmap, 0, PAGE_SIZE);
+			gmap_helper_discard(vcpu->kvm->mm, 0, PAGE_SIZE);
 		if (end > prefix + PAGE_SIZE)
-			gmap_discard(vcpu->arch.gmap, PAGE_SIZE, 2 * PAGE_SIZE);
-		gmap_discard(vcpu->arch.gmap, prefix + 2 * PAGE_SIZE, end);
+			gmap_helper_discard(vcpu->kvm->mm, PAGE_SIZE, 2 * PAGE_SIZE);
+		gmap_helper_discard(vcpu->kvm->mm, prefix + 2 * PAGE_SIZE, end);
 	}
+	mmap_read_unlock(vcpu->kvm->mm);
 	return 0;
 }
 
arch/s390/kvm/kvm-s390.c +4 -1
index 3f3175193fd7..10cfc047525d 100644
@@ -40,6 +40,7 @@
 #include <asm/machine.h>
 #include <asm/stp.h>
 #include <asm/gmap.h>
+#include <asm/gmap_helpers.h>
 #include <asm/nmi.h>
 #include <asm/isc.h>
 #include <asm/sclp.h>
@@ -2674,7 +2675,9 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		if (r)
 			break;
 
-		r = s390_disable_cow_sharing();
+		mmap_write_lock(kvm->mm);
+		r = gmap_helper_disable_cow_sharing();
+		mmap_write_unlock(kvm->mm);
 		if (r)
 			break;
 
arch/s390/mm/Makefile +2 -0
index 9726b91fe7e4..bd0401cc7ca5 100644
@@ -12,3 +12,5 @@ obj-$(CONFIG_HUGETLB_PAGE)	+= hugetlbpage.o
 obj-$(CONFIG_PTDUMP)		+= dump_pagetables.o
 obj-$(CONFIG_PGSTE)		+= gmap.o
 obj-$(CONFIG_PFAULT)		+= pfault.o
+
+obj-$(subst m,y,$(CONFIG_KVM))	+= gmap_helpers.o
arch/s390/mm/gmap.c +5 -179

219 lines not on this page · raw message

arch/s390/mm/gmap_helpers.c new file +224 -0

224 lines not on this page · raw message

Signature · 1 line
2.49.0
#5 lore raw

Re: [PATCH v4 3/4] KVM: s390: refactor and split some gmap helpers

kernel test robot noticed the following build errors:

Hi Claudio,

kernel test robot noticed the following build errors:

[auto build test ERROR on kvms390/next]
[also build test ERROR on s390/features kvm/queue kvm/next mst-vhost/linux-next linus/master v6.15] [cannot apply to kvm/linux-next next-20250526]
[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/Claudio-Imbrenda/s390-remove-unneeded-includes/20250523-210651
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git next
patch link:    https://lore.kernel.org/r/20250523130348.247446-4-imbrenda%40linux.ibm.com
patch subject: [PATCH v4 3/4] KVM: s390: refactor and split some gmap helpers
config: s390-randconfig-r051-20250527 (https://download.01.org/0day-ci/archive/20250527/[email protected]/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250527/[email protected]/reproduce)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/s390/mm/gmap_helpers.c:11:

>> include/linux/swapops.h:90:21: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
      90 |         ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
         |                            ^
   include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
      27 | #define SWP_TYPE_SHIFT  (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
         |                                              ^
   include/linux/swapops.h:90:49: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
      90 |         ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
         |                                                        ^
   include/linux/swapops.h:28:34: note: expanded from macro 'SWP_OFFSET_MASK'
      28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
         |                                  ^
   include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
      27 | #define SWP_TYPE_SHIFT  (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
         |                                              ^
   include/linux/swapops.h:100:23: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
     100 |         return (entry.val >> SWP_TYPE_SHIFT);
         |                              ^
   include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
      27 | #define SWP_TYPE_SHIFT  (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
         |                                              ^
   include/linux/swapops.h:109:21: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
     109 |         return entry.val & SWP_OFFSET_MASK;
         |                            ^
   include/linux/swapops.h:28:34: note: expanded from macro 'SWP_OFFSET_MASK'
      28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
         |                                  ^
   include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
      27 | #define SWP_TYPE_SHIFT  (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
         |                                              ^
>> include/linux/swapops.h:235:37: error: use of undeclared identifier 'SWP_MIGRATION_READ'
     235 |         return unlikely(swp_type(entry) == SWP_MIGRATION_READ ||
         |                                            ^
>> include/linux/swapops.h:236:23: error: use of undeclared identifier 'SWP_MIGRATION_READ_EXCLUSIVE'
     236 |                         swp_type(entry) == SWP_MIGRATION_READ_EXCLUSIVE ||
         |                                            ^
>> include/linux/swapops.h:237:23: error: use of undeclared identifier 'SWP_MIGRATION_WRITE'
     237 |                         swp_type(entry) == SWP_MIGRATION_WRITE);
         |                                            ^
   include/linux/swapops.h:242:37: error: use of undeclared identifier 'SWP_MIGRATION_WRITE'
     242 |         return unlikely(swp_type(entry) == SWP_MIGRATION_WRITE);
         |                                            ^
   include/linux/swapops.h:247:37: error: use of undeclared identifier 'SWP_MIGRATION_READ'; did you mean 'THP_MIGRATION_FAIL'?
     247 |         return unlikely(swp_type(entry) == SWP_MIGRATION_READ);
         |                                            ^~~~~~~~~~~~~~~~~~
         |                                            THP_MIGRATION_FAIL
   include/linux/compiler.h:77:42: note: expanded from macro 'unlikely'
      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
         |                                             ^
   include/linux/vm_event_item.h:73:3: note: 'THP_MIGRATION_FAIL' declared here
      73 |                 THP_MIGRATION_FAIL,
         |                 ^
   In file included from arch/s390/mm/gmap_helpers.c:11:
   include/linux/swapops.h:252:37: error: use of undeclared identifier 'SWP_MIGRATION_READ_EXCLUSIVE'
     252 |         return unlikely(swp_type(entry) == SWP_MIGRATION_READ_EXCLUSIVE);
         |                                            ^
   include/linux/swapops.h:257:19: error: use of undeclared identifier 'SWP_MIGRATION_READ'; did you mean 'THP_MIGRATION_FAIL'?
     257 |         return swp_entry(SWP_MIGRATION_READ, offset);
         |                          ^~~~~~~~~~~~~~~~~~
         |                          THP_MIGRATION_FAIL
   include/linux/vm_event_item.h:73:3: note: 'THP_MIGRATION_FAIL' declared here
      73 |                 THP_MIGRATION_FAIL,
         |                 ^
   In file included from arch/s390/mm/gmap_helpers.c:11:
   include/linux/swapops.h:262:19: error: use of undeclared identifier 'SWP_MIGRATION_READ_EXCLUSIVE'
     262 |         return swp_entry(SWP_MIGRATION_READ_EXCLUSIVE, offset);
         |                          ^
   include/linux/swapops.h:267:19: error: use of undeclared identifier 'SWP_MIGRATION_WRITE'
     267 |         return swp_entry(SWP_MIGRATION_WRITE, offset);
         |                          ^
>> include/linux/swapops.h:426:19: error: use of undeclared identifier 'SWP_PTE_MARKER'
     426 |         return swp_entry(SWP_PTE_MARKER, marker);
         |                          ^
   include/linux/swapops.h:431:28: error: use of undeclared identifier 'SWP_PTE_MARKER'
     431 |         return swp_type(entry) == SWP_PTE_MARKER;
         |                                   ^
   include/linux/swapops.h:525:15: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
     525 |         BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
         |                      ^
   include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
      27 | #define SWP_TYPE_SHIFT  (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
         |                                              ^
>> include/linux/swapops.h:599:28: error: use of undeclared identifier 'MAX_SWAPFILES'
     599 |         return swp_type(entry) >= MAX_SWAPFILES;
         |                                   ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:454:22: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     454 |         case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
         |                             ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:454:10: warning: array index 7 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     454 |         case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
         |                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:454:42: warning: array index 6 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     454 |         case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
         |                                                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:454:53: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     454 |         case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
         |                                                            ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:456:22: warning: array index 2 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     456 |         case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
         |                             ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:456:10: warning: array index 5 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     456 |         case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
         |                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:456:42: warning: array index 4 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     456 |         case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
         |                                                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:456:53: warning: array index 2 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     456 |         case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
         |                                                            ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:458:22: warning: array index 1 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     458 |         case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
         |                             ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/s390/mm/gmap_helpers.c:13:
   In file included from include/linux/ksm.h:14:
   In file included from include/linux/rmap.h:12:
   In file included from include/linux/memcontrol.h:23:
   In file included from include/linux/writeback.h:13:
   In file included from include/linux/blk_types.h:11:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:165:
   include/linux/compat.h:458:10: warning: array index 3 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     458 |         case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
         |                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:458:42: warning: array index 2 is past the end of the array (that has type 'compat_sigset_word[2]' (aka 'unsigned int[2]')) [-Warray-bounds]
     458 |         case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
         |                                                 ^     ~
   include/linux/compat.h:130:2: note: array 'sig' declared here
     130 |         compat_sigset_word      sig[_COMPAT_NSIG_WORDS];
         |         ^
   include/linux/compat.h:458:53: warning: array index 1 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
     458 |         case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
         |                                                            ^        ~
   arch/s390/include/asm/signal.h:22:9: note: array 'sig' declared here
      22 |         unsigned long sig[_NSIG_WORDS];
         |         ^
>> arch/s390/mm/gmap_helpers.c:31:2: error: call to undeclared function 'free_swap_and_cache'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      31 |         free_swap_and_cache(entry);
         |         ^

12 warnings and 18 errors generated.

vim +/MAX_SWAPFILES_SHIFT +90 include/linux/swapops.h

2e3468778dbe3e Peter Xu                       2022-08-11   14  
^1da177e4c3f41 Linus Torvalds                 2005-04-16   15  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16   16   * swapcache pages are stored in the swapper_space radix tree.  We want to
^1da177e4c3f41 Linus Torvalds                 2005-04-16   17   * get good packing density in that tree, so the index should be dense in
^1da177e4c3f41 Linus Torvalds                 2005-04-16   18   * the low-order bits.
^1da177e4c3f41 Linus Torvalds                 2005-04-16   19   *
a930c210c42dec Miaohe Lin                     2022-05-19   20   * We arrange the `type' and `offset' fields so that `type' is at the six
e83a9596712eb7 Paolo 'Blaisorblade' Giarrusso 2005-09-03   21   * high-order bits of the swp_entry_t and `offset' is right-aligned in the
9b15b817f3d624 Hugh Dickins                   2012-06-15   22   * remaining bits.  Although `type' itself needs only five bits, we allow for
a930c210c42dec Miaohe Lin                     2022-05-19   23   * shmem/tmpfs to shift it all up a further one bit: see swp_to_radix_entry().
^1da177e4c3f41 Linus Torvalds                 2005-04-16   24   *
^1da177e4c3f41 Linus Torvalds                 2005-04-16   25   * swp_entry_t's are *never* stored anywhere in their arch-dependent format.
^1da177e4c3f41 Linus Torvalds                 2005-04-16   26   */
3159f943aafdba Matthew Wilcox                 2017-11-03  @27  #define SWP_TYPE_SHIFT	(BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
3159f943aafdba Matthew Wilcox                 2017-11-03  @28  #define SWP_OFFSET_MASK	((1UL << SWP_TYPE_SHIFT) - 1)
^1da177e4c3f41 Linus Torvalds                 2005-04-16   29  
0d206b5d2e0d7d Peter Xu                       2022-08-11   30  /*
0d206b5d2e0d7d Peter Xu                       2022-08-11   31   * Definitions only for PFN swap entries (see is_pfn_swap_entry()).  To
0d206b5d2e0d7d Peter Xu                       2022-08-11   32   * store PFN, we only need SWP_PFN_BITS bits.  Each of the pfn swap entries
0d206b5d2e0d7d Peter Xu                       2022-08-11   33   * can use the extra bits to store other information besides PFN.
0d206b5d2e0d7d Peter Xu                       2022-08-11   34   */
0d206b5d2e0d7d Peter Xu                       2022-08-11   35  #ifdef MAX_PHYSMEM_BITS
0d206b5d2e0d7d Peter Xu                       2022-08-11   36  #define SWP_PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
0d206b5d2e0d7d Peter Xu                       2022-08-11   37  #else  /* MAX_PHYSMEM_BITS */
630dc25e43dacf David Hildenbrand              2022-12-05   38  #define SWP_PFN_BITS		min_t(int, \
630dc25e43dacf David Hildenbrand              2022-12-05   39  				      sizeof(phys_addr_t) * 8 - PAGE_SHIFT, \
630dc25e43dacf David Hildenbrand              2022-12-05   40  				      SWP_TYPE_SHIFT)
0d206b5d2e0d7d Peter Xu                       2022-08-11   41  #endif	/* MAX_PHYSMEM_BITS */
0d206b5d2e0d7d Peter Xu                       2022-08-11   42  #define SWP_PFN_MASK		(BIT(SWP_PFN_BITS) - 1)
0d206b5d2e0d7d Peter Xu                       2022-08-11   43  
2e3468778dbe3e Peter Xu                       2022-08-11   44  /**
2e3468778dbe3e Peter Xu                       2022-08-11   45   * Migration swap entry specific bitfield definitions.  Layout:
2e3468778dbe3e Peter Xu                       2022-08-11   46   *
2e3468778dbe3e Peter Xu                       2022-08-11   47   *   |----------+--------------------|
2e3468778dbe3e Peter Xu                       2022-08-11   48   *   | swp_type | swp_offset         |
2e3468778dbe3e Peter Xu                       2022-08-11   49   *   |----------+--------+-+-+-------|
2e3468778dbe3e Peter Xu                       2022-08-11   50   *   |          | resv   |D|A|  PFN  |
2e3468778dbe3e Peter Xu                       2022-08-11   51   *   |----------+--------+-+-+-------|
2e3468778dbe3e Peter Xu                       2022-08-11   52   *
2e3468778dbe3e Peter Xu                       2022-08-11   53   * @SWP_MIG_YOUNG_BIT: Whether the page used to have young bit set (bit A)
2e3468778dbe3e Peter Xu                       2022-08-11   54   * @SWP_MIG_DIRTY_BIT: Whether the page used to have dirty bit set (bit D)
2e3468778dbe3e Peter Xu                       2022-08-11   55   *
2e3468778dbe3e Peter Xu                       2022-08-11   56   * Note: A/D bits will be stored in migration entries iff there're enough
2e3468778dbe3e Peter Xu                       2022-08-11   57   * free bits in arch specific swp offset.  By default we'll ignore A/D bits
2e3468778dbe3e Peter Xu                       2022-08-11   58   * when migrating a page.  Please refer to migration_entry_supports_ad()
2e3468778dbe3e Peter Xu                       2022-08-11   59   * for more information.  If there're more bits besides PFN and A/D bits,
2e3468778dbe3e Peter Xu                       2022-08-11   60   * they should be reserved and always be zeros.
2e3468778dbe3e Peter Xu                       2022-08-11   61   */
2e3468778dbe3e Peter Xu                       2022-08-11   62  #define SWP_MIG_YOUNG_BIT		(SWP_PFN_BITS)
2e3468778dbe3e Peter Xu                       2022-08-11   63  #define SWP_MIG_DIRTY_BIT		(SWP_PFN_BITS + 1)
2e3468778dbe3e Peter Xu                       2022-08-11   64  #define SWP_MIG_TOTAL_BITS		(SWP_PFN_BITS + 2)
2e3468778dbe3e Peter Xu                       2022-08-11   65  
2e3468778dbe3e Peter Xu                       2022-08-11   66  #define SWP_MIG_YOUNG			BIT(SWP_MIG_YOUNG_BIT)
2e3468778dbe3e Peter Xu                       2022-08-11   67  #define SWP_MIG_DIRTY			BIT(SWP_MIG_DIRTY_BIT)
2e3468778dbe3e Peter Xu                       2022-08-11   68  
0d206b5d2e0d7d Peter Xu                       2022-08-11   69  static inline bool is_pfn_swap_entry(swp_entry_t entry);
0d206b5d2e0d7d Peter Xu                       2022-08-11   70  
099dd6878b9b12 Peter Xu                       2021-06-15   71  /* Clear all flags but only keep swp_entry_t related information */
099dd6878b9b12 Peter Xu                       2021-06-15   72  static inline pte_t pte_swp_clear_flags(pte_t pte)
099dd6878b9b12 Peter Xu                       2021-06-15   73  {
1493a1913e34b0 David Hildenbrand              2022-05-09   74  	if (pte_swp_exclusive(pte))
1493a1913e34b0 David Hildenbrand              2022-05-09   75  		pte = pte_swp_clear_exclusive(pte);
099dd6878b9b12 Peter Xu                       2021-06-15   76  	if (pte_swp_soft_dirty(pte))
099dd6878b9b12 Peter Xu                       2021-06-15   77  		pte = pte_swp_clear_soft_dirty(pte);
099dd6878b9b12 Peter Xu                       2021-06-15   78  	if (pte_swp_uffd_wp(pte))
099dd6878b9b12 Peter Xu                       2021-06-15   79  		pte = pte_swp_clear_uffd_wp(pte);
099dd6878b9b12 Peter Xu                       2021-06-15   80  	return pte;
099dd6878b9b12 Peter Xu                       2021-06-15   81  }
099dd6878b9b12 Peter Xu                       2021-06-15   82  
^1da177e4c3f41 Linus Torvalds                 2005-04-16   83  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16   84   * Store a type+offset into a swp_entry_t in an arch-independent format
^1da177e4c3f41 Linus Torvalds                 2005-04-16   85   */
^1da177e4c3f41 Linus Torvalds                 2005-04-16   86  static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset)
^1da177e4c3f41 Linus Torvalds                 2005-04-16   87  {
^1da177e4c3f41 Linus Torvalds                 2005-04-16   88  	swp_entry_t ret;
^1da177e4c3f41 Linus Torvalds                 2005-04-16   89  
3159f943aafdba Matthew Wilcox                 2017-11-03  @90  	ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
^1da177e4c3f41 Linus Torvalds                 2005-04-16   91  	return ret;
^1da177e4c3f41 Linus Torvalds                 2005-04-16   92  }
^1da177e4c3f41 Linus Torvalds                 2005-04-16   93  
^1da177e4c3f41 Linus Torvalds                 2005-04-16   94  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16   95   * Extract the `type' field from a swp_entry_t.  The swp_entry_t is in
^1da177e4c3f41 Linus Torvalds                 2005-04-16   96   * arch-independent format
^1da177e4c3f41 Linus Torvalds                 2005-04-16   97   */
^1da177e4c3f41 Linus Torvalds                 2005-04-16   98  static inline unsigned swp_type(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds                 2005-04-16   99  {
3159f943aafdba Matthew Wilcox                 2017-11-03  100  	return (entry.val >> SWP_TYPE_SHIFT);
^1da177e4c3f41 Linus Torvalds                 2005-04-16  101  }
^1da177e4c3f41 Linus Torvalds                 2005-04-16  102  
^1da177e4c3f41 Linus Torvalds                 2005-04-16  103  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16  104   * Extract the `offset' field from a swp_entry_t.  The swp_entry_t is in
^1da177e4c3f41 Linus Torvalds                 2005-04-16  105   * arch-independent format
^1da177e4c3f41 Linus Torvalds                 2005-04-16  106   */
^1da177e4c3f41 Linus Torvalds                 2005-04-16  107  static inline pgoff_t swp_offset(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds                 2005-04-16  108  {
3159f943aafdba Matthew Wilcox                 2017-11-03 @109  	return entry.val & SWP_OFFSET_MASK;
^1da177e4c3f41 Linus Torvalds                 2005-04-16  110  }
^1da177e4c3f41 Linus Torvalds                 2005-04-16  111  
0d206b5d2e0d7d Peter Xu                       2022-08-11  112  /*
0d206b5d2e0d7d Peter Xu                       2022-08-11  113   * This should only be called upon a pfn swap entry to get the PFN stored
0d206b5d2e0d7d Peter Xu                       2022-08-11  114   * in the swap entry.  Please refers to is_pfn_swap_entry() for definition
0d206b5d2e0d7d Peter Xu                       2022-08-11  115   * of pfn swap entry.
0d206b5d2e0d7d Peter Xu                       2022-08-11  116   */
0d206b5d2e0d7d Peter Xu                       2022-08-11  117  static inline unsigned long swp_offset_pfn(swp_entry_t entry)
0d206b5d2e0d7d Peter Xu                       2022-08-11  118  {
0d206b5d2e0d7d Peter Xu                       2022-08-11  119  	VM_BUG_ON(!is_pfn_swap_entry(entry));
0d206b5d2e0d7d Peter Xu                       2022-08-11  120  	return swp_offset(entry) & SWP_PFN_MASK;
0d206b5d2e0d7d Peter Xu                       2022-08-11  121  }
0d206b5d2e0d7d Peter Xu                       2022-08-11  122  
698dd4ba6b12e3 Matt Mackall                   2008-02-04  123  /* check whether a pte points to a swap entry */
698dd4ba6b12e3 Matt Mackall                   2008-02-04  124  static inline int is_swap_pte(pte_t pte)
698dd4ba6b12e3 Matt Mackall                   2008-02-04  125  {
21d9ee3eda7792 Mel Gorman                     2015-02-12  126  	return !pte_none(pte) && !pte_present(pte);
698dd4ba6b12e3 Matt Mackall                   2008-02-04  127  }
698dd4ba6b12e3 Matt Mackall                   2008-02-04  128  
^1da177e4c3f41 Linus Torvalds                 2005-04-16  129  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16  130   * Convert the arch-dependent pte representation of a swp_entry_t into an
^1da177e4c3f41 Linus Torvalds                 2005-04-16  131   * arch-independent swp_entry_t.
^1da177e4c3f41 Linus Torvalds                 2005-04-16  132   */
^1da177e4c3f41 Linus Torvalds                 2005-04-16  133  static inline swp_entry_t pte_to_swp_entry(pte_t pte)
^1da177e4c3f41 Linus Torvalds                 2005-04-16  134  {
^1da177e4c3f41 Linus Torvalds                 2005-04-16  135  	swp_entry_t arch_entry;
^1da177e4c3f41 Linus Torvalds                 2005-04-16  136  
099dd6878b9b12 Peter Xu                       2021-06-15  137  	pte = pte_swp_clear_flags(pte);
^1da177e4c3f41 Linus Torvalds                 2005-04-16  138  	arch_entry = __pte_to_swp_entry(pte);
^1da177e4c3f41 Linus Torvalds                 2005-04-16  139  	return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry));
^1da177e4c3f41 Linus Torvalds                 2005-04-16  140  }
^1da177e4c3f41 Linus Torvalds                 2005-04-16  141  
^1da177e4c3f41 Linus Torvalds                 2005-04-16  142  /*
^1da177e4c3f41 Linus Torvalds                 2005-04-16  143   * Convert the arch-independent representation of a swp_entry_t into the
^1da177e4c3f41 Linus Torvalds                 2005-04-16  144   * arch-dependent pte representation.
^1da177e4c3f41 Linus Torvalds                 2005-04-16  145   */
^1da177e4c3f41 Linus Torvalds                 2005-04-16  146  static inline pte_t swp_entry_to_pte(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds                 2005-04-16  147  {
^1da177e4c3f41 Linus Torvalds                 2005-04-16  148  	swp_entry_t arch_entry;
^1da177e4c3f41 Linus Torvalds                 2005-04-16  149  
^1da177e4c3f41 Linus Torvalds                 2005-04-16  150  	arch_entry = __swp_entry(swp_type(entry), swp_offset(entry));
^1da177e4c3f41 Linus Torvalds                 2005-04-16  151  	return __swp_entry_to_pte(arch_entry);
^1da177e4c3f41 Linus Torvalds                 2005-04-16  152  }
0697212a411c1d Christoph Lameter              2006-06-23  153  
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  154  static inline swp_entry_t radix_to_swp_entry(void *arg)
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  155  {
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  156  	swp_entry_t entry;
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  157  
3159f943aafdba Matthew Wilcox                 2017-11-03  158  	entry.val = xa_to_value(arg);
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  159  	return entry;
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  160  }
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  161  
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  162  static inline void *swp_to_radix_entry(swp_entry_t entry)
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  163  {
3159f943aafdba Matthew Wilcox                 2017-11-03  164  	return xa_mk_value(entry.val);
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  165  }
a2c16d6cb0e478 Hugh Dickins                   2011-08-03  166  

5042db43cc26f5 Jérôme Glisse 2017-09-08 167 #if IS_ENABLED(CONFIG_DEVICE_PRIVATE)
4dd845b5a3e57a Alistair Popple 2021-06-30 168 static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset)
5042db43cc26f5 Jérôme Glisse 2017-09-08 169 {
4dd845b5a3e57a Alistair Popple 2021-06-30 170 return swp_entry(SWP_DEVICE_READ, offset);

5042db43cc26f5 Jérôme Glisse                  2017-09-08  171  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  172  
4dd845b5a3e57a Alistair Popple                2021-06-30  173  static inline swp_entry_t make_writable_device_private_entry(pgoff_t offset)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  174  {
4dd845b5a3e57a Alistair Popple                2021-06-30  175  	return swp_entry(SWP_DEVICE_WRITE, offset);
5042db43cc26f5 Jérôme Glisse                  2017-09-08  176  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  177  
4dd845b5a3e57a Alistair Popple                2021-06-30  178  static inline bool is_device_private_entry(swp_entry_t entry)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  179  {
4dd845b5a3e57a Alistair Popple                2021-06-30  180  	int type = swp_type(entry);
4dd845b5a3e57a Alistair Popple                2021-06-30  181  	return type == SWP_DEVICE_READ || type == SWP_DEVICE_WRITE;
5042db43cc26f5 Jérôme Glisse                  2017-09-08  182  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  183  
4dd845b5a3e57a Alistair Popple                2021-06-30  184  static inline bool is_writable_device_private_entry(swp_entry_t entry)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  185  {
5042db43cc26f5 Jérôme Glisse                  2017-09-08  186  	return unlikely(swp_type(entry) == SWP_DEVICE_WRITE);
5042db43cc26f5 Jérôme Glisse                  2017-09-08  187  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  188  
c25465eb7630ff David Hildenbrand              2025-02-10  189  static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset)
b756a3b5e7ead8 Alistair Popple                2021-06-30  190  {
c25465eb7630ff David Hildenbrand              2025-02-10  191  	return swp_entry(SWP_DEVICE_EXCLUSIVE, offset);
b756a3b5e7ead8 Alistair Popple                2021-06-30  192  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  193  
b756a3b5e7ead8 Alistair Popple                2021-06-30  194  static inline bool is_device_exclusive_entry(swp_entry_t entry)
b756a3b5e7ead8 Alistair Popple                2021-06-30  195  {
c25465eb7630ff David Hildenbrand              2025-02-10  196  	return swp_type(entry) == SWP_DEVICE_EXCLUSIVE;
b756a3b5e7ead8 Alistair Popple                2021-06-30  197  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  198  
5042db43cc26f5 Jérôme Glisse                  2017-09-08  199  #else /* CONFIG_DEVICE_PRIVATE */
4dd845b5a3e57a Alistair Popple                2021-06-30  200  static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  201  {
5042db43cc26f5 Jérôme Glisse                  2017-09-08  202  	return swp_entry(0, 0);
5042db43cc26f5 Jérôme Glisse                  2017-09-08  203  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  204  
4dd845b5a3e57a Alistair Popple                2021-06-30  205  static inline swp_entry_t make_writable_device_private_entry(pgoff_t offset)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  206  {
4dd845b5a3e57a Alistair Popple                2021-06-30  207  	return swp_entry(0, 0);
5042db43cc26f5 Jérôme Glisse                  2017-09-08  208  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  209  
5042db43cc26f5 Jérôme Glisse                  2017-09-08  210  static inline bool is_device_private_entry(swp_entry_t entry)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  211  {
5042db43cc26f5 Jérôme Glisse                  2017-09-08  212  	return false;
5042db43cc26f5 Jérôme Glisse                  2017-09-08  213  }
5042db43cc26f5 Jérôme Glisse                  2017-09-08  214  
4dd845b5a3e57a Alistair Popple                2021-06-30  215  static inline bool is_writable_device_private_entry(swp_entry_t entry)
5042db43cc26f5 Jérôme Glisse                  2017-09-08  216  {
5042db43cc26f5 Jérôme Glisse                  2017-09-08  217  	return false;
5042db43cc26f5 Jérôme Glisse                  2017-09-08  218  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  219  
c25465eb7630ff David Hildenbrand              2025-02-10  220  static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset)
b756a3b5e7ead8 Alistair Popple                2021-06-30  221  {
b756a3b5e7ead8 Alistair Popple                2021-06-30  222  	return swp_entry(0, 0);
b756a3b5e7ead8 Alistair Popple                2021-06-30  223  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  224  
b756a3b5e7ead8 Alistair Popple                2021-06-30  225  static inline bool is_device_exclusive_entry(swp_entry_t entry)
b756a3b5e7ead8 Alistair Popple                2021-06-30  226  {
b756a3b5e7ead8 Alistair Popple                2021-06-30  227  	return false;
b756a3b5e7ead8 Alistair Popple                2021-06-30  228  }
b756a3b5e7ead8 Alistair Popple                2021-06-30  229  
5042db43cc26f5 Jérôme Glisse                  2017-09-08  230  #endif /* CONFIG_DEVICE_PRIVATE */
5042db43cc26f5 Jérôme Glisse                  2017-09-08  231  
0697212a411c1d Christoph Lameter              2006-06-23  232  #ifdef CONFIG_MIGRATION
0697212a411c1d Christoph Lameter              2006-06-23  233  static inline int is_migration_entry(swp_entry_t entry)
0697212a411c1d Christoph Lameter              2006-06-23  234  {
0697212a411c1d Christoph Lameter              2006-06-23 @235  	return unlikely(swp_type(entry) == SWP_MIGRATION_READ ||
6c287605fd5646 David Hildenbrand              2022-05-09 @236  			swp_type(entry) == SWP_MIGRATION_READ_EXCLUSIVE ||
0697212a411c1d Christoph Lameter              2006-06-23 @237  			swp_type(entry) == SWP_MIGRATION_WRITE);
0697212a411c1d Christoph Lameter              2006-06-23  238  }
0697212a411c1d Christoph Lameter              2006-06-23  239  
4dd845b5a3e57a Alistair Popple                2021-06-30  240  static inline int is_writable_migration_entry(swp_entry_t entry)
0697212a411c1d Christoph Lameter              2006-06-23  241  {
0697212a411c1d Christoph Lameter              2006-06-23  242  	return unlikely(swp_type(entry) == SWP_MIGRATION_WRITE);
0697212a411c1d Christoph Lameter              2006-06-23  243  }
0697212a411c1d Christoph Lameter              2006-06-23  244  
6c287605fd5646 David Hildenbrand              2022-05-09  245  static inline int is_readable_migration_entry(swp_entry_t entry)
6c287605fd5646 David Hildenbrand              2022-05-09  246  {
6c287605fd5646 David Hildenbrand              2022-05-09  247  	return unlikely(swp_type(entry) == SWP_MIGRATION_READ);
6c287605fd5646 David Hildenbrand              2022-05-09  248  }
6c287605fd5646 David Hildenbrand              2022-05-09  249  
6c287605fd5646 David Hildenbrand              2022-05-09  250  static inline int is_readable_exclusive_migration_entry(swp_entry_t entry)
6c287605fd5646 David Hildenbrand              2022-05-09  251  {
6c287605fd5646 David Hildenbrand              2022-05-09  252  	return unlikely(swp_type(entry) == SWP_MIGRATION_READ_EXCLUSIVE);
6c287605fd5646 David Hildenbrand              2022-05-09  253  }
6c287605fd5646 David Hildenbrand              2022-05-09  254  
4dd845b5a3e57a Alistair Popple                2021-06-30  255  static inline swp_entry_t make_readable_migration_entry(pgoff_t offset)
0697212a411c1d Christoph Lameter              2006-06-23  256  {
4dd845b5a3e57a Alistair Popple                2021-06-30  257  	return swp_entry(SWP_MIGRATION_READ, offset);
4dd845b5a3e57a Alistair Popple                2021-06-30  258  }
4dd845b5a3e57a Alistair Popple                2021-06-30  259  
6c287605fd5646 David Hildenbrand              2022-05-09  260  static inline swp_entry_t make_readable_exclusive_migration_entry(pgoff_t offset)
6c287605fd5646 David Hildenbrand              2022-05-09  261  {
6c287605fd5646 David Hildenbrand              2022-05-09 @262  	return swp_entry(SWP_MIGRATION_READ_EXCLUSIVE, offset);
6c287605fd5646 David Hildenbrand              2022-05-09  263  }
6c287605fd5646 David Hildenbrand              2022-05-09  264  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#6 lore raw

PATCH v4 4/4 KVM: s390: simplify and move pv code

In reply to Claudio Imbrenda

All functions in kvm/gmap.c fit better in kvm/pv.c instead. Move and rename them appropriately, then delete the now empty kvm/gmap.c and kvm/gmap.h.

---
 arch/s390/kernel/uv.c     |  12 ++--
 arch/s390/kvm/Makefile    |   2 +-
 arch/s390/kvm/gaccess.c   |   3 +-
 arch/s390/kvm/gmap-vsie.c |   1 -
 arch/s390/kvm/gmap.c      | 121 --------------------------------------
 arch/s390/kvm/gmap.h      |  39 ------------
 arch/s390/kvm/intercept.c |  10 +---
 arch/s390/kvm/kvm-s390.c  |   5 +-
 arch/s390/kvm/kvm-s390.h  |  42 +++++++++++++
 arch/s390/kvm/pv.c        |  61 ++++++++++++++++++-
 arch/s390/kvm/vsie.c      |  19 +++++-
 11 files changed, 133 insertions(+), 182 deletions(-)
 delete mode 100644 arch/s390/kvm/gmap.c
 delete mode 100644 arch/s390/kvm/gmap.h
arch/s390/kernel/uv.c +6 -6
index 9a5d5be8acf4..644c110287c4 100644
@@ -135,7 +135,7 @@ int uv_destroy_folio(struct folio *folio)
 {
 	int rc;
 
-	/* See gmap_make_secure(): large folios cannot be secure */
+	/* Large folios cannot be secure */
 	if (unlikely(folio_test_large(folio)))
 		return 0;
 
@@ -184,7 +184,7 @@ int uv_convert_from_secure_folio(struct folio *folio)
 {
 	int rc;
 
-	/* See gmap_make_secure(): large folios cannot be secure */
+	/* Large folios cannot be secure */
 	if (unlikely(folio_test_large(folio)))
 		return 0;
 
@@ -403,15 +403,15 @@ EXPORT_SYMBOL_GPL(make_hva_secure);
 
 /*
  * To be called with the folio locked or with an extra reference! This will
- * prevent gmap_make_secure from touching the folio concurrently. Having 2
- * parallel arch_make_folio_accessible is fine, as the UV calls will become a
- * no-op if the folio is already exported.
+ * prevent kvm_s390_pv_make_secure() from touching the folio concurrently.
+ * Having 2 parallel arch_make_folio_accessible is fine, as the UV calls will
+ * become a no-op if the folio is already exported.
  */
 int arch_make_folio_accessible(struct folio *folio)
 {
 	int rc = 0;
 
-	/* See gmap_make_secure(): large folios cannot be secure */
+	/* Large folios cannot be secure */
 	if (unlikely(folio_test_large(folio)))
 		return 0;
 
arch/s390/kvm/Makefile +1 -1
index f0ffe874adc2..9a723c48b05a 100644
@@ -8,7 +8,7 @@ include $(srctree)/virt/kvm/Makefile.kvm
 ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
 
 kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
-kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o gmap.o gmap-vsie.o
+kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o gmap-vsie.o
 
 kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
 obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/gaccess.c +2 -1
index f6fded15633a..e23670e1949c 100644
@@ -16,9 +16,10 @@
 #include <asm/gmap.h>
 #include <asm/dat-bits.h>
 #include "kvm-s390.h"
-#include "gmap.h"
 #include "gaccess.h"
 
+#define GMAP_SHADOW_FAKE_TABLE 1ULL
+
 /*
  * vaddress union in order to easily decode a virtual address into its
  * region first index, region second index etc. parts.
arch/s390/kvm/gmap-vsie.c +0 -1
index a6d1dbb04c97..56ef153eb8fe 100644
@@ -22,7 +22,6 @@
 #include <asm/uv.h>
 
 #include "kvm-s390.h"
-#include "gmap.h"
 
 /**
  * gmap_find_shadow - find a specific asce in the list of shadow tables
arch/s390/kvm/gmap.c deleted +0 -121

121 lines not on this page · raw message

arch/s390/kvm/gmap.h deleted +0 -39
deleted file mode 100644
index c8f031c9ea5f..000000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- *  KVM guest address space mapping code
- *
- *    Copyright IBM Corp. 2007, 2016, 2025
- *    Author(s): Martin Schwidefsky <[email protected]>
- *               Claudio Imbrenda <[email protected]>
- */
-
-#ifndef ARCH_KVM_S390_GMAP_H
-#define ARCH_KVM_S390_GMAP_H
-
-#define GMAP_SHADOW_FAKE_TABLE 1ULL
-
-int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb);
-int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr);
-int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr);
-struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, int edat_level);
-
-/**
- * gmap_shadow_valid - check if a shadow guest address space matches the
- *                     given properties and is still valid
- * @sg: pointer to the shadow guest address space structure
- * @asce: ASCE for which the shadow table is requested
- * @edat_level: edat level to be used for the shadow translation
- *
- * Returns 1 if the gmap shadow is still valid and matches the given
- * properties, the caller can continue using it. Returns 0 otherwise, the
- * caller has to request a new shadow gmap in this case.
- *
- */
-static inline int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level)
-{
-	if (sg->removed)
-		return 0;
-	return sg->orig_asce == asce && sg->edat_level == edat_level;
-}
-
-#endif
arch/s390/kvm/intercept.c +3 -7
index b4834bd4d216..c7908950c1f4 100644
@@ -16,13 +16,11 @@
 #include <asm/irq.h>
 #include <asm/sysinfo.h>
 #include <asm/uv.h>
-#include <asm/gmap.h>
 
 #include "kvm-s390.h"
 #include "gaccess.h"
 #include "trace.h"
 #include "trace-s390.h"
-#include "gmap.h"
 
 u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu)
 {
@@ -546,7 +544,7 @@ static int handle_pv_uvc(struct kvm_vcpu *vcpu)
 			  guest_uvcb->header.cmd);
 		return 0;
 	}
-	rc = gmap_make_secure(vcpu->arch.gmap, uvcb.gaddr, &uvcb);
+	rc = kvm_s390_pv_make_secure(vcpu->kvm, uvcb.gaddr, &uvcb);
 	/*
 	 * If the unpin did not succeed, the guest will exit again for the UVC
 	 * and we will retry the unpin.
@@ -654,10 +652,8 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
 		break;
 	case ICPT_PV_PREF:
 		rc = 0;
-		gmap_convert_to_secure(vcpu->arch.gmap,
-				       kvm_s390_get_prefix(vcpu));
-		gmap_convert_to_secure(vcpu->arch.gmap,
-				       kvm_s390_get_prefix(vcpu) + PAGE_SIZE);
+		kvm_s390_pv_convert_to_secure(vcpu->kvm, kvm_s390_get_prefix(vcpu));
+		kvm_s390_pv_convert_to_secure(vcpu->kvm, kvm_s390_get_prefix(vcpu) + PAGE_SIZE);
 		break;
 	default:
 		return -EOPNOTSUPP;
arch/s390/kvm/kvm-s390.c +2 -3
index 10cfc047525d..d5ad10791c25 100644
@@ -53,7 +53,6 @@
 #include "kvm-s390.h"
 #include "gaccess.h"
 #include "pci.h"
-#include "gmap.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace.h"
@@ -4976,7 +4975,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
 		 * previous protected guest. The old pages need to be destroyed
 		 * so the new guest can use them.
 		 */
-		if (gmap_destroy_page(vcpu->arch.gmap, gaddr)) {
+		if (kvm_s390_pv_destroy_page(vcpu->kvm, gaddr)) {
 			/*
 			 * Either KVM messed up the secure guest mapping or the
 			 * same page is mapped into multiple secure guests.
@@ -4998,7 +4997,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
 		 * guest has not been imported yet. Try to import the page into
 		 * the protected guest.
 		 */
-		rc = gmap_convert_to_secure(vcpu->arch.gmap, gaddr);
+		rc = kvm_s390_pv_convert_to_secure(vcpu->kvm, gaddr);
 		if (rc == -EINVAL)
 			send_sig(SIGSEGV, current, 0);
 		if (rc != -ENXIO)
arch/s390/kvm/kvm-s390.h +42 -0

60 lines not on this page · raw message

arch/s390/kvm/pv.c +59 -2

79 lines not on this page · raw message

arch/s390/kvm/vsie.c +18 -1
index a78df3a4f353..13a9661d2b28 100644
@@ -23,7 +23,6 @@
 #include <asm/facility.h>
 #include "kvm-s390.h"
 #include "gaccess.h"
-#include "gmap.h"
 
 enum vsie_page_flags {
 	VSIE_PAGE_IN_USE = 0,
@@ -68,6 +67,24 @@ struct vsie_page {
 	__u8 fac[S390_ARCH_FAC_LIST_SIZE_BYTE];	/* 0x0800 */
 };
 
+/**
+ * gmap_shadow_valid() - check if a shadow guest address space matches the
+ *                       given properties and is still valid
+ * @sg: pointer to the shadow guest address space structure
+ * @asce: ASCE for which the shadow table is requested
+ * @edat_level: edat level to be used for the shadow translation
+ *
+ * Returns 1 if the gmap shadow is still valid and matches the given
+ * properties, the caller can continue using it. Returns 0 otherwise; the
+ * caller has to request a new shadow gmap in this case.
+ */
+int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level)
+{
+	if (sg->removed)
+		return 0;
+	return sg->orig_asce == asce && sg->edat_level == edat_level;
+}
+
 /* trigger a validity icpt for the given scb */
 static int set_validity_icpt(struct kvm_s390_sie_block *scb,
 			     __u16 reason_code)
Signature · 1 line
2.49.0