Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2914746lqo; Tue, 21 May 2024 00:35:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZmnpCZuY7536NXVIURQCa3seBCJfydird6PJDGBJgc/eSr8pQWm3oWklxMT3pzHglHppUlxJoanv3OaGjLUzSbLAjA+VPXJ7h+EkbCg== X-Google-Smtp-Source: AGHT+IHgfClDYD4Y7WMDOV+9hzHBOTCVmQR8B8Ul1gCfXMbQGlHjRrleszZyM/JXRixBLa4s2xS/ X-Received: by 2002:ac8:5f49:0:b0:43a:daca:f300 with SMTP id d75a77b69052e-43dfdaf4c88mr341315641cf.24.1716276931979; Tue, 21 May 2024 00:35:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716276931; cv=pass; d=google.com; s=arc-20160816; b=d6Wo6mK9Lu9PvqgLWo2Kfai+F+w6pLddVU5u0wvqvSnnYauuF9YxPk4lTzE2Y14P2I KoHmHHgC3PXQg9MTE2PT8E9+goZo4zxo3Vmybnwd+2QTCbadkTq95qlQB84F63ZKLmnY r02yryu5I5YPV0UhJTyBssqKMFdClDbcoboEi8V3n1UHI+IPbsGV/ofGwQUZCKDKKxDc tP9wwte/AKUvLXoFRcGqEiSK6TdCX672CgoOQcm5gWyTMj4vkMtM/9RK7eh9uemjDwTq NWhXIZ0jojxIgrB2ZRpFdl9QHEqp+jiOaDX3L299s+koarB5rwBxTWmJTtpE0s2ldNca BZxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=gS6ZHDRAEP5u0AyGwv4unDcSt9/9sZ8/AZXkKtG/TYw=; fh=4mWvKYDvTF3Fn61klR4N/vzL5f8+oGsagwDFr5dEIVw=; b=D9FtdlieoFeOngmTowBFOoNQK8lFHZOus3ETSFAm1p5MaOm39QEk2/mO8wQrAAFldx 8qjdPMThUwmHjlFcxlBJGw34Z7ai+IOdVO/7LAbvPbxbrIuO3NTsO1xmXsrQ5ynsnfIU gJDsIBOF6VpD/exK4Rc+DqJnIcQ+/V4iUM0Q0vB1fg0ekG8wtA/Q3wJwL5RY8Ya9OdQ0 c6RO7GQnr2uXrM4hhAp1E7W5HH+vFcX7rQRIGPUlPluocSLEJcHP5udBwsjTcgDghdB9 HNhJZ7cjrJcmeTCiON53QKqI1LxSrFRYmGywKtntQ8NsBXg76rsJYtwMEyWeMLegscSa lq5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gpE5EzWy; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-184575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43e3845549esi10618021cf.728.2024.05.21.00.35.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 00:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184575-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=@intel.com header.s=Intel header.b=gpE5EzWy; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-184575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 A25A21C2117B for ; Tue, 21 May 2024 07:35:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FE825028B; Tue, 21 May 2024 07:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gpE5EzWy" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 EA4344F88A for ; Tue, 21 May 2024 07:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716276918; cv=none; b=b2WAmD/f2N1Gui+P8twQr4CXFODzEqfa2zRkhobbXtLfOypmokTfp3AWPtZ5mWL/rkwa0JXZbAnaR7H+5rQWFNf1iEgJ3Ebh3kkZPbUDFzzCdLNqvb3A7y2F8DRhvrGvw+SFXpNn1J7pAZF09bCg6nl3BC/KrGUwlHgQgtMxZPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716276918; c=relaxed/simple; bh=SmapWnD22BSkuuiCcoA8YWZC7F0yYy7UOwcrTcoz1PY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RwQlSRTwoRnM6Z3YRagwXAtd4Y1c6uijYSNbVcSqQboBJ3SpCdZ48RFDhV2GaqWaAlPJKTqEwGHW7TJr3Au11NvVMlS5sP+++4WvlLLiEGDsI4gVCL9Pm3IV+DFE+jVQLAxPCTwtT+7hPmdMTFeSdIRJZ6F2xx3HrlPPIHobHRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gpE5EzWy; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716276917; x=1747812917; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SmapWnD22BSkuuiCcoA8YWZC7F0yYy7UOwcrTcoz1PY=; b=gpE5EzWy0Zx30PL5DGZS9O6pVqEz0cvETm360cehSkaPciHLhMtlXJFi Z64FAK0DzzWvttY587aBN9FkmnKm/6A3e1XbU3urDcQKDvbMNYJQ6ztv3 bsjt+d9AXwxn6Ut1Qn/wMb0UiXCIwcgCyAnz5vfC7zTaTejqQq03wtRfr 6fRnSvJxyxvzY3LFq6m7Yp2XfL5YUSk0ZR5ebx0sP/uzoKMJJV/rolJl3 p31Ku0N2tiUNnD8QAlClqbzsS0jNj/x59JvsrrUL3JMiyXe+5z6H3ifd4 SPw9wEB61Twzb9g5CPRJMyMt1jlQ3aN72Y5zz3ElGZ9b+bl1dybtCpkny w==; X-CSE-ConnectionGUID: kJ0Q8QxaQ/61kt5+3Uv4Zw== X-CSE-MsgGUID: E+SLbkWySFqb28gIONfagA== X-IronPort-AV: E=McAfee;i="6600,9927,11078"; a="12297150" X-IronPort-AV: E=Sophos;i="6.08,177,1712646000"; d="scan'208";a="12297150" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 00:35:16 -0700 X-CSE-ConnectionGUID: rap6sGGaQ++LMZCDQqhltg== X-CSE-MsgGUID: PQvzxl7SSSaEubBwD6FX0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,177,1712646000"; d="scan'208";a="32854892" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa009.fm.intel.com with ESMTP; 21 May 2024 00:35:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id B2004179; Tue, 21 May 2024 10:35:12 +0300 (EEST) From: "Kirill A. Shutemov" To: "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, cho@microsoft.com, decui@microsoft.com, John.Starks@microsoft.com Subject: [PATCH] x86/tdx: Generate SIGBUS on userspace MMIO Date: Tue, 21 May 2024 10:35:05 +0300 Message-ID: <20240521073505.2190633-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently attempt to do MMIO from userspace in TDX guest leads to warning about unexpect #VE and SIGSEGV being delivered to the process. Enlightened userspace might choose to deal with MMIO on their own if kernel doesn't emulate it. Handle EPT_VIOLATION exit reason for userspace and deliver SIGBUS instead of SIGSEV. SIGBUS is more appropriate for MMIO situation. Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index c1cb90369915..d2aa93cebf5a 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -630,6 +631,11 @@ void tdx_get_ve_info(struct ve_info *ve) ve->instr_info = upper_32_bits(args.r10); } +static inline bool is_private_gpa(u64 gpa) +{ + return gpa == cc_mkenc(gpa); +} + /* * Handle the user initiated #VE. * @@ -641,17 +647,20 @@ static int virt_exception_user(struct pt_regs *regs, struct ve_info *ve) switch (ve->exit_reason) { 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."); + + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)ve->gla); + + /* Return 0 to avoid incrementing RIP */ + return 0; default: pr_warn("Unexpected #VE: %lld\n", ve->exit_reason); return -EIO; } } -static inline bool is_private_gpa(u64 gpa) -{ - return gpa == cc_mkenc(gpa); -} - /* * Handle the kernel #VE. * -- 2.43.0