Commit be760c6e authored by Xin Jiang's avatar Xin Jiang Committed by hanliyang
Browse files

x86/boot/compressed/64: Add CSV3 guest detection

hygon inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAYGKY


CVE: NA

---------------------------

Check if CSV3 guest is active at boot compressed stage. It
checks HYGON hardware with CPUID 0x00000000 and bit30 of MSR
0xc0010131.

Signed-off-by: default avatarXin Jiang <jiangxin@hygon.cn>
Signed-off-by: default avatarhanliyang <hanliyang@hygon.cn>
parent c97c1d01
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ ifdef CONFIG_X86_64
	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o
	vmlinux-objs-y += $(obj)/pgtable_64.o
	vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o
	vmlinux-objs-$(CONFIG_HYGON_CSV) += $(obj)/csv.o
endif

vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
+38 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Hygon CSV Support
 *
 * Copyright (C) Hygon Info Technologies Ltd.
 */

#include "misc.h"

#include <asm/csv.h>
#include <asm/cpuid.h>

static unsigned int csv3_enabled __section(".data");

void csv_set_status(void)
{
	unsigned int eax;
	unsigned int ebx;
	unsigned int ecx;
	unsigned int edx;

	eax = 0;
	native_cpuid(&eax, &ebx, &ecx, &edx);

	/* HygonGenuine */
	if (ebx == CPUID_VENDOR_HygonGenuine_ebx &&
	    ecx == CPUID_VENDOR_HygonGenuine_ecx &&
	    edx == CPUID_VENDOR_HygonGenuine_edx &&
	    sme_me_mask) {
		unsigned long low, high;

		asm volatile("rdmsr\n" : "=a" (low), "=d" (high) :
			"c" (MSR_AMD64_SEV));

		if (low & MSR_CSV3_ENABLED)
			csv3_enabled = 1;
	}
}
+23 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Hygon CSV header for early boot related functions.
 *
 * Copyright (C) Hygon Info Technologies Ltd.
 *
 * Author: Liyang Han <hanliyang@hygon.cn>
 */

#ifndef BOOT_COMPRESSED_CSV_H
#define BOOT_COMPRESSED_CSV_H

#ifdef CONFIG_HYGON_CSV

void csv_set_status(void);

#else

static inline void csv_set_status(void) { }

#endif

#endif	/* BOOT_COMPRESSED_CSV_H */
+10 −0
Original line number Diff line number Diff line
@@ -397,6 +397,16 @@ SYM_CODE_START(startup_64)
	movq	%r15, %rdi
	call	sev_enable
#endif
#ifdef CONFIG_HYGON_CSV
	/*
	 * Check CSV active status. The CSV and CSV2 guest are indicated by
	 * MSR_AMD64_SEV_ENABLED_BIT and MSR_AMD64_SEV_ES_ENABLED_BIT in MSR
	 * register 0xc0010131, respectively.
	 * The CSV3 guest is indicated by MSR_CSV3_ENABLED in MSR register
	 * 0xc0010131.
	 */
	call	csv_set_status
#endif

	/* Preserve only the CR4 bits that must be preserved, and clear the rest */
	movq	%cr4, %rax
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <asm/desc_defs.h>

#include "tdx.h"
#include "csv.h"

#define BOOT_CTYPE_H
#include <linux/acpi.h>
Loading