mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "pbonzini@redhat.com" <pbonzini@redhat.com>, "Christopherson,,
	Sean" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"guoke@uniontech.com" <guoke@uniontech.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"haiwenyao@uniontech.com" <haiwenyao@uniontech.com>
Subject: Re: [PATCH v2 4/8] KVM: x86: Add helper to get variable MTRR range from MSR index
Date: Fri, 12 May 2023 10:21:34 +0000	[thread overview]
Message-ID: <a9ddd6827ce6f69a2c54574971317340e085f8ab.camel@intel.com> (raw)
In-Reply-To: <20230511233351.635053-5-seanjc@google.com>

On Thu, 2023-05-11 at 16:33 -0700, Sean Christopherson wrote:
> Add a helper to dedup the logic for retrieving a variable MTRR range
> structure given a variable MTRR MSR index.
> 
> No functional change intended.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Kai Huang <kai.huang@intel.com>

> ---
>  arch/x86/kvm/mtrr.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
> index f65ce4b3980f..59851dbebfea 100644
> --- a/arch/x86/kvm/mtrr.c
> +++ b/arch/x86/kvm/mtrr.c
> @@ -31,6 +31,14 @@ static bool is_mtrr_base_msr(unsigned int msr)
>  	return !(msr & 0x1);
>  }
>  
> +static struct kvm_mtrr_range *var_mtrr_msr_to_range(struct kvm_vcpu *vcpu,
> +						    unsigned int msr)
> +{
> +	int index = (msr - 0x200) / 2;
> +
> +	return &vcpu->arch.mtrr_state.var_ranges[index];
> +}
> +
>  static bool msr_mtrr_valid(unsigned msr)
>  {
>  	switch (msr) {
> @@ -314,7 +322,6 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
>  {
>  	struct kvm_mtrr *mtrr_state = &vcpu->arch.mtrr_state;
>  	gfn_t start, end;
> -	int index;
>  
>  	if (msr == MSR_IA32_CR_PAT || !tdp_enabled ||
>  	      !kvm_arch_has_noncoherent_dma(vcpu->kvm))
> @@ -332,8 +339,7 @@ static void update_mtrr(struct kvm_vcpu *vcpu, u32 msr)
>  		end = ~0ULL;
>  	} else {
>  		/* variable range MTRRs. */
> -		index = (msr - 0x200) / 2;
> -		var_mtrr_range(&mtrr_state->var_ranges[index], &start, &end);
> +		var_mtrr_range(var_mtrr_msr_to_range(vcpu, msr), &start, &end);
>  	}
>  
>  	kvm_zap_gfn_range(vcpu->kvm, gpa_to_gfn(start), gpa_to_gfn(end));
> @@ -348,14 +354,12 @@ static void set_var_mtrr_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
>  {
>  	struct kvm_mtrr *mtrr_state = &vcpu->arch.mtrr_state;
>  	struct kvm_mtrr_range *tmp, *cur;
> -	int index;
>  
> -	index = (msr - 0x200) / 2;
> -	cur = &mtrr_state->var_ranges[index];
> +	cur = var_mtrr_msr_to_range(vcpu, msr);
>  
>  	/* remove the entry if it's in the list. */
>  	if (var_mtrr_range_is_valid(cur))
> -		list_del(&mtrr_state->var_ranges[index].node);
> +		list_del(&cur->node);
>  
>  	/*
>  	 * Set all illegal GPA bits in the mask, since those bits must
> @@ -423,11 +427,10 @@ int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
>  	else if (msr == MSR_IA32_CR_PAT)
>  		*pdata = vcpu->arch.pat;
>  	else {	/* Variable MTRRs */
> -		index = (msr - 0x200) / 2;
>  		if (is_mtrr_base_msr(msr))
> -			*pdata = vcpu->arch.mtrr_state.var_ranges[index].base;
> +			*pdata = var_mtrr_msr_to_range(vcpu, msr)->base;
>  		else
> -			*pdata = vcpu->arch.mtrr_state.var_ranges[index].mask;
> +			*pdata = var_mtrr_msr_to_range(vcpu, msr)->mask;
>  
>  		*pdata &= ~kvm_vcpu_reserved_gpa_bits_raw(vcpu);
>  	}
> -- 
> 2.40.1.606.ga4b1b128d6-goog
> 


  reply	other threads:[~2023-05-12 10:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-11 23:33 [PATCH v2 0/8] KVM: x86: Clean up MSR PAT handling Sean Christopherson
2023-05-11 23:33 ` [PATCH v2 1/8] KVM: VMX: Open code writing vCPU's PAT in VMX's MSR handler Sean Christopherson
2023-05-12 10:18   ` Huang, Kai
2023-05-11 23:33 ` [PATCH v2 2/8] KVM: SVM: Use kvm_pat_valid() directly instead of kvm_mtrr_valid() Sean Christopherson
2023-05-11 23:33 ` [PATCH v2 3/8] KVM: x86: Add helper to query if variable MTRR MSR is base (versus mask) Sean Christopherson
2023-05-11 23:33 ` [PATCH v2 4/8] KVM: x86: Add helper to get variable MTRR range from MSR index Sean Christopherson
2023-05-12 10:21   ` Huang, Kai [this message]
2023-05-11 23:33 ` [PATCH v2 5/8] KVM: x86: Use MTRR macros to define possible MTRR MSR ranges Sean Christopherson
2023-05-12 10:35   ` Huang, Kai
2023-05-12 16:35     ` Sean Christopherson
2023-05-15  0:37       ` Huang, Kai
2023-05-15 17:49         ` Sean Christopherson
2023-05-15 22:21           ` Huang, Kai
2023-05-11 23:33 ` [PATCH v2 6/8] KVM: x86: Move PAT MSR handling out of mtrr.c Sean Christopherson
2023-05-12 10:40   ` Huang, Kai
2023-05-11 23:33 ` [PATCH v2 7/8] KVM: x86: Make kvm_mtrr_valid() static now that there are no external users Sean Christopherson
2023-05-12 10:46   ` Huang, Kai
2023-05-11 23:33 ` [PATCH v2 8/8] KVM: x86: Move common handling of PAT MSR writes to kvm_set_msr_common() Sean Christopherson
2023-05-12 10:48   ` Huang, Kai
2023-06-02  1:21 ` [PATCH v2 0/8] KVM: x86: Clean up MSR PAT handling 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=a9ddd6827ce6f69a2c54574971317340e085f8ab.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=guoke@uniontech.com \
    --cc=haiwenyao@uniontech.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®