Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1536639rwb; Thu, 8 Dec 2022 11:56:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf59BML3SWD1/IjuP1G6BrTep6NsT+QQLgQYiB+EiaqXS8ErWh6iIkvEKS1TSwIZoaCX99nI X-Received: by 2002:a17:90b:1881:b0:219:3e66:c0ea with SMTP id mn1-20020a17090b188100b002193e66c0eamr53210860pjb.53.1670529418592; Thu, 08 Dec 2022 11:56:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670529418; cv=none; d=google.com; s=arc-20160816; b=0giKtZXF2EsHPRXi2kbhpX+XSDgIVNApFseP/pzvtZH5wHNDAEOO6Nf+96J8sw6QYM A/O4iQA7k50teIirF8/jsQ4ugaGhEUBAu6+Zf0WWt/4cjXBbZcEndsMn/8nhzxNRBf6E i8L4sPZx3bXKvjMQdzOJ1ocHvugSgsrc1eNZEWiMa1z+MehdbAo2dSEHyN6f6T+t9PDf aj7JYFm0ow/Y5cFRad59SJdrVl6M6j3IYD+FFdLsW3gea5xciF0Len/c7dkqMKjAg10+ DaOX8S2W0y/H8FzAQSYJtZgVtyH2576vgt0Xpcd+EbSNltxO2eb53p292GPkqFmkxg+i GIiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=hn/OnOtk3EASdGn92mWNbIzbnlYcn0q3Kf908b3pElo=; b=gXyB9oKSO83jUvrBAKhfCJAtMNFx55160roOu6QELF1zP3BQ6v3dn+otFl8rUmfl1T 3lX5Wymqqi1eeVjQTkS/I+mX/78rCI3ueRTfFxJptArV3Q+v40dABrTeEzeBY2VAz6iZ oNPY08nSI1PvIC/2Vu1/ykoscrUq3iz5umP7d2asVZnbqYhS93azHErPVA3STxe9Z8PO rm14ROJDrwngdMrwkJpvOseOsIJlL6mYpTdLIZdMVa16j6bGM+RS8urMjsdjTuCDgZry CO+cVwoG0WyEq76ziUGClKPKS+ccH3kFkpFKAbsbcOxwSbU87CZ8+kmYAL4rt1GyMpHe TU9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm3 header.b=k0BfM5Xm; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=qavhLUIr; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a170902cec600b00189d696974fsi13793735plg.522.2022.12.08.11.56.48; Thu, 08 Dec 2022 11:56:58 -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=@shutemov.name header.s=fm3 header.b=k0BfM5Xm; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=qavhLUIr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbiLHTsP (ORCPT + 73 others); Thu, 8 Dec 2022 14:48:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiLHTsM (ORCPT ); Thu, 8 Dec 2022 14:48:12 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0D2389DC; Thu, 8 Dec 2022 11:48:09 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id B2CA05C0069; Thu, 8 Dec 2022 14:48:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 08 Dec 2022 14:48:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1670528886; x=1670615286; bh=hn /OnOtk3EASdGn92mWNbIzbnlYcn0q3Kf908b3pElo=; b=k0BfM5Xmr1BuhCrrQl 03JuMYehLfM6mUUmRIOk0F3ik/ftbG7J2GUi93knfDi9fvkegXdewTDmKbYTdSWq Z81TR41z7Vplq+QyjWiqTbght6/53lIN1U9+9rWEOi5itMVycc3KSTSLPcv/ypvQ ewFRB95lN3Kl8eBFhpv1EHpX+vJE3cbQBMU+Qth9sx9/7PaTgryDartyR25robn3 /UGoitFYqhbTr3iJL36T8juROQBNqds0JvYnngTCj1k2LQ35FLE6Vofk7q8W01u4 H0z5cPE2ycN6YhJtznV7DxpppzSUL8b4I1bcsopa3yqqHvj18Ig9SVdaxNds+Qwo uzGA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1670528886; x=1670615286; bh=hn/OnOtk3EASdGn92mWNbIzbnlYc n0q3Kf908b3pElo=; b=qavhLUIrbBjbDvtE/aQE6C82RgilvuZVpyOGz0ip7N2U xn9kgkts8vSnerOddtY/Vj0Yj7+GS5szWg1APvswdRLqbYKa8QJUb57JAsp9A4be Dgv2lEsxeLeMznOlzuv5iSKdibFg5BaaRqsApONfrWOH8cJyveHbF3rMPK0g179b cwyDSgHnqTDq45/RWGbGq2zg+DhONNga83Swg9l9iGY8+pXW/SqijAdtb8UbT/Dq B14MnY6INU1v8EjDImlmKsBTOTND7H2KsfIgdbHc35daZf2ueBeuYKgD6R/C1Wh2 0ic2kFp+LI/HTgIjhqS47onD67Y5e4k4K6hSUTbGgA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddtgddufeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdttddttddtvdenucfhrhhomhepfdfmihhr ihhllhcutedrucfuhhhuthgvmhhovhdfuceokhhirhhilhhlsehshhhuthgvmhhovhdrnh grmhgvqeenucggtffrrghtthgvrhhnpefhieeghfdtfeehtdeftdehgfehuddtvdeuheet tddtheejueekjeegueeivdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehkihhrihhllhesshhhuhhtvghmohhvrdhnrghmvg X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 8 Dec 2022 14:48:05 -0500 (EST) Received: by box.shutemov.name (Postfix, from userid 1000) id 91B70109CB7; Thu, 8 Dec 2022 22:48:00 +0300 (+03) Date: Thu, 8 Dec 2022 22:48:00 +0300 From: "Kirill A. Shutemov" To: Dexuan Cui Cc: ak@linux.intel.com, arnd@arndb.de, bp@alien8.de, brijesh.singh@amd.com, dan.j.williams@intel.com, dave.hansen@linux.intel.com, haiyangz@microsoft.com, hpa@zytor.com, jane.chu@oracle.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, wei.liu@kernel.org, x86@kernel.org, mikelley@microsoft.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] x86/tdx: Retry TDVMCALL_MAP_GPA() when needed Message-ID: <20221208194800.n27ak4xj6pmyny46@box.shutemov.name> References: <20221207003325.21503-1-decui@microsoft.com> <20221207003325.21503-2-decui@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221207003325.21503-2-decui@microsoft.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 On Tue, Dec 06, 2022 at 04:33:20PM -0800, Dexuan Cui wrote: > GHCI spec for TDX 1.0 says that the MapGPA call may fail with the R10 > error code = TDG.VP.VMCALL_RETRY (1), and the guest must retry this > operation for the pages in the region starting at the GPA specified > in R11. > > When a TDX guest runs on Hyper-V, Hyper-V returns the retry error > when hyperv_init() -> swiotlb_update_mem_attributes() -> > set_memory_decrypted() decrypts up to 1GB of swiotlb bounce buffers. > > Signed-off-by: Dexuan Cui > --- > > Changes in v2: > Used __tdx_hypercall() directly in tdx_map_gpa(). > Added a max_retry_cnt of 1000. > Renamed a few variables, e.g., r11 -> map_fail_paddr. > > arch/x86/coco/tdx/tdx.c | 64 +++++++++++++++++++++++++++++++++-------- > 1 file changed, 52 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c > index 3fee96931ff5..cdeda698d308 100644 > --- a/arch/x86/coco/tdx/tdx.c > +++ b/arch/x86/coco/tdx/tdx.c > @@ -20,6 +20,8 @@ > /* TDX hypercall Leaf IDs */ > #define TDVMCALL_MAP_GPA 0x10001 > > +#define TDVMCALL_STATUS_RETRY 1 > + > /* MMIO direction */ > #define EPT_READ 0 > #define EPT_WRITE 1 > @@ -692,14 +694,15 @@ static bool try_accept_one(phys_addr_t *start, unsigned long len, > } > > /* > - * Inform the VMM of the guest's intent for this physical page: shared with > - * the VMM or private to the guest. The VMM is expected to change its mapping > - * of the page in response. > + * Notify the VMM about page mapping conversion. More info about ABI > + * can be found in TDX Guest-Host-Communication Interface (GHCI), > + * section "TDG.VP.VMCALL". > */ > -static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc) > +static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) > { > - phys_addr_t start = __pa(vaddr); > - phys_addr_t end = __pa(vaddr + numpages * PAGE_SIZE); > + int max_retry_cnt = 1000, retry_cnt = 0; Hm. max_retry_cnt looks too high to me. I expected to see 3 or something. Any justification for it to be *that* high? -- Kiryl Shutsemau / Kirill A. Shutemov