mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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 <brijesh.singh@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Venu Busireddy <venu.busireddy@oracle.com> Link: https://lore.kernel.org/r/20220307213356.2797205-12-brijesh.singh@amd.com
This commit is contained in:
		
							parent
							
								
									6c0f74d678
								
							
						
					
					
						commit
						2ea29c5abb
					
				
					 2 changed files with 15 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -12,7 +12,7 @@
 | 
			
		|||
#include <asm/insn.h>
 | 
			
		||||
#include <asm/sev-common.h>
 | 
			
		||||
 | 
			
		||||
#define GHCB_PROTO_OUR		0x0001UL
 | 
			
		||||
#define GHCB_PROTOCOL_MIN	1ULL
 | 
			
		||||
#define GHCB_PROTOCOL_MAX	1ULL
 | 
			
		||||
#define GHCB_DEFAULT_USAGE	0ULL
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,15 @@
 | 
			
		|||
#define has_cpuflag(f)	boot_cpu_has(f)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Since feature negotiation related variables are set early in the boot
 | 
			
		||||
 * process they must reside in the .data section so as not to be zeroed
 | 
			
		||||
 * out when the .bss section is later cleared.
 | 
			
		||||
 *
 | 
			
		||||
 * GHCB protocol version negotiated with the hypervisor.
 | 
			
		||||
 */
 | 
			
		||||
static u16 ghcb_version __ro_after_init;
 | 
			
		||||
 | 
			
		||||
static bool __init sev_es_check_cpu_features(void)
 | 
			
		||||
{
 | 
			
		||||
	if (!has_cpuflag(X86_FEATURE_RDRAND)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -51,10 +60,12 @@ static bool sev_es_negotiate_protocol(void)
 | 
			
		|||
	if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP)
 | 
			
		||||
		return false;
 | 
			
		||||
 | 
			
		||||
	if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTO_OUR ||
 | 
			
		||||
	    GHCB_MSR_PROTO_MIN(val) > GHCB_PROTO_OUR)
 | 
			
		||||
	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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +138,7 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr,
 | 
			
		|||
				   u64 exit_info_1, u64 exit_info_2)
 | 
			
		||||
{
 | 
			
		||||
	/* Fill in protocol and format specifiers */
 | 
			
		||||
	ghcb->protocol_version = GHCB_PROTOCOL_MAX;
 | 
			
		||||
	ghcb->protocol_version = ghcb_version;
 | 
			
		||||
	ghcb->ghcb_usage       = GHCB_DEFAULT_USAGE;
 | 
			
		||||
 | 
			
		||||
	ghcb_set_sw_exit_code(ghcb, exit_code);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue