Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp563498lqm; Wed, 1 May 2024 08:56:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmNJbTStKMRch4ZG5GjRiwdwF/P2dKVC6srdWD4BXBrufGuKOlkYiP45ksprATklWp9JuzjbuBTj54Lpr/4YSYGmjhp2bA+5idh5wXkw== X-Google-Smtp-Source: AGHT+IGb1V+AiDllQSOnosFl0hOisQpkkoISIjlCNXPtbazRkGZhWybVHfpNiwy3Pj3j+TbqveUp X-Received: by 2002:a05:690c:d88:b0:61b:3304:d29d with SMTP id da8-20020a05690c0d8800b0061b3304d29dmr3453220ywb.7.1714578993647; Wed, 01 May 2024 08:56:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714578993; cv=pass; d=google.com; s=arc-20160816; b=b/L0F9NgV0GkSTCdnQABcAapp9WkVyotCsmaAJt1rIrjIbhj4Oqi04mCA020nCABM6 eLBvKYFacl+4Tj3H+y6DYC2j3Png7v8vAnxBL6WbCKxWgSWQ4THBOf6pXUKHz/4eWgel R2tsc5JiOit7jrcJaBQJR2uVBW49M+LkM4Jzqav7h5DG59Mo6x98kiKuK8G9UgF/a264 W0+99HHpZ+qG1mztMY20XU7K1ab5IEtlruO1u4lCkGlMpPxdyom+6qCN7Fk2mLTxrzdf AozapuC0XGgvDgYKeFF744isxadwFdi6JHvQpVY35cwaTCdTjbyXYqdF6bGoNw1ycyvV MGXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0HiwjzC+fghpqU88XdSdTTfAuFlMKfO9IMEXcu+qb2k=; fh=1PwI+mYEir6M6vZFMv/Yd2vtLtotx2307x66b0Wq8QU=; b=fUKwc/nzcJ2EIrbP8L6AemHJuLUZRpuQeUkZ6lzF3KukmRMTyFNEXmtEtKyEjiAypF m32ycFfRU8yRwcIiRZ8rVUqzr9MbyTAGClyOE1T6fKjWNHKf1E/tS6l0CzlWKIBJQ1ww cCMXmGRExB7bWTrULHUNLuqx33ri44hkWRpN2FnWBGv35hP5V2xVwSfjNKlyqW0lXcGM zAaRh0Py91HBrl3uhFfBWPaW7kDQIO7U1+ZyQmS2Xl/3Onk0qfvHugtW3s4RQ0zQeOdb S/2bUp3E2ip09qqx8OmGIZRZluRObaTgbjRHKfGvu+DBfBGxW0Dsd7KjuKYfYA++TJbD +pcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CzjFCQLp; 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-165519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165519-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. [147.75.199.223]) by mx.google.com with ESMTPS id bp35-20020a05622a1ba300b0043b0007c5f1si6026728qtb.1.2024.05.01.08.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CzjFCQLp; 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-165519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165519-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 5BDD31C211C2 for ; Wed, 1 May 2024 15:56:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5641612FB28; Wed, 1 May 2024 15:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CzjFCQLp" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 A4FB64F898; Wed, 1 May 2024 15:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714578984; cv=none; b=pzCLTIfiAcmk6ncC6kA3yp2jomK73Acfm1CNO4DFPQA62DyKwhKOMr6vin2VU1l2K1s82KXvOgBPUM0PrUmpoFcWC/6lHuHqHknNQzN1hAsgQ+4eMHkkMH7Z4lghs85OgnaNNRoC/ZoZEU+la5fvDhDFnr7LsO699bdHcOTW3Vs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714578984; c=relaxed/simple; bh=Ul+Jpm9d6lTEfAqkG8TmFAbQb3enioJbvf95sNAE7uI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=earuoNLHONCfe+cGTmd3sCAkKS0RtPDA/61Nmf2Gi0mxLptzA6GvFxpC/LsWqmT2RkhpAXdTlpf+kNVUTItlZ4huPaFCOzz7RA1bt53aNZvRBqM8uXm/ttd/2H5kH/g0NbwgshiGQbUy8wYm/DPSOIeFuORhPqoBEtoTcVzfR80= 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=CzjFCQLp; arc=none smtp.client-ip=192.198.163.7 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=1714578982; x=1746114982; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Ul+Jpm9d6lTEfAqkG8TmFAbQb3enioJbvf95sNAE7uI=; b=CzjFCQLpLwupMzj5xygPoiVPYh1bSkw8WUs1ba/+nDWTzFihRb92ylBs fwhKpyEwU02mJj5WgcFuRYhkOM3slVBZBvbDkf76VLZLFKkkG1HcNeKnB pbtazssEBmVkxYz76J2URZI7OViP17I9uN2FzzRwU9Pr/mzu2vVP+b3n5 sQ1MDzwuIfJB3037q1xyrlzX+ygtBHACo+C9guZU5XJyUAYmVO2THVYux wMPiX8UsHoJQ4MLoQYAojMHeWNAWv1204ajH+IsAxqnzVWLJr9urv/BVT KHOW3QF8jZExuOvSca+JmOLr39qUb45hYlShHcz75SCDtaAv/7OvCn/wk g==; X-CSE-ConnectionGUID: urGOcVmJSWSAmmN2HnO3zg== X-CSE-MsgGUID: DqWBf76QRQ2YvtT7Vw49nQ== X-IronPort-AV: E=McAfee;i="6600,9927,11061"; a="35700423" X-IronPort-AV: E=Sophos;i="6.07,245,1708416000"; d="scan'208";a="35700423" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2024 08:56:21 -0700 X-CSE-ConnectionGUID: MxDtOalKSem0hZXTLSBVEA== X-CSE-MsgGUID: SnI2oLpSQtCt6AEYlAPvEA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,245,1708416000"; d="scan'208";a="57709782" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2024 08:56:22 -0700 Date: Wed, 1 May 2024 08:56:20 -0700 From: Isaku Yamahata To: Reinette Chatre Cc: Isaku Yamahata , Chao Gao , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH v19 101/130] KVM: TDX: handle ept violation/misconfig exit Message-ID: <20240501155620.GA13783@ls.amr.corp.intel.com> References: <20240403184216.GJ2444378@ls.amr.corp.intel.com> <43cbaf90-7af3-4742-97b7-2ea587b16174@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <43cbaf90-7af3-4742-97b7-2ea587b16174@intel.com> On Tue, Apr 30, 2024 at 01:47:07PM -0700, Reinette Chatre wrote: > Hi Isaku, > > On 4/3/2024 11:42 AM, Isaku Yamahata wrote: > > On Mon, Apr 01, 2024 at 12:10:58PM +0800, > > Chao Gao wrote: > > > >>> +static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) > >>> +{ > >>> + unsigned long exit_qual; > >>> + > >>> + if (kvm_is_private_gpa(vcpu->kvm, tdexit_gpa(vcpu))) { > >>> + /* > >>> + * Always treat SEPT violations as write faults. Ignore the > >>> + * EXIT_QUALIFICATION reported by TDX-SEAM for SEPT violations. > >>> + * TD private pages are always RWX in the SEPT tables, > >>> + * i.e. they're always mapped writable. Just as importantly, > >>> + * treating SEPT violations as write faults is necessary to > >>> + * avoid COW allocations, which will cause TDAUGPAGE failures > >>> + * due to aliasing a single HPA to multiple GPAs. > >>> + */ > >>> +#define TDX_SEPT_VIOLATION_EXIT_QUAL EPT_VIOLATION_ACC_WRITE > >>> + exit_qual = TDX_SEPT_VIOLATION_EXIT_QUAL; > >>> + } else { > >>> + exit_qual = tdexit_exit_qual(vcpu); > >>> + if (exit_qual & EPT_VIOLATION_ACC_INSTR) { > >> > >> Unless the CPU has a bug, instruction fetch in TD from shared memory causes a > >> #PF. I think you can add a comment for this. > > > > Yes. > > > > > >> Maybe KVM_BUG_ON() is more appropriate as it signifies a potential bug. > > > > Bug of what component? CPU. If so, I think KVM_EXIT_INTERNAL_ERROR + > > KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON is more appropriate. > > > > Is below what you have in mind? Yes. data[0] should be the raw value of exit reason if possible. data[2] should be exit_qual. Hmm, I don't find document on data[] for KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON. Qemu doesn't assumt ndata = 2. Just report all data within ndata. > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > index 499c6cd9633f..bd30b4c4d710 100644 > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -1305,11 +1305,18 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu) > } else { > exit_qual = tdexit_exit_qual(vcpu); > if (exit_qual & EPT_VIOLATION_ACC_INSTR) { > + /* > + * Instruction fetch in TD from shared memory > + * causes a #PF. > + */ > pr_warn("kvm: TDX instr fetch to shared GPA = 0x%lx @ RIP = 0x%lx\n", > tdexit_gpa(vcpu), kvm_rip_read(vcpu)); > - vcpu->run->exit_reason = KVM_EXIT_EXCEPTION; > - vcpu->run->ex.exception = PF_VECTOR; > - vcpu->run->ex.error_code = exit_qual; > + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; > + vcpu->run->internal.suberror = > + KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON; > + vcpu->run->internal.ndata = 2; > + vcpu->run->internal.data[0] = EXIT_REASON_EPT_VIOLATION; > + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu; > return 0; > } > } > > Thank you > > Reinette > > > -- Isaku Yamahata