// SPDX-License-Identifier: GPL-2.01/*2* AMD Encrypted Register State Support3*4* Author: Joerg Roedel <[email protected]>5*6* This file is not compiled stand-alone. It contains code shared7* between the pre-decompression boot code and the running Linux kernel8* and is included directly into both code-bases.9*/1011#include <asm/setup_data.h>1213#ifndef __BOOT_COMPRESSED14#define has_cpuflag(f) boot_cpu_has(f)15#else16#undef WARN17#define WARN(condition, format...) (!!(condition))18#endif1920/* Copy of the SNP firmware's CPUID page. */21static struct snp_cpuid_table cpuid_table_copy __ro_after_init;2223/*24* These will be initialized based on CPUID table so that non-present25* all-zero leaves (for sparse tables) can be differentiated from26* invalid/out-of-range leaves. This is needed since all-zero leaves27* still need to be post-processed.28*/29static u32 cpuid_std_range_max __ro_after_init;30static u32 cpuid_hyp_range_max __ro_after_init;31static u32 cpuid_ext_range_max __ro_after_init;3233bool sev_snp_needs_sfw;3435void __noreturn36sev_es_terminate(unsigned int set, unsigned int reason)37{38u64 val = GHCB_MSR_TERM_REQ;3940/* Tell the hypervisor what went wrong. */41val |= GHCB_SEV_TERM_REASON(set, reason);4243/* Request Guest Termination from Hypervisor */44sev_es_wr_ghcb_msr(val);45VMGEXIT();4647while (true)48asm volatile("hlt\n" : : : "memory");49}5051/*52* The hypervisor features are available from GHCB version 2 onward.53*/54u64 __init get_hv_features(void)55{56u64 val;5758if (ghcb_version < 2)59return 0;6061sev_es_wr_ghcb_msr(GHCB_MSR_HV_FT_REQ);62VMGEXIT();6364val = sev_es_rd_ghcb_msr();65if (GHCB_RESP_CODE(val) != GHCB_MSR_HV_FT_RESP)66return 0;6768return GHCB_MSR_HV_FT_RESP_VAL(val);69}7071int svsm_process_result_codes(struct svsm_call *call)72{73switch (call->rax_out) {74case SVSM_SUCCESS:75return 0;76case SVSM_ERR_INCOMPLETE:77case SVSM_ERR_BUSY:78return -EAGAIN;79default:80return -EINVAL;81}82}8384/*85* Issue a VMGEXIT to call the SVSM:86* - Load the SVSM register state (RAX, RCX, RDX, R8 and R9)87* - Set the CA call pending field to 188* - Issue VMGEXIT89* - Save the SVSM return register state (RAX, RCX, RDX, R8 and R9)90* - Perform atomic exchange of the CA call pending field91*92* - See the "Secure VM Service Module for SEV-SNP Guests" specification for93* details on the calling convention.94* - The calling convention loosely follows the Microsoft X64 calling95* convention by putting arguments in RCX, RDX, R8 and R9.96* - RAX specifies the SVSM protocol/callid as input and the return code97* as output.98*/99void svsm_issue_call(struct svsm_call *call, u8 *pending)100{101register unsigned long rax asm("rax") = call->rax;102register unsigned long rcx asm("rcx") = call->rcx;103register unsigned long rdx asm("rdx") = call->rdx;104register unsigned long r8 asm("r8") = call->r8;105register unsigned long r9 asm("r9") = call->r9;106107call->caa->call_pending = 1;108109asm volatile("rep; vmmcall\n\t"110: "+r" (rax), "+r" (rcx), "+r" (rdx), "+r" (r8), "+r" (r9)111: : "memory");112113*pending = xchg(&call->caa->call_pending, *pending);114115call->rax_out = rax;116call->rcx_out = rcx;117call->rdx_out = rdx;118call->r8_out = r8;119call->r9_out = r9;120}121122int svsm_perform_msr_protocol(struct svsm_call *call)123{124u8 pending = 0;125u64 val, resp;126127/*128* When using the MSR protocol, be sure to save and restore129* the current MSR value.130*/131val = sev_es_rd_ghcb_msr();132133sev_es_wr_ghcb_msr(GHCB_MSR_VMPL_REQ_LEVEL(0));134135svsm_issue_call(call, &pending);136137resp = sev_es_rd_ghcb_msr();138139sev_es_wr_ghcb_msr(val);140141if (pending)142return -EINVAL;143144if (GHCB_RESP_CODE(resp) != GHCB_MSR_VMPL_RESP)145return -EINVAL;146147if (GHCB_MSR_VMPL_RESP_VAL(resp))148return -EINVAL;149150return svsm_process_result_codes(call);151}152153static int __sev_cpuid_hv(u32 fn, int reg_idx, u32 *reg)154{155u64 val;156157sev_es_wr_ghcb_msr(GHCB_CPUID_REQ(fn, reg_idx));158VMGEXIT();159val = sev_es_rd_ghcb_msr();160if (GHCB_RESP_CODE(val) != GHCB_MSR_CPUID_RESP)161return -EIO;162163*reg = (val >> 32);164165return 0;166}167168static int __sev_cpuid_hv_msr(struct cpuid_leaf *leaf)169{170int ret;171172/*173* MSR protocol does not support fetching non-zero subfunctions, but is174* sufficient to handle current early-boot cases. Should that change,175* make sure to report an error rather than ignoring the index and176* grabbing random values. If this issue arises in the future, handling177* can be added here to use GHCB-page protocol for cases that occur late178* enough in boot that GHCB page is available.179*/180if (cpuid_function_is_indexed(leaf->fn) && leaf->subfn)181return -EINVAL;182183ret = __sev_cpuid_hv(leaf->fn, GHCB_CPUID_REQ_EAX, &leaf->eax);184ret = ret ? : __sev_cpuid_hv(leaf->fn, GHCB_CPUID_REQ_EBX, &leaf->ebx);185ret = ret ? : __sev_cpuid_hv(leaf->fn, GHCB_CPUID_REQ_ECX, &leaf->ecx);186ret = ret ? : __sev_cpuid_hv(leaf->fn, GHCB_CPUID_REQ_EDX, &leaf->edx);187188return ret;189}190191192193/*194* This may be called early while still running on the initial identity195* mapping. Use RIP-relative addressing to obtain the correct address196* while running with the initial identity mapping as well as the197* switch-over to kernel virtual addresses later.198*/199const struct snp_cpuid_table *snp_cpuid_get_table(void)200{201return rip_rel_ptr(&cpuid_table_copy);202}203204/*205* The SNP Firmware ABI, Revision 0.9, Section 7.1, details the use of206* XCR0_IN and XSS_IN to encode multiple versions of 0xD subfunctions 0207* and 1 based on the corresponding features enabled by a particular208* combination of XCR0 and XSS registers so that a guest can look up the209* version corresponding to the features currently enabled in its XCR0/XSS210* registers. The only values that differ between these versions/table211* entries is the enabled XSAVE area size advertised via EBX.212*213* While hypervisors may choose to make use of this support, it is more214* robust/secure for a guest to simply find the entry corresponding to the215* base/legacy XSAVE area size (XCR0=1 or XCR0=3), and then calculate the216* XSAVE area size using subfunctions 2 through 64, as documented in APM217* Volume 3, Rev 3.31, Appendix E.3.8, which is what is done here.218*219* Since base/legacy XSAVE area size is documented as 0x240, use that value220* directly rather than relying on the base size in the CPUID table.221*222* Return: XSAVE area size on success, 0 otherwise.223*/224static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)225{226const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();227u64 xfeatures_found = 0;228u32 xsave_size = 0x240;229int i;230231for (i = 0; i < cpuid_table->count; i++) {232const struct snp_cpuid_fn *e = &cpuid_table->fn[i];233234if (!(e->eax_in == 0xD && e->ecx_in > 1 && e->ecx_in < 64))235continue;236if (!(xfeatures_en & (BIT_ULL(e->ecx_in))))237continue;238if (xfeatures_found & (BIT_ULL(e->ecx_in)))239continue;240241xfeatures_found |= (BIT_ULL(e->ecx_in));242243if (compacted)244xsave_size += e->eax;245else246xsave_size = max(xsave_size, e->eax + e->ebx);247}248249/*250* Either the guest set unsupported XCR0/XSS bits, or the corresponding251* entries in the CPUID table were not present. This is not a valid252* state to be in.253*/254if (xfeatures_found != (xfeatures_en & GENMASK_ULL(63, 2)))255return 0;256257return xsave_size;258}259260static bool261snp_cpuid_get_validated_func(struct cpuid_leaf *leaf)262{263const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();264int i;265266for (i = 0; i < cpuid_table->count; i++) {267const struct snp_cpuid_fn *e = &cpuid_table->fn[i];268269if (e->eax_in != leaf->fn)270continue;271272if (cpuid_function_is_indexed(leaf->fn) && e->ecx_in != leaf->subfn)273continue;274275/*276* For 0xD subfunctions 0 and 1, only use the entry corresponding277* to the base/legacy XSAVE area size (XCR0=1 or XCR0=3, XSS=0).278* See the comments above snp_cpuid_calc_xsave_size() for more279* details.280*/281if (e->eax_in == 0xD && (e->ecx_in == 0 || e->ecx_in == 1))282if (!(e->xcr0_in == 1 || e->xcr0_in == 3) || e->xss_in)283continue;284285leaf->eax = e->eax;286leaf->ebx = e->ebx;287leaf->ecx = e->ecx;288leaf->edx = e->edx;289290return true;291}292293return false;294}295296static void snp_cpuid_hv_msr(void *ctx, struct cpuid_leaf *leaf)297{298if (__sev_cpuid_hv_msr(leaf))299sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV);300}301302static int303snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),304void *ctx, struct cpuid_leaf *leaf)305{306struct cpuid_leaf leaf_hv = *leaf;307308switch (leaf->fn) {309case 0x1:310cpuid_fn(ctx, &leaf_hv);311312/* initial APIC ID */313leaf->ebx = (leaf_hv.ebx & GENMASK(31, 24)) | (leaf->ebx & GENMASK(23, 0));314/* APIC enabled bit */315leaf->edx = (leaf_hv.edx & BIT(9)) | (leaf->edx & ~BIT(9));316317/* OSXSAVE enabled bit */318if (native_read_cr4() & X86_CR4_OSXSAVE)319leaf->ecx |= BIT(27);320break;321case 0x7:322/* OSPKE enabled bit */323leaf->ecx &= ~BIT(4);324if (native_read_cr4() & X86_CR4_PKE)325leaf->ecx |= BIT(4);326break;327case 0xB:328leaf_hv.subfn = 0;329cpuid_fn(ctx, &leaf_hv);330331/* extended APIC ID */332leaf->edx = leaf_hv.edx;333break;334case 0xD: {335bool compacted = false;336u64 xcr0 = 1, xss = 0;337u32 xsave_size;338339if (leaf->subfn != 0 && leaf->subfn != 1)340return 0;341342if (native_read_cr4() & X86_CR4_OSXSAVE)343xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK);344if (leaf->subfn == 1) {345/* Get XSS value if XSAVES is enabled. */346if (leaf->eax & BIT(3)) {347unsigned long lo, hi;348349asm volatile("rdmsr" : "=a" (lo), "=d" (hi)350: "c" (MSR_IA32_XSS));351xss = (hi << 32) | lo;352}353354/*355* The PPR and APM aren't clear on what size should be356* encoded in 0xD:0x1:EBX when compaction is not enabled357* by either XSAVEC (feature bit 1) or XSAVES (feature358* bit 3) since SNP-capable hardware has these feature359* bits fixed as 1. KVM sets it to 0 in this case, but360* to avoid this becoming an issue it's safer to simply361* treat this as unsupported for SNP guests.362*/363if (!(leaf->eax & (BIT(1) | BIT(3))))364return -EINVAL;365366compacted = true;367}368369xsave_size = snp_cpuid_calc_xsave_size(xcr0 | xss, compacted);370if (!xsave_size)371return -EINVAL;372373leaf->ebx = xsave_size;374}375break;376case 0x8000001E:377cpuid_fn(ctx, &leaf_hv);378379/* extended APIC ID */380leaf->eax = leaf_hv.eax;381/* compute ID */382leaf->ebx = (leaf->ebx & GENMASK(31, 8)) | (leaf_hv.ebx & GENMASK(7, 0));383/* node ID */384leaf->ecx = (leaf->ecx & GENMASK(31, 8)) | (leaf_hv.ecx & GENMASK(7, 0));385break;386default:387/* No fix-ups needed, use values as-is. */388break;389}390391return 0;392}393394/*395* Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return value396* should be treated as fatal by caller.397*/398int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),399void *ctx, struct cpuid_leaf *leaf)400{401const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();402403if (!cpuid_table->count)404return -EOPNOTSUPP;405406if (!snp_cpuid_get_validated_func(leaf)) {407/*408* Some hypervisors will avoid keeping track of CPUID entries409* where all values are zero, since they can be handled the410* same as out-of-range values (all-zero). This is useful here411* as well as it allows virtually all guest configurations to412* work using a single SNP CPUID table.413*414* To allow for this, there is a need to distinguish between415* out-of-range entries and in-range zero entries, since the416* CPUID table entries are only a template that may need to be417* augmented with additional values for things like418* CPU-specific information during post-processing. So if it's419* not in the table, set the values to zero. Then, if they are420* within a valid CPUID range, proceed with post-processing421* using zeros as the initial values. Otherwise, skip422* post-processing and just return zeros immediately.423*/424leaf->eax = leaf->ebx = leaf->ecx = leaf->edx = 0;425426/* Skip post-processing for out-of-range zero leafs. */427if (!(leaf->fn <= cpuid_std_range_max ||428(leaf->fn >= 0x40000000 && leaf->fn <= cpuid_hyp_range_max) ||429(leaf->fn >= 0x80000000 && leaf->fn <= cpuid_ext_range_max)))430return 0;431}432433return snp_cpuid_postprocess(cpuid_fn, ctx, leaf);434}435436/*437* Boot VC Handler - This is the first VC handler during boot, there is no GHCB438* page yet, so it only supports the MSR based communication with the439* hypervisor and only the CPUID exit-code.440*/441void do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)442{443unsigned int subfn = lower_bits(regs->cx, 32);444unsigned int fn = lower_bits(regs->ax, 32);445u16 opcode = *(unsigned short *)regs->ip;446struct cpuid_leaf leaf;447int ret;448449/* Only CPUID is supported via MSR protocol */450if (exit_code != SVM_EXIT_CPUID)451goto fail;452453/* Is it really a CPUID insn? */454if (opcode != 0xa20f)455goto fail;456457leaf.fn = fn;458leaf.subfn = subfn;459460/*461* If SNP is active, then snp_cpuid() uses the CPUID table to obtain the462* CPUID values (with possible HV interaction during post-processing of463* the values). But if SNP is not active (no CPUID table present), then464* snp_cpuid() returns -EOPNOTSUPP so that an SEV-ES guest can call the465* HV to obtain the CPUID information.466*/467ret = snp_cpuid(snp_cpuid_hv_msr, NULL, &leaf);468if (!ret)469goto cpuid_done;470471if (ret != -EOPNOTSUPP)472goto fail;473474/*475* This is reached by a SEV-ES guest and needs to invoke the HV for476* the CPUID data.477*/478if (__sev_cpuid_hv_msr(&leaf))479goto fail;480481cpuid_done:482regs->ax = leaf.eax;483regs->bx = leaf.ebx;484regs->cx = leaf.ecx;485regs->dx = leaf.edx;486487/*488* This is a VC handler and the #VC is only raised when SEV-ES is489* active, which means SEV must be active too. Do sanity checks on the490* CPUID results to make sure the hypervisor does not trick the kernel491* into the no-sev path. This could map sensitive data unencrypted and492* make it accessible to the hypervisor.493*494* In particular, check for:495* - Availability of CPUID leaf 0x8000001f496* - SEV CPUID bit.497*498* The hypervisor might still report the wrong C-bit position, but this499* can't be checked here.500*/501502if (fn == 0x80000000 && (regs->ax < 0x8000001f))503/* SEV leaf check */504goto fail;505else if ((fn == 0x8000001f && !(regs->ax & BIT(1))))506/* SEV bit */507goto fail;508509/* Skip over the CPUID two-byte opcode */510regs->ip += 2;511512return;513514fail:515/* Terminate the guest */516sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);517}518519struct cc_setup_data {520struct setup_data header;521u32 cc_blob_address;522};523524/*525* Search for a Confidential Computing blob passed in as a setup_data entry526* via the Linux Boot Protocol.527*/528static __init529struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)530{531struct cc_setup_data *sd = NULL;532struct setup_data *hdr;533534hdr = (struct setup_data *)bp->hdr.setup_data;535536while (hdr) {537if (hdr->type == SETUP_CC_BLOB) {538sd = (struct cc_setup_data *)hdr;539return (struct cc_blob_sev_info *)(unsigned long)sd->cc_blob_address;540}541hdr = (struct setup_data *)hdr->next;542}543544return NULL;545}546547/*548* Initialize the kernel's copy of the SNP CPUID table, and set up the549* pointer that will be used to access it.550*551* Maintaining a direct mapping of the SNP CPUID table used by firmware would552* be possible as an alternative, but the approach is brittle since the553* mapping needs to be updated in sync with all the changes to virtual memory554* layout and related mapping facilities throughout the boot process.555*/556static void __init setup_cpuid_table(const struct cc_blob_sev_info *cc_info)557{558const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table;559int i;560561if (!cc_info || !cc_info->cpuid_phys || cc_info->cpuid_len < PAGE_SIZE)562sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID);563564cpuid_table_fw = (const struct snp_cpuid_table *)cc_info->cpuid_phys;565if (!cpuid_table_fw->count || cpuid_table_fw->count > SNP_CPUID_COUNT_MAX)566sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID);567568cpuid_table = snp_cpuid_get_table();569memcpy((void *)cpuid_table, cpuid_table_fw, sizeof(*cpuid_table));570571/* Initialize CPUID ranges for range-checking. */572for (i = 0; i < cpuid_table->count; i++) {573const struct snp_cpuid_fn *fn = &cpuid_table->fn[i];574575if (fn->eax_in == 0x0)576cpuid_std_range_max = fn->eax;577else if (fn->eax_in == 0x40000000)578cpuid_hyp_range_max = fn->eax;579else if (fn->eax_in == 0x80000000)580cpuid_ext_range_max = fn->eax;581}582}583584static int svsm_call_msr_protocol(struct svsm_call *call)585{586int ret;587588do {589ret = svsm_perform_msr_protocol(call);590} while (ret == -EAGAIN);591592return ret;593}594595static void svsm_pval_4k_page(unsigned long paddr, bool validate,596struct svsm_ca *caa, u64 caa_pa)597{598struct svsm_pvalidate_call *pc;599struct svsm_call call = {};600unsigned long flags;601u64 pc_pa;602603/*604* This can be called very early in the boot, use native functions in605* order to avoid paravirt issues.606*/607flags = native_local_irq_save();608609call.caa = caa;610611pc = (struct svsm_pvalidate_call *)call.caa->svsm_buffer;612pc_pa = caa_pa + offsetof(struct svsm_ca, svsm_buffer);613614pc->num_entries = 1;615pc->cur_index = 0;616pc->entry[0].page_size = RMP_PG_SIZE_4K;617pc->entry[0].action = validate;618pc->entry[0].ignore_cf = 0;619pc->entry[0].rsvd = 0;620pc->entry[0].pfn = paddr >> PAGE_SHIFT;621622/* Protocol 0, Call ID 1 */623call.rax = SVSM_CORE_CALL(SVSM_CORE_PVALIDATE);624call.rcx = pc_pa;625626/*627* Use the MSR protocol exclusively, so that this code is usable in628* startup code where VA/PA translations of the GHCB page's address may629* be problematic.630*/631if (svsm_call_msr_protocol(&call))632sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE);633634native_local_irq_restore(flags);635}636637static void pvalidate_4k_page(unsigned long vaddr, unsigned long paddr,638bool validate, struct svsm_ca *caa, u64 caa_pa)639{640int ret;641642if (snp_vmpl) {643svsm_pval_4k_page(paddr, validate, caa, caa_pa);644} else {645ret = pvalidate(vaddr, RMP_PG_SIZE_4K, validate);646if (ret)647sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PVALIDATE);648}649650/*651* If validating memory (making it private) and affected by the652* cache-coherency vulnerability, perform the cache eviction mitigation.653*/654if (validate && sev_snp_needs_sfw)655sev_evict_cache((void *)vaddr, 1);656}657658static void __page_state_change(unsigned long vaddr, unsigned long paddr,659const struct psc_desc *desc)660{661u64 val, msr;662663/*664* If private -> shared then invalidate the page before requesting the665* state change in the RMP table.666*/667if (desc->op == SNP_PAGE_STATE_SHARED)668pvalidate_4k_page(vaddr, paddr, false, desc->ca, desc->caa_pa);669670/* Save the current GHCB MSR value */671msr = sev_es_rd_ghcb_msr();672673/* Issue VMGEXIT to change the page state in RMP table. */674sev_es_wr_ghcb_msr(GHCB_MSR_PSC_REQ_GFN(paddr >> PAGE_SHIFT, desc->op));675VMGEXIT();676677/* Read the response of the VMGEXIT. */678val = sev_es_rd_ghcb_msr();679if ((GHCB_RESP_CODE(val) != GHCB_MSR_PSC_RESP) || GHCB_MSR_PSC_RESP_VAL(val))680sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);681682/* Restore the GHCB MSR value */683sev_es_wr_ghcb_msr(msr);684685/*686* Now that page state is changed in the RMP table, validate it so that it is687* consistent with the RMP entry.688*/689if (desc->op == SNP_PAGE_STATE_PRIVATE)690pvalidate_4k_page(vaddr, paddr, true, desc->ca, desc->caa_pa);691}692693/*694* Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the SVSM695* services needed when not running in VMPL0.696*/697static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info,698void *page)699{700struct snp_secrets_page *secrets_page;701struct snp_cpuid_table *cpuid_table;702unsigned int i;703u64 caa;704705BUILD_BUG_ON(sizeof(*secrets_page) != PAGE_SIZE);706707/*708* Check if running at VMPL0.709*710* Use RMPADJUST (see the rmpadjust() function for a description of what711* the instruction does) to update the VMPL1 permissions of a page. If712* the guest is running at VMPL0, this will succeed and implies there is713* no SVSM. If the guest is running at any other VMPL, this will fail.714* Linux SNP guests only ever run at a single VMPL level so permission mask715* changes of a lesser-privileged VMPL are a don't-care.716*717* Use a rip-relative reference to obtain the proper address, since this718* routine is running identity mapped when called, both by the decompressor719* code and the early kernel code.720*/721if (!rmpadjust((unsigned long)page, RMP_PG_SIZE_4K, 1))722return false;723724/*725* Not running at VMPL0, ensure everything has been properly supplied726* for running under an SVSM.727*/728if (!cc_info || !cc_info->secrets_phys || cc_info->secrets_len != PAGE_SIZE)729sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SECRETS_PAGE);730731secrets_page = (struct snp_secrets_page *)cc_info->secrets_phys;732if (!secrets_page->svsm_size)733sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NO_SVSM);734735if (!secrets_page->svsm_guest_vmpl)736sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_VMPL0);737738snp_vmpl = secrets_page->svsm_guest_vmpl;739740caa = secrets_page->svsm_caa;741742/*743* An open-coded PAGE_ALIGNED() in order to avoid including744* kernel-proper headers into the decompressor.745*/746if (caa & (PAGE_SIZE - 1))747sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CAA);748749boot_svsm_caa_pa = caa;750751/* Advertise the SVSM presence via CPUID. */752cpuid_table = (struct snp_cpuid_table *)snp_cpuid_get_table();753for (i = 0; i < cpuid_table->count; i++) {754struct snp_cpuid_fn *fn = &cpuid_table->fn[i];755756if (fn->eax_in == 0x8000001f)757fn->eax |= BIT(28);758}759760return true;761}762763764