From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F31B415F29; Sun, 20 Sep 2026 21:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789939194; cv=none; b=ahF+X31/aNO6xZvVHVQi3al6D1emh4XrmBWKo5nzfDce02so3hWvSs07Whv71OUkaP3W4d2HYMdtLkrPDRx/FOWqAQ0mh0Z1lbqvLMThN4O7cYH2o+mCu+tWc2tTlXLusP9NW3815EWyIKmisvwF1EZ2AAUm53q7P4JhSbsMI+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789939194; c=relaxed/simple; bh=F13FbYKVRv3ojXr1TJH83gBA9Jq3rNNIf4+OJUxLqxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jFoWupYN+hxMbB0c+FLRUbDeZxcm2jIbGHETTUa+Ynjp9uS2Kl0fy7jH8G4yRTMpDMbqHF3RhO895IAPkID9yDuXtpE22xvypPodI0QSathzsb3y5tCU3AhLYiCjkYQDtoydbChAEO/i8HNOEqhAIxrPwhWmZ1gycmhNP3tsusw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BLFF5BkE; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BLFF5BkE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=L/r+STl0BFAv7SNJgRR9Rd8e8Ds2gUZgtW81r0pp3Us=; b=BLFF5BkEzFDeVeVRiDJcCt9HU/ 3brNwWurOKsDLPU3DAI4hmTTJ1Vo0et8T5Pt3yqSvu+Cny5uDwtzWf3/VhcJzA2XG4UZ5b6pE6l48 Tj/nBzNHue/GtPzlsdr7Zhhg7IZJq9JoT/4UrlaCCelJAvd3GUVkWog33SCihzhnDP0xLygONLXQO 3WZf69ZKfZMomlESbaCu+hTHMPFeqgIiUqLjImKf9jBX+rvot3AWrc225D2XdasQaepxmg4xu0RiL Z3W5le3a5uXjUNe3M4cZr03wXMF8o0ksPoqqmuwO4ACPmgeVxmOXa+m3Dt8rk9w0GzWuVpYIkHEk5 6ut5nBLw==; Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1x8OwW-0000000BdxV-49B8; Sun, 20 Sep 2026 21:19:26 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.4 #2 (Red Hat Linux)) id 1x8OwU-00000003tcV-1BBw; Sun, 20 Sep 2026 22:19:22 +0100 From: David Woodhouse To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, linux-rt-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Paul Durrant , Vitaly Kuznetsov , Fred Griffoul , "Paul E. McKenney" , Kunwu Chan , Kunwu Chan , Zqiang , Boqun Feng , Neeraj Upadhyay , Joel Fernandes , Lai Jiangshan , Josh Triplett , Mathieu Desnoyers , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Jason Gunthorpe , Michal Hocko , Nikita Kalyazin , Keir Fraser , David Matlack , nh-open-source@amazon.com, David Woodhouse Subject: [PATCH 03/17] KVM: x86/xen: Explicitly tag "shared info" page as never being dirty tracked Date: Sun, 20 Sep 2026 21:49:31 +0100 Message-ID: <20260920211920.928306-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260920211920.928306-1-dwmw2@infradead.org> References: <20260920211920.928306-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html From: Sean Christopherson Explicitly mark the Xen shared info page as never being dirty tracked so that higher-level gpc APIs can be added to automatically take care of things like dirty tracking, without reintroducing the bug fixed by commit 55749769fe60 ("KVM: x86: Fix wall clock writes in Xen shared_info not to mark page dirty"). And because the code _looks_ buggy. No functional change intended. Signed-off-by: Sean Christopherson Signed-off-by: David Woodhouse Assisted-by: Claude:claude-mythos-5 --- arch/x86/kvm/xen.c | 2 +- include/linux/kvm_host.h | 10 ++++++++-- include/linux/kvm_types.h | 1 + virt/kvm/pfncache.c | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 1364fe8ee751..198d7babf964 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -2410,7 +2410,7 @@ void kvm_xen_init_vm(struct kvm *kvm) { mutex_init(&kvm->arch.xen.xen_lock); xa_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 9da947eb08ed..7b2dbbd6b104 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1474,7 +1474,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 @@ -1983,7 +1989,7 @@ static inline void kvm_gpc_mark_dirty_in_slot(struct gfn_to_pfn_cache *gpc) RCU_LOCKDEP_WARN(!srcu_read_lock_held(&gpc->kvm->gpc_srcu), "kvm_gpc_mark_dirty_in_slot() without kvm->gpc_srcu 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 31f3eb0dd2aa..22393f97266a 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -109,6 +109,7 @@ struct gfn_to_pfn_cache { * instead. */ atomic_t state; + bool never_dirty; }; /* The cache is valid: pfn and khva may be used by readers. */ diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 067da05a87ac..2fe50dfa3fc1 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -598,7 +598,8 @@ 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) { mutex_init(&gpc->refresh_lock); @@ -608,6 +609,7 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm) gpc->uhva = KVM_HVA_ERR_BAD; gpc->active = false; atomic_set(&gpc->state, 0); + gpc->never_dirty = never_dirty; } static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long uhva, -- 2.55.0