| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/20 21:03 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch series exclusively modifies s390 architecture code (arch/s390, drivers/s390, and tools/testing/selftests/kvm/include/s390). Because the target architecture is amd64, all modified code paths are structurally unreachable and cannot be built or executed on the target architecture.",
"WorthFuzzing": false
} |
| 1/1 | 2026/09/20 21:03 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 916c012515bb06ef4903e61a4af5b1f93480b60b\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Sep 20 21:03:52 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/kvm_host_s390.h\nindex cd692f8fb7643..a19d3a5f550ce 100644\n--- a/arch/s390/include/asm/kvm_host_s390.h\n+++ b/arch/s390/include/asm/kvm_host_s390.h\n@@ -412,6 +412,10 @@ struct kvm_vm_stat {\n \tu64 gmap_shadow_r3_entry;\n \tu64 gmap_shadow_sg_entry;\n \tu64 gmap_shadow_pg_entry;\n+\tu64 vsie_shadow_scb;\n+\tu64 vsie_shadow_scb_reuse;\n+\tu64 vsie_shadow_sca;\n+\tu64 vsie_shadow_sca_reuse;\n };\n \n struct kvm_arch_memory_slot {\n@@ -572,13 +576,32 @@ struct sie_page2 {\n };\n \n struct vsie_page;\n+struct vsie_sca;\n \n+/*\n+ * vsie_pages, scas and accompanied management vars\n+ */\n struct kvm_s390_vsie {\n+\t/*\n+\t * protects pages[], page_count, next, addr_to_page\n+\t */\n \tstruct mutex mutex;\n-\tstruct radix_tree_root addr_to_page;\n+\tstruct xarray addr_to_page;\n \tint page_count;\n \tint next;\n-\tstruct vsie_page *pages[KVM_MAX_VCPUS];\n+\tstruct vsie_page *pages[KVM_S390_MAX_VSIE_VCPUS];\n+\t/*\n+\t * The vsie_sca_lock is used to synchronize access to\n+\t * - the kvm_s390_vsie.scas[]\n+\t * - the kvm_s390_vsie.osca_to_sca map\n+\t * - sca_count and sca_next\n+\t * - new vsie_sca creation and initialization\n+\t */\n+\tstruct rw_semaphore vsie_sca_lock;\n+\tstruct xarray osca_to_sca;\n+\tint sca_count;\n+\tint sca_next;\n+\tstruct vsie_sca *scas[KVM_S390_MAX_VSIE_VCPUS];\n };\n \n struct kvm_s390_gisa_iam {\n@@ -623,6 +646,7 @@ struct kvm_arch {\n \tint use_pfmfi;\n \tint use_skf;\n \tint use_zpci_interp;\n+\tint use_ssca;\n \tint user_cpu_state_ctrl;\n \tint user_sigp;\n \tint user_stsi;\ndiff --git a/arch/s390/include/asm/kvm_host_s390_types.h b/arch/s390/include/asm/kvm_host_s390_types.h\nindex 9e348a5304217..6eef71072b4ed 100644\n--- a/arch/s390/include/asm/kvm_host_s390_types.h\n+++ b/arch/s390/include/asm/kvm_host_s390_types.h\n@@ -6,10 +6,15 @@\n #include \u003clinux/atomic.h\u003e\n #include \u003clinux/types.h\u003e\n \n+#define KVM_S390_CPU_MASK 0xff\n+#define KVM_S390_MAX_VSIE_VCPUS 256\n+#define KVM_S390_MAX_SCA_PAGES 5\n+\n #define KVM_S390_BSCA_CPU_SLOTS 64\n #define KVM_S390_ESCA_CPU_SLOTS 248\n \n #define SCB_ALIGNMENT_SHIFT 9\n+#define SCA_ALIGNMENT_SHIFT 6\n \n #define SIGP_CTRL_C\t\t0x80\n #define SIGP_CTRL_SCN_MASK\t0x3f\n@@ -47,6 +52,13 @@ struct bsca_entry {\n \t__u64\treserved2[2];\n };\n \n+struct ssca_entry {\n+\t__u64\treserved1;\n+\t__u64\tssda;\n+\t__u64\tossea;\n+\t__u64\treserved2;\n+};\n+\n union ipte_control {\n \tunsigned long val;\n \tstruct {\n@@ -88,6 +100,20 @@ struct esca_block {\n \tstruct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];\n };\n \n+/*\n+ * The shadow sca / ssca needs to cover both bsca and esca depending on what the\n+ * guest uses so we allocate space for 256 entries that are defined in the\n+ * architecture.\n+ * The header part of the struct must not cross page boundaries.\n+ */\n+struct ssca_block {\n+\t__u64\tosca;\n+\t__u64\treserved08[7];\n+\tstruct ssca_entry cpu[KVM_S390_MAX_VSIE_VCPUS];\n+};\n+\n+static_assert(offsetof(struct ssca_block, cpu) == 64);\n+\n /*\n * This struct is used to store some machine check info from lowcore\n * for machine checks that happen while the guest is running.\n@@ -317,7 +343,7 @@ struct kvm_s390_sie_block {\n \t__u32\tfac;\t\t\t/* 0x01a0 */\n \t__u8\treserved1a4[20];\t/* 0x01a4 */\n \t__u64\tcbrlo;\t\t\t/* 0x01b8 */\n-\t__u8\treserved1c0[8];\t\t/* 0x01c0 */\n+\t__u64\tosda;\t\t\t/* 0x01c0 */\n #define ECD_HOSTREGMGMT\t0x20000000\n #define ECD_MEF\t\t0x08000000\n #define ECD_ETOKENF\t0x02000000\ndiff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h\nindex 44066550b9b10..9e960c09ce0b3 100644\n--- a/arch/s390/include/asm/sclp.h\n+++ b/arch/s390/include/asm/sclp.h\n@@ -105,6 +105,7 @@ struct sclp_info {\n \tunsigned char has_dirq : 1;\n \tunsigned char has_iplcc : 1;\n \tunsigned char has_zpci_lsi : 1;\n+\tunsigned char has_vsie_interp_extf : 1;\n \tunsigned char has_aisii : 1;\n \tunsigned char has_aeni : 1;\n \tunsigned char has_aisi : 1;\ndiff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c\nindex 5c73f43782a74..0d4480bd2cac3 100644\n--- a/arch/s390/kvm/s390/s390.c\n+++ b/arch/s390/kvm/s390/s390.c\n@@ -87,6 +87,10 @@ const struct kvm_stats_desc kvm_vm_stats_desc[] = {\n \tSTATS_DESC_COUNTER(VM, gmap_shadow_r3_entry),\n \tSTATS_DESC_COUNTER(VM, gmap_shadow_sg_entry),\n \tSTATS_DESC_COUNTER(VM, gmap_shadow_pg_entry),\n+\tSTATS_DESC_COUNTER(VM, vsie_shadow_scb),\n+\tSTATS_DESC_COUNTER(VM, vsie_shadow_scb_reuse),\n+\tSTATS_DESC_COUNTER(VM, vsie_shadow_sca),\n+\tSTATS_DESC_COUNTER(VM, vsie_shadow_sca_reuse),\n };\n \n const struct kvm_stats_header kvm_vm_stats_header = {\n@@ -244,6 +248,11 @@ static int async_destroy = 1;\n module_param(async_destroy, int, 0444);\n MODULE_PARM_DESC(async_destroy, \"Asynchronous destroy for protected guests\");\n \n+/* allow vsie sigp and srs interpretation if available */\n+static bool ssca = true;\n+module_param(ssca, bool, 0444);\n+MODULE_PARM_DESC(ssca, \"VSIE SIGPI and SRSI using the SSCA\");\n+\n #define HMFAI_DWORDS 16\n /*\n * Base feature mask that defines default mask for facilities. Consists of the\n@@ -473,6 +482,8 @@ static void __init kvm_s390_cpu_feat_init(void)\n \t\tallow_cpu_feat(KVM_S390_VM_CPU_FEAT_KSS);\n \tif (sclp.has_astfleie2)\n \t\tallow_cpu_feat(KVM_S390_VM_CPU_FEAT_ASTFLEIE2);\n+\tif (sclp.has_vsie_interp_extf \u0026\u0026 ssca)\n+\t\tallow_cpu_feat(KVM_S390_VM_CPU_FEAT_SIGPIF);\n \t/*\n \t * KVM_S390_VM_CPU_FEAT_SKEY: Wrong shadow of PTE.I bits will make\n \t * all skey handling functions read/set the skey from the PGSTE\n@@ -487,9 +498,6 @@ static void __init kvm_s390_cpu_feat_init(void)\n \t * For KVM_S390_VM_CPU_FEAT_SKEY, KVM_S390_VM_CPU_FEAT_CMMA and\n \t * KVM_S390_VM_CPU_FEAT_PFMFI, all PTE.I and PGSTE bits have to be\n \t * correctly shadowed. We can do that for the PGSTE but not for PTE.I.\n-\t *\n-\t * KVM_S390_VM_CPU_FEAT_SIGPIF: Wrong SCB addresses in the SCA. We\n-\t * cannot easily shadow the SCA because of the ipte lock.\n \t */\n }\n \n@@ -3359,6 +3367,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)\n \n \tkvm-\u003earch.use_pfmfi = sclp.has_pfmfi;\n \tkvm-\u003earch.use_skf = sclp.has_skey;\n+\tkvm-\u003earch.use_ssca = sclp.has_vsie_interp_extf \u0026\u0026 ssca;\n \tspin_lock_init(\u0026kvm-\u003earch.start_stop_lock);\n \tkvm_s390_vsie_init(kvm);\n \tif (use_gisa)\ndiff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c\nindex 5926689fa2267..04c14d33927a6 100644\n--- a/arch/s390/kvm/s390/vsie.c\n+++ b/arch/s390/kvm/s390/vsie.c\n@@ -29,6 +29,7 @@\n \n enum vsie_page_flags {\n \tVSIE_PAGE_IN_USE = 0,\n+\tVSIE_PAGE_SCB_PINNED = 1,\n };\n \n struct vsie_page {\n@@ -56,13 +57,13 @@ struct vsie_page {\n \tgpa_t sdnx_gpa;\t\t\t\t/* 0x0250 */\n \t/*\n \t * guest address of the original SCB. Remains set for free vsie\n-\t * pages, so we can properly look them up in our addr_to_page\n-\t * radix tree.\n+\t * pages, so we can properly look them up in our addr_to_page map.\n \t */\n \tgpa_t scb_gpa;\t\t\t\t/* 0x0258 */\n \t/* the shadow gmap in use by the vsie_page */\n \tstruct gmap_cache gmap_cache;\t\t/* 0x0260 */\n-\t__u8 reserved[0x06f8 - 0x0278];\t\t/* 0x0278 */\n+\tstruct vsie_sca *vsie_sca;\t\t/* 0x0278 */\n+\t__u8 reserved[0x06f8 - 0x0280];\t\t/* 0x0280 */\n \tstruct kvm_s390_crypto_cb crycb;\t/* 0x06f8 */\n \t__u8 fac[8 + S390_ARCH_FAC_LIST_SIZE_BYTE];/* 0x07f8 */\n };\n@@ -71,6 +72,90 @@ static_assert(sizeof(struct vsie_page) == PAGE_SIZE);\n static_assert(offsetof(struct vsie_page, mcck_info) == offsetof(struct sie_page, mcck_info));\n static_assert(IS_ALIGNED(offsetof(struct vsie_page, crycb), 8));\n \n+struct kvm_address_pair {\n+\tgpa_t gpa;\n+\thpa_t hpa;\n+};\n+\n+enum vsie_sca_flags {\n+\tVSIE_SCA_ESCA = 0,\n+\tVSIE_SCA_SCA_PINNED = 1,\n+};\n+\n+struct vsie_sca {\n+\tstruct_group(head,\n+\t\tstruct ssca_block\tssca;\n+\t);\n+\tstruct_group(keep,\n+\t\tstruct vsie_page\t*pages[KVM_S390_MAX_VSIE_VCPUS];\n+\t\t/* The mutex is used to synchronize access to the pages[] */\n+\t\tstruct mutex\t\tmutex;\n+\t\tatomic_t\t\tref_count;\n+\t);\n+\tstruct_group(tail,\n+\t\tgpa_t\t\t\tsca_gpa;\n+\t\tunsigned long\t\tflags;\n+\t\tu64\t\t\tmcn[4];\n+\t\tunsigned int\t\tsca_o_nr_pages;\n+\t\tstruct kvm_address_pair\tsca_o_pages[KVM_S390_MAX_SCA_PAGES];\n+\t);\n+};\n+\n+/*\n+ * SSCA needs to be 32-byte aligned and members before the cpu field need to be on the same page.\n+ * Forcing it to offset 0 will always fulfill the requirements.\n+ */\n+static_assert(!(offsetof(struct vsie_sca, ssca)));\n+\n+/* maximum vsie shadow scb */\n+static unsigned int vsie_shadow_scb_max = 1;\n+module_param(vsie_shadow_scb_max, uint, 0644);\n+MODULE_PARM_DESC(vsie_shadow_scb_max, \"Maximum number of VSIE shadow control blocks to keep. Values smaller number VCPUs uses number of VCPUs; maximum 256\");\n+\n+/* maximum vsie shadow sca */\n+static unsigned int vsie_shadow_sca_max = 1;\n+module_param(vsie_shadow_sca_max, uint, 0644);\n+MODULE_PARM_DESC(vsie_shadow_sca_max, \"Maximum number of VSIE shadow system control areas to keep. Values smaller number of VCPUs uses number of VCPUs; maximum 256\");\n+\n+static inline hpa_t sca_o_hpa(struct vsie_sca *vsie_sca)\n+{\n+\treturn vsie_sca-\u003esca_o_pages[0].hpa | (vsie_sca-\u003esca_gpa \u0026 ~PAGE_MASK);\n+}\n+\n+static inline bool sie_uses_esca(struct kvm_s390_sie_block *scb)\n+{\n+\treturn (scb-\u003eecb2 \u0026 ECB2_ESCA);\n+}\n+\n+static unsigned long read_scao(struct kvm *kvm, struct kvm_s390_sie_block *scb)\n+{\n+\tunsigned long vsie_sca = READ_ONCE(scb-\u003escaol) \u0026 ~0xfUL;\n+\n+\tif (test_kvm_cpu_feat(kvm, KVM_S390_VM_CPU_FEAT_64BSCAO))\n+\t\tvsie_sca |= (u64)READ_ONCE(scb-\u003escaoh) \u003c\u003c 32;\n+\n+\treturn vsie_sca;\n+}\n+\n+static void write_scao(struct kvm_s390_sie_block *scb, unsigned long hpa)\n+{\n+\tscb-\u003escaoh = (u32)((u64)hpa \u003e\u003e 32);\n+\tscb-\u003escaol = (u32)(u64)hpa;\n+}\n+\n+static inline bool use_ssca(struct kvm *kvm, struct kvm_s390_sie_block *scb)\n+{\n+\tif (!kvm-\u003earch.use_ssca)\n+\t\treturn false;\n+\tif (!test_kvm_cpu_feat(kvm, KVM_S390_VM_CPU_FEAT_SIGPIF))\n+\t\treturn false;\n+\tif (!(scb-\u003eeca \u0026 ECA_SIGPI) \u0026\u0026 !(scb-\u003eecb \u0026 ECB_SRSI))\n+\t\treturn false;\n+\tif (!read_scao(kvm, scb))\n+\t\treturn false;\n+\treturn true;\n+}\n+\n /* trigger a validity icpt for the given scb */\n static int set_validity_icpt(struct kvm_s390_sie_block *scb,\n \t\t\t __u16 reason_code)\n@@ -81,6 +166,25 @@ static int set_validity_icpt(struct kvm_s390_sie_block *scb,\n \treturn 1;\n }\n \n+/* The sca header must not cross pages etc. */\n+static int validate_scao(struct kvm_vcpu *vcpu, struct kvm_s390_sie_block *scb, gpa_t gpa)\n+{\n+\tint offset;\n+\n+\tif (gpa \u003c 2 * PAGE_SIZE)\n+\t\treturn set_validity_icpt(scb, 0x0038U);\n+\tif ((gpa \u0026 ~0x1fffUL) == kvm_s390_get_prefix(vcpu))\n+\t\treturn set_validity_icpt(scb, 0x0011U);\n+\n+\tif (sie_uses_esca(scb))\n+\t\toffset = offsetof(struct esca_block, cpu[0]) - 1;\n+\telse\n+\t\toffset = offsetof(struct bsca_block, cpu[0]) - 1;\n+\tif ((gpa \u0026 PAGE_MASK) != ((gpa + offset) \u0026 PAGE_MASK))\n+\t\treturn set_validity_icpt(scb, 0x003bU);\n+\treturn 0;\n+}\n+\n /* mark the prefix as unmapped, this will block the VSIE */\n static void prefix_unmapped(struct vsie_page *vsie_page)\n {\n@@ -109,6 +213,148 @@ static int prefix_is_mapped(struct vsie_page *vsie_page)\n \treturn !(atomic_read(\u0026vsie_page-\u003escb_s.prog20) \u0026 PROG_REQUEST);\n }\n \n+static void release_gmap_shadow(struct vsie_page *vsie_page)\n+{\n+\tstruct gmap *gmap = vsie_page-\u003egmap_cache.gmap;\n+\n+\tlockdep_assert_held(\u0026gmap-\u003ekvm-\u003earch.gmap-\u003echildren_lock);\n+\n+\tlist_del(\u0026vsie_page-\u003egmap_cache.list);\n+\tvsie_page-\u003egmap_cache.gmap = NULL;\n+\tprefix_unmapped(vsie_page);\n+\n+\tif (list_empty(\u0026gmap-\u003escb_users)) {\n+\t\tgmap_remove_child(gmap);\n+\t\tgmap_put(gmap);\n+\t}\n+}\n+\n+static void release_gmap_shadow_safe(struct kvm *kvm, struct vsie_page *vsie_page)\n+{\n+\tif (!vsie_page-\u003egmap_cache.gmap)\n+\t\treturn;\n+\n+\tguard(spinlock)(\u0026kvm-\u003earch.gmap-\u003echildren_lock);\n+\n+\tif (vsie_page-\u003egmap_cache.gmap)\n+\t\trelease_gmap_shadow(vsie_page);\n+}\n+\n+static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n+{\n+\tunion ctlreg0 cr0;\n+\tstruct gmap *gmap;\n+\tunion asce asce;\n+\tint edat;\n+\n+\tasce.val = vcpu-\u003earch.sie_block-\u003egcr[1];\n+\tcr0.val = vcpu-\u003earch.sie_block-\u003egcr[0];\n+\tedat = cr0.edat \u0026\u0026 test_kvm_facility(vcpu-\u003ekvm, 8);\n+\tedat += edat \u0026\u0026 test_kvm_facility(vcpu-\u003ekvm, 78);\n+\n+\tscoped_guard(spinlock, \u0026vcpu-\u003ekvm-\u003earch.gmap-\u003echildren_lock) {\n+\t\tgmap = vsie_page-\u003egmap_cache.gmap;\n+\t\tif (gmap) {\n+\t\t\t/*\n+\t\t\t * ASCE or EDAT could have changed since last icpt, or the gmap\n+\t\t\t * we're holding has been unshadowed. If the gmap is still valid,\n+\t\t\t * we can safely reuse it.\n+\t\t\t */\n+\t\t\tif (gmap_is_shadow_valid(gmap, asce, edat)) {\n+\t\t\t\tvcpu-\u003ekvm-\u003estat.gmap_shadow_reuse++;\n+\t\t\t\tgmap_get(gmap);\n+\t\t\t\treturn gmap;\n+\t\t\t}\n+\t\t\t/* release the old shadow and mark the prefix as unmapped */\n+\t\t\trelease_gmap_shadow(vsie_page);\n+\t\t}\n+\t}\n+again:\n+\tgmap = gmap_create_shadow(vcpu-\u003earch.mc, vcpu-\u003ekvm-\u003earch.gmap, asce, edat);\n+\tif (IS_ERR(gmap))\n+\t\treturn gmap;\n+\tscoped_guard(spinlock, \u0026vcpu-\u003ekvm-\u003earch.gmap-\u003echildren_lock) {\n+\t\t/* unlikely race condition, remove the previous shadow */\n+\t\tif (vsie_page-\u003egmap_cache.gmap)\n+\t\t\trelease_gmap_shadow(vsie_page);\n+\t\tif (!gmap-\u003eparent) {\n+\t\t\tgmap_put(gmap);\n+\t\t\tgoto again;\n+\t\t}\n+\t\tvcpu-\u003ekvm-\u003estat.gmap_shadow_create++;\n+\t\tlist_add(\u0026vsie_page-\u003egmap_cache.list, \u0026gmap-\u003escb_users);\n+\t\tvsie_page-\u003egmap_cache.gmap = gmap;\n+\t\tprefix_unmapped(vsie_page);\n+\t}\n+\treturn gmap;\n+}\n+\n+/*\n+ * Pin the guest page given by gpa and set hpa to the pinned host address.\n+ * Will always be pinned writable.\n+ *\n+ * Returns: - 0 on success\n+ * - -EINVAL if the gpa is not valid guest storage\n+ */\n+static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)\n+{\n+\tstruct page *page;\n+\n+\tpage = gfn_to_page(kvm, gpa_to_gfn(gpa));\n+\tif (!page)\n+\t\treturn -EINVAL;\n+\t*hpa = (hpa_t)page_to_phys(page) + (gpa \u0026 ~PAGE_MASK);\n+\treturn 0;\n+}\n+\n+/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */\n+static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)\n+{\n+\tkvm_release_page_dirty(pfn_to_page(phys_to_pfn(hpa)));\n+\t/* mark the page always as dirty for migration */\n+\tmark_page_dirty(kvm, gpa_to_gfn(gpa));\n+}\n+\n+/* unpin multiple guest pages pinned with pin_guest_pages() */\n+static void unpin_guest_pages(struct kvm *kvm, struct kvm_address_pair *addr, unsigned int nr_pages)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i \u003c nr_pages; i++) {\n+\t\tunpin_guest_page(kvm, addr[i].gpa, addr[i].hpa);\n+\t\taddr[i].gpa = 0;\n+\t\taddr[i].hpa = 0;\n+\t}\n+}\n+\n+/*\n+ * pin nr_pages consecutive guest pages\n+ */\n+static int pin_guest_pages(struct kvm *kvm, gpa_t gpa, unsigned int nr_pages,\n+\t\t\t struct kvm_address_pair *addr, unsigned int *nr_pages_pinned)\n+{\n+\tint rc = 0, i;\n+\thpa_t hpa;\n+\n+\tgpa = gpa \u0026 PAGE_MASK;\n+\n+\t/* the guest pages may not be mapped continuously, so pin each page */\n+\tfor (i = 0; i \u003c nr_pages; i++) {\n+\t\trc = pin_guest_page(kvm, gpa + PAGE_SIZE * i, \u0026hpa);\n+\t\tif (rc)\n+\t\t\tgoto err;\n+\t\taddr[i].gpa = gpa + PAGE_SIZE * i;\n+\t\taddr[i].hpa = hpa;\n+\t}\n+\t*nr_pages_pinned = i;\n+\treturn rc;\n+\n+err:\n+\tunpin_guest_pages(kvm, addr, i);\n+\t*nr_pages_pinned = 0;\n+\treturn rc;\n+}\n+\n /* copy the updated intervention request bits into the shadow scb */\n static void update_intervention_requests(struct vsie_page *vsie_page)\n {\n@@ -124,8 +370,7 @@ static void update_intervention_requests(struct vsie_page *vsie_page)\n static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n {\n \tstruct kvm_s390_sie_block *scb_s = \u0026vsie_page-\u003escb_s;\n-\tstruct kvm_s390_sie_block *scb_o = vsie_page-\u003escb_o;\n-\tint newflags, cpuflags = atomic_read(\u0026scb_o-\u003ecpuflags);\n+\tint newflags, cpuflags = atomic_read(\u0026vsie_page-\u003escb_o-\u003ecpuflags);\n \n \t/* we don't allow ESA/390 guests unless explicitly enabled */\n \tif (!(cpuflags \u0026 CPUSTAT_ZARCH) \u0026\u0026 !vcpu-\u003ekvm-\u003earch.allow_vsie_esamode)\n@@ -424,18 +669,27 @@ static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \t}\n }\n \n-/* unshadow the scb, copying parameters back to the real scb */\n-static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n+/*\n+ * Only write the interception fields back; avoid clobbering the timer and\n+ * guest-state fields in scb_o.\n+ */\n+static inline void unshadow_intercept(struct kvm_s390_sie_block *scb_o,\n+\t\t\t\t struct kvm_s390_sie_block *scb_s)\n {\n-\tstruct kvm_s390_sie_block *scb_s = \u0026vsie_page-\u003escb_s;\n-\tstruct kvm_s390_sie_block *scb_o = vsie_page-\u003escb_o;\n-\n-\t/* interception */\n \tscb_o-\u003eicptcode = scb_s-\u003eicptcode;\n \tscb_o-\u003eicptstatus = scb_s-\u003eicptstatus;\n \tscb_o-\u003eipa = scb_s-\u003eipa;\n \tscb_o-\u003eipb = scb_s-\u003eipb;\n \tscb_o-\u003egbea = scb_s-\u003egbea;\n+}\n+\n+/* unshadow the scb, copying parameters back to the real scb */\n+static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n+{\n+\tstruct kvm_s390_sie_block *scb_s = \u0026vsie_page-\u003escb_s;\n+\tstruct kvm_s390_sie_block *scb_o = vsie_page-\u003escb_o;\n+\n+\tunshadow_intercept(scb_o, scb_s);\n \n \t/* timer */\n \tscb_o-\u003ecputm = scb_s-\u003ecputm;\n@@ -469,6 +723,39 @@ static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \t\tscb_o-\u003eihcpu = scb_s-\u003eihcpu;\n }\n \n+static int shadow_scb_minimal(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n+{\n+\tstruct kvm_s390_sie_block *scb_s = \u0026vsie_page-\u003escb_s;\n+\tstruct kvm_s390_sie_block *scb_o = vsie_page-\u003escb_o;\n+\tint rc;\n+\n+\t/* make sure we don't have any leftovers when reusing the scb */\n+\tscb_s-\u003eicptcode = 0;\n+\tscb_s-\u003eeca = 0;\n+\tscb_s-\u003eecb = 0;\n+\tscb_s-\u003eecb2 = 0;\n+\tscb_s-\u003eecb3 = 0;\n+\tscb_s-\u003eecd = 0;\n+\tscb_s-\u003efac = 0;\n+\tscb_s-\u003efpf = 0;\n+\n+\trc = prepare_cpuflags(vcpu, vsie_page);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tscb_s-\u003eicpua = scb_o-\u003eicpua;\n+\tscb_s-\u003eecb2 |= scb_o-\u003eecb2 \u0026 ECB2_ESCA;\n+\n+\tif (vsie_page-\u003evsie_sca) {\n+\t\tscb_s-\u003eeca |= scb_o-\u003eeca \u0026 ECA_SIGPI;\n+\t\tscb_s-\u003eecb |= scb_o-\u003eecb \u0026 ECB_SRSI;\n+\t\twrite_scao(scb_s, virt_to_phys(\u0026vsie_page-\u003evsie_sca-\u003essca));\n+\t\tscb_s-\u003eosda = virt_to_phys(scb_o);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /*\n * Setup the shadow scb by copying and checking the relevant parts of the g2\n * provided scb.\n@@ -488,19 +775,9 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \tunsigned long new_mso = 0;\n \tint rc;\n \n-\t/* make sure we don't have any leftovers when reusing the scb */\n-\tscb_s-\u003eicptcode = 0;\n-\tscb_s-\u003eeca = 0;\n-\tscb_s-\u003eecb = 0;\n-\tscb_s-\u003eecb2 = 0;\n-\tscb_s-\u003eecb3 = 0;\n-\tscb_s-\u003eecd = 0;\n-\tscb_s-\u003efac = 0;\n-\tscb_s-\u003efpf = 0;\n-\n-\trc = prepare_cpuflags(vcpu, vsie_page);\n+\trc = shadow_scb_minimal(vcpu, vsie_page);\n \tif (rc)\n-\t\tgoto out;\n+\t\tgoto out_validity;\n \n \t/* timer */\n \tscb_s-\u003ecputm = scb_o-\u003ecputm;\n@@ -528,8 +805,6 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \tif (!(atomic_read(\u0026scb_s-\u003ecpuflags) \u0026 CPUSTAT_KSS))\n \t\tscb_s-\u003eictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;\n \n-\tscb_s-\u003eicpua = scb_o-\u003eicpua;\n-\n \tif (!(atomic_read(\u0026scb_s-\u003ecpuflags) \u0026 CPUSTAT_ZARCH))\n \t\tnew_prefix \u0026= GUEST_PREFIX_MASK_ESA;\n \telse\n@@ -614,10 +889,335 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \n \tprepare_ibc(vcpu, vsie_page);\n \trc = shadow_crycb(vcpu, vsie_page);\n-out:\n \tif (rc)\n \t\tunshadow_scb(vcpu, vsie_page);\n \treturn rc;\n+\n+out_validity:\n+\tunshadow_intercept(vsie_page-\u003escb_o, \u0026vsie_page-\u003escb_s);\n+\treturn rc;\n+}\n+\n+/* unpin the scb provided by guest 2, marking it as dirty */\n+static void unpin_scb(struct kvm *kvm, struct vsie_page *vsie_page)\n+{\n+\thpa_t hpa;\n+\n+\tif (!test_bit(VSIE_PAGE_SCB_PINNED, \u0026vsie_page-\u003eflags))\n+\t\treturn;\n+\n+\thpa = virt_to_phys(vsie_page-\u003escb_o);\n+\tif (hpa)\n+\t\tunpin_guest_page(kvm, vsie_page-\u003escb_gpa, hpa);\n+\tvsie_page-\u003escb_o = NULL;\n+\tclear_bit(VSIE_PAGE_SCB_PINNED, \u0026vsie_page-\u003eflags);\n+}\n+\n+/*\n+ * Pin the scb at gpa provided by guest 2 at vsie_page-\u003escb_o.\n+ *\n+ * Returns: - 0 if the scb was pinned.\n+ * - \u003e 0 if control has to be given to guest 2\n+ */\n+static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n+{\n+\thpa_t hpa;\n+\tint rc;\n+\n+\tif (test_bit(VSIE_PAGE_SCB_PINNED, \u0026vsie_page-\u003eflags))\n+\t\treturn 0;\n+\n+\trc = pin_guest_page(vcpu-\u003ekvm, vsie_page-\u003escb_gpa, \u0026hpa);\n+\tif (rc) {\n+\t\trc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);\n+\t\tWARN_ON_ONCE(rc);\n+\t\treturn 1;\n+\t}\n+\tvsie_page-\u003escb_o = phys_to_virt(hpa);\n+\tset_bit(VSIE_PAGE_SCB_PINNED, \u0026vsie_page-\u003eflags);\n+\treturn 0;\n+}\n+\n+/*\n+ * Unpin g2 original sca in g1 memory.\n+ *\n+ * Called with vsie_sca_lock held in write, except in the destroy path.\n+ */\n+static void unpin_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)\n+{\n+\tif (!test_bit(VSIE_SCA_SCA_PINNED, \u0026vsie_sca-\u003eflags))\n+\t\treturn;\n+\n+\tunpin_guest_pages(kvm, vsie_sca-\u003esca_o_pages, vsie_sca-\u003esca_o_nr_pages);\n+\tvsie_sca-\u003esca_o_nr_pages = 0;\n+\n+\tclear_bit(VSIE_SCA_SCA_PINNED, \u0026vsie_sca-\u003eflags);\n+}\n+\n+/*\n+ * Pin g2 original sca in g1 memory.\n+ *\n+ * Called with vsie_sca_lock held in write.\n+ */\n+static int pin_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)\n+{\n+\tbool is_esca = test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags);\n+\tgpa_t offset = vsie_sca-\u003esca_gpa \u0026 ~PAGE_MASK;\n+\tint rc, nr_pages;\n+\n+\tif (test_bit(VSIE_SCA_SCA_PINNED, \u0026vsie_sca-\u003eflags))\n+\t\treturn 0;\n+\n+\tif (is_esca) {\n+\t\tnr_pages = 4;\n+\t\tif (offset + sizeof(struct esca_block) \u003e 4 * PAGE_SIZE)\n+\t\t\tnr_pages = 5;\n+\t} else {\n+\t\tnr_pages = 1;\n+\t\tif (offset + sizeof(struct bsca_block) \u003e PAGE_SIZE)\n+\t\t\tnr_pages = 2;\n+\t}\n+\n+\trc = pin_guest_pages(kvm, vsie_sca-\u003esca_gpa, nr_pages, vsie_sca-\u003esca_o_pages,\n+\t\t\t \u0026vsie_sca-\u003esca_o_nr_pages);\n+\tif (rc)\n+\t\treturn rc;\n+\tset_bit(VSIE_SCA_SCA_PINNED, \u0026vsie_sca-\u003eflags);\n+\n+\treturn 0;\n+}\n+\n+static int get_sca_entry_addr(struct kvm *kvm, struct vsie_sca *vsie_sca, u16 cpu_nr, gpa_t *gpa,\n+\t\t\t hpa_t *hpa)\n+{\n+\thpa_t cpu_offset, offset;\n+\tint pn;\n+\n+\t/*\n+\t * We cannot simply access the hva since the esca_block has typically\n+\t * 4 pages (arch max 5 pages) that might not be continuous in g1 memory.\n+\t * The bsca_block may also be stretched over two pages. Only the header\n+\t * is guaranteed to be on the same page.\n+\t */\n+\tif (test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags))\n+\t\tcpu_offset = offsetof(struct esca_block, cpu[cpu_nr]);\n+\telse\n+\t\tcpu_offset = offsetof(struct bsca_block, cpu[cpu_nr]);\n+\tpn = ((vsie_sca-\u003esca_gpa \u0026 ~PAGE_MASK) + cpu_offset) \u003e\u003e PAGE_SHIFT;\n+\toffset = (vsie_sca-\u003esca_gpa + cpu_offset) \u0026 ~PAGE_MASK;\n+\tif (WARN_ON_ONCE(pn \u003e= vsie_sca-\u003esca_o_nr_pages))\n+\t\treturn -EINVAL;\n+\n+\tif (gpa)\n+\t\t*gpa = vsie_sca-\u003esca_o_pages[pn].gpa | offset;\n+\tif (hpa)\n+\t\t*hpa = vsie_sca-\u003esca_o_pages[pn].hpa | offset;\n+\treturn 0;\n+}\n+\n+static void put_vsie_sca(struct vsie_sca *vsie_sca)\n+{\n+\tif (!vsie_sca)\n+\t\treturn;\n+\n+\tWARN_ON_ONCE(atomic_dec_return(\u0026vsie_sca-\u003eref_count) \u003c 0);\n+}\n+\n+/*\n+ * Try to find a matching vsie_sca with the correct sca format.\n+ * @sca_o_gpa: original system control area address; guest-2 physical\n+ * @uses_esca: whether the guest SCB has ECB2_ESCA set\n+ *\n+ * Called with lock on vsie_sca_lock.\n+ */\n+static struct vsie_sca *get_vsie_sca_existing(struct kvm *kvm, gpa_t sca_o_gpa, bool uses_esca)\n+{\n+\tstruct vsie_sca *vsie_sca = xa_load(\u0026kvm-\u003earch.vsie.osca_to_sca,\n+\t\t\t\t\t sca_o_gpa \u003e\u003e SCA_ALIGNMENT_SHIFT);\n+\n+\tif (!vsie_sca)\n+\t\treturn NULL;\n+\tif (uses_esca != test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags))\n+\t\treturn NULL;\n+\tWARN_ON_ONCE(atomic_inc_return(\u0026vsie_sca-\u003eref_count) \u003c 1);\n+\treturn vsie_sca;\n+}\n+\n+/* Try to find and get a currently unused vsie_sca from the vsie struct. */\n+static struct vsie_sca *get_vsie_sca_unused(struct kvm *kvm)\n+{\n+\tstruct vsie_sca *vsie_sca;\n+\tint i, ref_count;\n+\n+\tfor (i = 0; i \u003c kvm-\u003earch.vsie.sca_count; i++) {\n+\t\tvsie_sca = READ_ONCE(kvm-\u003earch.vsie.scas[kvm-\u003earch.vsie.sca_next]);\n+\t\tkvm-\u003earch.vsie.sca_next++;\n+\t\tkvm-\u003earch.vsie.sca_next %= kvm-\u003earch.vsie.sca_count;\n+\t\tref_count = atomic_inc_return(\u0026vsie_sca-\u003eref_count);\n+\t\tWARN_ON_ONCE(ref_count \u003c 1);\n+\t\tif (ref_count == 1)\n+\t\t\treturn vsie_sca;\n+\t\tput_vsie_sca(vsie_sca);\n+\t}\n+\treturn ERR_PTR(-EAGAIN);\n+}\n+\n+static void free_vsie_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)\n+{\n+\tfree_pages_exact(vsie_sca, sizeof(*vsie_sca));\n+}\n+\n+static struct vsie_sca *alloc_vsie_sca(void)\n+{\n+\tstruct vsie_sca *vsie_sca;\n+\n+\tvsie_sca = alloc_pages_exact(sizeof(*vsie_sca), GFP_KERNEL_ACCOUNT | __GFP_ZERO);\n+\tif (!vsie_sca)\n+\t\treturn NULL;\n+\n+\tmutex_init(\u0026vsie_sca-\u003emutex);\n+\tatomic_set(\u0026vsie_sca-\u003eref_count, 0);\n+\n+\treturn vsie_sca;\n+}\n+\n+/* Clear the vsie_sca struct but keep the vsie_page references, mutex and ref_count */\n+static void clear_vsie_sca(struct vsie_sca *vsie_sca)\n+{\n+\tmemset(\u0026vsie_sca-\u003ehead, 0, sizeof(vsie_sca-\u003ehead));\n+\tmemset(\u0026vsie_sca-\u003etail, 0, sizeof(vsie_sca-\u003etail));\n+}\n+\n+/* Pin and get an existing or new guest-3 system control area.*/\n+static int get_vsie_sca(struct kvm_vcpu *vcpu, struct kvm_s390_sie_block *scb_o,\n+\t\tstruct vsie_sca **vsie_sca_out)\n+{\n+\tstruct vsie_sca *vsie_sca, *vsie_sca_new = NULL;\n+\tgpa_t sca_gpa = read_scao(vcpu-\u003ekvm, scb_o);\n+\tbool is_esca = sie_uses_esca(scb_o);\n+\tstruct vsie_page *vsie_page_n;\n+\tstruct kvm *kvm = vcpu-\u003ekvm;\n+\tunsigned int max_vsie_sca;\n+\tint rc, cpu_nr;\n+\n+\t/* validate scb_o as we do not unshadow on error here */\n+\trc = validate_scao(vcpu, scb_o, sca_gpa);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tdown_read(\u0026kvm-\u003earch.vsie.vsie_sca_lock);\n+\tvsie_sca = get_vsie_sca_existing(kvm, sca_gpa, is_esca);\n+\tup_read(\u0026kvm-\u003earch.vsie.vsie_sca_lock);\n+\tif (vsie_sca) {\n+\t\t*vsie_sca_out = vsie_sca;\n+\t\treturn 0;\n+\t}\n+\n+\t/*\n+\t * Allocate new vsie_sca, it will likely be needed below.\n+\t * We want at least #online_vcpus shadows, so every VCPU can execute the\n+\t * VSIE in parallel. (Worst case all single core VMs.)\n+\t */\n+\tmax_vsie_sca = min_t(unsigned int, max_t(unsigned int, atomic_read(\u0026kvm-\u003eonline_vcpus),\n+\t\t\t vsie_shadow_sca_max), KVM_S390_MAX_VSIE_VCPUS);\n+\n+\tif (kvm-\u003earch.vsie.sca_count \u003c max_vsie_sca) {\n+\t\tvsie_sca_new = alloc_vsie_sca();\n+\t\tif (!vsie_sca_new)\n+\t\t\treturn -ENOMEM;\n+\t}\n+\n+\t/*\n+\t * Now we're taking the vsie_sca_lock in write mode so that we can manipulate\n+\t * the xarray and arch.vise.scas, etc.\n+\t *\n+\t * In the next lines we try three things to get an SCA:\n+\t * - Retry getting an existing vsie_sca\n+\t * - Using our newly allocated vsie_sca if we're under the limit\n+\t * - Reusing an vsie_sca including ssca to shadow a different osca\n+\t */\n+\tdown_write(\u0026kvm-\u003earch.vsie.vsie_sca_lock);\n+\tvsie_sca = xa_load(\u0026kvm-\u003earch.vsie.osca_to_sca, sca_gpa \u003e\u003e SCA_ALIGNMENT_SHIFT);\n+\tif (vsie_sca) {\n+\t\tWARN_ON_ONCE(atomic_inc_return(\u0026vsie_sca-\u003eref_count) \u003c 1);\n+\t\tif (is_esca == test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags))\n+\t\t\tgoto out;\n+\t\t/* found vsie_sca with matching sca_gpa but wrong format */\n+\t\tput_vsie_sca(vsie_sca);\n+\t\txa_erase(\u0026kvm-\u003earch.vsie.osca_to_sca, sca_gpa \u003e\u003e SCA_ALIGNMENT_SHIFT);\n+\t}\n+\n+\t/* check again under write lock if we are still under our vsie_sca limit */\n+\tif (vsie_sca_new \u0026\u0026 kvm-\u003earch.vsie.sca_count \u003c max_vsie_sca) {\n+\t\t/* make use of vsie_sca just created */\n+\t\tvsie_sca = vsie_sca_new;\n+\t\tvsie_sca_new = NULL;\n+\n+\t\tkvm-\u003earch.vsie.scas[kvm-\u003earch.vsie.sca_count] = vsie_sca;\n+\t\tkvm-\u003earch.vsie.sca_count++;\n+\t\tatomic_set(\u0026vsie_sca-\u003eref_count, 1);\n+\t\tkvm-\u003estat.vsie_shadow_sca++;\n+\t} else {\n+\t\t/* reuse previously created vsie_sca allocation for different osca */\n+\t\tvsie_sca = get_vsie_sca_unused(kvm);\n+\t\t/* with nr_vcpus scas one must be reusable */\n+\t\tif (IS_ERR(vsie_sca)) {\n+\t\t\trc = PTR_ERR(vsie_sca);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\t/* unused vsie_sca exclusive under vsie_sca_lock write lock */\n+\t\txa_erase(\u0026kvm-\u003earch.vsie.osca_to_sca, vsie_sca-\u003esca_gpa \u003e\u003e SCA_ALIGNMENT_SHIFT);\n+\t\tfor (cpu_nr = 0; cpu_nr \u003c KVM_S390_MAX_VSIE_VCPUS; cpu_nr++) {\n+\t\t\tvsie_page_n = vsie_sca-\u003epages[cpu_nr];\n+\t\t\tif (!vsie_page_n)\n+\t\t\t\tcontinue;\n+\n+\t\t\t/* unpin but keep the vsie_page for reuse */\n+\t\t\tunpin_scb(kvm, vsie_page_n);\n+\t\t\trelease_gmap_shadow_safe(kvm, vsie_page_n);\n+\t\t\tmemset(vsie_page_n, 0, sizeof(struct vsie_page));\n+\t\t\tvsie_page_n-\u003escb_gpa = ULONG_MAX;\n+\t\t}\n+\t\tunpin_sca(kvm, vsie_sca);\n+\t\tclear_vsie_sca(vsie_sca);\n+\t\tkvm-\u003estat.vsie_shadow_sca_reuse++;\n+\t}\n+\n+\tif (sie_uses_esca(scb_o))\n+\t\tset_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags);\n+\tvsie_sca-\u003esca_gpa = sca_gpa;\n+\n+\t/*\n+\t * The pinned original sca will only be unpinned lazily to limit the\n+\t * required amount of pins/unpins on each vsie entry/exit.\n+\t * The unpin is done in the reuse vsie_sca allocation path above and\n+\t * kvm_s390_vsie_destroy().\n+\t */\n+\trc = pin_sca(kvm, vsie_sca);\n+\tif (rc) {\n+\t\tput_vsie_sca(vsie_sca);\n+\t\tvsie_sca-\u003esca_gpa = ULONG_MAX;\n+\t\tgoto out;\n+\t}\n+\n+\trc = xa_insert(\u0026kvm-\u003earch.vsie.osca_to_sca, vsie_sca-\u003esca_gpa \u003e\u003e SCA_ALIGNMENT_SHIFT,\n+\t\t vsie_sca, GFP_KERNEL_ACCOUNT);\n+\tif (rc) {\n+\t\tunpin_sca(kvm, vsie_sca);\n+\t\tput_vsie_sca(vsie_sca);\n+\t\tvsie_sca-\u003esca_gpa = ULONG_MAX;\n+\t\tif (rc == -EBUSY)\n+\t\t\trc = 1;\n+\t}\n+\n+out:\n+\tup_write(\u0026kvm-\u003earch.vsie.vsie_sca_lock);\n+\tif (vsie_sca_new)\n+\t\tfree_vsie_sca(kvm, vsie_sca_new);\n+\tif (vsie_sca)\n+\t\t*vsie_sca_out = vsie_sca;\n+\treturn rc;\n }\n \n void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, gpa_t start, gpa_t end)\n@@ -680,44 +1280,18 @@ static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct\n \treturn rc;\n }\n \n-/*\n- * Pin the guest page given by gpa and set hpa to the pinned host address.\n- * Will always be pinned writable.\n- *\n- * Returns: - 0 on success\n- * - -EINVAL if the gpa is not valid guest storage\n- */\n-static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)\n-{\n-\tstruct page *page;\n-\n-\tpage = gfn_to_page(kvm, gpa_to_gfn(gpa));\n-\tif (!page)\n-\t\treturn -EINVAL;\n-\t*hpa = (hpa_t)page_to_phys(page) + (gpa \u0026 ~PAGE_MASK);\n-\treturn 0;\n-}\n-\n-/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */\n-static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)\n-{\n-\tkvm_release_page_dirty(pfn_to_page(phys_to_pfn(hpa)));\n-\t/* mark the page always as dirty for migration */\n-\tmark_page_dirty(kvm, gpa_to_gfn(gpa));\n-}\n-\n /* unpin all blocks previously pinned by pin_blocks(), marking them dirty */\n static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n {\n \tstruct kvm_s390_sie_block *scb_s = \u0026vsie_page-\u003escb_s;\n \thpa_t hpa;\n \n-\thpa = (u64) scb_s-\u003escaoh \u003c\u003c 32 | scb_s-\u003escaol;\n-\tif (hpa) {\n-\t\tunpin_guest_page(vcpu-\u003ekvm, vsie_page-\u003esca_gpa, hpa);\n-\t\tvsie_page-\u003esca_gpa = 0;\n-\t\tscb_s-\u003escaol = 0;\n-\t\tscb_s-\u003escaoh = 0;\n+\tif (!vsie_page-\u003evsie_sca) {\n+\t\thpa = (u64) scb_s-\u003escaoh \u003c\u003c 32 | scb_s-\u003escaol;\n+\t\tif (hpa) {\n+\t\t\tunpin_guest_page(vcpu-\u003ekvm, vsie_page-\u003esca_gpa, hpa);\n+\t\t\twrite_scao(scb_s, 0);\n+\t\t}\n \t}\n \n \thpa = scb_s-\u003eitdba;\n@@ -756,9 +1330,6 @@ static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n * This works as long as the data lies in one page. If blocks ever exceed one\n * page, we have to fall back to shadowing.\n *\n- * As we reuse the sca, the vcpu pointers contained in it are invalid. We must\n- * therefore not enable any facilities that access these pointers (e.g. SIGPIF).\n- *\n * Returns: - 0 if all blocks were pinned.\n * - \u003e 0 if control has to be given to guest 2\n * - -ENOMEM if out of memory\n@@ -771,27 +1342,17 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \tgpa_t gpa;\n \tint rc = 0;\n \n-\tgpa = READ_ONCE(scb_o-\u003escaol) \u0026 ~0xfUL;\n-\tif (test_kvm_cpu_feat(vcpu-\u003ekvm, KVM_S390_VM_CPU_FEAT_64BSCAO))\n-\t\tgpa |= (u64) READ_ONCE(scb_o-\u003escaoh) \u003c\u003c 32;\n-\tif (gpa) {\n-\t\tif (gpa \u003c 2 * PAGE_SIZE)\n-\t\t\trc = set_validity_icpt(scb_s, 0x0038U);\n-\t\telse if ((gpa \u0026 ~0x1fffUL) == kvm_s390_get_prefix(vcpu))\n-\t\t\trc = set_validity_icpt(scb_s, 0x0011U);\n-\t\telse if ((gpa \u0026 PAGE_MASK) !=\n-\t\t\t ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) \u0026 PAGE_MASK))\n-\t\t\trc = set_validity_icpt(scb_s, 0x003bU);\n-\t\tif (!rc) {\n-\t\t\trc = pin_guest_page(vcpu-\u003ekvm, gpa, \u0026hpa);\n-\t\t\tif (rc)\n-\t\t\t\trc = set_validity_icpt(scb_s, 0x0034U);\n-\t\t}\n+\tgpa = vsie_page-\u003esca_gpa;\n+\tif (gpa \u0026\u0026 !vsie_page-\u003evsie_sca) {\n+\t\trc = validate_scao(vcpu, scb_s, gpa);\n \t\tif (rc)\n \t\t\tgoto unpin;\n-\t\tvsie_page-\u003esca_gpa = gpa;\n-\t\tscb_s-\u003escaoh = (u32)((u64)hpa \u003e\u003e 32);\n-\t\tscb_s-\u003escaol = (u32)(u64)hpa;\n+\t\trc = pin_guest_page(vcpu-\u003ekvm, gpa, \u0026hpa);\n+\t\tif (rc) {\n+\t\t\trc = set_validity_icpt(scb_s, 0x0034U);\n+\t\t\tgoto unpin;\n+\t\t}\n+\t\twrite_scao(scb_s, hpa);\n \t}\n \n \tgpa = READ_ONCE(scb_o-\u003eitdba) \u0026 ~0xffUL;\n@@ -866,51 +1427,18 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \t\t/* Due to alignment rules (checked above) this cannot\n \t\t * cross page boundaries\n \t\t */\n-\t\trc = pin_guest_page(vcpu-\u003ekvm, gpa, \u0026hpa);\n-\t\tif (rc) {\n-\t\t\trc = set_validity_icpt(scb_s, 0x10b0U);\n-\t\t\tgoto unpin;\n-\t\t}\n-\t\tvsie_page-\u003esdnx_gpa = gpa;\n-\t\tscb_s-\u003esdnxo = hpa | sdnxc;\n-\t}\n-\treturn 0;\n-unpin:\n-\tunpin_blocks(vcpu, vsie_page);\n-\treturn rc;\n-}\n-\n-/* unpin the scb provided by guest 2, marking it as dirty */\n-static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,\n-\t\t gpa_t gpa)\n-{\n-\thpa_t hpa = virt_to_phys(vsie_page-\u003escb_o);\n-\n-\tif (hpa)\n-\t\tunpin_guest_page(vcpu-\u003ekvm, gpa, hpa);\n-\tvsie_page-\u003escb_o = NULL;\n-}\n-\n-/*\n- * Pin the scb at gpa provided by guest 2 at vsie_page-\u003escb_o.\n- *\n- * Returns: - 0 if the scb was pinned.\n- * - \u003e 0 if control has to be given to guest 2\n- */\n-static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,\n-\t\t gpa_t gpa)\n-{\n-\thpa_t hpa;\n-\tint rc;\n-\n-\trc = pin_guest_page(vcpu-\u003ekvm, gpa, \u0026hpa);\n-\tif (rc) {\n-\t\trc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);\n-\t\tWARN_ON_ONCE(rc);\n-\t\treturn 1;\n+\t\trc = pin_guest_page(vcpu-\u003ekvm, gpa, \u0026hpa);\n+\t\tif (rc) {\n+\t\t\trc = set_validity_icpt(scb_s, 0x10b0U);\n+\t\t\tgoto unpin;\n+\t\t}\n+\t\tvsie_page-\u003esdnx_gpa = gpa;\n+\t\tscb_s-\u003esdnxo = hpa | sdnxc;\n \t}\n-\tvsie_page-\u003escb_o = phys_to_virt(hpa);\n \treturn 0;\n+unpin:\n+\tunpin_blocks(vcpu, vsie_page);\n+\treturn rc;\n }\n \n /*\n@@ -1281,71 +1809,6 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc\n \treturn rc;\n }\n \n-static void release_gmap_shadow(struct vsie_page *vsie_page)\n-{\n-\tstruct gmap *gmap = vsie_page-\u003egmap_cache.gmap;\n-\n-\tlockdep_assert_held(\u0026gmap-\u003ekvm-\u003earch.gmap-\u003echildren_lock);\n-\n-\tlist_del(\u0026vsie_page-\u003egmap_cache.list);\n-\tvsie_page-\u003egmap_cache.gmap = NULL;\n-\tprefix_unmapped(vsie_page);\n-\n-\tif (list_empty(\u0026gmap-\u003escb_users)) {\n-\t\tgmap_remove_child(gmap);\n-\t\tgmap_put(gmap);\n-\t}\n-}\n-\n-static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n-{\n-\tunion ctlreg0 cr0;\n-\tstruct gmap *gmap;\n-\tunion asce asce;\n-\tint edat;\n-\n-\tasce.val = vcpu-\u003earch.sie_block-\u003egcr[1];\n-\tcr0.val = vcpu-\u003earch.sie_block-\u003egcr[0];\n-\tedat = cr0.edat \u0026\u0026 test_kvm_facility(vcpu-\u003ekvm, 8);\n-\tedat += edat \u0026\u0026 test_kvm_facility(vcpu-\u003ekvm, 78);\n-\n-\tscoped_guard(spinlock, \u0026vcpu-\u003ekvm-\u003earch.gmap-\u003echildren_lock) {\n-\t\tgmap = vsie_page-\u003egmap_cache.gmap;\n-\t\tif (gmap) {\n-\t\t\t/*\n-\t\t\t * ASCE or EDAT could have changed since last icpt, or the gmap\n-\t\t\t * we're holding has been unshadowed. If the gmap is still valid,\n-\t\t\t * we can safely reuse it.\n-\t\t\t */\n-\t\t\tif (gmap_is_shadow_valid(gmap, asce, edat)) {\n-\t\t\t\tvcpu-\u003ekvm-\u003estat.gmap_shadow_reuse++;\n-\t\t\t\tgmap_get(gmap);\n-\t\t\t\treturn gmap;\n-\t\t\t}\n-\t\t\t/* release the old shadow and mark the prefix as unmapped */\n-\t\t\trelease_gmap_shadow(vsie_page);\n-\t\t}\n-\t}\n-again:\n-\tgmap = gmap_create_shadow(vcpu-\u003earch.mc, vcpu-\u003ekvm-\u003earch.gmap, asce, edat);\n-\tif (IS_ERR(gmap))\n-\t\treturn gmap;\n-\tscoped_guard(spinlock, \u0026vcpu-\u003ekvm-\u003earch.gmap-\u003echildren_lock) {\n-\t\t/* unlikely race condition, remove the previous shadow */\n-\t\tif (vsie_page-\u003egmap_cache.gmap)\n-\t\t\trelease_gmap_shadow(vsie_page);\n-\t\tif (!gmap-\u003eparent) {\n-\t\t\tgmap_put(gmap);\n-\t\t\tgoto again;\n-\t\t}\n-\t\tvcpu-\u003ekvm-\u003estat.gmap_shadow_create++;\n-\t\tlist_add(\u0026vsie_page-\u003egmap_cache.list, \u0026gmap-\u003escb_users);\n-\t\tvsie_page-\u003egmap_cache.gmap = gmap;\n-\t\tprefix_unmapped(vsie_page);\n-\t}\n-\treturn gmap;\n-}\n-\n /*\n * Register the shadow scb at the VCPU, e.g. for kicking out of vsie.\n */\n@@ -1429,7 +1892,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)\n \t\t */\n \t\tif (kvm_s390_vcpu_has_irq(vcpu, 0) ||\n \t\t kvm_s390_vcpu_sie_inhibited(vcpu)) {\n-\t\t\tkvm_s390_rewind_psw(vcpu, 4);\n+\t\t\trc = -EAGAIN;\n \t\t\tbreak;\n \t\t}\n \t\tif (sg)\n@@ -1472,93 +1935,370 @@ static void put_vsie_page(struct vsie_page *vsie_page)\n \tclear_bit(VSIE_PAGE_IN_USE, \u0026vsie_page-\u003eflags);\n }\n \n+static void free_vsie_page(struct vsie_page *vsie_page)\n+{\n+\tfree_page((unsigned long)vsie_page);\n+}\n+\n+static struct vsie_page *alloc_vsie_page(struct kvm *kvm)\n+{\n+\tstruct vsie_page *vsie_page;\n+\n+\tvsie_page = (struct vsie_page *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);\n+\tif (!vsie_page)\n+\t\treturn vsie_page;\n+\n+\t/* Mark it as invalid until it resides in the tree. */\n+\tvsie_page-\u003escb_gpa = ULONG_MAX;\n+\treturn vsie_page;\n+}\n+\n+static int init_vsie_page(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, unsigned long scb_gpa)\n+{\n+\tint rc;\n+\n+\tvsie_page-\u003escb_gpa = scb_gpa;\n+\trc = pin_scb(vcpu, vsie_page);\n+\tif (rc) {\n+\t\tvsie_page-\u003escb_gpa = ULONG_MAX;\n+\t\treturn rc;\n+\t}\n+\n+\tvsie_page-\u003esca_gpa = read_scao(vcpu-\u003ekvm, vsie_page-\u003escb_o);\n+\n+\treturn 0;\n+}\n+\n+/* Reset shadow state after a vsie_page has been (re)initialised for a new SCB. */\n+static void reset_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)\n+{\n+\tmemset(\u0026vsie_page-\u003escb_s, 0, sizeof(struct kvm_s390_sie_block));\n+\trelease_gmap_shadow_safe(kvm, vsie_page);\n+\tprefix_unmapped(vsie_page);\n+\tvsie_page-\u003efault_addr = 0;\n+\tvsie_page-\u003escb_s.ihcpu = 0xffffU;\n+}\n+\n /*\n * Get or create a vsie page for a scb address.\n *\n- * Returns: - address of a vsie page (cached or new one)\n- * - NULL if the same scb address is already used by another VCPU\n- * - ERR_PTR(-ENOMEM) if out of memory\n+ * Original control blocks are pinned when the vsie_page pointing to them is\n+ * returned.\n+ * Newly created vsie_pages only have vsie_page-\u003escb_gpa and vsie_page-\u003esca_gpa\n+ * set.\n+ *\n+ * Returns: - -EBUSY if the same scb address is already used by another VCPU\n+ * - -ENOMEM if out of memory\n */\n-static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)\n+static int get_vsie_page(struct kvm_vcpu *vcpu, unsigned long addr,\n+\t\t\t struct vsie_page **vsie_page_out)\n {\n-\tstruct vsie_page *vsie_page;\n-\tint nr_vcpus;\n-\n-\trcu_read_lock();\n-\tvsie_page = radix_tree_lookup(\u0026kvm-\u003earch.vsie.addr_to_page, addr \u003e\u003e SCB_ALIGNMENT_SHIFT);\n-\trcu_read_unlock();\n-\tif (vsie_page) {\n-\t\tif (try_get_vsie_page(vsie_page)) {\n-\t\t\tif (vsie_page-\u003escb_gpa == addr)\n-\t\t\t\treturn vsie_page;\n-\t\t\t/*\n-\t\t\t * We raced with someone reusing + putting this vsie\n-\t\t\t * page before we grabbed it.\n-\t\t\t */\n-\t\t\tput_vsie_page(vsie_page);\n+\tstruct vsie_page *vsie_page, *vsie_page_new = NULL;\n+\tstruct kvm *kvm = vcpu-\u003ekvm;\n+\tunsigned int max_vsie_page;\n+\tint rc, pages_idx;\n+\n+\tvsie_page = xa_load(\u0026kvm-\u003earch.vsie.addr_to_page, addr \u003e\u003e SCB_ALIGNMENT_SHIFT);\n+\tif (vsie_page \u0026\u0026 try_get_vsie_page(vsie_page)) {\n+\t\tif (vsie_page-\u003escb_gpa == addr) {\n+\t\t\t*vsie_page_out = vsie_page;\n+\t\t\treturn 0;\n \t\t}\n+\t\t/*\n+\t\t * We raced with someone reusing + putting this vsie\n+\t\t * page before we grabbed it.\n+\t\t */\n+\t\tput_vsie_page(vsie_page);\n \t}\n \n-\t/*\n-\t * We want at least #online_vcpus shadows, so every VCPU can execute\n-\t * the VSIE in parallel.\n-\t */\n-\tnr_vcpus = atomic_read(\u0026kvm-\u003eonline_vcpus);\n+\tmax_vsie_page = min_t(unsigned int, max_t(unsigned int, atomic_read(\u0026kvm-\u003eonline_vcpus),\n+\t\t\t vsie_shadow_scb_max), KVM_S390_MAX_VSIE_VCPUS);\n+\n+\t/* allocate new vsie_page - we will likely need it */\n+\tif (kvm-\u003earch.vsie.page_count \u003c max_vsie_page) {\n+\t\tvsie_page_new = alloc_vsie_page(kvm);\n+\t\tif (!vsie_page_new)\n+\t\t\treturn -ENOMEM;\n+\t\t__set_bit(VSIE_PAGE_IN_USE, \u0026vsie_page_new-\u003eflags);\n+\t}\n \n \tmutex_lock(\u0026kvm-\u003earch.vsie.mutex);\n-\tif (kvm-\u003earch.vsie.page_count \u003c nr_vcpus) {\n-\t\tvsie_page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);\n-\t\tif (!vsie_page) {\n+\tvsie_page = xa_load(\u0026kvm-\u003earch.vsie.addr_to_page, addr \u003e\u003e SCB_ALIGNMENT_SHIFT);\n+\tif (vsie_page \u0026\u0026 try_get_vsie_page(vsie_page)) {\n+\t\tif (vsie_page-\u003escb_gpa == addr) {\n \t\t\tmutex_unlock(\u0026kvm-\u003earch.vsie.mutex);\n-\t\t\treturn ERR_PTR(-ENOMEM);\n+\t\t\tif (vsie_page_new)\n+\t\t\t\tfree_vsie_page(vsie_page_new);\n+\t\t\t*vsie_page_out = vsie_page;\n+\t\t\treturn 0;\n \t\t}\n-\t\t__set_bit(VSIE_PAGE_IN_USE, \u0026vsie_page-\u003eflags);\n-\t\tkvm-\u003earch.vsie.pages[kvm-\u003earch.vsie.page_count] = vsie_page;\n+\t\t/*\n+\t\t * We raced with someone reusing + putting this vsie\n+\t\t * page before we grabbed it.\n+\t\t */\n+\t\tput_vsie_page(vsie_page);\n+\t}\n+\n+\tif (kvm-\u003earch.vsie.page_count \u003c max_vsie_page) {\n+\t\tpages_idx = kvm-\u003earch.vsie.page_count;\n+\t\tvsie_page = vsie_page_new;\n+\t\tvsie_page_new = NULL;\n+\t\tWRITE_ONCE(kvm-\u003earch.vsie.pages[kvm-\u003earch.vsie.page_count], vsie_page);\n \t\tkvm-\u003earch.vsie.page_count++;\n+\t\tkvm-\u003estat.vsie_shadow_scb++;\n \t} else {\n \t\t/* reuse an existing entry that belongs to nobody */\n \t\twhile (true) {\n-\t\t\tvsie_page = kvm-\u003earch.vsie.pages[kvm-\u003earch.vsie.next];\n+\t\t\tpages_idx = kvm-\u003earch.vsie.next;\n+\t\t\tkvm-\u003earch.vsie.next++;\n+\t\t\tkvm-\u003earch.vsie.next %= kvm-\u003earch.vsie.page_count;\n+\t\t\tvsie_page = kvm-\u003earch.vsie.pages[pages_idx];\n \t\t\tif (try_get_vsie_page(vsie_page))\n \t\t\t\tbreak;\n-\t\t\tkvm-\u003earch.vsie.next++;\n-\t\t\tkvm-\u003earch.vsie.next %= nr_vcpus;\n \t\t}\n \t\tif (vsie_page-\u003escb_gpa != ULONG_MAX)\n-\t\t\tradix_tree_delete(\u0026kvm-\u003earch.vsie.addr_to_page,\n-\t\t\t\t\t vsie_page-\u003escb_gpa \u003e\u003e SCB_ALIGNMENT_SHIFT);\n+\t\t\txa_erase(\u0026kvm-\u003earch.vsie.addr_to_page,\n+\t\t\t\t vsie_page-\u003escb_gpa \u003e\u003e SCB_ALIGNMENT_SHIFT);\n+\n+\t\tunpin_scb(kvm, vsie_page);\n+\t\t/* Mark it as invalid until it resides in the tree. */\n+\t\tvsie_page-\u003escb_gpa = ULONG_MAX;\n+\t\tkvm-\u003estat.vsie_shadow_scb_reuse++;\n \t}\n-\t/* Mark it as invalid until it resides in the tree. */\n-\tvsie_page-\u003escb_gpa = ULONG_MAX;\n \n-\t/* Double use of the same address or allocation failure. */\n-\tif (radix_tree_insert(\u0026kvm-\u003earch.vsie.addr_to_page, addr \u003e\u003e SCB_ALIGNMENT_SHIFT,\n-\t\t\t vsie_page)) {\n-\t\tput_vsie_page(vsie_page);\n-\t\tmutex_unlock(\u0026kvm-\u003earch.vsie.mutex);\n-\t\treturn NULL;\n+\trc = init_vsie_page(vcpu, vsie_page, addr);\n+\tif (!rc) {\n+\t\trc = xa_insert(\u0026kvm-\u003earch.vsie.addr_to_page, addr \u003e\u003e SCB_ALIGNMENT_SHIFT, vsie_page,\n+\t\t\t GFP_KERNEL_ACCOUNT);\n+\t\tif (rc == -EBUSY)\n+\t\t\trc = -EAGAIN;\n \t}\n-\tvsie_page-\u003escb_gpa = addr;\n+\n \tmutex_unlock(\u0026kvm-\u003earch.vsie.mutex);\n+\tif (vsie_page_new)\n+\t\tfree_vsie_page(vsie_page_new);\n+\tif (rc) {\n+\t\tunpin_scb(kvm, vsie_page);\n+\t\tvsie_page-\u003escb_gpa = ULONG_MAX;\n+\t\tput_vsie_page(vsie_page);\n+\t\treturn rc;\n+\t}\n \n-\tmemset(\u0026vsie_page-\u003escb_s, 0, sizeof(struct kvm_s390_sie_block));\n-\tif (vsie_page-\u003egmap_cache.gmap) {\n-\t\tscoped_guard(spinlock, \u0026kvm-\u003earch.gmap-\u003echildren_lock)\n-\t\t\tif (vsie_page-\u003egmap_cache.gmap)\n-\t\t\t\trelease_gmap_shadow(vsie_page);\n+\treset_vsie_page(kvm, vsie_page);\n+\n+\t*vsie_page_out = vsie_page;\n+\treturn 0;\n+}\n+\n+static int get_vsie_page_cpu_nr(struct kvm_vcpu *vcpu, struct vsie_sca *vsie_sca, gpa_t scb_gpa,\n+\t\t\t\tu16 cpu_nr, struct vsie_page **vsie_page_out)\n+{\n+\tstruct vsie_page *vsie_page, *vsie_page_new = NULL;\n+\tbool vsie_page_is_new = true;\n+\tint rc;\n+\n+\tvsie_page = vsie_sca-\u003epages[cpu_nr];\n+\tif (!vsie_page) {\n+\t\tvsie_page_new = alloc_vsie_page(vcpu-\u003ekvm);\n+\t\tif (!vsie_page_new)\n+\t\t\treturn -ENOMEM;\n+\t\tvsie_page_new-\u003evsie_sca = vsie_sca;\n+\t\t__set_bit(VSIE_PAGE_IN_USE, \u0026vsie_page_new-\u003eflags);\n+\n+\t\t/* be careful to not loose a page here if we raced */\n+\t\tscoped_guard(mutex, \u0026vsie_sca-\u003emutex) {\n+\t\t\tvsie_page = vsie_sca-\u003epages[cpu_nr];\n+\t\t\tif (!vsie_page) {\n+\t\t\t\tWRITE_ONCE(vsie_sca-\u003epages[cpu_nr], vsie_page_new);\n+\t\t\t\tvsie_page = vsie_page_new;\n+\t\t\t}\n+\t\t}\n \t}\n-\tprefix_unmapped(vsie_page);\n-\tvsie_page-\u003efault_addr = 0;\n-\tvsie_page-\u003escb_s.ihcpu = 0xffffU;\n-\treturn vsie_page;\n+\tif (vsie_page != vsie_page_new) {\n+\t\tvsie_page_is_new = false;\n+\t\tif (vsie_page_new)\n+\t\t\tfree_vsie_page(vsie_page_new);\n+\n+\t\t/* not a new vsie_page so get it */\n+\t\tif (!try_get_vsie_page(vsie_page))\n+\t\t\treturn -EAGAIN;\n+\t\tvsie_page-\u003evsie_sca = vsie_sca;\n+\t}\n+\tif (vsie_page-\u003escb_gpa != scb_gpa || vsie_page-\u003esca_gpa != vsie_sca-\u003esca_gpa) {\n+\t\tscoped_guard(mutex, \u0026vcpu-\u003ekvm-\u003earch.vsie.mutex) {\n+\t\t\tunpin_scb(vcpu-\u003ekvm, vsie_page);\n+\t\t\trc = init_vsie_page(vcpu, vsie_page, scb_gpa);\n+\t\t}\n+\t\tif (vsie_page_is_new)\n+\t\t\tvcpu-\u003ekvm-\u003estat.vsie_shadow_scb++;\n+\t\telse\n+\t\t\tvcpu-\u003ekvm-\u003estat.vsie_shadow_scb_reuse++;\n+\t\tif (rc) {\n+\t\t\tput_vsie_page(vsie_page);\n+\t\t\treturn rc;\n+\t\t}\n+\n+\t\treset_vsie_page(vcpu-\u003ekvm, vsie_page);\n+\t}\n+\n+\t*vsie_page_out = vsie_page;\n+\treturn 0;\n }\n \n-int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)\n+/*\n+ * Copy the mcn from the osca to the vsie_sca to be able to detect mcn changes later on.\n+ *\n+ * @vsie_sca: vsie_sca to copy mcn to.\n+ * @sca: Pointer to a struct bsca_block or struct esca_block to read from.\n+ */\n+static void sca_mcn_copy(struct vsie_sca *vsie_sca, void *sca)\n {\n-\tstruct vsie_page *vsie_page;\n-\tunsigned long scb_addr;\n+\tint offset = offsetof(struct bsca_block, mcn);\n+\tint size = sizeof(unsigned long);\n+\n+\tif (test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags)) {\n+\t\toffset = offsetof(struct esca_block, mcn);\n+\t\tsize = size * 4;\n+\t}\n+\tmemcpy(\u0026vsie_sca-\u003emcn, sca + offset, size);\n+}\n+\n+/*\n+ * Compare the mcn from the given sca to the vsie_sca to be able to detect mcn changes.\n+ *\n+ * @vsie_sca: vsie_sca to compare mcn to.\n+ * @sca: Pointer to a struct bsca_block or struct esca_block to compare to.\n+ */\n+static bool sca_mcn_equals(struct vsie_sca *vsie_sca, void *sca)\n+{\n+\tint offset = offsetof(struct bsca_block, mcn);\n+\tint size = sizeof(unsigned long);\n+\n+\tif (test_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags)) {\n+\t\tsize = size * 4;\n+\t\toffset = offsetof(struct esca_block, mcn);\n+\t}\n+\n+\treturn !memcmp(\u0026vsie_sca-\u003emcn, sca + offset, size);\n+}\n+\n+static void update_vsie_sca(struct vsie_sca *vsie_sca, unsigned int cpu_nr,\n+\t\t\t struct vsie_page *vsie_page_n, hpa_t sca_o_entry_hpa)\n+{\n+\tguard(mutex)(\u0026vsie_sca-\u003emutex);\n+\n+\tWRITE_ONCE(vsie_sca-\u003essca.cpu[cpu_nr].ssda, virt_to_phys(\u0026vsie_page_n-\u003escb_s));\n+\tWRITE_ONCE(vsie_sca-\u003essca.cpu[cpu_nr].ossea, sca_o_entry_hpa);\n+\tWRITE_ONCE(vsie_sca-\u003epages[cpu_nr], vsie_page_n);\n+}\n+\n+static int _shadow_sca_cpu(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,\n+\t\t\t struct vsie_sca *vsie_sca, hpa_t sca_o_entry_hpa,\n+\t\t\t unsigned int cpu_nr, bool is_esca)\n+{\n+\thva_t sca_o_entry_hva = (hva_t)phys_to_virt(sca_o_entry_hpa);\n+\tstruct vsie_page *vsie_page_n;\n+\tgpa_t scb_o_gpa;\n+\tint rc;\n+\n+\tif (is_esca)\n+\t\tscb_o_gpa = ((struct esca_entry *)sca_o_entry_hva)-\u003esda;\n+\telse\n+\t\tscb_o_gpa = ((struct bsca_entry *)sca_o_entry_hva)-\u003esda;\n+\tif (scb_o_gpa \u0026 0x1ffUL)\n+\t\treturn set_validity_icpt(vsie_page-\u003escb_o, 0x0001U);\n+\n+\trc = get_vsie_page_cpu_nr(vcpu, vsie_sca, scb_o_gpa, cpu_nr, \u0026vsie_page_n);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = shadow_scb_minimal(vcpu, vsie_page_n);\n+\tupdate_vsie_sca(vsie_sca, cpu_nr, vsie_page_n, sca_o_entry_hpa);\n+\tif (rc) {\n+\t\t/* copy intercept to primary scb_o, no unshadow_scb() on exit */\n+\t\tunshadow_intercept(vsie_page-\u003escb_o, \u0026vsie_page_n-\u003escb_s);\n+\t\trc = 1;\n+\t}\n+\tput_vsie_page(vsie_page_n);\n+\n+\treturn rc;\n+}\n+\n+/* Fill the shadow system control area used for VSIE SIGPI. */\n+static int _shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,\n+\t\t struct vsie_sca *vsie_sca)\n+{\n+\tbool is_esca = sie_uses_esca(vsie_page-\u003escb_o);\n+\tunsigned int cpu_nr, cpu_slots;\n+\thpa_t sca_o_entry_hpa;\n \tint rc;\n \n+\tif (is_esca)\n+\t\tset_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags);\n+\telse\n+\t\tclear_bit(VSIE_SCA_ESCA, \u0026vsie_sca-\u003eflags);\n+\tsca_mcn_copy(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca)));\n+\n+\t/* pin and make minimal shadow for ALL scb in the sca */\n+\tcpu_slots = is_esca ? KVM_S390_MAX_VSIE_VCPUS : KVM_S390_BSCA_CPU_SLOTS;\n+\tfor_each_set_bit_inv(cpu_nr, (unsigned long *)\u0026vsie_sca-\u003emcn, cpu_slots) {\n+\t\trc = get_sca_entry_addr(vcpu-\u003ekvm, vsie_sca, cpu_nr, NULL, \u0026sca_o_entry_hpa);\n+\t\tif (rc)\n+\t\t\tbreak;\n+\n+\t\tif ((vsie_page-\u003escb_o-\u003eicpua \u0026 KVM_S390_CPU_MASK) == cpu_nr) {\n+\t\t\tupdate_vsie_sca(vsie_sca, cpu_nr, vsie_page, sca_o_entry_hpa);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\trc = _shadow_sca_cpu(vcpu, vsie_page, vsie_sca, sca_o_entry_hpa, cpu_nr, is_esca);\n+\t\tif (rc)\n+\t\t\tbreak;\n+\t}\n+\n+\tif (rc) {\n+\t\tvsie_sca-\u003essca.osca = 0;\n+\t\tfor_each_set_bit_inv(cpu_nr, (unsigned long *)\u0026vsie_sca-\u003emcn, cpu_slots) {\n+\t\t\tvsie_sca-\u003essca.cpu[cpu_nr].ssda = 0;\n+\t\t\tvsie_sca-\u003essca.cpu[cpu_nr].ossea = 0;\n+\t\t}\n+\t} else {\n+\t\tvsie_sca-\u003essca.osca = sca_o_hpa(vsie_sca);\n+\t}\n+\treturn rc;\n+}\n+\n+static bool shadow_sca_needed(struct vsie_sca *vsie_sca)\n+{\n+\tif (!vsie_sca-\u003essca.osca)\n+\t\treturn true;\n+\treturn !sca_mcn_equals(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca)));\n+}\n+\n+/* Shadow or reshadow the SCA on VSIE enter. */\n+static int shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct vsie_sca *vsie_sca)\n+{\n+\tscoped_guard(rwsem_read, \u0026vcpu-\u003ekvm-\u003earch.vsie.vsie_sca_lock) {\n+\t\tif (!shadow_sca_needed(vsie_sca))\n+\t\t\treturn 0;\n+\t}\n+\n+\tguard(rwsem_write)(\u0026vcpu-\u003ekvm-\u003earch.vsie.vsie_sca_lock);\n+\tif (!shadow_sca_needed(vsie_sca))\n+\t\treturn 0;\n+\n+\treturn _shadow_sca(vcpu, vsie_page, vsie_sca);\n+}\n+\n+int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)\n+{\n+\tstruct vsie_page *vsie_page = NULL;\n+\tstruct vsie_sca *vsie_sca = NULL;\n+\tstruct kvm_s390_sie_block *scb_o;\n+\tgpa_t scb_addr;\n+\thpa_t scb_hpa;\n+\tint rc = 0;\n+\n \tvcpu-\u003estat.instruction_sie++;\n \tif (!test_kvm_cpu_feat(vcpu-\u003ekvm, KVM_S390_VM_CPU_FEAT_SIEF2))\n \t\treturn -EOPNOTSUPP;\n@@ -1576,35 +2316,60 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)\n \t\treturn 0;\n \t}\n \n-\tvsie_page = get_vsie_page(vcpu-\u003ekvm, scb_addr);\n-\tif (IS_ERR(vsie_page)) {\n-\t\treturn PTR_ERR(vsie_page);\n-\t} else if (!vsie_page) {\n-\t\t/* double use of sie control block - simply do nothing */\n-\t\tkvm_s390_rewind_psw(vcpu, 4);\n-\t\treturn 0;\n+\trc = pin_guest_page(vcpu-\u003ekvm, scb_addr, \u0026scb_hpa);\n+\tif (rc)\n+\t\treturn kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);\n+\tscb_o = (struct kvm_s390_sie_block *)phys_to_virt(scb_hpa);\n+\n+\tif (!use_ssca(vcpu-\u003ekvm, scb_o)) {\n+\t\t/* get the vsie_page with pinned scb_o */\n+\t\trc = get_vsie_page(vcpu, scb_addr, \u0026vsie_page);\n+\t\tif (rc)\n+\t\t\tgoto out_unpin;\n+\t\tvsie_page-\u003evsie_sca = NULL;\n+\t} else {\n+\t\t/* get the vsie_sca with pinned original sca */\n+\t\trc = get_vsie_sca(vcpu, scb_o, \u0026vsie_sca);\n+\t\tif (rc)\n+\t\t\tgoto out_unpin;\n+\t\trc = get_vsie_page_cpu_nr(vcpu, vsie_sca, scb_addr,\n+\t\t\t\t\t scb_o-\u003eicpua \u0026 KVM_S390_CPU_MASK, \u0026vsie_page);\n+\t\tif (rc)\n+\t\t\tgoto out_put_sca;\n \t}\n \n-\trc = pin_scb(vcpu, vsie_page, scb_addr);\n-\tif (rc)\n-\t\tgoto out_put;\n \trc = shadow_scb(vcpu, vsie_page);\n \tif (rc)\n-\t\tgoto out_unpin_scb;\n+\t\tgoto out_put;\n+\tif (vsie_sca) {\n+\t\t/* pin and shadow the sca including all scb_o in the g3 conf */\n+\t\trc = shadow_sca(vcpu, vsie_page, vsie_sca);\n+\t\tif (rc)\n+\t\t\tgoto out_put;\n+\t}\n+\n \trc = pin_blocks(vcpu, vsie_page);\n \tif (rc)\n \t\tgoto out_unshadow;\n \tregister_shadow_scb(vcpu, vsie_page);\n+\n \trc = vsie_run(vcpu, vsie_page);\n+\n \tunregister_shadow_scb(vcpu);\n \tunpin_blocks(vcpu, vsie_page);\n out_unshadow:\n \tunshadow_scb(vcpu, vsie_page);\n-out_unpin_scb:\n-\tunpin_scb(vcpu, vsie_page, scb_addr);\n out_put:\n \tput_vsie_page(vsie_page);\n+out_put_sca:\n+\tput_vsie_sca(vsie_sca);\n+out_unpin:\n+\tunpin_guest_page(vcpu-\u003ekvm, scb_addr, scb_hpa);\n \n+\tif (rc == -EAGAIN) {\n+\t\tkvm_s390_rewind_psw(vcpu, 4);\n+\t\trc = 0;\n+\t}\n \treturn rc \u003c 0 ? rc : 0;\n }\n \n@@ -1612,30 +2377,55 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)\n void kvm_s390_vsie_init(struct kvm *kvm)\n {\n \tmutex_init(\u0026kvm-\u003earch.vsie.mutex);\n-\tINIT_RADIX_TREE(\u0026kvm-\u003earch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT);\n+\txa_init_flags(\u0026kvm-\u003earch.vsie.addr_to_page, XA_FLAGS_ACCOUNT);\n+\tinit_rwsem(\u0026kvm-\u003earch.vsie.vsie_sca_lock);\n+\txa_init_flags(\u0026kvm-\u003earch.vsie.osca_to_sca, XA_FLAGS_ACCOUNT);\n+}\n+\n+static void kvm_s390_vsie_destroy_page(struct kvm *kvm, struct vsie_page *vsie_page)\n+{\n+\tunpin_scb(kvm, vsie_page);\n+\trelease_gmap_shadow_safe(kvm, vsie_page);\n+\tfree_vsie_page(vsie_page);\n }\n \n /* Destroy the vsie data structures. To be called when a vm is destroyed. */\n void kvm_s390_vsie_destroy(struct kvm *kvm)\n {\n \tstruct vsie_page *vsie_page;\n-\tint i;\n+\tstruct vsie_sca *vsie_sca;\n+\tint i, cpu_nr;\n+\n+\tguard(mutex)(\u0026kvm-\u003earch.vsie.mutex);\n \n-\tmutex_lock(\u0026kvm-\u003earch.vsie.mutex);\n \tfor (i = 0; i \u003c kvm-\u003earch.vsie.page_count; i++) {\n \t\tvsie_page = kvm-\u003earch.vsie.pages[i];\n-\t\tscoped_guard(spinlock, \u0026kvm-\u003earch.gmap-\u003echildren_lock)\n-\t\t\tif (vsie_page-\u003egmap_cache.gmap)\n-\t\t\t\trelease_gmap_shadow(vsie_page);\n \t\tkvm-\u003earch.vsie.pages[i] = NULL;\n-\t\t/* free the radix tree entry */\n-\t\tif (vsie_page-\u003escb_gpa != ULONG_MAX)\n-\t\t\tradix_tree_delete(\u0026kvm-\u003earch.vsie.addr_to_page,\n-\t\t\t\t\t vsie_page-\u003escb_gpa \u003e\u003e SCB_ALIGNMENT_SHIFT);\n-\t\tfree_page((unsigned long)vsie_page);\n+\t\tkvm_s390_vsie_destroy_page(kvm, vsie_page);\n \t}\n+\n \tkvm-\u003earch.vsie.page_count = 0;\n-\tmutex_unlock(\u0026kvm-\u003earch.vsie.mutex);\n+\tfor (i = 0; i \u003c kvm-\u003earch.vsie.sca_count; i++) {\n+\t\tvsie_sca = kvm-\u003earch.vsie.scas[i];\n+\t\tkvm-\u003earch.vsie.scas[i] = NULL;\n+\t\tif (!vsie_sca)\n+\t\t\tcontinue;\n+\n+\t\tfor (cpu_nr = 0; cpu_nr \u003c KVM_S390_MAX_VSIE_VCPUS; cpu_nr++) {\n+\t\t\tvsie_page = vsie_sca-\u003epages[cpu_nr];\n+\t\t\tvsie_sca-\u003epages[cpu_nr] = NULL;\n+\t\t\tif (!vsie_page)\n+\t\t\t\tcontinue;\n+\t\t\tunpin_scb(kvm, vsie_page);\n+\t\t\tkvm_s390_vsie_destroy_page(kvm, vsie_page);\n+\t\t}\n+\n+\t\tunpin_sca(kvm, vsie_sca);\n+\t\tfree_vsie_sca(kvm, vsie_sca);\n+\t}\n+\tkvm-\u003earch.vsie.sca_count = 0;\n+\txa_destroy(\u0026kvm-\u003earch.vsie.addr_to_page);\n+\txa_destroy(\u0026kvm-\u003earch.vsie.osca_to_sca);\n }\n \n void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu)\ndiff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c\nindex 22dd797e62291..40e6e346ee083 100644\n--- a/drivers/s390/char/sclp_early.c\n+++ b/drivers/s390/char/sclp_early.c\n@@ -56,6 +56,7 @@ static void __init sclp_early_facilities_detect(void)\n \t\tsclp.has_diag318 = !!(sccb-\u003ebyte_134 \u0026 0x80);\n \t\tsclp.has_diag320 = !!(sccb-\u003ebyte_134 \u0026 0x04);\n \t\tsclp.has_iplcc = !!(sccb-\u003ebyte_134 \u0026 0x02);\n+\t\tsclp.has_vsie_interp_extf = !!(sccb-\u003ebyte_134 \u0026 0x01);\n \t}\n \tif (sccb-\u003ecpuoff \u003e 137) {\n \t\tsclp.has_sipl = !!(sccb-\u003ecbl \u0026 0x4000);\ndiff --git a/tools/testing/selftests/kvm/include/s390/sie.h b/tools/testing/selftests/kvm/include/s390/sie.h\nindex 160acd4a1db92..4ff1c1a354af5 100644\n--- a/tools/testing/selftests/kvm/include/s390/sie.h\n+++ b/tools/testing/selftests/kvm/include/s390/sie.h\n@@ -223,7 +223,7 @@ struct kvm_s390_sie_block {\n \t__u32\tfac;\t\t\t/* 0x01a0 */\n \t__u8\treserved1a4[20];\t/* 0x01a4 */\n \t__u64\tcbrlo;\t\t\t/* 0x01b8 */\n-\t__u8\treserved1c0[8];\t\t/* 0x01c0 */\n+\t__u64\tosda;\t\t\t/* 0x01c0 */\n #define ECD_HOSTREGMGMT\t0x20000000\n #define ECD_MEF\t\t0x08000000\n #define ECD_ETOKENF\t0x02000000\n"
} |
| 2/1 | 2026/09/20 21:03 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series exclusively modifies s390 architecture code (arch/s390, drivers/s390, and tools/testing/selftests/kvm/include/s390). Because the target architecture is amd64, all modified code paths are structurally unreachable and cannot be built or executed on the target architecture.",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 916c012515bb06ef4903e61a4af5b1f93480b60b
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 20 21:03:52 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/kvm_host_s390.h
index cd692f8fb7643..a19d3a5f550ce 100644
--- a/arch/s390/include/asm/kvm_host_s390.h
+++ b/arch/s390/include/asm/kvm_host_s390.h
@@ -412,6 +412,10 @@ struct kvm_vm_stat {
u64 gmap_shadow_r3_entry;
u64 gmap_shadow_sg_entry;
u64 gmap_shadow_pg_entry;
+ u64 vsie_shadow_scb;
+ u64 vsie_shadow_scb_reuse;
+ u64 vsie_shadow_sca;
+ u64 vsie_shadow_sca_reuse;
};
struct kvm_arch_memory_slot {
@@ -572,13 +576,32 @@ struct sie_page2 {
};
struct vsie_page;
+struct vsie_sca;
+/*
+ * vsie_pages, scas and accompanied management vars
+ */
struct kvm_s390_vsie {
+ /*
+ * protects pages[], page_count, next, addr_to_page
+ */
struct mutex mutex;
- struct radix_tree_root addr_to_page;
+ struct xarray addr_to_page;
int page_count;
int next;
- struct vsie_page *pages[KVM_MAX_VCPUS];
+ struct vsie_page *pages[KVM_S390_MAX_VSIE_VCPUS];
+ /*
+ * The vsie_sca_lock is used to synchronize access to
+ * - the kvm_s390_vsie.scas[]
+ * - the kvm_s390_vsie.osca_to_sca map
+ * - sca_count and sca_next
+ * - new vsie_sca creation and initialization
+ */
+ struct rw_semaphore vsie_sca_lock;
+ struct xarray osca_to_sca;
+ int sca_count;
+ int sca_next;
+ struct vsie_sca *scas[KVM_S390_MAX_VSIE_VCPUS];
};
struct kvm_s390_gisa_iam {
@@ -623,6 +646,7 @@ struct kvm_arch {
int use_pfmfi;
int use_skf;
int use_zpci_interp;
+ int use_ssca;
int user_cpu_state_ctrl;
int user_sigp;
int user_stsi;
diff --git a/arch/s390/include/asm/kvm_host_s390_types.h b/arch/s390/include/asm/kvm_host_s390_types.h
index 9e348a5304217..6eef71072b4ed 100644
--- a/arch/s390/include/asm/kvm_host_s390_types.h
+++ b/arch/s390/include/asm/kvm_host_s390_types.h
@@ -6,10 +6,15 @@
#include <linux/atomic.h>
#include <linux/types.h>
+#define KVM_S390_CPU_MASK 0xff
+#define KVM_S390_MAX_VSIE_VCPUS 256
+#define KVM_S390_MAX_SCA_PAGES 5
+
#define KVM_S390_BSCA_CPU_SLOTS 64
#define KVM_S390_ESCA_CPU_SLOTS 248
#define SCB_ALIGNMENT_SHIFT 9
+#define SCA_ALIGNMENT_SHIFT 6
#define SIGP_CTRL_C 0x80
#define SIGP_CTRL_SCN_MASK 0x3f
@@ -47,6 +52,13 @@ struct bsca_entry {
__u64 reserved2[2];
};
+struct ssca_entry {
+ __u64 reserved1;
+ __u64 ssda;
+ __u64 ossea;
+ __u64 reserved2;
+};
+
union ipte_control {
unsigned long val;
struct {
@@ -88,6 +100,20 @@ struct esca_block {
struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
};
+/*
+ * The shadow sca / ssca needs to cover both bsca and esca depending on what the
+ * guest uses so we allocate space for 256 entries that are defined in the
+ * architecture.
+ * The header part of the struct must not cross page boundaries.
+ */
+struct ssca_block {
+ __u64 osca;
+ __u64 reserved08[7];
+ struct ssca_entry cpu[KVM_S390_MAX_VSIE_VCPUS];
+};
+
+static_assert(offsetof(struct ssca_block, cpu) == 64);
+
/*
* This struct is used to store some machine check info from lowcore
* for machine checks that happen while the guest is running.
@@ -317,7 +343,7 @@ struct kvm_s390_sie_block {
__u32 fac; /* 0x01a0 */
__u8 reserved1a4[20]; /* 0x01a4 */
__u64 cbrlo; /* 0x01b8 */
- __u8 reserved1c0[8]; /* 0x01c0 */
+ __u64 osda; /* 0x01c0 */
#define ECD_HOSTREGMGMT 0x20000000
#define ECD_MEF 0x08000000
#define ECD_ETOKENF 0x02000000
diff --git a/arch/s390/include/asm/sclp.h b/arch/s390/include/asm/sclp.h
index 44066550b9b10..9e960c09ce0b3 100644
--- a/arch/s390/include/asm/sclp.h
+++ b/arch/s390/include/asm/sclp.h
@@ -105,6 +105,7 @@ struct sclp_info {
unsigned char has_dirq : 1;
unsigned char has_iplcc : 1;
unsigned char has_zpci_lsi : 1;
+ unsigned char has_vsie_interp_extf : 1;
unsigned char has_aisii : 1;
unsigned char has_aeni : 1;
unsigned char has_aisi : 1;
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index 5c73f43782a74..0d4480bd2cac3 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -87,6 +87,10 @@ const struct kvm_stats_desc kvm_vm_stats_desc[] = {
STATS_DESC_COUNTER(VM, gmap_shadow_r3_entry),
STATS_DESC_COUNTER(VM, gmap_shadow_sg_entry),
STATS_DESC_COUNTER(VM, gmap_shadow_pg_entry),
+ STATS_DESC_COUNTER(VM, vsie_shadow_scb),
+ STATS_DESC_COUNTER(VM, vsie_shadow_scb_reuse),
+ STATS_DESC_COUNTER(VM, vsie_shadow_sca),
+ STATS_DESC_COUNTER(VM, vsie_shadow_sca_reuse),
};
const struct kvm_stats_header kvm_vm_stats_header = {
@@ -244,6 +248,11 @@ static int async_destroy = 1;
module_param(async_destroy, int, 0444);
MODULE_PARM_DESC(async_destroy, "Asynchronous destroy for protected guests");
+/* allow vsie sigp and srs interpretation if available */
+static bool ssca = true;
+module_param(ssca, bool, 0444);
+MODULE_PARM_DESC(ssca, "VSIE SIGPI and SRSI using the SSCA");
+
#define HMFAI_DWORDS 16
/*
* Base feature mask that defines default mask for facilities. Consists of the
@@ -473,6 +482,8 @@ static void __init kvm_s390_cpu_feat_init(void)
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_KSS);
if (sclp.has_astfleie2)
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ASTFLEIE2);
+ if (sclp.has_vsie_interp_extf && ssca)
+ allow_cpu_feat(KVM_S390_VM_CPU_FEAT_SIGPIF);
/*
* KVM_S390_VM_CPU_FEAT_SKEY: Wrong shadow of PTE.I bits will make
* all skey handling functions read/set the skey from the PGSTE
@@ -487,9 +498,6 @@ static void __init kvm_s390_cpu_feat_init(void)
* For KVM_S390_VM_CPU_FEAT_SKEY, KVM_S390_VM_CPU_FEAT_CMMA and
* KVM_S390_VM_CPU_FEAT_PFMFI, all PTE.I and PGSTE bits have to be
* correctly shadowed. We can do that for the PGSTE but not for PTE.I.
- *
- * KVM_S390_VM_CPU_FEAT_SIGPIF: Wrong SCB addresses in the SCA. We
- * cannot easily shadow the SCA because of the ipte lock.
*/
}
@@ -3359,6 +3367,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
kvm->arch.use_pfmfi = sclp.has_pfmfi;
kvm->arch.use_skf = sclp.has_skey;
+ kvm->arch.use_ssca = sclp.has_vsie_interp_extf && ssca;
spin_lock_init(&kvm->arch.start_stop_lock);
kvm_s390_vsie_init(kvm);
if (use_gisa)
diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c
index 5926689fa2267..04c14d33927a6 100644
--- a/arch/s390/kvm/s390/vsie.c
+++ b/arch/s390/kvm/s390/vsie.c
@@ -29,6 +29,7 @@
enum vsie_page_flags {
VSIE_PAGE_IN_USE = 0,
+ VSIE_PAGE_SCB_PINNED = 1,
};
struct vsie_page {
@@ -56,13 +57,13 @@ struct vsie_page {
gpa_t sdnx_gpa; /* 0x0250 */
/*
* guest address of the original SCB. Remains set for free vsie
- * pages, so we can properly look them up in our addr_to_page
- * radix tree.
+ * pages, so we can properly look them up in our addr_to_page map.
*/
gpa_t scb_gpa; /* 0x0258 */
/* the shadow gmap in use by the vsie_page */
struct gmap_cache gmap_cache; /* 0x0260 */
- __u8 reserved[0x06f8 - 0x0278]; /* 0x0278 */
+ struct vsie_sca *vsie_sca; /* 0x0278 */
+ __u8 reserved[0x06f8 - 0x0280]; /* 0x0280 */
struct kvm_s390_crypto_cb crycb; /* 0x06f8 */
__u8 fac[8 + S390_ARCH_FAC_LIST_SIZE_BYTE];/* 0x07f8 */
};
@@ -71,6 +72,90 @@ static_assert(sizeof(struct vsie_page) == PAGE_SIZE);
static_assert(offsetof(struct vsie_page, mcck_info) == offsetof(struct sie_page, mcck_info));
static_assert(IS_ALIGNED(offsetof(struct vsie_page, crycb), 8));
+struct kvm_address_pair {
+ gpa_t gpa;
+ hpa_t hpa;
+};
+
+enum vsie_sca_flags {
+ VSIE_SCA_ESCA = 0,
+ VSIE_SCA_SCA_PINNED = 1,
+};
+
+struct vsie_sca {
+ struct_group(head,
+ struct ssca_block ssca;
+ );
+ struct_group(keep,
+ struct vsie_page *pages[KVM_S390_MAX_VSIE_VCPUS];
+ /* The mutex is used to synchronize access to the pages[] */
+ struct mutex mutex;
+ atomic_t ref_count;
+ );
+ struct_group(tail,
+ gpa_t sca_gpa;
+ unsigned long flags;
+ u64 mcn[4];
+ unsigned int sca_o_nr_pages;
+ struct kvm_address_pair sca_o_pages[KVM_S390_MAX_SCA_PAGES];
+ );
+};
+
+/*
+ * SSCA needs to be 32-byte aligned and members before the cpu field need to be on the same page.
+ * Forcing it to offset 0 will always fulfill the requirements.
+ */
+static_assert(!(offsetof(struct vsie_sca, ssca)));
+
+/* maximum vsie shadow scb */
+static unsigned int vsie_shadow_scb_max = 1;
+module_param(vsie_shadow_scb_max, uint, 0644);
+MODULE_PARM_DESC(vsie_shadow_scb_max, "Maximum number of VSIE shadow control blocks to keep. Values smaller number VCPUs uses number of VCPUs; maximum 256");
+
+/* maximum vsie shadow sca */
+static unsigned int vsie_shadow_sca_max = 1;
+module_param(vsie_shadow_sca_max, uint, 0644);
+MODULE_PARM_DESC(vsie_shadow_sca_max, "Maximum number of VSIE shadow system control areas to keep. Values smaller number of VCPUs uses number of VCPUs; maximum 256");
+
+static inline hpa_t sca_o_hpa(struct vsie_sca *vsie_sca)
+{
+ return vsie_sca->sca_o_pages[0].hpa | (vsie_sca->sca_gpa & ~PAGE_MASK);
+}
+
+static inline bool sie_uses_esca(struct kvm_s390_sie_block *scb)
+{
+ return (scb->ecb2 & ECB2_ESCA);
+}
+
+static unsigned long read_scao(struct kvm *kvm, struct kvm_s390_sie_block *scb)
+{
+ unsigned long vsie_sca = READ_ONCE(scb->scaol) & ~0xfUL;
+
+ if (test_kvm_cpu_feat(kvm, KVM_S390_VM_CPU_FEAT_64BSCAO))
+ vsie_sca |= (u64)READ_ONCE(scb->scaoh) << 32;
+
+ return vsie_sca;
+}
+
+static void write_scao(struct kvm_s390_sie_block *scb, unsigned long hpa)
+{
+ scb->scaoh = (u32)((u64)hpa >> 32);
+ scb->scaol = (u32)(u64)hpa;
+}
+
+static inline bool use_ssca(struct kvm *kvm, struct kvm_s390_sie_block *scb)
+{
+ if (!kvm->arch.use_ssca)
+ return false;
+ if (!test_kvm_cpu_feat(kvm, KVM_S390_VM_CPU_FEAT_SIGPIF))
+ return false;
+ if (!(scb->eca & ECA_SIGPI) && !(scb->ecb & ECB_SRSI))
+ return false;
+ if (!read_scao(kvm, scb))
+ return false;
+ return true;
+}
+
/* trigger a validity icpt for the given scb */
static int set_validity_icpt(struct kvm_s390_sie_block *scb,
__u16 reason_code)
@@ -81,6 +166,25 @@ static int set_validity_icpt(struct kvm_s390_sie_block *scb,
return 1;
}
+/* The sca header must not cross pages etc. */
+static int validate_scao(struct kvm_vcpu *vcpu, struct kvm_s390_sie_block *scb, gpa_t gpa)
+{
+ int offset;
+
+ if (gpa < 2 * PAGE_SIZE)
+ return set_validity_icpt(scb, 0x0038U);
+ if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
+ return set_validity_icpt(scb, 0x0011U);
+
+ if (sie_uses_esca(scb))
+ offset = offsetof(struct esca_block, cpu[0]) - 1;
+ else
+ offset = offsetof(struct bsca_block, cpu[0]) - 1;
+ if ((gpa & PAGE_MASK) != ((gpa + offset) & PAGE_MASK))
+ return set_validity_icpt(scb, 0x003bU);
+ return 0;
+}
+
/* mark the prefix as unmapped, this will block the VSIE */
static void prefix_unmapped(struct vsie_page *vsie_page)
{
@@ -109,6 +213,148 @@ static int prefix_is_mapped(struct vsie_page *vsie_page)
return !(atomic_read(&vsie_page->scb_s.prog20) & PROG_REQUEST);
}
+static void release_gmap_shadow(struct vsie_page *vsie_page)
+{
+ struct gmap *gmap = vsie_page->gmap_cache.gmap;
+
+ lockdep_assert_held(&gmap->kvm->arch.gmap->children_lock);
+
+ list_del(&vsie_page->gmap_cache.list);
+ vsie_page->gmap_cache.gmap = NULL;
+ prefix_unmapped(vsie_page);
+
+ if (list_empty(&gmap->scb_users)) {
+ gmap_remove_child(gmap);
+ gmap_put(gmap);
+ }
+}
+
+static void release_gmap_shadow_safe(struct kvm *kvm, struct vsie_page *vsie_page)
+{
+ if (!vsie_page->gmap_cache.gmap)
+ return;
+
+ guard(spinlock)(&kvm->arch.gmap->children_lock);
+
+ if (vsie_page->gmap_cache.gmap)
+ release_gmap_shadow(vsie_page);
+}
+
+static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
+{
+ union ctlreg0 cr0;
+ struct gmap *gmap;
+ union asce asce;
+ int edat;
+
+ asce.val = vcpu->arch.sie_block->gcr[1];
+ cr0.val = vcpu->arch.sie_block->gcr[0];
+ edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
+ edat += edat && test_kvm_facility(vcpu->kvm, 78);
+
+ scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) {
+ gmap = vsie_page->gmap_cache.gmap;
+ if (gmap) {
+ /*
+ * ASCE or EDAT could have changed since last icpt, or the gmap
+ * we're holding has been unshadowed. If the gmap is still valid,
+ * we can safely reuse it.
+ */
+ if (gmap_is_shadow_valid(gmap, asce, edat)) {
+ vcpu->kvm->stat.gmap_shadow_reuse++;
+ gmap_get(gmap);
+ return gmap;
+ }
+ /* release the old shadow and mark the prefix as unmapped */
+ release_gmap_shadow(vsie_page);
+ }
+ }
+again:
+ gmap = gmap_create_shadow(vcpu->arch.mc, vcpu->kvm->arch.gmap, asce, edat);
+ if (IS_ERR(gmap))
+ return gmap;
+ scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) {
+ /* unlikely race condition, remove the previous shadow */
+ if (vsie_page->gmap_cache.gmap)
+ release_gmap_shadow(vsie_page);
+ if (!gmap->parent) {
+ gmap_put(gmap);
+ goto again;
+ }
+ vcpu->kvm->stat.gmap_shadow_create++;
+ list_add(&vsie_page->gmap_cache.list, &gmap->scb_users);
+ vsie_page->gmap_cache.gmap = gmap;
+ prefix_unmapped(vsie_page);
+ }
+ return gmap;
+}
+
+/*
+ * Pin the guest page given by gpa and set hpa to the pinned host address.
+ * Will always be pinned writable.
+ *
+ * Returns: - 0 on success
+ * - -EINVAL if the gpa is not valid guest storage
+ */
+static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
+{
+ struct page *page;
+
+ page = gfn_to_page(kvm, gpa_to_gfn(gpa));
+ if (!page)
+ return -EINVAL;
+ *hpa = (hpa_t)page_to_phys(page) + (gpa & ~PAGE_MASK);
+ return 0;
+}
+
+/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */
+static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
+{
+ kvm_release_page_dirty(pfn_to_page(phys_to_pfn(hpa)));
+ /* mark the page always as dirty for migration */
+ mark_page_dirty(kvm, gpa_to_gfn(gpa));
+}
+
+/* unpin multiple guest pages pinned with pin_guest_pages() */
+static void unpin_guest_pages(struct kvm *kvm, struct kvm_address_pair *addr, unsigned int nr_pages)
+{
+ int i;
+
+ for (i = 0; i < nr_pages; i++) {
+ unpin_guest_page(kvm, addr[i].gpa, addr[i].hpa);
+ addr[i].gpa = 0;
+ addr[i].hpa = 0;
+ }
+}
+
+/*
+ * pin nr_pages consecutive guest pages
+ */
+static int pin_guest_pages(struct kvm *kvm, gpa_t gpa, unsigned int nr_pages,
+ struct kvm_address_pair *addr, unsigned int *nr_pages_pinned)
+{
+ int rc = 0, i;
+ hpa_t hpa;
+
+ gpa = gpa & PAGE_MASK;
+
+ /* the guest pages may not be mapped continuously, so pin each page */
+ for (i = 0; i < nr_pages; i++) {
+ rc = pin_guest_page(kvm, gpa + PAGE_SIZE * i, &hpa);
+ if (rc)
+ goto err;
+ addr[i].gpa = gpa + PAGE_SIZE * i;
+ addr[i].hpa = hpa;
+ }
+ *nr_pages_pinned = i;
+ return rc;
+
+err:
+ unpin_guest_pages(kvm, addr, i);
+ *nr_pages_pinned = 0;
+ return rc;
+}
+
/* copy the updated intervention request bits into the shadow scb */
static void update_intervention_requests(struct vsie_page *vsie_page)
{
@@ -124,8 +370,7 @@ static void update_intervention_requests(struct vsie_page *vsie_page)
static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
{
struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
- struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
- int newflags, cpuflags = atomic_read(&scb_o->cpuflags);
+ int newflags, cpuflags = atomic_read(&vsie_page->scb_o->cpuflags);
/* we don't allow ESA/390 guests unless explicitly enabled */
if (!(cpuflags & CPUSTAT_ZARCH) && !vcpu->kvm->arch.allow_vsie_esamode)
@@ -424,18 +669,27 @@ static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
}
}
-/* unshadow the scb, copying parameters back to the real scb */
-static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
+/*
+ * Only write the interception fields back; avoid clobbering the timer and
+ * guest-state fields in scb_o.
+ */
+static inline void unshadow_intercept(struct kvm_s390_sie_block *scb_o,
+ struct kvm_s390_sie_block *scb_s)
{
- struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
- struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
-
- /* interception */
scb_o->icptcode = scb_s->icptcode;
scb_o->icptstatus = scb_s->icptstatus;
scb_o->ipa = scb_s->ipa;
scb_o->ipb = scb_s->ipb;
scb_o->gbea = scb_s->gbea;
+}
+
+/* unshadow the scb, copying parameters back to the real scb */
+static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
+{
+ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
+ struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
+
+ unshadow_intercept(scb_o, scb_s);
/* timer */
scb_o->cputm = scb_s->cputm;
@@ -469,6 +723,39 @@ static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
scb_o->ihcpu = scb_s->ihcpu;
}
+static int shadow_scb_minimal(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
+{
+ struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
+ struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
+ int rc;
+
+ /* make sure we don't have any leftovers when reusing the scb */
+ scb_s->icptcode = 0;
+ scb_s->eca = 0;
+ scb_s->ecb = 0;
+ scb_s->ecb2 = 0;
+ scb_s->ecb3 = 0;
+ scb_s->ecd = 0;
+ scb_s->fac = 0;
+ scb_s->fpf = 0;
+
+ rc = prepare_cpuflags(vcpu, vsie_page);
+ if (rc)
+ return rc;
+
+ scb_s->icpua = scb_o->icpua;
+ scb_s->ecb2 |= scb_o->ecb2 & ECB2_ESCA;
+
+ if (vsie_page->vsie_sca) {
+ scb_s->eca |= scb_o->eca & ECA_SIGPI;
+ scb_s->ecb |= scb_o->ecb & ECB_SRSI;
+ write_scao(scb_s, virt_to_phys(&vsie_page->vsie_sca->ssca));
+ scb_s->osda = virt_to_phys(scb_o);
+ }
+
+ return 0;
+}
+
/*
* Setup the shadow scb by copying and checking the relevant parts of the g2
* provided scb.
@@ -488,19 +775,9 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
unsigned long new_mso = 0;
int rc;
- /* make sure we don't have any leftovers when reusing the scb */
- scb_s->icptcode = 0;
- scb_s->eca = 0;
- scb_s->ecb = 0;
- scb_s->ecb2 = 0;
- scb_s->ecb3 = 0;
- scb_s->ecd = 0;
- scb_s->fac = 0;
- scb_s->fpf = 0;
-
- rc = prepare_cpuflags(vcpu, vsie_page);
+ rc = shadow_scb_minimal(vcpu, vsie_page);
if (rc)
- goto out;
+ goto out_validity;
/* timer */
scb_s->cputm = scb_o->cputm;
@@ -528,8 +805,6 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_KSS))
scb_s->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
- scb_s->icpua = scb_o->icpua;
-
if (!(atomic_read(&scb_s->cpuflags) & CPUSTAT_ZARCH))
new_prefix &= GUEST_PREFIX_MASK_ESA;
else
@@ -614,10 +889,335 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
prepare_ibc(vcpu, vsie_page);
rc = shadow_crycb(vcpu, vsie_page);
-out:
if (rc)
unshadow_scb(vcpu, vsie_page);
return rc;
+
+out_validity:
+ unshadow_intercept(vsie_page->scb_o, &vsie_page->scb_s);
+ return rc;
+}
+
+/* unpin the scb provided by guest 2, marking it as dirty */
+static void unpin_scb(struct kvm *kvm, struct vsie_page *vsie_page)
+{
+ hpa_t hpa;
+
+ if (!test_bit(VSIE_PAGE_SCB_PINNED, &vsie_page->flags))
+ return;
+
+ hpa = virt_to_phys(vsie_page->scb_o);
+ if (hpa)
+ unpin_guest_page(kvm, vsie_page->scb_gpa, hpa);
+ vsie_page->scb_o = NULL;
+ clear_bit(VSIE_PAGE_SCB_PINNED, &vsie_page->flags);
+}
+
+/*
+ * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
+ *
+ * Returns: - 0 if the scb was pinned.
+ * - > 0 if control has to be given to guest 2
+ */
+static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
+{
+ hpa_t hpa;
+ int rc;
+
+ if (test_bit(VSIE_PAGE_SCB_PINNED, &vsie_page->flags))
+ return 0;
+
+ rc = pin_guest_page(vcpu->kvm, vsie_page->scb_gpa, &hpa);
+ if (rc) {
+ rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+ WARN_ON_ONCE(rc);
+ return 1;
+ }
+ vsie_page->scb_o = phys_to_virt(hpa);
+ set_bit(VSIE_PAGE_SCB_PINNED, &vsie_page->flags);
+ return 0;
+}
+
+/*
+ * Unpin g2 original sca in g1 memory.
+ *
+ * Called with vsie_sca_lock held in write, except in the destroy path.
+ */
+static void unpin_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)
+{
+ if (!test_bit(VSIE_SCA_SCA_PINNED, &vsie_sca->flags))
+ return;
+
+ unpin_guest_pages(kvm, vsie_sca->sca_o_pages, vsie_sca->sca_o_nr_pages);
+ vsie_sca->sca_o_nr_pages = 0;
+
+ clear_bit(VSIE_SCA_SCA_PINNED, &vsie_sca->flags);
+}
+
+/*
+ * Pin g2 original sca in g1 memory.
+ *
+ * Called with vsie_sca_lock held in write.
+ */
+static int pin_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)
+{
+ bool is_esca = test_bit(VSIE_SCA_ESCA, &vsie_sca->flags);
+ gpa_t offset = vsie_sca->sca_gpa & ~PAGE_MASK;
+ int rc, nr_pages;
+
+ if (test_bit(VSIE_SCA_SCA_PINNED, &vsie_sca->flags))
+ return 0;
+
+ if (is_esca) {
+ nr_pages = 4;
+ if (offset + sizeof(struct esca_block) > 4 * PAGE_SIZE)
+ nr_pages = 5;
+ } else {
+ nr_pages = 1;
+ if (offset + sizeof(struct bsca_block) > PAGE_SIZE)
+ nr_pages = 2;
+ }
+
+ rc = pin_guest_pages(kvm, vsie_sca->sca_gpa, nr_pages, vsie_sca->sca_o_pages,
+ &vsie_sca->sca_o_nr_pages);
+ if (rc)
+ return rc;
+ set_bit(VSIE_SCA_SCA_PINNED, &vsie_sca->flags);
+
+ return 0;
+}
+
+static int get_sca_entry_addr(struct kvm *kvm, struct vsie_sca *vsie_sca, u16 cpu_nr, gpa_t *gpa,
+ hpa_t *hpa)
+{
+ hpa_t cpu_offset, offset;
+ int pn;
+
+ /*
+ * We cannot simply access the hva since the esca_block has typically
+ * 4 pages (arch max 5 pages) that might not be continuous in g1 memory.
+ * The bsca_block may also be stretched over two pages. Only the header
+ * is guaranteed to be on the same page.
+ */
+ if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags))
+ cpu_offset = offsetof(struct esca_block, cpu[cpu_nr]);
+ else
+ cpu_offset = offsetof(struct bsca_block, cpu[cpu_nr]);
+ pn = ((vsie_sca->sca_gpa & ~PAGE_MASK) + cpu_offset) >> PAGE_SHIFT;
+ offset = (vsie_sca->sca_gpa + cpu_offset) & ~PAGE_MASK;
+ if (WARN_ON_ONCE(pn >= vsie_sca->sca_o_nr_pages))
+ return -EINVAL;
+
+ if (gpa)
+ *gpa = vsie_sca->sca_o_pages[pn].gpa | offset;
+ if (hpa)
+ *hpa = vsie_sca->sca_o_pages[pn].hpa | offset;
+ return 0;
+}
+
+static void put_vsie_sca(struct vsie_sca *vsie_sca)
+{
+ if (!vsie_sca)
+ return;
+
+ WARN_ON_ONCE(atomic_dec_return(&vsie_sca->ref_count) < 0);
+}
+
+/*
+ * Try to find a matching vsie_sca with the correct sca format.
+ * @sca_o_gpa: original system control area address; guest-2 physical
+ * @uses_esca: whether the guest SCB has ECB2_ESCA set
+ *
+ * Called with lock on vsie_sca_lock.
+ */
+static struct vsie_sca *get_vsie_sca_existing(struct kvm *kvm, gpa_t sca_o_gpa, bool uses_esca)
+{
+ struct vsie_sca *vsie_sca = xa_load(&kvm->arch.vsie.osca_to_sca,
+ sca_o_gpa >> SCA_ALIGNMENT_SHIFT);
+
+ if (!vsie_sca)
+ return NULL;
+ if (uses_esca != test_bit(VSIE_SCA_ESCA, &vsie_sca->flags))
+ return NULL;
+ WARN_ON_ONCE(atomic_inc_return(&vsie_sca->ref_count) < 1);
+ return vsie_sca;
+}
+
+/* Try to find and get a currently unused vsie_sca from the vsie struct. */
+static struct vsie_sca *get_vsie_sca_unused(struct kvm *kvm)
+{
+ struct vsie_sca *vsie_sca;
+ int i, ref_count;
+
+ for (i = 0; i < kvm->arch.vsie.sca_count; i++) {
+ vsie_sca = READ_ONCE(kvm->arch.vsie.scas[kvm->arch.vsie.sca_next]);
+ kvm->arch.vsie.sca_next++;
+ kvm->arch.vsie.sca_next %= kvm->arch.vsie.sca_count;
+ ref_count = atomic_inc_return(&vsie_sca->ref_count);
+ WARN_ON_ONCE(ref_count < 1);
+ if (ref_count == 1)
+ return vsie_sca;
+ put_vsie_sca(vsie_sca);
+ }
+ return ERR_PTR(-EAGAIN);
+}
+
+static void free_vsie_sca(struct kvm *kvm, struct vsie_sca *vsie_sca)
+{
+ free_pages_exact(vsie_sca, sizeof(*vsie_sca));
+}
+
+static struct vsie_sca *alloc_vsie_sca(void)
+{
+ struct vsie_sca *vsie_sca;
+
+ vsie_sca = alloc_pages_exact(sizeof(*vsie_sca), GFP_KERNEL_ACCOUNT | __GFP_ZERO);
+ if (!vsie_sca)
+ return NULL;
+
+ mutex_init(&vsie_sca->mutex);
+ atomic_set(&vsie_sca->ref_count, 0);
+
+ return vsie_sca;
+}
+
+/* Clear the vsie_sca struct but keep the vsie_page references, mutex and ref_count */
+static void clear_vsie_sca(struct vsie_sca *vsie_sca)
+{
+ memset(&vsie_sca->head, 0, sizeof(vsie_sca->head));
+ memset(&vsie_sca->tail, 0, sizeof(vsie_sca->tail));
+}
+
+/* Pin and get an existing or new guest-3 system control area.*/
+static int get_vsie_sca(struct kvm_vcpu *vcpu, struct kvm_s390_sie_block *scb_o,
+ struct vsie_sca **vsie_sca_out)
+{
+ struct vsie_sca *vsie_sca, *vsie_sca_new = NULL;
+ gpa_t sca_gpa = read_scao(vcpu->kvm, scb_o);
+ bool is_esca = sie_uses_esca(scb_o);
+ struct vsie_page *vsie_page_n;
+ struct kvm *kvm = vcpu->kvm;
+ unsigned int max_vsie_sca;
+ int rc, cpu_nr;
+
+ /* validate scb_o as we do not unshadow on error here */
+ rc = validate_scao(vcpu, scb_o, sca_gpa);
+ if (rc)
+ return rc;
+
+ down_read(&kvm->arch.vsie.vsie_sca_lock);
+ vsie_sca = get_vsie_sca_existing(kvm, sca_gpa, is_esca);
+ up_read(&kvm->arch.vsie.vsie_sca_lock);
+ if (vsie_sca) {
+ *vsie_sca_out = vsie_sca;
+ return 0;
+ }
+
+ /*
+ * Allocate new vsie_sca, it will likely be needed below.
+ * We want at least #online_vcpus shadows, so every VCPU can execute the
+ * VSIE in parallel. (Worst case all single core VMs.)
+ */
+ max_vsie_sca = min_t(unsigned int, max_t(unsigned int, atomic_read(&kvm->online_vcpus),
+ vsie_shadow_sca_max), KVM_S390_MAX_VSIE_VCPUS);
+
+ if (kvm->arch.vsie.sca_count < max_vsie_sca) {
+ vsie_sca_new = alloc_vsie_sca();
+ if (!vsie_sca_new)
+ return -ENOMEM;
+ }
+
+ /*
+ * Now we're taking the vsie_sca_lock in write mode so that we can manipulate
+ * the xarray and arch.vise.scas, etc.
+ *
+ * In the next lines we try three things to get an SCA:
+ * - Retry getting an existing vsie_sca
+ * - Using our newly allocated vsie_sca if we're under the limit
+ * - Reusing an vsie_sca including ssca to shadow a different osca
+ */
+ down_write(&kvm->arch.vsie.vsie_sca_lock);
+ vsie_sca = xa_load(&kvm->arch.vsie.osca_to_sca, sca_gpa >> SCA_ALIGNMENT_SHIFT);
+ if (vsie_sca) {
+ WARN_ON_ONCE(atomic_inc_return(&vsie_sca->ref_count) < 1);
+ if (is_esca == test_bit(VSIE_SCA_ESCA, &vsie_sca->flags))
+ goto out;
+ /* found vsie_sca with matching sca_gpa but wrong format */
+ put_vsie_sca(vsie_sca);
+ xa_erase(&kvm->arch.vsie.osca_to_sca, sca_gpa >> SCA_ALIGNMENT_SHIFT);
+ }
+
+ /* check again under write lock if we are still under our vsie_sca limit */
+ if (vsie_sca_new && kvm->arch.vsie.sca_count < max_vsie_sca) {
+ /* make use of vsie_sca just created */
+ vsie_sca = vsie_sca_new;
+ vsie_sca_new = NULL;
+
+ kvm->arch.vsie.scas[kvm->arch.vsie.sca_count] = vsie_sca;
+ kvm->arch.vsie.sca_count++;
+ atomic_set(&vsie_sca->ref_count, 1);
+ kvm->stat.vsie_shadow_sca++;
+ } else {
+ /* reuse previously created vsie_sca allocation for different osca */
+ vsie_sca = get_vsie_sca_unused(kvm);
+ /* with nr_vcpus scas one must be reusable */
+ if (IS_ERR(vsie_sca)) {
+ rc = PTR_ERR(vsie_sca);
+ goto out;
+ }
+
+ /* unused vsie_sca exclusive under vsie_sca_lock write lock */
+ xa_erase(&kvm->arch.vsie.osca_to_sca, vsie_sca->sca_gpa >> SCA_ALIGNMENT_SHIFT);
+ for (cpu_nr = 0; cpu_nr < KVM_S390_MAX_VSIE_VCPUS; cpu_nr++) {
+ vsie_page_n = vsie_sca->pages[cpu_nr];
+ if (!vsie_page_n)
+ continue;
+
+ /* unpin but keep the vsie_page for reuse */
+ unpin_scb(kvm, vsie_page_n);
+ release_gmap_shadow_safe(kvm, vsie_page_n);
+ memset(vsie_page_n, 0, sizeof(struct vsie_page));
+ vsie_page_n->scb_gpa = ULONG_MAX;
+ }
+ unpin_sca(kvm, vsie_sca);
+ clear_vsie_sca(vsie_sca);
+ kvm->stat.vsie_shadow_sca_reuse++;
+ }
+
+ if (sie_uses_esca(scb_o))
+ set_bit(VSIE_SCA_ESCA, &vsie_sca->flags);
+ vsie_sca->sca_gpa = sca_gpa;
+
+ /*
+ * The pinned original sca will only be unpinned lazily to limit the
+ * required amount of pins/unpins on each vsie entry/exit.
+ * The unpin is done in the reuse vsie_sca allocation path above and
+ * kvm_s390_vsie_destroy().
+ */
+ rc = pin_sca(kvm, vsie_sca);
+ if (rc) {
+ put_vsie_sca(vsie_sca);
+ vsie_sca->sca_gpa = ULONG_MAX;
+ goto out;
+ }
+
+ rc = xa_insert(&kvm->arch.vsie.osca_to_sca, vsie_sca->sca_gpa >> SCA_ALIGNMENT_SHIFT,
+ vsie_sca, GFP_KERNEL_ACCOUNT);
+ if (rc) {
+ unpin_sca(kvm, vsie_sca);
+ put_vsie_sca(vsie_sca);
+ vsie_sca->sca_gpa = ULONG_MAX;
+ if (rc == -EBUSY)
+ rc = 1;
+ }
+
+out:
+ up_write(&kvm->arch.vsie.vsie_sca_lock);
+ if (vsie_sca_new)
+ free_vsie_sca(kvm, vsie_sca_new);
+ if (vsie_sca)
+ *vsie_sca_out = vsie_sca;
+ return rc;
}
void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, gpa_t start, gpa_t end)
@@ -680,44 +1280,18 @@ static int map_prefix(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct
return rc;
}
-/*
- * Pin the guest page given by gpa and set hpa to the pinned host address.
- * Will always be pinned writable.
- *
- * Returns: - 0 on success
- * - -EINVAL if the gpa is not valid guest storage
- */
-static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa)
-{
- struct page *page;
-
- page = gfn_to_page(kvm, gpa_to_gfn(gpa));
- if (!page)
- return -EINVAL;
- *hpa = (hpa_t)page_to_phys(page) + (gpa & ~PAGE_MASK);
- return 0;
-}
-
-/* Unpins a page previously pinned via pin_guest_page, marking it as dirty. */
-static void unpin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t hpa)
-{
- kvm_release_page_dirty(pfn_to_page(phys_to_pfn(hpa)));
- /* mark the page always as dirty for migration */
- mark_page_dirty(kvm, gpa_to_gfn(gpa));
-}
-
/* unpin all blocks previously pinned by pin_blocks(), marking them dirty */
static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
{
struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
hpa_t hpa;
- hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol;
- if (hpa) {
- unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa);
- vsie_page->sca_gpa = 0;
- scb_s->scaol = 0;
- scb_s->scaoh = 0;
+ if (!vsie_page->vsie_sca) {
+ hpa = (u64) scb_s->scaoh << 32 | scb_s->scaol;
+ if (hpa) {
+ unpin_guest_page(vcpu->kvm, vsie_page->sca_gpa, hpa);
+ write_scao(scb_s, 0);
+ }
}
hpa = scb_s->itdba;
@@ -756,9 +1330,6 @@ static void unpin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
* This works as long as the data lies in one page. If blocks ever exceed one
* page, we have to fall back to shadowing.
*
- * As we reuse the sca, the vcpu pointers contained in it are invalid. We must
- * therefore not enable any facilities that access these pointers (e.g. SIGPIF).
- *
* Returns: - 0 if all blocks were pinned.
* - > 0 if control has to be given to guest 2
* - -ENOMEM if out of memory
@@ -771,27 +1342,17 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
gpa_t gpa;
int rc = 0;
- gpa = READ_ONCE(scb_o->scaol) & ~0xfUL;
- if (test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_64BSCAO))
- gpa |= (u64) READ_ONCE(scb_o->scaoh) << 32;
- if (gpa) {
- if (gpa < 2 * PAGE_SIZE)
- rc = set_validity_icpt(scb_s, 0x0038U);
- else if ((gpa & ~0x1fffUL) == kvm_s390_get_prefix(vcpu))
- rc = set_validity_icpt(scb_s, 0x0011U);
- else if ((gpa & PAGE_MASK) !=
- ((gpa + offsetof(struct bsca_block, cpu[0]) - 1) & PAGE_MASK))
- rc = set_validity_icpt(scb_s, 0x003bU);
- if (!rc) {
- rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc)
- rc = set_validity_icpt(scb_s, 0x0034U);
- }
+ gpa = vsie_page->sca_gpa;
+ if (gpa && !vsie_page->vsie_sca) {
+ rc = validate_scao(vcpu, scb_s, gpa);
if (rc)
goto unpin;
- vsie_page->sca_gpa = gpa;
- scb_s->scaoh = (u32)((u64)hpa >> 32);
- scb_s->scaol = (u32)(u64)hpa;
+ rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
+ if (rc) {
+ rc = set_validity_icpt(scb_s, 0x0034U);
+ goto unpin;
+ }
+ write_scao(scb_s, hpa);
}
gpa = READ_ONCE(scb_o->itdba) & ~0xffUL;
@@ -866,51 +1427,18 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
/* Due to alignment rules (checked above) this cannot
* cross page boundaries
*/
- rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc) {
- rc = set_validity_icpt(scb_s, 0x10b0U);
- goto unpin;
- }
- vsie_page->sdnx_gpa = gpa;
- scb_s->sdnxo = hpa | sdnxc;
- }
- return 0;
-unpin:
- unpin_blocks(vcpu, vsie_page);
- return rc;
-}
-
-/* unpin the scb provided by guest 2, marking it as dirty */
-static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
- gpa_t gpa)
-{
- hpa_t hpa = virt_to_phys(vsie_page->scb_o);
-
- if (hpa)
- unpin_guest_page(vcpu->kvm, gpa, hpa);
- vsie_page->scb_o = NULL;
-}
-
-/*
- * Pin the scb at gpa provided by guest 2 at vsie_page->scb_o.
- *
- * Returns: - 0 if the scb was pinned.
- * - > 0 if control has to be given to guest 2
- */
-static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
- gpa_t gpa)
-{
- hpa_t hpa;
- int rc;
-
- rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
- if (rc) {
- rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
- WARN_ON_ONCE(rc);
- return 1;
+ rc = pin_guest_page(vcpu->kvm, gpa, &hpa);
+ if (rc) {
+ rc = set_validity_icpt(scb_s, 0x10b0U);
+ goto unpin;
+ }
+ vsie_page->sdnx_gpa = gpa;
+ scb_s->sdnxo = hpa | sdnxc;
}
- vsie_page->scb_o = phys_to_virt(hpa);
return 0;
+unpin:
+ unpin_blocks(vcpu, vsie_page);
+ return rc;
}
/*
@@ -1281,71 +1809,6 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc
return rc;
}
-static void release_gmap_shadow(struct vsie_page *vsie_page)
-{
- struct gmap *gmap = vsie_page->gmap_cache.gmap;
-
- lockdep_assert_held(&gmap->kvm->arch.gmap->children_lock);
-
- list_del(&vsie_page->gmap_cache.list);
- vsie_page->gmap_cache.gmap = NULL;
- prefix_unmapped(vsie_page);
-
- if (list_empty(&gmap->scb_users)) {
- gmap_remove_child(gmap);
- gmap_put(gmap);
- }
-}
-
-static struct gmap *acquire_gmap_shadow(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
-{
- union ctlreg0 cr0;
- struct gmap *gmap;
- union asce asce;
- int edat;
-
- asce.val = vcpu->arch.sie_block->gcr[1];
- cr0.val = vcpu->arch.sie_block->gcr[0];
- edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8);
- edat += edat && test_kvm_facility(vcpu->kvm, 78);
-
- scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) {
- gmap = vsie_page->gmap_cache.gmap;
- if (gmap) {
- /*
- * ASCE or EDAT could have changed since last icpt, or the gmap
- * we're holding has been unshadowed. If the gmap is still valid,
- * we can safely reuse it.
- */
- if (gmap_is_shadow_valid(gmap, asce, edat)) {
- vcpu->kvm->stat.gmap_shadow_reuse++;
- gmap_get(gmap);
- return gmap;
- }
- /* release the old shadow and mark the prefix as unmapped */
- release_gmap_shadow(vsie_page);
- }
- }
-again:
- gmap = gmap_create_shadow(vcpu->arch.mc, vcpu->kvm->arch.gmap, asce, edat);
- if (IS_ERR(gmap))
- return gmap;
- scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock) {
- /* unlikely race condition, remove the previous shadow */
- if (vsie_page->gmap_cache.gmap)
- release_gmap_shadow(vsie_page);
- if (!gmap->parent) {
- gmap_put(gmap);
- goto again;
- }
- vcpu->kvm->stat.gmap_shadow_create++;
- list_add(&vsie_page->gmap_cache.list, &gmap->scb_users);
- vsie_page->gmap_cache.gmap = gmap;
- prefix_unmapped(vsie_page);
- }
- return gmap;
-}
-
/*
* Register the shadow scb at the VCPU, e.g. for kicking out of vsie.
*/
@@ -1429,7 +1892,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
*/
if (kvm_s390_vcpu_has_irq(vcpu, 0) ||
kvm_s390_vcpu_sie_inhibited(vcpu)) {
- kvm_s390_rewind_psw(vcpu, 4);
+ rc = -EAGAIN;
break;
}
if (sg)
@@ -1472,93 +1935,370 @@ static void put_vsie_page(struct vsie_page *vsie_page)
clear_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
}
+static void free_vsie_page(struct vsie_page *vsie_page)
+{
+ free_page((unsigned long)vsie_page);
+}
+
+static struct vsie_page *alloc_vsie_page(struct kvm *kvm)
+{
+ struct vsie_page *vsie_page;
+
+ vsie_page = (struct vsie_page *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);
+ if (!vsie_page)
+ return vsie_page;
+
+ /* Mark it as invalid until it resides in the tree. */
+ vsie_page->scb_gpa = ULONG_MAX;
+ return vsie_page;
+}
+
+static int init_vsie_page(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, unsigned long scb_gpa)
+{
+ int rc;
+
+ vsie_page->scb_gpa = scb_gpa;
+ rc = pin_scb(vcpu, vsie_page);
+ if (rc) {
+ vsie_page->scb_gpa = ULONG_MAX;
+ return rc;
+ }
+
+ vsie_page->sca_gpa = read_scao(vcpu->kvm, vsie_page->scb_o);
+
+ return 0;
+}
+
+/* Reset shadow state after a vsie_page has been (re)initialised for a new SCB. */
+static void reset_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)
+{
+ memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));
+ release_gmap_shadow_safe(kvm, vsie_page);
+ prefix_unmapped(vsie_page);
+ vsie_page->fault_addr = 0;
+ vsie_page->scb_s.ihcpu = 0xffffU;
+}
+
/*
* Get or create a vsie page for a scb address.
*
- * Returns: - address of a vsie page (cached or new one)
- * - NULL if the same scb address is already used by another VCPU
- * - ERR_PTR(-ENOMEM) if out of memory
+ * Original control blocks are pinned when the vsie_page pointing to them is
+ * returned.
+ * Newly created vsie_pages only have vsie_page->scb_gpa and vsie_page->sca_gpa
+ * set.
+ *
+ * Returns: - -EBUSY if the same scb address is already used by another VCPU
+ * - -ENOMEM if out of memory
*/
-static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
+static int get_vsie_page(struct kvm_vcpu *vcpu, unsigned long addr,
+ struct vsie_page **vsie_page_out)
{
- struct vsie_page *vsie_page;
- int nr_vcpus;
-
- rcu_read_lock();
- vsie_page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> SCB_ALIGNMENT_SHIFT);
- rcu_read_unlock();
- if (vsie_page) {
- if (try_get_vsie_page(vsie_page)) {
- if (vsie_page->scb_gpa == addr)
- return vsie_page;
- /*
- * We raced with someone reusing + putting this vsie
- * page before we grabbed it.
- */
- put_vsie_page(vsie_page);
+ struct vsie_page *vsie_page, *vsie_page_new = NULL;
+ struct kvm *kvm = vcpu->kvm;
+ unsigned int max_vsie_page;
+ int rc, pages_idx;
+
+ vsie_page = xa_load(&kvm->arch.vsie.addr_to_page, addr >> SCB_ALIGNMENT_SHIFT);
+ if (vsie_page && try_get_vsie_page(vsie_page)) {
+ if (vsie_page->scb_gpa == addr) {
+ *vsie_page_out = vsie_page;
+ return 0;
}
+ /*
+ * We raced with someone reusing + putting this vsie
+ * page before we grabbed it.
+ */
+ put_vsie_page(vsie_page);
}
- /*
- * We want at least #online_vcpus shadows, so every VCPU can execute
- * the VSIE in parallel.
- */
- nr_vcpus = atomic_read(&kvm->online_vcpus);
+ max_vsie_page = min_t(unsigned int, max_t(unsigned int, atomic_read(&kvm->online_vcpus),
+ vsie_shadow_scb_max), KVM_S390_MAX_VSIE_VCPUS);
+
+ /* allocate new vsie_page - we will likely need it */
+ if (kvm->arch.vsie.page_count < max_vsie_page) {
+ vsie_page_new = alloc_vsie_page(kvm);
+ if (!vsie_page_new)
+ return -ENOMEM;
+ __set_bit(VSIE_PAGE_IN_USE, &vsie_page_new->flags);
+ }
mutex_lock(&kvm->arch.vsie.mutex);
- if (kvm->arch.vsie.page_count < nr_vcpus) {
- vsie_page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);
- if (!vsie_page) {
+ vsie_page = xa_load(&kvm->arch.vsie.addr_to_page, addr >> SCB_ALIGNMENT_SHIFT);
+ if (vsie_page && try_get_vsie_page(vsie_page)) {
+ if (vsie_page->scb_gpa == addr) {
mutex_unlock(&kvm->arch.vsie.mutex);
- return ERR_PTR(-ENOMEM);
+ if (vsie_page_new)
+ free_vsie_page(vsie_page_new);
+ *vsie_page_out = vsie_page;
+ return 0;
}
- __set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);
- kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = vsie_page;
+ /*
+ * We raced with someone reusing + putting this vsie
+ * page before we grabbed it.
+ */
+ put_vsie_page(vsie_page);
+ }
+
+ if (kvm->arch.vsie.page_count < max_vsie_page) {
+ pages_idx = kvm->arch.vsie.page_count;
+ vsie_page = vsie_page_new;
+ vsie_page_new = NULL;
+ WRITE_ONCE(kvm->arch.vsie.pages[kvm->arch.vsie.page_count], vsie_page);
kvm->arch.vsie.page_count++;
+ kvm->stat.vsie_shadow_scb++;
} else {
/* reuse an existing entry that belongs to nobody */
while (true) {
- vsie_page = kvm->arch.vsie.pages[kvm->arch.vsie.next];
+ pages_idx = kvm->arch.vsie.next;
+ kvm->arch.vsie.next++;
+ kvm->arch.vsie.next %= kvm->arch.vsie.page_count;
+ vsie_page = kvm->arch.vsie.pages[pages_idx];
if (try_get_vsie_page(vsie_page))
break;
- kvm->arch.vsie.next++;
- kvm->arch.vsie.next %= nr_vcpus;
}
if (vsie_page->scb_gpa != ULONG_MAX)
- radix_tree_delete(&kvm->arch.vsie.addr_to_page,
- vsie_page->scb_gpa >> SCB_ALIGNMENT_SHIFT);
+ xa_erase(&kvm->arch.vsie.addr_to_page,
+ vsie_page->scb_gpa >> SCB_ALIGNMENT_SHIFT);
+
+ unpin_scb(kvm, vsie_page);
+ /* Mark it as invalid until it resides in the tree. */
+ vsie_page->scb_gpa = ULONG_MAX;
+ kvm->stat.vsie_shadow_scb_reuse++;
}
- /* Mark it as invalid until it resides in the tree. */
- vsie_page->scb_gpa = ULONG_MAX;
- /* Double use of the same address or allocation failure. */
- if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> SCB_ALIGNMENT_SHIFT,
- vsie_page)) {
- put_vsie_page(vsie_page);
- mutex_unlock(&kvm->arch.vsie.mutex);
- return NULL;
+ rc = init_vsie_page(vcpu, vsie_page, addr);
+ if (!rc) {
+ rc = xa_insert(&kvm->arch.vsie.addr_to_page, addr >> SCB_ALIGNMENT_SHIFT, vsie_page,
+ GFP_KERNEL_ACCOUNT);
+ if (rc == -EBUSY)
+ rc = -EAGAIN;
}
- vsie_page->scb_gpa = addr;
+
mutex_unlock(&kvm->arch.vsie.mutex);
+ if (vsie_page_new)
+ free_vsie_page(vsie_page_new);
+ if (rc) {
+ unpin_scb(kvm, vsie_page);
+ vsie_page->scb_gpa = ULONG_MAX;
+ put_vsie_page(vsie_page);
+ return rc;
+ }
- memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));
- if (vsie_page->gmap_cache.gmap) {
- scoped_guard(spinlock, &kvm->arch.gmap->children_lock)
- if (vsie_page->gmap_cache.gmap)
- release_gmap_shadow(vsie_page);
+ reset_vsie_page(kvm, vsie_page);
+
+ *vsie_page_out = vsie_page;
+ return 0;
+}
+
+static int get_vsie_page_cpu_nr(struct kvm_vcpu *vcpu, struct vsie_sca *vsie_sca, gpa_t scb_gpa,
+ u16 cpu_nr, struct vsie_page **vsie_page_out)
+{
+ struct vsie_page *vsie_page, *vsie_page_new = NULL;
+ bool vsie_page_is_new = true;
+ int rc;
+
+ vsie_page = vsie_sca->pages[cpu_nr];
+ if (!vsie_page) {
+ vsie_page_new = alloc_vsie_page(vcpu->kvm);
+ if (!vsie_page_new)
+ return -ENOMEM;
+ vsie_page_new->vsie_sca = vsie_sca;
+ __set_bit(VSIE_PAGE_IN_USE, &vsie_page_new->flags);
+
+ /* be careful to not loose a page here if we raced */
+ scoped_guard(mutex, &vsie_sca->mutex) {
+ vsie_page = vsie_sca->pages[cpu_nr];
+ if (!vsie_page) {
+ WRITE_ONCE(vsie_sca->pages[cpu_nr], vsie_page_new);
+ vsie_page = vsie_page_new;
+ }
+ }
}
- prefix_unmapped(vsie_page);
- vsie_page->fault_addr = 0;
- vsie_page->scb_s.ihcpu = 0xffffU;
- return vsie_page;
+ if (vsie_page != vsie_page_new) {
+ vsie_page_is_new = false;
+ if (vsie_page_new)
+ free_vsie_page(vsie_page_new);
+
+ /* not a new vsie_page so get it */
+ if (!try_get_vsie_page(vsie_page))
+ return -EAGAIN;
+ vsie_page->vsie_sca = vsie_sca;
+ }
+ if (vsie_page->scb_gpa != scb_gpa || vsie_page->sca_gpa != vsie_sca->sca_gpa) {
+ scoped_guard(mutex, &vcpu->kvm->arch.vsie.mutex) {
+ unpin_scb(vcpu->kvm, vsie_page);
+ rc = init_vsie_page(vcpu, vsie_page, scb_gpa);
+ }
+ if (vsie_page_is_new)
+ vcpu->kvm->stat.vsie_shadow_scb++;
+ else
+ vcpu->kvm->stat.vsie_shadow_scb_reuse++;
+ if (rc) {
+ put_vsie_page(vsie_page);
+ return rc;
+ }
+
+ reset_vsie_page(vcpu->kvm, vsie_page);
+ }
+
+ *vsie_page_out = vsie_page;
+ return 0;
}
-int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
+/*
+ * Copy the mcn from the osca to the vsie_sca to be able to detect mcn changes later on.
+ *
+ * @vsie_sca: vsie_sca to copy mcn to.
+ * @sca: Pointer to a struct bsca_block or struct esca_block to read from.
+ */
+static void sca_mcn_copy(struct vsie_sca *vsie_sca, void *sca)
{
- struct vsie_page *vsie_page;
- unsigned long scb_addr;
+ int offset = offsetof(struct bsca_block, mcn);
+ int size = sizeof(unsigned long);
+
+ if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags)) {
+ offset = offsetof(struct esca_block, mcn);
+ size = size * 4;
+ }
+ memcpy(&vsie_sca->mcn, sca + offset, size);
+}
+
+/*
+ * Compare the mcn from the given sca to the vsie_sca to be able to detect mcn changes.
+ *
+ * @vsie_sca: vsie_sca to compare mcn to.
+ * @sca: Pointer to a struct bsca_block or struct esca_block to compare to.
+ */
+static bool sca_mcn_equals(struct vsie_sca *vsie_sca, void *sca)
+{
+ int offset = offsetof(struct bsca_block, mcn);
+ int size = sizeof(unsigned long);
+
+ if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags)) {
+ size = size * 4;
+ offset = offsetof(struct esca_block, mcn);
+ }
+
+ return !memcmp(&vsie_sca->mcn, sca + offset, size);
+}
+
+static void update_vsie_sca(struct vsie_sca *vsie_sca, unsigned int cpu_nr,
+ struct vsie_page *vsie_page_n, hpa_t sca_o_entry_hpa)
+{
+ guard(mutex)(&vsie_sca->mutex);
+
+ WRITE_ONCE(vsie_sca->ssca.cpu[cpu_nr].ssda, virt_to_phys(&vsie_page_n->scb_s));
+ WRITE_ONCE(vsie_sca->ssca.cpu[cpu_nr].ossea, sca_o_entry_hpa);
+ WRITE_ONCE(vsie_sca->pages[cpu_nr], vsie_page_n);
+}
+
+static int _shadow_sca_cpu(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
+ struct vsie_sca *vsie_sca, hpa_t sca_o_entry_hpa,
+ unsigned int cpu_nr, bool is_esca)
+{
+ hva_t sca_o_entry_hva = (hva_t)phys_to_virt(sca_o_entry_hpa);
+ struct vsie_page *vsie_page_n;
+ gpa_t scb_o_gpa;
+ int rc;
+
+ if (is_esca)
+ scb_o_gpa = ((struct esca_entry *)sca_o_entry_hva)->sda;
+ else
+ scb_o_gpa = ((struct bsca_entry *)sca_o_entry_hva)->sda;
+ if (scb_o_gpa & 0x1ffUL)
+ return set_validity_icpt(vsie_page->scb_o, 0x0001U);
+
+ rc = get_vsie_page_cpu_nr(vcpu, vsie_sca, scb_o_gpa, cpu_nr, &vsie_page_n);
+ if (rc)
+ return rc;
+
+ rc = shadow_scb_minimal(vcpu, vsie_page_n);
+ update_vsie_sca(vsie_sca, cpu_nr, vsie_page_n, sca_o_entry_hpa);
+ if (rc) {
+ /* copy intercept to primary scb_o, no unshadow_scb() on exit */
+ unshadow_intercept(vsie_page->scb_o, &vsie_page_n->scb_s);
+ rc = 1;
+ }
+ put_vsie_page(vsie_page_n);
+
+ return rc;
+}
+
+/* Fill the shadow system control area used for VSIE SIGPI. */
+static int _shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
+ struct vsie_sca *vsie_sca)
+{
+ bool is_esca = sie_uses_esca(vsie_page->scb_o);
+ unsigned int cpu_nr, cpu_slots;
+ hpa_t sca_o_entry_hpa;
int rc;
+ if (is_esca)
+ set_bit(VSIE_SCA_ESCA, &vsie_sca->flags);
+ else
+ clear_bit(VSIE_SCA_ESCA, &vsie_sca->flags);
+ sca_mcn_copy(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca)));
+
+ /* pin and make minimal shadow for ALL scb in the sca */
+ cpu_slots = is_esca ? KVM_S390_MAX_VSIE_VCPUS : KVM_S390_BSCA_CPU_SLOTS;
+ for_each_set_bit_inv(cpu_nr, (unsigned long *)&vsie_sca->mcn, cpu_slots) {
+ rc = get_sca_entry_addr(vcpu->kvm, vsie_sca, cpu_nr, NULL, &sca_o_entry_hpa);
+ if (rc)
+ break;
+
+ if ((vsie_page->scb_o->icpua & KVM_S390_CPU_MASK) == cpu_nr) {
+ update_vsie_sca(vsie_sca, cpu_nr, vsie_page, sca_o_entry_hpa);
+ continue;
+ }
+
+ rc = _shadow_sca_cpu(vcpu, vsie_page, vsie_sca, sca_o_entry_hpa, cpu_nr, is_esca);
+ if (rc)
+ break;
+ }
+
+ if (rc) {
+ vsie_sca->ssca.osca = 0;
+ for_each_set_bit_inv(cpu_nr, (unsigned long *)&vsie_sca->mcn, cpu_slots) {
+ vsie_sca->ssca.cpu[cpu_nr].ssda = 0;
+ vsie_sca->ssca.cpu[cpu_nr].ossea = 0;
+ }
+ } else {
+ vsie_sca->ssca.osca = sca_o_hpa(vsie_sca);
+ }
+ return rc;
+}
+
+static bool shadow_sca_needed(struct vsie_sca *vsie_sca)
+{
+ if (!vsie_sca->ssca.osca)
+ return true;
+ return !sca_mcn_equals(vsie_sca, phys_to_virt(sca_o_hpa(vsie_sca)));
+}
+
+/* Shadow or reshadow the SCA on VSIE enter. */
+static int shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct vsie_sca *vsie_sca)
+{
+ scoped_guard(rwsem_read, &vcpu->kvm->arch.vsie.vsie_sca_lock) {
+ if (!shadow_sca_needed(vsie_sca))
+ return 0;
+ }
+
+ guard(rwsem_write)(&vcpu->kvm->arch.vsie.vsie_sca_lock);
+ if (!shadow_sca_needed(vsie_sca))
+ return 0;
+
+ return _shadow_sca(vcpu, vsie_page, vsie_sca);
+}
+
+int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
+{
+ struct vsie_page *vsie_page = NULL;
+ struct vsie_sca *vsie_sca = NULL;
+ struct kvm_s390_sie_block *scb_o;
+ gpa_t scb_addr;
+ hpa_t scb_hpa;
+ int rc = 0;
+
vcpu->stat.instruction_sie++;
if (!test_kvm_cpu_feat(vcpu->kvm, KVM_S390_VM_CPU_FEAT_SIEF2))
return -EOPNOTSUPP;
@@ -1576,35 +2316,60 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
return 0;
}
- vsie_page = get_vsie_page(vcpu->kvm, scb_addr);
- if (IS_ERR(vsie_page)) {
- return PTR_ERR(vsie_page);
- } else if (!vsie_page) {
- /* double use of sie control block - simply do nothing */
- kvm_s390_rewind_psw(vcpu, 4);
- return 0;
+ rc = pin_guest_page(vcpu->kvm, scb_addr, &scb_hpa);
+ if (rc)
+ return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+ scb_o = (struct kvm_s390_sie_block *)phys_to_virt(scb_hpa);
+
+ if (!use_ssca(vcpu->kvm, scb_o)) {
+ /* get the vsie_page with pinned scb_o */
+ rc = get_vsie_page(vcpu, scb_addr, &vsie_page);
+ if (rc)
+ goto out_unpin;
+ vsie_page->vsie_sca = NULL;
+ } else {
+ /* get the vsie_sca with pinned original sca */
+ rc = get_vsie_sca(vcpu, scb_o, &vsie_sca);
+ if (rc)
+ goto out_unpin;
+ rc = get_vsie_page_cpu_nr(vcpu, vsie_sca, scb_addr,
+ scb_o->icpua & KVM_S390_CPU_MASK, &vsie_page);
+ if (rc)
+ goto out_put_sca;
}
- rc = pin_scb(vcpu, vsie_page, scb_addr);
- if (rc)
- goto out_put;
rc = shadow_scb(vcpu, vsie_page);
if (rc)
- goto out_unpin_scb;
+ goto out_put;
+ if (vsie_sca) {
+ /* pin and shadow the sca including all scb_o in the g3 conf */
+ rc = shadow_sca(vcpu, vsie_page, vsie_sca);
+ if (rc)
+ goto out_put;
+ }
+
rc = pin_blocks(vcpu, vsie_page);
if (rc)
goto out_unshadow;
register_shadow_scb(vcpu, vsie_page);
+
rc = vsie_run(vcpu, vsie_page);
+
unregister_shadow_scb(vcpu);
unpin_blocks(vcpu, vsie_page);
out_unshadow:
unshadow_scb(vcpu, vsie_page);
-out_unpin_scb:
- unpin_scb(vcpu, vsie_page, scb_addr);
out_put:
put_vsie_page(vsie_page);
+out_put_sca:
+ put_vsie_sca(vsie_sca);
+out_unpin:
+ unpin_guest_page(vcpu->kvm, scb_addr, scb_hpa);
+ if (rc == -EAGAIN) {
+ kvm_s390_rewind_psw(vcpu, 4);
+ rc = 0;
+ }
return rc < 0 ? rc : 0;
}
@@ -1612,30 +2377,55 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
void kvm_s390_vsie_init(struct kvm *kvm)
{
mutex_init(&kvm->arch.vsie.mutex);
- INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT);
+ xa_init_flags(&kvm->arch.vsie.addr_to_page, XA_FLAGS_ACCOUNT);
+ init_rwsem(&kvm->arch.vsie.vsie_sca_lock);
+ xa_init_flags(&kvm->arch.vsie.osca_to_sca, XA_FLAGS_ACCOUNT);
+}
+
+static void kvm_s390_vsie_destroy_page(struct kvm *kvm, struct vsie_page *vsie_page)
+{
+ unpin_scb(kvm, vsie_page);
+ release_gmap_shadow_safe(kvm, vsie_page);
+ free_vsie_page(vsie_page);
}
/* Destroy the vsie data structures. To be called when a vm is destroyed. */
void kvm_s390_vsie_destroy(struct kvm *kvm)
{
struct vsie_page *vsie_page;
- int i;
+ struct vsie_sca *vsie_sca;
+ int i, cpu_nr;
+
+ guard(mutex)(&kvm->arch.vsie.mutex);
- mutex_lock(&kvm->arch.vsie.mutex);
for (i = 0; i < kvm->arch.vsie.page_count; i++) {
vsie_page = kvm->arch.vsie.pages[i];
- scoped_guard(spinlock, &kvm->arch.gmap->children_lock)
- if (vsie_page->gmap_cache.gmap)
- release_gmap_shadow(vsie_page);
kvm->arch.vsie.pages[i] = NULL;
- /* free the radix tree entry */
- if (vsie_page->scb_gpa != ULONG_MAX)
- radix_tree_delete(&kvm->arch.vsie.addr_to_page,
- vsie_page->scb_gpa >> SCB_ALIGNMENT_SHIFT);
- free_page((unsigned long)vsie_page);
+ kvm_s390_vsie_destroy_page(kvm, vsie_page);
}
+
kvm->arch.vsie.page_count = 0;
- mutex_unlock(&kvm->arch.vsie.mutex);
+ for (i = 0; i < kvm->arch.vsie.sca_count; i++) {
+ vsie_sca = kvm->arch.vsie.scas[i];
+ kvm->arch.vsie.scas[i] = NULL;
+ if (!vsie_sca)
+ continue;
+
+ for (cpu_nr = 0; cpu_nr < KVM_S390_MAX_VSIE_VCPUS; cpu_nr++) {
+ vsie_page = vsie_sca->pages[cpu_nr];
+ vsie_sca->pages[cpu_nr] = NULL;
+ if (!vsie_page)
+ continue;
+ unpin_scb(kvm, vsie_page);
+ kvm_s390_vsie_destroy_page(kvm, vsie_page);
+ }
+
+ unpin_sca(kvm, vsie_sca);
+ free_vsie_sca(kvm, vsie_sca);
+ }
+ kvm->arch.vsie.sca_count = 0;
+ xa_destroy(&kvm->arch.vsie.addr_to_page);
+ xa_destroy(&kvm->arch.vsie.osca_to_sca);
}
void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu)
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
index 22dd797e62291..40e6e346ee083 100644
--- a/drivers/s390/char/sclp_early.c
+++ b/drivers/s390/char/sclp_early.c
@@ -56,6 +56,7 @@ static void __init sclp_early_facilities_detect(void)
sclp.has_diag318 = !!(sccb->byte_134 & 0x80);
sclp.has_diag320 = !!(sccb->byte_134 & 0x04);
sclp.has_iplcc = !!(sccb->byte_134 & 0x02);
+ sclp.has_vsie_interp_extf = !!(sccb->byte_134 & 0x01);
}
if (sccb->cpuoff > 137) {
sclp.has_sipl = !!(sccb->cbl & 0x4000);
diff --git a/tools/testing/selftests/kvm/include/s390/sie.h b/tools/testing/selftests/kvm/include/s390/sie.h
index 160acd4a1db92..4ff1c1a354af5 100644
--- a/tools/testing/selftests/kvm/include/s390/sie.h
+++ b/tools/testing/selftests/kvm/include/s390/sie.h
@@ -223,7 +223,7 @@ struct kvm_s390_sie_block {
__u32 fac; /* 0x01a0 */
__u8 reserved1a4[20]; /* 0x01a4 */
__u64 cbrlo; /* 0x01b8 */
- __u8 reserved1c0[8]; /* 0x01c0 */
+ __u64 osda; /* 0x01c0 */
#define ECD_HOSTREGMGMT 0x20000000
#define ECD_MEF 0x08000000
#define ECD_ETOKENF 0x02000000
|
| 3/2 | 2026/09/20 21:03 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27903 output: 32 thoughts: 611 Thoughts: **WorthFuzzing Evaluation: Negative** Okay, here's the deal. I need to figure out if this patch series is worth fuzzing with syzkaller. First things first, the target architecture is amd64. Got it. But hold on, I see the modified files: they're all in `arch/s390`, `drivers/s390`, and `tools/testing/.../s390`. My internal alarm bells are going off. Now, let's go back and carefully analyze those *negative* criteria. We have these specific reasons to reject fuzzing. I need to make sure none of these apply. Looking at the criteria, there's a specific bullet point that catches my attention: "* Code paths exclusive to architectures other than the target architecture." Bingo. My immediate gut reaction is that this is the case here. The target is amd64, and we're looking at `arch/s390` code. Is this s390 code reachable on amd64? Nope! The very name, `arch/s390`, screams that this is s390-specific architecture. Just to be absolutely sure, I'm checking the Kconfig and Makefiles in `drivers/s390` or anything in `arch/s390`, but it's clear: `arch/s390` is for s390, not amd64. This is an unreachable execution path for the specified target. Therefore, because all the modified code is *strictly* related to an architecture *other* than the target, this patch series is **not** worth fuzzing, and I will set `WorthFuzzing=false`. |
| 4/2 | 2026/09/20 21:03 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_S390",
"PathPrefix": "drivers/s390"
}Results: {
"Output": "drivers/s390/char/Makefile=44=tape_s390-objs := tape_3490.o tape_char.o tape_class.o tape_core.o tape_std.o $(tape-y)\ndrivers/s390/char/Makefile:45:obj-$(CONFIG_S390_TAPE) += tape_s390.o\ndrivers/s390/char/Makefile-46-obj-$(CONFIG_MONREADER) += monreader.o\ndrivers/s390/char/Makefile=47=obj-$(CONFIG_MONWRITER) += monwriter.o\ndrivers/s390/char/Makefile:48:obj-$(CONFIG_S390_VMUR) += vmur.o\ndrivers/s390/char/Makefile-49-obj-$(CONFIG_CRASH_DUMP) += sclp_sdias.o zcore.o\ndrivers/s390/char/Makefile:50:obj-$(CONFIG_S390_UV_UAPI) += uvdevice.o\ndrivers/s390/char/Makefile-51-\n--\ndrivers/s390/virtio/Makefile=6=CONTEXT_ANALYSIS := y\ndrivers/s390/virtio/Makefile-7-\ndrivers/s390/virtio/Makefile:8:obj-$(CONFIG_S390_GUEST) += virtio_ccw.o\n"
} |
| 5/2 | 2026/09/20 21:03 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29269 output: 27 thoughts: 19 Thoughts: Here's my summary, as if I were thinking these thoughts: **Investigating Driver Inclusion in the Build Process** Okay, so I need to figure out precisely how the s390 driver code is integrated into the build. To do that, the logical first step is to dive into the `drivers/Makefile`. This is the central point for managing the compilation of kernel drivers, so it's the most likely place to find how the s390-specific components are brought into the broader build process. I'm expecting to see an include statement, a conditional block, or something similar that specifies the rules for incorporating the `drivers/s390` directory. Let's get to it. |
| 6/2 | 2026/09/20 21:04 | tool | grepper |
0mArgs:{
"Expression": "s390",
"PathPrefix": "drivers/Makefile"
}Results: {
"Output": "drivers/Makefile=199=obj-$(CONFIG_DIBS)\t\t+= dibs/\ndrivers/Makefile:200:obj-$(CONFIG_S390)\t\t+= s390/\n"
} |
| 7/2 | 2026/09/20 21:04 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29524 output: 103 thoughts: 1013 Thoughts: **Analysis of the Patch for Fuzzing Eligibility**
Okay, let's break this down. From the `Makefile`, it's clear that code under `drivers/s390/` is specific to the `s390` architecture, and the `arch/s390` directory is *only* built when `CONFIG_S390` is enabled. The `tools/testing/selftests/...` directory contains userspace self-tests. The target architecture, in this case, is `amd64`.
Therefore, the modified code is exclusively:
* User-space self-tests within `tools/testing/selftests/kvm/include/s390/sie.h`.
* Code paths dedicated to architectures other than the target (`amd64`):
* `arch/s390/include/asm/kvm_host_s390.h`
* `arch/s390/include/asm/kvm_host_s390_types.h`
* `arch/s390/include/asm/sclp.h`
* `arch/s390/kvm/s390/s390.c`
* `arch/s390/kvm/s390/vsie.c`
* `drivers/s390/char/sclp_early.c`
Now, let's cross-reference this with Section 2 of the prompt. We're looking for reasons to return `WorthFuzzing=false`. And there it is: "Code paths exclusive to architectures other than the target architecture" – that's a perfect match!
The target is `amd64`. ALL the modified code lives within the `s390` architecture (`arch/s390/`, `drivers/s390/`, and s390-specific selftests). This code *cannot* be compiled or executed on `amd64`.
Consequently, I'm setting:
* `WorthFuzzing = false`
* `EnableConfigs = []` (no specific configurations are relevant)
* `FocusSymbols = []` (no specific symbols need attention)
The reasoning is straightforward: The patch series focuses on `s390`-specific code (both kernel and userspace testing), which is completely unreachable from the `amd64` target.
Just to be absolutely certain, let's quickly re-check the modified files:
1. `arch/s390/include/asm/kvm_host_s390.h`
2. `arch/s390/include/asm/kvm_host_s390_types.h`
3. `arch/s390/include/asm/sclp.h`
4. `arch/s390/kvm/s390/s390.c`
5. `arch/s390/kvm/s390/vsie.c`
6. `drivers/s390/char/sclp_early.c`
7. `tools/testing/selftests/kvm/include/s390/sie.h`
Yup. Every single file is either specific to `s390` or within the `selftests` directory. `WorthFuzzing=false` is definitely the right call. Time to call `set-results`.
|
| 8/2 | 2026/09/20 21:04 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch series exclusively modifies s390 architecture code (arch/s390, drivers/s390, and tools/testing/selftests/kvm/include/s390). Because the target architecture is amd64, all modified code paths are structurally unreachable and cannot be built or executed on the target architecture.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series exclusively modifies s390 architecture code (arch/s390, drivers/s390, and tools/testing/selftests/kvm/include/s390). Because the target architecture is amd64, all modified code paths are structurally unreachable and cannot be built or executed on the target architecture.",
"WorthFuzzing": false
} |
| 9/1 | 2026/09/20 21:04 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|