Re: [PATCH v6 2/7] x86/apic: Add an SVSM APIC driver

From: Melody Wang

Date: Sat Dec 05 2026 - 21:50:20 EST


Hi Tom,

On 11/20/26 12:47 PM, Tom Lendacky wrote:
+
+static int svsm_apic_probe(void)
+{
+ if (!cc_platform_has(CC_ATTR_SNP_ALTERNATE_INJECTION)) {
+ return 0;
+ } else {

No need for an else here if the "if" above has a return.

+ if (!snp_vmpl) {
+ pr_err("Alternate Injection in VMPL0 impossible. Terminating.\n");
+ goto terminate;
+ }
+ }
+
+ if (!x2apic_mode) {
+ pr_err("Alternate Injection in non x2APIC mode impossible. Terminating.\n");
+ goto terminate;
+ }
+
+ pr_info("Alternate Injection SVSM APIC enabled\n");
+
+ return 1;
+
+terminate:
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);

Should you come up with individual fail codes for each of the above?

It seems too many fail codes for Alternate Injection itself while there are only 255 values total.

+static u64 __svsm_apic_icr_rw(u32 low, u32 id, bool write)
+{
+ struct svsm_call call = {};
+ const char *call_reg_str;
+ unsigned int call_reg;
+ u32 reg;
+ int ret;
+
+ reg = APIC_ICR;
+
+ call_reg = write ? SVSM_APIC_WRITE_REGISTER
+ : SVSM_APIC_READ_REGISTER;
+
+ call_reg_str = write ? "SVSM_APIC_WRITE_REGISTER"
+ : "SVSM_APIC_READ_REGISTER";

You only use call_reg and call_reg_str in one place each, no need to
create variables.

Sure.

+
+ .get_apic_id = svsm_apic_get_apic_id,

Should this just use x2apic_get_apic_id ?

Sure.

Thanks,
Melody