From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by mx.groups.io with SMTP id smtpd.web12.139.1652739741822941017 for ; Mon, 16 May 2022 15:22:22 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@canonical.com header.s=20210705 header.b=o2dfjQqp; spf=pass (domain: canonical.com, ip: 185.125.188.122, mailfrom: dann.frazier@canonical.com) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id A6E083F5FB for ; Mon, 16 May 2022 22:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1652739738; bh=wfXi9KZkGNHazZjBiqYtrXEcZlybov2Tpm6GIHOQ7hs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=o2dfjQqp1+9hG9LEK7Pox9BlKhvebK7dsLER7bzumy1+vtLl5XOGuPQK6gDtaCpHD Q6xTeqP3fY3Wuy/QA1UfsA2sPSky/FAVk7r48QFyI/1AGZ1pc3kU3tvLPnDRcIn3R+ Khmb4l5LvEI4YK2BIfAZtKyv0jUfHi7KyZg8+j4jaV0hpVGXgBmM5TkCTySmA8jmH7 OTI6IHSj5rGksTHiozN1UEipF88ilucTm4Lw4+dW3jYIDfFADk6f/T5LtezMV1ust1 D8f/c8HonUB3JiszDaW+vsXHOAzudwYMwhP1p15wWfVI49ay9IbQ7atV01WmOWGNM3 MDWs4auIDdf5Q== Received: by mail-io1-f72.google.com with SMTP id k184-20020a6bbac1000000b0065aeedd4ba8so11258769iof.20 for ; Mon, 16 May 2022 15:22:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wfXi9KZkGNHazZjBiqYtrXEcZlybov2Tpm6GIHOQ7hs=; b=RL9GFElWhhQdLwx9wJJO30da3CX8bfxOBih6OPsjqYak0XlQgKYCsu8Q612iE/+pBS uIRtLpy3OX7AsrT2ZYa6HqRCmUQ56vS0dm0k5oeHXMl7WFxsMfSK2zWVbYLAkWE+W1N+ qyi0LdOOx4637PLR7Agaac28wIv0bYOjtpyZnB/SYEKjpci66nnRhTP3lGQ4ANutUwYw qj0fHfUS7kKpUgAlMefUG1klkU14kjfyq1bNmZejV9H0SkWGQCMibWBeSSYAKtBJJznM NzsTt9MjrstdoVQWug5br8izfRt7qzkn3ADbEgf4O+5KGCZCFFrY4SkZbMw+XklvpcHc XoIg== X-Gm-Message-State: AOAM530U/YgSNDA9k3MrzsFZWhD3JXgZdQblmSFwK2FfuxVbVb51spdj 2nNWllW3FuThlBFw3e3kX4Spuk3FCwbpmSyX0uy5LauWKEbBttK3DKpfpW62jaGWphkdifPaJGY sTAlZC1TVGPUH/7Dpv3XXv4Ns4rULJ0o= X-Received: by 2002:a05:6e02:1b81:b0:2cf:1aa3:679b with SMTP id h1-20020a056e021b8100b002cf1aa3679bmr10317399ili.266.1652739736443; Mon, 16 May 2022 15:22:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0ie6X6gORwSYhS0XMTh4nztS9XUn1TYCO8XSxAxV4vWkIwppZxacC0NKYovz+DQUKdPJJeA== X-Received: by 2002:a05:6e02:1b81:b0:2cf:1aa3:679b with SMTP id h1-20020a056e021b8100b002cf1aa3679bmr10317382ili.266.1652739736201; Mon, 16 May 2022 15:22:16 -0700 (PDT) Received: from xps13.dannf (c-73-14-97-161.hsd1.co.comcast.net. [73.14.97.161]) by smtp.gmail.com with ESMTPSA id a21-20020a056638019500b0032e2ff3ab34sm1181719jaq.7.2022.05.16.15.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 15:22:14 -0700 (PDT) Date: Mon, 16 May 2022 16:22:12 -0600 From: "dann frazier" To: devel@edk2.groups.io, min.m.xu@intel.com Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , James Bottomley , James Bottomley , Jiewen Yao , Gerd Hoffmann Subject: Re: [edk2-devel] [PATCH V2 5/6] MdePkg: Probe Cc guest in BaseIoLibIntrinsicSev Message-ID: References: <7af1cd76cb8b4684bbff0de2ab2dafa9b43d5d9f.1649980548.git.min.m.xu@intel.com> MIME-Version: 1.0 In-Reply-To: <7af1cd76cb8b4684bbff0de2ab2dafa9b43d5d9f.1649980548.git.min.m.xu@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Apr 15, 2022 at 08:07:08AM +0800, Min Xu wrote: > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3902 > > Bad IO performance in SEC phase is observed after TDX features was > introduced. (after commit b6b2de884864 - "MdePkg: Support mmio for > Tdx guest in BaseIoLibIntrinsic"). > > This is because IsTdxGuest() will be called in each MMIO operation. > It is trying to cache the result of the probe in the efi data segment. > However, that doesn't work in SEC, because the data segment is read only > (so the write seems to succeed but a read will always return the > original value), leading to us calling TdIsEnabled() check for every > mmio we do, which is causing the slowdown because it's very expensive. > > This patch is to call CcProbe instead of TdIsEnabled in IsTdxGuest. > Null instance of CcProbe always returns CCGuestTypeNonEncrypted. Its > OvmfPkg version returns the guest type in Ovmf work area. Hi! I ran through our tests on stable-202205-rc1, and I'm finding that all of the tests using 2M FD_SIZE & SMM_REQUIRE=TRUE are failing with QEMU hanging w/o output. Equivalent tests w/ 4M FD_SIZE are working fine. I bisected it down to this commit, and also confirmed that reverting this commit on top of 202205-rc1 also avoids the problem. I might have a chance to debug more tomorrow, but for now I just wanted to flag it. -dann > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: James Bottomley > Cc: James Bottomley > Cc: Jiewen Yao > Cc: Gerd Hoffmann > Signed-off-by: Min Xu > --- > .../BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf | 1 + > .../Library/BaseIoLibIntrinsic/IoLibInternalTdx.c | 13 ++----------- > 2 files changed, 3 insertions(+), 11 deletions(-) > > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > index 7fe1c60f046e..e1b8298ac451 100644 > --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf > @@ -55,6 +55,7 @@ > DebugLib > BaseLib > RegisterFilterLib > + CcProbeLib > > [LibraryClasses.X64] > TdxLib > diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c b/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c > index 1e539dbfbbad..8af6fc35c591 100644 > --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c > +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLibInternalTdx.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include "IoLibTdx.h" > > // Size of TDVMCALL Access, including IO and MMIO > @@ -22,9 +23,6 @@ > #define TDVMCALL_ACCESS_READ 0 > #define TDVMCALL_ACCESS_WRITE 1 > > -BOOLEAN mTdxEnabled = FALSE; > -BOOLEAN mTdxProbed = FALSE; > - > /** > Check if it is Tdx guest. > > @@ -38,14 +36,7 @@ IsTdxGuest ( > VOID > ) > { > - if (mTdxProbed) { > - return mTdxEnabled; > - } > - > - mTdxEnabled = TdIsEnabled (); > - mTdxProbed = TRUE; > - > - return mTdxEnabled; > + return CcProbe () == CCGuestTypeIntelTdx; > } > > /**