From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399335; b=hx0oDK7PenVeRE2QUnnD8SsyMwwGut6PMzH9L+YilxT1QR8u5zmBs2OK9twhEiF9NoSx 9BtMapyF8Gq8n3X+9bNc56SA+pq4EimkS7I1qdOEETmld+c0FwSNR5Fzlh9J26QoufaX2 KdnNVDd1cfHodgOC3PRsygEMmbvSxpd7xlws9V3b6WZJQrq53l2Lvx8xAtHWqoG7f+mjm iOosfXnFEE4N4/cScEK4d5orf0fmraWauDxFc7z4N/bg27qJAG3fVFy0+rzZBihQUmEBV TRi+lU0NnM+6RP79DLw1RvruHEn16jmooAF3lUasNfZvfGgQPluzCXgv4rNTPYRo9PA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399335; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Developer-Key:X-Developer-Signature:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=x39Fc4Nf3d8SSyt4Srrz7cGL5EJu1JqpVWC5jT2Dmr0=; b=JMnX4M9QjwH9Q7YkXS7SO5J2UmwKoHhbq7v3G67m1tYpiQXJrqL2WcmzYPePqYpa07ez z52/PNQwkurrwndg0owc1VG/K1mDZIX6QczpMpU6sph//8uf4JTrzdpbbnodhex5y+cUn crygxjdSh1aK8JoCZm4Z+jrGymLqplkFdwbUQlUYQP1lfe1WlAdVgES3o+Ym9A4cT7TAb zf0ObNg/zcW0ADPdmOOArqfDX22XmGkIM+oX5McoUYo3yYso0bF5lltDr1t49IFjHyYF4 K6eJXhP0/Hb65MWcQneRFuuNTXT4FMlLqMmcvz9MtJ6IPv2ndk1m9RxL+oFCJmNJAtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b="UnIh+V/t"; arc=none smtp.remote-ip=209.85.221.71 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FB90606A322 for ; Fri, 4 Dec 2026 15:48:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1FB90606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=UnIh+V/t Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-49337a224a8so589651f8f.3 for ; Fri, 04 Dec 2026 07:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796399333; x=1797004133; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=x39Fc4Nf3d8SSyt4Srrz7cGL5EJu1JqpVWC5jT2Dmr0=; b=UnIh+V/tM7JCxVG1Tor6SfbXxe1IU+L9wJD5x3dY9j703DYg54aOj4hmk4mbr1MF2j wtfcMYfiGVgOJHKCAYCPGwcC9vuQwmPB/NF2LRuSZCiyVIDnzd+H3hZaN15XrkkQH0Ie KVg4wJxC6g/3sZ+BU1SJ/1pggoOm8zqkNrKDvLncCzpnA9M3W1Q6nYYKTxOyBkRpofz0 0O+NdqIz4FearsZdebMZldHkofhV8e2C1seG0F41ugVtMMukiLDI86UmcxTaSEYWZ1sv covbkQVXlftEvdmNq3FpSLHFiZ7g5bkdviYB5/NebxK+fllmf7UcAKUhr2uBepDwObSX FMlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796399333; x=1797004133; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=x39Fc4Nf3d8SSyt4Srrz7cGL5EJu1JqpVWC5jT2Dmr0=; b=AnpTaBsSkKVu3XWTU126ywFQ7tYauNNuUEzAjnRtdZ1WcGzsQZl709iEM705nzm6fp yzB8MVvYnZSiGwS0CBXAv4AGurpNTHfB/AkfciEQ6dsQ+qTI5Yt04zFHx816waxv0t0R CcJtj4aU17eiLe32IQoQxqjzbKieqjsn9CmSLMLZykcFFO7cGw6A2H6UyOr818eKmUgd l1jCCFLRcgElKfjvPtObSPgq2J8dZDRnqxa7p431jCadDsF10uRHxbAEl3qVSPDYNZ7l O1+s43FFdeEs8inSUG6MT9Q6wpRRIjCUMiWIHDvrbVKw2uIXn+ChdDt6/9p1WYjbFHkv t4Rw== X-Gm-Message-State: AB4q+uHGlgyw+ABOLUKz4Km25myQHOnGCaO/Hwx6bJeUuDjKW3QrYjrA BUnvpWbL0GFe413pQODs35myM3JZNDCqaYSkbZYxoH1mSX7HlRz9AF026fFopEHOeFfh3hD89c6 4hv61c48hn7KkIXbyiZU9+qH4V7k63WBl5V4T1uzaEjMX0PxbFUXTJS+T5Pb0fUvFeT3nqrM2F2 Ioin9R2+xt79PP/VU47//cjDIuGDLKCA== X-Received: from wrsn3.prod.google.com ([2002:a5d:4843:0:b0:4a7:4422:f19c]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2902:b0:48d:fd4d:7fbe with SMTP id ffacd0b85a97d-4d1e291e0ffmr5770389f8f.2.1796399333083; Fri, 04 Dec 2026 07:48:53 -0800 (PST) Date: Fri, 4 Dec 2026 16:48:45 +0100 In-Reply-To: <20261204154842.414894-5-ardb+git@google.com> X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204154842.414894-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5496; i=ardb@kernel.org; h=from:subject; bh=1jeg3euRilRo7EXTD1iWfIFI5e83Up6kfMtjOlZY6CI=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIVvowb2nh9YXfvi14CnH0yna57aG1b5p4OU7z5f27Dnn8 YIpJlNvdpSyMIhxMciKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJMCcwMky/8erOutuBJ5eb J8+9esuqx/nUDat1cX8XnJmQ67rBffddhr8is1bsELtUU+jCVDn7ynNBuSqVzvLeRP03KlucxOa b7GQCAA== X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204154842.414894-7-ardb+git@google.com> Subject: [PATCH v2 2/3] x86/sev: Check for SVSM GHCB event support in svsm_setup_ca() From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Borislav Petkov , Tom Lendacky , Ashish Kalra Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel Running an SEV-SNP guest at a VMPL other than 0 requires the hypervisor to support the GHCB events that are used to communicate with the SVSM. Currently, this is only checked in the decompressor's sev_enable(), which the EFI stub calls as well before handing over to the core kernel, but the core kernel's SEV-SNP startup code does not perform this check itself. This is the only check performed by sev_enable() that is not duplicated by the core kernel, and so moving it into code that is shared with the core kernel is needed so that SEV-SNP enablement can be omitted entirely from the EFI stub boot path, without losing this check. So move the check into svsm_setup_ca(), which is shared between the decompressor and the core kernel's startup code, and is where it is first established that the guest is not running at VMPL0. Given that the hypervisor features are only available from GHCB protocol version 2 onward, and that svsm_setup_ca() is called before the GHCB protocol version is negotiated, move sev_es_negotiate_protocol() into the shared startup code as well, and call it before querying the hypervisor features. Suggested-by: Tom Lendacky Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/sev.c | 7 ----- arch/x86/boot/startup/exports.h | 1 + arch/x86/boot/startup/sev-shared.c | 32 ++++++++++++++++++++ arch/x86/coco/sev/vc-shared.c | 21 ------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index c6512f2ea31e..496cb65c46ba 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -420,13 +420,6 @@ void sev_enable(struct boot_params *bp) hv_features = get_hv_features(); if (!(hv_features & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - - /* - * Running at VMPL0 is required unless an SVSM is present and - * the hypervisor supports the required SVSM GHCB events. - */ - if (snp_vmpl && !(hv_features & GHCB_HV_FT_SNP_MULTI_VMPL)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) diff --git a/arch/x86/boot/startup/exports.h b/arch/x86/boot/startup/exports.h index 01d2363dc445..daab87c9e2db 100644 --- a/arch/x86/boot/startup/exports.h +++ b/arch/x86/boot/startup/exports.h @@ -7,6 +7,7 @@ PROVIDE(early_set_pages_state = __pi_early_set_pages_state); PROVIDE(early_snp_set_memory_private = __pi_early_snp_set_memory_private); PROVIDE(early_snp_set_memory_shared = __pi_early_snp_set_memory_shared); PROVIDE(get_hv_features = __pi_get_hv_features); +PROVIDE(sev_es_negotiate_protocol = __pi_sev_es_negotiate_protocol); PROVIDE(sev_es_terminate = __pi_sev_es_terminate); PROVIDE(snp_cpuid = __pi_snp_cpuid); PROVIDE(snp_cpuid_get_table = __pi_snp_cpuid_get_table); diff --git a/arch/x86/boot/startup/sev-shared.c b/arch/x86/boot/startup/sev-shared.c index d9ac3a929d33..c6648501433e 100644 --- a/arch/x86/boot/startup/sev-shared.c +++ b/arch/x86/boot/startup/sev-shared.c @@ -49,6 +49,27 @@ sev_es_terminate(unsigned int set, unsigned int reason) asm volatile("hlt\n" : : : "memory"); } +bool sev_es_negotiate_protocol(void) +{ + u64 val; + + /* Do the GHCB protocol version negotiation */ + sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ); + VMGEXIT(); + val = sev_es_rd_ghcb_msr(); + + if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP) + return false; + + if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || + GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) + return false; + + ghcb_version = min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX); + + return true; +} + /* * The hypervisor features are available from GHCB version 2 onward. */ @@ -722,6 +743,17 @@ static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info, if (!rmpadjust((unsigned long)page, RMP_PG_SIZE_4K, 1)) return false; + /* + * Running at VMPL0 is required unless an SVSM is present and the + * hypervisor supports the required SVSM GHCB events. The hypervisor + * features are only available from GHCB version 2 onward, and this + * code may run before the GHCB protocol version has been negotiated, + * so take care of that first. + */ + if (!sev_es_negotiate_protocol() || + !(get_hv_features() & GHCB_HV_FT_SNP_MULTI_VMPL)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); + /* * Not running at VMPL0, ensure everything has been properly supplied * for running under an SVSM. diff --git a/arch/x86/coco/sev/vc-shared.c b/arch/x86/coco/sev/vc-shared.c index 58b2f985d546..3048347c158c 100644 --- a/arch/x86/coco/sev/vc-shared.c +++ b/arch/x86/coco/sev/vc-shared.c @@ -633,24 +633,3 @@ bool __init sev_es_check_cpu_features(void) return true; } - -bool sev_es_negotiate_protocol(void) -{ - u64 val; - - /* Do the GHCB protocol version negotiation */ - sev_es_wr_ghcb_msr(GHCB_MSR_SEV_INFO_REQ); - VMGEXIT(); - val = sev_es_rd_ghcb_msr(); - - if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP) - return false; - - if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || - GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) - return false; - - ghcb_version = min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX); - - return true; -} -- 2.56.1.915.g69d5ec7298-goog