All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Gerd Hoffmann <kraxel@redhat.com>, kvm@vger.kernel.org
Cc: Tom Lendacky <thomas.lendacky@amd.com>,
	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>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] kvm/cpuid: remove GuestPhysBits code.
Date: Tue, 12 Mar 2024 10:38:04 +0800	[thread overview]
Message-ID: <69628e0d-a1c8-4bf2-8eea-abfc0da1a6aa@intel.com> (raw)
In-Reply-To: <20240311104118.284054-2-kraxel@redhat.com>

On 3/11/2024 6:41 PM, Gerd Hoffmann wrote:
 > [PATCH v3 1/2] kvm/cpuid: remove GuestPhysBits code.

No need for a ending . in the title.

> GuestPhysBits (cpuid leaf 80000008, eax[23:16]) is intended for software
> use.  Physical CPUs do not set that field.  The current code which
> propagates the host's GuestPhysBits to the guest's PhysBits does not
> make sense.  Remove it.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   arch/x86/kvm/cpuid.c | 32 ++++++++++++++------------------
>   1 file changed, 14 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index adba49afb5fe..c638b5fb2144 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1221,26 +1221,22 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
>   		entry->eax = entry->ebx = entry->ecx = 0;
>   		break;
>   	case 0x80000008: {
> -		unsigned g_phys_as = (entry->eax >> 16) & 0xff;
> -		unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U);
> -		unsigned phys_as = entry->eax & 0xff;
> +		unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U);
> +		unsigned int phys_as;
>   
> -		/*
> -		 * If TDP (NPT) is disabled use the adjusted host MAXPHYADDR as
> -		 * the guest operates in the same PA space as the host, i.e.
> -		 * reductions in MAXPHYADDR for memory encryption affect shadow
> -		 * paging, too.
> -		 *
> -		 * If TDP is enabled but an explicit guest MAXPHYADDR is not
> -		 * provided, use the raw bare metal MAXPHYADDR as reductions to
> -		 * the HPAs do not affect GPAs.
> -		 */
> -		if (!tdp_enabled)
> -			g_phys_as = boot_cpu_data.x86_phys_bits;
> -		else if (!g_phys_as)
> -			g_phys_as = phys_as;
> +		if (!tdp_enabled) {
> +			/*
> +			 * If TDP (NPT) is disabled use the adjusted host
> +			 * MAXPHYADDR as the guest operates in the same PA
> +			 * space as the host, i.e.  reductions in MAXPHYADDR
> +			 * for memory encryption affect shadow paging, too.
> +			 */

I suggest keeping as the original comment to stay out of if check, and 
keeping the second paragraph with guest MAXPHYADDR thing removed as 
below, because the second paragraph is also useful.

   If TDP is enabled, use the raw bare metal MAXPHYADDR as reductions to
   the HPAs do not affect GPAs.

Otherwise,

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> +			phys_as = boot_cpu_data.x86_phys_bits;
> +		} else {
> +			phys_as = entry->eax & 0xff;
> +		}
>   
> -		entry->eax = g_phys_as | (virt_as << 8);
> +		entry->eax = phys_as | (virt_as << 8);
>   		entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8));
>   		entry->edx = 0;
>   		cpuid_entry_override(entry, CPUID_8000_0008_EBX);


  reply	other threads:[~2024-03-12  2:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 10:41 [PATCH v3 0/2] kvm/cpuid: set proper GuestPhysBits in CPUID.0x80000008 Gerd Hoffmann
2024-03-11 10:41 ` [PATCH v3 1/2] kvm/cpuid: remove GuestPhysBits code Gerd Hoffmann
2024-03-12  2:38   ` Xiaoyao Li [this message]
2024-03-11 10:41 ` [PATCH v3 2/2] kvm/cpuid: set proper GuestPhysBits in CPUID.0x80000008 Gerd Hoffmann
2024-03-12  2:44   ` Xiaoyao Li
2024-03-13  1:06   ` Tao Su
2024-03-13  1:14     ` Xiaoyao Li
2024-03-13  8:38       ` Gerd Hoffmann

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=69628e0d-a1c8-4bf2-8eea-abfc0da1a6aa@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.