Skip to content

Commit 2ea29c5

Browse files
codomaniasuryasaimadhu
authored andcommitted
x86/sev: Save the negotiated GHCB version
The SEV-ES guest calls sev_es_negotiate_protocol() to negotiate the GHCB protocol version before establishing the GHCB. Cache the negotiated GHCB version so that it can be used later. Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Venu Busireddy <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6c0f74d commit 2ea29c5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

arch/x86/include/asm/sev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <asm/insn.h>
1313
#include <asm/sev-common.h>
1414

15-
#define GHCB_PROTO_OUR 0x0001UL
15+
#define GHCB_PROTOCOL_MIN 1ULL
1616
#define GHCB_PROTOCOL_MAX 1ULL
1717
#define GHCB_DEFAULT_USAGE 0ULL
1818

arch/x86/kernel/sev-shared.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
#define has_cpuflag(f) boot_cpu_has(f)
1515
#endif
1616

17+
/*
18+
* Since feature negotiation related variables are set early in the boot
19+
* process they must reside in the .data section so as not to be zeroed
20+
* out when the .bss section is later cleared.
21+
*
22+
* GHCB protocol version negotiated with the hypervisor.
23+
*/
24+
static u16 ghcb_version __ro_after_init;
25+
1726
static bool __init sev_es_check_cpu_features(void)
1827
{
1928
if (!has_cpuflag(X86_FEATURE_RDRAND)) {
@@ -51,10 +60,12 @@ static bool sev_es_negotiate_protocol(void)
5160
if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP)
5261
return false;
5362

54-
if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTO_OUR ||
55-
GHCB_MSR_PROTO_MIN(val) > GHCB_PROTO_OUR)
63+
if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN ||
64+
GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX)
5665
return false;
5766

67+
ghcb_version = min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX);
68+
5869
return true;
5970
}
6071

@@ -127,7 +138,7 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr,
127138
u64 exit_info_1, u64 exit_info_2)
128139
{
129140
/* Fill in protocol and format specifiers */
130-
ghcb->protocol_version = GHCB_PROTOCOL_MAX;
141+
ghcb->protocol_version = ghcb_version;
131142
ghcb->ghcb_usage = GHCB_DEFAULT_USAGE;
132143

133144
ghcb_set_sw_exit_code(ghcb, exit_code);

0 commit comments

Comments
 (0)