Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "Pratik R. Sampat" <pratikrajesh.sampat@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: <kvm@vger.kernel.org>, <pbonzini@redhat.com>, <pgonda@google.com>,
	<thomas.lendacky@amd.com>, <michael.roth@amd.com>,
	<shuah@kernel.org>, <linux-kselftest@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/9] KVM: selftests: Add a basic SNP smoke test
Date: Mon, 4 Nov 2024 22:14:47 -0600	[thread overview]
Message-ID: <0efe04cf-9b12-4a22-ad76-b7cd1f719f45@amd.com> (raw)
In-Reply-To: <ZyldJ_ociCLg-b9a@google.com>



On 11/4/2024 5:47 PM, Sean Christopherson wrote:
> On Mon, Nov 04, 2024, Pratik R. Sampat wrote:
>>
>>
>> On 10/31/2024 11:27 AM, Sean Christopherson wrote:
>>> On Thu, Oct 31, 2024, Pratik R. Sampat wrote:
>>>> Hi Sean,
>>>>
>>>> On 10/30/2024 12:57 PM, Sean Christopherson wrote:
>>>>> On Wed, Oct 30, 2024, Pratik R. Sampat wrote:
>>>>>> On 10/30/2024 8:46 AM, Sean Christopherson wrote:
>>>>>>> +/* Minimum firmware version required for the SEV-SNP support */
>>>>>>> +#define SNP_FW_REQ_VER_MAJOR   1
>>>>>>> +#define SNP_FW_REQ_VER_MINOR   51
>>>>>>>
>>>>>>> Side topic, why are these hardcoded?  And where did they come from?  If they're
>>>>>>> arbitrary KVM selftests values, make that super duper clear.
>>>>>>
>>>>>> Well, it's not entirely arbitrary. This was the version that SNP GA'd
>>>>>> with first so that kind of became the minimum required version needed.
>>>>>>
>>>>>> I think the only place we've documented this is here -
>>>>>> https://github.com/AMDESE/AMDSEV/tree/snp-latest?tab=readme-ov-file#upgrade-sev-firmware.
>>>>>>
>>>>>> Maybe, I can modify the comment above to say something like -
>>>>>> Minimum general availability release firmware required for SEV-SNP support.
>>>>>
>>>>> Hmm, so if AMD says SNP is only supported for firmware version >= 1.51, why on
>>>>> earth is that not checked and enforced by the kernel?  Relying on userspace to
>>>>> not crash the host (or worse) because of unsupported firmware is not a winning
>>>>> strategy.
>>>>
>>>> We do check against the firmware level 1.51 while setting things up
>>>> first (drivers/crypto/ccp/sev-dev.c:__sev_snp_init_locked()) and we bail
>>>> out if it's otherwise. From the userspace, calls to KVM_SEV_INIT2 or any
>>>> other corresponding SNP calls should fail cleanly without any adverse
>>>> effects to the host.
>>>
>>> And I'm saying, that's not good enough.  If the platform doesn't support SNP,
>>> the KVM *must not* advertise support for SNP.
>>>
>>
>> Sure, fair to expect this. Currently, if the FW check fails, SNP is not
>> setup and there is nothing that indicates in the KVM capabilities (apart
>> from one dmesg error) that the support does not exist.
>>
>> One thing I could do (as an independent patch) is to introduce a CC API
>> that abstracts the FW version check made by the CCP module. Since sev
>> platform status can be gotten before INIT to extract the major and minor
>> version numbers, KVM can also call into this API and use that to decide
>> if the KVM capabilities for SNP must be set or not.
> 
> Why is CC_ATTR_HOST_SEV_SNP set if hardware/firmware can't actually support SNP?
> KVM shouldn't have to care about some arbitrary firmware API version, the whole
> point of a driver is so that KVM doesn't have to deal with such details.
> 
> I'm a-ok with a KVM selftest *asserting* that the kernel isn't broken, but KVM
> itself shouldn't need to manually check the firmware version.

Clearing CC_ATTR_HOST_SEV_SNP when the init fails is one approach to go
about it. Here we could clear it from here and eventually that would
prevent the the SNP feature being set in KVM capability.

+++ b/drivers/crypto/ccp/sev-dev.c
@@ -1099,6 +1099,7 @@ static int __sev_snp_init_locked(int *error)
                return 0;

        if (!sev_version_greater_or_equal(SNP_MIN_API_MAJOR, SNP_MIN_API_MINOR)) {
+               cc_platform_clear(CC_ATTR_HOST_SEV_SNP);

A suggestion where we could more directly approach this could be by
exporting an explicit check from ccp instead?

--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -122,6 +122,12 @@ static inline bool sev_version_greater_or_equal(u8 maj, u8 min)
        return false;
 }

+bool sev_snp_fw_available(void)
+{
+    return sev_version_greater_or_equal(SNP_MIN_API_MAJOR, SNP_MIN_API_MINOR);
+}
+EXPORT_SYMBOL_GPL(sev_snp_fw_available);

which could be then called on will as follows:

--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3050,7 +3050,9 @@ void __init sev_hardware_setup(void)
        sev_es_asid_count = min_sev_asid - 1;
        WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count));
        sev_es_supported = true;
-       sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP);
+       sev_snp_supported = sev_snp_enabled && cc_platform_has(CC_ATTR_HOST_SEV_SNP) && sev_snp_fw_available();

 out:
        if (boot_cpu_has(X86_FEATURE_SEV))

This would ensure that we could enable and disable the SNP capability
even in the case where maybe the firmware can get hotloaded using the
proposed download_firmware_ex[1] or in cases where the INIT could be
deferred; all while KVM wouldn't need to be bothered with the API
details.

[1]: https://lore.kernel.org/lkml/20241029183907.3536683-1-dionnaglaze@google.com/



  reply	other threads:[~2024-11-05  4:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-05 12:40 [PATCH v3 0/9] SEV Kernel Selftests Pratik R. Sampat
2024-09-05 12:40 ` [PATCH v3 1/9] KVM: selftests: Decouple SEV ioctls from asserts Pratik R. Sampat
2024-10-14 22:18   ` Sean Christopherson
2024-10-21 20:23     ` Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 2/9] KVM: selftests: Add a basic SNP smoke test Pratik R. Sampat
2024-10-14 22:46   ` Sean Christopherson
2024-10-21 20:23     ` Pratik R. Sampat
2024-10-28 17:55       ` Sean Christopherson
2024-10-28 20:41         ` Pratik R. Sampat
2024-10-30 13:46           ` Sean Christopherson
2024-10-30 16:35             ` Pratik R. Sampat
2024-10-30 17:57               ` Sean Christopherson
2024-10-31 15:45                 ` Pratik R. Sampat
2024-10-31 16:27                   ` Sean Christopherson
2024-11-04 20:21                     ` Pratik R. Sampat
2024-11-04 23:47                       ` Sean Christopherson
2024-11-05  4:14                         ` Pratik R. Sampat [this message]
2024-09-05 12:41 ` [PATCH v3 3/9] KVM: selftests: Add SNP to shutdown testing Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 4/9] KVM: selftests: SEV IOCTL test Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 5/9] KVM: selftests: SNP " Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 6/9] KVM: selftests: SEV-SNP test for KVM_SEV_INIT2 Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 7/9] KVM: selftests: Add interface to manually flag protected/encrypted ranges Pratik R. Sampat
2024-10-14 22:58   ` Sean Christopherson
2024-10-21 20:23     ` Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 8/9] KVM: selftests: Add a CoCo-specific test for KVM_PRE_FAULT_MEMORY Pratik R. Sampat
2024-09-05 12:41 ` [PATCH v3 9/9] KVM: selftests: Interleave fallocate " Pratik R. Sampat
2024-10-14 22:23 ` [PATCH v3 0/9] SEV Kernel Selftests Sean Christopherson
2024-10-21 20:23   ` Pratik R. Sampat

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=0efe04cf-9b12-4a22-ad76-b7cd1f719f45@amd.com \
    --to=pratikrajesh.sampat@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=thomas.lendacky@amd.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