| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/06/27 01:49 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"KVM_AMD_SEV"
],
"FocusSymbols": [
"kvm_arch_flush_shadow_memslot",
"__kvm_mmu_zap_all_fast_front_half",
"__kvm_mmu_zap_all_fast_back_half",
"sev_snp_init_protected_guest_state",
"__sev_snp_reload_vmsa",
"sev_snp_reload_vmsa",
"sev_gmem_invalidate_range",
"sev_gmem_free_folio"
],
"Reasoning": "The patch modifies core KVM MMU logic for flushing shadow memslots and introduces new SEV-SNP specific logic for handling guest_memfd invalidations and VMSA reloading. These changes are reachable via KVM ioctls and guest execution.",
"WorthFuzzing": true
} |
| 1/1 | 2026/06/27 01:49 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 14debc60cc473296addc95629b20432d1cf25808\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sat Jun 27 01:49:49 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h\nindex 83dc5086138b39..fd08454c755364 100644\n--- a/arch/x86/include/asm/kvm-x86-ops.h\n+++ b/arch/x86/include/asm/kvm-x86-ops.h\n@@ -134,6 +134,7 @@ KVM_X86_OP_OPTIONAL(mem_enc_unregister_region)\n KVM_X86_OP_OPTIONAL(vm_copy_enc_context_from)\n KVM_X86_OP_OPTIONAL(vm_move_enc_context_from)\n KVM_X86_OP_OPTIONAL(guest_memory_reclaimed)\n+KVM_X86_OP_OPTIONAL(reload_vmsa)\n KVM_X86_OP(get_feature_msr)\n KVM_X86_OP(check_emulate_instruction)\n KVM_X86_OP(apic_init_signal_blocked)\n@@ -145,9 +146,14 @@ KVM_X86_OP(vcpu_deliver_sipi_vector)\n KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);\n KVM_X86_OP_OPTIONAL(get_untagged_addr)\n KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE\n KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)\n+#endif\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n+KVM_X86_OP_OPTIONAL(gmem_invalidate_range)\n+KVM_X86_OP_OPTIONAL(gmem_free_folio)\n+#endif\n KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)\n-KVM_X86_OP_OPTIONAL(gmem_invalidate)\n #endif\n \n #undef KVM_X86_OP\ndiff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h\nindex b517257a631532..ee47a0d1feb990 100644\n--- a/arch/x86/include/asm/kvm_host.h\n+++ b/arch/x86/include/asm/kvm_host.h\n@@ -122,6 +122,8 @@\n \tKVM_ARCH_REQ_FLAGS(31, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)\n #define KVM_REQ_HV_TLB_FLUSH \\\n \tKVM_ARCH_REQ_FLAGS(32, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)\n+#define KVM_REQ_VMSA_PAGE_RELOAD \\\n+\tKVM_ARCH_REQ_FLAGS(33, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)\n #define KVM_REQ_UPDATE_PROTECTED_GUEST_STATE \\\n \tKVM_ARCH_REQ_FLAGS(34, KVM_REQUEST_WAIT)\n \n@@ -1878,6 +1880,7 @@ struct kvm_x86_ops {\n \tint (*vm_copy_enc_context_from)(struct kvm *kvm, unsigned int source_fd);\n \tint (*vm_move_enc_context_from)(struct kvm *kvm, unsigned int source_fd);\n \tvoid (*guest_memory_reclaimed)(struct kvm *kvm);\n+\tvoid (*reload_vmsa)(struct kvm_vcpu *vcpu);\n \n \tint (*get_feature_msr)(u32 msr, u64 *data);\n \n@@ -1900,8 +1903,13 @@ struct kvm_x86_ops {\n \n \tgva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);\n \tvoid *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu);\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE\n \tint (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);\n-\tvoid (*gmem_invalidate)(kvm_pfn_t start, kvm_pfn_t end);\n+#endif\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n+\tvoid (*gmem_invalidate_range)(struct kvm *kvm, struct kvm_gfn_range *range);\n+\tvoid (*gmem_free_folio)(struct folio *folio);\n+#endif\n \tint (*gmem_max_mapping_level)(struct kvm *kvm, kvm_pfn_t pfn, bool is_private);\n };\n \ndiff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c\nindex 6c13da942bfccc..8d36ca0a380b5a 100644\n--- a/arch/x86/kvm/mmu/mmu.c\n+++ b/arch/x86/kvm/mmu/mmu.c\n@@ -6921,20 +6921,11 @@ static void kvm_zap_obsolete_pages(struct kvm *kvm)\n \tkvm_mmu_commit_zap_page(kvm, \u0026invalid_list);\n }\n \n-/*\n- * Fast invalidate all shadow pages and use lock-break technique\n- * to zap obsolete pages.\n- *\n- * It's required when memslot is being deleted or VM is being\n- * destroyed, in these cases, we should ensure that KVM MMU does\n- * not use any resource of the being-deleted slot or all slots\n- * after calling the function.\n- */\n-static void kvm_mmu_zap_all_fast(struct kvm *kvm)\n+static void __kvm_mmu_zap_all_fast_front_half(struct kvm *kvm)\n {\n \tlockdep_assert_held(\u0026kvm-\u003eslots_lock);\n+\tlockdep_assert_held_write(\u0026kvm-\u003emmu_lock);\n \n-\twrite_lock(\u0026kvm-\u003emmu_lock);\n \ttrace_kvm_mmu_zap_all_fast(kvm);\n \n \t/*\n@@ -6971,8 +6962,12 @@ static void kvm_mmu_zap_all_fast(struct kvm *kvm)\n \tkvm_make_all_cpus_request(kvm, KVM_REQ_MMU_FREE_OBSOLETE_ROOTS);\n \n \tkvm_zap_obsolete_pages(kvm);\n+}\n \n-\twrite_unlock(\u0026kvm-\u003emmu_lock);\n+static void __kvm_mmu_zap_all_fast_back_half(struct kvm *kvm)\n+{\n+\tlockdep_assert_held(\u0026kvm-\u003eslots_lock);\n+\tlockdep_assert_not_held(\u0026kvm-\u003emmu_lock);\n \n \t/*\n \t * Zap the invalidated TDP MMU roots, all SPTEs must be dropped before\n@@ -6986,6 +6981,24 @@ static void kvm_mmu_zap_all_fast(struct kvm *kvm)\n \t\tkvm_tdp_mmu_zap_invalidated_roots(kvm, true);\n }\n \n+/*\n+ * Fast invalidate all shadow pages and use lock-break technique\n+ * to zap obsolete pages.\n+ *\n+ * It's required when memslot is being deleted or VM is being\n+ * destroyed, in these cases, we should ensure that KVM MMU does\n+ * not use any resource of the being-deleted slot or all slots\n+ * after calling the function.\n+ */\n+static void kvm_mmu_zap_all_fast(struct kvm *kvm)\n+{\n+\twrite_lock(\u0026kvm-\u003emmu_lock);\n+\t__kvm_mmu_zap_all_fast_front_half(kvm);\n+\twrite_unlock(\u0026kvm-\u003emmu_lock);\n+\n+\t__kvm_mmu_zap_all_fast_back_half(kvm);\n+}\n+\n int kvm_mmu_init_vm(struct kvm *kvm)\n {\n \tint r, i;\n@@ -7560,8 +7573,14 @@ static void kvm_mmu_zap_memslot_pages_and_flush(struct kvm *kvm,\n \tkvm_mmu_remote_flush_or_zap(kvm, \u0026invalid_list, flush);\n }\n \n-static void kvm_mmu_zap_memslot(struct kvm *kvm,\n-\t\t\t\tstruct kvm_memory_slot *slot)\n+static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)\n+{\n+\treturn kvm-\u003earch.vm_type == KVM_X86_DEFAULT_VM \u0026\u0026\n+\t kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);\n+}\n+\n+void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\n+\t\t\t\t struct kvm_memory_slot *slot)\n {\n \tstruct kvm_gfn_range range = {\n \t\t.slot = slot,\n@@ -7573,24 +7592,23 @@ static void kvm_mmu_zap_memslot(struct kvm *kvm,\n \tbool flush;\n \n \twrite_lock(\u0026kvm-\u003emmu_lock);\n-\tflush = kvm_unmap_gfn_range(kvm, \u0026range);\n-\tkvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);\n-\twrite_unlock(\u0026kvm-\u003emmu_lock);\n-}\n \n-static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)\n-{\n-\treturn kvm-\u003earch.vm_type == KVM_X86_DEFAULT_VM \u0026\u0026\n-\t kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);\n-}\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n+\tif (slot-\u003egmem.file)\n+\t\tkvm_arch_gmem_invalidate_range(kvm, \u0026range);\n+#endif\n+\n+\tif (kvm_memslot_flush_zap_all(kvm)) {\n+\t\t__kvm_mmu_zap_all_fast_front_half(kvm);\n+\t} else {\n+\t\tflush = kvm_unmap_gfn_range(kvm, \u0026range);\n+\t\tkvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);\n+\t}\n+\n+\twrite_unlock(\u0026kvm-\u003emmu_lock);\n \n-void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\n-\t\t\t\t struct kvm_memory_slot *slot)\n-{\n \tif (kvm_memslot_flush_zap_all(kvm))\n-\t\tkvm_mmu_zap_all_fast(kvm);\n-\telse\n-\t\tkvm_mmu_zap_memslot(kvm, slot);\n+\t\t__kvm_mmu_zap_all_fast_back_half(kvm);\n }\n \n void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)\ndiff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c\nindex 74fb15551e83fa..7e06ed16f47461 100644\n--- a/arch/x86/kvm/svm/sev.c\n+++ b/arch/x86/kvm/svm/sev.c\n@@ -3979,30 +3979,21 @@ static int snp_begin_psc(struct vcpu_svm *svm)\n \treturn snp_do_psc(svm);\n }\n \n-/*\n- * Invoked as part of svm_vcpu_reset() processing of an init event.\n- */\n-static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n+static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)\n {\n \tstruct vcpu_svm *svm = to_svm(vcpu);\n \tstruct kvm_memory_slot *slot;\n+\tstruct kvm *kvm = vcpu-\u003ekvm;\n+\tgfn_t gfn = gpa_to_gfn(gpa);\n+\tunsigned long mmu_seq;\n \tstruct page *page;\n \tkvm_pfn_t pfn;\n-\tgfn_t gfn;\n-\n-\tguard(mutex)(\u0026svm-\u003esev_es.snp_vmsa_mutex);\n-\n-\tif (!svm-\u003esev_es.snp_ap_waiting_for_reset)\n-\t\treturn;\n-\n-\tsvm-\u003esev_es.snp_ap_waiting_for_reset = false;\n \n-\t/* Mark the vCPU as offline and not runnable */\n-\tvcpu-\u003earch.pv.pv_unhalted = false;\n-\tkvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED);\n+\tlockdep_assert_held(\u0026svm-\u003esev_es.snp_vmsa_mutex);\n \n-\t/* Clear use of the VMSA */\n+\t/* Clear use of the VMSA. */\n \tsvm-\u003evmcb-\u003econtrol.vmsa_pa = INVALID_PAGE;\n+\tsvm-\u003esev_es.snp_guest_vmsa_gpa = INVALID_PAGE;\n \n \t/*\n \t * When replacing the VMSA during SEV-SNP AP creation,\n@@ -4010,16 +4001,27 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n \t */\n \tvmcb_mark_all_dirty(svm-\u003evmcb);\n \n-\tif (!VALID_PAGE(svm-\u003esev_es.snp_vmsa_gpa))\n-\t\treturn;\n+\t/*\n+\t * From this point forward, the VMSA will always be a guest-mapped page\n+\t * rather than the initial one allocated by KVM in svm-\u003esev_es.vmsa. In\n+\t * theory, svm-\u003esev_es.vmsa could be free'd and cleaned up here, but\n+\t * that involves cleanups like flushing caches, which would ideally be\n+\t * handled during teardown rather than guest boot. Deferring that also\n+\t * allows the existing logic for SEV-ES VMSAs to be re-used with\n+\t * minimal SNP-specific changes.\n+\t */\n+\tsvm-\u003esev_es.snp_has_guest_vmsa = true;\n \n-\tgfn = gpa_to_gfn(svm-\u003esev_es.snp_vmsa_gpa);\n-\tsvm-\u003esev_es.snp_vmsa_gpa = INVALID_PAGE;\n+\tif (!VALID_PAGE(gpa))\n+\t\treturn;\n \n \tslot = gfn_to_memslot(vcpu-\u003ekvm, gfn);\n \tif (!slot)\n \t\treturn;\n \n+\tmmu_seq = kvm-\u003emmu_invalidate_seq;\n+\tsmp_rmb();\n+\n \t/*\n \t * The new VMSA will be private memory guest memory, so retrieve the\n \t * PFN from the gmem backend.\n@@ -4027,29 +4029,64 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n \tif (kvm_gmem_get_pfn(vcpu-\u003ekvm, slot, gfn, \u0026pfn, \u0026page, NULL))\n \t\treturn;\n \n+\tread_lock(\u0026kvm-\u003emmu_lock);\n \t/*\n-\t * From this point forward, the VMSA will always be a guest-mapped page\n-\t * rather than the initial one allocated by KVM in svm-\u003esev_es.vmsa. In\n-\t * theory, svm-\u003esev_es.vmsa could be free'd and cleaned up here, but\n-\t * that involves cleanups like flushing caches, which would ideally be\n-\t * handled during teardown rather than guest boot. Deferring that also\n-\t * allows the existing logic for SEV-ES VMSAs to be re-used with\n-\t * minimal SNP-specific changes.\n+\t * Save the guest-provided GPA. If retry is needed, then KVM will try\n+\t * again with the same GPA. If the VMSA is usable, then KVM needs to\n+\t * track the GPA so that the VMSA can be reloaded if the backing page\n+\t * for the GPA is invalidated.\n \t */\n-\tsvm-\u003esev_es.snp_has_guest_vmsa = true;\n+\tsvm-\u003esev_es.snp_guest_vmsa_gpa = gpa;\n+\tif (mmu_invalidate_retry_gfn(kvm, mmu_seq, gfn))\n+\t\tkvm_make_request(KVM_REQ_VMSA_PAGE_RELOAD, vcpu);\n+\telse\n+\t\tsvm-\u003evmcb-\u003econtrol.vmsa_pa = pfn_to_hpa(pfn);\n+\tread_unlock(\u0026kvm-\u003emmu_lock);\n+\n+\tkvm_release_page_clean(page);\n+}\n+\n+/*\n+ * Invoked as part of svm_vcpu_reset() processing of an init event.\n+ */\n+static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n+{\n+\tstruct vcpu_svm *svm = to_svm(vcpu);\n+\tgpa_t gpa;\n+\n+\tguard(mutex)(\u0026svm-\u003esev_es.snp_vmsa_mutex);\n+\n+\tif (!svm-\u003esev_es.snp_ap_waiting_for_reset)\n+\t\treturn;\n+\n+\tsvm-\u003esev_es.snp_ap_waiting_for_reset = false;\n+\n+\t/* Mark the vCPU as offline and not runnable */\n+\tvcpu-\u003earch.pv.pv_unhalted = false;\n+\tkvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED);\n \n-\t/* Use the new VMSA */\n-\tsvm-\u003evmcb-\u003econtrol.vmsa_pa = pfn_to_hpa(pfn);\n+\tgpa = svm-\u003esev_es.snp_pending_vmsa_gpa;\n+\tsvm-\u003esev_es.snp_pending_vmsa_gpa = INVALID_PAGE;\n \n-\t/* Mark the vCPU as runnable */\n-\tkvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);\n+\t__sev_snp_reload_vmsa(vcpu, gpa);\n \n \t/*\n-\t * gmem pages aren't currently migratable, but if this ever changes\n-\t * then care should be taken to ensure svm-\u003esev_es.vmsa is pinned\n-\t * through some other means.\n+\t * Mark the vCPU as runnable for CREATE requests, indicated by a valid\n+\t * VMSA GPA, even if installing the VMSA failed, so that KVM_RUN will\n+\t * fail instead of blocking indefinitely and hanging the vCPU, e.g. if\n+\t * the backing guest_memfd page is unavailable.\n \t */\n-\tkvm_release_page_clean(page);\n+\tif (VALID_PAGE(gpa))\n+\t\tkvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);\n+}\n+\n+void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu)\n+{\n+\tstruct vcpu_sev_es_state *sev_es = \u0026to_svm(vcpu)-\u003esev_es;\n+\n+\tguard(mutex)(\u0026sev_es-\u003esnp_vmsa_mutex);\n+\n+\t__sev_snp_reload_vmsa(vcpu, sev_es-\u003esnp_guest_vmsa_gpa);\n }\n \n static int sev_snp_ap_creation(struct vcpu_svm *svm)\n@@ -4105,10 +4142,10 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)\n \t\t\treturn -EINVAL;\n \t\t}\n \n-\t\ttarget_svm-\u003esev_es.snp_vmsa_gpa = svm-\u003evmcb-\u003econtrol.exit_info_2;\n+\t\ttarget_svm-\u003esev_es.snp_pending_vmsa_gpa = svm-\u003evmcb-\u003econtrol.exit_info_2;\n \t\tbreak;\n \tcase SVM_VMGEXIT_AP_DESTROY:\n-\t\ttarget_svm-\u003esev_es.snp_vmsa_gpa = INVALID_PAGE;\n+\t\ttarget_svm-\u003esev_es.snp_pending_vmsa_gpa = INVALID_PAGE;\n \t\tbreak;\n \tdefault:\n \t\tvcpu_unimpl(vcpu, \"vmgexit: invalid AP creation request [%#x] from guest\\n\",\n@@ -4791,6 +4828,8 @@ int sev_vcpu_create(struct kvm_vcpu *vcpu)\n \t\treturn -ENOMEM;\n \n \tsvm-\u003esev_es.vmsa = page_address(vmsa_page);\n+\tsvm-\u003esev_es.snp_pending_vmsa_gpa = INVALID_PAGE;\n+\tsvm-\u003esev_es.snp_guest_vmsa_gpa = INVALID_PAGE;\n \n \tvcpu-\u003earch.guest_tsc_protected = snp_is_secure_tsc_enabled(vcpu-\u003ekvm);\n \n@@ -5115,9 +5154,36 @@ int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order)\n \n \treturn 0;\n }\n+void sev_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range)\n+{\n+\tstruct kvm_vcpu *vcpu;\n+\tunsigned long i;\n+\n+\tlockdep_assert_held_write(\u0026kvm-\u003emmu_lock);\n+\n+\t/*\n+\t * An unstable result for \"is SNP\" is a-ok here, thanks to mmu_lock.\n+\t * The vCPU's VMSA GPA is invalidated before the vCPU is made visible\n+\t * to other tasks, and can only become valid while holding mmu_lock,\n+\t * after the VM is fully committed to being an SNP VM.\n+\t */\n+\tif (!____sev_snp_guest(kvm))\n+\t\treturn;\n+\n+\tkvm_for_each_vcpu(i, vcpu, kvm) {\n+\t\tgpa_t gpa = to_svm(vcpu)-\u003esev_es.snp_guest_vmsa_gpa;\n+\n+\t\tif (VALID_PAGE(gpa) \u0026\u0026\n+\t\t gpa_to_gfn(gpa) \u003e= range-\u003estart \u0026\u0026\n+\t\t gpa_to_gfn(gpa) \u003c range-\u003eend)\n+\t\t\tkvm_make_request_and_kick(KVM_REQ_VMSA_PAGE_RELOAD, vcpu);\n+\t}\n+}\n \n-void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end)\n+void sev_gmem_free_folio(struct folio *folio)\n {\n+\tkvm_pfn_t start = page_to_pfn(folio_page(folio, 0));\n+\tkvm_pfn_t end = start + (1ul \u003c\u003c folio_order(folio));\n \tkvm_pfn_t pfn;\n \n \tif (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))\ndiff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c\nindex ef69a51ab27f98..7d3dd371907045 100644\n--- a/arch/x86/kvm/svm/svm.c\n+++ b/arch/x86/kvm/svm/svm.c\n@@ -5445,6 +5445,7 @@ struct kvm_x86_ops svm_x86_ops __initdata = {\n \t.mem_enc_register_region = sev_mem_enc_register_region,\n \t.mem_enc_unregister_region = sev_mem_enc_unregister_region,\n \t.guest_memory_reclaimed = sev_guest_memory_reclaimed,\n+\t.reload_vmsa = sev_snp_reload_vmsa,\n \n \t.vm_copy_enc_context_from = sev_vm_copy_enc_context_from,\n \t.vm_move_enc_context_from = sev_vm_move_enc_context_from,\n@@ -5460,9 +5461,12 @@ struct kvm_x86_ops svm_x86_ops __initdata = {\n \t.vcpu_get_apicv_inhibit_reasons = avic_vcpu_get_apicv_inhibit_reasons,\n \t.alloc_apic_backing_page = svm_alloc_apic_backing_page,\n \n+#ifdef CONFIG_KVM_AMD_SEV\n \t.gmem_prepare = sev_gmem_prepare,\n-\t.gmem_invalidate = sev_gmem_invalidate,\n+\t.gmem_invalidate_range = sev_gmem_invalidate_range,\n+\t.gmem_free_folio = sev_gmem_free_folio,\n \t.gmem_max_mapping_level = sev_gmem_max_mapping_level,\n+#endif\n };\n \n /*\ndiff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h\nindex 716be21fba3354..c7ecc5fca689b0 100644\n--- a/arch/x86/kvm/svm/svm.h\n+++ b/arch/x86/kvm/svm/svm.h\n@@ -271,7 +271,8 @@ struct vcpu_sev_es_state {\n \tu64 ghcb_registered_gpa;\n \n \tstruct mutex snp_vmsa_mutex; /* Used to handle concurrent updates of VMSA. */\n-\tgpa_t snp_vmsa_gpa;\n+\tgpa_t snp_pending_vmsa_gpa;\n+\tgpa_t snp_guest_vmsa_gpa;\n \tbool snp_ap_waiting_for_reset;\n \tbool snp_has_guest_vmsa;\n };\n@@ -995,6 +996,7 @@ static inline struct page *snp_safe_alloc_page(void)\n {\n \treturn snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);\n }\n+void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu);\n \n int sev_vcpu_create(struct kvm_vcpu *vcpu);\n void sev_free_vcpu(struct kvm_vcpu *vcpu);\n@@ -1008,7 +1010,8 @@ int sev_dev_get_attr(u32 group, u64 attr, u64 *val);\n extern unsigned int max_sev_asid;\n void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code);\n int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);\n-void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);\n+void sev_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);\n+void sev_gmem_free_folio(struct folio *folio);\n int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_private);\n struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcpu);\n void sev_free_decrypted_vmsa(struct kvm_vcpu *vcpu, struct vmcb_save_area *vmsa);\n@@ -1038,7 +1041,6 @@ static inline int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, in\n {\n \treturn 0;\n }\n-static inline void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end) {}\n static inline int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_private)\n {\n \treturn 0;\ndiff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c\nindex 0626e835e9eb77..9df6acf9a982e6 100644\n--- a/arch/x86/kvm/x86.c\n+++ b/arch/x86/kvm/x86.c\n@@ -8167,6 +8167,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)\n \t\t\t\tgoto out;\n \t\t\t}\n \t\t}\n+\t\tif (kvm_check_request(KVM_REQ_VMSA_PAGE_RELOAD, vcpu))\n+\t\t\tkvm_x86_call(reload_vmsa)(vcpu);\n \t}\n \n \tif (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win ||\n@@ -10592,9 +10594,13 @@ int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_ord\n #endif\n \n #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n-void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end)\n+void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range)\n {\n-\tkvm_x86_call(gmem_invalidate)(start, end);\n+\tkvm_x86_call(gmem_invalidate_range)(kvm, range);\n+}\n+void kvm_arch_gmem_free_folio(struct folio *folio)\n+{\n+\tkvm_x86_call(gmem_free_folio)(folio);\n }\n #endif\n #endif\ndiff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h\nindex ab8cfaec82d31e..6b7f8801505d5c 100644\n--- a/include/linux/kvm_host.h\n+++ b/include/linux/kvm_host.h\n@@ -2607,7 +2607,8 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src,\n #endif\n \n #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n-void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);\n+void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);\n+void kvm_arch_gmem_free_folio(struct folio *folio);\n #endif\n \n #ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY\ndiff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c\nindex 86690683b2fe3e..8ec5041934dbcf 100644\n--- a/virt/kvm/guest_memfd.c\n+++ b/virt/kvm/guest_memfd.c\n@@ -185,6 +185,10 @@ static void __kvm_gmem_invalidate_start(struct gmem_file *f, pgoff_t start,\n \t\t}\n \n \t\tflush |= kvm_mmu_unmap_gfn_range(kvm, \u0026gfn_range);\n+\n+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n+\t\tkvm_arch_gmem_invalidate_range(kvm, \u0026gfn_range);\n+#endif\n \t}\n \n \tif (flush)\n@@ -523,23 +527,12 @@ static int kvm_gmem_error_folio(struct address_space *mapping, struct folio *fol\n \treturn MF_DELAYED;\n }\n \n-#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n-static void kvm_gmem_free_folio(struct folio *folio)\n-{\n-\tstruct page *page = folio_page(folio, 0);\n-\tkvm_pfn_t pfn = page_to_pfn(page);\n-\tint order = folio_order(folio);\n-\n-\tkvm_arch_gmem_invalidate(pfn, pfn + (1ul \u003c\u003c order));\n-}\n-#endif\n-\n static const struct address_space_operations kvm_gmem_aops = {\n \t.dirty_folio = noop_dirty_folio,\n \t.migrate_folio\t= kvm_gmem_migrate_folio,\n \t.error_remove_folio = kvm_gmem_error_folio,\n #ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\n-\t.free_folio = kvm_gmem_free_folio,\n+\t.free_folio = kvm_arch_gmem_free_folio,\n #endif\n };\n \n"
} |
| 2/1 | 2026/06/27 01:49 | agent | patch-evaluator |
1mModel:gemini-3.1-pro-preview Args: null Results: {
"EnableConfigs": [
"KVM_AMD_SEV"
],
"FocusSymbols": [
"kvm_arch_flush_shadow_memslot",
"__kvm_mmu_zap_all_fast_front_half",
"__kvm_mmu_zap_all_fast_back_half",
"sev_snp_init_protected_guest_state",
"__sev_snp_reload_vmsa",
"sev_snp_reload_vmsa",
"sev_gmem_invalidate_range",
"sev_gmem_free_folio"
],
"Reasoning": "The patch modifies core KVM MMU logic for flushing shadow memslots and introduces new SEV-SNP specific logic for handling guest_memfd invalidations and VMSA reloading. These changes are reachable via KVM ioctls and guest execution.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Do not list too generic configs (we already have them enabled). Only list those that specifically cover the modified code. List them in the EnableConfigs output array, and DO NOT add a '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: For your convenience, here is the diff of the changes:
commit 14debc60cc473296addc95629b20432d1cf25808
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Jun 27 01:49:49 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
index 83dc5086138b39..fd08454c755364 100644
--- a/arch/x86/include/asm/kvm-x86-ops.h
+++ b/arch/x86/include/asm/kvm-x86-ops.h
@@ -134,6 +134,7 @@ KVM_X86_OP_OPTIONAL(mem_enc_unregister_region)
KVM_X86_OP_OPTIONAL(vm_copy_enc_context_from)
KVM_X86_OP_OPTIONAL(vm_move_enc_context_from)
KVM_X86_OP_OPTIONAL(guest_memory_reclaimed)
+KVM_X86_OP_OPTIONAL(reload_vmsa)
KVM_X86_OP(get_feature_msr)
KVM_X86_OP(check_emulate_instruction)
KVM_X86_OP(apic_init_signal_blocked)
@@ -145,9 +146,14 @@ KVM_X86_OP(vcpu_deliver_sipi_vector)
KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);
KVM_X86_OP_OPTIONAL(get_untagged_addr)
KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)
+#endif
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
+KVM_X86_OP_OPTIONAL(gmem_invalidate_range)
+KVM_X86_OP_OPTIONAL(gmem_free_folio)
+#endif
KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)
-KVM_X86_OP_OPTIONAL(gmem_invalidate)
#endif
#undef KVM_X86_OP
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index b517257a631532..ee47a0d1feb990 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -122,6 +122,8 @@
KVM_ARCH_REQ_FLAGS(31, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
#define KVM_REQ_HV_TLB_FLUSH \
KVM_ARCH_REQ_FLAGS(32, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
+#define KVM_REQ_VMSA_PAGE_RELOAD \
+ KVM_ARCH_REQ_FLAGS(33, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
#define KVM_REQ_UPDATE_PROTECTED_GUEST_STATE \
KVM_ARCH_REQ_FLAGS(34, KVM_REQUEST_WAIT)
@@ -1878,6 +1880,7 @@ struct kvm_x86_ops {
int (*vm_copy_enc_context_from)(struct kvm *kvm, unsigned int source_fd);
int (*vm_move_enc_context_from)(struct kvm *kvm, unsigned int source_fd);
void (*guest_memory_reclaimed)(struct kvm *kvm);
+ void (*reload_vmsa)(struct kvm_vcpu *vcpu);
int (*get_feature_msr)(u32 msr, u64 *data);
@@ -1900,8 +1903,13 @@ struct kvm_x86_ops {
gva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);
void *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu);
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_PREPARE
int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
- void (*gmem_invalidate)(kvm_pfn_t start, kvm_pfn_t end);
+#endif
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
+ void (*gmem_invalidate_range)(struct kvm *kvm, struct kvm_gfn_range *range);
+ void (*gmem_free_folio)(struct folio *folio);
+#endif
int (*gmem_max_mapping_level)(struct kvm *kvm, kvm_pfn_t pfn, bool is_private);
};
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 6c13da942bfccc..8d36ca0a380b5a 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -6921,20 +6921,11 @@ static void kvm_zap_obsolete_pages(struct kvm *kvm)
kvm_mmu_commit_zap_page(kvm, &invalid_list);
}
-/*
- * Fast invalidate all shadow pages and use lock-break technique
- * to zap obsolete pages.
- *
- * It's required when memslot is being deleted or VM is being
- * destroyed, in these cases, we should ensure that KVM MMU does
- * not use any resource of the being-deleted slot or all slots
- * after calling the function.
- */
-static void kvm_mmu_zap_all_fast(struct kvm *kvm)
+static void __kvm_mmu_zap_all_fast_front_half(struct kvm *kvm)
{
lockdep_assert_held(&kvm->slots_lock);
+ lockdep_assert_held_write(&kvm->mmu_lock);
- write_lock(&kvm->mmu_lock);
trace_kvm_mmu_zap_all_fast(kvm);
/*
@@ -6971,8 +6962,12 @@ static void kvm_mmu_zap_all_fast(struct kvm *kvm)
kvm_make_all_cpus_request(kvm, KVM_REQ_MMU_FREE_OBSOLETE_ROOTS);
kvm_zap_obsolete_pages(kvm);
+}
- write_unlock(&kvm->mmu_lock);
+static void __kvm_mmu_zap_all_fast_back_half(struct kvm *kvm)
+{
+ lockdep_assert_held(&kvm->slots_lock);
+ lockdep_assert_not_held(&kvm->mmu_lock);
/*
* Zap the invalidated TDP MMU roots, all SPTEs must be dropped before
@@ -6986,6 +6981,24 @@ static void kvm_mmu_zap_all_fast(struct kvm *kvm)
kvm_tdp_mmu_zap_invalidated_roots(kvm, true);
}
+/*
+ * Fast invalidate all shadow pages and use lock-break technique
+ * to zap obsolete pages.
+ *
+ * It's required when memslot is being deleted or VM is being
+ * destroyed, in these cases, we should ensure that KVM MMU does
+ * not use any resource of the being-deleted slot or all slots
+ * after calling the function.
+ */
+static void kvm_mmu_zap_all_fast(struct kvm *kvm)
+{
+ write_lock(&kvm->mmu_lock);
+ __kvm_mmu_zap_all_fast_front_half(kvm);
+ write_unlock(&kvm->mmu_lock);
+
+ __kvm_mmu_zap_all_fast_back_half(kvm);
+}
+
int kvm_mmu_init_vm(struct kvm *kvm)
{
int r, i;
@@ -7560,8 +7573,14 @@ static void kvm_mmu_zap_memslot_pages_and_flush(struct kvm *kvm,
kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
}
-static void kvm_mmu_zap_memslot(struct kvm *kvm,
- struct kvm_memory_slot *slot)
+static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)
+{
+ return kvm->arch.vm_type == KVM_X86_DEFAULT_VM &&
+ kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);
+}
+
+void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
+ struct kvm_memory_slot *slot)
{
struct kvm_gfn_range range = {
.slot = slot,
@@ -7573,24 +7592,23 @@ static void kvm_mmu_zap_memslot(struct kvm *kvm,
bool flush;
write_lock(&kvm->mmu_lock);
- flush = kvm_unmap_gfn_range(kvm, &range);
- kvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);
- write_unlock(&kvm->mmu_lock);
-}
-static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)
-{
- return kvm->arch.vm_type == KVM_X86_DEFAULT_VM &&
- kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);
-}
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
+ if (slot->gmem.file)
+ kvm_arch_gmem_invalidate_range(kvm, &range);
+#endif
+
+ if (kvm_memslot_flush_zap_all(kvm)) {
+ __kvm_mmu_zap_all_fast_front_half(kvm);
+ } else {
+ flush = kvm_unmap_gfn_range(kvm, &range);
+ kvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);
+ }
+
+ write_unlock(&kvm->mmu_lock);
-void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
- struct kvm_memory_slot *slot)
-{
if (kvm_memslot_flush_zap_all(kvm))
- kvm_mmu_zap_all_fast(kvm);
- else
- kvm_mmu_zap_memslot(kvm, slot);
+ __kvm_mmu_zap_all_fast_back_half(kvm);
}
void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 74fb15551e83fa..7e06ed16f47461 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3979,30 +3979,21 @@ static int snp_begin_psc(struct vcpu_svm *svm)
return snp_do_psc(svm);
}
-/*
- * Invoked as part of svm_vcpu_reset() processing of an init event.
- */
-static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
+static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
{
struct vcpu_svm *svm = to_svm(vcpu);
struct kvm_memory_slot *slot;
+ struct kvm *kvm = vcpu->kvm;
+ gfn_t gfn = gpa_to_gfn(gpa);
+ unsigned long mmu_seq;
struct page *page;
kvm_pfn_t pfn;
- gfn_t gfn;
-
- guard(mutex)(&svm->sev_es.snp_vmsa_mutex);
-
- if (!svm->sev_es.snp_ap_waiting_for_reset)
- return;
-
- svm->sev_es.snp_ap_waiting_for_reset = false;
- /* Mark the vCPU as offline and not runnable */
- vcpu->arch.pv.pv_unhalted = false;
- kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED);
+ lockdep_assert_held(&svm->sev_es.snp_vmsa_mutex);
- /* Clear use of the VMSA */
+ /* Clear use of the VMSA. */
svm->vmcb->control.vmsa_pa = INVALID_PAGE;
+ svm->sev_es.snp_guest_vmsa_gpa = INVALID_PAGE;
/*
* When replacing the VMSA during SEV-SNP AP creation,
@@ -4010,16 +4001,27 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
*/
vmcb_mark_all_dirty(svm->vmcb);
- if (!VALID_PAGE(svm->sev_es.snp_vmsa_gpa))
- return;
+ /*
+ * From this point forward, the VMSA will always be a guest-mapped page
+ * rather than the initial one allocated by KVM in svm->sev_es.vmsa. In
+ * theory, svm->sev_es.vmsa could be free'd and cleaned up here, but
+ * that involves cleanups like flushing caches, which would ideally be
+ * handled during teardown rather than guest boot. Deferring that also
+ * allows the existing logic for SEV-ES VMSAs to be re-used with
+ * minimal SNP-specific changes.
+ */
+ svm->sev_es.snp_has_guest_vmsa = true;
- gfn = gpa_to_gfn(svm->sev_es.snp_vmsa_gpa);
- svm->sev_es.snp_vmsa_gpa = INVALID_PAGE;
+ if (!VALID_PAGE(gpa))
+ return;
slot = gfn_to_memslot(vcpu->kvm, gfn);
if (!slot)
return;
+ mmu_seq = kvm->mmu_invalidate_seq;
+ smp_rmb();
+
/*
* The new VMSA will be private memory guest memory, so retrieve the
* PFN from the gmem backend.
@@ -4027,29 +4029,64 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
if (kvm_gmem_get_pfn(vcpu->kvm, slot, gfn, &pfn, &page, NULL))
return;
+ read_lock(&kvm->mmu_lock);
/*
- * From this point forward, the VMSA will always be a guest-mapped page
- * rather than the initial one allocated by KVM in svm->sev_es.vmsa. In
- * theory, svm->sev_es.vmsa could be free'd and cleaned up here, but
- * that involves cleanups like flushing caches, which would ideally be
- * handled during teardown rather than guest boot. Deferring that also
- * allows the existing logic for SEV-ES VMSAs to be re-used with
- * minimal SNP-specific changes.
+ * Save the guest-provided GPA. If retry is needed, then KVM will try
+ * again with the same GPA. If the VMSA is usable, then KVM needs to
+ * track the GPA so that the VMSA can be reloaded if the backing page
+ * for the GPA is invalidated.
*/
- svm->sev_es.snp_has_guest_vmsa = true;
+ svm->sev_es.snp_guest_vmsa_gpa = gpa;
+ if (mmu_invalidate_retry_gfn(kvm, mmu_seq, gfn))
+ kvm_make_request(KVM_REQ_VMSA_PAGE_RELOAD, vcpu);
+ else
+ svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn);
+ read_unlock(&kvm->mmu_lock);
+
+ kvm_release_page_clean(page);
+}
+
+/*
+ * Invoked as part of svm_vcpu_reset() processing of an init event.
+ */
+static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+ gpa_t gpa;
+
+ guard(mutex)(&svm->sev_es.snp_vmsa_mutex);
+
+ if (!svm->sev_es.snp_ap_waiting_for_reset)
+ return;
+
+ svm->sev_es.snp_ap_waiting_for_reset = false;
+
+ /* Mark the vCPU as offline and not runnable */
+ vcpu->arch.pv.pv_unhalted = false;
+ kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED);
- /* Use the new VMSA */
- svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn);
+ gpa = svm->sev_es.snp_pending_vmsa_gpa;
+ svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE;
- /* Mark the vCPU as runnable */
- kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);
+ __sev_snp_reload_vmsa(vcpu, gpa);
/*
- * gmem pages aren't currently migratable, but if this ever changes
- * then care should be taken to ensure svm->sev_es.vmsa is pinned
- * through some other means.
+ * Mark the vCPU as runnable for CREATE requests, indicated by a valid
+ * VMSA GPA, even if installing the VMSA failed, so that KVM_RUN will
+ * fail instead of blocking indefinitely and hanging the vCPU, e.g. if
+ * the backing guest_memfd page is unavailable.
*/
- kvm_release_page_clean(page);
+ if (VALID_PAGE(gpa))
+ kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);
+}
+
+void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_sev_es_state *sev_es = &to_svm(vcpu)->sev_es;
+
+ guard(mutex)(&sev_es->snp_vmsa_mutex);
+
+ __sev_snp_reload_vmsa(vcpu, sev_es->snp_guest_vmsa_gpa);
}
static int sev_snp_ap_creation(struct vcpu_svm *svm)
@@ -4105,10 +4142,10 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
return -EINVAL;
}
- target_svm->sev_es.snp_vmsa_gpa = svm->vmcb->control.exit_info_2;
+ target_svm->sev_es.snp_pending_vmsa_gpa = svm->vmcb->control.exit_info_2;
break;
case SVM_VMGEXIT_AP_DESTROY:
- target_svm->sev_es.snp_vmsa_gpa = INVALID_PAGE;
+ target_svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE;
break;
default:
vcpu_unimpl(vcpu, "vmgexit: invalid AP creation request [%#x] from guest\n",
@@ -4791,6 +4828,8 @@ int sev_vcpu_create(struct kvm_vcpu *vcpu)
return -ENOMEM;
svm->sev_es.vmsa = page_address(vmsa_page);
+ svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE;
+ svm->sev_es.snp_guest_vmsa_gpa = INVALID_PAGE;
vcpu->arch.guest_tsc_protected = snp_is_secure_tsc_enabled(vcpu->kvm);
@@ -5115,9 +5154,36 @@ int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order)
return 0;
}
+void sev_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range)
+{
+ struct kvm_vcpu *vcpu;
+ unsigned long i;
+
+ lockdep_assert_held_write(&kvm->mmu_lock);
+
+ /*
+ * An unstable result for "is SNP" is a-ok here, thanks to mmu_lock.
+ * The vCPU's VMSA GPA is invalidated before the vCPU is made visible
+ * to other tasks, and can only become valid while holding mmu_lock,
+ * after the VM is fully committed to being an SNP VM.
+ */
+ if (!____sev_snp_guest(kvm))
+ return;
+
+ kvm_for_each_vcpu(i, vcpu, kvm) {
+ gpa_t gpa = to_svm(vcpu)->sev_es.snp_guest_vmsa_gpa;
+
+ if (VALID_PAGE(gpa) &&
+ gpa_to_gfn(gpa) >= range->start &&
+ gpa_to_gfn(gpa) < range->end)
+ kvm_make_request_and_kick(KVM_REQ_VMSA_PAGE_RELOAD, vcpu);
+ }
+}
-void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end)
+void sev_gmem_free_folio(struct folio *folio)
{
+ kvm_pfn_t start = page_to_pfn(folio_page(folio, 0));
+ kvm_pfn_t end = start + (1ul << folio_order(folio));
kvm_pfn_t pfn;
if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index ef69a51ab27f98..7d3dd371907045 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -5445,6 +5445,7 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
.mem_enc_register_region = sev_mem_enc_register_region,
.mem_enc_unregister_region = sev_mem_enc_unregister_region,
.guest_memory_reclaimed = sev_guest_memory_reclaimed,
+ .reload_vmsa = sev_snp_reload_vmsa,
.vm_copy_enc_context_from = sev_vm_copy_enc_context_from,
.vm_move_enc_context_from = sev_vm_move_enc_context_from,
@@ -5460,9 +5461,12 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
.vcpu_get_apicv_inhibit_reasons = avic_vcpu_get_apicv_inhibit_reasons,
.alloc_apic_backing_page = svm_alloc_apic_backing_page,
+#ifdef CONFIG_KVM_AMD_SEV
.gmem_prepare = sev_gmem_prepare,
- .gmem_invalidate = sev_gmem_invalidate,
+ .gmem_invalidate_range = sev_gmem_invalidate_range,
+ .gmem_free_folio = sev_gmem_free_folio,
.gmem_max_mapping_level = sev_gmem_max_mapping_level,
+#endif
};
/*
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 716be21fba3354..c7ecc5fca689b0 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -271,7 +271,8 @@ struct vcpu_sev_es_state {
u64 ghcb_registered_gpa;
struct mutex snp_vmsa_mutex; /* Used to handle concurrent updates of VMSA. */
- gpa_t snp_vmsa_gpa;
+ gpa_t snp_pending_vmsa_gpa;
+ gpa_t snp_guest_vmsa_gpa;
bool snp_ap_waiting_for_reset;
bool snp_has_guest_vmsa;
};
@@ -995,6 +996,7 @@ static inline struct page *snp_safe_alloc_page(void)
{
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
}
+void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu);
int sev_vcpu_create(struct kvm_vcpu *vcpu);
void sev_free_vcpu(struct kvm_vcpu *vcpu);
@@ -1008,7 +1010,8 @@ int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
extern unsigned int max_sev_asid;
void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code);
int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
-void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);
+void sev_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);
+void sev_gmem_free_folio(struct folio *folio);
int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_private);
struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcpu);
void sev_free_decrypted_vmsa(struct kvm_vcpu *vcpu, struct vmcb_save_area *vmsa);
@@ -1038,7 +1041,6 @@ static inline int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, in
{
return 0;
}
-static inline void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end) {}
static inline int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_private)
{
return 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0626e835e9eb77..9df6acf9a982e6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8167,6 +8167,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
goto out;
}
}
+ if (kvm_check_request(KVM_REQ_VMSA_PAGE_RELOAD, vcpu))
+ kvm_x86_call(reload_vmsa)(vcpu);
}
if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win ||
@@ -10592,9 +10594,13 @@ int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_ord
#endif
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
-void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end)
+void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range)
{
- kvm_x86_call(gmem_invalidate)(start, end);
+ kvm_x86_call(gmem_invalidate_range)(kvm, range);
+}
+void kvm_arch_gmem_free_folio(struct folio *folio)
+{
+ kvm_x86_call(gmem_free_folio)(folio);
}
#endif
#endif
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ab8cfaec82d31e..6b7f8801505d5c 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2607,7 +2607,8 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src,
#endif
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
-void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);
+void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);
+void kvm_arch_gmem_free_folio(struct folio *folio);
#endif
#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 86690683b2fe3e..8ec5041934dbcf 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -185,6 +185,10 @@ static void __kvm_gmem_invalidate_start(struct gmem_file *f, pgoff_t start,
}
flush |= kvm_mmu_unmap_gfn_range(kvm, &gfn_range);
+
+#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
+ kvm_arch_gmem_invalidate_range(kvm, &gfn_range);
+#endif
}
if (flush)
@@ -523,23 +527,12 @@ static int kvm_gmem_error_folio(struct address_space *mapping, struct folio *fol
return MF_DELAYED;
}
-#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
-static void kvm_gmem_free_folio(struct folio *folio)
-{
- struct page *page = folio_page(folio, 0);
- kvm_pfn_t pfn = page_to_pfn(page);
- int order = folio_order(folio);
-
- kvm_arch_gmem_invalidate(pfn, pfn + (1ul << order));
-}
-#endif
-
static const struct address_space_operations kvm_gmem_aops = {
.dirty_folio = noop_dirty_folio,
.migrate_folio = kvm_gmem_migrate_folio,
.error_remove_folio = kvm_gmem_error_folio,
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
- .free_folio = kvm_gmem_free_folio,
+ .free_folio = kvm_arch_gmem_free_folio,
#endif
};
|
| 3/2 | 2026/06/27 01:49 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 10416 output: 23 thoughts: 546 Thoughts: **Analyzing a KVM Patch for SEV-SNP and guest_memfd** Okay, so I'm looking at this patch for KVM on x86, specifically targeted at SEV-SNP and how it interacts with `guest_memfd`. It's introducing new functionalities: `KVM_REQ_VMSA_PAGE_RELOAD`, `reload_vmsa` within `kvm_x86_ops`. It also refactors parts of the existing memory management logic. We're seeing modifications to `kvm_mmu_zap_all_fast`, splitting it, and changes in how the shadow memory slots are handled via `kvm_arch_flush_shadow_memslot`, which now considers `slot->gmem.file`. There are further tweaks to `sev_snp_init_protected_guest_state` with the addition of `sev_snp_reload_vmsa`, and also changes to memory invalidation routines: specifically refactoring `gmem_invalidate` into `gmem_invalidate_range`, along with the `gmem_free_folio` functions. My initial thought is to assess its reachability and functionality. It's definitely KVM code, and it's specifically for AMD SEV-SNP and guest_memfd, which are related to secure virtual machines. SEV-SNP is a hardware feature, but the underlying KVM code could theoretically be fuzzed, depending on the configurations. Now, a key question arises: can we fuzz SEV-SNP in a virtualized environment? The documentation I'm looking at raises a concern about unreachable code paths in environments like GCE or QEMU, even with hardware emulations. Can SEV-SNP be triggered in QEMU? I know QEMU supports SEV and SEV-ES emulation, but I'm not entirely sure about SEV-SNP. Even if the emulation isn't perfect, the KVM ioctls might be reachable to some extent. Then I see that `cc_platform_has(CC_ATTR_HOST_SEV_SNP)` is used in `sev_gmem_free_folio`. This means we need to consider the specific hardware requirements for SEV-SNP. Yes, SEV-SNP requires specific AMD EPYC processors. So, can we fuzz this in GCE? GCE does offer AMD instances, and some of them *might* support SEV-SNP. This needs verification. Also, I know syzkaller heavily fuzzes KVM, which is a promising sign. I should also double-check the relevant configuration options: specifically, `CONFIG_KVM_AMD_SEV` and `CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE`. Time for a quick grep. |
| 4/2 | 2026/06/27 01:49 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_KVM_AMD_SEV"
}Results: {
"Output": "arch/x86/include/asm/sev.h=645=static inline u64 savic_ghcb_msr_read(u32 reg) { return 0; }\n--\narch/x86/include/asm/sev.h-648-\narch/x86/include/asm/sev.h:649:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/include/asm/sev.h-650-bool snp_probe_rmptable_info(void);\n--\narch/x86/kvm/Makefile=24=kvm-amd-y\t\t+= svm/svm.o svm/vmenter.o svm/pmu.o svm/nested.o svm/avic.o\narch/x86/kvm/Makefile-25-\narch/x86/kvm/Makefile:26:kvm-amd-$(CONFIG_KVM_AMD_SEV)\t+= svm/sev.o\narch/x86/kvm/Makefile-27-kvm-amd-$(CONFIG_KVM_HYPERV)\t+= svm/hyperv.o\n--\narch/x86/kvm/svm/svm.c=3332=static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = {\n--\narch/x86/kvm/svm/svm.c-3404-\t[SVM_EXIT_AVIC_UNACCELERATED_ACCESS]\t= avic_unaccelerated_access_interception,\narch/x86/kvm/svm/svm.c:3405:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-3406-\t[SVM_EXIT_VMGEXIT]\t\t\t= sev_handle_vmgexit,\n--\narch/x86/kvm/svm/svm.c=3620=int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 __exit_code)\n--\narch/x86/kvm/svm/svm.c-3646-\t\treturn npf_interception(vcpu);\narch/x86/kvm/svm/svm.c:3647:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-3648-\telse if (exit_code == SVM_EXIT_VMGEXIT)\n--\narch/x86/kvm/svm/svm.c=4392=static int svm_vcpu_pre_run(struct kvm_vcpu *vcpu)\narch/x86/kvm/svm/svm.c-4393-{\narch/x86/kvm/svm/svm.c:4394:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-4395-\tif (to_kvm_sev_info(vcpu-\u003ekvm)-\u003eneed_init)\n--\narch/x86/kvm/svm/svm.c=4685=static bool svm_has_emulated_msr(struct kvm *kvm, u32 index)\n--\narch/x86/kvm/svm/svm.c-4694-\narch/x86/kvm/svm/svm.c:4695:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-4696-\t\t/*\n--\narch/x86/kvm/svm/svm.c=5325=struct kvm_x86_ops svm_x86_ops __initdata = {\n--\narch/x86/kvm/svm/svm.c-5441-\narch/x86/kvm/svm/svm.c:5442:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-5443-\t.dev_get_attr = sev_dev_get_attr,\n--\narch/x86/kvm/svm/svm.c-5463-\narch/x86/kvm/svm/svm.c:5464:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.c-5465-\t.gmem_prepare = sev_gmem_prepare,\n--\narch/x86/kvm/svm/svm.h=66=enum {\n--\narch/x86/kvm/svm/svm.h-97-\narch/x86/kvm/svm/svm.h:98:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.h-99-struct kvm_sev_info {\n--\narch/x86/kvm/svm/svm.h=126=struct kvm_svm {\n--\narch/x86/kvm/svm/svm.h-134-\narch/x86/kvm/svm/svm.h:135:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.h-136-\tstruct kvm_sev_info sev_info;\n--\narch/x86/kvm/svm/svm.h=389=static __always_inline struct kvm_svm *to_kvm_svm(struct kvm *kvm)\n--\narch/x86/kvm/svm/svm.h-393-\narch/x86/kvm/svm/svm.h:394:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.h-395-static __always_inline struct kvm_sev_info *to_kvm_sev_info(struct kvm *kvm)\n--\narch/x86/kvm/svm/svm.h=979=void sev_es_unmap_ghcb(struct vcpu_svm *svm);\narch/x86/kvm/svm/svm.h-980-\narch/x86/kvm/svm/svm.h:981:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/svm.h-982-int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp);\n--\narch/x86/kvm/svm/vmenter.S=210=SYM_FUNC_END(__svm_vcpu_run)\narch/x86/kvm/svm/vmenter.S-211-\narch/x86/kvm/svm/vmenter.S:212:#ifdef CONFIG_KVM_AMD_SEV\narch/x86/kvm/svm/vmenter.S-213-\n--\narch/x86/kvm/svm/vmenter.S=283=SYM_FUNC_END(__svm_sev_es_vcpu_run)\narch/x86/kvm/svm/vmenter.S:284:#endif /* CONFIG_KVM_AMD_SEV */\n--\narch/x86/virt/svm/Makefile-2-\narch/x86/virt/svm/Makefile:3:obj-$(CONFIG_KVM_AMD_SEV) += sev.o\narch/x86/virt/svm/Makefile-4-obj-$(CONFIG_CPU_SUP_AMD) += cmdline.o\n--\ndrivers/crypto/ccp/sp-dev.c=266=static int __init sp_mod_init(void)\n--\ndrivers/crypto/ccp/sp-dev.c-300-\ndrivers/crypto/ccp/sp-dev.c:301:#if IS_BUILTIN(CONFIG_KVM_AMD) \u0026\u0026 IS_ENABLED(CONFIG_KVM_AMD_SEV)\ndrivers/crypto/ccp/sp-dev.c-302-int __init sev_module_init(void)\n--\ndrivers/iommu/amd/init.c=3372=static __init void iommu_snp_enable(void)\ndrivers/iommu/amd/init.c-3373-{\ndrivers/iommu/amd/init.c:3374:#ifdef CONFIG_KVM_AMD_SEV\ndrivers/iommu/amd/init.c-3375-\tif (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))\n--\ndrivers/iommu/amd/init.c=3413=static void amd_iommu_apply_erratum_snp(void)\ndrivers/iommu/amd/init.c-3414-{\ndrivers/iommu/amd/init.c:3415:#ifdef CONFIG_KVM_AMD_SEV\ndrivers/iommu/amd/init.c-3416-\tif (!amd_iommu_snp_en)\n--\ndrivers/iommu/amd/init.c=4020=int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn, u64 *value)\n--\ndrivers/iommu/amd/init.c-4027-\ndrivers/iommu/amd/init.c:4028:#ifdef CONFIG_KVM_AMD_SEV\ndrivers/iommu/amd/init.c-4029-static int iommu_page_make_shared(void *page)\n--\ninclude/linux/amd-iommu.h=69=struct amd_iommu *get_amd_iommu(unsigned int idx);\ninclude/linux/amd-iommu.h-70-\ninclude/linux/amd-iommu.h:71:#ifdef CONFIG_KVM_AMD_SEV\ninclude/linux/amd-iommu.h-72-int amd_iommu_snp_disable(void);\n--\ninclude/linux/misc_cgroup.h=14=enum misc_res_type {\ninclude/linux/misc_cgroup.h:15:#ifdef CONFIG_KVM_AMD_SEV\ninclude/linux/misc_cgroup.h-16-\t/** @MISC_CG_RES_SEV: AMD SEV ASIDs resource */\n--\nkernel/cgroup/misc.c=20=static const char *const misc_res_name[] = {\nkernel/cgroup/misc.c:21:#ifdef CONFIG_KVM_AMD_SEV\nkernel/cgroup/misc.c-22-\t/* AMD SEV ASIDs resource */\n"
} |
| 5/2 | 2026/06/27 01:49 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 14205 output: 27 thoughts: 127 Thoughts: Okay, let's see what's going on here. **Analyzing This KVM/AMD SEV Patch** Right, so this patch is touching some key KVM/AMD SEV related files: `arch/x86/kvm/svm/sev.c`, the core SVM code, then some of the MMU code in `mmu.c`, and even the `guest_memfd.c` file. Interesting. Seems like they are really getting into the details here. Looks like the developer is also working with `CONFIG_KVM_AMD_SEV`, which is expected, that is the main config option. Hold on a second... they are also using `CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE`. Now, that's a bit less obvious. I should probably check if that is something we can toggle or if it's just a default boolean. I need to understand that dependency better before I go any further. |
| 6/2 | 2026/06/27 01:50 | tool | grepper |
0mArgs:{
"Expression": "HAVE_KVM_ARCH_GMEM_INVALIDATE"
}Results: {
"Output": "arch/x86/include/asm/kvm-x86-ops.h=150=KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)\narch/x86/include/asm/kvm-x86-ops.h-151-#endif\narch/x86/include/asm/kvm-x86-ops.h:152:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\narch/x86/include/asm/kvm-x86-ops.h-153-KVM_X86_OP_OPTIONAL(gmem_invalidate_range)\n--\narch/x86/include/asm/kvm_host.h=1680=struct kvm_x86_ops {\n--\narch/x86/include/asm/kvm_host.h-1908-#endif\narch/x86/include/asm/kvm_host.h:1909:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\narch/x86/include/asm/kvm_host.h-1910-\tvoid (*gmem_invalidate_range)(struct kvm *kvm, struct kvm_gfn_range *range);\n--\narch/x86/kvm/Kconfig=156=config KVM_AMD_SEV\n--\narch/x86/kvm/Kconfig-163-\tselect HAVE_KVM_ARCH_GMEM_PREPARE\narch/x86/kvm/Kconfig:164:\tselect HAVE_KVM_ARCH_GMEM_INVALIDATE\narch/x86/kvm/Kconfig-165-\tselect HAVE_KVM_ARCH_GMEM_POPULATE\n--\narch/x86/kvm/mmu/mmu.c=7582=void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\n--\narch/x86/kvm/mmu/mmu.c-7595-\narch/x86/kvm/mmu/mmu.c:7596:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\narch/x86/kvm/mmu/mmu.c-7597-\tif (slot-\u003egmem.file)\n--\narch/x86/kvm/x86.c=10590=int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order)\n--\narch/x86/kvm/x86.c-10595-\narch/x86/kvm/x86.c:10596:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\narch/x86/kvm/x86.c-10597-void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range)\n--\ninclude/linux/kvm_host.h=2604=long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src,\n--\ninclude/linux/kvm_host.h-2608-\ninclude/linux/kvm_host.h:2609:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\ninclude/linux/kvm_host.h-2610-void kvm_arch_gmem_invalidate_range(struct kvm *kvm, struct kvm_gfn_range *range);\n--\nvirt/kvm/Kconfig=110=config HAVE_KVM_ARCH_GMEM_PREPARE\n--\nvirt/kvm/Kconfig-113-\nvirt/kvm/Kconfig:114:config HAVE_KVM_ARCH_GMEM_INVALIDATE\nvirt/kvm/Kconfig-115- bool\n--\nvirt/kvm/guest_memfd.c=160=static void __kvm_gmem_invalidate_start(struct gmem_file *f, pgoff_t start,\n--\nvirt/kvm/guest_memfd.c-188-\nvirt/kvm/guest_memfd.c:189:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\nvirt/kvm/guest_memfd.c-190-\t\tkvm_arch_gmem_invalidate_range(kvm, \u0026gfn_range);\n--\nvirt/kvm/guest_memfd.c=530=static const struct address_space_operations kvm_gmem_aops = {\n--\nvirt/kvm/guest_memfd.c-533-\t.error_remove_folio = kvm_gmem_error_folio,\nvirt/kvm/guest_memfd.c:534:#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE\nvirt/kvm/guest_memfd.c-535-\t.free_folio = kvm_arch_gmem_free_folio,\n"
} |
| 7/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15849 output: 26 thoughts: 127 Thoughts: **Analyzing the KVM Configuration for AMD SEV Support** Okay, so `HAVE_KVM_ARCH_GMEM_INVALIDATE` is getting pulled in because of `KVM_AMD_SEV`. Right, that makes sense; `KVM_AMD_SEV` is the primary configuration option here. My focus should be on understanding *it* as the core of the support. Hmm, this patch modifies `kvm_mmu_zap_all_fast` in `arch/x86/kvm/mmu/mmu.c`. Interesting. And that function is called by `kvm_arch_flush_shadow_memslot`. Wait a minute... `kvm_arch_flush_shadow_memslot` isn't specific to SEV, is it? That's important. I need to understand the implications of this broader connection. It's not *just* affecting the SEV-specific path. Let me go check what's up with that `kvm_arch_flush_shadow_memslot` function. I need to be sure I understand the scope of the impact of this change. |
| 8/2 | 2026/06/27 01:50 | tool | grepper |
0mArgs:{
"Expression": "kvm_arch_flush_shadow_memslot"
}Results: {
"Output": "arch/arm64/kvm/mmu.c=2704=void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen)\n--\narch/arm64/kvm/mmu.c-2707-\narch/arm64/kvm/mmu.c:2708:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/arm64/kvm/mmu.c-2709-\t\t\t\t struct kvm_memory_slot *slot)\n--\narch/loongarch/kvm/mmu.c=442=void kvm_arch_commit_memory_region(struct kvm *kvm,\n--\narch/loongarch/kvm/mmu.c-466-\t * MOVE/DELETE:\tThe old mappings will already have been cleaned up by\narch/loongarch/kvm/mmu.c:467:\t *\t\tkvm_arch_flush_shadow_memslot()\narch/loongarch/kvm/mmu.c-468-\t */\n--\narch/loongarch/kvm/mmu.c=487=void kvm_arch_flush_shadow_all(struct kvm *kvm)\n--\narch/loongarch/kvm/mmu.c-491-\narch/loongarch/kvm/mmu.c:492:void kvm_arch_flush_shadow_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)\narch/loongarch/kvm/mmu.c-493-{\n--\narch/mips/kvm/mips.c=181=void kvm_arch_flush_shadow_all(struct kvm *kvm)\n--\narch/mips/kvm/mips.c-187-\narch/mips/kvm/mips.c:188:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/mips/kvm/mips.c-189-\t\t\t\t struct kvm_memory_slot *slot)\n--\narch/mips/kvm/mips.c=212=void kvm_arch_commit_memory_region(struct kvm *kvm,\n--\narch/mips/kvm/mips.c-225-\t * MOVE/DELETE:\tThe old mappings will already have been cleaned up by\narch/mips/kvm/mips.c:226:\t *\t\tkvm_arch_flush_shadow_memslot()\narch/mips/kvm/mips.c-227-\t */\n--\narch/powerpc/kvm/book3s_hv.c=5354=static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm,\n--\narch/powerpc/kvm/book3s_hv.c-5369-\t * For change == KVM_MR_MOVE or KVM_MR_DELETE, higher levels\narch/powerpc/kvm/book3s_hv.c:5370:\t * have already called kvm_arch_flush_shadow_memslot() to\narch/powerpc/kvm/book3s_hv.c-5371-\t * flush shadow mappings. For KVM_MR_CREATE we have no\n--\narch/powerpc/kvm/powerpc.c=727=void kvm_arch_commit_memory_region(struct kvm *kvm,\n--\narch/powerpc/kvm/powerpc.c-734-\narch/powerpc/kvm/powerpc.c:735:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/powerpc/kvm/powerpc.c-736-\t\t\t\t struct kvm_memory_slot *slot)\n--\narch/riscv/kvm/mmu.c=131=void kvm_arch_flush_shadow_all(struct kvm *kvm)\n--\narch/riscv/kvm/mmu.c-135-\narch/riscv/kvm/mmu.c:136:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/riscv/kvm/mmu.c-137-\t\t\t\t struct kvm_memory_slot *slot)\n--\narch/s390/include/asm/kvm_host.h=762=static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}\narch/s390/include/asm/kvm_host.h:763:static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/s390/include/asm/kvm_host.h-764-\t\tstruct kvm_memory_slot *slot) {}\n--\narch/x86/kvm/mmu/mmu.c=7576=static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)\n--\narch/x86/kvm/mmu/mmu.c-7581-\narch/x86/kvm/mmu/mmu.c:7582:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\narch/x86/kvm/mmu/mmu.c-7583-\t\t\t\t struct kvm_memory_slot *slot)\n--\narch/x86/kvm/x86.c=10160=static void kvm_mmu_slot_apply_flags(struct kvm *kvm,\n--\narch/x86/kvm/x86.c-10182-\t * MOVE/DELETE: The old mappings will already have been cleaned up by\narch/x86/kvm/x86.c:10183:\t *\t\tkvm_arch_flush_shadow_memslot()\narch/x86/kvm/x86.c-10184-\t *\n--\narch/x86/kvm/x86.c-10188-\t * MOVE/DELETE: The old mappings will already have been cleaned up by\narch/x86/kvm/x86.c:10189:\t *\t\tkvm_arch_flush_shadow_memslot().\narch/x86/kvm/x86.c-10190-\t */\n--\ninclude/linux/kvm_host.h=1254=void kvm_arch_flush_shadow_all(struct kvm *kvm);\ninclude/linux/kvm_host.h-1255-/* flush memory translations pointing to 'slot' */\ninclude/linux/kvm_host.h:1256:void kvm_arch_flush_shadow_memslot(struct kvm *kvm,\ninclude/linux/kvm_host.h-1257-\t\t\t\t struct kvm_memory_slot *slot);\n--\nvirt/kvm/kvm_main.c=1798=static void kvm_invalidate_memslot(struct kvm *kvm,\n--\nvirt/kvm/kvm_main.c-1823-\t */\nvirt/kvm/kvm_main.c:1824:\tkvm_arch_flush_shadow_memslot(kvm, old);\nvirt/kvm/kvm_main.c-1825-\tkvm_arch_guest_memory_reclaimed(kvm);\n"
} |
| 9/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18145 output: 22 thoughts: 1476 Thoughts: **Analysis of KVM MMU Logic Modifications for Fuzzing** Okay, so I'm looking at this patch and immediately, my brain zeroes in on the implications for fuzzing. `kvm_arch_flush_shadow_memslot` is the key function here, as it's the core of the change in `arch/x86/kvm/mmu/mmu.c`. It's called when a memslot is deleted or moved, triggered by `kvm_invalidate_memslot` in `virt/kvm/kvm_main.c`. That's important. The code itself has a few interesting paths. Even without SEV-SNP, it's reachable if `kvm_memslot_flush_zap_all(kvm)` is true or if `slot->gmem.file` is set. Now, `kvm_memslot_flush_zap_all(kvm)` is true under the default KVM X86 environment, specifically when `kvm->arch.vm_type == KVM_X86_DEFAULT_VM` and `kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL)`. This is a very common scenario for KVM, meaning these code paths are highly relevant and definitely fuzzable. This is core KVM MMU logic. So, it's definitely worth targeting. Now, I need to figure out how to best configure syzkaller for this. Let's think about the config flags. I see `CONFIG_KVM_AMD_SEV`. That's a good place to start, and specifically covers the modified code. Should be listed as a configuration in `EnableConfigs`. However, `KVM_AMD_SEV` is specific to AMD, and syzkaller does tests on Intel and AMD. The prompt notes, "Only list those that specifically cover the modified code." and `KVM_AMD_SEV` looks like a good starting point. I also need to see what `CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE` is, and note that it's selected by `KVM_AMD_SEV`. Now, the `FocusSymbols`. The modified functions are: `kvm_arch_flush_shadow_memslot`, `__kvm_mmu_zap_all_fast_front_half`, `__kvm_mmu_zap_all_fast_back_half`, `sev_snp_init_protected_guest_state`, `__sev_snp_reload_vmsa`, `sev_snp_reload_vmsa`, `sev_gmem_invalidate_range`, and `sev_gmem_free_folio`. Syzkaller needs the full list of these functions. `kvm_arch_flush_shadow_memslot` is a solid focus symbol. `__kvm_mmu_zap_all_fast_front_half` and `__kvm_mmu_zap_all_fast_back_half` are static, but syzkaller should still be able to fuzz them if they are in the binary. Syzkaller focuses on functions, so let's list them all: `kvm_arch_flush_shadow_memslot`, `__kvm_mmu_zap_all_fast_front_half`, `__kvm_mmu_zap_all_fast_back_half`, `sev_snp_init_protected_guest_state`, `sev_snp_reload_vmsa`, `sev_gmem_invalidate_range`, and `sev_gmem_free_folio`. I have to verify whether these are hot paths. `kvm_arch_flush_shadow_memslot` is called during memslot deletion or movement, so not a hot path. Same for `sev_snp_init_protected_guest_state`, `sev_snp_reload_vmsa`, `sev_gmem_invalidate_range`, and `sev_gmem_free_folio`. These all look like initialization or rare event paths. I should also double-check `CONFIG_KVM_AMD_SEV` in `arch/x86/kvm/Kconfig` to be sure. |
| 10/2 | 2026/06/27 01:50 | tool | grepper |
0mArgs:{
"Expression": "config KVM_AMD_SEV"
}Results: {
"Output": "arch/x86/kvm/Kconfig=146=config KVM_AMD\n--\narch/x86/kvm/Kconfig-155-\narch/x86/kvm/Kconfig:156:config KVM_AMD_SEV\narch/x86/kvm/Kconfig-157-\tbool \"AMD Secure Encrypted Virtualization (SEV) support\"\n"
} |
| 11/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20696 output: 21 thoughts: 53 Thoughts: Okay, here's my take on those thoughts, framed as my own: **Analyzing Kernel Configurations and Patch Scope** Alright, so `KVM_AMD_SEV`, yeah, that's definitely a user-selectable config, I know that one. Makes you wonder though, are there any *other* related configs in play here that I'm missing? Gotta make sure I'm getting the whole picture, especially when dealing with these security features. Hmm, the patch itself is touching `virt/kvm/guest_memfd.c`. Okay, so it’s dealing with the guest memory file descriptor interface within KVM. This has me wondering - is there a configuration option related to the `guest_memfd` functionality itself? It's crucial to understand if this is a feature that can be enabled/disabled at compile time or runtime independently of `KVM_AMD_SEV`, as that could have implications for its integration with SEV. That’s something I need to look into. |
| 12/2 | 2026/06/27 01:50 | tool | grepper |
0mError:no matches Args: {
"Expression": "config KVM_PRIVATE_MEM"
}Results: {
"error": "no matches"
} |
| 13/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20997 output: 18 thoughts: 19 Thoughts: Here's my thought process, as if I were considering this myself: **Investigating the `guest_memfd` Option in KVM Configuration** Okay, so I need to find the definition or usage of `guest_memfd`. Given the context, it's highly likely this is related to a KVM feature. My initial instinct is to check the `Kconfig` file within the KVM directory, specifically `virt/kvm/Kconfig`. That's the standard place for configuring features and dependencies within the KVM subsystem, so that's where I'll begin my search. Let's start digging there and see what we can find. I'm expecting this `Kconfig` file to give me the definitive answer on what `guest_memfd` does. |
| 14/2 | 2026/06/27 01:50 | tool | grepper |
0mArgs:{
"Expression": "guest_memfd"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 577 lines.\nUse more precise expression if possible.\n\nDocumentation/virt/kvm/api.rst=6334=KVM_SET_USER_MEMORY_REGION2 is an extension to KVM_SET_USER_MEMORY_REGION that\nDocumentation/virt/kvm/api.rst:6335:allows mapping guest_memfd memory into a guest. All fields shared with\nDocumentation/virt/kvm/api.rst-6336-KVM_SET_USER_MEMORY_REGION identically. Userspace can set KVM_MEM_GUEST_MEMFD\nDocumentation/virt/kvm/api.rst:6337:in flags to have KVM bind the memory region to a given guest_memfd range of\nDocumentation/virt/kvm/api.rst:6338:[guest_memfd_offset, guest_memfd_offset + memory_size]. The target guest_memfd\nDocumentation/virt/kvm/api.rst-6339-must point at a file created via KVM_CREATE_GUEST_MEMFD on the current VM, and\n--\nDocumentation/virt/kvm/api.rst=6341=bounds checks apply (use common sense).\n--\nDocumentation/virt/kvm/api.rst-6350-\t__u64 userspace_addr; /* start of the userspace allocated memory */\nDocumentation/virt/kvm/api.rst:6351:\t__u64 guest_memfd_offset;\nDocumentation/virt/kvm/api.rst:6352:\t__u32 guest_memfd;\nDocumentation/virt/kvm/api.rst-6353-\t__u32 pad1;\n--\nDocumentation/virt/kvm/api.rst-6356-\nDocumentation/virt/kvm/api.rst:6357:A KVM_MEM_GUEST_MEMFD region _must_ have a valid guest_memfd (private memory) and\nDocumentation/virt/kvm/api.rst-6358-userspace_addr (shared memory). However, \"valid\" for userspace_addr simply\n--\nDocumentation/virt/kvm/api.rst=6364=When mapping a gfn into the guest, KVM selects shared vs. private, i.e consumes\nDocumentation/virt/kvm/api.rst:6365:userspace_addr vs. guest_memfd, based on the gfn's KVM_MEMORY_ATTRIBUTE_PRIVATE\nDocumentation/virt/kvm/api.rst-6366-state. At VM creation time, all memory is shared, i.e. the PRIVATE attribute\n--\nDocumentation/virt/kvm/api.rst=6410=The \"flags\" field is reserved for future extensions and must be '0'.\n--\nDocumentation/virt/kvm/api.rst-6417-:Type: vm ioctl\nDocumentation/virt/kvm/api.rst:6418::Parameters: struct kvm_create_guest_memfd(in)\nDocumentation/virt/kvm/api.rst-6419-:Returns: A file descriptor on success, \u003c0 on error\n--\nDocumentation/virt/kvm/api.rst=6421=KVM_CREATE_GUEST_MEMFD creates an anonymous file and returns a file descriptor\nDocumentation/virt/kvm/api.rst:6422:that refers to it. guest_memfd files are roughly analogous to files created\nDocumentation/virt/kvm/api.rst:6423:via memfd_create(), e.g. guest_memfd files live in RAM, have volatile storage,\nDocumentation/virt/kvm/api.rst-6424-and are automatically released when the last reference is dropped. Unlike\nDocumentation/virt/kvm/api.rst:6425:\"regular\" memfd_create() files, guest_memfd files are bound to their owning\nDocumentation/virt/kvm/api.rst-6426-virtual machine (see below), cannot be mapped, read, or written by userspace,\nDocumentation/virt/kvm/api.rst:6427:and cannot be resized (guest_memfd files do however support PUNCH_HOLE).\nDocumentation/virt/kvm/api.rst-6428-\n--\nDocumentation/virt/kvm/api.rst-6430-\nDocumentation/virt/kvm/api.rst:6431: struct kvm_create_guest_memfd {\nDocumentation/virt/kvm/api.rst-6432-\t__u64 size;\n--\nDocumentation/virt/kvm/api.rst-6436-\nDocumentation/virt/kvm/api.rst:6437:Conceptually, the inode backing a guest_memfd file represents physical memory,\nDocumentation/virt/kvm/api.rst-6438-i.e. is coupled to the virtual machine as a thing, not to a \"struct kvm\". The\n--\nDocumentation/virt/kvm/api.rst=6443=migration of a virtual machine.\nDocumentation/virt/kvm/api.rst-6444-\nDocumentation/virt/kvm/api.rst:6445:KVM currently only supports mapping guest_memfd via KVM_SET_USER_MEMORY_REGION2,\nDocumentation/virt/kvm/api.rst:6446:and more specifically via the guest_memfd and guest_memfd_offset fields in\nDocumentation/virt/kvm/api.rst:6447:\"struct kvm_userspace_memory_region2\", where guest_memfd_offset is the offset\nDocumentation/virt/kvm/api.rst:6448:into the guest_memfd instance. For a given guest_memfd file, there can be at\nDocumentation/virt/kvm/api.rst-6449-most one mapping per page, i.e. binding multiple memory regions to a single\nDocumentation/virt/kvm/api.rst:6450:guest_memfd range is not allowed (any number of memory regions can be bound to\nDocumentation/virt/kvm/api.rst:6451:a single guest_memfd file, but the bound ranges must not overlap).\nDocumentation/virt/kvm/api.rst-6452-\n--\nDocumentation/virt/kvm/api.rst=6454=specified via KVM_CREATE_GUEST_MEMFD. Currently defined flags:\n--\nDocumentation/virt/kvm/api.rst-6456- ============================ ================================================\nDocumentation/virt/kvm/api.rst:6457: GUEST_MEMFD_FLAG_MMAP Enable using mmap() on the guest_memfd file\nDocumentation/virt/kvm/api.rst-6458- descriptor.\n--\nDocumentation/virt/kvm/api.rst=6466=When the KVM MMU performs a PFN lookup to service a guest fault and the backing\nDocumentation/virt/kvm/api.rst:6467:guest_memfd has the GUEST_MEMFD_FLAG_MMAP set, then the fault will always be\nDocumentation/virt/kvm/api.rst:6468:consumed from guest_memfd, regardless of whether it is a shared or a private\nDocumentation/virt/kvm/api.rst-6469-fault.\n--\narch/arm64/kvm/mmu.c=2611=int kvm_arch_prepare_memory_region(struct kvm *kvm,\n--\narch/arm64/kvm/mmu.c-2643-\t/*\narch/arm64/kvm/mmu.c:2644:\t * Only support guest_memfd backed memslots with mappable memory, since\narch/arm64/kvm/mmu.c-2645-\t * there aren't any CoCo VMs that support only private memory on arm64.\n--\narch/arm64/kvm/nested.c=1474=int kvm_handle_vncr_abort(struct kvm_vcpu *vcpu)\n--\narch/arm64/kvm/nested.c-1503-\t\t\t/*\narch/arm64/kvm/nested.c:1504:\t\t\t * For guest_memfd, this indicates that it failed to\narch/arm64/kvm/nested.c-1505-\t\t\t * create a folio to back the memory. Inform userspace.\n--\narch/x86/kvm/mmu/mmu.c=3346=static u8 kvm_gmem_max_mapping_level(struct kvm *kvm, struct kvm_page_fault *fault,\n--\narch/x86/kvm/mmu/mmu.c-3357-\t} else {\narch/x86/kvm/mmu/mmu.c:3358:\t\t/* TODO: Call into guest_memfd once hugepages are supported. */\narch/x86/kvm/mmu/mmu.c:3359:\t\tWARN_ONCE(1, \"Get pfn+order from guest_memfd\");\narch/x86/kvm/mmu/mmu.c-3360-\t\tpfn = KVM_PFN_ERR_FAULT;\n--\narch/x86/kvm/mmu/mmu.c=5147=int kvm_tdp_mmu_map_private_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn)\n--\narch/x86/kvm/mmu/mmu.c-5172-\t * Mapping a pre-determined private pfn is intended only for use when\narch/x86/kvm/mmu/mmu.c:5173:\t * populating a guest_memfd instance. Assert that the slot is backed\narch/x86/kvm/mmu/mmu.c:5174:\t * by guest_memfd and that the gmem instance's invalidate_lock is held.\narch/x86/kvm/mmu/mmu.c-5175-\t */\n--\narch/x86/kvm/svm/sev.c=2398=static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)\n--\narch/x86/kvm/svm/sev.c-2437-\t * beforehand.\narch/x86/kvm/svm/sev.c:2438:\t * 3) The PFN of the guest_memfd has not already been set to private\narch/x86/kvm/svm/sev.c-2439-\t * in the RMP table.\n--\narch/x86/kvm/svm/sev.c=4052=static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/svm/sev.c-4076-\t * fail instead of blocking indefinitely and hanging the vCPU, e.g. if\narch/x86/kvm/svm/sev.c:4077:\t * the backing guest_memfd page is unavailable.\narch/x86/kvm/svm/sev.c-4078-\t */\n--\narch/x86/kvm/svm/sev.c=5183=void sev_gmem_free_folio(struct folio *folio)\n--\narch/x86/kvm/svm/sev.c-5235-\t\t * userspace may also free gmem pages during run-time via\narch/x86/kvm/svm/sev.c:5236:\t\t * hole-punching operations on the guest_memfd, so flush the\narch/x86/kvm/svm/sev.c-5237-\t\t * cache entries for these pages before free'ing them back to\n--\narch/x86/kvm/vmx/tdx.c=2952=static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx)\n--\narch/x86/kvm/vmx/tdx.c-3015-\t * the TDX-Module, and to ensure the no-fail MMU paths succeed, e.g. if\narch/x86/kvm/vmx/tdx.c:3016:\t * a concurrent PUNCH_HOLE on guest_memfd triggers removal of SPTEs.\narch/x86/kvm/vmx/tdx.c-3017-\t */\n--\narch/x86/kvm/vmx/tdx.c=3189=static int tdx_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,\n--\narch/x86/kvm/vmx/tdx.c-3213-\t * between mapping the pfn and now, but slots_lock prevents memslot\narch/x86/kvm/vmx/tdx.c:3214:\t * updates, filemap_invalidate_lock() prevents guest_memfd updates,\narch/x86/kvm/vmx/tdx.c-3215-\t * mmu_notifier events can't reach S-EPT entries, and KVM's internal\n--\narch/x86/kvm/x86.c=10573=bool kvm_arch_no_poll(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-10579-/*\narch/x86/kvm/x86.c:10580: * KVM doesn't yet support initializing guest_memfd memory as shared for VMs\narch/x86/kvm/x86.c-10581- * with private memory (the private vs. shared tracking needs to be moved into\narch/x86/kvm/x86.c:10582: * guest_memfd).\narch/x86/kvm/x86.c-10583- */\n--\ninclude/uapi/linux/kvm.h=39=struct kvm_userspace_memory_region2 {\n--\ninclude/uapi/linux/kvm.h-44-\t__u64 userspace_addr;\ninclude/uapi/linux/kvm.h:45:\t__u64 guest_memfd_offset;\ninclude/uapi/linux/kvm.h:46:\t__u32 guest_memfd;\ninclude/uapi/linux/kvm.h-47-\t__u32 pad1;\n--\ninclude/uapi/linux/kvm.h=1645=struct kvm_memory_attributes {\n--\ninclude/uapi/linux/kvm.h-1653-\ninclude/uapi/linux/kvm.h:1654:#define KVM_CREATE_GUEST_MEMFD\t_IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd)\ninclude/uapi/linux/kvm.h-1655-#define GUEST_MEMFD_FLAG_MMAP\t\t(1ULL \u003c\u003c 0)\n--\ninclude/uapi/linux/kvm.h-1657-\ninclude/uapi/linux/kvm.h:1658:struct kvm_create_guest_memfd {\ninclude/uapi/linux/kvm.h-1659-\t__u64 size;\n--\ntools/include/uapi/linux/kvm.h=38=struct kvm_userspace_memory_region2 {\n--\ntools/include/uapi/linux/kvm.h-43-\t__u64 userspace_addr;\ntools/include/uapi/linux/kvm.h:44:\t__u64 guest_memfd_offset;\ntools/include/uapi/linux/kvm.h:45:\t__u32 guest_memfd;\ntools/include/uapi/linux/kvm.h-46-\t__u32 pad1;\n--\ntools/include/uapi/linux/kvm.h=1635=struct kvm_memory_attributes {\n--\ntools/include/uapi/linux/kvm.h-1643-\ntools/include/uapi/linux/kvm.h:1644:#define KVM_CREATE_GUEST_MEMFD\t_IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd)\ntools/include/uapi/linux/kvm.h-1645-#define GUEST_MEMFD_FLAG_MMAP\t\t(1ULL \u003c\u003c 0)\n--\ntools/include/uapi/linux/kvm.h-1647-\ntools/include/uapi/linux/kvm.h:1648:struct kvm_create_guest_memfd {\ntools/include/uapi/linux/kvm.h-1649-\t__u64 size;\n--\ntools/testing/selftests/kvm/Makefile.kvm=157=TEST_GEN_PROGS_x86 += dirty_log_perf_test\ntools/testing/selftests/kvm/Makefile.kvm:158:TEST_GEN_PROGS_x86 += guest_memfd_test\ntools/testing/selftests/kvm/Makefile.kvm-159-TEST_GEN_PROGS_x86 += hardware_disable_test\n--\ntools/testing/selftests/kvm/Makefile.kvm=196=TEST_GEN_PROGS_arm64 += get-reg-list\ntools/testing/selftests/kvm/Makefile.kvm:197:TEST_GEN_PROGS_arm64 += guest_memfd_test\ntools/testing/selftests/kvm/Makefile.kvm-198-TEST_GEN_PROGS_arm64 += mmu_stress_test\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=42=static void test_mmap_cow(int fd, size_t size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-46-\tmem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c:47:\tTEST_ASSERT(mem == MAP_FAILED, \"Copy-on-write not allowed by guest_memfd.\");\ntools/testing/selftests/kvm/guest_memfd_test.c-48-}\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=174=static void test_collapse(int fd, u64 flags)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-182-\t/*\ntools/testing/selftests/kvm/guest_memfd_test.c:183:\t * To even reach the point where the guest_memfd folios will\ntools/testing/selftests/kvm/guest_memfd_test.c-184-\t * get collapsed, both the userspace address and the offset\ntools/testing/selftests/kvm/guest_memfd_test.c:185:\t * within the guest_memfd have to be aligned to pmd_size.\ntools/testing/selftests/kvm/guest_memfd_test.c-186-\t *\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-208-\t/*\ntools/testing/selftests/kvm/guest_memfd_test.c:209:\t * Advising the use of huge pages in guest_memfd should be\ntools/testing/selftests/kvm/guest_memfd_test.c-210-\t * fine...\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=348=static void test_invalid_binding(struct kvm_vm *vm, int fd, size_t size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-357-\ntools/testing/selftests/kvm/guest_memfd_test.c:358:static void test_create_guest_memfd_invalid_sizes(struct kvm_vm *vm,\ntools/testing/selftests/kvm/guest_memfd_test.c:359:\t\t\t\t\t\t u64 guest_memfd_flags)\ntools/testing/selftests/kvm/guest_memfd_test.c-360-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-364-\tfor (size = 1; size \u003c page_size; size++) {\ntools/testing/selftests/kvm/guest_memfd_test.c:365:\t\tfd = __vm_create_guest_memfd(vm, size, guest_memfd_flags);\ntools/testing/selftests/kvm/guest_memfd_test.c-366-\t\tTEST_ASSERT(fd \u003c 0 \u0026\u0026 errno == EINVAL,\ntools/testing/selftests/kvm/guest_memfd_test.c:367:\t\t\t \"guest_memfd() with non-page-aligned page size '0x%lx' should fail with EINVAL\",\ntools/testing/selftests/kvm/guest_memfd_test.c-368-\t\t\t size);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-371-\ntools/testing/selftests/kvm/guest_memfd_test.c:372:static void test_create_guest_memfd_multiple(struct kvm_vm *vm)\ntools/testing/selftests/kvm/guest_memfd_test.c-373-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-376-\ntools/testing/selftests/kvm/guest_memfd_test.c:377:\tfd1 = __vm_create_guest_memfd(vm, page_size, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-378-\tTEST_ASSERT(fd1 != -1, \"memfd creation should succeed\");\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-383-\ntools/testing/selftests/kvm/guest_memfd_test.c:384:\tfd2 = __vm_create_guest_memfd(vm, page_size * 2, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-385-\tTEST_ASSERT(fd2 != -1, \"memfd creation should succeed\");\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-399-\ntools/testing/selftests/kvm/guest_memfd_test.c:400:static void test_guest_memfd_flags(struct kvm_vm *vm)\ntools/testing/selftests/kvm/guest_memfd_test.c-401-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-406-\tfor (flag = BIT(0); flag; flag \u003c\u003c= 1) {\ntools/testing/selftests/kvm/guest_memfd_test.c:407:\t\tfd = __vm_create_guest_memfd(vm, page_size, flag);\ntools/testing/selftests/kvm/guest_memfd_test.c-408-\t\tif (flag \u0026 valid_flags) {\ntools/testing/selftests/kvm/guest_memfd_test.c-409-\t\t\tTEST_ASSERT(fd \u003e= 0,\ntools/testing/selftests/kvm/guest_memfd_test.c:410:\t\t\t\t \"guest_memfd() with flag '0x%lx' should succeed\",\ntools/testing/selftests/kvm/guest_memfd_test.c-411-\t\t\t\t flag);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-414-\t\t\tTEST_ASSERT(fd \u003c 0 \u0026\u0026 errno == EINVAL,\ntools/testing/selftests/kvm/guest_memfd_test.c:415:\t\t\t\t \"guest_memfd() with flag '0x%lx' should fail with EINVAL\",\ntools/testing/selftests/kvm/guest_memfd_test.c-416-\t\t\t\t flag);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=422=do {\t\t\t\t\t\t\t\t\t\\\ntools/testing/selftests/kvm/guest_memfd_test.c:423:\tint fd = vm_create_guest_memfd(__vm, __gmem_size, __flags);\t\\\ntools/testing/selftests/kvm/guest_memfd_test.c-424-\t\t\t\t\t\t\t\t\t\\\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-440-\ntools/testing/selftests/kvm/guest_memfd_test.c:441:static void __test_guest_memfd(struct kvm_vm *vm, u64 flags)\ntools/testing/selftests/kvm/guest_memfd_test.c-442-{\ntools/testing/selftests/kvm/guest_memfd_test.c:443:\ttest_create_guest_memfd_multiple(vm);\ntools/testing/selftests/kvm/guest_memfd_test.c:444:\ttest_create_guest_memfd_invalid_sizes(vm, flags);\ntools/testing/selftests/kvm/guest_memfd_test.c-445-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-471-\ntools/testing/selftests/kvm/guest_memfd_test.c:472:static void test_guest_memfd(unsigned long vm_type)\ntools/testing/selftests/kvm/guest_memfd_test.c-473-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-476-\ntools/testing/selftests/kvm/guest_memfd_test.c:477:\ttest_guest_memfd_flags(vm);\ntools/testing/selftests/kvm/guest_memfd_test.c-478-\ntools/testing/selftests/kvm/guest_memfd_test.c:479:\t__test_guest_memfd(vm, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-480-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-482-\tif (flags \u0026 GUEST_MEMFD_FLAG_MMAP)\ntools/testing/selftests/kvm/guest_memfd_test.c:483:\t\t__test_guest_memfd(vm, GUEST_MEMFD_FLAG_MMAP);\ntools/testing/selftests/kvm/guest_memfd_test.c-484-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-486-\tif (flags \u0026 GUEST_MEMFD_FLAG_INIT_SHARED)\ntools/testing/selftests/kvm/guest_memfd_test.c:487:\t\t__test_guest_memfd(vm, GUEST_MEMFD_FLAG_MMAP |\ntools/testing/selftests/kvm/guest_memfd_test.c-488-\t\t\t\t GUEST_MEMFD_FLAG_INIT_SHARED);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=493=static void guest_code(u8 *mem, u64 size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-504-\ntools/testing/selftests/kvm/guest_memfd_test.c:505:static void test_guest_memfd_guest(void)\ntools/testing/selftests/kvm/guest_memfd_test.c-506-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-534-\t * Use the max of the host or guest page size for all operations, as\ntools/testing/selftests/kvm/guest_memfd_test.c:535:\t * KVM requires guest_memfd files and memslots to be sized to multiples\ntools/testing/selftests/kvm/guest_memfd_test.c-536-\t * of the host page size.\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-538-\tsize = max_t(size_t, vm-\u003epage_size, page_size);\ntools/testing/selftests/kvm/guest_memfd_test.c:539:\tfd = vm_create_guest_memfd(vm, size, GUEST_MEMFD_FLAG_MMAP |\ntools/testing/selftests/kvm/guest_memfd_test.c-540-\t\t\t\t\t GUEST_MEMFD_FLAG_INIT_SHARED);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=561=int main(int argc, char *argv[])\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-570-\t * Not all architectures support KVM_CAP_VM_TYPES. However, those that\ntools/testing/selftests/kvm/guest_memfd_test.c:571:\t * support guest_memfd have that support for the default VM type.\ntools/testing/selftests/kvm/guest_memfd_test.c-572-\t */\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-577-\tfor_each_set_bit(vm_type, \u0026vm_types, BITS_PER_TYPE(vm_types))\ntools/testing/selftests/kvm/guest_memfd_test.c:578:\t\ttest_guest_memfd(vm_type);\ntools/testing/selftests/kvm/guest_memfd_test.c-579-\ntools/testing/selftests/kvm/guest_memfd_test.c:580:\ttest_guest_memfd_guest();\ntools/testing/selftests/kvm/guest_memfd_test.c-581-}\n--\ntools/testing/selftests/kvm/include/kvm_util.h=665=void vm_create_irqchip(struct kvm_vm *vm);\ntools/testing/selftests/kvm/include/kvm_util.h-666-\ntools/testing/selftests/kvm/include/kvm_util.h:667:static inline int __vm_create_guest_memfd(struct kvm_vm *vm, u64 size,\ntools/testing/selftests/kvm/include/kvm_util.h-668-\t\t\t\t\t u64 flags)\ntools/testing/selftests/kvm/include/kvm_util.h-669-{\ntools/testing/selftests/kvm/include/kvm_util.h:670:\tstruct kvm_create_guest_memfd guest_memfd = {\ntools/testing/selftests/kvm/include/kvm_util.h-671-\t\t.size = size,\n--\ntools/testing/selftests/kvm/include/kvm_util.h-674-\ntools/testing/selftests/kvm/include/kvm_util.h:675:\treturn __vm_ioctl(vm, KVM_CREATE_GUEST_MEMFD, \u0026guest_memfd);\ntools/testing/selftests/kvm/include/kvm_util.h-676-}\ntools/testing/selftests/kvm/include/kvm_util.h-677-\ntools/testing/selftests/kvm/include/kvm_util.h:678:static inline int vm_create_guest_memfd(struct kvm_vm *vm, u64 size,\ntools/testing/selftests/kvm/include/kvm_util.h-679-\t\t\t\t\tu64 flags)\ntools/testing/selftests/kvm/include/kvm_util.h-680-{\ntools/testing/selftests/kvm/include/kvm_util.h:681:\tint fd = __vm_create_guest_memfd(vm, size, flags);\ntools/testing/selftests/kvm/include/kvm_util.h-682-\n--\ntools/testing/selftests/kvm/include/kvm_util.h=691=void vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h-692-\t\t\t\tgpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/include/kvm_util.h:693:\t\t\t\tu32 guest_memfd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-694-int __vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h-695-\t\t\t\t gpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/include/kvm_util.h:696:\t\t\t\t u32 guest_memfd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-697-\n--\ntools/testing/selftests/kvm/include/kvm_util.h=701=void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,\ntools/testing/selftests/kvm/include/kvm_util.h-702-\t\tgpa_t gpa, u32 slot, u64 npages, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h:703:\t\tint guest_memfd_fd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-704-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=438=void kvm_set_files_rlimit(u32 nr_vcpus)\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-469-\ntools/testing/selftests/kvm/lib/kvm_util.c:470:static bool is_guest_memfd_required(struct vm_shape shape)\ntools/testing/selftests/kvm/lib/kvm_util.c-471-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=479=struct kvm_vm *__vm_create(struct vm_shape shape, u32 nr_runnable_vcpus,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-499-\tflags = 0;\ntools/testing/selftests/kvm/lib/kvm_util.c:500:\tif (is_guest_memfd_required(shape))\ntools/testing/selftests/kvm/lib/kvm_util.c-501-\t\tflags |= KVM_MEM_GUEST_MEMFD;\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=804=static void __vm_mem_region_delete(struct kvm_vm *vm,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-818-\t}\ntools/testing/selftests/kvm/lib/kvm_util.c:819:\tif ((int)region-\u003eregion.guest_memfd \u003e= 0)\ntools/testing/selftests/kvm/lib/kvm_util.c:820:\t\tkvm_free_fd(region-\u003eregion.guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-821-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=947=int __vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c-948-\t\t\t\t gpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:949:\t\t\t\t u32 guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-950-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-956-\t\t.userspace_addr = (uintptr_t)hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:957:\t\t.guest_memfd = guest_memfd,\ntools/testing/selftests/kvm/lib/kvm_util.c:958:\t\t.guest_memfd_offset = guest_memfd_offset,\ntools/testing/selftests/kvm/lib/kvm_util.c-959-\t};\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=966=void vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c-967-\t\t\t\tgpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:968:\t\t\t\tu32 guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-969-{\ntools/testing/selftests/kvm/lib/kvm_util.c-970-\tint ret = __vm_set_user_memory_region2(vm, slot, flags, gpa, size, hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:971:\t\t\t\t\t guest_memfd, guest_memfd_offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-972-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=979=void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,\ntools/testing/selftests/kvm/lib/kvm_util.c-980-\t\tgpa_t gpa, u32 slot, u64 npages, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c:981:\t\tint guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-982-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1085-\tif (flags \u0026 KVM_MEM_GUEST_MEMFD) {\ntools/testing/selftests/kvm/lib/kvm_util.c:1086:\t\tif (guest_memfd \u003c 0) {\ntools/testing/selftests/kvm/lib/kvm_util.c:1087:\t\t\tu32 guest_memfd_flags = 0;\ntools/testing/selftests/kvm/lib/kvm_util.c:1088:\t\t\tTEST_ASSERT(!guest_memfd_offset,\ntools/testing/selftests/kvm/lib/kvm_util.c:1089:\t\t\t\t \"Offset must be zero when creating new guest_memfd\");\ntools/testing/selftests/kvm/lib/kvm_util.c:1090:\t\t\tguest_memfd = vm_create_guest_memfd(vm, mem_size, guest_memfd_flags);\ntools/testing/selftests/kvm/lib/kvm_util.c-1091-\t\t} else {\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1097-\t\t\t */\ntools/testing/selftests/kvm/lib/kvm_util.c:1098:\t\t\tguest_memfd = kvm_dup(guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-1099-\t\t}\ntools/testing/selftests/kvm/lib/kvm_util.c-1100-\ntools/testing/selftests/kvm/lib/kvm_util.c:1101:\t\tregion-\u003eregion.guest_memfd = guest_memfd;\ntools/testing/selftests/kvm/lib/kvm_util.c:1102:\t\tregion-\u003eregion.guest_memfd_offset = guest_memfd_offset;\ntools/testing/selftests/kvm/lib/kvm_util.c-1103-\t} else {\ntools/testing/selftests/kvm/lib/kvm_util.c:1104:\t\tregion-\u003eregion.guest_memfd = -1;\ntools/testing/selftests/kvm/lib/kvm_util.c-1105-\t}\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1119-\t\t\" slot: %u flags: 0x%x\\n\"\ntools/testing/selftests/kvm/lib/kvm_util.c:1120:\t\t\" guest_phys_addr: 0x%lx size: 0x%llx guest_memfd: %d\",\ntools/testing/selftests/kvm/lib/kvm_util.c-1121-\t\tret, errno, slot, flags, gpa, region-\u003eregion.memory_size,\ntools/testing/selftests/kvm/lib/kvm_util.c:1122:\t\tregion-\u003eregion.guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-1123-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=1274=void vm_guest_mem_fallocate(struct kvm_vm *vm, u64 base, u64 size,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1291-\t\toffset = gpa - region-\u003eregion.guest_phys_addr;\ntools/testing/selftests/kvm/lib/kvm_util.c:1292:\t\tfd_offset = region-\u003eregion.guest_memfd_offset + offset;\ntools/testing/selftests/kvm/lib/kvm_util.c-1293-\t\tlen = min_t(u64, end - gpa, region-\u003eregion.memory_size - offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-1294-\ntools/testing/selftests/kvm/lib/kvm_util.c:1295:\t\tret = fallocate(region-\u003eregion.guest_memfd, mode, fd_offset, len);\ntools/testing/selftests/kvm/lib/kvm_util.c-1296-\t\tTEST_ASSERT(!ret, \"fallocate() failed to %s at %lx (len = %lu), fd = %d, mode = %x, offset = %lx\",\ntools/testing/selftests/kvm/lib/kvm_util.c-1297-\t\t\t punch_hole ? \"punch hole\" : \"allocate\", gpa, len,\ntools/testing/selftests/kvm/lib/kvm_util.c:1298:\t\t\t region-\u003eregion.guest_memfd, mode, fd_offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-1299-\t}\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=346=static void test_invalid_memory_region_flags(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-386-\tif (supported_flags \u0026 KVM_MEM_GUEST_MEMFD) {\ntools/testing/selftests/kvm/set_memory_region_test.c:387:\t\tint guest_memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-388-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-390-\t\t\t\t\t\t KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_GUEST_MEMFD,\ntools/testing/selftests/kvm/set_memory_region_test.c:391:\t\t\t\t\t\t 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-392-\t\tTEST_ASSERT(r \u0026\u0026 errno == EINVAL,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-396-\t\t\t\t\t\t KVM_MEM_READONLY | KVM_MEM_GUEST_MEMFD,\ntools/testing/selftests/kvm/set_memory_region_test.c:397:\t\t\t\t\t\t 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-398-\t\tTEST_ASSERT(r \u0026\u0026 errno == EINVAL,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-400-\ntools/testing/selftests/kvm/set_memory_region_test.c:401:\t\tclose(guest_memfd);\ntools/testing/selftests/kvm/set_memory_region_test.c-402-\t}\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=409=static void test_add_max_memory_regions(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-457-#ifdef __x86_64__\ntools/testing/selftests/kvm/set_memory_region_test.c:458:static void test_invalid_guest_memfd(struct kvm_vm *vm, int memfd,\ntools/testing/selftests/kvm/set_memory_region_test.c-459-\t\t\t\t size_t offset, const char *msg)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=467=static void test_add_private_memory_region(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-475-\ntools/testing/selftests/kvm/set_memory_region_test.c:476:\ttest_invalid_guest_memfd(vm, vm-\u003ekvm_fd, 0, \"KVM fd should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c:477:\ttest_invalid_guest_memfd(vm, vm-\u003efd, 0, \"VM's fd should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-478-\ntools/testing/selftests/kvm/set_memory_region_test.c-479-\tmemfd = kvm_memfd_alloc(MEM_REGION_SIZE, false);\ntools/testing/selftests/kvm/set_memory_region_test.c:480:\ttest_invalid_guest_memfd(vm, memfd, 0, \"Regular memfd() should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-481-\tclose(memfd);\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-483-\tvm2 = vm_create_barebones_type(KVM_X86_SW_PROTECTED_VM);\ntools/testing/selftests/kvm/set_memory_region_test.c:484:\tmemfd = vm_create_guest_memfd(vm2, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c:485:\ttest_invalid_guest_memfd(vm, memfd, 0, \"Other VM's guest_memfd() should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-486-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-491-\ntools/testing/selftests/kvm/set_memory_region_test.c:492:\tmemfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-493-\tfor (i = 1; i \u003c PAGE_SIZE; i++)\ntools/testing/selftests/kvm/set_memory_region_test.c:494:\t\ttest_invalid_guest_memfd(vm, memfd, i, \"Unaligned offset should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-495-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=503=static void test_add_overlapping_private_memory_regions(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-512-\ntools/testing/selftests/kvm/set_memory_region_test.c:513:\tmemfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE * 5, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-514-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-523-\t * Delete the first memslot, and then attempt to recreate it except\ntools/testing/selftests/kvm/set_memory_region_test.c:524:\t * with a \"bad\" offset that results in overlap in the guest_memfd().\ntools/testing/selftests/kvm/set_memory_region_test.c-525-\t */\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-529-\t/*\ntools/testing/selftests/kvm/set_memory_region_test.c:530:\t * Verify that overlap in the guest_memfd bindings (i.e. in guest_memfd\ntools/testing/selftests/kvm/set_memory_region_test.c-531-\t * file offsets), but _not_ in the GPA space, fails with -EEXIST.\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-537-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:538:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-539-\ntools/testing/selftests/kvm/set_memory_region_test.c:540:\t/* And now the back half of the other slot's guest_memfd binding. */\ntools/testing/selftests/kvm/set_memory_region_test.c-541-\tr = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_GUEST_MEMFD,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-545-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:546:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-547-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-557-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:558:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-559-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-565-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:566:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-567-\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=230=static void guest_test_punch_hole(u64 base_gpa, bool precise)\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-236-\t * Convert the entire range to private, this testcase is all about\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:237:\t * punching holes in guest_memfd, i.e. shared mappings aren't needed.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-238-\t */\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=271=static void guest_code(u64 base_gpa)\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-274-\t * Run the conversion test twice, with and without doing fallocate() on\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:275:\t * the guest_memfd backing when converting between shared and private.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-276-\t */\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-280-\t/*\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:281:\t * Run the PUNCH_HOLE test twice too, once with the entire guest_memfd\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-282-\t * faulted in, once with only the target range faulted in.\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=369=static void test_mem_conversions(enum vm_mem_backing_src_type src_type, u32 nr_vcpus,\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-396-\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:397:\tmemfd = vm_create_guest_memfd(vm, memfd_size, 0);\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-398-\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-425-\t/*\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:426:\t * Allocate and free memory from the guest_memfd after closing the VM\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:427:\t * fd. The guest_memfd is gifted a reference to its owning VM, i.e.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-428-\t * should prevent the VM from being fully destroyed until the last\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:429:\t * reference to the guest_memfd is also put.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-430-\t */\n\n"
} |
| 15/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 35688 output: 21 thoughts: 182 Thoughts: Okay, let me break this down. **Investigating the `guest_memfd` Implementation in KVM** Alright, so `guest_memfd` is directly tied to `KVM_SET_USER_MEMORY_REGION2` with the `KVM_MEM_GUEST_MEMFD` flag. Right off the bat, I don't see any explicit configuration options for it – it seems to be enabled implicitly when `CONFIG_KVM` is active and the underlying architecture is compatible. That's good to know, simplifies things somewhat. Now, wait a second... this `CONFIG_KVM_AMD_SEV` configuration. It appears that enabling AMD's Secure Encrypted Virtualization also brings in `HAVE_KVM_ARCH_GMEM_PREPARE` and `HAVE_KVM_ARCH_GMEM_INVALIDATE`. Hmmm, I need to understand this connection better. Is `guest_memfd` indirectly enabled by `CONFIG_KVM` when *either* `HAVE_KVM_ARCH_GMEM_PREPARE` or `HAVE_KVM_ARCH_GMEM_INVALIDATE` are present? Or is there some other condition I am missing? It seems like it must be enabled conditionally somehow, rather than being universally available. I'm going to jump into the `virt/kvm/Kconfig` file immediately. That's the most likely spot for a clear definition of the dependency chain here. I need to clarify what the relationship is between `guest_memfd`, these `HAVE_KVM_ARCH_GMEM_*` macros, and the overall `CONFIG_KVM` settings. |
| 16/2 | 2026/06/27 01:50 | tool | grepper |
0mError:no matches Args: {
"Expression": "config KVM_PRIVATE_MEM"
}Results: {
"error": "no matches"
} |
| 17/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 36263 output: 18 thoughts: 20 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Checking the KVM Configuration for Guest Memory Sharing** Right, let's dive into the kernel configuration. I need to refresh my memory on the specifics of memory sharing within KVM guests, particularly related to `memfd`. My immediate thought is to check the `virt/kvm/Kconfig` file. That's the logical place to start. I'm looking for the configuration option associated with `guest_memfd`. It’ll be the key to understanding how memory file descriptors are being used or can be enabled for these guests. I need to see the dependencies, help text, and default settings. Hopefully, this Kconfig entry gives me a clear picture of its integration and potential implications for my work. This should be a quick and efficient way to pinpoint how the system handles it, and if it's relevant to this current focus. |
| 18/2 | 2026/06/27 01:50 | tool | grepper |
0mArgs:{
"Expression": "guest_memfd"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 577 lines.\nUse more precise expression if possible.\n\nDocumentation/virt/kvm/api.rst=6334=KVM_SET_USER_MEMORY_REGION2 is an extension to KVM_SET_USER_MEMORY_REGION that\nDocumentation/virt/kvm/api.rst:6335:allows mapping guest_memfd memory into a guest. All fields shared with\nDocumentation/virt/kvm/api.rst-6336-KVM_SET_USER_MEMORY_REGION identically. Userspace can set KVM_MEM_GUEST_MEMFD\nDocumentation/virt/kvm/api.rst:6337:in flags to have KVM bind the memory region to a given guest_memfd range of\nDocumentation/virt/kvm/api.rst:6338:[guest_memfd_offset, guest_memfd_offset + memory_size]. The target guest_memfd\nDocumentation/virt/kvm/api.rst-6339-must point at a file created via KVM_CREATE_GUEST_MEMFD on the current VM, and\n--\nDocumentation/virt/kvm/api.rst=6341=bounds checks apply (use common sense).\n--\nDocumentation/virt/kvm/api.rst-6350-\t__u64 userspace_addr; /* start of the userspace allocated memory */\nDocumentation/virt/kvm/api.rst:6351:\t__u64 guest_memfd_offset;\nDocumentation/virt/kvm/api.rst:6352:\t__u32 guest_memfd;\nDocumentation/virt/kvm/api.rst-6353-\t__u32 pad1;\n--\nDocumentation/virt/kvm/api.rst-6356-\nDocumentation/virt/kvm/api.rst:6357:A KVM_MEM_GUEST_MEMFD region _must_ have a valid guest_memfd (private memory) and\nDocumentation/virt/kvm/api.rst-6358-userspace_addr (shared memory). However, \"valid\" for userspace_addr simply\n--\nDocumentation/virt/kvm/api.rst=6364=When mapping a gfn into the guest, KVM selects shared vs. private, i.e consumes\nDocumentation/virt/kvm/api.rst:6365:userspace_addr vs. guest_memfd, based on the gfn's KVM_MEMORY_ATTRIBUTE_PRIVATE\nDocumentation/virt/kvm/api.rst-6366-state. At VM creation time, all memory is shared, i.e. the PRIVATE attribute\n--\nDocumentation/virt/kvm/api.rst=6410=The \"flags\" field is reserved for future extensions and must be '0'.\n--\nDocumentation/virt/kvm/api.rst-6417-:Type: vm ioctl\nDocumentation/virt/kvm/api.rst:6418::Parameters: struct kvm_create_guest_memfd(in)\nDocumentation/virt/kvm/api.rst-6419-:Returns: A file descriptor on success, \u003c0 on error\n--\nDocumentation/virt/kvm/api.rst=6421=KVM_CREATE_GUEST_MEMFD creates an anonymous file and returns a file descriptor\nDocumentation/virt/kvm/api.rst:6422:that refers to it. guest_memfd files are roughly analogous to files created\nDocumentation/virt/kvm/api.rst:6423:via memfd_create(), e.g. guest_memfd files live in RAM, have volatile storage,\nDocumentation/virt/kvm/api.rst-6424-and are automatically released when the last reference is dropped. Unlike\nDocumentation/virt/kvm/api.rst:6425:\"regular\" memfd_create() files, guest_memfd files are bound to their owning\nDocumentation/virt/kvm/api.rst-6426-virtual machine (see below), cannot be mapped, read, or written by userspace,\nDocumentation/virt/kvm/api.rst:6427:and cannot be resized (guest_memfd files do however support PUNCH_HOLE).\nDocumentation/virt/kvm/api.rst-6428-\n--\nDocumentation/virt/kvm/api.rst-6430-\nDocumentation/virt/kvm/api.rst:6431: struct kvm_create_guest_memfd {\nDocumentation/virt/kvm/api.rst-6432-\t__u64 size;\n--\nDocumentation/virt/kvm/api.rst-6436-\nDocumentation/virt/kvm/api.rst:6437:Conceptually, the inode backing a guest_memfd file represents physical memory,\nDocumentation/virt/kvm/api.rst-6438-i.e. is coupled to the virtual machine as a thing, not to a \"struct kvm\". The\n--\nDocumentation/virt/kvm/api.rst=6443=migration of a virtual machine.\nDocumentation/virt/kvm/api.rst-6444-\nDocumentation/virt/kvm/api.rst:6445:KVM currently only supports mapping guest_memfd via KVM_SET_USER_MEMORY_REGION2,\nDocumentation/virt/kvm/api.rst:6446:and more specifically via the guest_memfd and guest_memfd_offset fields in\nDocumentation/virt/kvm/api.rst:6447:\"struct kvm_userspace_memory_region2\", where guest_memfd_offset is the offset\nDocumentation/virt/kvm/api.rst:6448:into the guest_memfd instance. For a given guest_memfd file, there can be at\nDocumentation/virt/kvm/api.rst-6449-most one mapping per page, i.e. binding multiple memory regions to a single\nDocumentation/virt/kvm/api.rst:6450:guest_memfd range is not allowed (any number of memory regions can be bound to\nDocumentation/virt/kvm/api.rst:6451:a single guest_memfd file, but the bound ranges must not overlap).\nDocumentation/virt/kvm/api.rst-6452-\n--\nDocumentation/virt/kvm/api.rst=6454=specified via KVM_CREATE_GUEST_MEMFD. Currently defined flags:\n--\nDocumentation/virt/kvm/api.rst-6456- ============================ ================================================\nDocumentation/virt/kvm/api.rst:6457: GUEST_MEMFD_FLAG_MMAP Enable using mmap() on the guest_memfd file\nDocumentation/virt/kvm/api.rst-6458- descriptor.\n--\nDocumentation/virt/kvm/api.rst=6466=When the KVM MMU performs a PFN lookup to service a guest fault and the backing\nDocumentation/virt/kvm/api.rst:6467:guest_memfd has the GUEST_MEMFD_FLAG_MMAP set, then the fault will always be\nDocumentation/virt/kvm/api.rst:6468:consumed from guest_memfd, regardless of whether it is a shared or a private\nDocumentation/virt/kvm/api.rst-6469-fault.\n--\narch/arm64/kvm/mmu.c=2611=int kvm_arch_prepare_memory_region(struct kvm *kvm,\n--\narch/arm64/kvm/mmu.c-2643-\t/*\narch/arm64/kvm/mmu.c:2644:\t * Only support guest_memfd backed memslots with mappable memory, since\narch/arm64/kvm/mmu.c-2645-\t * there aren't any CoCo VMs that support only private memory on arm64.\n--\narch/arm64/kvm/nested.c=1474=int kvm_handle_vncr_abort(struct kvm_vcpu *vcpu)\n--\narch/arm64/kvm/nested.c-1503-\t\t\t/*\narch/arm64/kvm/nested.c:1504:\t\t\t * For guest_memfd, this indicates that it failed to\narch/arm64/kvm/nested.c-1505-\t\t\t * create a folio to back the memory. Inform userspace.\n--\narch/x86/kvm/mmu/mmu.c=3346=static u8 kvm_gmem_max_mapping_level(struct kvm *kvm, struct kvm_page_fault *fault,\n--\narch/x86/kvm/mmu/mmu.c-3357-\t} else {\narch/x86/kvm/mmu/mmu.c:3358:\t\t/* TODO: Call into guest_memfd once hugepages are supported. */\narch/x86/kvm/mmu/mmu.c:3359:\t\tWARN_ONCE(1, \"Get pfn+order from guest_memfd\");\narch/x86/kvm/mmu/mmu.c-3360-\t\tpfn = KVM_PFN_ERR_FAULT;\n--\narch/x86/kvm/mmu/mmu.c=5147=int kvm_tdp_mmu_map_private_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn)\n--\narch/x86/kvm/mmu/mmu.c-5172-\t * Mapping a pre-determined private pfn is intended only for use when\narch/x86/kvm/mmu/mmu.c:5173:\t * populating a guest_memfd instance. Assert that the slot is backed\narch/x86/kvm/mmu/mmu.c:5174:\t * by guest_memfd and that the gmem instance's invalidate_lock is held.\narch/x86/kvm/mmu/mmu.c-5175-\t */\n--\narch/x86/kvm/svm/sev.c=2398=static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)\n--\narch/x86/kvm/svm/sev.c-2437-\t * beforehand.\narch/x86/kvm/svm/sev.c:2438:\t * 3) The PFN of the guest_memfd has not already been set to private\narch/x86/kvm/svm/sev.c-2439-\t * in the RMP table.\n--\narch/x86/kvm/svm/sev.c=4052=static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/svm/sev.c-4076-\t * fail instead of blocking indefinitely and hanging the vCPU, e.g. if\narch/x86/kvm/svm/sev.c:4077:\t * the backing guest_memfd page is unavailable.\narch/x86/kvm/svm/sev.c-4078-\t */\n--\narch/x86/kvm/svm/sev.c=5183=void sev_gmem_free_folio(struct folio *folio)\n--\narch/x86/kvm/svm/sev.c-5235-\t\t * userspace may also free gmem pages during run-time via\narch/x86/kvm/svm/sev.c:5236:\t\t * hole-punching operations on the guest_memfd, so flush the\narch/x86/kvm/svm/sev.c-5237-\t\t * cache entries for these pages before free'ing them back to\n--\narch/x86/kvm/vmx/tdx.c=2952=static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx)\n--\narch/x86/kvm/vmx/tdx.c-3015-\t * the TDX-Module, and to ensure the no-fail MMU paths succeed, e.g. if\narch/x86/kvm/vmx/tdx.c:3016:\t * a concurrent PUNCH_HOLE on guest_memfd triggers removal of SPTEs.\narch/x86/kvm/vmx/tdx.c-3017-\t */\n--\narch/x86/kvm/vmx/tdx.c=3189=static int tdx_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,\n--\narch/x86/kvm/vmx/tdx.c-3213-\t * between mapping the pfn and now, but slots_lock prevents memslot\narch/x86/kvm/vmx/tdx.c:3214:\t * updates, filemap_invalidate_lock() prevents guest_memfd updates,\narch/x86/kvm/vmx/tdx.c-3215-\t * mmu_notifier events can't reach S-EPT entries, and KVM's internal\n--\narch/x86/kvm/x86.c=10573=bool kvm_arch_no_poll(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-10579-/*\narch/x86/kvm/x86.c:10580: * KVM doesn't yet support initializing guest_memfd memory as shared for VMs\narch/x86/kvm/x86.c-10581- * with private memory (the private vs. shared tracking needs to be moved into\narch/x86/kvm/x86.c:10582: * guest_memfd).\narch/x86/kvm/x86.c-10583- */\n--\ninclude/uapi/linux/kvm.h=39=struct kvm_userspace_memory_region2 {\n--\ninclude/uapi/linux/kvm.h-44-\t__u64 userspace_addr;\ninclude/uapi/linux/kvm.h:45:\t__u64 guest_memfd_offset;\ninclude/uapi/linux/kvm.h:46:\t__u32 guest_memfd;\ninclude/uapi/linux/kvm.h-47-\t__u32 pad1;\n--\ninclude/uapi/linux/kvm.h=1645=struct kvm_memory_attributes {\n--\ninclude/uapi/linux/kvm.h-1653-\ninclude/uapi/linux/kvm.h:1654:#define KVM_CREATE_GUEST_MEMFD\t_IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd)\ninclude/uapi/linux/kvm.h-1655-#define GUEST_MEMFD_FLAG_MMAP\t\t(1ULL \u003c\u003c 0)\n--\ninclude/uapi/linux/kvm.h-1657-\ninclude/uapi/linux/kvm.h:1658:struct kvm_create_guest_memfd {\ninclude/uapi/linux/kvm.h-1659-\t__u64 size;\n--\ntools/include/uapi/linux/kvm.h=38=struct kvm_userspace_memory_region2 {\n--\ntools/include/uapi/linux/kvm.h-43-\t__u64 userspace_addr;\ntools/include/uapi/linux/kvm.h:44:\t__u64 guest_memfd_offset;\ntools/include/uapi/linux/kvm.h:45:\t__u32 guest_memfd;\ntools/include/uapi/linux/kvm.h-46-\t__u32 pad1;\n--\ntools/include/uapi/linux/kvm.h=1635=struct kvm_memory_attributes {\n--\ntools/include/uapi/linux/kvm.h-1643-\ntools/include/uapi/linux/kvm.h:1644:#define KVM_CREATE_GUEST_MEMFD\t_IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd)\ntools/include/uapi/linux/kvm.h-1645-#define GUEST_MEMFD_FLAG_MMAP\t\t(1ULL \u003c\u003c 0)\n--\ntools/include/uapi/linux/kvm.h-1647-\ntools/include/uapi/linux/kvm.h:1648:struct kvm_create_guest_memfd {\ntools/include/uapi/linux/kvm.h-1649-\t__u64 size;\n--\ntools/testing/selftests/kvm/Makefile.kvm=157=TEST_GEN_PROGS_x86 += dirty_log_perf_test\ntools/testing/selftests/kvm/Makefile.kvm:158:TEST_GEN_PROGS_x86 += guest_memfd_test\ntools/testing/selftests/kvm/Makefile.kvm-159-TEST_GEN_PROGS_x86 += hardware_disable_test\n--\ntools/testing/selftests/kvm/Makefile.kvm=196=TEST_GEN_PROGS_arm64 += get-reg-list\ntools/testing/selftests/kvm/Makefile.kvm:197:TEST_GEN_PROGS_arm64 += guest_memfd_test\ntools/testing/selftests/kvm/Makefile.kvm-198-TEST_GEN_PROGS_arm64 += mmu_stress_test\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=42=static void test_mmap_cow(int fd, size_t size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-46-\tmem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c:47:\tTEST_ASSERT(mem == MAP_FAILED, \"Copy-on-write not allowed by guest_memfd.\");\ntools/testing/selftests/kvm/guest_memfd_test.c-48-}\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=174=static void test_collapse(int fd, u64 flags)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-182-\t/*\ntools/testing/selftests/kvm/guest_memfd_test.c:183:\t * To even reach the point where the guest_memfd folios will\ntools/testing/selftests/kvm/guest_memfd_test.c-184-\t * get collapsed, both the userspace address and the offset\ntools/testing/selftests/kvm/guest_memfd_test.c:185:\t * within the guest_memfd have to be aligned to pmd_size.\ntools/testing/selftests/kvm/guest_memfd_test.c-186-\t *\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-208-\t/*\ntools/testing/selftests/kvm/guest_memfd_test.c:209:\t * Advising the use of huge pages in guest_memfd should be\ntools/testing/selftests/kvm/guest_memfd_test.c-210-\t * fine...\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=348=static void test_invalid_binding(struct kvm_vm *vm, int fd, size_t size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-357-\ntools/testing/selftests/kvm/guest_memfd_test.c:358:static void test_create_guest_memfd_invalid_sizes(struct kvm_vm *vm,\ntools/testing/selftests/kvm/guest_memfd_test.c:359:\t\t\t\t\t\t u64 guest_memfd_flags)\ntools/testing/selftests/kvm/guest_memfd_test.c-360-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-364-\tfor (size = 1; size \u003c page_size; size++) {\ntools/testing/selftests/kvm/guest_memfd_test.c:365:\t\tfd = __vm_create_guest_memfd(vm, size, guest_memfd_flags);\ntools/testing/selftests/kvm/guest_memfd_test.c-366-\t\tTEST_ASSERT(fd \u003c 0 \u0026\u0026 errno == EINVAL,\ntools/testing/selftests/kvm/guest_memfd_test.c:367:\t\t\t \"guest_memfd() with non-page-aligned page size '0x%lx' should fail with EINVAL\",\ntools/testing/selftests/kvm/guest_memfd_test.c-368-\t\t\t size);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-371-\ntools/testing/selftests/kvm/guest_memfd_test.c:372:static void test_create_guest_memfd_multiple(struct kvm_vm *vm)\ntools/testing/selftests/kvm/guest_memfd_test.c-373-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-376-\ntools/testing/selftests/kvm/guest_memfd_test.c:377:\tfd1 = __vm_create_guest_memfd(vm, page_size, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-378-\tTEST_ASSERT(fd1 != -1, \"memfd creation should succeed\");\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-383-\ntools/testing/selftests/kvm/guest_memfd_test.c:384:\tfd2 = __vm_create_guest_memfd(vm, page_size * 2, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-385-\tTEST_ASSERT(fd2 != -1, \"memfd creation should succeed\");\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-399-\ntools/testing/selftests/kvm/guest_memfd_test.c:400:static void test_guest_memfd_flags(struct kvm_vm *vm)\ntools/testing/selftests/kvm/guest_memfd_test.c-401-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-406-\tfor (flag = BIT(0); flag; flag \u003c\u003c= 1) {\ntools/testing/selftests/kvm/guest_memfd_test.c:407:\t\tfd = __vm_create_guest_memfd(vm, page_size, flag);\ntools/testing/selftests/kvm/guest_memfd_test.c-408-\t\tif (flag \u0026 valid_flags) {\ntools/testing/selftests/kvm/guest_memfd_test.c-409-\t\t\tTEST_ASSERT(fd \u003e= 0,\ntools/testing/selftests/kvm/guest_memfd_test.c:410:\t\t\t\t \"guest_memfd() with flag '0x%lx' should succeed\",\ntools/testing/selftests/kvm/guest_memfd_test.c-411-\t\t\t\t flag);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-414-\t\t\tTEST_ASSERT(fd \u003c 0 \u0026\u0026 errno == EINVAL,\ntools/testing/selftests/kvm/guest_memfd_test.c:415:\t\t\t\t \"guest_memfd() with flag '0x%lx' should fail with EINVAL\",\ntools/testing/selftests/kvm/guest_memfd_test.c-416-\t\t\t\t flag);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=422=do {\t\t\t\t\t\t\t\t\t\\\ntools/testing/selftests/kvm/guest_memfd_test.c:423:\tint fd = vm_create_guest_memfd(__vm, __gmem_size, __flags);\t\\\ntools/testing/selftests/kvm/guest_memfd_test.c-424-\t\t\t\t\t\t\t\t\t\\\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-440-\ntools/testing/selftests/kvm/guest_memfd_test.c:441:static void __test_guest_memfd(struct kvm_vm *vm, u64 flags)\ntools/testing/selftests/kvm/guest_memfd_test.c-442-{\ntools/testing/selftests/kvm/guest_memfd_test.c:443:\ttest_create_guest_memfd_multiple(vm);\ntools/testing/selftests/kvm/guest_memfd_test.c:444:\ttest_create_guest_memfd_invalid_sizes(vm, flags);\ntools/testing/selftests/kvm/guest_memfd_test.c-445-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-471-\ntools/testing/selftests/kvm/guest_memfd_test.c:472:static void test_guest_memfd(unsigned long vm_type)\ntools/testing/selftests/kvm/guest_memfd_test.c-473-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-476-\ntools/testing/selftests/kvm/guest_memfd_test.c:477:\ttest_guest_memfd_flags(vm);\ntools/testing/selftests/kvm/guest_memfd_test.c-478-\ntools/testing/selftests/kvm/guest_memfd_test.c:479:\t__test_guest_memfd(vm, 0);\ntools/testing/selftests/kvm/guest_memfd_test.c-480-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-482-\tif (flags \u0026 GUEST_MEMFD_FLAG_MMAP)\ntools/testing/selftests/kvm/guest_memfd_test.c:483:\t\t__test_guest_memfd(vm, GUEST_MEMFD_FLAG_MMAP);\ntools/testing/selftests/kvm/guest_memfd_test.c-484-\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-486-\tif (flags \u0026 GUEST_MEMFD_FLAG_INIT_SHARED)\ntools/testing/selftests/kvm/guest_memfd_test.c:487:\t\t__test_guest_memfd(vm, GUEST_MEMFD_FLAG_MMAP |\ntools/testing/selftests/kvm/guest_memfd_test.c-488-\t\t\t\t GUEST_MEMFD_FLAG_INIT_SHARED);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=493=static void guest_code(u8 *mem, u64 size)\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-504-\ntools/testing/selftests/kvm/guest_memfd_test.c:505:static void test_guest_memfd_guest(void)\ntools/testing/selftests/kvm/guest_memfd_test.c-506-{\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-534-\t * Use the max of the host or guest page size for all operations, as\ntools/testing/selftests/kvm/guest_memfd_test.c:535:\t * KVM requires guest_memfd files and memslots to be sized to multiples\ntools/testing/selftests/kvm/guest_memfd_test.c-536-\t * of the host page size.\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-538-\tsize = max_t(size_t, vm-\u003epage_size, page_size);\ntools/testing/selftests/kvm/guest_memfd_test.c:539:\tfd = vm_create_guest_memfd(vm, size, GUEST_MEMFD_FLAG_MMAP |\ntools/testing/selftests/kvm/guest_memfd_test.c-540-\t\t\t\t\t GUEST_MEMFD_FLAG_INIT_SHARED);\n--\ntools/testing/selftests/kvm/guest_memfd_test.c=561=int main(int argc, char *argv[])\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-570-\t * Not all architectures support KVM_CAP_VM_TYPES. However, those that\ntools/testing/selftests/kvm/guest_memfd_test.c:571:\t * support guest_memfd have that support for the default VM type.\ntools/testing/selftests/kvm/guest_memfd_test.c-572-\t */\n--\ntools/testing/selftests/kvm/guest_memfd_test.c-577-\tfor_each_set_bit(vm_type, \u0026vm_types, BITS_PER_TYPE(vm_types))\ntools/testing/selftests/kvm/guest_memfd_test.c:578:\t\ttest_guest_memfd(vm_type);\ntools/testing/selftests/kvm/guest_memfd_test.c-579-\ntools/testing/selftests/kvm/guest_memfd_test.c:580:\ttest_guest_memfd_guest();\ntools/testing/selftests/kvm/guest_memfd_test.c-581-}\n--\ntools/testing/selftests/kvm/include/kvm_util.h=665=void vm_create_irqchip(struct kvm_vm *vm);\ntools/testing/selftests/kvm/include/kvm_util.h-666-\ntools/testing/selftests/kvm/include/kvm_util.h:667:static inline int __vm_create_guest_memfd(struct kvm_vm *vm, u64 size,\ntools/testing/selftests/kvm/include/kvm_util.h-668-\t\t\t\t\t u64 flags)\ntools/testing/selftests/kvm/include/kvm_util.h-669-{\ntools/testing/selftests/kvm/include/kvm_util.h:670:\tstruct kvm_create_guest_memfd guest_memfd = {\ntools/testing/selftests/kvm/include/kvm_util.h-671-\t\t.size = size,\n--\ntools/testing/selftests/kvm/include/kvm_util.h-674-\ntools/testing/selftests/kvm/include/kvm_util.h:675:\treturn __vm_ioctl(vm, KVM_CREATE_GUEST_MEMFD, \u0026guest_memfd);\ntools/testing/selftests/kvm/include/kvm_util.h-676-}\ntools/testing/selftests/kvm/include/kvm_util.h-677-\ntools/testing/selftests/kvm/include/kvm_util.h:678:static inline int vm_create_guest_memfd(struct kvm_vm *vm, u64 size,\ntools/testing/selftests/kvm/include/kvm_util.h-679-\t\t\t\t\tu64 flags)\ntools/testing/selftests/kvm/include/kvm_util.h-680-{\ntools/testing/selftests/kvm/include/kvm_util.h:681:\tint fd = __vm_create_guest_memfd(vm, size, flags);\ntools/testing/selftests/kvm/include/kvm_util.h-682-\n--\ntools/testing/selftests/kvm/include/kvm_util.h=691=void vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h-692-\t\t\t\tgpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/include/kvm_util.h:693:\t\t\t\tu32 guest_memfd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-694-int __vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h-695-\t\t\t\t gpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/include/kvm_util.h:696:\t\t\t\t u32 guest_memfd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-697-\n--\ntools/testing/selftests/kvm/include/kvm_util.h=701=void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,\ntools/testing/selftests/kvm/include/kvm_util.h-702-\t\tgpa_t gpa, u32 slot, u64 npages, u32 flags,\ntools/testing/selftests/kvm/include/kvm_util.h:703:\t\tint guest_memfd_fd, u64 guest_memfd_offset);\ntools/testing/selftests/kvm/include/kvm_util.h-704-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=438=void kvm_set_files_rlimit(u32 nr_vcpus)\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-469-\ntools/testing/selftests/kvm/lib/kvm_util.c:470:static bool is_guest_memfd_required(struct vm_shape shape)\ntools/testing/selftests/kvm/lib/kvm_util.c-471-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=479=struct kvm_vm *__vm_create(struct vm_shape shape, u32 nr_runnable_vcpus,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-499-\tflags = 0;\ntools/testing/selftests/kvm/lib/kvm_util.c:500:\tif (is_guest_memfd_required(shape))\ntools/testing/selftests/kvm/lib/kvm_util.c-501-\t\tflags |= KVM_MEM_GUEST_MEMFD;\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=804=static void __vm_mem_region_delete(struct kvm_vm *vm,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-818-\t}\ntools/testing/selftests/kvm/lib/kvm_util.c:819:\tif ((int)region-\u003eregion.guest_memfd \u003e= 0)\ntools/testing/selftests/kvm/lib/kvm_util.c:820:\t\tkvm_free_fd(region-\u003eregion.guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-821-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=947=int __vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c-948-\t\t\t\t gpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:949:\t\t\t\t u32 guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-950-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-956-\t\t.userspace_addr = (uintptr_t)hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:957:\t\t.guest_memfd = guest_memfd,\ntools/testing/selftests/kvm/lib/kvm_util.c:958:\t\t.guest_memfd_offset = guest_memfd_offset,\ntools/testing/selftests/kvm/lib/kvm_util.c-959-\t};\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=966=void vm_set_user_memory_region2(struct kvm_vm *vm, u32 slot, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c-967-\t\t\t\tgpa_t gpa, u64 size, void *hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:968:\t\t\t\tu32 guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-969-{\ntools/testing/selftests/kvm/lib/kvm_util.c-970-\tint ret = __vm_set_user_memory_region2(vm, slot, flags, gpa, size, hva,\ntools/testing/selftests/kvm/lib/kvm_util.c:971:\t\t\t\t\t guest_memfd, guest_memfd_offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-972-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=979=void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,\ntools/testing/selftests/kvm/lib/kvm_util.c-980-\t\tgpa_t gpa, u32 slot, u64 npages, u32 flags,\ntools/testing/selftests/kvm/lib/kvm_util.c:981:\t\tint guest_memfd, u64 guest_memfd_offset)\ntools/testing/selftests/kvm/lib/kvm_util.c-982-{\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1085-\tif (flags \u0026 KVM_MEM_GUEST_MEMFD) {\ntools/testing/selftests/kvm/lib/kvm_util.c:1086:\t\tif (guest_memfd \u003c 0) {\ntools/testing/selftests/kvm/lib/kvm_util.c:1087:\t\t\tu32 guest_memfd_flags = 0;\ntools/testing/selftests/kvm/lib/kvm_util.c:1088:\t\t\tTEST_ASSERT(!guest_memfd_offset,\ntools/testing/selftests/kvm/lib/kvm_util.c:1089:\t\t\t\t \"Offset must be zero when creating new guest_memfd\");\ntools/testing/selftests/kvm/lib/kvm_util.c:1090:\t\t\tguest_memfd = vm_create_guest_memfd(vm, mem_size, guest_memfd_flags);\ntools/testing/selftests/kvm/lib/kvm_util.c-1091-\t\t} else {\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1097-\t\t\t */\ntools/testing/selftests/kvm/lib/kvm_util.c:1098:\t\t\tguest_memfd = kvm_dup(guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-1099-\t\t}\ntools/testing/selftests/kvm/lib/kvm_util.c-1100-\ntools/testing/selftests/kvm/lib/kvm_util.c:1101:\t\tregion-\u003eregion.guest_memfd = guest_memfd;\ntools/testing/selftests/kvm/lib/kvm_util.c:1102:\t\tregion-\u003eregion.guest_memfd_offset = guest_memfd_offset;\ntools/testing/selftests/kvm/lib/kvm_util.c-1103-\t} else {\ntools/testing/selftests/kvm/lib/kvm_util.c:1104:\t\tregion-\u003eregion.guest_memfd = -1;\ntools/testing/selftests/kvm/lib/kvm_util.c-1105-\t}\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1119-\t\t\" slot: %u flags: 0x%x\\n\"\ntools/testing/selftests/kvm/lib/kvm_util.c:1120:\t\t\" guest_phys_addr: 0x%lx size: 0x%llx guest_memfd: %d\",\ntools/testing/selftests/kvm/lib/kvm_util.c-1121-\t\tret, errno, slot, flags, gpa, region-\u003eregion.memory_size,\ntools/testing/selftests/kvm/lib/kvm_util.c:1122:\t\tregion-\u003eregion.guest_memfd);\ntools/testing/selftests/kvm/lib/kvm_util.c-1123-\n--\ntools/testing/selftests/kvm/lib/kvm_util.c=1274=void vm_guest_mem_fallocate(struct kvm_vm *vm, u64 base, u64 size,\n--\ntools/testing/selftests/kvm/lib/kvm_util.c-1291-\t\toffset = gpa - region-\u003eregion.guest_phys_addr;\ntools/testing/selftests/kvm/lib/kvm_util.c:1292:\t\tfd_offset = region-\u003eregion.guest_memfd_offset + offset;\ntools/testing/selftests/kvm/lib/kvm_util.c-1293-\t\tlen = min_t(u64, end - gpa, region-\u003eregion.memory_size - offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-1294-\ntools/testing/selftests/kvm/lib/kvm_util.c:1295:\t\tret = fallocate(region-\u003eregion.guest_memfd, mode, fd_offset, len);\ntools/testing/selftests/kvm/lib/kvm_util.c-1296-\t\tTEST_ASSERT(!ret, \"fallocate() failed to %s at %lx (len = %lu), fd = %d, mode = %x, offset = %lx\",\ntools/testing/selftests/kvm/lib/kvm_util.c-1297-\t\t\t punch_hole ? \"punch hole\" : \"allocate\", gpa, len,\ntools/testing/selftests/kvm/lib/kvm_util.c:1298:\t\t\t region-\u003eregion.guest_memfd, mode, fd_offset);\ntools/testing/selftests/kvm/lib/kvm_util.c-1299-\t}\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=346=static void test_invalid_memory_region_flags(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-386-\tif (supported_flags \u0026 KVM_MEM_GUEST_MEMFD) {\ntools/testing/selftests/kvm/set_memory_region_test.c:387:\t\tint guest_memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-388-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-390-\t\t\t\t\t\t KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_GUEST_MEMFD,\ntools/testing/selftests/kvm/set_memory_region_test.c:391:\t\t\t\t\t\t 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-392-\t\tTEST_ASSERT(r \u0026\u0026 errno == EINVAL,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-396-\t\t\t\t\t\t KVM_MEM_READONLY | KVM_MEM_GUEST_MEMFD,\ntools/testing/selftests/kvm/set_memory_region_test.c:397:\t\t\t\t\t\t 0, MEM_REGION_SIZE, NULL, guest_memfd, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-398-\t\tTEST_ASSERT(r \u0026\u0026 errno == EINVAL,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-400-\ntools/testing/selftests/kvm/set_memory_region_test.c:401:\t\tclose(guest_memfd);\ntools/testing/selftests/kvm/set_memory_region_test.c-402-\t}\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=409=static void test_add_max_memory_regions(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-457-#ifdef __x86_64__\ntools/testing/selftests/kvm/set_memory_region_test.c:458:static void test_invalid_guest_memfd(struct kvm_vm *vm, int memfd,\ntools/testing/selftests/kvm/set_memory_region_test.c-459-\t\t\t\t size_t offset, const char *msg)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=467=static void test_add_private_memory_region(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-475-\ntools/testing/selftests/kvm/set_memory_region_test.c:476:\ttest_invalid_guest_memfd(vm, vm-\u003ekvm_fd, 0, \"KVM fd should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c:477:\ttest_invalid_guest_memfd(vm, vm-\u003efd, 0, \"VM's fd should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-478-\ntools/testing/selftests/kvm/set_memory_region_test.c-479-\tmemfd = kvm_memfd_alloc(MEM_REGION_SIZE, false);\ntools/testing/selftests/kvm/set_memory_region_test.c:480:\ttest_invalid_guest_memfd(vm, memfd, 0, \"Regular memfd() should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-481-\tclose(memfd);\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-483-\tvm2 = vm_create_barebones_type(KVM_X86_SW_PROTECTED_VM);\ntools/testing/selftests/kvm/set_memory_region_test.c:484:\tmemfd = vm_create_guest_memfd(vm2, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c:485:\ttest_invalid_guest_memfd(vm, memfd, 0, \"Other VM's guest_memfd() should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-486-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-491-\ntools/testing/selftests/kvm/set_memory_region_test.c:492:\tmemfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-493-\tfor (i = 1; i \u003c PAGE_SIZE; i++)\ntools/testing/selftests/kvm/set_memory_region_test.c:494:\t\ttest_invalid_guest_memfd(vm, memfd, i, \"Unaligned offset should fail\");\ntools/testing/selftests/kvm/set_memory_region_test.c-495-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c=503=static void test_add_overlapping_private_memory_regions(void)\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-512-\ntools/testing/selftests/kvm/set_memory_region_test.c:513:\tmemfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE * 5, 0);\ntools/testing/selftests/kvm/set_memory_region_test.c-514-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-523-\t * Delete the first memslot, and then attempt to recreate it except\ntools/testing/selftests/kvm/set_memory_region_test.c:524:\t * with a \"bad\" offset that results in overlap in the guest_memfd().\ntools/testing/selftests/kvm/set_memory_region_test.c-525-\t */\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-529-\t/*\ntools/testing/selftests/kvm/set_memory_region_test.c:530:\t * Verify that overlap in the guest_memfd bindings (i.e. in guest_memfd\ntools/testing/selftests/kvm/set_memory_region_test.c-531-\t * file offsets), but _not_ in the GPA space, fails with -EEXIST.\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-537-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:538:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-539-\ntools/testing/selftests/kvm/set_memory_region_test.c:540:\t/* And now the back half of the other slot's guest_memfd binding. */\ntools/testing/selftests/kvm/set_memory_region_test.c-541-\tr = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_GUEST_MEMFD,\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-545-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:546:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-547-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-557-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:558:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-559-\n--\ntools/testing/selftests/kvm/set_memory_region_test.c-565-\tTEST_ASSERT(r == -1 \u0026\u0026 errno == EEXIST,\ntools/testing/selftests/kvm/set_memory_region_test.c:566:\t\t \"Overlapping guest_memfd() bindings should fail with EEXIST\");\ntools/testing/selftests/kvm/set_memory_region_test.c-567-\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=230=static void guest_test_punch_hole(u64 base_gpa, bool precise)\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-236-\t * Convert the entire range to private, this testcase is all about\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:237:\t * punching holes in guest_memfd, i.e. shared mappings aren't needed.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-238-\t */\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=271=static void guest_code(u64 base_gpa)\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-274-\t * Run the conversion test twice, with and without doing fallocate() on\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:275:\t * the guest_memfd backing when converting between shared and private.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-276-\t */\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-280-\t/*\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:281:\t * Run the PUNCH_HOLE test twice too, once with the entire guest_memfd\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-282-\t * faulted in, once with only the target range faulted in.\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c=369=static void test_mem_conversions(enum vm_mem_backing_src_type src_type, u32 nr_vcpus,\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-396-\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:397:\tmemfd = vm_create_guest_memfd(vm, memfd_size, 0);\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-398-\n--\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-425-\t/*\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:426:\t * Allocate and free memory from the guest_memfd after closing the VM\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:427:\t * fd. The guest_memfd is gifted a reference to its owning VM, i.e.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-428-\t * should prevent the VM from being fully destroyed until the last\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c:429:\t * reference to the guest_memfd is also put.\ntools/testing/selftests/kvm/x86/private_mem_conversions_test.c-430-\t */\n\n"
} |
| 19/2 | 2026/06/27 01:50 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 50986 output: 203 thoughts: 799 Thoughts: **My Analysis of the KVM Patch's Fuzzing Potential**
Alright, let's break this down. First, `guest_memfd` – that's just a KVM feature, nothing specific to this particular patch. So, the key config to target here appears to be `KVM_AMD_SEV`. And yes, `KVM_AMD_SEV` is a simple boolean configuration option. Good. It looks like it selects `HAVE_KVM_ARCH_GMEM_INVALIDATE`, which sounds promising.
Now, let's scrutinize the `FocusSymbols`. We have `kvm_arch_flush_shadow_memslot`, `__kvm_mmu_zap_all_fast_front_half`, `__kvm_mmu_zap_all_fast_back_half`, `sev_snp_init_protected_guest_state`, `sev_snp_reload_vmsa`, `sev_gmem_invalidate_range`, and `sev_gmem_free_folio`.
Wait, I need to include `__sev_snp_reload_vmsa` because it's a function.
Okay, let's see which of these are reachable regardless of SEV being enabled. `kvm_arch_flush_shadow_memslot` is called during memslot movement or deletion, so that's core functionality. The zap functions, `__kvm_mmu_zap_all_fast_front_half` and `__kvm_mmu_zap_all_fast_back_half`, are reachable too if `kvm_memslot_flush_zap_all(kvm)` is true. However, `sev_snp_init_protected_guest_state` and `sev_snp_reload_vmsa` seem SEV-SNP specific. Similarly, `sev_gmem_invalidate_range` relies on `____sev_snp_guest(kvm)` and `sev_gmem_free_folio` checks `cc_platform_has(CC_ATTR_HOST_SEV_SNP)`, confirming their SEV-SNP exclusivity.
So, the conclusion is clear: this patch is touching both core KVM MMU logic and also injecting SEV-SNP specific code. That's a perfect combination for fuzzing. We have changes related to both fundamental memory management (memslot flushing, and zap functions) and the new SEV-SNP behavior (VMSA reloading, and protected guest state initialisation).
Let's summarize this clearly:
* **WorthFuzzing: True**
* **EnableConfigs: \["KVM\_AMD\_SEV"\]**
* **FocusSymbols:**
* `kvm_arch_flush_shadow_memslot`
* `__kvm_mmu_zap_all_fast_front_half`
* `__kvm_mmu_zap_all_fast_back_half`
* `sev_snp_init_protected_guest_state`
* `__sev_snp_reload_vmsa`
* `sev_gmem_invalidate_range`
* `sev_gmem_free_folio`
* **Reasoning:** "The patch modifies core KVM MMU logic for flushing shadow memslots and introduces new SEV-SNP specific logic for handling guest\_memfd invalidations and VMSA reloading. These changes are reachable via KVM ioctls and guest execution."
Just to be absolutely sure, let's rule out any other relevant configs. `KVM` is far too broad, `KVM_AMD` is too generic. Yes, `KVM_AMD_SEV` looks like the perfect and only necessary config. Okay, I'm ready to commit to this. Let's call `set-results`.
|
| 20/2 | 2026/06/27 01:50 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"KVM_AMD_SEV"
],
"FocusSymbols": [
"kvm_arch_flush_shadow_memslot",
"__kvm_mmu_zap_all_fast_front_half",
"__kvm_mmu_zap_all_fast_back_half",
"sev_snp_init_protected_guest_state",
"__sev_snp_reload_vmsa",
"sev_snp_reload_vmsa",
"sev_gmem_invalidate_range",
"sev_gmem_free_folio"
],
"Reasoning": "The patch modifies core KVM MMU logic for flushing shadow memslots and introduces new SEV-SNP specific logic for handling guest_memfd invalidations and VMSA reloading. These changes are reachable via KVM ioctls and guest execution.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"KVM_AMD_SEV"
],
"FocusSymbols": [
"kvm_arch_flush_shadow_memslot",
"__kvm_mmu_zap_all_fast_front_half",
"__kvm_mmu_zap_all_fast_back_half",
"sev_snp_init_protected_guest_state",
"__sev_snp_reload_vmsa",
"sev_snp_reload_vmsa",
"sev_gmem_invalidate_range",
"sev_gmem_free_folio"
],
"Reasoning": "The patch modifies core KVM MMU logic for flushing shadow memslots and introduces new SEV-SNP specific logic for handling guest_memfd invalidations and VMSA reloading. These changes are reachable via KVM ioctls and guest execution.",
"WorthFuzzing": true
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|