All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wen Pu <puwen@hygon.cn>
To: Tom Lendacky <thomas.lendacky@amd.com>,
	"x86@kernel.org" <x86@kernel.org>
Cc: "joro@8bytes.org" <joro@8bytes.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>, "bp@suse.de" <bp@suse.de>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"jroedel@suse.de" <jroedel@suse.de>,
	"sashal@kernel.org" <sashal@kernel.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] x86/sev: Check whether SEV or SME is supported first
Date: Wed, 2 Jun 2021 06:55:05 +0000	[thread overview]
Message-ID: <8e1d7510-563a-3b54-6037-8c0904998123@hygon.cn> (raw)
In-Reply-To: <dc69a9bb-a4a0-d82b-2e9c-cf6336ab8252@amd.com>

On 2021/6/2 2:30, Tom Lendacky wrote:
> On 5/26/21 2:24 AM, Pu Wen wrote:
>> The first two bits of the CPUID leaf 0x8000001F EAX indicate whether
>> SEV or SME is supported respectively. It's better to check whether
>> SEV or SME is supported before checking the SEV MSR(0xc0010131) to
>> see whether SEV or SME is enabled.
>>
>> This also avoid the MSR reading failure on the first generation Hygon
>> Dhyana CPU which does not support SEV or SME.
>>
>> Fixes: eab696d8e8b9 ("x86/sev: Do not require Hypervisor CPUID bit for SEV guests")
>> Cc: <stable@vger.kernel.org> # v5.10+
>> Signed-off-by: Pu Wen <puwen@hygon.cn>
> 
> I think the commit message needs to be expanded to clarify the situations
> and provide more detail.

Okay.

> This is both a bare-metal issue and a guest/VM issue. Since Hygon doesn't
> support the MSR_AMD64_SEV MSR, reading that MSR results in a #GP - either
> directly from hardware in the bare-metal case or via the hypervisor
> (because the RDMSR is actually intercepted) in the guest/VM case,
> resulting in a failed boot. And since this is very early in the boot
> phase, rdmsrl_safe()/native_read_msr_safe() can't be used.

The description is good, will add this.

> So by checking the CPUID information before attempting the RDMSR, this
> goes back to the behavior before the patch identified in the Fixes: tag.
> 
> With an improved commit message:
> 
> Acked-by: Tom Lendacky <thomas.lendacky@amd.com>

Thanks, will send patch v2 with improved commit messages.

-- 
Regards,
Pu Wen

>> ---
>>  arch/x86/mm/mem_encrypt_identity.c | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c
>> index a9639f663d25..470b20208430 100644
>> --- a/arch/x86/mm/mem_encrypt_identity.c
>> +++ b/arch/x86/mm/mem_encrypt_identity.c
>> @@ -504,10 +504,6 @@ void __init sme_enable(struct boot_params *bp)
>>  #define AMD_SME_BIT	BIT(0)
>>  #define AMD_SEV_BIT	BIT(1)
>>  
>> -	/* Check the SEV MSR whether SEV or SME is enabled */
>> -	sev_status   = __rdmsr(MSR_AMD64_SEV);
>> -	feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
>> -
>>  	/*
>>  	 * Check for the SME/SEV feature:
>>  	 *   CPUID Fn8000_001F[EAX]
>> @@ -519,11 +515,16 @@ void __init sme_enable(struct boot_params *bp)
>>  	eax = 0x8000001f;
>>  	ecx = 0;
>>  	native_cpuid(&eax, &ebx, &ecx, &edx);
>> -	if (!(eax & feature_mask))
>> +	/* Check whether SEV or SME is supported */
>> +	if (!(eax & (AMD_SEV_BIT | AMD_SME_BIT)))
>>  		return;
>>  
>>  	me_mask = 1UL << (ebx & 0x3f);
>>  
>> +	/* Check the SEV MSR whether SEV or SME is enabled */
>> +	sev_status   = __rdmsr(MSR_AMD64_SEV);
>> +	feature_mask = (sev_status & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BIT;
>> +
>>  	/* Check if memory encryption is enabled */
>>  	if (feature_mask == AMD_SME_BIT) {
>>  		/*
>>

      reply	other threads:[~2021-06-02  6:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26  7:24 [PATCH] x86/sev: Check whether SEV or SME is supported first Pu Wen
2021-05-26 17:27 ` Sean Christopherson
2021-05-27 15:08   ` Pu Wen
2021-05-31  9:37     ` Joerg Roedel
2021-05-31 14:56       ` Pu Wen
2021-06-01 14:39         ` Borislav Petkov
2021-06-01 16:14           ` Sean Christopherson
2021-06-01 16:36             ` Tom Lendacky
2021-06-01 16:59               ` Borislav Petkov
2021-06-01 17:16                 ` Sean Christopherson
2021-06-01 17:48                   ` Borislav Petkov
2021-06-01 18:08                     ` Sean Christopherson
2021-06-01 18:24                       ` Borislav Petkov
2021-06-01 17:09               ` Sean Christopherson
2021-06-01 18:30 ` Tom Lendacky
2021-06-02  6:55   ` Wen Pu [this message]

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=8e1d7510-563a-3b54-6037-8c0904998123@hygon.cn \
    --to=puwen@hygon.cn \
    --cc=bp@suse.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --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.