From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25347C7EE23 for ; Thu, 8 Jun 2023 23:54:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB0736B0075; Thu, 8 Jun 2023 19:54:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3A4B6B0078; Thu, 8 Jun 2023 19:54:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DB1E8E0001; Thu, 8 Jun 2023 19:54:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8BEC46B0075 for ; Thu, 8 Jun 2023 19:54:04 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52FFAC02C8 for ; Thu, 8 Jun 2023 23:54:04 +0000 (UTC) X-FDA: 80881236408.06.23D3071 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf27.hostedemail.com (Postfix) with ESMTP id 22C8340018 for ; Thu, 8 Jun 2023 23:54:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=afmgkJP+; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf27.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686268442; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MuPKw4gCTO6abkJLk8mAjcNZoBe6JnGa5u5OVMI+Vis=; b=delCzf2WxY+h2doGnHZrnjp+Gr5YLX4EQJVAAVx/y4OKn3lU7m9Cx5Bz3ol0RpTIeE88rx g4pYi/zIC53dhDIUaRgYwNulvBWIpkZjSzt2PD8nE954yecEr6TAsOBdux3VuJ8BTLQ/2q d3e38n4qCoD7KPr7gIn9HptfsxZorvc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=afmgkJP+; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf27.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686268442; a=rsa-sha256; cv=none; b=HXRGwZkek/jIktN3U7UwfYN3vaMl/Vn+L0yQktAIbK6HpZ7iXSkKuEUxRBuybGLCZFAfJH JQ0F53DcA7o5wG6VWMOqblncKAbkeFhDgfuGEhbLYET7ypc0vhe7Yvkq2mvh1mR0k3y+GP G+UiqJtg++aHL7aW+yxdWglq5YimyKw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686268442; x=1717804442; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=FR3CJyjeIQ8jPwCBjuJP9efs0Wq+kfk5E5wSAuTzgxA=; b=afmgkJP+tC9abmGOZJ12E3cjJd55ClC43v5nEJIzEQ6wkO0fw5ezw2mB ECqLvdrPXB+aE+xYoWqM2LiA4RdmAyZ4UmqUQVPh4XEdFN80dzXw92vqg JjOC7e/XeGdh8fMsc2L+x/SCOcL6h4CyV+w512o9S37v7aeYbzD2ZWZs2 8kuioVjatKvFWDxMW+mHNLh4tFCxz6V9fyZZC9dNCU0P89NOXHzVE0a0d AlXG1pCo/c9GHLjJyruStoljVrhn1RIU+hU398zH5oD2oUlhbyIixUESY tDcyplCk4z0V+e1xfM2UsKhdJhgtsoVFLoWKqky6Yx3M4RppO5+ZbgA1W Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="357471092" X-IronPort-AV: E=Sophos;i="6.00,228,1681196400"; d="scan'208";a="357471092" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 16:54:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="956928208" X-IronPort-AV: E=Sophos;i="6.00,228,1681196400"; d="scan'208";a="956928208" Received: from fgorter-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.59.89]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2023 16:53:56 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2B23E104C0F; Fri, 9 Jun 2023 02:53:54 +0300 (+03) Date: Fri, 9 Jun 2023 02:53:54 +0300 From: kirill.shutemov@linux.intel.com To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, dave.hansen@intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v11 15/20] x86/virt/tdx: Configure global KeyID on all packages Message-ID: <20230608235354.aqgsuuhkryhsrls7@box.shutemov.name> References: <30358db4eff961c69783bbd4d9f3e50932a9a759.1685887183.git.kai.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30358db4eff961c69783bbd4d9f3e50932a9a759.1685887183.git.kai.huang@intel.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 22C8340018 X-Stat-Signature: psz7c7du3rjw56dfirdf7q55sb9n5mpc X-Rspam-User: X-HE-Tag: 1686268441-150859 X-HE-Meta: U2FsdGVkX18p9CKlAR4WyYEG8TwELBeLCuxU+pdfWnkTrPNibhzWSpRXjxlfUxy5wCpcY8zDXDovsglFu+7b7nHRk3L1Yp7fr78rUzfnDRCDchbbbcCMEjrFs9mJKBxr1wWxhweJnOBG7v1daaNMStZ6lc4bF+uaaaw9q51EPP3LBfSbw6A+FWHiuVXO8r6BDam/iBLRVxLiLNQdag3+4sBZN50IOD9U1ZhPDh7wMlWKAEjcOAuPz7X+HdN439yALr2GD7LR9sCTyVWPaBjyihirkbLgeRPUIwvIGwGkNq/7BRdc1+qzUopJaPS8et6FA1AG+m2x4CdfU+TdqXR3oAOVLUsvOaOPdZybNKuGo7O2X6+HyTGTrTXBz3ssu4zIAm41RBKIVta/xBbR+QIiGb6io1+pDewfFzmftcepyYEyPnlDDjF5ViuhCSjHlRvTkx47FjZ2uSFJdVueYNMNvZnaU4DQ1a3tZtW0vGNxSflZx3D8mzLbUFkJVmbZT5osfVfnVx2qIHP9VWdMHsctRp1xHPVPjJgZF+fQTlFSuAdAY1QFRZSpph0x7OfwDS1CPoEjgYfvTr9oiYO17o3JuzQCGwawMsxhkblzWPuFJJmyrYZRw5NN0OeQ90lct3Bnt1Y6Xnw1fWUF9UvxBbQLqnP24fOldfKXQqrlvpJxmYBI/9p7CjTTMiHMXjQVES1tR97XcaOftbSau0pTqH3LBFYmbRoO+0lPqLIju3mYYhmdLdYjbIo6C9c9PxlFMmy4+MYE7PfM1J4vO03HN/VoyMPjrrJYfPFYtCSCEQwfNIot8IXxVTsK3gMBfvqds8mN/oRCQmN2JCldLuiKr+xlUTmC1gVNYMsgAd7e7Bply9Uljh0ri+zHnqXpUdMkK09zjTnlXIL7OKvklDzomWavyq4yz47bWO7VF5+QYOvF20v582Rf1oBbG9y8Y1J9FEiZDMN1m5NfehAkjf+Wj1Q 1AlP4Ki5 I3ondgPsYDJxYTG6nzMeOMtCa06UUkk/G1LBzM2QNsz0FdzJ5odflmD7sXsqpjs+aGhBK95yQyhD6lS7ndo8RLUwDvQS8+JGuB/J/13uLsMgr4TiQaKN5wcnIOzROwRy522ieuwW5qUbU9vebl7iDS9bvCyrz60zX0aajeQzSsBIAWE8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jun 05, 2023 at 02:27:28AM +1200, Kai Huang wrote: > After the list of TDMRs and the global KeyID are configured to the TDX > module, the kernel needs to configure the key of the global KeyID on all > packages using TDH.SYS.KEY.CONFIG. > > This SEAMCALL cannot run parallel on different cpus. Loop all online > cpus and use smp_call_on_cpu() to call this SEAMCALL on the first cpu of > each package. > > To keep things simple, this implementation takes no affirmative steps to > online cpus to make sure there's at least one cpu for each package. The > callers (aka. KVM) can ensure success by ensuring that. > > Intel hardware doesn't guarantee cache coherency across different > KeyIDs. The PAMTs are transitioning from being used by the kernel > mapping (KeyId 0) to the TDX module's "global KeyID" mapping. > > This means that the kernel must flush any dirty KeyID-0 PAMT cachelines > before the TDX module uses the global KeyID to access the PAMTs. > Otherwise, if those dirty cachelines were written back, they would > corrupt the TDX module's metadata. Aside: This corruption would be > detected by the memory integrity hardware on the next read of the memory > with the global KeyID. The result would likely be fatal to the system > but would not impact TDX security. > > Following the TDX module specification, flush cache before configuring > the global KeyID on all packages. Given the PAMT size can be large > (~1/256th of system RAM), just use WBINVD on all CPUs to flush. > > If TDH.SYS.KEY.CONFIG fails, the TDX module may already have used the > global KeyID to write the PAMTs. Therefore, use WBINVD to flush cache > before returning the PAMTs back to the kernel. Also convert all PAMTs > back to normal by using MOVDIR64B as suggested by the TDX module spec, > although on the platform without the "partial write machine check" > erratum it's OK to leave PAMTs as is. > > Signed-off-by: Kai Huang > Reviewed-by: Isaku Yamahata Reviewed-by: Kirill A. Shutemov -- Kiryl Shutsemau / Kirill A. Shutemov