mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
Merge tag 'x86_sev_for_v6.9_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SEV updates from Borislav Petkov: - Add the x86 part of the SEV-SNP host support. This will allow the kernel to be used as a KVM hypervisor capable of running SNP (Secure Nested Paging) guests. Roughly speaking, SEV-SNP is the ultimate goal of the AMD confidential computing side, providing the most comprehensive confidential computing environment up to date. This is the x86 part and there is a KVM part which did not get ready in time for the merge window so latter will be forthcoming in the next cycle. - Rework the early code's position-dependent SEV variable references in order to allow building the kernel with clang and -fPIE/-fPIC and -mcmodel=kernel - The usual set of fixes, cleanups and improvements all over the place * tag 'x86_sev_for_v6.9_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits) x86/sev: Disable KMSAN for memory encryption TUs x86/sev: Dump SEV_STATUS crypto: ccp - Have it depend on AMD_IOMMU iommu/amd: Fix failure return from snp_lookup_rmpentry() x86/sev: Fix position dependent variable references in startup code crypto: ccp: Make snp_range_list static x86/Kconfig: Remove CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT Documentation: virt: Fix up pre-formatted text block for SEV ioctls crypto: ccp: Add the SNP_SET_CONFIG command crypto: ccp: Add the SNP_COMMIT command crypto: ccp: Add the SNP_PLATFORM_STATUS command x86/cpufeatures: Enable/unmask SEV-SNP CPU feature KVM: SEV: Make AVIC backing, VMSA and VMCB memory allocation SNP safe crypto: ccp: Add panic notifier for SEV/SNP firmware shutdown on kdump iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown crypto: ccp: Handle legacy SEV commands when SNP is enabled crypto: ccp: Handle non-volatile INIT_EX data when SNP is enabled crypto: ccp: Handle the legacy TMR allocation when SNP is enabled x86/sev: Introduce an SNP leaked pages list crypto: ccp: Provide an API to issue SEV and SNP commands ...
This commit is contained in:
@@ -3318,9 +3318,7 @@
|
||||
|
||||
mem_encrypt= [X86-64] AMD Secure Memory Encryption (SME) control
|
||||
Valid arguments: on, off
|
||||
Default (depends on kernel configuration option):
|
||||
on (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y)
|
||||
off (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=n)
|
||||
Default: off
|
||||
mem_encrypt=on: Activate SME
|
||||
mem_encrypt=off: Do not activate SME
|
||||
|
||||
|
||||
@@ -87,14 +87,14 @@ The state of SME in the Linux kernel can be documented as follows:
|
||||
kernel is non-zero).
|
||||
|
||||
SME can also be enabled and activated in the BIOS. If SME is enabled and
|
||||
activated in the BIOS, then all memory accesses will be encrypted and it will
|
||||
not be necessary to activate the Linux memory encryption support. If the BIOS
|
||||
merely enables SME (sets bit 23 of the MSR_AMD64_SYSCFG), then Linux can activate
|
||||
memory encryption by default (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y) or
|
||||
by supplying mem_encrypt=on on the kernel command line. However, if BIOS does
|
||||
not enable SME, then Linux will not be able to activate memory encryption, even
|
||||
if configured to do so by default or the mem_encrypt=on command line parameter
|
||||
is specified.
|
||||
activated in the BIOS, then all memory accesses will be encrypted and it
|
||||
will not be necessary to activate the Linux memory encryption support.
|
||||
|
||||
If the BIOS merely enables SME (sets bit 23 of the MSR_AMD64_SYSCFG),
|
||||
then memory encryption can be enabled by supplying mem_encrypt=on on the
|
||||
kernel command line. However, if BIOS does not enable SME, then Linux
|
||||
will not be able to activate memory encryption, even if configured to do
|
||||
so by default or the mem_encrypt=on command line parameter is specified.
|
||||
|
||||
Secure Nested Paging (SNP)
|
||||
==========================
|
||||
|
||||
@@ -67,6 +67,23 @@ counter (e.g. counter overflow), then -EIO will be returned.
|
||||
};
|
||||
};
|
||||
|
||||
The host ioctls are issued to a file descriptor of the /dev/sev device.
|
||||
The ioctl accepts the command ID/input structure documented below.
|
||||
|
||||
::
|
||||
|
||||
struct sev_issue_cmd {
|
||||
/* Command ID */
|
||||
__u32 cmd;
|
||||
|
||||
/* Command request structure */
|
||||
__u64 data;
|
||||
|
||||
/* Firmware error code on failure (see psp-sev.h) */
|
||||
__u32 error;
|
||||
};
|
||||
|
||||
|
||||
2.1 SNP_GET_REPORT
|
||||
------------------
|
||||
|
||||
@@ -124,6 +141,41 @@ be updated with the expected value.
|
||||
|
||||
See GHCB specification for further detail on how to parse the certificate blob.
|
||||
|
||||
2.4 SNP_PLATFORM_STATUS
|
||||
-----------------------
|
||||
:Technology: sev-snp
|
||||
:Type: hypervisor ioctl cmd
|
||||
:Parameters (out): struct sev_user_data_snp_status
|
||||
:Returns (out): 0 on success, -negative on error
|
||||
|
||||
The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The
|
||||
status includes API major, minor version and more. See the SEV-SNP
|
||||
specification for further details.
|
||||
|
||||
2.5 SNP_COMMIT
|
||||
--------------
|
||||
:Technology: sev-snp
|
||||
:Type: hypervisor ioctl cmd
|
||||
:Returns (out): 0 on success, -negative on error
|
||||
|
||||
SNP_COMMIT is used to commit the currently installed firmware using the
|
||||
SEV-SNP firmware SNP_COMMIT command. This prevents roll-back to a previously
|
||||
committed firmware version. This will also update the reported TCB to match
|
||||
that of the currently installed firmware.
|
||||
|
||||
2.6 SNP_SET_CONFIG
|
||||
------------------
|
||||
:Technology: sev-snp
|
||||
:Type: hypervisor ioctl cmd
|
||||
:Parameters (in): struct sev_user_data_snp_config
|
||||
:Returns (out): 0 on success, -negative on error
|
||||
|
||||
SNP_SET_CONFIG is used to set the system-wide configuration such as
|
||||
reported TCB version in the attestation report. The command is similar
|
||||
to SNP_CONFIG command defined in the SEV-SNP spec. The current values of
|
||||
the firmware parameters affected by this command can be queried via
|
||||
SNP_PLATFORM_STATUS.
|
||||
|
||||
3. SEV-SNP CPUID Enforcement
|
||||
============================
|
||||
|
||||
|
||||
@@ -28,5 +28,7 @@ obj-y += net/
|
||||
|
||||
obj-$(CONFIG_KEXEC_FILE) += purgatory/
|
||||
|
||||
obj-y += virt/svm/
|
||||
|
||||
# for cleaning
|
||||
subdir- += boot tools
|
||||
|
||||
@@ -1548,19 +1548,6 @@ config AMD_MEM_ENCRYPT
|
||||
This requires an AMD processor that supports Secure Memory
|
||||
Encryption (SME).
|
||||
|
||||
config AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
|
||||
bool "Activate AMD Secure Memory Encryption (SME) by default"
|
||||
depends on AMD_MEM_ENCRYPT
|
||||
help
|
||||
Say yes to have system memory encrypted by default if running on
|
||||
an AMD processor that supports Secure Memory Encryption (SME).
|
||||
|
||||
If set to Y, then the encryption of system memory can be
|
||||
deactivated with the mem_encrypt=off command line option.
|
||||
|
||||
If set to N, then the encryption of system memory can be
|
||||
activated with the mem_encrypt=on command line option.
|
||||
|
||||
# Common NUMA Features
|
||||
config NUMA
|
||||
bool "NUMA Memory Allocation and Scheduler Support"
|
||||
|
||||
@@ -304,6 +304,10 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
|
||||
if (result != ES_OK)
|
||||
goto finish;
|
||||
|
||||
result = vc_check_opcode_bytes(&ctxt, exit_code);
|
||||
if (result != ES_OK)
|
||||
goto finish;
|
||||
|
||||
switch (exit_code) {
|
||||
case SVM_EXIT_RDTSC:
|
||||
case SVM_EXIT_RDTSCP:
|
||||
@@ -365,7 +369,7 @@ static void enforce_vmpl0(void)
|
||||
MSR_AMD64_SNP_VMPL_SSS | \
|
||||
MSR_AMD64_SNP_SECURE_TSC | \
|
||||
MSR_AMD64_SNP_VMGEXIT_PARAM | \
|
||||
MSR_AMD64_SNP_VMSA_REG_PROTECTION | \
|
||||
MSR_AMD64_SNP_VMSA_REG_PROT | \
|
||||
MSR_AMD64_SNP_RESERVED_BIT13 | \
|
||||
MSR_AMD64_SNP_RESERVED_BIT15 | \
|
||||
MSR_AMD64_SNP_RESERVED_MASK)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <asm/processor.h>
|
||||
|
||||
enum cc_vendor cc_vendor __ro_after_init = CC_VENDOR_NONE;
|
||||
static u64 cc_mask __ro_after_init;
|
||||
u64 cc_mask __ro_after_init;
|
||||
|
||||
static bool noinstr intel_cc_platform_has(enum cc_attr attr)
|
||||
{
|
||||
@@ -148,8 +148,3 @@ u64 cc_mkdec(u64 val)
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cc_mkdec);
|
||||
|
||||
__init void cc_set_mask(u64 mask)
|
||||
{
|
||||
cc_mask = mask;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,20 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#ifndef __pic__
|
||||
static __always_inline __pure void *rip_rel_ptr(void *p)
|
||||
{
|
||||
asm("leaq %c1(%%rip), %0" : "=r"(p) : "i"(p));
|
||||
|
||||
return p;
|
||||
}
|
||||
#define RIP_REL_REF(var) (*(typeof(&(var)))rip_rel_ptr(&(var)))
|
||||
#else
|
||||
#define RIP_REL_REF(var) (var)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros to generate condition code outputs from inline assembly,
|
||||
* The output operand must be type "bool".
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef _ASM_X86_COCO_H
|
||||
#define _ASM_X86_COCO_H
|
||||
|
||||
#include <asm/asm.h>
|
||||
#include <asm/types.h>
|
||||
|
||||
enum cc_vendor {
|
||||
@@ -12,7 +13,13 @@ enum cc_vendor {
|
||||
|
||||
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
|
||||
extern enum cc_vendor cc_vendor;
|
||||
void cc_set_mask(u64 mask);
|
||||
extern u64 cc_mask;
|
||||
|
||||
static inline void cc_set_mask(u64 mask)
|
||||
{
|
||||
RIP_REL_REF(cc_mask) = mask;
|
||||
}
|
||||
|
||||
u64 cc_mkenc(u64 val);
|
||||
u64 cc_mkdec(u64 val);
|
||||
#else
|
||||
|
||||
@@ -442,6 +442,7 @@
|
||||
#define X86_FEATURE_SEV (19*32+ 1) /* AMD Secure Encrypted Virtualization */
|
||||
#define X86_FEATURE_VM_PAGE_FLUSH (19*32+ 2) /* "" VM Page Flush MSR is supported */
|
||||
#define X86_FEATURE_SEV_ES (19*32+ 3) /* AMD Secure Encrypted Virtualization - Encrypted State */
|
||||
#define X86_FEATURE_SEV_SNP (19*32+ 4) /* AMD Secure Encrypted Virtualization - Secure Nested Paging */
|
||||
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */
|
||||
#define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced cache coherency */
|
||||
#define X86_FEATURE_DEBUG_SWAP (19*32+14) /* AMD SEV-ES full debug state swap support */
|
||||
|
||||
@@ -123,6 +123,12 @@
|
||||
# define DISABLE_FRED (1 << (X86_FEATURE_FRED & 31))
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KVM_AMD_SEV
|
||||
#define DISABLE_SEV_SNP 0
|
||||
#else
|
||||
#define DISABLE_SEV_SNP (1 << (X86_FEATURE_SEV_SNP & 31))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Make sure to add features to the correct mask
|
||||
*/
|
||||
@@ -147,7 +153,7 @@
|
||||
DISABLE_ENQCMD)
|
||||
#define DISABLED_MASK17 0
|
||||
#define DISABLED_MASK18 (DISABLE_IBT)
|
||||
#define DISABLED_MASK19 0
|
||||
#define DISABLED_MASK19 (DISABLE_SEV_SNP)
|
||||
#define DISABLED_MASK20 0
|
||||
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ extern int force_iommu, no_iommu;
|
||||
extern int iommu_detected;
|
||||
extern int iommu_merge;
|
||||
extern int panic_on_overflow;
|
||||
extern bool amd_iommu_snp_en;
|
||||
|
||||
#ifdef CONFIG_SWIOTLB
|
||||
extern bool x86_swiotlb_enable;
|
||||
|
||||
@@ -138,6 +138,7 @@ KVM_X86_OP(complete_emulated_msr)
|
||||
KVM_X86_OP(vcpu_deliver_sipi_vector)
|
||||
KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons);
|
||||
KVM_X86_OP_OPTIONAL(get_untagged_addr)
|
||||
KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)
|
||||
|
||||
#undef KVM_X86_OP
|
||||
#undef KVM_X86_OP_OPTIONAL
|
||||
|
||||
@@ -1796,6 +1796,7 @@ struct kvm_x86_ops {
|
||||
unsigned long (*vcpu_get_apicv_inhibit_reasons)(struct kvm_vcpu *vcpu);
|
||||
|
||||
gva_t (*get_untagged_addr)(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);
|
||||
void *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu);
|
||||
};
|
||||
|
||||
struct kvm_x86_nested_ops {
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/cc_platform.h>
|
||||
|
||||
#include <asm/bootparam.h>
|
||||
#include <asm/asm.h>
|
||||
struct boot_params;
|
||||
|
||||
#ifdef CONFIG_X86_MEM_ENCRYPT
|
||||
void __init mem_encrypt_init(void);
|
||||
@@ -58,6 +59,11 @@ void __init mem_encrypt_free_decrypted_mem(void);
|
||||
|
||||
void __init sev_es_init_vc_handling(void);
|
||||
|
||||
static inline u64 sme_get_me_mask(void)
|
||||
{
|
||||
return RIP_REL_REF(sme_me_mask);
|
||||
}
|
||||
|
||||
#define __bss_decrypted __section(".bss..decrypted")
|
||||
|
||||
#else /* !CONFIG_AMD_MEM_ENCRYPT */
|
||||
@@ -89,6 +95,8 @@ early_set_mem_enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool en
|
||||
|
||||
static inline void mem_encrypt_free_decrypted_mem(void) { }
|
||||
|
||||
static inline u64 sme_get_me_mask(void) { return 0; }
|
||||
|
||||
#define __bss_decrypted
|
||||
|
||||
#endif /* CONFIG_AMD_MEM_ENCRYPT */
|
||||
@@ -106,11 +114,6 @@ void add_encrypt_protection_map(void);
|
||||
|
||||
extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
|
||||
|
||||
static inline u64 sme_get_me_mask(void)
|
||||
{
|
||||
return sme_me_mask;
|
||||
}
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif /* __X86_MEM_ENCRYPT_H__ */
|
||||
|
||||
@@ -605,34 +605,47 @@
|
||||
#define MSR_AMD64_SEV_ES_GHCB 0xc0010130
|
||||
#define MSR_AMD64_SEV 0xc0010131
|
||||
#define MSR_AMD64_SEV_ENABLED_BIT 0
|
||||
#define MSR_AMD64_SEV_ES_ENABLED_BIT 1
|
||||
#define MSR_AMD64_SEV_SNP_ENABLED_BIT 2
|
||||
#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)
|
||||
#define MSR_AMD64_SEV_ES_ENABLED_BIT 1
|
||||
#define MSR_AMD64_SEV_ES_ENABLED BIT_ULL(MSR_AMD64_SEV_ES_ENABLED_BIT)
|
||||
#define MSR_AMD64_SEV_SNP_ENABLED_BIT 2
|
||||
#define MSR_AMD64_SEV_SNP_ENABLED BIT_ULL(MSR_AMD64_SEV_SNP_ENABLED_BIT)
|
||||
|
||||
/* SNP feature bits enabled by the hypervisor */
|
||||
#define MSR_AMD64_SNP_VTOM BIT_ULL(3)
|
||||
#define MSR_AMD64_SNP_REFLECT_VC BIT_ULL(4)
|
||||
#define MSR_AMD64_SNP_RESTRICTED_INJ BIT_ULL(5)
|
||||
#define MSR_AMD64_SNP_ALT_INJ BIT_ULL(6)
|
||||
#define MSR_AMD64_SNP_DEBUG_SWAP BIT_ULL(7)
|
||||
#define MSR_AMD64_SNP_PREVENT_HOST_IBS BIT_ULL(8)
|
||||
#define MSR_AMD64_SNP_BTB_ISOLATION BIT_ULL(9)
|
||||
#define MSR_AMD64_SNP_VMPL_SSS BIT_ULL(10)
|
||||
#define MSR_AMD64_SNP_SECURE_TSC BIT_ULL(11)
|
||||
#define MSR_AMD64_SNP_VMGEXIT_PARAM BIT_ULL(12)
|
||||
#define MSR_AMD64_SNP_IBS_VIRT BIT_ULL(14)
|
||||
#define MSR_AMD64_SNP_VMSA_REG_PROTECTION BIT_ULL(16)
|
||||
#define MSR_AMD64_SNP_SMT_PROTECTION BIT_ULL(17)
|
||||
|
||||
/* SNP feature bits reserved for future use. */
|
||||
#define MSR_AMD64_SNP_RESERVED_BIT13 BIT_ULL(13)
|
||||
#define MSR_AMD64_SNP_RESERVED_BIT15 BIT_ULL(15)
|
||||
#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, 18)
|
||||
#define MSR_AMD64_SNP_VTOM_BIT 3
|
||||
#define MSR_AMD64_SNP_VTOM BIT_ULL(MSR_AMD64_SNP_VTOM_BIT)
|
||||
#define MSR_AMD64_SNP_REFLECT_VC_BIT 4
|
||||
#define MSR_AMD64_SNP_REFLECT_VC BIT_ULL(MSR_AMD64_SNP_REFLECT_VC_BIT)
|
||||
#define MSR_AMD64_SNP_RESTRICTED_INJ_BIT 5
|
||||
#define MSR_AMD64_SNP_RESTRICTED_INJ BIT_ULL(MSR_AMD64_SNP_RESTRICTED_INJ_BIT)
|
||||
#define MSR_AMD64_SNP_ALT_INJ_BIT 6
|
||||
#define MSR_AMD64_SNP_ALT_INJ BIT_ULL(MSR_AMD64_SNP_ALT_INJ_BIT)
|
||||
#define MSR_AMD64_SNP_DEBUG_SWAP_BIT 7
|
||||
#define MSR_AMD64_SNP_DEBUG_SWAP BIT_ULL(MSR_AMD64_SNP_DEBUG_SWAP_BIT)
|
||||
#define MSR_AMD64_SNP_PREVENT_HOST_IBS_BIT 8
|
||||
#define MSR_AMD64_SNP_PREVENT_HOST_IBS BIT_ULL(MSR_AMD64_SNP_PREVENT_HOST_IBS_BIT)
|
||||
#define MSR_AMD64_SNP_BTB_ISOLATION_BIT 9
|
||||
#define MSR_AMD64_SNP_BTB_ISOLATION BIT_ULL(MSR_AMD64_SNP_BTB_ISOLATION_BIT)
|
||||
#define MSR_AMD64_SNP_VMPL_SSS_BIT 10
|
||||
#define MSR_AMD64_SNP_VMPL_SSS BIT_ULL(MSR_AMD64_SNP_VMPL_SSS_BIT)
|
||||
#define MSR_AMD64_SNP_SECURE_TSC_BIT 11
|
||||
#define MSR_AMD64_SNP_SECURE_TSC BIT_ULL(MSR_AMD64_SNP_SECURE_TSC_BIT)
|
||||
#define MSR_AMD64_SNP_VMGEXIT_PARAM_BIT 12
|
||||
#define MSR_AMD64_SNP_VMGEXIT_PARAM BIT_ULL(MSR_AMD64_SNP_VMGEXIT_PARAM_BIT)
|
||||
#define MSR_AMD64_SNP_RESERVED_BIT13 BIT_ULL(13)
|
||||
#define MSR_AMD64_SNP_IBS_VIRT_BIT 14
|
||||
#define MSR_AMD64_SNP_IBS_VIRT BIT_ULL(MSR_AMD64_SNP_IBS_VIRT_BIT)
|
||||
#define MSR_AMD64_SNP_RESERVED_BIT15 BIT_ULL(15)
|
||||
#define MSR_AMD64_SNP_VMSA_REG_PROT_BIT 16
|
||||
#define MSR_AMD64_SNP_VMSA_REG_PROT BIT_ULL(MSR_AMD64_SNP_VMSA_REG_PROT_BIT)
|
||||
#define MSR_AMD64_SNP_SMT_PROT_BIT 17
|
||||
#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)
|
||||
#define MSR_AMD64_SNP_RESV_BIT 18
|
||||
#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)
|
||||
|
||||
#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f
|
||||
|
||||
#define MSR_AMD64_RMP_BASE 0xc0010132
|
||||
#define MSR_AMD64_RMP_END 0xc0010133
|
||||
|
||||
/* AMD Collaborative Processor Performance Control MSRs */
|
||||
#define MSR_AMD_CPPC_CAP1 0xc00102b0
|
||||
#define MSR_AMD_CPPC_ENABLE 0xc00102b1
|
||||
@@ -719,8 +732,15 @@
|
||||
#define MSR_K8_TOP_MEM1 0xc001001a
|
||||
#define MSR_K8_TOP_MEM2 0xc001001d
|
||||
#define MSR_AMD64_SYSCFG 0xc0010010
|
||||
#define MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT 23
|
||||
#define MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT 23
|
||||
#define MSR_AMD64_SYSCFG_MEM_ENCRYPT BIT_ULL(MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT)
|
||||
#define MSR_AMD64_SYSCFG_SNP_EN_BIT 24
|
||||
#define MSR_AMD64_SYSCFG_SNP_EN BIT_ULL(MSR_AMD64_SYSCFG_SNP_EN_BIT)
|
||||
#define MSR_AMD64_SYSCFG_SNP_VMPL_EN_BIT 25
|
||||
#define MSR_AMD64_SYSCFG_SNP_VMPL_EN BIT_ULL(MSR_AMD64_SYSCFG_SNP_VMPL_EN_BIT)
|
||||
#define MSR_AMD64_SYSCFG_MFDM_BIT 19
|
||||
#define MSR_AMD64_SYSCFG_MFDM BIT_ULL(MSR_AMD64_SYSCFG_MFDM_BIT)
|
||||
|
||||
#define MSR_K8_INT_PENDING_MSG 0xc0010055
|
||||
/* C1E active bits in int pending message */
|
||||
#define K8_INTP_C1E_ACTIVE_MASK 0x18000000
|
||||
|
||||
@@ -87,9 +87,23 @@ extern bool handle_vc_boot_ghcb(struct pt_regs *regs);
|
||||
/* Software defined (when rFlags.CF = 1) */
|
||||
#define PVALIDATE_FAIL_NOUPDATE 255
|
||||
|
||||
/* RMUPDATE detected 4K page and 2MB page overlap. */
|
||||
#define RMPUPDATE_FAIL_OVERLAP 4
|
||||
|
||||
/* RMP page size */
|
||||
#define RMP_PG_SIZE_4K 0
|
||||
#define RMP_PG_SIZE_2M 1
|
||||
#define RMP_TO_PG_LEVEL(level) (((level) == RMP_PG_SIZE_4K) ? PG_LEVEL_4K : PG_LEVEL_2M)
|
||||
#define PG_LEVEL_TO_RMP(level) (((level) == PG_LEVEL_4K) ? RMP_PG_SIZE_4K : RMP_PG_SIZE_2M)
|
||||
|
||||
struct rmp_state {
|
||||
u64 gpa;
|
||||
u8 assigned;
|
||||
u8 pagesize;
|
||||
u8 immutable;
|
||||
u8 rsvd;
|
||||
u32 asid;
|
||||
} __packed;
|
||||
|
||||
#define RMPADJUST_VMSA_PAGE_BIT BIT(16)
|
||||
|
||||
@@ -213,6 +227,8 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct sn
|
||||
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
|
||||
u64 snp_get_unsupported_features(u64 status);
|
||||
u64 sev_get_status(void);
|
||||
void kdump_sev_callback(void);
|
||||
void sev_show_status(void);
|
||||
#else
|
||||
static inline void sev_es_ist_enter(struct pt_regs *regs) { }
|
||||
static inline void sev_es_ist_exit(void) { }
|
||||
@@ -241,6 +257,30 @@ static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_data *in
|
||||
static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { }
|
||||
static inline u64 snp_get_unsupported_features(u64 status) { return 0; }
|
||||
static inline u64 sev_get_status(void) { return 0; }
|
||||
static inline void kdump_sev_callback(void) { }
|
||||
static inline void sev_show_status(void) { }
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KVM_AMD_SEV
|
||||
bool snp_probe_rmptable_info(void);
|
||||
int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level);
|
||||
void snp_dump_hva_rmpentry(unsigned long address);
|
||||
int psmash(u64 pfn);
|
||||
int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asid, bool immutable);
|
||||
int rmp_make_shared(u64 pfn, enum pg_level level);
|
||||
void snp_leak_pages(u64 pfn, unsigned int npages);
|
||||
#else
|
||||
static inline bool snp_probe_rmptable_info(void) { return false; }
|
||||
static inline int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level) { return -ENODEV; }
|
||||
static inline void snp_dump_hva_rmpentry(unsigned long address) {}
|
||||
static inline int psmash(u64 pfn) { return -ENODEV; }
|
||||
static inline int rmp_make_private(u64 pfn, u64 gpa, enum pg_level level, u32 asid,
|
||||
bool immutable)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
static inline int rmp_make_shared(u64 pfn, enum pg_level level) { return -ENODEV; }
|
||||
static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#ifndef _ASM_X86_TRAP_PF_H
|
||||
#define _ASM_X86_TRAP_PF_H
|
||||
|
||||
#include <linux/bits.h>
|
||||
|
||||
/*
|
||||
* Page fault error code bits:
|
||||
*
|
||||
@@ -13,16 +15,18 @@
|
||||
* bit 5 == 1: protection keys block access
|
||||
* bit 6 == 1: shadow stack access fault
|
||||
* bit 15 == 1: SGX MMU page-fault
|
||||
* bit 31 == 1: fault was due to RMP violation
|
||||
*/
|
||||
enum x86_pf_error_code {
|
||||
X86_PF_PROT = 1 << 0,
|
||||
X86_PF_WRITE = 1 << 1,
|
||||
X86_PF_USER = 1 << 2,
|
||||
X86_PF_RSVD = 1 << 3,
|
||||
X86_PF_INSTR = 1 << 4,
|
||||
X86_PF_PK = 1 << 5,
|
||||
X86_PF_SHSTK = 1 << 6,
|
||||
X86_PF_SGX = 1 << 15,
|
||||
X86_PF_PROT = BIT(0),
|
||||
X86_PF_WRITE = BIT(1),
|
||||
X86_PF_USER = BIT(2),
|
||||
X86_PF_RSVD = BIT(3),
|
||||
X86_PF_INSTR = BIT(4),
|
||||
X86_PF_PK = BIT(5),
|
||||
X86_PF_SHSTK = BIT(6),
|
||||
X86_PF_SGX = BIT(15),
|
||||
X86_PF_RMP = BIT(31),
|
||||
};
|
||||
|
||||
#endif /* _ASM_X86_TRAP_PF_H */
|
||||
|
||||
@@ -33,6 +33,7 @@ KASAN_SANITIZE_sev.o := n
|
||||
KCSAN_SANITIZE := n
|
||||
KMSAN_SANITIZE_head$(BITS).o := n
|
||||
KMSAN_SANITIZE_nmi.o := n
|
||||
KMSAN_SANITIZE_sev.o := n
|
||||
|
||||
# If instrumentation of the following files is enabled, boot hangs during
|
||||
# first second.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <asm/delay.h>
|
||||
#include <asm/debugreg.h>
|
||||
#include <asm/resctrl.h>
|
||||
#include <asm/sev.h>
|
||||
|
||||
#ifdef CONFIG_X86_64
|
||||
# include <asm/mmconfig.h>
|
||||
@@ -451,6 +452,21 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cpu_has(c, X86_FEATURE_SEV_SNP)) {
|
||||
/*
|
||||
* RMP table entry format is not architectural and it can vary by processor
|
||||
* and is defined by the per-processor PPR. Restrict SNP support on the
|
||||
* known CPU model and family for which the RMP table entry format is
|
||||
* currently defined for.
|
||||
*/
|
||||
if (!boot_cpu_has(X86_FEATURE_ZEN3) &&
|
||||
!boot_cpu_has(X86_FEATURE_ZEN4) &&
|
||||
!boot_cpu_has(X86_FEATURE_ZEN5))
|
||||
setup_clear_cpu_cap(X86_FEATURE_SEV_SNP);
|
||||
else if (!snp_probe_rmptable_info())
|
||||
setup_clear_cpu_cap(X86_FEATURE_SEV_SNP);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
warn:
|
||||
@@ -469,8 +485,8 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
|
||||
* SME feature (set in scattered.c).
|
||||
* If the kernel has not enabled SME via any means then
|
||||
* don't advertise the SME feature.
|
||||
* For SEV: If BIOS has not enabled SEV then don't advertise the
|
||||
* SEV and SEV_ES feature (set in scattered.c).
|
||||
* For SEV: If BIOS has not enabled SEV then don't advertise SEV and
|
||||
* any additional functionality based on it.
|
||||
*
|
||||
* In all cases, since support for SME and SEV requires long mode,
|
||||
* don't advertise the feature under CONFIG_X86_32.
|
||||
@@ -505,6 +521,7 @@ clear_all:
|
||||
clear_sev:
|
||||
setup_clear_cpu_cap(X86_FEATURE_SEV);
|
||||
setup_clear_cpu_cap(X86_FEATURE_SEV_ES);
|
||||
setup_clear_cpu_cap(X86_FEATURE_SEV_SNP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user