Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3085596lqo; Tue, 21 May 2024 06:36:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXxcRlTygMlzQQVothA4dj6x5rE6V9HdAC/Ec5+PjNR5/JG3HPA7ym01Tuuq2El+EjKu501ZDyoodonDJv10sQPt++iDM13tb3MXCn2Zw== X-Google-Smtp-Source: AGHT+IEwbZctJCe8ydAKCTuDKbcREmzTAjtrN9z5ISmvZaeMheRMQ0/fbICERReViIRgVH0JWMp+ X-Received: by 2002:a50:8a84:0:b0:56e:2c34:cfec with SMTP id 4fb4d7f45d1cf-5734d59043dmr23866906a12.7.1716298562165; Tue, 21 May 2024 06:36:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716298562; cv=pass; d=google.com; s=arc-20160816; b=uCqfDuX2OGQQM0vRdL8Mcodvv2sxXRHQtU3fyDqjoVtrgmIV8aT8eSvj8RP3ACuBmY WO3cbKlS8tkian7AmzaBjS181b4h0XoCUDLe2ibzHFOvtdQtt63eOLjSYF39yI29gjuS Wey0vppX+QV010E/GuWsL9fyvDrvPw4g9mQ3HJCF3Dg+n430epfc24EV0j2vKdySk0IE BIgda8iYQWCfEGFENB9C/1UIBK+oEEFTGNgylKKiaP4y/7KFXXjS6oH1P77/TbKjQT2z 1hs3/NUdazNSlXx3ebyf5zI3x4ow5S8N26QBoseAPrN0zY/AAyiMSYW0RYfesgW8OamV J/Ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=OHtPmLk8n59R2bGYCs10YPaNhR/pBrdzfv2c7atjm0c=; fh=4mWvKYDvTF3Fn61klR4N/vzL5f8+oGsagwDFr5dEIVw=; b=looXKGe4tzSXHwpkpsn6zNtRniP73+Z9kAwCQSXlUgSXrF1lgd9qFLpsCNP4IV7qk5 EVQ89F5Qqb3c1XU0ccoBP4iSmln5L1T5+W0wdB/+UF6qBS6Cc8u/+X3OWHPvbb8dJriQ gED/oHm2h8mXEtk0lOg9a1MKPMw+qavm8f4nXsk7y1nm3+Tuf/YHKm4IYJiqVTtaD+nC fc+JXt/bcNRKCCf87paZvbGez4wVSCcBTuzpyOb3dv0YWmIajrj6JYE8BZ5MIK3TIDC+ lJj7vU9NSTLYCj8PQ7rMZRtVlh/NSqyUEMGHdvaAkkmbpFj//O97xKEmuWixz9ETtWXz RluQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mfFo78A3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-185018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185018-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-574b41804c3si11462036a12.641.2024.05.21.06.36.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 06:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mfFo78A3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-185018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185018-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D3C051F21B2B for ; Tue, 21 May 2024 13:36:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F12C47EEF3; Tue, 21 May 2024 13:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mfFo78A3" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 6EBA26E602 for ; Tue, 21 May 2024 13:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716298553; cv=none; b=KIC53jBc9BUjUKHTSa7SuBIGvEdSIfr6qGwrsKXX9UfX577ogVr7hH1M/HVheIzhwLh14W5y06HIIZiK8koPUELaA3guk73Z5+QZ8x0OggF67H9o8wZmjSBpjPr0Ozgp8vspO6IYbxJMRdavLL484rSnlNrmKXP28wsKUFA5TTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716298553; c=relaxed/simple; bh=Jatn8u4QFUuL+pR08zoVUZZsvNQF78BGvon9Gukephw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=erMtP6JqpS/J26fQpnIXkJjadRJxAnylhRatWZPls2Q0LAmtoGCDu7fokLFROFm/6paUUMukopVXWAKzbti0+hPFR6MFFzpmh4fUq+/NGnVy5eKFCABbhgih/7xhiErhM+dzPiRPS/0m3SK3NiqcBMcmliZAl4beIe6iVQWbpew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mfFo78A3; arc=none smtp.client-ip=192.198.163.12 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.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716298552; x=1747834552; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Jatn8u4QFUuL+pR08zoVUZZsvNQF78BGvon9Gukephw=; b=mfFo78A3pJc7R0fus06fompILajLRMU7cfU2h7+435yv1ZRMUIsIcfkT n+8+NNmvKpoqQIzJ1YhDMvbC2HrEzyqRWPzuKFo0lYJ8iJ/DsXZSIukaL jCCNHvywlMzeG1s3WB2W9vBEcPgHNVClW3xI1k1xosbC4GbMcWRYWwgWZ h9qyL5y9Z9+XH+O6dM062+AiC6+8Sknrz5Wc7lpEhGStKskuQ5p1w36D4 ERpDXTz4ymdkVcp4M+I3TqmSyaUM21U/jwTP3IXdMDmxK6Ef4cZzSNHhV lle2SCgG9YjH2v0e5R4Rew1M3dt4dzc2xMBKUYuxYyb6th2ocraAmy7er w==; X-CSE-ConnectionGUID: +i49ERRsTheevRXL4W7JaQ== X-CSE-MsgGUID: D2gWwjYSRhKBvY9IIzMelA== X-IronPort-AV: E=McAfee;i="6600,9927,11078"; a="16330966" X-IronPort-AV: E=Sophos;i="6.08,177,1712646000"; d="scan'208";a="16330966" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 06:35:51 -0700 X-CSE-ConnectionGUID: kPBC/OVTTnG2naU3R85JMA== X-CSE-MsgGUID: 71kxtUr8T8mlgwjFVvkliA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,177,1712646000"; d="scan'208";a="33526496" Received: from bjrankin-mobl3.amr.corp.intel.com (HELO [10.124.221.140]) ([10.124.221.140]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 06:35:50 -0700 Message-ID: <38dec9ee-1dde-4b3b-87c7-a65161d4a015@linux.intel.com> Date: Tue, 21 May 2024 06:35:49 -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: <20240521073505.2190633-1-kirill.shutemov@linux.intel.com> Content-Language: en-US From: Kuppuswamy Sathyanarayanan In-Reply-To: <20240521073505.2190633-1-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/21/24 12:35 AM, Kirill A. Shutemov wrote: > 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. Any specific use cases ? Like who is using 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 > --- Code looks good to me. Reviewed-by: Kuppuswamy Sathyanarayanan > 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. > * -- Sathyanarayanan Kuppuswamy Linux Kernel Developer