From patchwork Fri Jan 27 18:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 49588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp981049wrn; Fri, 27 Jan 2023 10:29:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXtZJRp2dQINn9xpx4l4WDj+XRWB2bikXhBe5M6ZLw9sZ/1yqi//8KNEsBHS1RY6E24w4Ion X-Received: by 2002:a05:6a21:6d92:b0:b0:3e0f:508d with SMTP id wl18-20020a056a216d9200b000b03e0f508dmr53555695pzb.55.1674844191399; Fri, 27 Jan 2023 10:29:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674844191; cv=none; d=google.com; s=arc-20160816; b=RcizedgmkkjUdwIS0WYnEZIpvTRWzv4KJ/XbNVU4d0air/lSDxaLAkidkY010tyT8E dZfGliul8CWqGakW0Wh6h4QybFyruf5aTQNdawq22zmnZSmysSbRwidXIwVDEO+WhKOu jeoXnnXefCBFOxV/H9CpiI2DKbNM8ruqd5ueE8M38OnEiDNr3yGRvdHQQic2df1LvbTD 5gmnSd9i1zPYpl/RTKy6/OVmF7JjUkB/lZ7/JXwGUOuwYlcvTV0/mr3u7k5RUobCc9G0 IBEToImgL3JQtnA6r2zSnYnlAUPp43TOkZxh4JNwQgDk2nZOzecSovlC1Jc8uKRwMWNF KCpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=8MPK0X48FMiysaw0nsOseqJtZ6B9eEOkLBK2xmsdWRY=; b=sGt2io44ohJTdvArrB67/sRpt1zlRJZyTTpodFGnS1uZH30pnzeOvuU8G0DOiiPpLJ 4fYzuPyBnb/cVtZJ3XQ388sd31BGapBcurspX3HZkcQ695r9oA8UFVYvqxALXn/0Azrn eE0oLbGBdVjH4QibgFeVHAqoJ2wU7eHHvEgpuDVaDcpyq02SfsjRoImLURFKIN1PXclp zyTDpigLDeksY5gflEvZkVGQYK/qO3tBr4wQ57T6ShHP8Muwhlpq8k0tvOdlQg3zVILt sSQLkRPQzOBIK+Vl0KxNEX56ES2EoFoosn8I4GHRvu078GeZ0pInzUvKRgACWj0xz/E4 VINQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=10RUjvF4; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63930c000000b004da46ea2717si4901058pge.35.2023.01.27.10.29.39; Fri, 27 Jan 2023 10:29:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=10RUjvF4; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235406AbjA0S3Y (ORCPT + 99 others); Fri, 27 Jan 2023 13:29:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234919AbjA0S3L (ORCPT ); Fri, 27 Jan 2023 13:29:11 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208708A553; Fri, 27 Jan 2023 10:28:40 -0800 (PST) Date: Fri, 27 Jan 2023 18:26:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1674844016; 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; bh=8MPK0X48FMiysaw0nsOseqJtZ6B9eEOkLBK2xmsdWRY=; b=10RUjvF4Dj8jQVyI+p3bbUyOpQr+mgydmdZ+R0sp5dNDkEdHNnIjtKXUCY9pV02HQUC7OA 2Ir7SspzBzUczygc32CIB+DWsgas5OtYrCGntT1LIG6q5i6RawthvZ1RwYbM3MKg1QQK/E LkgDTqz6BIFDD7iwfaHonC6OfXd5u8/51AGp5DGVxUCOQBECs4yBhNZ3lhS9+gMeWhJXDj BVdw/0QEqBXpYpSRZMMArDjR7EjAyzyhbBUva08dwXSbaqmoESxl1MxfCYNWXVFPduVkpZ X/awzeoMKRmbF79mWNaSs2JQivd4Wjz0aoyq8XZtZ044JMwjubamW9GnZpcCiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1674844016; 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; bh=8MPK0X48FMiysaw0nsOseqJtZ6B9eEOkLBK2xmsdWRY=; b=U6hOmyJvZWLGwHCWNlOvBulQlPzIQEWmlGQ3kDAo023bx4xxV5/Zxv904tLas+UXLOG1om a7hFsA9gIlyt/GCA== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx: Relax SEPT_VE_DISABLE check for debug TD Cc: "Kirill A. Shutemov" , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <167484401594.4906.4180234768994841109.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756201422823057256?= X-GMAIL-MSGID: =?utf-8?q?1756201422823057256?= The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 47e67cf317ed6ad22a3df9762daae75dfcba76a8 Gitweb: https://git.kernel.org/tip/47e67cf317ed6ad22a3df9762daae75dfcba76a8 Author: Kirill A. Shutemov AuthorDate: Fri, 27 Jan 2023 01:11:58 +03:00 Committer: Dave Hansen CommitterDate: Fri, 27 Jan 2023 09:46:05 -08:00 x86/tdx: Relax SEPT_VE_DISABLE check for debug TD A "SEPT #VE" occurs when a TDX guest touches memory that is not properly mapped into the "secure EPT". This can be the result of hypervisor attacks or bugs, *OR* guest bugs. Most notably, buggy guests might touch unaccepted memory for lots of different memory safety bugs like buffer overflows. TDX guests do not want to continue in the face of hypervisor attacks or hypervisor bugs. They want to terminate as fast and safely as possible. SEPT_VE_DISABLE ensures that TDX guests *can't* continue in the face of these kinds of issues. But, that causes a problem. TDX guests that can't continue can't spit out oopses or other debugging info. In essence SEPT_VE_DISABLE=1 guests are not debuggable. Relax the SEPT_VE_DISABLE check to warning on debug TD and panic() in the #VE handler on EPT-violation on private memory. It will produce useful backtrace. Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Link: https://lore.kernel.org/all/20230126221159.8635-7-kirill.shutemov%40linux.intel.com --- arch/x86/coco/tdx/tdx.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index fbb9913..c4a1299 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -38,6 +38,7 @@ #define VE_GET_PORT_NUM(e) ((e) >> 16) #define VE_IS_IO_STRING(e) ((e) & BIT(4)) +#define ATTR_DEBUG BIT(0) #define ATTR_SEPT_VE_DISABLE BIT(28) /* TDX Module call error codes */ @@ -207,8 +208,15 @@ static void tdx_parse_tdinfo(u64 *cc_mask) * TD-private memory. Only VMM-shared memory (MMIO) will #VE. */ td_attr = out.rdx; - if (!(td_attr & ATTR_SEPT_VE_DISABLE)) - tdx_panic("TD misconfiguration: SEPT_VE_DISABLE attribute must be set."); + if (!(td_attr & ATTR_SEPT_VE_DISABLE)) { + const char *msg = "TD misconfiguration: SEPT_VE_DISABLE attribute must be set."; + + /* Relax SEPT_VE_DISABLE check for debug TD. */ + if (td_attr & ATTR_DEBUG) + pr_warn("%s\n", msg); + else + tdx_panic(msg); + } } /* @@ -664,6 +672,11 @@ static int virt_exception_user(struct pt_regs *regs, struct ve_info *ve) } } +static inline bool is_private_gpa(u64 gpa) +{ + return gpa == cc_mkenc(gpa); +} + /* * Handle the kernel #VE. * @@ -682,6 +695,8 @@ static int virt_exception_kernel(struct pt_regs *regs, struct ve_info *ve) case EXIT_REASON_CPUID: return handle_cpuid(regs, ve); case EXIT_REASON_EPT_VIOLATION: + if (is_private_gpa(ve->gpa)) + panic("Unexpected EPT-violation on private memory."); return handle_mmio(regs, ve); case EXIT_REASON_IO_INSTRUCTION: return handle_io(regs, ve);