Fixes for recovery for machine check in TDX/SEAM non-root mode
v2 cover Fixes for recovery for machine check in TDX/SEAM non-root mode
Hi
Here is V2 of a small fix related to recovery for machine check in TDX/SEAM non-root mode, and a small tidy-up.
Changes in V2:
x86/mce: Fix missing address mask in recovery for errors in TDX/SEAM non-root mode
Mask address when it is read
Amend struct mce addr description
KVM: TDX: Do not clear poisoned pages
Patch dropped
x86/mce: Remove MCI_ADDR_PHYSADDR
New patch
The issue was noticed as part of work to determine the conditions under which TDX private memory needs to be cleared after being reclaimed. For guests with a large amount of memory, clearing all private pages during VM shutdown can take minutes, so we are looking at when that can be skipped. A future patch will deal with that.
One thing that was investigated was the effect of deliberately corrupting a TDX guest private page by writing to it on the host, and then reading it on the guest, which results in a machine check as expected, but revealed the issue addressed in patch 1.
There are 2 outstanding issues:
1. It is assumed that once the TDX VM is shutdown that the memory is returned to the allocator. That is true at present, but may not be in the future. Consider, for example, patch set "New KVM ioctl to link a gmem inode to a new gmem file" :
https://lore.kernel.org/r/[email protected]/
2. Currently, KVM TDX does not cater for the TDX VM to enter a FATAL error state, where the only operation permitted is to tear down the VM. KVM just carries on, hitting various errors, but in particular, memory reclaim fails because it is not following the teardown procedure, and all guest private memory is leaked.
Adrian Hunter (2):
x86/mce: Fix missing address mask in recovery for errors in TDX/SEAM non-root mode x86/mce: Remove MCI_ADDR_PHYSADDR
arch/x86/include/asm/mce.h | 3 --- arch/x86/include/uapi/asm/mce.h | 2 +- arch/x86/kernel/cpu/mce/core.c | 9 ++++++--- drivers/cxl/core/mce.c | 2 +- drivers/edac/skx_common.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
Regards
Adrian
PATCH v2 1/2 x86/mce: Fix missing address mask in recovery for errors in TDX/SEAM non-root mode
Commit 8a01ec97dc066 ("x86/mce: Mask out non-address bits from machine check bank") introduced a new #define MCI_ADDR_PHYSADDR for the mask of valid physical address bits within the machine check bank address register.
This is particularly needed in the case of errors in TDX/SEAM non-root mode because the reported address contains the TDX KeyID. Refer to TDX and TME-MK documentation for more information about KeyIDs.
Commit 7911f145de5fe ("x86/mce: Implement recovery for errors in TDX/SEAM non-root mode") uses the address to mark the affected page as poisoned, but omits to use the aforementioned mask.
Investigation of user space expectations has concluded it would be more correct for the address to contain only address bits in the first place. Refer https://lore.kernel.org/r/[email protected]
Mask the address when it is read from the machine check bank address register. Do not use MCI_ADDR_PHYSADDR because that will be removed in a later patch.
It is assumed __log_error() in arch/x86/kernel/cpu/mce/amd.c does not need similar treatment.
Amend struct mce addr member description slightly to reflect that it is not, and never has been, an exact copy of the bank's MCi_ADDR MSR.
---
Changes in V2:
Mask address when it is read
Amend struct mce addr description
arch/x86/include/uapi/asm/mce.h | 2 +- arch/x86/kernel/cpu/mce/core.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/include/uapi/asm/mce.h +1 -1
@@ -14,7 +14,7 @@struct mce {__u64 status;/* Bank's MCi_STATUS MSR */ __u64 misc;/* Bank's MCi_MISC MSR */ -__u64 addr;/* Bank's MCi_ADDR MSR */ +__u64 addr;/* Address from bank's MCi_ADDR MSR */ __u64 mcgstatus;/* Machine Check Global Status MSR */ __u64 ip;/* Instruction Pointer when the error happened */ __u64 tsc;/* CPU time stamp counter */
arch/x86/kernel/cpu/mce/core.c +3 -0
@@ -699,6 +699,9 @@ static noinstr void mce_read_aux(struct mce_hw_err *err, int i) }smca_extract_err_addr (m); + +/* Mask out non-address bits, such as TDX KeyID */ + m->addr &=GENMASK_ULL (boot_cpu_data.x86_phys_bits -1 ,0 ); }if (mce_flags.smca) {
Signature · 1 line
2.48.1
PATCH v2 2/2 x86/mce: Remove MCI_ADDR_PHYSADDR
In reply to Adrian HunterNow that the address is masked when it is read from the machine check bank address register (refer patch "x86/mce: Fix missing address mask in recovery for errors in TDX/SEAM non-root mode"), the MCI_ADDR_PHYSADDR macro is no longer needed. Remove it.
Note MCE address information also enters the kernel from APEI via the Common Platform Error Record (CPER) Memory Error Section "Physical Address" field (struct cper_sec_mem_err physical_addr), refer the UEFI specification. It is assumed that field contains only the physical address.
---
Changes in V2:
New patch
arch/x86/include/asm/mce.h | 3 --- arch/x86/kernel/cpu/mce/core.c | 6 +++--- drivers/cxl/core/mce.c | 2 +- drivers/edac/skx_common.c | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-)
arch/x86/include/asm/mce.h +0 -3
@@ -91,9 +91,6 @@#define MCI_MISC_ADDR_MEM 3/* memory address */ #define MCI_MISC_ADDR_GENERIC 7/* generic */ -/* MCi_ADDR register defines */ -#define MCI_ADDR_PHYSADDR GENMASK_ULL(boot_cpu_data.x86_phys_bits - 1, 0) -/* CTL2 register defines */ #define MCI_CTL2_CMCI_EN BIT_ULL(30)#define MCI_CTL2_CMCI_THRESHOLD_MASK 0x7fffULL
arch/x86/kernel/cpu/mce/core.c +3 -3
@@ -642,7 +642,7 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val, mce->severity != MCE_DEFERRED_SEVERITY)return NOTIFY_DONE ; - pfn = (mce->addr &MCI_ADDR_PHYSADDR ) >>PAGE_SHIFT ; + pfn = mce->addr >>PAGE_SHIFT ;if (!memory_failure (pfn,0 )) {set_mce_nospec (pfn); mce->kflags |=MCE_HANDLED_UC ;
@@ -1415,7 +1415,7 @@ static void kill_me_maybe(struct callback_head *cb)if (!p->mce_ripv) flags |=MF_MUST_KILL ; - pfn = (p->mce_addr &MCI_ADDR_PHYSADDR ) >>PAGE_SHIFT ; + pfn = p->mce_addr >>PAGE_SHIFT ; ret =memory_failure (pfn, flags);if (!ret) {set_mce_nospec (pfn);
@@ -1444,7 +1444,7 @@ static void kill_me_never(struct callback_head *cb) p->mce_count =0 ;pr_err ("Kernel accessed poison in user space at %llx\n" , p->mce_addr); - pfn = (p->mce_addr &MCI_ADDR_PHYSADDR ) >>PAGE_SHIFT ; + pfn = p->mce_addr >>PAGE_SHIFT ;if (!memory_failure (pfn,0 ))set_mce_nospec (pfn); }
drivers/cxl/core/mce.c +1 -1
@@ -24,7 +24,7 @@ static int cxl_handle_mce(struct notifier_block *nb, unsigned long val,if (!endpoint)return NOTIFY_DONE ; - spa = mce->addr &MCI_ADDR_PHYSADDR ; + spa = mce->addr; pfn = spa >>PAGE_SHIFT ;if (!pfn_valid (pfn))
drivers/edac/skx_common.c +1 -1
@@ -732,7 +732,7 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,memset (&res,0 ,sizeof (res)); res.mce = mce; - res.addr = mce->addr &MCI_ADDR_PHYSADDR ; + res.addr = mce->addr;if (!pfn_to_online_page (res.addr >>PAGE_SHIFT ) && !arch_is_platform_page (res.addr)) {pr_err ("Invalid address 0x%llx in IA32_MC%d_ADDR\n" , mce->addr, mce->bank);return NOTIFY_DONE ;
Signature · 1 line
2.48.1