Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp380274lqp; Mon, 10 Jun 2024 07:02:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV+UUbZ+6drhjCn75yv/kPDUhBld522xeN5v+UxWzBqZ176yNz47spz2MalKnXqBJKnPcMOJBP6Jyl7JBTYcvgvc+VhVjK7Jjb92xLHwA== X-Google-Smtp-Source: AGHT+IHFkxKRLhRNwBwGsm/tihrWXc37NS2+rzPzjPtv7HTB5vVIROjXfdotsc6uyxkK+rabJviE X-Received: by 2002:a05:6358:d28:b0:19f:1e0c:e1a3 with SMTP id e5c5f4694b2df-19f1ff8fc57mr1298854355d.22.1718028155532; Mon, 10 Jun 2024 07:02:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718028155; cv=pass; d=google.com; s=arc-20160816; b=asLk+nha4UFvZXutj6Ald9U+kjLyvDSfS3nt3DlvOJZ61h3ylpuxsWuoC6lGWvijVV GWX+blqmm7wrHaTfzDQ+adLvN+6k3+9ivuyNjT/qf58jZRp97Ps3XdF2u8eDB5k0xBBI NJjiApt9t8DIrpt19ybMnpjDlsz92DBswWpEe2v8e342c8CIrmoFTocAop/0NYCVjkHq 525Iphn24fXFZO0qxwfjNbHrNm7MCcQFVamHAlAImZTYEWx8stV97N4luQowYzYqWnCz v6GmuOQfrNNWdqdCKX6i6e8Otx8r2Xa+QDCyU+JZz+Dk7Ze9XXRWXXJEQF9CGsY0382q 9gNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=kV2fk5Po11xLrtr938DJlp2J0hUN5w0lJ7IoteirR2Y=; fh=4mWvKYDvTF3Fn61klR4N/vzL5f8+oGsagwDFr5dEIVw=; b=Pegxi5M5bzQRymC/9b4CmBJg8Mw5hhj/louFR74K0xZXc5S562Zai4WlOWO+4u9OEN oQ3KiEkyDJHL12GPQbE+/QnuSRONiViRxO1kKrG9i258KyBHjO3ZckOYN2yfB7pkHGbv FxfDtNkjD1II9EOQKbS+3Qn0vRZAF/WYOaEEcFPdU6wFNMBNs7rwlHy0sIpc1fDf/Z2Y Ih/q57JGSn716m103A/j7hPxie9GbTWiD1gqq5j1g18YZU5TGXI+ytZFtkj/LUwu6/jU s2H2vSXPaH2FZ507ZCrEf5Ig7rvOZS6aRYJpxpTL9QU2Ub4aWGBR/lJPbHQxRS6T/CVo /dPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VnHKWS1M; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-208304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e39ef4e555si3554203a12.200.2024.06.10.07.02.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:02:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VnHKWS1M; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-208304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208304-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3793F280F63 for ; Mon, 10 Jun 2024 14:00:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EFCE13FD95; Mon, 10 Jun 2024 13:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VnHKWS1M" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 BB35C12E1F1 for ; Mon, 10 Jun 2024 13:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027761; cv=none; b=QaLzlZJWz30Yjk4SepQSc7OuCBbklzvumLu5E/LDLKpnW5ZMvO5mbp/5yepmcMXBGFHFihDf/ZVCr64YmAc9WAPzNTB7rD/PWIzw1Hoyeg+wr6KzXrb12RYxINN8RD4+lEGP1duIfU3kTEjI9y+v47l8QvpS09lq3amw4cqvZRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027761; c=relaxed/simple; bh=8aWqcWVakj8eKQfBYOFwbkfW13rGZgEUtkOjfqy2+zs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VcFhXPVjIdfiFZo/wHQX6YaTXnnOPdLkBP+vMzhKH3tF2PqJe42DHBncX8kGibODxrj4peELc/PjnGQT3NDqUeqIzS6IyuXY6RPkf3KLLDfw7pohB/eo59tTZ0O/6v/oIu9FT7nntcX1B/m/V/JkkOeT/ikIWUJ3GjUG9Lu5d8U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VnHKWS1M; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718027758; x=1749563758; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=8aWqcWVakj8eKQfBYOFwbkfW13rGZgEUtkOjfqy2+zs=; b=VnHKWS1M/LpmYfz0XsjvdsFSveChViVx8YS3ulrt7TQCNMTbtvaXF+XF Fy0dMMvpqx0LYR/HYo0RR8kpK4L2GJFUyOmDWkoGKzvtycFMstWGOlUPD 6VZ2scohTQooxwhmQwa63zDK/kc4LIB5b/HEAaRZGhLGHW1h5J2y9Mz9x i7rNbfBeoeu+rFyflU9oOHt7mIcQmQg0QMaBb+/34ci8fKskMv1PShyA7 wvfeOS3MIbYR3ZBNv7WzIBW1Knkf+cDCxR8yJRIUAScuJExVOKTbLrliS 96yGZbXi++9eusjnx5gDu1GCBC50rVUE7CzMSJ1S3A5n9VNym7YOXPatg Q==; X-CSE-ConnectionGUID: hnU3sAHVSdmU1atD+4UzFw== X-CSE-MsgGUID: WpLFEbhiQ2q7unnJVEX+2g== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="17611556" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="17611556" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 06:55:58 -0700 X-CSE-ConnectionGUID: CMbdMgL7QJe/ce3cJSwdhw== X-CSE-MsgGUID: BUkolO3kSVmqkEaIXQQBVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39184108" Received: from unknown (HELO [10.125.110.41]) ([10.125.110.41]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 06:55:56 -0700 Message-ID: <4df2ebee-40c0-4ea3-8909-13b90f049ff1@intel.com> Date: Mon, 10 Jun 2024 06:55:56 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/tdx: Generate SIGBUS on userspace MMIO 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 References: <20240528100919.520881-1-kirill.shutemov@linux.intel.com> Content-Language: en-US From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668Qp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cOvufXkBTm+whm +AyNTjaCRt6aSMnA/QHVGSJ8grrTJCoACVNhnXg/R0g90g8iV8Q+IBZyDkG0tBThaDdw1B2l asInUTeb9EiVfL/Zjdg5VWiF9LL7iS+9hTeVdR09vThQ/DhVbCNxVk+DtyBHsjOKifrVsYep WpRGBIAu3bK8eXtyvrw1igWTNs2wazJ71+0z2jMzbclKAyRHKU9JdN6Hkkgr2nPb561yjcB8 sIq1pFXKyO+nKy6SZYxOvHxCcjk2fkw6UmPU6/j/nQlj2lfOAgNVKuDLothIxzi8pndB8Jju KktE5HJqUUMXePkAYIxEQ0mMc8Po7tuXdejgPMwgP7x65xtfEqI0RuzbUioFltsp1jUaRwQZ MTsCeQDdjpgHsj+P2ZDeEKCbma4m6Ez/YWs4+zDm1X8uZDkZcfQlD9NldbKDJEXLIjYWo1PH hYepSffIWPyvBMBTW2W5FRjJ4vLRrJSUoEfJuPQ3vW9Y73foyo/qFoURHO48AinGPZ7PC7TF vUaNOTjKedrqHkaOcqB185ahG2had0xnFsDPlx5y In-Reply-To: <20240528100919.520881-1-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/28/24 03:09, Kirill A. Shutemov wrote: > Currently, attempting to perform MMIO from userspace in a TDX guest > leads to a warning about an unexpected #VE and SIGSEGV being delivered > to the process. Does it _always_ result in a #VE? Or is this only when guests mmap() something like from a driver and the host doesn't back the shared memory? > Enlightened userspace may choose to handle MMIO on their own if the > kernel does not emulate it. > > Handle the EPT_VIOLATION exit reason for userspace and deliver SIGBUS > instead of SIGSEGV. SIGBUS is more appropriate for the MMIO situation. Is any userspace _actually_ doing this? Sure, SIGBUS is more appropriate but in practice unprepared userspace crashes either way. > @@ -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; This _really_ needs a comment, probably even a helper function where you can actually explain what is going on. I could barely remember what this is for today. There's no hope for me in a couple of years. Just thinking through the possibilities here: Private=> Private : no #VE Private=> Anything else : fatal shutdown Shared => Shared : no #VE Shared => Private : #VE (end up here) Shared => !Present : #VE (end up here) So I think you're trying to differentiate between the last 2 cases. "Shared => !Present" is the normal case where today the VM wants to generate a VMEXIT. We'll probably get these from setups where somebody is trying to do good ol' device emulation but in TDX. "Shared => Private" is an actual kernel bug. Why panic() though? Do we *know* the system is unstable at this point? Why not just dump an error, send a fatal signal, and move on?