Skip to content

Commit ccb013c

Browse files
committed
Merge tag 'x86_urgent_for_v5.13_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: "The three SEV commits are not really urgent material. But we figured since getting them in now will avoid a huge amount of conflicts between future SEV changes touching tip, the kvm and probably other trees, sending them to you now would be best. The idea is that the tip, kvm etc branches for 5.14 will all base ontop of -rc2 and thus everything will be peachy. What is more, those changes are purely mechanical and defines movement so they should be fine to go now (famous last words). Summary: - Enable -Wundef for the compressed kernel build stage - Reorganize SEV code to streamline and simplify future development" * tag 'x86_urgent_for_v5.13_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/boot/compressed: Enable -Wundef x86/msr: Rename MSR_K8_SYSCFG to MSR_AMD64_SYSCFG x86/sev: Move GHCB MSR protocol and NAE definitions in a common header x86/sev-es: Rename sev-es.{ch} to sev.{ch}
2 parents 63d1cb5 + a554e74 commit ccb013c

File tree

29 files changed

+124
-113
lines changed

29 files changed

+124
-113
lines changed

Documentation/virt/kvm/amd-memory-encryption.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to SEV::
2222
[ecx]:
2323
Bits[31:0] Number of encrypted guests supported simultaneously
2424

25-
If support for SEV is present, MSR 0xc001_0010 (MSR_K8_SYSCFG) and MSR 0xc001_0015
25+
If support for SEV is present, MSR 0xc001_0010 (MSR_AMD64_SYSCFG) and MSR 0xc001_0015
2626
(MSR_K7_HWCR) can be used to determine if it can be enabled::
2727

2828
0xc001_0010:

Documentation/x86/amd-memory-encryption.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CPUID function 0x8000001f reports information related to SME::
5353
system physical addresses, not guest physical
5454
addresses)
5555

56-
If support for SME is present, MSR 0xc00100010 (MSR_K8_SYSCFG) can be used to
56+
If support for SME is present, MSR 0xc00100010 (MSR_AMD64_SYSCFG) can be used to
5757
determine if SME is enabled and/or to enable memory encryption::
5858

5959
0xc0010010:
@@ -79,7 +79,7 @@ The state of SME in the Linux kernel can be documented as follows:
7979
The CPU supports SME (determined through CPUID instruction).
8080

8181
- Enabled:
82-
Supported and bit 23 of MSR_K8_SYSCFG is set.
82+
Supported and bit 23 of MSR_AMD64_SYSCFG is set.
8383

8484
- Active:
8585
Supported, Enabled and the Linux kernel is actively applying
@@ -89,7 +89,7 @@ The state of SME in the Linux kernel can be documented as follows:
8989
SME can also be enabled and activated in the BIOS. If SME is enabled and
9090
activated in the BIOS, then all memory accesses will be encrypted and it will
9191
not be necessary to activate the Linux memory encryption support. If the BIOS
92-
merely enables SME (sets bit 23 of the MSR_K8_SYSCFG), then Linux can activate
92+
merely enables SME (sets bit 23 of the MSR_AMD64_SYSCFG), then Linux can activate
9393
memory encryption by default (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y) or
9494
by supplying mem_encrypt=on on the kernel command line. However, if BIOS does
9595
not enable SME, then Linux will not be able to activate memory encryption, even

arch/x86/boot/compressed/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
3030

3131
KBUILD_CFLAGS := -m$(BITS) -O2
3232
KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
33+
KBUILD_CFLAGS += -Wundef
3334
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
3435
cflags-$(CONFIG_X86_32) := -march=i386
3536
cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
@@ -48,10 +49,10 @@ KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
4849
KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
4950
KBUILD_CFLAGS += $(CLANG_FLAGS)
5051

51-
# sev-es.c indirectly inludes inat-table.h which is generated during
52+
# sev.c indirectly inludes inat-table.h which is generated during
5253
# compilation and stored in $(objtree). Add the directory to the includes so
5354
# that the compiler finds it even with out-of-tree builds (make O=/some/path).
54-
CFLAGS_sev-es.o += -I$(objtree)/arch/x86/lib/
55+
CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/
5556

5657
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5758
GCOV_PROFILE := n
@@ -93,7 +94,7 @@ ifdef CONFIG_X86_64
9394
vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
9495
vmlinux-objs-y += $(obj)/mem_encrypt.o
9596
vmlinux-objs-y += $(obj)/pgtable_64.o
96-
vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev-es.o
97+
vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
9798
endif
9899

99100
vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o

arch/x86/boot/compressed/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void __puthex(unsigned long value)
172172
}
173173
}
174174

175-
#if CONFIG_X86_NEED_RELOCS
175+
#ifdef CONFIG_X86_NEED_RELOCS
176176
static void handle_relocations(void *output, unsigned long output_len,
177177
unsigned long virt_addr)
178178
{

arch/x86/boot/compressed/misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct mem_vector {
7979
u64 size;
8080
};
8181

82-
#if CONFIG_RANDOMIZE_BASE
82+
#ifdef CONFIG_RANDOMIZE_BASE
8383
/* kaslr.c */
8484
void choose_random_location(unsigned long input,
8585
unsigned long input_size,

arch/x86/boot/compressed/sev-es.c renamed to arch/x86/boot/compressed/sev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "misc.h"
1414

1515
#include <asm/pgtable_types.h>
16-
#include <asm/sev-es.h>
16+
#include <asm/sev.h>
1717
#include <asm/trapnr.h>
1818
#include <asm/trap_pf.h>
1919
#include <asm/msr-index.h>
@@ -117,7 +117,7 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
117117
#include "../../lib/insn.c"
118118

119119
/* Include code for early handlers */
120-
#include "../../kernel/sev-es-shared.c"
120+
#include "../../kernel/sev-shared.c"
121121

122122
static bool early_setup_sev_es(void)
123123
{

arch/x86/include/asm/msr-index.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@
537537
/* K8 MSRs */
538538
#define MSR_K8_TOP_MEM1 0xc001001a
539539
#define MSR_K8_TOP_MEM2 0xc001001d
540-
#define MSR_K8_SYSCFG 0xc0010010
541-
#define MSR_K8_SYSCFG_MEM_ENCRYPT_BIT 23
542-
#define MSR_K8_SYSCFG_MEM_ENCRYPT BIT_ULL(MSR_K8_SYSCFG_MEM_ENCRYPT_BIT)
540+
#define MSR_AMD64_SYSCFG 0xc0010010
541+
#define MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT 23
542+
#define MSR_AMD64_SYSCFG_MEM_ENCRYPT BIT_ULL(MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT)
543543
#define MSR_K8_INT_PENDING_MSG 0xc0010055
544544
/* C1E active bits in int pending message */
545545
#define K8_INTP_C1E_ACTIVE_MASK 0x18000000

arch/x86/include/asm/sev-common.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* AMD SEV header common between the guest and the hypervisor.
4+
*
5+
* Author: Brijesh Singh <[email protected]>
6+
*/
7+
8+
#ifndef __ASM_X86_SEV_COMMON_H
9+
#define __ASM_X86_SEV_COMMON_H
10+
11+
#define GHCB_MSR_INFO_POS 0
12+
#define GHCB_MSR_INFO_MASK (BIT_ULL(12) - 1)
13+
14+
#define GHCB_MSR_SEV_INFO_RESP 0x001
15+
#define GHCB_MSR_SEV_INFO_REQ 0x002
16+
#define GHCB_MSR_VER_MAX_POS 48
17+
#define GHCB_MSR_VER_MAX_MASK 0xffff
18+
#define GHCB_MSR_VER_MIN_POS 32
19+
#define GHCB_MSR_VER_MIN_MASK 0xffff
20+
#define GHCB_MSR_CBIT_POS 24
21+
#define GHCB_MSR_CBIT_MASK 0xff
22+
#define GHCB_MSR_SEV_INFO(_max, _min, _cbit) \
23+
((((_max) & GHCB_MSR_VER_MAX_MASK) << GHCB_MSR_VER_MAX_POS) | \
24+
(((_min) & GHCB_MSR_VER_MIN_MASK) << GHCB_MSR_VER_MIN_POS) | \
25+
(((_cbit) & GHCB_MSR_CBIT_MASK) << GHCB_MSR_CBIT_POS) | \
26+
GHCB_MSR_SEV_INFO_RESP)
27+
#define GHCB_MSR_INFO(v) ((v) & 0xfffUL)
28+
#define GHCB_MSR_PROTO_MAX(v) (((v) >> GHCB_MSR_VER_MAX_POS) & GHCB_MSR_VER_MAX_MASK)
29+
#define GHCB_MSR_PROTO_MIN(v) (((v) >> GHCB_MSR_VER_MIN_POS) & GHCB_MSR_VER_MIN_MASK)
30+
31+
#define GHCB_MSR_CPUID_REQ 0x004
32+
#define GHCB_MSR_CPUID_RESP 0x005
33+
#define GHCB_MSR_CPUID_FUNC_POS 32
34+
#define GHCB_MSR_CPUID_FUNC_MASK 0xffffffff
35+
#define GHCB_MSR_CPUID_VALUE_POS 32
36+
#define GHCB_MSR_CPUID_VALUE_MASK 0xffffffff
37+
#define GHCB_MSR_CPUID_REG_POS 30
38+
#define GHCB_MSR_CPUID_REG_MASK 0x3
39+
#define GHCB_CPUID_REQ_EAX 0
40+
#define GHCB_CPUID_REQ_EBX 1
41+
#define GHCB_CPUID_REQ_ECX 2
42+
#define GHCB_CPUID_REQ_EDX 3
43+
#define GHCB_CPUID_REQ(fn, reg) \
44+
(GHCB_MSR_CPUID_REQ | \
45+
(((unsigned long)reg & GHCB_MSR_CPUID_REG_MASK) << GHCB_MSR_CPUID_REG_POS) | \
46+
(((unsigned long)fn) << GHCB_MSR_CPUID_FUNC_POS))
47+
48+
#define GHCB_MSR_TERM_REQ 0x100
49+
#define GHCB_MSR_TERM_REASON_SET_POS 12
50+
#define GHCB_MSR_TERM_REASON_SET_MASK 0xf
51+
#define GHCB_MSR_TERM_REASON_POS 16
52+
#define GHCB_MSR_TERM_REASON_MASK 0xff
53+
#define GHCB_SEV_TERM_REASON(reason_set, reason_val) \
54+
(((((u64)reason_set) & GHCB_MSR_TERM_REASON_SET_MASK) << GHCB_MSR_TERM_REASON_SET_POS) | \
55+
((((u64)reason_val) & GHCB_MSR_TERM_REASON_MASK) << GHCB_MSR_TERM_REASON_POS))
56+
57+
#define GHCB_SEV_ES_REASON_GENERAL_REQUEST 0
58+
#define GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED 1
59+
60+
#define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK)
61+
62+
#endif

arch/x86/include/asm/sev-es.h renamed to arch/x86/include/asm/sev.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,12 @@
1010

1111
#include <linux/types.h>
1212
#include <asm/insn.h>
13+
#include <asm/sev-common.h>
1314

14-
#define GHCB_SEV_INFO 0x001UL
15-
#define GHCB_SEV_INFO_REQ 0x002UL
16-
#define GHCB_INFO(v) ((v) & 0xfffUL)
17-
#define GHCB_PROTO_MAX(v) (((v) >> 48) & 0xffffUL)
18-
#define GHCB_PROTO_MIN(v) (((v) >> 32) & 0xffffUL)
19-
#define GHCB_PROTO_OUR 0x0001UL
20-
#define GHCB_SEV_CPUID_REQ 0x004UL
21-
#define GHCB_CPUID_REQ_EAX 0
22-
#define GHCB_CPUID_REQ_EBX 1
23-
#define GHCB_CPUID_REQ_ECX 2
24-
#define GHCB_CPUID_REQ_EDX 3
25-
#define GHCB_CPUID_REQ(fn, reg) (GHCB_SEV_CPUID_REQ | \
26-
(((unsigned long)reg & 3) << 30) | \
27-
(((unsigned long)fn) << 32))
15+
#define GHCB_PROTO_OUR 0x0001UL
16+
#define GHCB_PROTOCOL_MAX 1ULL
17+
#define GHCB_DEFAULT_USAGE 0ULL
2818

29-
#define GHCB_PROTOCOL_MAX 0x0001UL
30-
#define GHCB_DEFAULT_USAGE 0x0000UL
31-
32-
#define GHCB_SEV_CPUID_RESP 0x005UL
33-
#define GHCB_SEV_TERMINATE 0x100UL
34-
#define GHCB_SEV_TERMINATE_REASON(reason_set, reason_val) \
35-
(((((u64)reason_set) & 0x7) << 12) | \
36-
((((u64)reason_val) & 0xff) << 16))
37-
#define GHCB_SEV_ES_REASON_GENERAL_REQUEST 0
38-
#define GHCB_SEV_ES_REASON_PROTOCOL_UNSUPPORTED 1
39-
40-
#define GHCB_SEV_GHCB_RESP_CODE(v) ((v) & 0xfff)
4119
#define VMGEXIT() { asm volatile("rep; vmmcall\n\r"); }
4220

4321
enum es_result {

arch/x86/kernel/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ CFLAGS_REMOVE_kvmclock.o = -pg
2020
CFLAGS_REMOVE_ftrace.o = -pg
2121
CFLAGS_REMOVE_early_printk.o = -pg
2222
CFLAGS_REMOVE_head64.o = -pg
23-
CFLAGS_REMOVE_sev-es.o = -pg
23+
CFLAGS_REMOVE_sev.o = -pg
2424
endif
2525

2626
KASAN_SANITIZE_head$(BITS).o := n
2727
KASAN_SANITIZE_dumpstack.o := n
2828
KASAN_SANITIZE_dumpstack_$(BITS).o := n
2929
KASAN_SANITIZE_stacktrace.o := n
3030
KASAN_SANITIZE_paravirt.o := n
31-
KASAN_SANITIZE_sev-es.o := n
31+
KASAN_SANITIZE_sev.o := n
3232

3333
# With some compiler versions the generated code results in boot hangs, caused
3434
# by several compilation units. To be safe, disable all instrumentation.
@@ -148,7 +148,7 @@ obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o
148148
obj-$(CONFIG_UNWINDER_FRAME_POINTER) += unwind_frame.o
149149
obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o
150150

151-
obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev-es.o
151+
obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o
152152
###
153153
# 64 bit specific files
154154
ifeq ($(CONFIG_X86_64),y)

0 commit comments

Comments
 (0)