From: Sean Christopherson <seanjc@google.com>
To: Manuel Andreas <manuel.andreas@tum.de>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] x86/hyper-v: Validate entire GVA range for non-canonical addresses during PV TLB flush
Date: Fri, 20 Feb 2026 09:23:13 -0800 [thread overview]
Message-ID: <aZiYgTNHfM5Y_Mo7@google.com> (raw)
In-Reply-To: <00a7a31b-573b-4d92-91f8-7d7e2f88ea48@tum.de>
+Vitaly and Paolo
Please use scripts/get_maintainer.pl, otherwise your emails might not reach the
right eyeballs.
On Thu, Feb 19, 2026, Manuel Andreas wrote:
> In KVM guests with Hyper-V hypercalls enabled, the hypercalls
> HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST and HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX
> allow a guest to request invalidation of portions of a virtual TLB.
> For this, the hypercall parameter includes a list of GVAs that are supposed
> to be invalidated.
>
> Currently, only the base GVA is checked to be canonical. In reality,
> this check needs to be performed for the entire range of GVAs.
> This still enables guests running on Intel hardware to trigger a
> WARN_ONCE in the host (see prior commit below).
>
> This patch simply moves the check for non-canonical addresses to be
> performed for every single GVA of the supplied range. This should also
> be more in line with the Hyper-V specification, since, although
> unlikely, a range starting with an invalid GVA may still contain
> GVAs that are valid.
>
> Fixes: fa787ac07b3c ("KVM: x86/hyper-v: Skip non-canonical addresses during PV TLB flush")
> Signed-off-by: Manuel Andreas <manuel.andreas@tum.de>
> ---
> arch/x86/kvm/hyperv.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index de92292eb1f5..f4f6accf1a33 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -1981,16 +1981,17 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
> if (entries[i] == KVM_HV_TLB_FLUSHALL_ENTRY)
> goto out_flush_all;
>
> - if (is_noncanonical_invlpg_address(entries[i], vcpu))
> - continue;
> -
> /*
> * Lower 12 bits of 'address' encode the number of additional
> * pages to flush.
> */
> gva = entries[i] & PAGE_MASK;
> - for (j = 0; j < (entries[i] & ~PAGE_MASK) + 1; j++)
> + for (j = 0; j < (entries[i] & ~PAGE_MASK) + 1; j++) {
> + if (is_noncanonical_invlpg_address(gva + j * PAGE_SIZE, vcpu))
> + continue;
> +
> kvm_x86_call(flush_tlb_gva)(vcpu, gva + j * PAGE_SIZE);
> + }
Vitaly, can we treat the entire request as garbage and throw it away if any part
isn't valid? Or do you think we should go with the more conservative approach
as above?
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index de92292eb1f5..f568f3d4f6e5 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -1967,8 +1967,8 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
struct kvm_vcpu_hv_tlb_flush_fifo *tlb_flush_fifo;
struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
u64 entries[KVM_HV_TLB_FLUSH_FIFO_SIZE];
+ gva_t gva, extra_pages;
int i, j, count;
- gva_t gva;
if (!tdp_enabled || !hv_vcpu)
return -EINVAL;
@@ -1978,18 +1978,22 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
count = kfifo_out(&tlb_flush_fifo->entries, entries, KVM_HV_TLB_FLUSH_FIFO_SIZE);
for (i = 0; i < count; i++) {
+
if (entries[i] == KVM_HV_TLB_FLUSHALL_ENTRY)
goto out_flush_all;
- if (is_noncanonical_invlpg_address(entries[i], vcpu))
- continue;
-
/*
* Lower 12 bits of 'address' encode the number of additional
* pages to flush.
*/
gva = entries[i] & PAGE_MASK;
- for (j = 0; j < (entries[i] & ~PAGE_MASK) + 1; j++)
+ extra_pages = (entries[i] & ~PAGE_MASK);
+
+ if (is_noncanonical_invlpg_address(gva, vcpu) ||
+ is_noncanonical_invlpg_address(gva + extra_pages * PAGE_SIZE))
+ continue;
+
+ for (j = 0; j < extra_pages + 1; j++)
kvm_x86_call(flush_tlb_gva)(vcpu, gva + j * PAGE_SIZE);
++vcpu->stat.tlb_flush;
next prev parent reply other threads:[~2026-02-20 17:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 20:05 [PATCH] x86/hyper-v: Validate entire GVA range for non-canonical addresses during PV TLB flush Manuel Andreas
2026-02-20 17:23 ` Sean Christopherson [this message]
2026-02-23 8:55 ` Vitaly Kuznetsov
2026-02-23 8:58 ` Vitaly Kuznetsov
2026-03-05 17:07 ` Sean Christopherson
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=aZiYgTNHfM5Y_Mo7@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manuel.andreas@tum.de \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
/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