| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/08/05 21:19 | flow | patch-triage |
9mArgs:null Results: {
"EnableConfigs": [
"KVM",
"KVM_XEN"
],
"FocusSymbols": [
"kvm_gpc_refresh",
"kvm_gpc_activate",
"kvm_gpc_deactivate",
"gfn_to_pfn_cache_invalidate_start",
"kvm_xen_set_evtchn_fast",
"kvm_xen_update_runstate",
"kvm_xen_vcpu_set_attr",
"kvm_xen_hvm_set_attr",
"kvm_xen_inject_pending_events",
"kvm_xen_hypercall",
"__kvm_xen_has_interrupt",
"kvm_guest_time_update"
],
"Reasoning": "The patch replaces rwlock_t with RCU-based synchronization for gfn_to_pfn_cache (GPC) in KVM, which is used for guest-to-host page caching (e.g., steal time, Xen shared info). This is a significant functional change in core KVM logic and should be fuzzed.",
"WorthFuzzing": true
} |
| 1/1 | 2026/08/05 21:19 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 18dbcd239103c347388dd02c52495279abea46c1\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Aug 5 21:19:37 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h\nindex 283847619ff88..93514cb1f2f70 100644\n--- a/arch/x86/include/asm/kvm_host.h\n+++ b/arch/x86/include/asm/kvm_host.h\n@@ -873,7 +873,7 @@ struct kvm_vcpu_arch {\n \t\tu8 preempted;\n \t\tu64 msr_val;\n \t\tu64 last_steal;\n-\t\tstruct gfn_to_hva_cache cache;\n+\t\tstruct gfn_to_pfn_cache cache;\n \t} st;\n \n \tu64 l1_tsc_offset;\ndiff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c\nindex 66fa7140d65d9..37d79d84e2f89 100644\n--- a/arch/x86/kvm/msrs.c\n+++ b/arch/x86/kvm/msrs.c\n@@ -1717,8 +1717,13 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)\n \n \t\tvcpu-\u003earch.st.msr_val = data;\n \n-\t\tif (!(data \u0026 KVM_MSR_ENABLED))\n+\t\tif (!(data \u0026 KVM_MSR_ENABLED)) {\n+\t\t\tkvm_gpc_deactivate(\u0026vcpu-\u003earch.st.cache);\n \t\t\tbreak;\n+\t\t}\n+\n+\t\tkvm_gpc_activate(\u0026vcpu-\u003earch.st.cache, data \u0026 ~KVM_MSR_ENABLED,\n+\t\t\t\t sizeof(struct kvm_steal_time));\n \n \t\tkvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);\n \ndiff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c\nindex d94b59140c452..4a5753623909d 100644\n--- a/arch/x86/kvm/x86.c\n+++ b/arch/x86/kvm/x86.c\n@@ -1719,18 +1719,17 @@ static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,\n {\n \tstruct pvclock_vcpu_time_info *guest_hv_clock;\n \tstruct pvclock_vcpu_time_info hv_clock;\n-\tunsigned long flags;\n \n \tmemcpy(\u0026hv_clock, ref_hv_clock, sizeof(hv_clock));\n \n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc, offset + sizeof(*guest_hv_clock))) {\n-\t\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_unlock();\n \n \t\tif (kvm_gpc_refresh(gpc, offset + sizeof(*guest_hv_clock)))\n \t\t\treturn;\n \n-\t\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_lock();\n \t}\n \n \tguest_hv_clock = (void *)(gpc-\u003ekhva + offset);\n@@ -1755,7 +1754,7 @@ static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,\n \tguest_hv_clock-\u003eversion = ++hv_clock.version;\n \n \tkvm_gpc_mark_dirty_in_slot(gpc);\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\trcu_read_unlock();\n \n \ttrace_kvm_pvclock_update(vcpu-\u003evcpu_id, \u0026hv_clock);\n }\n@@ -2047,10 +2046,8 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_service_local_tlb_flush_requests);\n \n static void record_steal_time(struct kvm_vcpu *vcpu)\n {\n-\tstruct gfn_to_hva_cache *ghc = \u0026vcpu-\u003earch.st.cache;\n-\tstruct kvm_steal_time __user *st;\n-\tstruct kvm_memslots *slots;\n-\tgpa_t gpa = vcpu-\u003earch.st.msr_val \u0026 KVM_STEAL_VALID_BITS;\n+\tstruct gfn_to_pfn_cache *gpc = \u0026vcpu-\u003earch.st.cache;\n+\tstruct kvm_steal_time *st;\n \tu64 steal;\n \tu32 version;\n \n@@ -2065,42 +2062,27 @@ static void record_steal_time(struct kvm_vcpu *vcpu)\n \tif (WARN_ON_ONCE(current-\u003emm != vcpu-\u003ekvm-\u003emm))\n \t\treturn;\n \n-\tslots = kvm_memslots(vcpu-\u003ekvm);\n+\t/* We rely on the fact that it fits in a single page. */\n+\tBUILD_BUG_ON((sizeof(*st) - 1) \u0026 KVM_STEAL_VALID_BITS);\n \n-\tif (unlikely(slots-\u003egeneration != ghc-\u003egeneration ||\n-\t\t gpa != ghc-\u003egpa ||\n-\t\t kvm_is_error_hva(ghc-\u003ehva) || !ghc-\u003ememslot)) {\n-\t\t/* We rely on the fact that it fits in a single page. */\n-\t\tBUILD_BUG_ON((sizeof(*st) - 1) \u0026 KVM_STEAL_VALID_BITS);\n+\trcu_read_lock();\n+\twhile (!kvm_gpc_check(gpc, sizeof(*st))) {\n+\t\trcu_read_unlock();\n \n-\t\tif (kvm_gfn_to_hva_cache_init(vcpu-\u003ekvm, ghc, gpa, sizeof(*st)) ||\n-\t\t kvm_is_error_hva(ghc-\u003ehva) || !ghc-\u003ememslot)\n+\t\tif (kvm_gpc_refresh(gpc, sizeof(*st)))\n \t\t\treturn;\n+\n+\t\trcu_read_lock();\n \t}\n \n-\tst = (struct kvm_steal_time __user *)ghc-\u003ehva;\n+\tst = gpc-\u003ekhva;\n+\n \t/*\n \t * Doing a TLB flush here, on the guest's behalf, can avoid\n \t * expensive IPIs.\n \t */\n \tif (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) {\n-\t\tu8 st_preempted = 0;\n-\t\tint err = -EFAULT;\n-\n-\t\tif (!user_access_begin(st, sizeof(*st)))\n-\t\t\treturn;\n-\n-\t\tasm volatile(\"1: xchgb %0, %2\\n\"\n-\t\t\t \"xor %1, %1\\n\"\n-\t\t\t \"2:\\n\"\n-\t\t\t _ASM_EXTABLE_UA(1b, 2b)\n-\t\t\t : \"+q\" (st_preempted),\n-\t\t\t \"+\u0026r\" (err),\n-\t\t\t \"+m\" (st-\u003epreempted));\n-\t\tif (err)\n-\t\t\tgoto out;\n-\n-\t\tuser_access_end();\n+\t\tu8 st_preempted = xchg(\u0026st-\u003epreempted, 0);\n \n \t\tvcpu-\u003earch.st.preempted = 0;\n \n@@ -2108,39 +2090,33 @@ static void record_steal_time(struct kvm_vcpu *vcpu)\n \t\t\t\t st_preempted \u0026 KVM_VCPU_FLUSH_TLB);\n \t\tif (st_preempted \u0026 KVM_VCPU_FLUSH_TLB)\n \t\t\tkvm_vcpu_flush_tlb_guest(vcpu);\n-\n-\t\tif (!user_access_begin(st, sizeof(*st)))\n-\t\t\tgoto dirty;\n \t} else {\n-\t\tif (!user_access_begin(st, sizeof(*st)))\n-\t\t\treturn;\n-\n-\t\tunsafe_put_user(0, \u0026st-\u003epreempted, out);\n+\t\tWRITE_ONCE(st-\u003epreempted, 0);\n \t\tvcpu-\u003earch.st.preempted = 0;\n \t}\n \n-\tunsafe_get_user(version, \u0026st-\u003eversion, out);\n+\tversion = READ_ONCE(st-\u003eversion);\n \tif (version \u0026 1)\n \t\tversion += 1; /* first time write, random junk */\n \n \tversion += 1;\n-\tunsafe_put_user(version, \u0026st-\u003eversion, out);\n+\tWRITE_ONCE(st-\u003eversion, version);\n \n \tsmp_wmb();\n \n-\tunsafe_get_user(steal, \u0026st-\u003esteal, out);\n+\tsteal = READ_ONCE(st-\u003esteal);\n \tsteal += current-\u003esched_info.run_delay -\n \t\tvcpu-\u003earch.st.last_steal;\n \tvcpu-\u003earch.st.last_steal = current-\u003esched_info.run_delay;\n-\tunsafe_put_user(steal, \u0026st-\u003esteal, out);\n+\tWRITE_ONCE(st-\u003esteal, steal);\n+\n+\tsmp_wmb();\n \n \tversion += 1;\n-\tunsafe_put_user(version, \u0026st-\u003eversion, out);\n+\tWRITE_ONCE(st-\u003eversion, version);\n \n- out:\n-\tuser_access_end();\n- dirty:\n-\tmark_page_dirty_in_slot(vcpu-\u003ekvm, ghc-\u003ememslot, gpa_to_gfn(ghc-\u003egpa));\n+\tkvm_gpc_mark_dirty_in_slot(gpc);\n+\trcu_read_unlock();\n }\n \n static inline bool kvm_can_mwait_in_guest(void)\n@@ -2614,11 +2590,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)\n \n static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)\n {\n-\tstruct gfn_to_hva_cache *ghc = \u0026vcpu-\u003earch.st.cache;\n-\tstruct kvm_steal_time __user *st;\n-\tstruct kvm_memslots *slots;\n-\tstatic const u8 preempted = KVM_VCPU_PREEMPTED;\n-\tgpa_t gpa = vcpu-\u003earch.st.msr_val \u0026 KVM_STEAL_VALID_BITS;\n+\tstruct gfn_to_pfn_cache *gpc = \u0026vcpu-\u003earch.st.cache;\n+\tstruct kvm_steal_time *st;\n \n \t/*\n \t * The vCPU can be marked preempted if and only if the VM-Exit was on\n@@ -2643,20 +2616,32 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)\n \tif (unlikely(current-\u003emm != vcpu-\u003ekvm-\u003emm))\n \t\treturn;\n \n-\tslots = kvm_memslots(vcpu-\u003ekvm);\n-\n-\tif (unlikely(slots-\u003egeneration != ghc-\u003egeneration ||\n-\t\t gpa != ghc-\u003egpa ||\n-\t\t kvm_is_error_hva(ghc-\u003ehva) || !ghc-\u003ememslot))\n-\t\treturn;\n-\n-\tst = (struct kvm_steal_time __user *)ghc-\u003ehva;\n-\tBUILD_BUG_ON(sizeof(st-\u003epreempted) != sizeof(preempted));\n-\n-\tif (!copy_to_user_nofault(\u0026st-\u003epreempted, \u0026preempted, sizeof(preempted)))\n+\t/*\n+\t * This is called from the scheduler path (via kvm_sched_out), so\n+\t * the cache cannot be refreshed here. Setting 'preempted' is\n+\t * best-effort anyway; the old HVA-based code used\n+\t * copy_to_user_nofault(), which could also silently fail. If the\n+\t * cache is invalid, it will be refreshed from task context by\n+\t * record_steal_time() before the vCPU next enters the guest, since\n+\t * kvm_arch_vcpu_load() unconditionally raises KVM_REQ_STEAL_UPDATE.\n+\t */\n+\trcu_read_lock();\n+\tif (kvm_gpc_check(gpc, sizeof(*st))) {\n+\t\tst = gpc-\u003ekhva;\n+\t\tWRITE_ONCE(st-\u003epreempted, KVM_VCPU_PREEMPTED);\n \t\tvcpu-\u003earch.st.preempted = KVM_VCPU_PREEMPTED;\n \n-\tmark_page_dirty_in_slot(vcpu-\u003ekvm, ghc-\u003ememslot, gpa_to_gfn(ghc-\u003egpa));\n+\t\tkvm_gpc_mark_dirty_in_slot(gpc);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+static void kvm_steal_time_reset(struct kvm_vcpu *vcpu)\n+{\n+\tkvm_gpc_deactivate(\u0026vcpu-\u003earch.st.cache);\n+\tvcpu-\u003earch.st.preempted = 0;\n+\tvcpu-\u003earch.st.msr_val = 0;\n+\tvcpu-\u003earch.st.last_steal = 0;\n }\n \n void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)\n@@ -9348,6 +9333,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)\n \n \tkvm_gpc_init(\u0026vcpu-\u003earch.pv_time, vcpu-\u003ekvm);\n \n+\tkvm_gpc_init(\u0026vcpu-\u003earch.st.cache, vcpu-\u003ekvm);\n+\n \tif (!irqchip_in_kernel(vcpu-\u003ekvm) || kvm_vcpu_is_reset_bsp(vcpu))\n \t\tkvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);\n \telse\n@@ -9455,6 +9442,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)\n \tkvm_clear_async_pf_completion_queue(vcpu);\n \tkvm_mmu_unload(vcpu);\n \n+\tkvm_steal_time_reset(vcpu);\n+\n \tkvmclock_reset(vcpu);\n \n \tfor_each_possible_cpu(cpu)\n@@ -9575,7 +9564,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)\n \tkvm_make_request(KVM_REQ_EVENT, vcpu);\n \tvcpu-\u003earch.apf.msr_en_val = 0;\n \tvcpu-\u003earch.apf.msr_int_val = 0;\n-\tvcpu-\u003earch.st.msr_val = 0;\n+\n+\tkvm_steal_time_reset(vcpu);\n \n \tkvmclock_reset(vcpu);\n \ndiff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c\nindex f2c6757fc1faf..9f1a9c93442d7 100644\n--- a/arch/x86/kvm/xen.c\n+++ b/arch/x86/kvm/xen.c\n@@ -46,15 +46,15 @@ static int kvm_xen_shared_info_init(struct kvm *kvm)\n \tint ret = 0;\n \tint idx = srcu_read_lock(\u0026kvm-\u003esrcu);\n \n-\tread_lock_irq(\u0026gpc-\u003elock);\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc, PAGE_SIZE)) {\n-\t\tread_unlock_irq(\u0026gpc-\u003elock);\n+\t\trcu_read_unlock();\n \n \t\tret = kvm_gpc_refresh(gpc, PAGE_SIZE);\n \t\tif (ret)\n \t\t\tgoto out;\n \n-\t\tread_lock_irq(\u0026gpc-\u003elock);\n+\t\trcu_read_lock();\n \t}\n \n \t/*\n@@ -97,7 +97,7 @@ static int kvm_xen_shared_info_init(struct kvm *kvm)\n \tsmp_wmb();\n \n \twc-\u003eversion = wc_version + 1;\n-\tread_unlock_irq(\u0026gpc-\u003elock);\n+\trcu_read_unlock();\n \n out:\n \tsrcu_read_unlock(\u0026kvm-\u003esrcu, idx);\n@@ -154,22 +154,21 @@ static int xen_get_guest_pvclock(struct kvm_vcpu *vcpu,\n \t\t\t\t struct gfn_to_pfn_cache *gpc,\n \t\t\t\t unsigned int offset)\n {\n-\tunsigned long flags;\n \tint r;\n \n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc, offset + sizeof(*hv_clock))) {\n-\t\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_unlock();\n \n \t\tr = kvm_gpc_refresh(gpc, offset + sizeof(*hv_clock));\n \t\tif (r)\n \t\t\treturn r;\n \n-\t\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_lock();\n \t}\n \n \tmemcpy(hv_clock, gpc-\u003ekhva + offset, sizeof(*hv_clock));\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\trcu_read_unlock();\n \n \t/*\n \t * Sanity check TSC shift+multiplier to verify the guest's view of time\n@@ -324,7 +323,6 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\n \tstruct gfn_to_pfn_cache *gpc2 = \u0026vx-\u003erunstate2_cache;\n \tsize_t user_len, user_len1, user_len2;\n \tstruct vcpu_runstate_info rs;\n-\tunsigned long flags;\n \tsize_t times_ofs;\n \tuint8_t *update_bit = NULL;\n \tuint64_t entry_time;\n@@ -416,20 +414,12 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\n \n retry:\n \t/*\n-\t * Attempt to obtain the GPC lock on *both* (if there are two)\n-\t * gfn_to_pfn caches that cover the region.\n+\t * Check *both* (if there are two) gfn_to_pfn caches that cover\n+\t * the region, under a single RCU read-side critical section.\n \t */\n-\tif (atomic) {\n-\t\tlocal_irq_save(flags);\n-\t\tif (!read_trylock(\u0026gpc1-\u003elock)) {\n-\t\t\tlocal_irq_restore(flags);\n-\t\t\treturn;\n-\t\t}\n-\t} else {\n-\t\tread_lock_irqsave(\u0026gpc1-\u003elock, flags);\n-\t}\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc1, user_len1)) {\n-\t\tread_unlock_irqrestore(\u0026gpc1-\u003elock, flags);\n+\t\trcu_read_unlock();\n \n \t\t/* When invoked from kvm_sched_out() we cannot sleep */\n \t\tif (atomic)\n@@ -438,7 +428,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\n \t\tif (kvm_gpc_refresh(gpc1, user_len1))\n \t\t\treturn;\n \n-\t\tread_lock_irqsave(\u0026gpc1-\u003elock, flags);\n+\t\trcu_read_lock();\n \t}\n \n \tif (likely(!user_len2)) {\n@@ -458,24 +448,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\n \t} else {\n \t\t/*\n \t\t * The guest's runstate_info is split across two pages and we\n-\t\t * need to hold and validate both GPCs simultaneously. We can\n-\t\t * declare a lock ordering GPC1 \u003e GPC2 because nothing else\n-\t\t * takes them more than one at a time. Set a subclass on the\n-\t\t * gpc1 lock to make lockdep shut up about it.\n+\t\t * need to validate both GPCs simultaneously. They are both\n+\t\t * covered by the single RCU read-side critical section above.\n \t\t */\n-\t\tlock_set_subclass(\u0026gpc1-\u003elock.dep_map, 1, _THIS_IP_);\n-\t\tif (atomic) {\n-\t\t\tif (!read_trylock(\u0026gpc2-\u003elock)) {\n-\t\t\t\tread_unlock_irqrestore(\u0026gpc1-\u003elock, flags);\n-\t\t\t\treturn;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tread_lock(\u0026gpc2-\u003elock);\n-\t\t}\n-\n \t\tif (!kvm_gpc_check(gpc2, user_len2)) {\n-\t\t\tread_unlock(\u0026gpc2-\u003elock);\n-\t\t\tread_unlock_irqrestore(\u0026gpc1-\u003elock, flags);\n+\t\t\trcu_read_unlock();\n \n \t\t\t/* When invoked from kvm_sched_out() we cannot sleep */\n \t\t\tif (atomic)\n@@ -574,13 +551,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\n \t\tsmp_wmb();\n \t}\n \n-\tif (user_len2) {\n+\tif (user_len2)\n \t\tkvm_gpc_mark_dirty_in_slot(gpc2);\n-\t\tread_unlock(\u0026gpc2-\u003elock);\n-\t}\n \n \tkvm_gpc_mark_dirty_in_slot(gpc1);\n-\tread_unlock_irqrestore(\u0026gpc1-\u003elock, flags);\n+\trcu_read_unlock();\n }\n \n void kvm_xen_update_runstate(struct kvm_vcpu *v, int state)\n@@ -639,7 +614,6 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\n {\n \tunsigned long evtchn_pending_sel = READ_ONCE(v-\u003earch.xen.evtchn_pending_sel);\n \tstruct gfn_to_pfn_cache *gpc = \u0026v-\u003earch.xen.vcpu_info_cache;\n-\tunsigned long flags;\n \n \tif (!evtchn_pending_sel)\n \t\treturn;\n@@ -649,14 +623,14 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\n \t * does anyway. Page it in and retry the instruction. We're just a\n \t * little more honest about it.\n \t */\n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {\n-\t\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_unlock();\n \n \t\tif (kvm_gpc_refresh(gpc, sizeof(struct vcpu_info)))\n \t\t\treturn;\n \n-\t\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_lock();\n \t}\n \n \t/* Now gpc-\u003ekhva is a valid kernel address for the vcpu_info */\n@@ -685,8 +659,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\n \t\tWRITE_ONCE(vi-\u003eevtchn_upcall_pending, 1);\n \t}\n \n-\tkvm_gpc_mark_dirty_in_slot(gpc);\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\trcu_read_unlock();\n \n \t/* For the per-vCPU lapic vector, deliver it as MSI. */\n \tif (v-\u003earch.xen.upcall_vector)\n@@ -696,7 +669,6 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\n int __kvm_xen_has_interrupt(struct kvm_vcpu *v)\n {\n \tstruct gfn_to_pfn_cache *gpc = \u0026v-\u003earch.xen.vcpu_info_cache;\n-\tunsigned long flags;\n \tu8 rc = 0;\n \n \t/*\n@@ -712,9 +684,9 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)\n \tBUILD_BUG_ON(sizeof(rc) !=\n \t\t sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending));\n \n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \twhile (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {\n-\t\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_unlock();\n \n \t\t/*\n \t\t * This function gets called from kvm_vcpu_block() after setting the\n@@ -734,11 +706,11 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)\n \t\t\t */\n \t\t\treturn 0;\n \t\t}\n-\t\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\t\trcu_read_lock();\n \t}\n \n \trc = ((struct vcpu_info *)gpc-\u003ekhva)-\u003eevtchn_upcall_pending;\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\trcu_read_unlock();\n \treturn rc;\n }\n \n@@ -1437,12 +1409,11 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,\n \tstruct kvm *kvm = vcpu-\u003ekvm;\n \tstruct gfn_to_pfn_cache *gpc = \u0026kvm-\u003earch.xen.shinfo_cache;\n \tunsigned long *pending_bits;\n-\tunsigned long flags;\n \tbool ret = true;\n \tint idx, i;\n \n \tidx = srcu_read_lock(\u0026kvm-\u003esrcu);\n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \tif (!kvm_gpc_check(gpc, PAGE_SIZE))\n \t\tgoto out_rcu;\n \n@@ -1463,7 +1434,7 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,\n \t}\n \n out_rcu:\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n+\trcu_read_unlock();\n \tsrcu_read_unlock(\u0026kvm-\u003esrcu, idx);\n \n \treturn ret;\n@@ -1787,6 +1758,67 @@ static void kvm_xen_check_poller(struct kvm_vcpu *vcpu, int port)\n \t}\n }\n \n+/* Called with kvm-\u003esrcu held, as kvm_gpc_check() consults the memslots. */\n+static void __kvm_xen_set_evtchn_fast(struct kvm_vcpu *vcpu, int port_word_bit)\n+{\n+\tstruct gfn_to_pfn_cache *gpc = \u0026vcpu-\u003earch.xen.vcpu_info_cache;\n+\tbool kick_vcpu = false;\n+\n+\t/* Now switch to the vCPU's vcpu_info to set the index and pending_sel */\n+\trcu_read_lock();\n+\tif (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {\n+\t\t/*\n+\t\t * Could not access the vcpu_info. Set the bit in-kernel and\n+\t\t * prod the vCPU to deliver it for itself.\n+\t\t */\n+\t\tif (!test_and_set_bit(port_word_bit, \u0026vcpu-\u003earch.xen.evtchn_pending_sel))\n+\t\t\tkick_vcpu = true;\n+\t\tgoto out_unlock;\n+\t}\n+\n+\tif (IS_ENABLED(CONFIG_64BIT) \u0026\u0026 vcpu-\u003ekvm-\u003earch.xen.long_mode) {\n+\t\tstruct vcpu_info *vcpu_info = gpc-\u003ekhva;\n+\n+\t\tif (!test_and_set_bit(port_word_bit, \u0026vcpu_info-\u003eevtchn_pending_sel)) {\n+\t\t\tWRITE_ONCE(vcpu_info-\u003eevtchn_upcall_pending, 1);\n+\t\t\tkick_vcpu = true;\n+\t\t}\n+\t} else {\n+\t\tstruct compat_vcpu_info *vcpu_info = gpc-\u003ekhva;\n+\n+\t\tif (!test_and_set_bit(port_word_bit,\n+\t\t\t\t (unsigned long *)\u0026vcpu_info-\u003eevtchn_pending_sel)) {\n+\t\t\tWRITE_ONCE(vcpu_info-\u003eevtchn_upcall_pending, 1);\n+\t\t\tkick_vcpu = true;\n+\t\t}\n+\t}\n+\n+out_unlock:\n+\trcu_read_unlock();\n+\n+\t/*\n+\t * Deliver the upcall or kick the vCPU only after dropping the RCU\n+\t * read lock. Both paths end up in kvm_vcpu_kick(), and the MSI\n+\t * delivery also walks the APIC map and takes APIC locks; none of\n+\t * that wants to be nested inside the GPC read-side critical\n+\t * section, which must be no longer than the accesses to gpc-\u003ekhva\n+\t * above. Invalidation waits for a grace period, so holding the\n+\t * read lock across the kick would extend how long a memory\n+\t * invalidation is blocked.\n+\t */\n+\tif (!kick_vcpu)\n+\t\treturn;\n+\n+\t/* For the per-vCPU lapic vector, deliver it as MSI. */\n+\tif (vcpu-\u003earch.xen.upcall_vector) {\n+\t\tkvm_xen_inject_vcpu_vector(vcpu);\n+\t\treturn;\n+\t}\n+\n+\tkvm_make_request(KVM_REQ_UNBLOCK, vcpu);\n+\tkvm_vcpu_kick(vcpu);\n+}\n+\n /*\n * The return value from this function is propagated to kvm_set_irq() API,\n * so it returns:\n@@ -1802,9 +1834,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)\n \tstruct gfn_to_pfn_cache *gpc = \u0026kvm-\u003earch.xen.shinfo_cache;\n \tstruct kvm_vcpu *vcpu;\n \tunsigned long *pending_bits, *mask_bits;\n-\tunsigned long flags;\n \tint port_word_bit;\n-\tbool kick_vcpu = false;\n \tint vcpu_idx, idx, rc;\n \n \tvcpu_idx = READ_ONCE(xe-\u003evcpu_idx);\n@@ -1824,7 +1854,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)\n \n \tidx = srcu_read_lock(\u0026kvm-\u003esrcu);\n \n-\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n+\trcu_read_lock();\n \tif (!kvm_gpc_check(gpc, PAGE_SIZE))\n \t\tgoto out_rcu;\n \n@@ -1854,51 +1884,15 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)\n \t\tkvm_xen_check_poller(vcpu, xe-\u003eport);\n \t} else {\n \t\trc = 1; /* Delivered to the bitmap in shared_info. */\n-\t\t/* Now switch to the vCPU's vcpu_info to set the index and pending_sel */\n-\t\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n-\t\tgpc = \u0026vcpu-\u003earch.xen.vcpu_info_cache;\n-\n-\t\tread_lock_irqsave(\u0026gpc-\u003elock, flags);\n-\t\tif (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {\n-\t\t\t/*\n-\t\t\t * Could not access the vcpu_info. Set the bit in-kernel\n-\t\t\t * and prod the vCPU to deliver it for itself.\n-\t\t\t */\n-\t\t\tif (!test_and_set_bit(port_word_bit, \u0026vcpu-\u003earch.xen.evtchn_pending_sel))\n-\t\t\t\tkick_vcpu = true;\n-\t\t\tgoto out_rcu;\n-\t\t}\n-\n-\t\tif (IS_ENABLED(CONFIG_64BIT) \u0026\u0026 kvm-\u003earch.xen.long_mode) {\n-\t\t\tstruct vcpu_info *vcpu_info = gpc-\u003ekhva;\n-\t\t\tif (!test_and_set_bit(port_word_bit, \u0026vcpu_info-\u003eevtchn_pending_sel)) {\n-\t\t\t\tWRITE_ONCE(vcpu_info-\u003eevtchn_upcall_pending, 1);\n-\t\t\t\tkick_vcpu = true;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tstruct compat_vcpu_info *vcpu_info = gpc-\u003ekhva;\n-\t\t\tif (!test_and_set_bit(port_word_bit,\n-\t\t\t\t\t (unsigned long *)\u0026vcpu_info-\u003eevtchn_pending_sel)) {\n-\t\t\t\tWRITE_ONCE(vcpu_info-\u003eevtchn_upcall_pending, 1);\n-\t\t\t\tkick_vcpu = true;\n-\t\t\t}\n-\t\t}\n-\n-\t\t/* For the per-vCPU lapic vector, deliver it as MSI. */\n-\t\tif (kick_vcpu \u0026\u0026 vcpu-\u003earch.xen.upcall_vector) {\n-\t\t\tkvm_xen_inject_vcpu_vector(vcpu);\n-\t\t\tkick_vcpu = false;\n-\t\t}\n \t}\n \n out_rcu:\n-\tread_unlock_irqrestore(\u0026gpc-\u003elock, flags);\n-\tsrcu_read_unlock(\u0026kvm-\u003esrcu, idx);\n+\trcu_read_unlock();\n \n-\tif (kick_vcpu) {\n-\t\tkvm_make_request(KVM_REQ_UNBLOCK, vcpu);\n-\t\tkvm_vcpu_kick(vcpu);\n-\t}\n+\tif (rc == 1)\n+\t\t__kvm_xen_set_evtchn_fast(vcpu, port_word_bit);\n+\n+\tsrcu_read_unlock(\u0026kvm-\u003esrcu, idx);\n \n \treturn rc;\n }\n@@ -2313,7 +2307,7 @@ void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu)\n \n \tkvm_gpc_init(\u0026vcpu-\u003earch.xen.runstate_cache, vcpu-\u003ekvm);\n \tkvm_gpc_init(\u0026vcpu-\u003earch.xen.runstate2_cache, vcpu-\u003ekvm);\n-\tkvm_gpc_init(\u0026vcpu-\u003earch.xen.vcpu_info_cache, vcpu-\u003ekvm);\n+\t__kvm_gpc_init(\u0026vcpu-\u003earch.xen.vcpu_info_cache, vcpu-\u003ekvm, true);\n \tkvm_gpc_init(\u0026vcpu-\u003earch.xen.vcpu_time_info_cache, vcpu-\u003ekvm);\n }\n \n@@ -2334,7 +2328,7 @@ void kvm_xen_init_vm(struct kvm *kvm)\n {\n \tmutex_init(\u0026kvm-\u003earch.xen.xen_lock);\n \tidr_init(\u0026kvm-\u003earch.xen.evtchn_ports);\n-\tkvm_gpc_init(\u0026kvm-\u003earch.xen.shinfo_cache, kvm);\n+\t__kvm_gpc_init(\u0026kvm-\u003earch.xen.shinfo_cache, kvm, true);\n }\n \n void kvm_xen_destroy_vm(struct kvm *kvm)\ndiff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h\nindex 03bfc92864b6e..1725284121c9e 100644\n--- a/include/linux/kvm_host.h\n+++ b/include/linux/kvm_host.h\n@@ -855,6 +855,8 @@ struct kvm {\n \tgfn_t mmu_invalidate_range_start;\n \tgfn_t mmu_invalidate_range_end;\n \n+\tunsigned long gpc_invalidate_seq;\n+\n \tstruct list_head devices;\n \tu64 manual_dirty_log_protect;\n \tstruct dentry *debugfs_dentry;\n@@ -1463,7 +1465,13 @@ int kvm_vcpu_write_guest(struct kvm_vcpu *vcpu, gpa_t gpa, const void *data,\n * immutable attributes. Note, the cache must be zero-allocated (or zeroed by\n * the caller before init).\n */\n-void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm);\n+void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,\n+\t\t bool never_dirty);\n+\n+static inline void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)\n+{\n+\t__kvm_gpc_init(gpc, kvm, false);\n+}\n \n /**\n * kvm_gpc_activate - prepare a cached kernel mapping and HPA for a given guest\n@@ -1508,12 +1516,9 @@ int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long hva, unsign\n * @return:\t %true if the cache is still valid and the address matches.\n *\t\t %false if the cache is not valid.\n *\n- * Callers outside IN_GUEST_MODE context should hold a read lock on @gpc-\u003elock\n- * while calling this function, and then continue to hold the lock until the\n- * access is complete.\n- *\n- * Callers in IN_GUEST_MODE may do so without locking, although they should\n- * still hold a read lock on kvm-\u003escru for the memslot checks.\n+ * Callers must hold the RCU read lock across this function and any\n+ * subsequent access to the target page, and must hold a read lock on\n+ * kvm-\u003esrcu for the memslot checks.\n */\n bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len);\n \n@@ -1530,8 +1535,8 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len);\n * This will attempt to refresh a gfn_to_pfn_cache. Note that a successful\n * return from this function does not mean the page can be immediately\n * accessed because it may have raced with an invalidation. Callers must\n- * still lock and check the cache status, as this function does not return\n- * with the lock still held to permit access.\n+ * still check the cache status under the RCU read lock, via\n+ * kvm_gpc_check(), before accessing the target page.\n */\n int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len);\n \n@@ -1972,9 +1977,10 @@ static inline bool kvm_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa)\n \n static inline void kvm_gpc_mark_dirty_in_slot(struct gfn_to_pfn_cache *gpc)\n {\n-\tlockdep_assert_held(\u0026gpc-\u003elock);\n+\tRCU_LOCKDEP_WARN(!rcu_read_lock_held(),\n+\t\t\t \"kvm_gpc_mark_dirty_in_slot() without RCU read lock\");\n \n-\tif (!gpc-\u003ememslot)\n+\tif (!gpc-\u003ememslot || gpc-\u003enever_dirty)\n \t\treturn;\n \n \tmark_page_dirty_in_slot(gpc-\u003ekvm, gpc-\u003ememslot, gpa_to_gfn(gpc-\u003egpa));\ndiff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h\nindex a568d8e6f4e82..1ad35ec01f876 100644\n--- a/include/linux/kvm_types.h\n+++ b/include/linux/kvm_types.h\n@@ -88,12 +88,12 @@ struct gfn_to_pfn_cache {\n \tstruct kvm_memory_slot *memslot;\n \tstruct kvm *kvm;\n \tstruct list_head list;\n-\trwlock_t lock;\n \tstruct mutex refresh_lock;\n \tvoid *khva;\n \tkvm_pfn_t pfn;\n \tbool active;\n \tbool valid;\n+\tbool never_dirty;\n };\n \n #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE\ndiff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c\nindex 245b74f39f912..cd5d15cd646a5 100644\n--- a/mm/mmu_notifier.c\n+++ b/mm/mmu_notifier.c\n@@ -520,11 +520,7 @@ static int mn_hlist_invalidate_range_start(\n \t\tif (ops-\u003einvalidate_range_start) {\n \t\t\tint _ret;\n \n-\t\t\tif (!mmu_notifier_range_blockable(range))\n-\t\t\t\tnon_block_start();\n \t\t\t_ret = ops-\u003einvalidate_range_start(subscription, range);\n-\t\t\tif (!mmu_notifier_range_blockable(range))\n-\t\t\t\tnon_block_end();\n \t\t\tif (_ret) {\n \t\t\t\tpr_info(\"%pS callback failed with %d in %sblockable context.\\n\",\n \t\t\t\t\tops-\u003einvalidate_range_start, _ret,\n@@ -591,14 +587,9 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions,\n \tid = srcu_read_lock(\u0026srcu);\n \thlist_for_each_entry_srcu(subscription, \u0026subscriptions-\u003elist, hlist,\n \t\t\t\t srcu_read_lock_held(\u0026srcu)) {\n-\t\tif (subscription-\u003eops-\u003einvalidate_range_end) {\n-\t\t\tif (!mmu_notifier_range_blockable(range))\n-\t\t\t\tnon_block_start();\n+\t\tif (subscription-\u003eops-\u003einvalidate_range_end)\n \t\t\tsubscription-\u003eops-\u003einvalidate_range_end(subscription,\n \t\t\t\t\t\t\t\trange);\n-\t\t\tif (!mmu_notifier_range_blockable(range))\n-\t\t\t\tnon_block_end();\n-\t\t}\n \t}\n \tsrcu_read_unlock(\u0026srcu, id);\n }\ndiff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c\nindex 345d56a15fa48..41c88a8ade959 100644\n--- a/virt/kvm/kvm_main.c\n+++ b/virt/kvm/kvm_main.c\n@@ -812,6 +812,16 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,\n \n \t/* Pairs with the increment in range_start(). */\n \tspin_lock(\u0026kvm-\u003emn_invalidate_lock);\n+\tkvm-\u003egpc_invalidate_seq++;\n+\n+\t/*\n+\t * As with the MMU sequence counter and mmu_invalidate_in_progress, the\n+\t * GPC sequence increase must be visible before the invalidate count\n+\t * goes to zero. Pairs with the smp_rmb() in\n+\t * mmu_notifier_retry_cache().\n+\t */\n+\tsmp_wmb();\n+\n \tif (!WARN_ON_ONCE(!kvm-\u003emn_active_invalidate_count))\n \t\t--kvm-\u003emn_active_invalidate_count;\n \twake = !kvm-\u003emn_active_invalidate_count;\ndiff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c\nindex 728d2c1b488a8..ffb4e61053446 100644\n--- a/virt/kvm/pfncache.c\n+++ b/virt/kvm/pfncache.c\n@@ -26,35 +26,49 @@ void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start,\n \t\t\t\t unsigned long end)\n {\n \tstruct gfn_to_pfn_cache *gpc;\n+\tbool cleared = false;\n \n \tspin_lock(\u0026kvm-\u003egpc_lock);\n \tlist_for_each_entry(gpc, \u0026kvm-\u003egpc_list, list) {\n-\t\tread_lock_irq(\u0026gpc-\u003elock);\n-\n-\t\t/* Only a single page so no need to care about length */\n-\t\tif (gpc-\u003evalid \u0026\u0026 !is_error_noslot_pfn(gpc-\u003epfn) \u0026\u0026\n+\t\t/*\n+\t\t * Only a single page so no need to care about length.\n+\t\t * A cache whose refresh is in flight has valid == false\n+\t\t * and is caught by the gpc_invalidate_seq check in\n+\t\t * hva_to_pfn_retry() instead.\n+\t\t */\n+\t\t/*\n+\t\t * The acquire pairs with the release-publish of valid in\n+\t\t * hva_to_pfn_retry(): if valid is seen true, the uhva read\n+\t\t * below is guaranteed to see the value which was stored\n+\t\t * before valid was published, not a stale one. (A stale\n+\t\t * uhva paired with a fresh valid could otherwise cause a\n+\t\t * cache whose new uhva is in the invalidated range to be\n+\t\t * skipped.)\n+\t\t */\n+\t\tif (smp_load_acquire(\u0026gpc-\u003evalid) \u0026\u0026\n \t\t gpc-\u003euhva \u003e= start \u0026\u0026 gpc-\u003euhva \u003c end) {\n-\t\t\tread_unlock_irq(\u0026gpc-\u003elock);\n-\n-\t\t\t/*\n-\t\t\t * There is a small window here where the cache could\n-\t\t\t * be modified, and invalidation would no longer be\n-\t\t\t * necessary. Hence check again whether invalidation\n-\t\t\t * is still necessary once the write lock has been\n-\t\t\t * acquired.\n-\t\t\t */\n-\n-\t\t\twrite_lock_irq(\u0026gpc-\u003elock);\n-\t\t\tif (gpc-\u003evalid \u0026\u0026 !is_error_noslot_pfn(gpc-\u003epfn) \u0026\u0026\n-\t\t\t gpc-\u003euhva \u003e= start \u0026\u0026 gpc-\u003euhva \u003c end)\n-\t\t\t\tgpc-\u003evalid = false;\n-\t\t\twrite_unlock_irq(\u0026gpc-\u003elock);\n-\t\t\tcontinue;\n+\t\t\tWRITE_ONCE(gpc-\u003evalid, false);\n+\t\t\tcleared = true;\n \t\t}\n-\n-\t\tread_unlock_irq(\u0026gpc-\u003elock);\n \t}\n \tspin_unlock(\u0026kvm-\u003egpc_lock);\n+\n+\t/*\n+\t * Readers may still be using the old mapping, having sampled\n+\t * gpc-\u003evalid before it was cleared. Wait for them all to drain\n+\t * before the caller proceeds to zap the page tables; like a TLB\n+\t * shootdown, this guarantees no access via the stale mapping\n+\t * once the invalidation completes.\n+\t *\n+\t * This wait is safe even on unblockable ranges (the OOM reaper):\n+\t * the constraint there is not \"no sleeping\" but \"no blocking on\n+\t * anything which may itself depend on memory allocation to make\n+\t * progress\" (see the reasoning in commit 312364f3534c and its\n+\t * discussion). An RCU grace period has no such dependency: GPC\n+\t * readers never allocate, never take mmap_lock, and never sleep.\n+\t */\n+\tif (cleared)\n+\t\tsynchronize_rcu();\n }\n \n static bool kvm_gpc_is_valid_len(gpa_t gpa, unsigned long uhva,\n@@ -74,6 +88,22 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)\n {\n \tstruct kvm_memslots *slots = kvm_memslots(gpc-\u003ekvm);\n \n+\tRCU_LOCKDEP_WARN(!rcu_read_lock_held(),\n+\t\t\t \"kvm_gpc_check() without RCU read lock\");\n+\n+\t/*\n+\t * Check valid *first*. The acquire pairs with the release-publish\n+\t * in hva_to_pfn_retry(), so every field read below — and any use\n+\t * of gpc-\u003ekhva by the caller — is guaranteed to be from the\n+\t * published generation, not a stale value reordered from before\n+\t * the publish. The fields are then stable for the remainder of\n+\t * the RCU read-side critical section, because every mutator\n+\t * clears valid and waits a full grace period before changing\n+\t * anything.\n+\t */\n+\tif (!smp_load_acquire(\u0026gpc-\u003evalid))\n+\t\treturn false;\n+\n \tif (!gpc-\u003eactive)\n \t\treturn false;\n \n@@ -90,9 +120,6 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)\n \tif (!kvm_gpc_is_valid_len(gpc-\u003egpa, gpc-\u003euhva, len))\n \t\treturn false;\n \n-\tif (!gpc-\u003evalid)\n-\t\treturn false;\n-\n \treturn true;\n }\n \n@@ -124,7 +151,7 @@ static void gpc_unmap(kvm_pfn_t pfn, void *khva)\n #endif\n }\n \n-static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_seq)\n+static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long gpc_seq)\n {\n \t/*\n \t * mn_active_invalidate_count acts for all intents and purposes\n@@ -134,22 +161,22 @@ static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_s\n \t * is elevated.\n \t *\n \t * Note, it does not matter that mn_active_invalidate_count\n-\t * is not protected by gpc-\u003elock. It is guaranteed to\n-\t * be elevated before the mmu_notifier acquires gpc-\u003elock, and\n-\t * isn't dropped until after mmu_invalidate_seq is updated.\n+\t * is not protected by any lock the refresher holds. It is\n+\t * guaranteed to be elevated before the mmu_notifier walk, and\n+\t * isn't dropped until after gpc_invalidate_seq is updated.\n \t */\n \tif (kvm-\u003emn_active_invalidate_count)\n \t\treturn true;\n \n \t/*\n \t * Ensure mn_active_invalidate_count is read before\n-\t * mmu_invalidate_seq. This pairs with the smp_wmb() in\n-\t * mmu_notifier_invalidate_range_end() to guarantee either the\n+\t * gpc_invalidate_seq. This pairs with the smp_wmb() in\n+\t * kvm_mmu_notifier_invalidate_range_end() to guarantee either the\n \t * old (non-zero) value of mn_active_invalidate_count or the\n-\t * new (incremented) value of mmu_invalidate_seq is observed.\n+\t * new (incremented) value of gpc_invalidate_seq is observed.\n \t */\n \tsmp_rmb();\n-\treturn kvm-\u003emmu_invalidate_seq != mmu_seq;\n+\treturn kvm-\u003egpc_invalidate_seq != gpc_seq;\n }\n \n static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n@@ -158,7 +185,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n \tvoid *old_khva = (void *)PAGE_ALIGN_DOWN((uintptr_t)gpc-\u003ekhva);\n \tkvm_pfn_t new_pfn = KVM_PFN_ERR_FAULT;\n \tvoid *new_khva = NULL;\n-\tunsigned long mmu_seq;\n+\tunsigned long gpc_seq;\n \tstruct page *page;\n \n \tstruct kvm_follow_pfn kfp = {\n@@ -171,21 +198,12 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n \n \tlockdep_assert_held(\u0026gpc-\u003erefresh_lock);\n \n-\tlockdep_assert_held_write(\u0026gpc-\u003elock);\n-\n-\t/*\n-\t * Invalidate the cache prior to dropping gpc-\u003elock, the gpa=\u003euhva\n-\t * assets have already been updated and so a concurrent check() from a\n-\t * different task may not fail the gpa/uhva/generation checks.\n-\t */\n-\tgpc-\u003evalid = false;\n+\tWARN_ON_ONCE(gpc-\u003evalid);\n \n \tdo {\n-\t\tmmu_seq = gpc-\u003ekvm-\u003emmu_invalidate_seq;\n+\t\tgpc_seq = gpc-\u003ekvm-\u003egpc_invalidate_seq;\n \t\tsmp_rmb();\n \n-\t\twrite_unlock_irq(\u0026gpc-\u003elock);\n-\n \t\t/*\n \t\t * If the previous iteration \"failed\" due to an mmu_notifier\n \t\t * event, release the pfn and unmap the kernel virtual address\n@@ -213,7 +231,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n \t\t/*\n \t\t * Obtain a new kernel mapping if KVM itself will access the\n \t\t * pfn. Note, kmap() and memremap() can both sleep, so this\n-\t\t * too must be done outside of gpc-\u003elock!\n+\t\t * can sleep, which is fine: this path holds no spinning locks.\n \t\t */\n \t\tif (new_pfn == gpc-\u003epfn)\n \t\t\tnew_khva = old_khva;\n@@ -224,20 +242,17 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n \t\t\tkvm_release_page_unused(page);\n \t\t\tgoto out_error;\n \t\t}\n+\t} while (mmu_notifier_retry_cache(gpc-\u003ekvm, gpc_seq));\n \n-\t\twrite_lock_irq(\u0026gpc-\u003elock);\n-\n-\t\t/*\n-\t\t * Other tasks must wait for _this_ refresh to complete before\n-\t\t * attempting to refresh.\n-\t\t */\n-\t\tWARN_ON_ONCE(gpc-\u003evalid);\n-\t} while (mmu_notifier_retry_cache(gpc-\u003ekvm, mmu_seq));\n-\n-\tgpc-\u003evalid = true;\n \tgpc-\u003epfn = new_pfn;\n \tgpc-\u003ekhva = new_khva + offset_in_page(gpc-\u003euhva);\n \n+\t/*\n+\t * Publish. Pairs with the smp_load_acquire() in kvm_gpc_check();\n+\t * the pfn/khva stores above must be visible before valid is.\n+\t */\n+\tsmp_store_release(\u0026gpc-\u003evalid, true);\n+\n \t/*\n \t * Put the reference to the _new_ page. The page is now tracked by the\n \t * cache and can be safely migrated, swapped, etc... as the cache will\n@@ -248,8 +263,6 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n \treturn 0;\n \n out_error:\n-\twrite_lock_irq(\u0026gpc-\u003elock);\n-\n \treturn -EFAULT;\n }\n \n@@ -259,7 +272,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \tbool unmap_old = false;\n \tunsigned long old_uhva;\n \tkvm_pfn_t old_pfn;\n-\tbool hva_change = false;\n+\tbool was_valid;\n \tvoid *old_khva;\n \tint ret;\n \n@@ -269,11 +282,85 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \n \tlockdep_assert_held(\u0026gpc-\u003erefresh_lock);\n \n-\twrite_lock_irq(\u0026gpc-\u003elock);\n+\tif (!gpc-\u003eactive)\n+\t\treturn -EINVAL;\n \n-\tif (!gpc-\u003eactive) {\n-\t\tret = -EINVAL;\n-\t\tgoto out_unlock;\n+\t/*\n+\t * Resolve the target uHVA (and memslot, for a GPA-based cache) before\n+\t * deciding whether anything needs to be invalidated at all.\n+\t *\n+\t * If the cache is still valid and this refresh resolves to exactly the\n+\t * same uHVA, in the same memslot, for the same GPA, then nothing which\n+\t * a reader can observe is changing: the gPA =\u003e uHVA translation is\n+\t * unchanged, and gpc-\u003evalid being set is precisely the assertion that\n+\t * the second stage (uHVA =\u003e PFN, and the kernel mapping of it) is\n+\t * still good. No mapping is retired, so there is nothing for a grace\n+\t * period to wait for. At most the memslot generation needs updating,\n+\t * which no reader consults except via kvm_gpc_check() itself.\n+\t *\n+\t * All of the following must hold to take this shortcut:\n+\t *\n+\t * - gpc-\u003evalid: the PFN and its kernel mapping are still good.\n+\t * - the resolved uHVA is unchanged. kvm_gpc_check() validates\n+\t * 'offset + len \u003c= PAGE_SIZE' from gpc-\u003euhva/gpa on the reader's\n+\t * behalf, and the reader then accesses gpc-\u003ekhva for 'len' bytes\n+\t * with no recheck; moving the offset under a live reader would let\n+\t * it run off the end of the page.\n+\t * - the memslot is unchanged. kvm_gpc_mark_dirty_in_slot() uses\n+\t * gpc-\u003ememslot, so replacing it under a reader could mark the wrong\n+\t * slot dirty and thus lose a dirty page for live migration.\n+\t * - the gPA is unchanged, as it provides the gfn for dirty tracking.\n+\t */\n+\tif (READ_ONCE(gpc-\u003evalid)) {\n+\t\tstruct kvm_memory_slot *new_slot = gpc-\u003ememslot;\n+\t\tunsigned long new_uhva = KVM_HVA_ERR_BAD;\n+\t\tu64 new_generation = gpc-\u003egeneration;\n+\n+\t\tif (kvm_is_error_gpa(gpa)) {\n+\t\t\tnew_uhva = uhva;\n+\t\t} else {\n+\t\t\tstruct kvm_memslots *slots = kvm_memslots(gpc-\u003ekvm);\n+\t\t\tgfn_t gfn = gpa_to_gfn(gpa);\n+\n+\t\t\tnew_generation = slots-\u003egeneration;\n+\t\t\tnew_slot = __gfn_to_memslot(slots, gfn);\n+\t\t\tif (new_slot)\n+\t\t\t\tnew_uhva = gfn_to_hva_memslot(new_slot, gfn) +\n+\t\t\t\t\t offset_in_page(gpa);\n+\t\t}\n+\n+\t\tif (!kvm_is_error_hva(new_uhva) \u0026\u0026 new_uhva == gpc-\u003euhva \u0026\u0026\n+\t\t new_slot == gpc-\u003ememslot \u0026\u0026 gpa == gpc-\u003egpa) {\n+\t\t\t/*\n+\t\t\t * Nothing to invalidate. A concurrent reader may be\n+\t\t\t * using the cache right now and can safely continue\n+\t\t\t * to do so; only the memslot generation, which is\n+\t\t\t * read solely by kvm_gpc_check(), may need updating.\n+\t\t\t */\n+\t\t\tif (new_generation != gpc-\u003egeneration)\n+\t\t\t\tWRITE_ONCE(gpc-\u003egeneration, new_generation);\n+\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Take the cache invalid and wait for all current readers to\n+\t * drain before mutating anything they might be looking at. Once\n+\t * the grace period has elapsed, this task (serialized by\n+\t * refresh_lock) owns all the cache fields exclusively: readers\n+\t * check valid (with an acquire load) inside their RCU read-side\n+\t * critical sections and back off. This mirrors what a TLB\n+\t * shootdown does for the hardware page tables.\n+\t *\n+\t * If the cache wasn't valid, concurrent readers were already\n+\t * backing off, and any concurrent invalidation is handled by the\n+\t * gpc_invalidate_seq check in hva_to_pfn_retry().\n+\t */\n+\twas_valid = READ_ONCE(gpc-\u003evalid);\n+\tif (was_valid) {\n+\t\tWRITE_ONCE(gpc-\u003evalid, false);\n+\t\tsynchronize_rcu();\n \t}\n \n \told_pfn = gpc-\u003epfn;\n@@ -286,9 +373,6 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \t\tgpc-\u003egpa = INVALID_GPA;\n \t\tgpc-\u003ememslot = NULL;\n \t\tgpc-\u003euhva = PAGE_ALIGN_DOWN(uhva);\n-\n-\t\tif (gpc-\u003euhva != old_uhva)\n-\t\t\thva_change = true;\n \t} else {\n \t\tstruct kvm_memslots *slots = kvm_memslots(gpc-\u003ekvm);\n \n@@ -308,12 +392,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \t\t\t\tgoto out;\n \t\t\t}\n \n-\t\t\t/*\n-\t\t\t * Even if the GPA and/or the memslot generation changed, the\n-\t\t\t * HVA may still be the same.\n-\t\t\t */\n-\t\t\tif (gpc-\u003euhva != old_uhva)\n-\t\t\t\thva_change = true;\n+\n \t\t} else {\n \t\t\tgpc-\u003euhva = old_uhva;\n \t\t}\n@@ -323,21 +402,16 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \tgpc-\u003euhva += page_offset;\n \n \t/*\n-\t * If the userspace HVA changed or the PFN was already invalid,\n-\t * drop the lock and do the HVA to PFN lookup again.\n+\t * Always redo the HVA to PFN lookup: an invalidation of our uhva\n+\t * may have raced with (or followed) the valid-clearing above, in\n+\t * which case the notifier walk skipped this cache (valid was\n+\t * already false) and the old pfn may already be stale. The\n+\t * gpc_invalidate_seq check in hva_to_pfn_retry() is what detects\n+\t * that race, so the lookup path is the only safe way to publish.\n+\t * If the mapping is in fact unchanged, hva_to_pfn_retry() reuses\n+\t * the existing kernel mapping for the same pfn.\n \t */\n-\tif (!gpc-\u003evalid || hva_change) {\n-\t\tret = hva_to_pfn_retry(gpc);\n-\t} else {\n-\t\t/*\n-\t\t * If the HVA→PFN mapping was already valid, don't unmap it.\n-\t\t * But do update gpc-\u003ekhva because the offset within the page\n-\t\t * may have changed.\n-\t\t */\n-\t\tgpc-\u003ekhva = old_khva + page_offset;\n-\t\tret = 0;\n-\t\tgoto out_unlock;\n-\t}\n+\tret = hva_to_pfn_retry(gpc);\n \n out:\n \t/*\n@@ -346,17 +420,12 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l\n \t * valid, leave it as is.\n \t */\n \tif (ret) {\n-\t\tgpc-\u003evalid = false;\n+\t\tWARN_ON_ONCE(gpc-\u003evalid);\n \t\tgpc-\u003epfn = KVM_PFN_ERR_FAULT;\n \t\tgpc-\u003ekhva = NULL;\n \t}\n \n-\t/* Detect a pfn change before dropping the lock! */\n \tunmap_old = (old_pfn != gpc-\u003epfn);\n-\n-out_unlock:\n-\twrite_unlock_irq(\u0026gpc-\u003elock);\n-\n \tif (unmap_old)\n \t\tgpc_unmap(old_pfn, old_khva);\n \n@@ -382,9 +451,9 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len)\n \treturn __kvm_gpc_refresh(gpc, gpc-\u003egpa, uhva);\n }\n \n-void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)\n+void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,\n+\t\t bool never_dirty)\n {\n-\trwlock_init(\u0026gpc-\u003elock);\n \tmutex_init(\u0026gpc-\u003erefresh_lock);\n \n \tgpc-\u003ekvm = kvm;\n@@ -392,6 +461,7 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)\n \tgpc-\u003egpa = INVALID_GPA;\n \tgpc-\u003euhva = KVM_HVA_ERR_BAD;\n \tgpc-\u003eactive = gpc-\u003evalid = false;\n+\tgpc-\u003enever_dirty = never_dirty;\n }\n \n static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva,\n@@ -415,11 +485,11 @@ static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned\n \t\t/*\n \t\t * Activate the cache after adding it to the list, a concurrent\n \t\t * refresh must not establish a mapping until the cache is\n-\t\t * reachable by mmu_notifier events.\n+\t\t * reachable by mmu_notifier events. (Refreshes are serialized\n+\t\t * by refresh_lock, which we hold; the store ordering matters\n+\t\t * only against the notifier walk, which holds gpc_lock.)\n \t\t */\n-\t\twrite_lock_irq(\u0026gpc-\u003elock);\n-\t\tgpc-\u003eactive = true;\n-\t\twrite_unlock_irq(\u0026gpc-\u003elock);\n+\t\tWRITE_ONCE(gpc-\u003eactive, true);\n \t}\n \treturn __kvm_gpc_refresh(gpc, gpa, uhva);\n }\n@@ -454,13 +524,16 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)\n \n \tif (gpc-\u003eactive) {\n \t\t/*\n-\t\t * Deactivate the cache before removing it from the list, KVM\n-\t\t * must stall mmu_notifier events until all users go away, i.e.\n-\t\t * until gpc-\u003elock is dropped and refresh is guaranteed to fail.\n+\t\t * Mark the cache inactive and invalid, and wait for all\n+\t\t * current readers to drain, before tearing down the mapping\n+\t\t * they may have been using. Refreshes are excluded by\n+\t\t * refresh_lock, which we hold.\n \t\t */\n-\t\twrite_lock_irq(\u0026gpc-\u003elock);\n-\t\tgpc-\u003eactive = false;\n-\t\tgpc-\u003evalid = false;\n+\t\tWRITE_ONCE(gpc-\u003eactive, false);\n+\t\tif (READ_ONCE(gpc-\u003evalid)) {\n+\t\t\tWRITE_ONCE(gpc-\u003evalid, false);\n+\t\t\tsynchronize_rcu();\n+\t\t}\n \n \t\t/*\n \t\t * Leave the GPA =\u003e uHVA cache intact, it's protected by the\n@@ -473,7 +546,6 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)\n \n \t\told_pfn = gpc-\u003epfn;\n \t\tgpc-\u003epfn = KVM_PFN_ERR_FAULT;\n-\t\twrite_unlock_irq(\u0026gpc-\u003elock);\n \n \t\tspin_lock(\u0026kvm-\u003egpc_lock);\n \t\tlist_del(\u0026gpc-\u003elist);\n"
} |
| 2/1 | 2026/08/05 21:19 | agent | patch-evaluator |
9mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"KVM",
"KVM_XEN"
],
"FocusSymbols": [
"kvm_gpc_refresh",
"kvm_gpc_activate",
"kvm_gpc_deactivate",
"gfn_to_pfn_cache_invalidate_start",
"kvm_xen_set_evtchn_fast",
"kvm_xen_update_runstate",
"kvm_xen_vcpu_set_attr",
"kvm_xen_hvm_set_attr",
"kvm_xen_inject_pending_events",
"kvm_xen_hypercall",
"__kvm_xen_has_interrupt",
"kvm_guest_time_update"
],
"Reasoning": "The patch replaces rwlock_t with RCU-based synchronization for gfn_to_pfn_cache (GPC) in KVM, which is used for guest-to-host page caching (e.g., steal time, Xen shared info). This is a significant functional change in core KVM logic and should be fuzzed.",
"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). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. 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. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 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. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. 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 18dbcd239103c347388dd02c52495279abea46c1
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Aug 5 21:19:37 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 283847619ff88..93514cb1f2f70 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -873,7 +873,7 @@ struct kvm_vcpu_arch {
u8 preempted;
u64 msr_val;
u64 last_steal;
- struct gfn_to_hva_cache cache;
+ struct gfn_to_pfn_cache cache;
} st;
u64 l1_tsc_offset;
diff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c
index 66fa7140d65d9..37d79d84e2f89 100644
--- a/arch/x86/kvm/msrs.c
+++ b/arch/x86/kvm/msrs.c
@@ -1717,8 +1717,13 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
vcpu->arch.st.msr_val = data;
- if (!(data & KVM_MSR_ENABLED))
+ if (!(data & KVM_MSR_ENABLED)) {
+ kvm_gpc_deactivate(&vcpu->arch.st.cache);
break;
+ }
+
+ kvm_gpc_activate(&vcpu->arch.st.cache, data & ~KVM_MSR_ENABLED,
+ sizeof(struct kvm_steal_time));
kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d94b59140c452..4a5753623909d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1719,18 +1719,17 @@ static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,
{
struct pvclock_vcpu_time_info *guest_hv_clock;
struct pvclock_vcpu_time_info hv_clock;
- unsigned long flags;
memcpy(&hv_clock, ref_hv_clock, sizeof(hv_clock));
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
while (!kvm_gpc_check(gpc, offset + sizeof(*guest_hv_clock))) {
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
if (kvm_gpc_refresh(gpc, offset + sizeof(*guest_hv_clock)))
return;
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
}
guest_hv_clock = (void *)(gpc->khva + offset);
@@ -1755,7 +1754,7 @@ static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,
guest_hv_clock->version = ++hv_clock.version;
kvm_gpc_mark_dirty_in_slot(gpc);
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
trace_kvm_pvclock_update(vcpu->vcpu_id, &hv_clock);
}
@@ -2047,10 +2046,8 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_service_local_tlb_flush_requests);
static void record_steal_time(struct kvm_vcpu *vcpu)
{
- struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache;
- struct kvm_steal_time __user *st;
- struct kvm_memslots *slots;
- gpa_t gpa = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS;
+ struct gfn_to_pfn_cache *gpc = &vcpu->arch.st.cache;
+ struct kvm_steal_time *st;
u64 steal;
u32 version;
@@ -2065,42 +2062,27 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
if (WARN_ON_ONCE(current->mm != vcpu->kvm->mm))
return;
- slots = kvm_memslots(vcpu->kvm);
+ /* We rely on the fact that it fits in a single page. */
+ BUILD_BUG_ON((sizeof(*st) - 1) & KVM_STEAL_VALID_BITS);
- if (unlikely(slots->generation != ghc->generation ||
- gpa != ghc->gpa ||
- kvm_is_error_hva(ghc->hva) || !ghc->memslot)) {
- /* We rely on the fact that it fits in a single page. */
- BUILD_BUG_ON((sizeof(*st) - 1) & KVM_STEAL_VALID_BITS);
+ rcu_read_lock();
+ while (!kvm_gpc_check(gpc, sizeof(*st))) {
+ rcu_read_unlock();
- if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gpa, sizeof(*st)) ||
- kvm_is_error_hva(ghc->hva) || !ghc->memslot)
+ if (kvm_gpc_refresh(gpc, sizeof(*st)))
return;
+
+ rcu_read_lock();
}
- st = (struct kvm_steal_time __user *)ghc->hva;
+ st = gpc->khva;
+
/*
* Doing a TLB flush here, on the guest's behalf, can avoid
* expensive IPIs.
*/
if (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) {
- u8 st_preempted = 0;
- int err = -EFAULT;
-
- if (!user_access_begin(st, sizeof(*st)))
- return;
-
- asm volatile("1: xchgb %0, %2\n"
- "xor %1, %1\n"
- "2:\n"
- _ASM_EXTABLE_UA(1b, 2b)
- : "+q" (st_preempted),
- "+&r" (err),
- "+m" (st->preempted));
- if (err)
- goto out;
-
- user_access_end();
+ u8 st_preempted = xchg(&st->preempted, 0);
vcpu->arch.st.preempted = 0;
@@ -2108,39 +2090,33 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
st_preempted & KVM_VCPU_FLUSH_TLB);
if (st_preempted & KVM_VCPU_FLUSH_TLB)
kvm_vcpu_flush_tlb_guest(vcpu);
-
- if (!user_access_begin(st, sizeof(*st)))
- goto dirty;
} else {
- if (!user_access_begin(st, sizeof(*st)))
- return;
-
- unsafe_put_user(0, &st->preempted, out);
+ WRITE_ONCE(st->preempted, 0);
vcpu->arch.st.preempted = 0;
}
- unsafe_get_user(version, &st->version, out);
+ version = READ_ONCE(st->version);
if (version & 1)
version += 1; /* first time write, random junk */
version += 1;
- unsafe_put_user(version, &st->version, out);
+ WRITE_ONCE(st->version, version);
smp_wmb();
- unsafe_get_user(steal, &st->steal, out);
+ steal = READ_ONCE(st->steal);
steal += current->sched_info.run_delay -
vcpu->arch.st.last_steal;
vcpu->arch.st.last_steal = current->sched_info.run_delay;
- unsafe_put_user(steal, &st->steal, out);
+ WRITE_ONCE(st->steal, steal);
+
+ smp_wmb();
version += 1;
- unsafe_put_user(version, &st->version, out);
+ WRITE_ONCE(st->version, version);
- out:
- user_access_end();
- dirty:
- mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa));
+ kvm_gpc_mark_dirty_in_slot(gpc);
+ rcu_read_unlock();
}
static inline bool kvm_can_mwait_in_guest(void)
@@ -2614,11 +2590,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
{
- struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache;
- struct kvm_steal_time __user *st;
- struct kvm_memslots *slots;
- static const u8 preempted = KVM_VCPU_PREEMPTED;
- gpa_t gpa = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS;
+ struct gfn_to_pfn_cache *gpc = &vcpu->arch.st.cache;
+ struct kvm_steal_time *st;
/*
* The vCPU can be marked preempted if and only if the VM-Exit was on
@@ -2643,20 +2616,32 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
if (unlikely(current->mm != vcpu->kvm->mm))
return;
- slots = kvm_memslots(vcpu->kvm);
-
- if (unlikely(slots->generation != ghc->generation ||
- gpa != ghc->gpa ||
- kvm_is_error_hva(ghc->hva) || !ghc->memslot))
- return;
-
- st = (struct kvm_steal_time __user *)ghc->hva;
- BUILD_BUG_ON(sizeof(st->preempted) != sizeof(preempted));
-
- if (!copy_to_user_nofault(&st->preempted, &preempted, sizeof(preempted)))
+ /*
+ * This is called from the scheduler path (via kvm_sched_out), so
+ * the cache cannot be refreshed here. Setting 'preempted' is
+ * best-effort anyway; the old HVA-based code used
+ * copy_to_user_nofault(), which could also silently fail. If the
+ * cache is invalid, it will be refreshed from task context by
+ * record_steal_time() before the vCPU next enters the guest, since
+ * kvm_arch_vcpu_load() unconditionally raises KVM_REQ_STEAL_UPDATE.
+ */
+ rcu_read_lock();
+ if (kvm_gpc_check(gpc, sizeof(*st))) {
+ st = gpc->khva;
+ WRITE_ONCE(st->preempted, KVM_VCPU_PREEMPTED);
vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED;
- mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa));
+ kvm_gpc_mark_dirty_in_slot(gpc);
+ }
+ rcu_read_unlock();
+}
+
+static void kvm_steal_time_reset(struct kvm_vcpu *vcpu)
+{
+ kvm_gpc_deactivate(&vcpu->arch.st.cache);
+ vcpu->arch.st.preempted = 0;
+ vcpu->arch.st.msr_val = 0;
+ vcpu->arch.st.last_steal = 0;
}
void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
@@ -9348,6 +9333,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
kvm_gpc_init(&vcpu->arch.pv_time, vcpu->kvm);
+ kvm_gpc_init(&vcpu->arch.st.cache, vcpu->kvm);
+
if (!irqchip_in_kernel(vcpu->kvm) || kvm_vcpu_is_reset_bsp(vcpu))
kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);
else
@@ -9455,6 +9442,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
kvm_clear_async_pf_completion_queue(vcpu);
kvm_mmu_unload(vcpu);
+ kvm_steal_time_reset(vcpu);
+
kvmclock_reset(vcpu);
for_each_possible_cpu(cpu)
@@ -9575,7 +9564,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
kvm_make_request(KVM_REQ_EVENT, vcpu);
vcpu->arch.apf.msr_en_val = 0;
vcpu->arch.apf.msr_int_val = 0;
- vcpu->arch.st.msr_val = 0;
+
+ kvm_steal_time_reset(vcpu);
kvmclock_reset(vcpu);
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index f2c6757fc1faf..9f1a9c93442d7 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -46,15 +46,15 @@ static int kvm_xen_shared_info_init(struct kvm *kvm)
int ret = 0;
int idx = srcu_read_lock(&kvm->srcu);
- read_lock_irq(&gpc->lock);
+ rcu_read_lock();
while (!kvm_gpc_check(gpc, PAGE_SIZE)) {
- read_unlock_irq(&gpc->lock);
+ rcu_read_unlock();
ret = kvm_gpc_refresh(gpc, PAGE_SIZE);
if (ret)
goto out;
- read_lock_irq(&gpc->lock);
+ rcu_read_lock();
}
/*
@@ -97,7 +97,7 @@ static int kvm_xen_shared_info_init(struct kvm *kvm)
smp_wmb();
wc->version = wc_version + 1;
- read_unlock_irq(&gpc->lock);
+ rcu_read_unlock();
out:
srcu_read_unlock(&kvm->srcu, idx);
@@ -154,22 +154,21 @@ static int xen_get_guest_pvclock(struct kvm_vcpu *vcpu,
struct gfn_to_pfn_cache *gpc,
unsigned int offset)
{
- unsigned long flags;
int r;
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
while (!kvm_gpc_check(gpc, offset + sizeof(*hv_clock))) {
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
r = kvm_gpc_refresh(gpc, offset + sizeof(*hv_clock));
if (r)
return r;
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
}
memcpy(hv_clock, gpc->khva + offset, sizeof(*hv_clock));
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
/*
* Sanity check TSC shift+multiplier to verify the guest's view of time
@@ -324,7 +323,6 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
struct gfn_to_pfn_cache *gpc2 = &vx->runstate2_cache;
size_t user_len, user_len1, user_len2;
struct vcpu_runstate_info rs;
- unsigned long flags;
size_t times_ofs;
uint8_t *update_bit = NULL;
uint64_t entry_time;
@@ -416,20 +414,12 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
retry:
/*
- * Attempt to obtain the GPC lock on *both* (if there are two)
- * gfn_to_pfn caches that cover the region.
+ * Check *both* (if there are two) gfn_to_pfn caches that cover
+ * the region, under a single RCU read-side critical section.
*/
- if (atomic) {
- local_irq_save(flags);
- if (!read_trylock(&gpc1->lock)) {
- local_irq_restore(flags);
- return;
- }
- } else {
- read_lock_irqsave(&gpc1->lock, flags);
- }
+ rcu_read_lock();
while (!kvm_gpc_check(gpc1, user_len1)) {
- read_unlock_irqrestore(&gpc1->lock, flags);
+ rcu_read_unlock();
/* When invoked from kvm_sched_out() we cannot sleep */
if (atomic)
@@ -438,7 +428,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
if (kvm_gpc_refresh(gpc1, user_len1))
return;
- read_lock_irqsave(&gpc1->lock, flags);
+ rcu_read_lock();
}
if (likely(!user_len2)) {
@@ -458,24 +448,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
} else {
/*
* The guest's runstate_info is split across two pages and we
- * need to hold and validate both GPCs simultaneously. We can
- * declare a lock ordering GPC1 > GPC2 because nothing else
- * takes them more than one at a time. Set a subclass on the
- * gpc1 lock to make lockdep shut up about it.
+ * need to validate both GPCs simultaneously. They are both
+ * covered by the single RCU read-side critical section above.
*/
- lock_set_subclass(&gpc1->lock.dep_map, 1, _THIS_IP_);
- if (atomic) {
- if (!read_trylock(&gpc2->lock)) {
- read_unlock_irqrestore(&gpc1->lock, flags);
- return;
- }
- } else {
- read_lock(&gpc2->lock);
- }
-
if (!kvm_gpc_check(gpc2, user_len2)) {
- read_unlock(&gpc2->lock);
- read_unlock_irqrestore(&gpc1->lock, flags);
+ rcu_read_unlock();
/* When invoked from kvm_sched_out() we cannot sleep */
if (atomic)
@@ -574,13 +551,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
smp_wmb();
}
- if (user_len2) {
+ if (user_len2)
kvm_gpc_mark_dirty_in_slot(gpc2);
- read_unlock(&gpc2->lock);
- }
kvm_gpc_mark_dirty_in_slot(gpc1);
- read_unlock_irqrestore(&gpc1->lock, flags);
+ rcu_read_unlock();
}
void kvm_xen_update_runstate(struct kvm_vcpu *v, int state)
@@ -639,7 +614,6 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
{
unsigned long evtchn_pending_sel = READ_ONCE(v->arch.xen.evtchn_pending_sel);
struct gfn_to_pfn_cache *gpc = &v->arch.xen.vcpu_info_cache;
- unsigned long flags;
if (!evtchn_pending_sel)
return;
@@ -649,14 +623,14 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
* does anyway. Page it in and retry the instruction. We're just a
* little more honest about it.
*/
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
while (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
if (kvm_gpc_refresh(gpc, sizeof(struct vcpu_info)))
return;
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
}
/* Now gpc->khva is a valid kernel address for the vcpu_info */
@@ -685,8 +659,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
WRITE_ONCE(vi->evtchn_upcall_pending, 1);
}
- kvm_gpc_mark_dirty_in_slot(gpc);
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
/* For the per-vCPU lapic vector, deliver it as MSI. */
if (v->arch.xen.upcall_vector)
@@ -696,7 +669,6 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
{
struct gfn_to_pfn_cache *gpc = &v->arch.xen.vcpu_info_cache;
- unsigned long flags;
u8 rc = 0;
/*
@@ -712,9 +684,9 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
BUILD_BUG_ON(sizeof(rc) !=
sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending));
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
while (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
/*
* This function gets called from kvm_vcpu_block() after setting the
@@ -734,11 +706,11 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
*/
return 0;
}
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
}
rc = ((struct vcpu_info *)gpc->khva)->evtchn_upcall_pending;
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
return rc;
}
@@ -1437,12 +1409,11 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,
struct kvm *kvm = vcpu->kvm;
struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache;
unsigned long *pending_bits;
- unsigned long flags;
bool ret = true;
int idx, i;
idx = srcu_read_lock(&kvm->srcu);
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
if (!kvm_gpc_check(gpc, PAGE_SIZE))
goto out_rcu;
@@ -1463,7 +1434,7 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,
}
out_rcu:
- read_unlock_irqrestore(&gpc->lock, flags);
+ rcu_read_unlock();
srcu_read_unlock(&kvm->srcu, idx);
return ret;
@@ -1787,6 +1758,67 @@ static void kvm_xen_check_poller(struct kvm_vcpu *vcpu, int port)
}
}
+/* Called with kvm->srcu held, as kvm_gpc_check() consults the memslots. */
+static void __kvm_xen_set_evtchn_fast(struct kvm_vcpu *vcpu, int port_word_bit)
+{
+ struct gfn_to_pfn_cache *gpc = &vcpu->arch.xen.vcpu_info_cache;
+ bool kick_vcpu = false;
+
+ /* Now switch to the vCPU's vcpu_info to set the index and pending_sel */
+ rcu_read_lock();
+ if (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {
+ /*
+ * Could not access the vcpu_info. Set the bit in-kernel and
+ * prod the vCPU to deliver it for itself.
+ */
+ if (!test_and_set_bit(port_word_bit, &vcpu->arch.xen.evtchn_pending_sel))
+ kick_vcpu = true;
+ goto out_unlock;
+ }
+
+ if (IS_ENABLED(CONFIG_64BIT) && vcpu->kvm->arch.xen.long_mode) {
+ struct vcpu_info *vcpu_info = gpc->khva;
+
+ if (!test_and_set_bit(port_word_bit, &vcpu_info->evtchn_pending_sel)) {
+ WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1);
+ kick_vcpu = true;
+ }
+ } else {
+ struct compat_vcpu_info *vcpu_info = gpc->khva;
+
+ if (!test_and_set_bit(port_word_bit,
+ (unsigned long *)&vcpu_info->evtchn_pending_sel)) {
+ WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1);
+ kick_vcpu = true;
+ }
+ }
+
+out_unlock:
+ rcu_read_unlock();
+
+ /*
+ * Deliver the upcall or kick the vCPU only after dropping the RCU
+ * read lock. Both paths end up in kvm_vcpu_kick(), and the MSI
+ * delivery also walks the APIC map and takes APIC locks; none of
+ * that wants to be nested inside the GPC read-side critical
+ * section, which must be no longer than the accesses to gpc->khva
+ * above. Invalidation waits for a grace period, so holding the
+ * read lock across the kick would extend how long a memory
+ * invalidation is blocked.
+ */
+ if (!kick_vcpu)
+ return;
+
+ /* For the per-vCPU lapic vector, deliver it as MSI. */
+ if (vcpu->arch.xen.upcall_vector) {
+ kvm_xen_inject_vcpu_vector(vcpu);
+ return;
+ }
+
+ kvm_make_request(KVM_REQ_UNBLOCK, vcpu);
+ kvm_vcpu_kick(vcpu);
+}
+
/*
* The return value from this function is propagated to kvm_set_irq() API,
* so it returns:
@@ -1802,9 +1834,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)
struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache;
struct kvm_vcpu *vcpu;
unsigned long *pending_bits, *mask_bits;
- unsigned long flags;
int port_word_bit;
- bool kick_vcpu = false;
int vcpu_idx, idx, rc;
vcpu_idx = READ_ONCE(xe->vcpu_idx);
@@ -1824,7 +1854,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)
idx = srcu_read_lock(&kvm->srcu);
- read_lock_irqsave(&gpc->lock, flags);
+ rcu_read_lock();
if (!kvm_gpc_check(gpc, PAGE_SIZE))
goto out_rcu;
@@ -1854,51 +1884,15 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)
kvm_xen_check_poller(vcpu, xe->port);
} else {
rc = 1; /* Delivered to the bitmap in shared_info. */
- /* Now switch to the vCPU's vcpu_info to set the index and pending_sel */
- read_unlock_irqrestore(&gpc->lock, flags);
- gpc = &vcpu->arch.xen.vcpu_info_cache;
-
- read_lock_irqsave(&gpc->lock, flags);
- if (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) {
- /*
- * Could not access the vcpu_info. Set the bit in-kernel
- * and prod the vCPU to deliver it for itself.
- */
- if (!test_and_set_bit(port_word_bit, &vcpu->arch.xen.evtchn_pending_sel))
- kick_vcpu = true;
- goto out_rcu;
- }
-
- if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) {
- struct vcpu_info *vcpu_info = gpc->khva;
- if (!test_and_set_bit(port_word_bit, &vcpu_info->evtchn_pending_sel)) {
- WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1);
- kick_vcpu = true;
- }
- } else {
- struct compat_vcpu_info *vcpu_info = gpc->khva;
- if (!test_and_set_bit(port_word_bit,
- (unsigned long *)&vcpu_info->evtchn_pending_sel)) {
- WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1);
- kick_vcpu = true;
- }
- }
-
- /* For the per-vCPU lapic vector, deliver it as MSI. */
- if (kick_vcpu && vcpu->arch.xen.upcall_vector) {
- kvm_xen_inject_vcpu_vector(vcpu);
- kick_vcpu = false;
- }
}
out_rcu:
- read_unlock_irqrestore(&gpc->lock, flags);
- srcu_read_unlock(&kvm->srcu, idx);
+ rcu_read_unlock();
- if (kick_vcpu) {
- kvm_make_request(KVM_REQ_UNBLOCK, vcpu);
- kvm_vcpu_kick(vcpu);
- }
+ if (rc == 1)
+ __kvm_xen_set_evtchn_fast(vcpu, port_word_bit);
+
+ srcu_read_unlock(&kvm->srcu, idx);
return rc;
}
@@ -2313,7 +2307,7 @@ void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu)
kvm_gpc_init(&vcpu->arch.xen.runstate_cache, vcpu->kvm);
kvm_gpc_init(&vcpu->arch.xen.runstate2_cache, vcpu->kvm);
- kvm_gpc_init(&vcpu->arch.xen.vcpu_info_cache, vcpu->kvm);
+ __kvm_gpc_init(&vcpu->arch.xen.vcpu_info_cache, vcpu->kvm, true);
kvm_gpc_init(&vcpu->arch.xen.vcpu_time_info_cache, vcpu->kvm);
}
@@ -2334,7 +2328,7 @@ void kvm_xen_init_vm(struct kvm *kvm)
{
mutex_init(&kvm->arch.xen.xen_lock);
idr_init(&kvm->arch.xen.evtchn_ports);
- kvm_gpc_init(&kvm->arch.xen.shinfo_cache, kvm);
+ __kvm_gpc_init(&kvm->arch.xen.shinfo_cache, kvm, true);
}
void kvm_xen_destroy_vm(struct kvm *kvm)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 03bfc92864b6e..1725284121c9e 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -855,6 +855,8 @@ struct kvm {
gfn_t mmu_invalidate_range_start;
gfn_t mmu_invalidate_range_end;
+ unsigned long gpc_invalidate_seq;
+
struct list_head devices;
u64 manual_dirty_log_protect;
struct dentry *debugfs_dentry;
@@ -1463,7 +1465,13 @@ int kvm_vcpu_write_guest(struct kvm_vcpu *vcpu, gpa_t gpa, const void *data,
* immutable attributes. Note, the cache must be zero-allocated (or zeroed by
* the caller before init).
*/
-void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm);
+void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,
+ bool never_dirty);
+
+static inline void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)
+{
+ __kvm_gpc_init(gpc, kvm, false);
+}
/**
* kvm_gpc_activate - prepare a cached kernel mapping and HPA for a given guest
@@ -1508,12 +1516,9 @@ int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long hva, unsign
* @return: %true if the cache is still valid and the address matches.
* %false if the cache is not valid.
*
- * Callers outside IN_GUEST_MODE context should hold a read lock on @gpc->lock
- * while calling this function, and then continue to hold the lock until the
- * access is complete.
- *
- * Callers in IN_GUEST_MODE may do so without locking, although they should
- * still hold a read lock on kvm->scru for the memslot checks.
+ * Callers must hold the RCU read lock across this function and any
+ * subsequent access to the target page, and must hold a read lock on
+ * kvm->srcu for the memslot checks.
*/
bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len);
@@ -1530,8 +1535,8 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len);
* This will attempt to refresh a gfn_to_pfn_cache. Note that a successful
* return from this function does not mean the page can be immediately
* accessed because it may have raced with an invalidation. Callers must
- * still lock and check the cache status, as this function does not return
- * with the lock still held to permit access.
+ * still check the cache status under the RCU read lock, via
+ * kvm_gpc_check(), before accessing the target page.
*/
int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len);
@@ -1972,9 +1977,10 @@ static inline bool kvm_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa)
static inline void kvm_gpc_mark_dirty_in_slot(struct gfn_to_pfn_cache *gpc)
{
- lockdep_assert_held(&gpc->lock);
+ RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
+ "kvm_gpc_mark_dirty_in_slot() without RCU read lock");
- if (!gpc->memslot)
+ if (!gpc->memslot || gpc->never_dirty)
return;
mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpa_to_gfn(gpc->gpa));
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index a568d8e6f4e82..1ad35ec01f876 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -88,12 +88,12 @@ struct gfn_to_pfn_cache {
struct kvm_memory_slot *memslot;
struct kvm *kvm;
struct list_head list;
- rwlock_t lock;
struct mutex refresh_lock;
void *khva;
kvm_pfn_t pfn;
bool active;
bool valid;
+ bool never_dirty;
};
#ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
index 245b74f39f912..cd5d15cd646a5 100644
--- a/mm/mmu_notifier.c
+++ b/mm/mmu_notifier.c
@@ -520,11 +520,7 @@ static int mn_hlist_invalidate_range_start(
if (ops->invalidate_range_start) {
int _ret;
- if (!mmu_notifier_range_blockable(range))
- non_block_start();
_ret = ops->invalidate_range_start(subscription, range);
- if (!mmu_notifier_range_blockable(range))
- non_block_end();
if (_ret) {
pr_info("%pS callback failed with %d in %sblockable context.\n",
ops->invalidate_range_start, _ret,
@@ -591,14 +587,9 @@ mn_hlist_invalidate_end(struct mmu_notifier_subscriptions *subscriptions,
id = srcu_read_lock(&srcu);
hlist_for_each_entry_srcu(subscription, &subscriptions->list, hlist,
srcu_read_lock_held(&srcu)) {
- if (subscription->ops->invalidate_range_end) {
- if (!mmu_notifier_range_blockable(range))
- non_block_start();
+ if (subscription->ops->invalidate_range_end)
subscription->ops->invalidate_range_end(subscription,
range);
- if (!mmu_notifier_range_blockable(range))
- non_block_end();
- }
}
srcu_read_unlock(&srcu, id);
}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 345d56a15fa48..41c88a8ade959 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -812,6 +812,16 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
/* Pairs with the increment in range_start(). */
spin_lock(&kvm->mn_invalidate_lock);
+ kvm->gpc_invalidate_seq++;
+
+ /*
+ * As with the MMU sequence counter and mmu_invalidate_in_progress, the
+ * GPC sequence increase must be visible before the invalidate count
+ * goes to zero. Pairs with the smp_rmb() in
+ * mmu_notifier_retry_cache().
+ */
+ smp_wmb();
+
if (!WARN_ON_ONCE(!kvm->mn_active_invalidate_count))
--kvm->mn_active_invalidate_count;
wake = !kvm->mn_active_invalidate_count;
diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c
index 728d2c1b488a8..ffb4e61053446 100644
--- a/virt/kvm/pfncache.c
+++ b/virt/kvm/pfncache.c
@@ -26,35 +26,49 @@ void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start,
unsigned long end)
{
struct gfn_to_pfn_cache *gpc;
+ bool cleared = false;
spin_lock(&kvm->gpc_lock);
list_for_each_entry(gpc, &kvm->gpc_list, list) {
- read_lock_irq(&gpc->lock);
-
- /* Only a single page so no need to care about length */
- if (gpc->valid && !is_error_noslot_pfn(gpc->pfn) &&
+ /*
+ * Only a single page so no need to care about length.
+ * A cache whose refresh is in flight has valid == false
+ * and is caught by the gpc_invalidate_seq check in
+ * hva_to_pfn_retry() instead.
+ */
+ /*
+ * The acquire pairs with the release-publish of valid in
+ * hva_to_pfn_retry(): if valid is seen true, the uhva read
+ * below is guaranteed to see the value which was stored
+ * before valid was published, not a stale one. (A stale
+ * uhva paired with a fresh valid could otherwise cause a
+ * cache whose new uhva is in the invalidated range to be
+ * skipped.)
+ */
+ if (smp_load_acquire(&gpc->valid) &&
gpc->uhva >= start && gpc->uhva < end) {
- read_unlock_irq(&gpc->lock);
-
- /*
- * There is a small window here where the cache could
- * be modified, and invalidation would no longer be
- * necessary. Hence check again whether invalidation
- * is still necessary once the write lock has been
- * acquired.
- */
-
- write_lock_irq(&gpc->lock);
- if (gpc->valid && !is_error_noslot_pfn(gpc->pfn) &&
- gpc->uhva >= start && gpc->uhva < end)
- gpc->valid = false;
- write_unlock_irq(&gpc->lock);
- continue;
+ WRITE_ONCE(gpc->valid, false);
+ cleared = true;
}
-
- read_unlock_irq(&gpc->lock);
}
spin_unlock(&kvm->gpc_lock);
+
+ /*
+ * Readers may still be using the old mapping, having sampled
+ * gpc->valid before it was cleared. Wait for them all to drain
+ * before the caller proceeds to zap the page tables; like a TLB
+ * shootdown, this guarantees no access via the stale mapping
+ * once the invalidation completes.
+ *
+ * This wait is safe even on unblockable ranges (the OOM reaper):
+ * the constraint there is not "no sleeping" but "no blocking on
+ * anything which may itself depend on memory allocation to make
+ * progress" (see the reasoning in commit 312364f3534c and its
+ * discussion). An RCU grace period has no such dependency: GPC
+ * readers never allocate, never take mmap_lock, and never sleep.
+ */
+ if (cleared)
+ synchronize_rcu();
}
static bool kvm_gpc_is_valid_len(gpa_t gpa, unsigned long uhva,
@@ -74,6 +88,22 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)
{
struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
+ RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
+ "kvm_gpc_check() without RCU read lock");
+
+ /*
+ * Check valid *first*. The acquire pairs with the release-publish
+ * in hva_to_pfn_retry(), so every field read below — and any use
+ * of gpc->khva by the caller — is guaranteed to be from the
+ * published generation, not a stale value reordered from before
+ * the publish. The fields are then stable for the remainder of
+ * the RCU read-side critical section, because every mutator
+ * clears valid and waits a full grace period before changing
+ * anything.
+ */
+ if (!smp_load_acquire(&gpc->valid))
+ return false;
+
if (!gpc->active)
return false;
@@ -90,9 +120,6 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)
if (!kvm_gpc_is_valid_len(gpc->gpa, gpc->uhva, len))
return false;
- if (!gpc->valid)
- return false;
-
return true;
}
@@ -124,7 +151,7 @@ static void gpc_unmap(kvm_pfn_t pfn, void *khva)
#endif
}
-static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_seq)
+static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long gpc_seq)
{
/*
* mn_active_invalidate_count acts for all intents and purposes
@@ -134,22 +161,22 @@ static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_s
* is elevated.
*
* Note, it does not matter that mn_active_invalidate_count
- * is not protected by gpc->lock. It is guaranteed to
- * be elevated before the mmu_notifier acquires gpc->lock, and
- * isn't dropped until after mmu_invalidate_seq is updated.
+ * is not protected by any lock the refresher holds. It is
+ * guaranteed to be elevated before the mmu_notifier walk, and
+ * isn't dropped until after gpc_invalidate_seq is updated.
*/
if (kvm->mn_active_invalidate_count)
return true;
/*
* Ensure mn_active_invalidate_count is read before
- * mmu_invalidate_seq. This pairs with the smp_wmb() in
- * mmu_notifier_invalidate_range_end() to guarantee either the
+ * gpc_invalidate_seq. This pairs with the smp_wmb() in
+ * kvm_mmu_notifier_invalidate_range_end() to guarantee either the
* old (non-zero) value of mn_active_invalidate_count or the
- * new (incremented) value of mmu_invalidate_seq is observed.
+ * new (incremented) value of gpc_invalidate_seq is observed.
*/
smp_rmb();
- return kvm->mmu_invalidate_seq != mmu_seq;
+ return kvm->gpc_invalidate_seq != gpc_seq;
}
static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
@@ -158,7 +185,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
void *old_khva = (void *)PAGE_ALIGN_DOWN((uintptr_t)gpc->khva);
kvm_pfn_t new_pfn = KVM_PFN_ERR_FAULT;
void *new_khva = NULL;
- unsigned long mmu_seq;
+ unsigned long gpc_seq;
struct page *page;
struct kvm_follow_pfn kfp = {
@@ -171,21 +198,12 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
lockdep_assert_held(&gpc->refresh_lock);
- lockdep_assert_held_write(&gpc->lock);
-
- /*
- * Invalidate the cache prior to dropping gpc->lock, the gpa=>uhva
- * assets have already been updated and so a concurrent check() from a
- * different task may not fail the gpa/uhva/generation checks.
- */
- gpc->valid = false;
+ WARN_ON_ONCE(gpc->valid);
do {
- mmu_seq = gpc->kvm->mmu_invalidate_seq;
+ gpc_seq = gpc->kvm->gpc_invalidate_seq;
smp_rmb();
- write_unlock_irq(&gpc->lock);
-
/*
* If the previous iteration "failed" due to an mmu_notifier
* event, release the pfn and unmap the kernel virtual address
@@ -213,7 +231,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
/*
* Obtain a new kernel mapping if KVM itself will access the
* pfn. Note, kmap() and memremap() can both sleep, so this
- * too must be done outside of gpc->lock!
+ * can sleep, which is fine: this path holds no spinning locks.
*/
if (new_pfn == gpc->pfn)
new_khva = old_khva;
@@ -224,20 +242,17 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
kvm_release_page_unused(page);
goto out_error;
}
+ } while (mmu_notifier_retry_cache(gpc->kvm, gpc_seq));
- write_lock_irq(&gpc->lock);
-
- /*
- * Other tasks must wait for _this_ refresh to complete before
- * attempting to refresh.
- */
- WARN_ON_ONCE(gpc->valid);
- } while (mmu_notifier_retry_cache(gpc->kvm, mmu_seq));
-
- gpc->valid = true;
gpc->pfn = new_pfn;
gpc->khva = new_khva + offset_in_page(gpc->uhva);
+ /*
+ * Publish. Pairs with the smp_load_acquire() in kvm_gpc_check();
+ * the pfn/khva stores above must be visible before valid is.
+ */
+ smp_store_release(&gpc->valid, true);
+
/*
* Put the reference to the _new_ page. The page is now tracked by the
* cache and can be safely migrated, swapped, etc... as the cache will
@@ -248,8 +263,6 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
return 0;
out_error:
- write_lock_irq(&gpc->lock);
-
return -EFAULT;
}
@@ -259,7 +272,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
bool unmap_old = false;
unsigned long old_uhva;
kvm_pfn_t old_pfn;
- bool hva_change = false;
+ bool was_valid;
void *old_khva;
int ret;
@@ -269,11 +282,85 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
lockdep_assert_held(&gpc->refresh_lock);
- write_lock_irq(&gpc->lock);
+ if (!gpc->active)
+ return -EINVAL;
- if (!gpc->active) {
- ret = -EINVAL;
- goto out_unlock;
+ /*
+ * Resolve the target uHVA (and memslot, for a GPA-based cache) before
+ * deciding whether anything needs to be invalidated at all.
+ *
+ * If the cache is still valid and this refresh resolves to exactly the
+ * same uHVA, in the same memslot, for the same GPA, then nothing which
+ * a reader can observe is changing: the gPA => uHVA translation is
+ * unchanged, and gpc->valid being set is precisely the assertion that
+ * the second stage (uHVA => PFN, and the kernel mapping of it) is
+ * still good. No mapping is retired, so there is nothing for a grace
+ * period to wait for. At most the memslot generation needs updating,
+ * which no reader consults except via kvm_gpc_check() itself.
+ *
+ * All of the following must hold to take this shortcut:
+ *
+ * - gpc->valid: the PFN and its kernel mapping are still good.
+ * - the resolved uHVA is unchanged. kvm_gpc_check() validates
+ * 'offset + len <= PAGE_SIZE' from gpc->uhva/gpa on the reader's
+ * behalf, and the reader then accesses gpc->khva for 'len' bytes
+ * with no recheck; moving the offset under a live reader would let
+ * it run off the end of the page.
+ * - the memslot is unchanged. kvm_gpc_mark_dirty_in_slot() uses
+ * gpc->memslot, so replacing it under a reader could mark the wrong
+ * slot dirty and thus lose a dirty page for live migration.
+ * - the gPA is unchanged, as it provides the gfn for dirty tracking.
+ */
+ if (READ_ONCE(gpc->valid)) {
+ struct kvm_memory_slot *new_slot = gpc->memslot;
+ unsigned long new_uhva = KVM_HVA_ERR_BAD;
+ u64 new_generation = gpc->generation;
+
+ if (kvm_is_error_gpa(gpa)) {
+ new_uhva = uhva;
+ } else {
+ struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
+ gfn_t gfn = gpa_to_gfn(gpa);
+
+ new_generation = slots->generation;
+ new_slot = __gfn_to_memslot(slots, gfn);
+ if (new_slot)
+ new_uhva = gfn_to_hva_memslot(new_slot, gfn) +
+ offset_in_page(gpa);
+ }
+
+ if (!kvm_is_error_hva(new_uhva) && new_uhva == gpc->uhva &&
+ new_slot == gpc->memslot && gpa == gpc->gpa) {
+ /*
+ * Nothing to invalidate. A concurrent reader may be
+ * using the cache right now and can safely continue
+ * to do so; only the memslot generation, which is
+ * read solely by kvm_gpc_check(), may need updating.
+ */
+ if (new_generation != gpc->generation)
+ WRITE_ONCE(gpc->generation, new_generation);
+
+ return 0;
+ }
+ }
+
+ /*
+ * Take the cache invalid and wait for all current readers to
+ * drain before mutating anything they might be looking at. Once
+ * the grace period has elapsed, this task (serialized by
+ * refresh_lock) owns all the cache fields exclusively: readers
+ * check valid (with an acquire load) inside their RCU read-side
+ * critical sections and back off. This mirrors what a TLB
+ * shootdown does for the hardware page tables.
+ *
+ * If the cache wasn't valid, concurrent readers were already
+ * backing off, and any concurrent invalidation is handled by the
+ * gpc_invalidate_seq check in hva_to_pfn_retry().
+ */
+ was_valid = READ_ONCE(gpc->valid);
+ if (was_valid) {
+ WRITE_ONCE(gpc->valid, false);
+ synchronize_rcu();
}
old_pfn = gpc->pfn;
@@ -286,9 +373,6 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
gpc->gpa = INVALID_GPA;
gpc->memslot = NULL;
gpc->uhva = PAGE_ALIGN_DOWN(uhva);
-
- if (gpc->uhva != old_uhva)
- hva_change = true;
} else {
struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
@@ -308,12 +392,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
goto out;
}
- /*
- * Even if the GPA and/or the memslot generation changed, the
- * HVA may still be the same.
- */
- if (gpc->uhva != old_uhva)
- hva_change = true;
+
} else {
gpc->uhva = old_uhva;
}
@@ -323,21 +402,16 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
gpc->uhva += page_offset;
/*
- * If the userspace HVA changed or the PFN was already invalid,
- * drop the lock and do the HVA to PFN lookup again.
+ * Always redo the HVA to PFN lookup: an invalidation of our uhva
+ * may have raced with (or followed) the valid-clearing above, in
+ * which case the notifier walk skipped this cache (valid was
+ * already false) and the old pfn may already be stale. The
+ * gpc_invalidate_seq check in hva_to_pfn_retry() is what detects
+ * that race, so the lookup path is the only safe way to publish.
+ * If the mapping is in fact unchanged, hva_to_pfn_retry() reuses
+ * the existing kernel mapping for the same pfn.
*/
- if (!gpc->valid || hva_change) {
- ret = hva_to_pfn_retry(gpc);
- } else {
- /*
- * If the HVA→PFN mapping was already valid, don't unmap it.
- * But do update gpc->khva because the offset within the page
- * may have changed.
- */
- gpc->khva = old_khva + page_offset;
- ret = 0;
- goto out_unlock;
- }
+ ret = hva_to_pfn_retry(gpc);
out:
/*
@@ -346,17 +420,12 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned l
* valid, leave it as is.
*/
if (ret) {
- gpc->valid = false;
+ WARN_ON_ONCE(gpc->valid);
gpc->pfn = KVM_PFN_ERR_FAULT;
gpc->khva = NULL;
}
- /* Detect a pfn change before dropping the lock! */
unmap_old = (old_pfn != gpc->pfn);
-
-out_unlock:
- write_unlock_irq(&gpc->lock);
-
if (unmap_old)
gpc_unmap(old_pfn, old_khva);
@@ -382,9 +451,9 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len)
return __kvm_gpc_refresh(gpc, gpc->gpa, uhva);
}
-void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)
+void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,
+ bool never_dirty)
{
- rwlock_init(&gpc->lock);
mutex_init(&gpc->refresh_lock);
gpc->kvm = kvm;
@@ -392,6 +461,7 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm)
gpc->gpa = INVALID_GPA;
gpc->uhva = KVM_HVA_ERR_BAD;
gpc->active = gpc->valid = false;
+ gpc->never_dirty = never_dirty;
}
static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva,
@@ -415,11 +485,11 @@ static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned
/*
* Activate the cache after adding it to the list, a concurrent
* refresh must not establish a mapping until the cache is
- * reachable by mmu_notifier events.
+ * reachable by mmu_notifier events. (Refreshes are serialized
+ * by refresh_lock, which we hold; the store ordering matters
+ * only against the notifier walk, which holds gpc_lock.)
*/
- write_lock_irq(&gpc->lock);
- gpc->active = true;
- write_unlock_irq(&gpc->lock);
+ WRITE_ONCE(gpc->active, true);
}
return __kvm_gpc_refresh(gpc, gpa, uhva);
}
@@ -454,13 +524,16 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)
if (gpc->active) {
/*
- * Deactivate the cache before removing it from the list, KVM
- * must stall mmu_notifier events until all users go away, i.e.
- * until gpc->lock is dropped and refresh is guaranteed to fail.
+ * Mark the cache inactive and invalid, and wait for all
+ * current readers to drain, before tearing down the mapping
+ * they may have been using. Refreshes are excluded by
+ * refresh_lock, which we hold.
*/
- write_lock_irq(&gpc->lock);
- gpc->active = false;
- gpc->valid = false;
+ WRITE_ONCE(gpc->active, false);
+ if (READ_ONCE(gpc->valid)) {
+ WRITE_ONCE(gpc->valid, false);
+ synchronize_rcu();
+ }
/*
* Leave the GPA => uHVA cache intact, it's protected by the
@@ -473,7 +546,6 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)
old_pfn = gpc->pfn;
gpc->pfn = KVM_PFN_ERR_FAULT;
- write_unlock_irq(&gpc->lock);
spin_lock(&kvm->gpc_lock);
list_del(&gpc->list);
|
| 3/2 | 2026/08/05 21:19 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 19754 output: 37 thoughts: 921 Thoughts: **Analyzing the KVM GPC Synchronization Patch** Okay, so I'm looking at this patch for KVM that's making some pretty substantial changes to the `gfn_to_pfn_cache` (GPC) mechanism. It's essentially swapping out the existing `rwlock_t` with RCU synchronization. Right away, this screams "potential for interesting behavior" and, frankly, needs a thorough fuzzing campaign. This is a core part of KVM, impacting how the hypervisor deals with guest-to-host page mappings, critical for things like steal time calculation and Xen shared info. Specifically, the patch seems to be swapping out `read_lock_irqsave` with `rcu_read_lock()` and ensuring that `kvm_gpc_check` is called under RCU read protection now. I'm seeing changes across a significant number of files: `arch/x86/kvm/msrs.c`, `arch/x86/kvm/x86.c`, `arch/x86/kvm/xen.c`, `include/linux/kvm_host.h`, `include/linux/kvm_types.h`, `mm/mmu_notifier.c`, `virt/kvm/kvm_main.c`, and `virt/kvm/pfncache.c`. That's a wide reach, indicating how fundamental this change is. I need to nail down the affected areas for a focused fuzzing effort. Let's list the key symbols being touched: I see modifications to `kvm_set_msr_common`, `kvm_setup_guest_pvclock`, `record_steal_time`, `kvm_steal_time_set_preempted`, `kvm_steal_time_reset`, `kvm_arch_vcpu_create`, `kvm_arch_vcpu_destroy`, `kvm_vcpu_reset`, `kvm_xen_shared_info_init`, `xen_get_guest_pvclock`, `kvm_xen_update_runstate_guest`, `kvm_xen_inject_pending_events`, `__kvm_xen_has_interrupt`, `wait_pending_event`, `__kvm_xen_set_evtchn_fast`, `kvm_xen_set_evtchn_fast`, `kvm_xen_init_vcpu`, `kvm_xen_init_vm`, and the GPC-related functions: `gfn_to_pfn_cache_invalidate_start`, `kvm_gpc_check`, `hva_to_pfn_retry`, `__kvm_gpc_refresh`, `kvm_gpc_refresh`, `__kvm_gpc_init`, `__kvm_gpc_activate`, and `kvm_gpc_deactivate`. Interesting... `gfn_to_pfn_cache_invalidate_start` is involved with MMU notifiers. That will require close attention during testing. The rest of the GPC functions reside in `virt/kvm/pfncache.c`. The Xen-specific functions are in `arch/x86/kvm/xen.c`, and the steal time/pvclock functions are in `arch/x86/kvm/x86.c`. Okay, let's see about any specific configurations. I'm obviously going to need KVM enabled (`CONFIG_KVM`). The presence of Xen-related functions suggests `CONFIG_KVM_XEN` might be necessary as well. Time to peek at `arch/x86/kvm/Kconfig` to confirm any dependency details. |
| 4/2 | 2026/08/05 21:19 | tool | grepper |
0mArgs:{
"Expression": "config KVM_XEN",
"PathPrefix": "arch/x86/kvm/Kconfig"
}Results: {
"Output": "arch/x86/kvm/Kconfig=194=config KVM_HYPERV\n--\narch/x86/kvm/Kconfig-207-\narch/x86/kvm/Kconfig:208:config KVM_XEN\narch/x86/kvm/Kconfig-209-\tbool \"Support for Xen hypercall interface\"\n"
} |
| 5/2 | 2026/08/05 21:19 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21622 output: 43 thoughts: 369 Thoughts: **KVM and Xen Configuration Deep Dive** Okay, so I'm digging into this `CONFIG_KVM_XEN` thing. My initial thought is to figure out if simply having `CONFIG_KVM` is sufficient, or if we really *need* to explicitly enable `CONFIG_KVM_XEN`. Based on what I'm seeing, `CONFIG_KVM_XEN` seems to be the right choice here. Now, let's see if there are any other related configurations that warrant attention. `CONFIG_MMU_NOTIFIER` is usually handled implicitly by KVM, so that's likely already taken care of. Next, I'll hone in on some key symbols. I need to understand the relationship between Xen and KVM, so the symbols I'm focusing on are: * `kvm_gpc_check` * `kvm_gpc_refresh` * `kvm_gpc_activate` * `kvm_gpc_deactivate` * `gfn_to_pfn_cache_invalidate_start` * `kvm_xen_set_evtchn_fast` * `kvm_xen_update_runstate_guest` * `kvm_xen_inject_pending_events` * `record_steal_time` * `kvm_steal_time_set_preempted` * `kvm_setup_guest_pvclock` My next step is to quickly determine which of these symbols are global or static. Knowing this is crucial for understanding how they interact with each other and their potential for external use. I am marking `kvm_gpc_check`, `kvm_gpc_refresh`, `kvm_gpc_activate`, `kvm_gpc_deactivate`, `gfn_to_pfn_cache_invalidate_start`, and `kvm_xen_set_evtchn_fast` as exported/global, meaning they are accessible from other parts of the system. I have to quickly double-check the `kvm_xen_update_runstate_guest` symbol to ensure it is not static. |
| 6/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_update_runstate_guest",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=312=static void kvm_xen_stop_timer(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/xen.c-318-\narch/x86/kvm/xen.c:319:static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\narch/x86/kvm/xen.c-320-{\n--\narch/x86/kvm/xen.c=561=void kvm_xen_update_runstate(struct kvm_vcpu *v, int state)\n--\narch/x86/kvm/xen.c-588-\tif (vx-\u003erunstate_cache.active)\narch/x86/kvm/xen.c:589:\t\tkvm_xen_update_runstate_guest(v, state == RUNSTATE_runnable);\narch/x86/kvm/xen.c-590-}\n--\narch/x86/kvm/xen.c=877=int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)\n--\narch/x86/kvm/xen.c-948-\t\t * If the guest switches to 64-bit mode after setting the runstate\narch/x86/kvm/xen.c:949:\t\t * address, that's actually OK. kvm_xen_update_runstate_guest()\narch/x86/kvm/xen.c-950-\t\t * will cope.\n--\narch/x86/kvm/xen.c-975-\narch/x86/kvm/xen.c:976:\t\tkvm_xen_update_runstate_guest(vcpu, false);\narch/x86/kvm/xen.c-977-\t\tbreak;\n--\narch/x86/kvm/xen.c-1071-\t\telse if (vcpu-\u003earch.xen.runstate_cache.active)\narch/x86/kvm/xen.c:1072:\t\t\tkvm_xen_update_runstate_guest(vcpu, false);\narch/x86/kvm/xen.c-1073-\t\tr = 0;\n"
} |
| 7/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23115 output: 42 thoughts: 92 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Refactoring the KVM/Xen Interaction** Right, so I'm looking at `kvm_xen_update_runstate_guest`. It's static, which always raises a flag. We need to trace where it's called from. Looks like `kvm_xen_update_runstate` and `kvm_xen_vcpu_set_attr` are the culprits. Seems like we can replace the guest-specific function call with the calling functions, consolidating logic in those two places. Makes sense from a maintainability perspective, reducing code duplication and centralizing the runstate management. We'll simplify things overall, I'm expecting a cleaner interface, and less chance of unintended consequences from that nested function call. But, hang on, there's `kvm_xen_inject_pending_events`. Need to consider how this change will impact the event injection path. Make sure we didn't break anything there. I need to review how those functions interact and ensure the refactor doesn't introduce any regressions related to those pending events. |
| 8/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_inject_pending_events",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=592=void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v)\n--\narch/x86/kvm/xen.c-612- */\narch/x86/kvm/xen.c:613:void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\narch/x86/kvm/xen.c-614-{\n"
} |
| 9/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23625 output: 39 thoughts: 26 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating KVM/Xen Event Injection and Steal Time** Right, let me see... `kvm_xen_inject_pending_events`... that's a global function, isn't it? A global function suggests it's a critical point of synchronization or interaction across the system. It definitely warrants a closer look – understand where it's being called, under what conditions, and what kind of potential bottlenecks it might introduce. We need to be especially cautious with globals in these environments. Any potential concurrency issues have to be assessed. Now, that's got me thinking... what about `record_steal_time`? That's likely related to how the hypervisor is handling time allocation, right? Steal time is a critical performance indicator in virtualized systems. We're concerned with how much time a VM spends waiting for CPU cycles that are allocated to other VMs. If we're looking at event injection, especially in a KVM/Xen environment, the two could be related. Are these events contributing to an increase in steal time? If we have to inject events, is `record_steal_time` actually capturing it, and are those injected events contributing to increased steal time metrics? Or, perhaps, is event injection being *affected* by steal time? The interplay here is important. We might need to correlate these two areas to get a complete picture of performance. Need to check the call sites for those functions and how they interrelate. |
| 10/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "record_steal_time",
"PathPrefix": "arch/x86/kvm/x86.c"
}Results: {
"Output": "arch/x86/kvm/x86.c=2045=EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_service_local_tlb_flush_requests);\narch/x86/kvm/x86.c-2046-\narch/x86/kvm/x86.c:2047:static void record_steal_time(struct kvm_vcpu *vcpu)\narch/x86/kvm/x86.c-2048-{\n--\narch/x86/kvm/x86.c=2591=static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-2624-\t * cache is invalid, it will be refreshed from task context by\narch/x86/kvm/x86.c:2625:\t * record_steal_time() before the vCPU next enters the guest, since\narch/x86/kvm/x86.c-2626-\t * kvm_arch_vcpu_load() unconditionally raises KVM_REQ_STEAL_UPDATE.\n--\narch/x86/kvm/x86.c=8036=static int vcpu_enter_guest(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-8126-\t\tif (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))\narch/x86/kvm/x86.c:8127:\t\t\trecord_steal_time(vcpu);\narch/x86/kvm/x86.c-8128-\t\tif (kvm_check_request(KVM_REQ_PMU, vcpu))\n"
} |
| 11/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 24488 output: 46 thoughts: 75 Thoughts: Okay, let's break this down. **My Analysis of Steal Time Calculation** Right, so `record_steal_time` is statically defined, that's good to know. It's called specifically from `vcpu_enter_guest`. That seems like the right entry point. This means, as an optimization, we can probably simplify things. Instead of going through all these hoops, the approach I should take is to look at using `kvm_set_msr_common`, because that sets up the steal time correctly, and then call `kvm_arch_vcpu_load`. This feels like it should give us the results we need, and reduce some of the complexity in the process. Now, what about that `kvm_steal_time_set_preempted` function? I need to consider where that fits into the picture. It seems separate, and that I may still need it. I'll need to carefully evaluate its role to make sure that combining this first method with this second doesn't cause any conflicts, or miss any critical data. It's a key function to understand in relation to the new approach. |
| 12/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_steal_time_set_preempted",
"PathPrefix": "arch/x86/kvm/x86.c"
}Results: {
"Output": "arch/x86/kvm/x86.c=2511=void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)\n--\narch/x86/kvm/x86.c-2590-\narch/x86/kvm/x86.c:2591:static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)\narch/x86/kvm/x86.c-2592-{\n--\narch/x86/kvm/x86.c=2647=void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-2667-\t\telse\narch/x86/kvm/x86.c:2668:\t\t\tkvm_steal_time_set_preempted(vcpu);\narch/x86/kvm/x86.c-2669-\t\tsrcu_read_unlock(\u0026vcpu-\u003ekvm-\u003esrcu, idx);\n"
} |
| 13/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 25147 output: 43 thoughts: 59 Thoughts: Here's my summary, as the thought process unfolds: **Thinking Through KVM Timekeeping Updates** Okay, so I'm digging into how we're handling time-related issues with KVM. I remember seeing `kvm_steal_time_set_preempted`, and I recall it's a static function. That also means it can only be called from within the same file, or some included file, right? Let me check where it's called from... Ah, right, it's used inside `kvm_arch_vcpu_put`. That's good; it means we can potentially leverage `kvm_arch_vcpu_put` in our fix. Now, wait a second... what about `kvm_setup_guest_pvclock`? I need to consider that function in relation to this, since it seems related to time too. Let me quickly refresh my memory on the interactions of those two functions. I need to make sure I don't introduce a regression or conflict when updating the former. Okay, let's explore this further. |
| 14/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_setup_guest_pvclock",
"PathPrefix": "arch/x86/kvm/x86.c"
}Results: {
"Output": "arch/x86/kvm/x86.c=1707=u64 get_kvmclock_ns(struct kvm *kvm)\n--\narch/x86/kvm/x86.c-1714-\narch/x86/kvm/x86.c:1715:static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,\narch/x86/kvm/x86.c-1716-\t\t\t\t struct kvm_vcpu *vcpu,\n--\narch/x86/kvm/x86.c=1762=int kvm_guest_time_update(struct kvm_vcpu *v)\n--\narch/x86/kvm/x86.c-1859-\t\t}\narch/x86/kvm/x86.c:1860:\t\tkvm_setup_guest_pvclock(\u0026hv_clock, v, \u0026vcpu-\u003epv_time, 0);\narch/x86/kvm/x86.c-1861-\n--\narch/x86/kvm/x86.c-1879-\tif (vcpu-\u003exen.vcpu_info_cache.active)\narch/x86/kvm/x86.c:1880:\t\tkvm_setup_guest_pvclock(\u0026hv_clock, v, \u0026vcpu-\u003exen.vcpu_info_cache,\narch/x86/kvm/x86.c-1881-\t\t\t\t\toffsetof(struct compat_vcpu_info, time));\narch/x86/kvm/x86.c-1882-\tif (vcpu-\u003exen.vcpu_time_info_cache.active)\narch/x86/kvm/x86.c:1883:\t\tkvm_setup_guest_pvclock(\u0026hv_clock, v, \u0026vcpu-\u003exen.vcpu_time_info_cache, 0);\narch/x86/kvm/x86.c-1884-#endif\n"
} |
| 15/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 26017 output: 43 thoughts: 212 Thoughts: **My Analysis of KVM Timekeeping and Xen Integration** Okay, let's break this down. It looks like we're zeroing in on the interaction between KVM's guest timekeeping and its integration with Xen. I see that `kvm_setup_guest_pvclock` is static and called from `kvm_guest_time_update`. This is key. The implication is that we can leverage `kvm_guest_time_update` as the central point. That shifts the focus for me. These symbols are particularly interesting now: * `kvm_gpc_check`, `kvm_gpc_refresh`, `kvm_gpc_activate`, `kvm_gpc_deactivate`: These are obviously involved in the Guest Physical Clock (GPC) management, the core of the pvclock implementation within KVM. * `gfn_to_pfn_cache_invalidate_start`: This cache invalidation function is one to understand, as it is a point where the mapping from Guest Frame Number (GFN) to Physical Frame Number (PFN) gets updated and requires synchronization. It's related to memory and can impact timing significantly. * `kvm_xen_set_evtchn_fast`, `kvm_xen_update_runstate`, `kvm_xen_vcpu_set_attr`, `kvm_xen_inject_pending_events`: These functions reveal how KVM interfaces with Xen's event channels and vCPU management. This is what helps in orchestrating the guest within a Xen environment. * `kvm_arch_vcpu_put`: This is the vCPU management, which is how we manage vCPUs in KVM. * `kvm_guest_time_update`: This is the main one that we are focusing on and is the central part. * `kvm_set_msr_common`: This indicates the setting of Model Specific Registers (MSRs) which might be pivotal for pvclock. My first check will be `gfn_to_pfn_cache_invalidate_start`. Understanding how and when this cache is invalidated is crucial to ensure time updates are reflected correctly. This would likely involve further analysis to ensure data integrity and avoid time jumps or drifts. |
| 16/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "gfn_to_pfn_cache_invalidate_start",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c-24- */\nvirt/kvm/pfncache.c:25:void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start,\nvirt/kvm/pfncache.c-26-\t\t\t\t unsigned long end)\n"
} |
| 17/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 26854 output: 37 thoughts: 89 Thoughts: Here's my thought process, as it stands: **Navigating Global vs. Static Scope in KVM Memory Management** Okay, so I'm digging into this code and my first thought is, "Hang on, `gfn_to_pfn_cache_invalidate_start`... that's global, isn't it?" This immediately triggers a concern about potential scope-related issues. I need to understand its impact and where it's being used across the system. Now, let's back off from that for a minute. Let me shift my focus to a few related functions. I know that `__kvm_gpc_refresh` and `hva_to_pfn_retry` are declared `static`. That's good; a limited scope implies less coupling. They are less of a concern for now. However, `kvm_gpc_refresh` is global. That means it might be accessible and modified from anywhere. I need to understand the relationship between these functions, and if the refresh has any relation to the cache invalidation. Finally, I need to look at initialization routines. Let's see how `__kvm_gpc_init` and `kvm_gpc_init` fit into all this. The initialization might shed light on how global variables are set up and how they interact with each other. This is all about getting a holistic view of the system's memory management. |
| 18/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_gpc_init",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c=435=int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len)\n--\nvirt/kvm/pfncache.c-453-\nvirt/kvm/pfncache.c:454:void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,\nvirt/kvm/pfncache.c-455-\t\t bool never_dirty)\n"
} |
| 19/2 | 2026/08/05 21:20 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 27428 output: 42 thoughts: 30 Thoughts: Here's my summary, as though I'm thinking through this process: **Diving into KVM Initialization** Okay, so `__kvm_gpc_init` is a global function, which means it's pretty fundamental to the overall KVM initialization process. I should probably understand its role to grasp the broader picture. Let's trace through its dependencies and understand how it interfaces with other core components. Given the global scope, I'm expecting it to establish some critical base state. Now, let me shift gears. I need to understand this process in a bigger context. Let's see how `kvm_xen_shared_info_init` factors in. Its name suggests it has something to do with initialization of shared information with Xen. I want to check its interplay with this global function. This might be a critical section of the code and I need to understand it in the context of the larger KVM ecosystem. I'm curious if this shared info is global as well. |
| 20/2 | 2026/08/05 21:20 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_shared_info_init",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=37=DEFINE_STATIC_KEY_DEFERRED_FALSE(kvm_xen_enabled, HZ);\narch/x86/kvm/xen.c-38-\narch/x86/kvm/xen.c:39:static int kvm_xen_shared_info_init(struct kvm *kvm)\narch/x86/kvm/xen.c-40-{\n--\narch/x86/kvm/xen.c=717=int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)\n--\narch/x86/kvm/xen.c-736-\t\t\tr = kvm-\u003earch.xen.shinfo_cache.active ?\narch/x86/kvm/xen.c:737:\t\t\t\tkvm_xen_shared_info_init(kvm) : 0;\narch/x86/kvm/xen.c-738-\t\t\tmutex_unlock(\u0026kvm-\u003earch.xen.xen_lock);\n--\narch/x86/kvm/xen.c-776-\t\tif (!r \u0026\u0026 kvm-\u003earch.xen.shinfo_cache.active)\narch/x86/kvm/xen.c:777:\t\t\tr = kvm_xen_shared_info_init(kvm);\narch/x86/kvm/xen.c-778-\n--\narch/x86/kvm/xen.c=1249=int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)\n--\narch/x86/kvm/xen.c-1265-\t\tif (kvm-\u003earch.xen.shinfo_cache.active \u0026\u0026\narch/x86/kvm/xen.c:1266:\t\t kvm_xen_shared_info_init(kvm))\narch/x86/kvm/xen.c-1267-\t\t\tr = 1;\n"
} |
| 21/2 | 2026/08/05 21:20 | llm | patch-evaluator |
5mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 28231 output: 40 thoughts: 75 Thoughts: Okay, let's break this down. **Analyzing KVM-Xen Integration** Right, so `kvm_xen_shared_info_init` is a static function. That's good to know. It's called internally by `kvm_xen_hvm_set_attr` and `kvm_xen_write_hypercall_page`. Now, seeing as it's static, it makes sense to focus on the points of invocation. It seems like using `kvm_xen_hvm_set_attr` is a reasonable starting point for my investigation. I'll see what I can learn there. Now, let's shift gears a little bit. I need to look into how the guest pvclock information is being accessed. The next thing I need to investigate is `xen_get_guest_pvclock`. |
| 22/2 | 2026/08/05 21:26 | tool | grepper |
0mArgs:{
"Expression": "xen_get_guest_pvclock",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=124=static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)\n--\narch/x86/kvm/xen.c-151-\narch/x86/kvm/xen.c:152:static int xen_get_guest_pvclock(struct kvm_vcpu *vcpu,\narch/x86/kvm/xen.c-153-\t\t\t\t struct pvclock_vcpu_time_info *hv_clock,\n--\narch/x86/kvm/xen.c=184=static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs,\n--\narch/x86/kvm/xen.c-224-\t\tif (xen-\u003evcpu_info_cache.active)\narch/x86/kvm/xen.c:225:\t\t\tr = xen_get_guest_pvclock(vcpu, \u0026hv_clock, \u0026xen-\u003evcpu_info_cache,\narch/x86/kvm/xen.c-226-\t\t\t\t\t\t offsetof(struct compat_vcpu_info, time));\narch/x86/kvm/xen.c-227-\t\tif (r \u0026\u0026 xen-\u003evcpu_time_info_cache.active)\narch/x86/kvm/xen.c:228:\t\t\tr = xen_get_guest_pvclock(vcpu, \u0026hv_clock, \u0026xen-\u003evcpu_time_info_cache, 0);\narch/x86/kvm/xen.c-229-\t\tif (r)\n"
} |
| 23/2 | 2026/08/05 21:26 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 28945 output: 37 thoughts: 89 Thoughts: **Analyzing the Xen-KVM Interaction** Okay, so I'm looking at how Xen and KVM are talking to each other, specifically the virtual clock synchronization. I see that `xen_get_guest_pvclock` is defined as `static`. This is interesting, meaning it has internal linkage and is only accessible within the current compilation unit. It's called from `kvm_xen_start_timer`. That function, `kvm_xen_start_timer`, is also static. I'm noting the call chain here. It's invoked by `kvm_xen_vcpu_set_attr` and `kvm_xen_hypercall`. Now, if I'm understanding this correctly, my best bet for interacting with this mechanism appears to be `kvm_xen_hypercall`. I'll need to explore that further to see what options it gives me. Next step: I should take a look at `wait_pending_event`. That might provide some insight into the synchronization points, or any pending events that need to be handled during the clock updates. |
| 24/2 | 2026/08/05 21:26 | tool | grepper |
0mArgs:{
"Expression": "wait_pending_event",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=1398=static inline int max_evtchn_port(struct kvm *kvm)\n--\narch/x86/kvm/xen.c-1405-\narch/x86/kvm/xen.c:1406:static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,\narch/x86/kvm/xen.c-1407-\t\t\t evtchn_port_t *ports)\n--\narch/x86/kvm/xen.c=1443=static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool longmode,\n--\narch/x86/kvm/xen.c-1516-\narch/x86/kvm/xen.c:1517:\tif (!wait_pending_event(vcpu, sched_poll.nr_ports, ports)) {\narch/x86/kvm/xen.c-1518-\t\tkvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED);\n"
} |
| 25/2 | 2026/08/05 21:26 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 29595 output: 44 thoughts: 85 Thoughts: Here's my thought process, distilled: **Tracing the Call Path: Finding the Entry Point** Okay, so I'm looking at this code and need to understand the control flow. The `wait_pending_event` function seems to be a static function, and it's getting called by `kvm_xen_schedop_poll`. Right, `kvm_xen_schedop_poll` is also static, and it's called from `kvm_xen_hypercall`. That means `kvm_xen_hypercall` is probably the key entry point I want to focus on. It sits higher up in the call stack, so understanding it will give me the broader context. Let's see what's happening there. I will look at that function next. Before I dive too deep into that though, let me check `__kvm_xen_set_evtchn_fast`, to make sure nothing important is happening there first. |
| 26/2 | 2026/08/05 21:26 | tool | grepper |
0mArgs:{
"Expression": "__kvm_xen_set_evtchn_fast",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=1750=static void kvm_xen_check_poller(struct kvm_vcpu *vcpu, int port)\n--\narch/x86/kvm/xen.c-1761-/* Called with kvm-\u003esrcu held, as kvm_gpc_check() consults the memslots. */\narch/x86/kvm/xen.c:1762:static void __kvm_xen_set_evtchn_fast(struct kvm_vcpu *vcpu, int port_word_bit)\narch/x86/kvm/xen.c-1763-{\n--\narch/x86/kvm/xen.c=1832=int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)\n--\narch/x86/kvm/xen.c-1892-\tif (rc == 1)\narch/x86/kvm/xen.c:1893:\t\t__kvm_xen_set_evtchn_fast(vcpu, port_word_bit);\narch/x86/kvm/xen.c-1894-\n"
} |
| 27/2 | 2026/08/05 21:26 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 30242 output: 43 thoughts: 50 Thoughts: Here's my analysis of the provided snippet, framed as my own thought process: **Diving into the KVM/Xen Event Channel Setup** Alright, so `__kvm_xen_set_evtchn_fast` is a static function, which immediately tells me it's likely an internal helper function. The fact that it's called from `kvm_xen_set_evtchn_fast` is a useful hint. This suggests a modular design; the main function, `kvm_xen_set_evtchn_fast`, probably handles some initial setup or error checking, and then calls this "fast" function for the core operation of setting up the event channel. Given that it's labelled 'fast', I bet it's optimized for the common case. I need to take a look at `kvm_xen_set_evtchn_fast` to understand its role and how `__kvm_xen_set_evtchn_fast` fits in. Time to go spelunking in the code. |
| 28/2 | 2026/08/05 21:26 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_set_evtchn_fast",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=124=static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)\n--\narch/x86/kvm/xen.c-138-\narch/x86/kvm/xen.c:139:\trc = kvm_xen_set_evtchn_fast(\u0026e, vcpu-\u003ekvm);\narch/x86/kvm/xen.c-140-\tif (rc != -EWOULDBLOCK) {\n--\narch/x86/kvm/xen.c=1750=static void kvm_xen_check_poller(struct kvm_vcpu *vcpu, int port)\n--\narch/x86/kvm/xen.c-1761-/* Called with kvm-\u003esrcu held, as kvm_gpc_check() consults the memslots. */\narch/x86/kvm/xen.c:1762:static void __kvm_xen_set_evtchn_fast(struct kvm_vcpu *vcpu, int port_word_bit)\narch/x86/kvm/xen.c-1763-{\n--\narch/x86/kvm/xen.c-1831- */\narch/x86/kvm/xen.c:1832:int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)\narch/x86/kvm/xen.c-1833-{\n--\narch/x86/kvm/xen.c-1892-\tif (rc == 1)\narch/x86/kvm/xen.c:1893:\t\t__kvm_xen_set_evtchn_fast(vcpu, port_word_bit);\narch/x86/kvm/xen.c-1894-\n--\narch/x86/kvm/xen.c=1900=static int kvm_xen_set_evtchn(struct kvm_xen_evtchn *xe, struct kvm *kvm)\n--\narch/x86/kvm/xen.c-1904-\narch/x86/kvm/xen.c:1905:\trc = kvm_xen_set_evtchn_fast(xe, kvm);\narch/x86/kvm/xen.c-1906-\tif (rc != -EWOULDBLOCK)\n--\narch/x86/kvm/xen.c-1938-\narch/x86/kvm/xen.c:1939:\t\trc = kvm_xen_set_evtchn_fast(xe, kvm);\narch/x86/kvm/xen.c-1940-\t\tif (rc != -EWOULDBLOCK)\n"
} |
| 29/2 | 2026/08/05 21:26 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 31273 output: 41 thoughts: 32 Thoughts: Okay, here's my take on those thoughts, framed from an expert's perspective: **Diving into the KVM/Xen Interrupt Handling** Right, `kvm_xen_set_evtchn_fast`... that's a global function, isn't it? Meaning it's potentially accessed and modified from various contexts, which immediately raises a flag for potential synchronization challenges and performance bottlenecks. I need to be mindful of that. My next thought is to investigate that `__kvm_xen_has_interrupt` function. I need to understand its role. Is it a helper? A check to see if an interrupt is pending? Does it indicate the interrupt status for a specific vCPU or a global state? It's essential to grasp how it interacts with `kvm_xen_set_evtchn_fast` because their interplay is critical for efficient and correct virtualized interrupt delivery, especially in the Xen environment. I'll need to trace the code path to understand its usage and possible data races. |
| 30/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "__kvm_xen_has_interrupt",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=613=void kvm_xen_inject_pending_events(struct kvm_vcpu *v)\n--\narch/x86/kvm/xen.c-668-\narch/x86/kvm/xen.c:669:int __kvm_xen_has_interrupt(struct kvm_vcpu *v)\narch/x86/kvm/xen.c-670-{\n"
} |
| 31/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 31689 output: 41 thoughts: 41 Thoughts: Okay, here's my interpretation of those thoughts, framed as my own: **Analyzing Xen-KVM Interrupt Handling** Right, so `__kvm_xen_has_interrupt` is a global variable, which immediately piques my interest. Global variables always require careful consideration in any system, especially a hypervisor like Xen-KVM. They can be a source of synchronization issues and make it difficult to reason about code flow. I need to understand its role and how it's used. My immediate next step is to trace its initialization and usage. Where better to start than the core initialization functions? Let's dive into `kvm_xen_init_vcpu` and `kvm_xen_init_vm`. Understanding how the virtual CPUs and the virtual machine itself are set up will likely reveal how and when `__kvm_xen_has_interrupt` gets its value and how it's used to manage interrupt handling within the Xen-KVM environment. I suspect these functions hold the key to understanding the interrupt delivery mechanism. I'll need to look for related code such as interrupt controller configuration. |
| 32/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_init_vcpu",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=2264=static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r)\n--\narch/x86/kvm/xen.c-2298-\narch/x86/kvm/xen.c:2299:void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu)\narch/x86/kvm/xen.c-2300-{\n"
} |
| 33/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 32153 output: 40 thoughts: 29 Thoughts: Here's my take on the thought process, as if it were my own: **Initial Assessment: KVM/Xen Interaction** Okay, so `kvm_xen_init_vcpu` is a global function. That's a key observation. Now, I need to understand how the KVM and Xen layers are initializing the virtual CPUs in their interaction. The structure of the virtualization environment is often quite complex, and it's essential to pinpoint where initialization occurs. Given that it's global, it suggests a central point of control. It will be helpful to understand its relationship with other functions. Therefore, my next logical step is to dive into `kvm_xen_init_vm`. Understanding how the virtual machine (VM) itself is initialized in the hybrid environment is probably going to provide important context. This may illuminate the role `kvm_xen_init_vcpu` plays in the broader scheme of things. |
| 34/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_init_vm",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=2314=void kvm_xen_destroy_vcpu(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/xen.c-2326-\narch/x86/kvm/xen.c:2327:void kvm_xen_init_vm(struct kvm *kvm)\narch/x86/kvm/xen.c-2328-{\n"
} |
| 35/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 32545 output: 42 thoughts: 390 Thoughts: **My Current Thinking on KVM/Xen Integration Points** Okay, so I'm looking at how KVM and Xen interact, specifically where we might find relevant code for analysis. I know that `kvm_xen_init_vm` is a global entry point, which is a good starting point. I should also check the VCPU creation and destruction functions, `kvm_arch_vcpu_create` and `kvm_arch_vcpu_destroy` – they’re global too. And, of course, `kvm_vcpu_reset`, also global. So, here's a refined list of functions that seem particularly relevant and potentially less broad: * `kvm_gpc_check` * `kvm_gpc_refresh` * `kvm_gpc_activate` * `kvm_gpc_deactivate` * `gfn_to_pfn_cache_invalidate_start` * `kvm_xen_set_evtchn_fast` * `kvm_xen_update_runstate` * `kvm_xen_vcpu_set_attr` * `kvm_xen_inject_pending_events` * `kvm_guest_time_update` * `kvm_set_msr_common` * `kvm_arch_vcpu_put` * `kvm_xen_hypercall` * `__kvm_xen_has_interrupt` Wait, hang on a second. `kvm_set_msr_common`... that’s a *very* hot path. It handles all Machine Specific Registers (MSRs), which is a huge area. It might be too general to provide a useful starting point. And `kvm_arch_vcpu_load`, which calls `record_steal_time`, is also high-traffic. So, let's refine this. Let's focus on `kvm_guest_time_update` and `kvm_arch_vcpu_put` - hopefully they capture some relevant behavior without being too general. Is there another way to get steal time? Ah, yes. `kvm_set_msr_common` *does* handle `MSR_KVM_STEAL_TIME`, after all. Let's check `kvm_set_msr_common`. |
| 36/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_set_msr_common",
"PathPrefix": "arch/x86/kvm/msrs.c"
}Results: {
"Output": "arch/x86/kvm/msrs.c=1436=static inline u64 kvm_guest_supported_xfd(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/msrs.c-1441-\narch/x86/kvm/msrs.c:1442:int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)\narch/x86/kvm/msrs.c-1443-{\n--\narch/x86/kvm/msrs.c-1851-}\narch/x86/kvm/msrs.c:1852:EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_set_msr_common);\narch/x86/kvm/msrs.c-1853-\n"
} |
| 37/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 33743 output: 37 thoughts: 332 Thoughts: **Reflecting on KVM Steal Time and Xen Integration** Okay, so I'm thinking about how to handle steal time in this KVM context. Right now, `kvm_set_msr_common` seems to be the only option, even though it's a performance hotspot. I wonder if there's a more efficient path, maybe incorporating `kvm_xen_hvm_set_attr` since it calls `kvm_xen_shared_info_init`. That might be a better approach. Let me refine my list of focus symbols to optimize things. I've got a growing list: `kvm_gpc_check`, `kvm_gpc_refresh`, `kvm_gpc_activate`, `kvm_gpc_deactivate`, `gfn_to_pfn_cache_invalidate_start`, `kvm_xen_set_evtchn_fast`, `kvm_xen_update_runstate`, `kvm_xen_vcpu_set_attr`, `kvm_xen_hvm_set_attr`, `kvm_xen_inject_pending_events`, `kvm_xen_hypercall`, `__kvm_xen_has_interrupt`, and `kvm_guest_time_update`. Hold on, I'm noticing something about `kvm_gpc_check`. It seems to be called incredibly frequently. I see it's triggered from `kvm_xen_update_runstate_guest`, which is, in turn, called by `kvm_arch_vcpu_put` and `kvm_arch_vcpu_load`. Is this a performance bottleneck? It's kind of an inline-like helper, but it's also exported. I should probably check if it's actually exported. That might be the source of some pain here. |
| 38/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_gpc_check",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c=74=static bool kvm_gpc_is_valid_len(gpa_t gpa, unsigned long uhva,\n--\nvirt/kvm/pfncache.c-86-\nvirt/kvm/pfncache.c:87:bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len)\nvirt/kvm/pfncache.c-88-{\n--\nvirt/kvm/pfncache.c-91-\tRCU_LOCKDEP_WARN(!rcu_read_lock_held(),\nvirt/kvm/pfncache.c:92:\t\t\t \"kvm_gpc_check() without RCU read lock\");\nvirt/kvm/pfncache.c-93-\n--\nvirt/kvm/pfncache.c=182=static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n--\nvirt/kvm/pfncache.c-250-\t/*\nvirt/kvm/pfncache.c:251:\t * Publish. Pairs with the smp_load_acquire() in kvm_gpc_check();\nvirt/kvm/pfncache.c-252-\t * the pfn/khva stores above must be visible before valid is.\n--\nvirt/kvm/pfncache.c=269=static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva)\n--\nvirt/kvm/pfncache.c-298-\t * period to wait for. At most the memslot generation needs updating,\nvirt/kvm/pfncache.c:299:\t * which no reader consults except via kvm_gpc_check() itself.\nvirt/kvm/pfncache.c-300-\t *\n--\nvirt/kvm/pfncache.c-303-\t * - gpc-\u003evalid: the PFN and its kernel mapping are still good.\nvirt/kvm/pfncache.c:304:\t * - the resolved uHVA is unchanged. kvm_gpc_check() validates\nvirt/kvm/pfncache.c-305-\t * 'offset + len \u003c= PAGE_SIZE' from gpc-\u003euhva/gpa on the reader's\n--\nvirt/kvm/pfncache.c-337-\t\t\t * to do so; only the memslot generation, which is\nvirt/kvm/pfncache.c:338:\t\t\t * read solely by kvm_gpc_check(), may need updating.\nvirt/kvm/pfncache.c-339-\t\t\t */\n"
} |
| 39/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 35204 output: 41 thoughts: 65 Thoughts: **Examining the Visibility of a KVM Function** Okay, so I'm looking at this function and immediately I see it's not explicitly exported using `EXPORT_SYMBOL`. That's a key detail. The code is located in `virt/kvm/pfncache.c`, which rings a bell. Ah, yes, that source file gets compiled into `kvm.ko`. Given that it's within `kvm.ko`, and it isn't explicitly exported, I need to verify that it *isn't* exposed as a symbol from the KVM module. Let's confirm that. |
| 40/2 | 2026/08/05 21:27 | tool | grepper |
0mError:no matches Args: {
"Expression": "EXPORT_SYMBOL.*kvm_gpc_check",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"error": "no matches"
} |
| 41/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 35455 output: 40 thoughts: 38 Thoughts: Okay, here's my interpretation of those thoughts, summarized from a first-person expert perspective: **Internal KVM Scope and Function Visibility** Alright, so I'm thinking about the scope of this particular function. It seems it's *not* designed to be exposed outside the core KVM module itself. It's essentially global within the KVM context. But, hold on a second... `kvm_gpc_check` is actually exported? That's a bit unexpected. I need to understand why it's made available for internal KVM use. I need to trace its usage within the KVM project itself. It could be for a specific architecture or feature set. |
| 42/2 | 2026/08/05 21:27 | tool | grepper |
0mError:no matches Args: {
"Expression": "EXPORT_SYMBOL.*kvm_gpc_",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"error": "no matches"
} |
| 43/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 35692 output: 29 thoughts: 36 Thoughts: Here's my analysis of the situation: **Investigating the KVM PFN Cache** Okay, so I'm looking at `virt/kvm/pfncache.c`. I need to figure out how this component fits into the overall KVM (Kernel-based Virtual Machine) module ecosystem. My initial thought is that `pfncache.c` is probably compiled into `kvm.ko`. To confirm this, I need to check the build process. I'll need to dive into the `virt/kvm/Makefile` file. That's where all the dependencies and compilation targets should be defined. Knowing the Makefile structure is key to understanding how these pieces are assembled. Let's see what the makefile reveals! |
| 44/2 | 2026/08/05 21:27 | tool | grepper |
0mError:no matches Args: {
"Expression": "pfncache",
"PathPrefix": "virt/kvm/Makefile"
}Results: {
"error": "no matches"
} |
| 45/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 35927 output: 28 thoughts: 13 Thoughts: Okay, here's my summary, taking the perspective of someone deeply familiar with kernel internals and build systems: **Where Did That Go? Investigating the Compilation of `pfncache.c`** Alright, hold on a second. I'm just running through the mental checklist of my current project, and I've hit a snag. I'm looking at some code that interacts with the page frame number cache, and I need to understand its compilation process. Specifically, I'm thinking about `pfncache.c`. But... where is that thing actually compiled? It's a fundamental part of the memory management subsystem, so it *should* be linked in with a core set of files, but I'm drawing a blank on the exact build target and the source tree location at this moment. I need to quickly identify the Makefile or build script responsible for compiling this file, tracing dependencies, and ensuring that everything's configured correctly. This information is crucial for any modifications or debugging I'll be doing. Time to dig in and re-familiarize myself with the build system and module dependencies. |
| 46/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "pfncache",
"PathPrefix": "virt/kvm/"
}Results: {
"Output": "virt/kvm/Makefile.kvm=13=kvm-$(CONFIG_HAVE_KVM_DIRTY_RING) += $(KVM)/dirty_ring.o\nvirt/kvm/Makefile.kvm:14:kvm-$(CONFIG_HAVE_KVM_PFNCACHE) += $(KVM)/pfncache.o\nvirt/kvm/Makefile.kvm-15-kvm-$(CONFIG_KVM_GUEST_MEMFD) += $(KVM)/guest_memfd.o\n"
} |
| 47/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 36332 output: 39 thoughts: 262 Thoughts: **Analyzing the KVM Makefile** Okay, so I'm looking at `Makefile.kvm` and it's clear this is all related to `kvm.ko`. My initial thought is that these functions within the KVM module are global, which means syzkaller *could* fuzz them directly, either because they're baked into `vmlinux` or because we can specify them as targets. Wait a second, syzkaller is smarter than I initially gave it credit for. It can fuzz *any* function that’s in `vmlinux` or any loadable module, which is a key realization! Now, even though `kvm_gpc_check` is probably a good target in terms of frequency, the fact it’s so frequently called likely means that it's probably pretty thoroughly tested. It might be better to zero in on setup functions that could have a higher impact if they have bugs: * `kvm_gpc_refresh` * `kvm_gpc_activate` * `kvm_gpc_deactivate` * `gfn_to_pfn_cache_invalidate_start` * `kvm_xen_set_evtchn_fast` * `kvm_xen_update_runstate` * `kvm_xen_vcpu_set_attr` * `kvm_xen_hvm_set_attr` * `kvm_xen_inject_pending_events` * `kvm_xen_hypercall` * `__kvm_xen_has_interrupt` * `kvm_guest_time_update` My instinct is to start with `kvm_xen_hypercall`. Let's see if it's declared global – that will be the determining factor. |
| 48/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_hypercall",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=1249=int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)\n--\narch/x86/kvm/xen.c-1279-\t */\narch/x86/kvm/xen.c:1280:\tif (kvm_xen_hypercall_enabled(kvm)) {\narch/x86/kvm/xen.c-1281-\t\tu8 instructions[32];\n--\narch/x86/kvm/xen.c=1335=int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc)\n--\narch/x86/kvm/xen.c-1381-\narch/x86/kvm/xen.c:1382:static int kvm_xen_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)\narch/x86/kvm/xen.c-1383-{\n--\narch/x86/kvm/xen.c-1387-\narch/x86/kvm/xen.c:1388:static int kvm_xen_hypercall_complete_userspace(struct kvm_vcpu *vcpu)\narch/x86/kvm/xen.c-1389-{\n--\narch/x86/kvm/xen.c-1394-\narch/x86/kvm/xen.c:1395:\treturn kvm_xen_hypercall_set_result(vcpu, run-\u003exen.u.hcall.result);\narch/x86/kvm/xen.c-1396-}\n--\narch/x86/kvm/xen.c=1635=static bool kvm_xen_hcall_set_timer_op(struct kvm_vcpu *vcpu, uint64_t timeout,\n--\narch/x86/kvm/xen.c-1649-\narch/x86/kvm/xen.c:1650:int kvm_xen_hypercall(struct kvm_vcpu *vcpu)\narch/x86/kvm/xen.c-1651-{\n--\narch/x86/kvm/xen.c-1686-\tcpl = kvm_x86_call(get_cpl)(vcpu);\narch/x86/kvm/xen.c:1687:\ttrace_kvm_xen_hypercall(cpl, input, params[0], params[1], params[2],\narch/x86/kvm/xen.c-1688-\t\t\t\tparams[3], params[4], params[5]);\n--\narch/x86/kvm/xen.c-1728-\tif (handled)\narch/x86/kvm/xen.c:1729:\t\treturn kvm_xen_hypercall_set_result(vcpu, r);\narch/x86/kvm/xen.c-1730-\n--\narch/x86/kvm/xen.c-1744-\tvcpu-\u003earch.complete_userspace_io =\narch/x86/kvm/xen.c:1745:\t\tkvm_xen_hypercall_complete_userspace;\narch/x86/kvm/xen.c-1746-\n"
} |
| 49/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 37914 output: 42 thoughts: 29 Thoughts: Okay, here's my take on those thoughts, framed as my own: **Analyzing `kvm_xen_hypercall` and Related Functions** Alright, so the first thing that pops into my head is confirming that `kvm_xen_hypercall` really *is* a global variable. Yep, that rings true. Now, given that, my next line of inquiry is naturally going to be directed at `kvm_guest_time_update`. I need to understand how this global variable interacts with time management within the KVM/Xen environment. I'm thinking about the implications of a global variable in this context, potential race conditions, and how `kvm_guest_time_update` might be impacted by or impact `kvm_xen_hypercall`. I want to dig into the timing specifics. Let's see what's what. |
| 50/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_guest_time_update",
"PathPrefix": "arch/x86/kvm/x86.c"
}Results: {
"Output": "arch/x86/kvm/x86.c=1715=static void kvm_setup_guest_pvclock(struct pvclock_vcpu_time_info *ref_hv_clock,\n--\narch/x86/kvm/x86.c-1761-\narch/x86/kvm/x86.c:1762:int kvm_guest_time_update(struct kvm_vcpu *v)\narch/x86/kvm/x86.c-1763-{\n--\narch/x86/kvm/x86.c=4300=static int kvm_vm_ioctl_set_clock(struct kvm *kvm, void __user *argp)\n--\narch/x86/kvm/x86.c-4320-\t/*\narch/x86/kvm/x86.c:4321:\t * This pairs with kvm_guest_time_update(): when masterclock is\narch/x86/kvm/x86.c-4322-\t * in use, we use master_kernel_ns + kvmclock_offset to set\n--\narch/x86/kvm/x86.c=8036=static int vcpu_enter_guest(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/x86.c-8072-\t\tif (kvm_check_request(KVM_REQ_CLOCK_UPDATE, vcpu)) {\narch/x86/kvm/x86.c:8073:\t\t\tr = kvm_guest_time_update(vcpu);\narch/x86/kvm/x86.c-8074-\t\t\tif (unlikely(r))\n"
} |
| 51/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 38622 output: 43 thoughts: 33 Thoughts: Okay, here's my interpretation of those thoughts, presented as a first-person expert summary: **Analyzing Global Variables and Xen Interaction** Right, so I'm thinking about `kvm_guest_time_update`. Yes, I'm pretty sure that one's a global, which, as we know, always warrants careful consideration due to potential race conditions and impacts across the entire system. Gotta keep that in mind when dealing with time-related mechanisms; these are often sensitive areas. Now, let's pivot and take a look at `kvm_xen_hvm_set_attr`. I need to refresh my memory on how that function specifically interacts with the Xen hypervisor within a KVM environment. It's crucial to understand how attributes are being set and managed here. I need to understand this to determine how it is impacting the updates, considering the global. Any interaction needs to be precise, or we are inviting errors. |
| 52/2 | 2026/08/05 21:27 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_hvm_set_attr",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=669=int __kvm_xen_has_interrupt(struct kvm_vcpu *v)\n--\narch/x86/kvm/xen.c-716-\narch/x86/kvm/xen.c:717:int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)\narch/x86/kvm/xen.c-718-{\n"
} |
| 53/2 | 2026/08/05 21:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 39035 output: 43 thoughts: 36 Thoughts: Okay, here's my interpretation of those thoughts, presented as a personal thought process, as requested: **Assessing Attribute Setting in the KVM/Xen Context** Alright, so the first thing that pops into my head is that `kvm_xen_hvm_set_attr`... yeah, that one's definitely a global operation. We're talking about something that's likely affecting the overall HVM (Hardware Virtual Machine) configuration, so makes sense it's a global function. Now, my next line of inquiry has to be about how we are setting the attributes on the vCPU's. I need to now turn my attention to investigate the characteristics of `kvm_xen_vcpu_set_attr`. I need to figure out how it works, what it does, and how that interacts with the overall KVM/Xen system. Let's see how that one fits into the picture. |
| 54/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_vcpu_set_attr",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=822=int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)\n--\narch/x86/kvm/xen.c-876-\narch/x86/kvm/xen.c:877:int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)\narch/x86/kvm/xen.c-878-{\n"
} |
| 55/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 39466 output: 41 thoughts: 34 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing `kvm_xen_vcpu_set_attr` and Related Functionality** Alright, so the initial thought lands on the global nature of `kvm_xen_vcpu_set_attr`. Right, that's an important point to immediately register, since globals can often be a source of contention or potential synchronization issues in complex systems. We'll need to keep that in mind as we delve deeper. Given that concern, the natural next step is to examine the implications of any state changes that can occur in concert with its use. Specifically, I'll need to double-check the behavior of `kvm_xen_update_runstate` relative to `kvm_xen_vcpu_set_attr`. I'll need to mentally trace the control flow and consider whether there's any risk of race conditions or data inconsistencies. Does `update_runstate` provide sufficient protection or serialization? Are there any potential ABA problems lurking? Does this involve a critical section with the use of a mutex, read-write lock, or atomic variables? I'll probably need to consult the code to confirm my initial hypothesis on its global nature. |
| 56/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "kvm_xen_update_runstate",
"PathPrefix": "arch/x86/kvm/xen.c"
}Results: {
"Output": "arch/x86/kvm/xen.c=312=static void kvm_xen_stop_timer(struct kvm_vcpu *vcpu)\n--\narch/x86/kvm/xen.c-318-\narch/x86/kvm/xen.c:319:static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)\narch/x86/kvm/xen.c-320-{\n--\narch/x86/kvm/xen.c-560-\narch/x86/kvm/xen.c:561:void kvm_xen_update_runstate(struct kvm_vcpu *v, int state)\narch/x86/kvm/xen.c-562-{\n--\narch/x86/kvm/xen.c-588-\tif (vx-\u003erunstate_cache.active)\narch/x86/kvm/xen.c:589:\t\tkvm_xen_update_runstate_guest(v, state == RUNSTATE_runnable);\narch/x86/kvm/xen.c-590-}\n--\narch/x86/kvm/xen.c=877=int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)\n--\narch/x86/kvm/xen.c-948-\t\t * If the guest switches to 64-bit mode after setting the runstate\narch/x86/kvm/xen.c:949:\t\t * address, that's actually OK. kvm_xen_update_runstate_guest()\narch/x86/kvm/xen.c-950-\t\t * will cope.\n--\narch/x86/kvm/xen.c-975-\narch/x86/kvm/xen.c:976:\t\tkvm_xen_update_runstate_guest(vcpu, false);\narch/x86/kvm/xen.c-977-\t\tbreak;\n--\narch/x86/kvm/xen.c-988-\narch/x86/kvm/xen.c:989:\t\tkvm_xen_update_runstate(vcpu, data-\u003eu.runstate.state);\narch/x86/kvm/xen.c-990-\t\tr = 0;\n--\narch/x86/kvm/xen.c-1069-\t\tif (data-\u003eu.runstate.state \u003c= RUNSTATE_offline)\narch/x86/kvm/xen.c:1070:\t\t\tkvm_xen_update_runstate(vcpu, data-\u003eu.runstate.state);\narch/x86/kvm/xen.c-1071-\t\telse if (vcpu-\u003earch.xen.runstate_cache.active)\narch/x86/kvm/xen.c:1072:\t\t\tkvm_xen_update_runstate_guest(vcpu, false);\narch/x86/kvm/xen.c-1073-\t\tr = 0;\n"
} |
| 57/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 40603 output: 37 thoughts: 192 Thoughts: **My Current Thinking** Okay, so I've confirmed that `kvm_xen_update_runstate` is indeed a global variable. Now, let me quickly review the finalized list of focus symbols. Here they are: * `kvm_gpc_refresh` * `kvm_gpc_activate` * `kvm_gpc_deactivate` * `gfn_to_pfn_cache_invalidate_start` * `kvm_xen_set_evtchn_fast` * `kvm_xen_update_runstate` * `kvm_xen_vcpu_set_attr` * `kvm_xen_hvm_set_attr` * `kvm_xen_inject_pending_events` * `kvm_xen_hypercall` * `__kvm_xen_has_interrupt` * `kvm_guest_time_update` Just a quick sanity check, I need to confirm `kvm_gpc_activate` is also a global entity. |
| 58/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "kvm_gpc_activate",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c=454=void __kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,\n--\nvirt/kvm/pfncache.c-466-\nvirt/kvm/pfncache.c:467:static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva,\nvirt/kvm/pfncache.c-468-\t\t\t unsigned long len)\n--\nvirt/kvm/pfncache.c-496-\nvirt/kvm/pfncache.c:497:int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)\nvirt/kvm/pfncache.c-498-{\n--\nvirt/kvm/pfncache.c-505-\nvirt/kvm/pfncache.c:506:\treturn __kvm_gpc_activate(gpc, gpa, KVM_HVA_ERR_BAD, len);\nvirt/kvm/pfncache.c-507-}\nvirt/kvm/pfncache.c-508-\nvirt/kvm/pfncache.c:509:int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long uhva, unsigned long len)\nvirt/kvm/pfncache.c-510-{\n--\nvirt/kvm/pfncache.c-513-\nvirt/kvm/pfncache.c:514:\treturn __kvm_gpc_activate(gpc, INVALID_GPA, uhva, len);\nvirt/kvm/pfncache.c-515-}\n"
} |
| 59/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 41549 output: 38 thoughts: 42 Thoughts: Okay, here's my interpretation of those thoughts, summarized from my perspective as someone familiar with KVM internals: **Checking Global Guard Page Context Management** Right, `kvm_gpc_activate` and `kvm_gpc_activate_hva`, those functions are definitely global in scope. They have to be; they're managing that Guard Page Context which needs to be accessible from all the relevant parts of the hypervisor. Now, the next logical step is to quickly review `kvm_gpc_deactivate`. I need to ensure that the cleanup and deallocation are handled properly on the other end, considering the activation is global. I have to make sure there are no leaks or unexpected side effects there. |
| 60/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "kvm_gpc_deactivate",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c=509=int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long uhva, unsigned long len)\n--\nvirt/kvm/pfncache.c-516-\nvirt/kvm/pfncache.c:517:void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc)\nvirt/kvm/pfncache.c-518-{\n"
} |
| 61/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 41919 output: 37 thoughts: 29 Thoughts: Okay, here's my take on those thoughts, framed as my own reasoning: **Analyzing KVM Global Page Counter Deactivation** Alright, so the discussion revolves around `kvm_gpc_deactivate`. The immediate conclusion is that this function has a global scope. This means any changes it makes are likely impacting the entire KVM system, not just a specific virtual machine or isolated component. That's a key piece of information to start with. Now, given that `kvm_gpc_deactivate` is global, the next logical step is to understand how the system interacts with it. To do that, I'm going to shift my focus over to `kvm_gpc_refresh`. I need to figure out how these functions interact, what the refresh is doing, and if it's dependent upon `kvm_gpc_deactivate` |
| 62/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "kvm_gpc_refresh",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c=182=static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)\n--\nvirt/kvm/pfncache.c-268-\nvirt/kvm/pfncache.c:269:static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva)\nvirt/kvm/pfncache.c-270-{\n--\nvirt/kvm/pfncache.c-434-\nvirt/kvm/pfncache.c:435:int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len)\nvirt/kvm/pfncache.c-436-{\n--\nvirt/kvm/pfncache.c-450-\nvirt/kvm/pfncache.c:451:\treturn __kvm_gpc_refresh(gpc, gpc-\u003egpa, uhva);\nvirt/kvm/pfncache.c-452-}\n--\nvirt/kvm/pfncache.c=467=static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva,\n--\nvirt/kvm/pfncache.c-493-\t}\nvirt/kvm/pfncache.c:494:\treturn __kvm_gpc_refresh(gpc, gpa, uhva);\nvirt/kvm/pfncache.c-495-}\n"
} |
| 63/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 42592 output: 43 thoughts: 34 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing KVM Global State & Cache Invalidation** Alright, so the immediate thought is confirmation: **`kvm_gpc_refresh` is, as expected, a global entity.** This is crucial for understanding its impact across the entire hypervisor. I need to keep that in mind as I consider the implications of its function. Now, let's drill down. The next logical step is to analyze the related function, **`gfn_to_pfn_cache_invalidate_start`.** Understanding its interactions with `kvm_gpc_refresh` is key. My initial hypothesis is that it likely plays a role in invalidating cached translations, perhaps in response to changes that `kvm_gpc_refresh` might initiate. I'll need to dig into the code surrounding those two to fully understand the scope. |
| 64/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "gfn_to_pfn_cache_invalidate_start",
"PathPrefix": "virt/kvm/pfncache.c"
}Results: {
"Output": "virt/kvm/pfncache.c-24- */\nvirt/kvm/pfncache.c:25:void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start,\nvirt/kvm/pfncache.c-26-\t\t\t\t unsigned long end)\n"
} |
| 65/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 42952 output: 37 thoughts: 72 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the Global Scope and Configuration Dependencies** Alright, so `gfn_to_pfn_cache_invalidate_start`, yes, it's global, just as I suspected. That's a key detail to keep in mind, and it's something that often gets overlooked in these kinds of discussions. Now, regarding the necessary configuration options: I believe we're looking at `KVM` and `KVM_XEN`. Hold on a second, though, `KVM_XEN` is a boolean, isn't it? Let me just double-check the `arch/x86/kvm/Kconfig` file again to confirm that I'm not missing anything crucial. Gotta get the dependencies nailed down precisely. |
| 66/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "config KVM_XEN",
"PathPrefix": "arch/x86/kvm/Kconfig"
}Results: {
"Output": "arch/x86/kvm/Kconfig=194=config KVM_HYPERV\n--\narch/x86/kvm/Kconfig-207-\narch/x86/kvm/Kconfig:208:config KVM_XEN\narch/x86/kvm/Kconfig-209-\tbool \"Support for Xen hypercall interface\"\n"
} |
| 67/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 43343 output: 34 thoughts: 59 Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, as if they were my own: **KVM Configuration Deep Dive** Right, `KVM_XEN` is definitely a boolean option. That's straightforward enough. Now, I need to check if there are any other related configurations. It seems like `MMU_NOTIFIER` is automatically selected if `KVM` is, which makes sense from a dependency perspective. To be absolutely sure, I'll drill down into `arch/x86/kvm/Kconfig` – that's the place to find the comprehensive details regarding the `KVM` configuration options and their interactions. Let's make sure I didn't miss anything that needs further consideration for this particular task. |
| 68/2 | 2026/08/05 21:28 | tool | grepper |
0mArgs:{
"Expression": "config KVM",
"PathPrefix": "arch/x86/kvm/Kconfig"
}Results: {
"Output": "arch/x86/kvm/Kconfig=18=if VIRTUALIZATION\narch/x86/kvm/Kconfig-19-\narch/x86/kvm/Kconfig:20:config KVM_X86\narch/x86/kvm/Kconfig-21-\tdef_tristate KVM if (KVM_INTEL != n || KVM_AMD != n)\n--\narch/x86/kvm/Kconfig-51-\narch/x86/kvm/Kconfig:52:config KVM\narch/x86/kvm/Kconfig-53-\ttristate \"Kernel-based Virtual Machine (KVM) support\"\n--\narch/x86/kvm/Kconfig-68-\narch/x86/kvm/Kconfig:69:config KVM_WERROR\narch/x86/kvm/Kconfig-70-\tbool \"Compile KVM with -Werror\"\n--\narch/x86/kvm/Kconfig-82-\narch/x86/kvm/Kconfig:83:config KVM_SW_PROTECTED_VM\narch/x86/kvm/Kconfig-84-\tbool \"Enable support for KVM software-protected VMs\"\n--\narch/x86/kvm/Kconfig-95-\narch/x86/kvm/Kconfig:96:config KVM_INTEL\narch/x86/kvm/Kconfig-97-\ttristate \"KVM for Intel (and compatible) processors support\"\n--\narch/x86/kvm/Kconfig-106-\narch/x86/kvm/Kconfig:107:config KVM_INTEL_PROVE_VE\narch/x86/kvm/Kconfig-108- bool \"Check that guests do not receive #VE exceptions\"\n--\narch/x86/kvm/Kconfig=122=config X86_SGX_KVM\n--\narch/x86/kvm/Kconfig-133-\narch/x86/kvm/Kconfig:134:config KVM_INTEL_TDX\narch/x86/kvm/Kconfig-135-\tbool \"Intel Trust Domain Extensions (TDX) support\"\n--\narch/x86/kvm/Kconfig-145-\narch/x86/kvm/Kconfig:146:config KVM_AMD\narch/x86/kvm/Kconfig-147-\ttristate \"KVM for AMD processors support\"\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--\narch/x86/kvm/Kconfig-172-\narch/x86/kvm/Kconfig:173:config KVM_IOAPIC\narch/x86/kvm/Kconfig-174-\tbool \"I/O APIC, PIC, and PIT emulation\"\n--\narch/x86/kvm/Kconfig-182-\narch/x86/kvm/Kconfig:183:config KVM_SMM\narch/x86/kvm/Kconfig-184-\tbool \"System Management Mode emulation\"\n--\narch/x86/kvm/Kconfig-193-\narch/x86/kvm/Kconfig:194:config KVM_HYPERV\narch/x86/kvm/Kconfig-195-\tbool \"Support for Microsoft Hyper-V emulation\"\n--\narch/x86/kvm/Kconfig-207-\narch/x86/kvm/Kconfig:208:config KVM_XEN\narch/x86/kvm/Kconfig-209-\tbool \"Support for Xen hypercall interface\"\n--\narch/x86/kvm/Kconfig-216-\narch/x86/kvm/Kconfig:217:config KVM_PROVE_MMU\narch/x86/kvm/Kconfig-218-\tbool \"Prove KVM MMU correctness\"\n--\narch/x86/kvm/Kconfig-229-\narch/x86/kvm/Kconfig:230:config KVM_EXTERNAL_WRITE_TRACKING\narch/x86/kvm/Kconfig-231-\tbool\narch/x86/kvm/Kconfig-232-\narch/x86/kvm/Kconfig:233:config KVM_MAX_NR_VCPUS\narch/x86/kvm/Kconfig-234-\tint \"Maximum number of vCPUs per KVM guest\"\n"
} |
| 69/2 | 2026/08/05 21:28 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 44816 output: 261 thoughts: 284 Thoughts: **My Assessment of the KVM/KVM_XEN Patch** Okay, so I'm looking at this patch and immediately, `KVM` and `KVM_XEN` are the key configurations in play. I need to understand the implications of the core changes. Let's break down the critical symbols associated with the KVM changes. The focus seems to be on: * `kvm_gpc_refresh`, `kvm_gpc_activate`, `kvm_gpc_deactivate`: These are obviously related to the Guest Page Cache (GPC) management. * `gfn_to_pfn_cache_invalidate_start`: This indicates interactions with the Guest Frame Number to Physical Frame Number translation cache invalidation. * `kvm_xen_set_evtchn_fast`, `kvm_xen_update_runstate`, `kvm_xen_vcpu_set_attr`, `kvm_xen_hvm_set_attr`, `kvm_xen_inject_pending_events`, `kvm_xen_hypercall`, `__kvm_xen_has_interrupt`, `kvm_guest_time_update`: These are the KVM/Xen integration specific call points. Crucially, all these functions are non-static and non-inlined API entrypoints. This means they're not just local helper functions; they're the public-facing interfaces of this change. Now, the core of the patch is the replacement of `rwlock_t` with RCU for synchronizing access to the `gfn_to_pfn_cache`. This is significant! We're talking about a fundamental shift in how the GPC, which is used for guest-to-host page caching (e.g., steal time, Xen shared info) is managed. RCU-based synchronization versus read-write locks is a functional change with concurrency implications. This is going to change the characteristics of this portion of the code. Given the scope of the change and that it is core KVM logic, it's pretty clear: this *needs* fuzzing. We're talking about the potential for concurrency bugs and subtle race conditions that could manifest as VM instability or, worse, security vulnerabilities. It's essential to validate the correct behavior with a robust and extensive fuzzing campaign. |
| 70/2 | 2026/08/05 21:28 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"KVM",
"KVM_XEN"
],
"FocusSymbols": [
"kvm_gpc_refresh",
"kvm_gpc_activate",
"kvm_gpc_deactivate",
"gfn_to_pfn_cache_invalidate_start",
"kvm_xen_set_evtchn_fast",
"kvm_xen_update_runstate",
"kvm_xen_vcpu_set_attr",
"kvm_xen_hvm_set_attr",
"kvm_xen_inject_pending_events",
"kvm_xen_hypercall",
"__kvm_xen_has_interrupt",
"kvm_guest_time_update"
],
"Reasoning": "The patch replaces rwlock_t with RCU-based synchronization for gfn_to_pfn_cache (GPC) in KVM, which is used for guest-to-host page caching (e.g., steal time, Xen shared info). This is a significant functional change in core KVM logic and should be fuzzed.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"KVM",
"KVM_XEN"
],
"FocusSymbols": [
"kvm_gpc_refresh",
"kvm_gpc_activate",
"kvm_gpc_deactivate",
"gfn_to_pfn_cache_invalidate_start",
"kvm_xen_set_evtchn_fast",
"kvm_xen_update_runstate",
"kvm_xen_vcpu_set_attr",
"kvm_xen_hvm_set_attr",
"kvm_xen_inject_pending_events",
"kvm_xen_hypercall",
"__kvm_xen_has_interrupt",
"kvm_guest_time_update"
],
"Reasoning": "The patch replaces rwlock_t with RCU-based synchronization for gfn_to_pfn_cache (GPC) in KVM, which is used for guest-to-host page caching (e.g., steal time, Xen shared info). This is a significant functional change in core KVM logic and should be fuzzed.",
"WorthFuzzing": true
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|