From: Paul Durrant <paul@xen.org>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Paul Durrant <pdurrant@amazon.com>,
David Woodhouse <dwmw2@infradead.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org
Subject: [PATCH v2 03/12] KVM: pfncache: add a helper to get the gpa
Date: Mon, 18 Sep 2023 11:21:39 +0000 [thread overview]
Message-ID: <20230918112148.28855-4-paul@xen.org> (raw)
In-Reply-To: <20230918112148.28855-1-paul@xen.org>
From: Paul Durrant <pdurrant@amazon.com>
A subsequent patch will rename this field since it will become overloaded.
To avoid churn in places that currently retrieve the gpa, add a helper for
that purpose now.
No functional change intended.
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: David Woodhouse <dwmw2@infradead.org>
---
Cc: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
---
arch/x86/kvm/xen.c | 15 ++++++++-------
include/linux/kvm_host.h | 7 +++++++
virt/kvm/pfncache.c | 6 ++++++
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 33fddd29824b..8e6fdcd7bb6e 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -261,8 +261,8 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
* alignment (and the 32-bit ABI doesn't align the 64-bit integers
* anyway, even if the overall struct had been 64-bit aligned).
*/
- if ((gpc1->gpa & ~PAGE_MASK) + user_len >= PAGE_SIZE) {
- user_len1 = PAGE_SIZE - (gpc1->gpa & ~PAGE_MASK);
+ if ((kvm_gpc_gpa(gpc1) & ~PAGE_MASK) + user_len >= PAGE_SIZE) {
+ user_len1 = PAGE_SIZE - (kvm_gpc_gpa(gpc1) & ~PAGE_MASK);
user_len2 = user_len - user_len1;
} else {
user_len1 = user_len;
@@ -343,7 +343,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
* to the second page now because the guest changed to
* 64-bit mode, the second GPC won't have been set up.
*/
- if (kvm_gpc_activate(gpc2, gpc1->gpa + user_len1,
+ if (kvm_gpc_activate(gpc2, kvm_gpc_gpa(gpc1) + user_len1,
user_len2))
return;
@@ -677,7 +677,8 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
case KVM_XEN_ATTR_TYPE_SHARED_INFO:
if (kvm->arch.xen.shinfo_cache.active)
- data->u.shared_info.gfn = gpa_to_gfn(kvm->arch.xen.shinfo_cache.gpa);
+ data->u.shared_info.gfn =
+ gpa_to_gfn(kvm_gpc_gpa(&kvm->arch.xen.shinfo_cache));
else
data->u.shared_info.gfn = KVM_XEN_INVALID_GFN;
r = 0;
@@ -955,7 +956,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
switch (data->type) {
case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO:
if (vcpu->arch.xen.vcpu_info_cache.active)
- data->u.gpa = vcpu->arch.xen.vcpu_info_cache.gpa;
+ data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_info_cache);
else
data->u.gpa = KVM_XEN_INVALID_GPA;
r = 0;
@@ -963,7 +964,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO:
if (vcpu->arch.xen.vcpu_time_info_cache.active)
- data->u.gpa = vcpu->arch.xen.vcpu_time_info_cache.gpa;
+ data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_time_info_cache);
else
data->u.gpa = KVM_XEN_INVALID_GPA;
r = 0;
@@ -975,7 +976,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
break;
}
if (vcpu->arch.xen.runstate_cache.active) {
- data->u.gpa = vcpu->arch.xen.runstate_cache.gpa;
+ data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.runstate_cache);
r = 0;
}
break;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c71e8fbccaaf..4d8027fe9928 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1374,6 +1374,13 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc);
*/
void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc);
+/**
+ * kvm_gpc_gpa - retrieve the guest physical address of a cached mapping
+ *
+ * @gpc: struct gfn_to_pfn_cache object.
+ */
+gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc);
+
void kvm_sigset_activate(struct kvm_vcpu *vcpu);
void kvm_sigset_deactivate(struct kvm_vcpu *vcpu);
diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c
index b68ed7fa56a2..17afbb464a70 100644
--- a/virt/kvm/pfncache.c
+++ b/virt/kvm/pfncache.c
@@ -386,6 +386,12 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
}
EXPORT_SYMBOL_GPL(kvm_gpc_activate);
+gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc)
+{
+ return gpc->gpa;
+}
+EXPORT_SYMBOL_GPL(kvm_gpc_gpa);
+
void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc)
{
mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);
--
2.39.2
next prev parent reply other threads:[~2023-09-18 11:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 11:21 [PATCH v2 00/12] KVM: xen: update shared_info and vcpu_info handling Paul Durrant
2023-09-18 11:21 ` [PATCH v2 01/12] KVM: pfncache: add a map helper function Paul Durrant
2023-09-18 11:21 ` [PATCH v2 02/12] KVM: pfncache: add a mark-dirty helper Paul Durrant
2023-09-18 11:21 ` Paul Durrant [this message]
2023-09-18 11:21 ` [PATCH v2 04/12] KVM: pfncache: base offset check on khva rather than gpa Paul Durrant
2023-09-18 11:21 ` [PATCH v2 05/12] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA Paul Durrant
2023-09-18 11:34 ` David Woodhouse
2023-09-18 12:11 ` Paul Durrant
2023-09-18 12:59 ` David Woodhouse
2023-09-18 13:00 ` Paul Durrant
2023-09-18 11:21 ` [PATCH v2 06/12] KVM: xen: allow shared_info to be mapped by fixed HVA Paul Durrant
2023-09-18 11:21 ` [PATCH v2 07/12] KVM: xen: prepare for using 'default' vcpu_info Paul Durrant
2023-09-18 11:21 ` [PATCH v2 08/12] KVM: xen: automatically use the vcpu_info embedded in shared_info Paul Durrant
2023-09-18 11:49 ` David Woodhouse
2023-09-18 12:15 ` Paul Durrant
2023-09-18 11:21 ` [PATCH v2 09/12] KVM: selftests / xen: set KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID Paul Durrant
2023-09-18 11:59 ` David Woodhouse
2023-09-18 12:18 ` Paul Durrant
2023-09-18 12:26 ` David Woodhouse
2023-09-18 11:21 ` [PATCH v2 10/12] KVM: selftests / xen: map shared_info using HVA rather than GFN Paul Durrant
2023-09-18 13:19 ` David Woodhouse
2023-09-18 13:24 ` Paul Durrant
2023-09-18 13:30 ` David Woodhouse
2023-09-18 11:21 ` [PATCH v2 11/12] KVM: selftests / xen: don't explicitly set the vcpu_info address Paul Durrant
2023-09-18 13:21 ` David Woodhouse
2023-09-18 13:26 ` Paul Durrant
2023-09-18 13:36 ` David Woodhouse
2023-09-18 13:41 ` Paul Durrant
2023-09-18 14:05 ` David Woodhouse
2023-09-18 14:14 ` Paul Durrant
2023-09-18 11:21 ` [PATCH v2 12/12] KVM: xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability Paul Durrant
2023-09-18 13:22 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230918112148.28855-4-paul@xen.org \
--to=paul@xen.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pdurrant@amazon.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®