mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Suthikulpanit, Suravee" <suravee.suthikulpanit@amd.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Subject: Re: [PATCH v2 3/3] KVM: SVM: WARN if GATag generation drops VM or vCPU ID information
Date: Thu, 16 Feb 2023 03:20:38 +0700	[thread overview]
Message-ID: <c653acea-d060-ed81-d3a0-c7379ecb0799@amd.com> (raw)
In-Reply-To: <20230207002156.521736-4-seanjc@google.com>



On 2/7/2023 7:21 AM, Sean Christopherson wrote:
> WARN if generating a GATag given a VM ID and vCPU ID doesn't yield the
> same IDs when pulling the IDs back out of the tag.  Don't bother adding
> error handling to callers, this is very much a paranoid sanity check as
> KVM fully controls the VM ID and is supposed to reject too-big vCPU IDs.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/svm/avic.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index 326341a22153..cfc8ab773025 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -43,12 +43,21 @@
>   #define AVIC_VM_ID_SHIFT		HWEIGHT32(AVIC_PHYSICAL_MAX_INDEX_MASK)
>   #define AVIC_VM_ID_MASK			(GENMASK(31, AVIC_VM_ID_SHIFT) >> AVIC_VM_ID_SHIFT)
>   
> -#define AVIC_GATAG(x, y)		(((x & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \
> -						(y & AVIC_VCPU_ID_MASK))
>   #define AVIC_GATAG_TO_VMID(x)		((x >> AVIC_VM_ID_SHIFT) & AVIC_VM_ID_MASK)
>   #define AVIC_GATAG_TO_VCPUID(x)		(x & AVIC_VCPU_ID_MASK)
>   
> -static_assert(AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) == -1u);
> +#define __AVIC_GATAG(vm_id, vcpu_id)	((((vm_id) & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \
> +					 ((vcpu_id) & AVIC_VCPU_ID_MASK))
> +#define AVIC_GATAG(vm_id, vcpu_id)					\
> +({									\
> +	u32 ga_tag = __AVIC_GATAG(vm_id, vcpu_id);			\
> +									\
> +	WARN_ON_ONCE(AVIC_GATAG_TO_VCPUID(ga_tag) != (vcpu_id));	\
> +	WARN_ON_ONCE(AVIC_GATAG_TO_VMID(ga_tag) != (vm_id));		\
> +	ga_tag;								\
> +})
> +
> +static_assert(__AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) == -1u);
>   
>   static bool force_avic;
>   module_param_unsafe(force_avic, bool, 0444);

Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>

Thanks,
Suravee

  reply	other threads:[~2023-02-15 20:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  0:21 [PATCH v2 0/3] KVM: SVM: Fix GATag bug for >256 vCPUs Sean Christopherson
2023-02-07  0:21 ` [PATCH v2 1/3] KVM: SVM: Fix a benign off-by-one bug in AVIC physical table mask Sean Christopherson
2023-02-15 15:38   ` Suthikulpanit, Suravee
2023-02-07  0:21 ` [PATCH v2 2/3] KVM: SVM: Modify AVIC GATag to support max number of 512 vCPUs Sean Christopherson
2023-02-07  8:33   ` Igor Mammedov
2023-02-07 11:15     ` Joao Martins
2023-02-07 16:38       ` Sean Christopherson
2023-02-15 20:15         ` Suthikulpanit, Suravee
2023-02-15 15:50   ` Suthikulpanit, Suravee
2023-02-07  0:21 ` [PATCH v2 3/3] KVM: SVM: WARN if GATag generation drops VM or vCPU ID information Sean Christopherson
2023-02-15 20:20   ` Suthikulpanit, Suravee [this message]
2023-02-15 20:21 ` [PATCH v2 0/3] KVM: SVM: Fix GATag bug for >256 vCPUs Suthikulpanit, Suravee
2023-02-15 22:11   ` Sean Christopherson
2023-03-14 13:36 ` Paolo Bonzini

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=c653acea-d060-ed81-d3a0-c7379ecb0799@amd.com \
    --to=suravee.suthikulpanit@amd.com \
    --cc=alejandro.j.jimenez@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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

all inboxes | Powered by JetHome®