Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1836845lqe; Tue, 9 Apr 2024 01:34:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOcd171hUHLFRJKwn7pSzdzybd5iICz74rtH/EG7eruO9EAau1brkuey4CBNwFpuxK4ryCUyGVpUHPThczvls/lO2Izawt373GVbJ09Q== X-Google-Smtp-Source: AGHT+IFYLOoSc/GkXEcB9OIMeizCfOSi88KSlHhf5yy6G6oMg/qCQGc5WmqqIZjHzv2yrjhYtSbZ X-Received: by 2002:a05:6902:2b0a:b0:dc6:b9d6:1542 with SMTP id fi10-20020a0569022b0a00b00dc6b9d61542mr12297201ybb.48.1712651685531; Tue, 09 Apr 2024 01:34:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712651685; cv=pass; d=google.com; s=arc-20160816; b=kP/CFZx+wPx3SAEfyCR4sVieQ8ILYAyoW+YkYVo2/1jwgpbkMbVdaO+3OvvE2NuVNI zCwIW72HTbaf+Bn8b8X8FKruMbykaTfaLEgFYVpbROJ/xBptPkBu2chhoYt6Ely9eid/ wmGVFQXFepN+UbW3DZveugStMVvCOWcpk5KZwHv4ANXlwORmVTctt8FXF2NWgOUV1t2z 1c4J8sBf68ioP+FUulH/AjOkfu2f4PFiW3sSV7pDpJ+E8MyR3vobR6nOY+RJYL2aNBcS GrZ+zZ1+QE9nJiOlEtHJxUwmBjMNXkdwCfNQ2Ef+rHFtoFZq7a3lX2tpbG15vCo1hWFF xlLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=Uv3eqwvRlzTvqyKKBFLuJ5zhdqBDogQRJAanaG8Ixeg=; fh=6kTV6MH5ZA6Qzm0bnYp88EdQVmxEXUQRunCSTv05aOo=; b=kP0/B/qHWaSiwWqwj6oLShyZk6cXKU6Jnv8cvOM5hA5AX9YE3XutIKA4HuEMA5VlK1 O/kh3BBjBE4orghy8TD5jMPb2qfZZyt4s0XadwKyCNpnF0NUMDcXku3m6BoM2Y+llz9I 9VdK6fwRdzhscWbC/XFwUQojEemCFozr+HWMks3MVzW8wCRVHZjRcED9y9lqzZtoJsSD AIxe81iHebaEArmKbYIBoC7xRSoo2gr0NPCE+sKyFZNizhU7sho2gUjV1NACa12II8aC PcycDIqX2+m8hijJWsf6XP7PlzVZh1sHgiEnkfn1bI6AJvlrirZKANbL989kypuSzlYI m5Lg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DDLPpozD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-136475-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136475-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w6-20020a05622a190600b00432e7e18c20si10046352qtc.271.2024.04.09.01.34.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 01:34:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136475-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=DDLPpozD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-136475-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136475-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CB8E1C21C1A for ; Tue, 9 Apr 2024 08:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C1997E772; Tue, 9 Apr 2024 08:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DDLPpozD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TIX6bOHt" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 415A713048B; Tue, 9 Apr 2024 08:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712651268; cv=none; b=AnHXi4u5FynB7UbOGjK2GTcpzRkOk5ZUHwzmWZCz0nG0CYfOhry+Yt0sZWAWy2tMX/oUbGRagMtyYK691v1RP6aROw7w9Z22WAz5NlC6XIyy+KG9I3SF+4m6FGZg0Zb/DZw0PIeNDNz0QeCesaAh3yw58/6QYAN03qSoJ1MSCoo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712651268; c=relaxed/simple; bh=/+Hi6vwrI+/azqu2PLMP1pkwyqM1tyJ2TALzPG1MuyA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=YmhCTiKpM73n/24HmnLV5ItNs3Y+s7o1mb+A7Spo7+Zr2kLgRQFfdtLz5O3WfOxLm46D9DvLOUZ65BH3DAP0mnjfrp6u5DtkhGRrft68Qd+4iGyqBZ5AaNg83HGVrBJoTkKN9bxSDnDolbXZRQvIVJ/k39bxI47zg/oK08akMmw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DDLPpozD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TIX6bOHt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Tue, 09 Apr 2024 08:27:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712651264; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uv3eqwvRlzTvqyKKBFLuJ5zhdqBDogQRJAanaG8Ixeg=; b=DDLPpozDuuyGUMP55FuJwgxpjzCgAIwpdiGfPcZ8i+AkOvxNhaIMCXU8dIS/ErkS+Z7w9S zBRQWb2XzUTlshc0WBfv1w4+Bh+mIbeMf3+7zLfzJrd5fGRgtoU4/7WqhVmqhQKO+80Cg3 m0OGOApjRUlJVR9QFnLMqr78BJvhIrW7cyZqUhlJzOJkkW2KfIrx4RS6/iy8RlXjjjCgkg vgR9UQSrUmY+1F6jIrEBgj7s4dgAMxxz8XOanvIKrRyVj8N3++0WCSUw9OntvwJfHZODur u1Z/YGNMeyWg3oThettLkSjjEi9RYqM3R9S2pMtgN2FlvKaXMZbrnsf078KNAA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712651264; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Uv3eqwvRlzTvqyKKBFLuJ5zhdqBDogQRJAanaG8Ixeg=; b=TIX6bOHtOHpk2vhI67s7+g3m+18TQCl1dsBenLUu3B8M72TaWz358Se3Jv09Mrv5pLt4Ke LeAaY5u+O4Q/pxDA== From: "tip-bot2 for Tony Luck" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cpu] x86/mce: Implement recovery for errors in TDX/SEAM non-root mode Cc: Tony Luck , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240408180944.44638-1-tony.luck@intel.com> References: <20240408180944.44638-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171265126376.10875.16864387954272613660.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/cpu branch of tip: Commit-ID: 7911f145de5fecbee1d67f27f73bec12f0fbc472 Gitweb: https://git.kernel.org/tip/7911f145de5fecbee1d67f27f73bec12f0fbc472 Author: Tony Luck AuthorDate: Mon, 08 Apr 2024 11:09:44 -07:00 Committer: Ingo Molnar CommitterDate: Tue, 09 Apr 2024 09:30:36 +02:00 x86/mce: Implement recovery for errors in TDX/SEAM non-root mode Machine check SMIs (MSMI) signaled during SEAM operation (typically inside TDX guests), on a system with Intel eMCA enabled, might eventually be reported to the kernel #MC handler with the saved RIP on the stack pointing to the instruction in kernel code after the SEAMCALL instruction that entered the SEAM operation. Linux currently says that is a fatal error and shuts down. There is a new bit in IA32_MCG_STATUS that, when set to 1, indicates that the machine check didn't originally occur at that saved RIP, but during SEAM non-root operation. Add new entries to the severity table to detect this for both data load and instruction fetch that set the severity to "AR" (action required). Increase the width of the mcgmask/mcgres fields in "struct severity" from unsigned char to unsigned short since the new bit is in position 12. Action required for these errors is just mark the page as poisoned and return from the machine check handler. HW ABI notes: ============= The SEAM_NR bit in IA32_MCG_STATUS hasn't yet made it into the Intel Software Developers' Manual. But it is described in section 16.5.2 of "Intel(R) Trust Domain Extensions (Intel(R) TDX) Module Base Architecture Specification" downloadable from: https://cdrdv2.intel.com/v1/dl/getContent/733575 Backport notes: =============== Little value in backporting this patch to stable or LTS kernels as this is only relevant with support for TDX, which I assume won't be backported. But for anyone taking this to v6.1 or older, you also need commit: a51cbd0d86d3 ("x86/mce: Use severity table to handle uncorrected errors in kernel") Signed-off-by: Tony Luck Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20240408180944.44638-1-tony.luck@intel.com --- arch/x86/include/asm/mce.h | 2 ++ arch/x86/kernel/cpu/mce/core.c | 18 ++++++++++++++++++ arch/x86/kernel/cpu/mce/severity.c | 16 ++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h index de31183..dfd2e96 100644 --- a/arch/x86/include/asm/mce.h +++ b/arch/x86/include/asm/mce.h @@ -13,6 +13,7 @@ #define MCG_CTL_P BIT_ULL(8) /* MCG_CTL register available */ #define MCG_EXT_P BIT_ULL(9) /* Extended registers available */ #define MCG_CMCI_P BIT_ULL(10) /* CMCI supported */ +#define MCG_SEAM_NR BIT_ULL(12) /* MCG_STATUS_SEAM_NR supported */ #define MCG_EXT_CNT_MASK 0xff0000 /* Number of Extended registers */ #define MCG_EXT_CNT_SHIFT 16 #define MCG_EXT_CNT(c) (((c) & MCG_EXT_CNT_MASK) >> MCG_EXT_CNT_SHIFT) @@ -25,6 +26,7 @@ #define MCG_STATUS_EIPV BIT_ULL(1) /* ip points to correct instruction */ #define MCG_STATUS_MCIP BIT_ULL(2) /* machine check in progress */ #define MCG_STATUS_LMCES BIT_ULL(3) /* LMCE signaled */ +#define MCG_STATUS_SEAM_NR BIT_ULL(12) /* Machine check inside SEAM non-root mode */ /* MCG_EXT_CTL register defines */ #define MCG_EXT_CTL_LMCE_EN BIT_ULL(0) /* Enable LMCE */ diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 84d41be..771a9f1 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1593,6 +1593,24 @@ noinstr void do_machine_check(struct pt_regs *regs) else queue_task_work(&m, msg, kill_me_maybe); + } else if (m.mcgstatus & MCG_STATUS_SEAM_NR) { + /* + * Saved RIP on stack makes it look like the machine check + * was taken in the kernel on the instruction following + * the entry to SEAM mode. But MCG_STATUS_SEAM_NR indicates + * that the machine check was taken inside SEAM non-root + * mode. CPU core has already marked that guest as dead. + * It is OK for the kernel to resume execution at the + * apparent point of the machine check as the fault did + * not occur there. Mark the page as poisoned so it won't + * be added to free list when the guest is terminated. + */ + if (mce_usable_address(&m)) { + struct page *p = pfn_to_online_page(m.addr >> PAGE_SHIFT); + + if (p) + SetPageHWPoison(p); + } } else { /* * Handle an MCE which has happened in kernel space but from diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index c447716..fc8988c 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -39,8 +39,8 @@ static struct severity { u64 mask; u64 result; unsigned char sev; - unsigned char mcgmask; - unsigned char mcgres; + unsigned short mcgmask; + unsigned short mcgres; unsigned char ser; unsigned char context; unsigned char excp; @@ -174,6 +174,18 @@ static struct severity { USER ), MCESEV( + AR, "Data load error in SEAM non-root mode", + SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA), + MCGMASK(MCG_STATUS_SEAM_NR, MCG_STATUS_SEAM_NR), + KERNEL + ), + MCESEV( + AR, "Instruction fetch error in SEAM non-root mode", + SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_INSTR), + MCGMASK(MCG_STATUS_SEAM_NR, MCG_STATUS_SEAM_NR), + KERNEL + ), + MCESEV( PANIC, "Data load in unrecoverable area of kernel", SER, MASK(MCI_STATUS_OVER|MCI_UC_SAR|MCI_ADDR|MCACOD, MCI_UC_SAR|MCI_ADDR|MCACOD_DATA), KERNEL