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 B2F40C4332F for ; Wed, 30 Nov 2022 15:13:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 211446B0072; Wed, 30 Nov 2022 10:13:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C1F36B0073; Wed, 30 Nov 2022 10:13:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 089AE6B0074; Wed, 30 Nov 2022 10:13:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EBA296B0072 for ; Wed, 30 Nov 2022 10:13:26 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B6F1A1A1120 for ; Wed, 30 Nov 2022 15:13:26 +0000 (UTC) X-FDA: 80190452412.21.388F345 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf05.hostedemail.com (Postfix) with ESMTP id 4A02C10000B for ; Wed, 30 Nov 2022 15:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669821205; x=1701357205; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=t0g+VAX2SuLcI7520dAKthU0OO4VL8H7Rn6/w+sOkno=; b=KYRksTK+8o98Wt7dDssjEmGEHYSLhGejJ2f2TVpyVp7P6L24UWI9eLEk cH1umJOXwrk0VKrvWijuNVWtyyzE7kjeuABW7X1y3KmH8XHSb6ZnEJw+c GLTVB2PUw8XwpSFvnSHoU0N4klEKgt4/nXcoVEdDHm2HQ9dD8ExAVFpBO 2vZN/PNPuamLNj/NT2EZpGBhZUFsglMvzgbPdSEkY1MCQfhaK1l7BzarS 8hXWv+JGFbfdsH+wZVIMyVvt8ymH4JLJAaUkJOmoAWAr0dNSjmCXw9ef6 /LwafQX6JHi62NnT+GNJW5zuoLH7Z73wI/hFrrMx5CSd09+o7xWOAUAT2 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="377578167" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="377578167" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 07:13:22 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="712841768" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="712841768" Received: from avintux-mobl1.amr.corp.intel.com (HELO [10.212.242.146]) ([10.212.242.146]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 07:13:19 -0800 Message-ID: <6b0980fc-74e7-3be5-c4a3-2583d6c26137@intel.com> Date: Wed, 30 Nov 2022 07:13:18 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v7 17/20] x86/virt/tdx: Configure global KeyID on all packages Content-Language: en-US To: "Huang, Kai" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "binbin.wu@linux.intel.com" Cc: "Luck, Tony" , "bagasdotme@gmail.com" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "kirill.shutemov@linux.intel.com" , "Christopherson,, Sean" , "Chatre, Reinette" , "pbonzini@redhat.com" , "linux-mm@kvack.org" , "Yamahata, Isaku" , "peterz@infradead.org" , "Shahar, Sagi" , "imammedo@redhat.com" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" References: <8d8285cc5efa6302cf42a3fe2c9153d1a9dbcdac.1668988357.git.kai.huang@intel.com> <3d19683cdc13b7a3884f1e9e75743e922d4630f3.camel@intel.com> From: Dave Hansen In-Reply-To: <3d19683cdc13b7a3884f1e9e75743e922d4630f3.camel@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=KYRksTK+; spf=pass (imf05.hostedemail.com: domain of dave.hansen@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669821206; a=rsa-sha256; cv=none; b=fe6Uqj1G/7W5uQC5mjySayeZpqz+2vEqGpxlmyG7W2FiBKMVbylcXWkY/UXM/EsvRVePSv VfBIJafx+MCSF6WP7zaUDTHOc5x38A4aeL9oBnYHW6PojYg4UzNtYFUyPHWWJQfPgJqwTs 6WVXzTUENW9PNYRoTzmIlGR2BcFJc6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669821206; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=17YPLQhuXZi4TQjsNSz3lzh4/Eeozts4q4bNdm1iKq4=; b=pOfHl+fHcaEUZzONt1GjT8EwtQpvmSYtnjYEEfJsDf4YG86vGQ9/2HSNWNMtjCIFhFpxgr t+NCewZ0RMwgLQ01U4YcxqwlyWyzPnn1BF9ym/RVGTVwQnIE7atatxbPaAuRCUEUdFypne BK4kW0iy2N8Ccez0JKcPeM4OW+tWSA4= X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4A02C10000B Authentication-Results: imf05.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=KYRksTK+; spf=pass (imf05.hostedemail.com: domain of dave.hansen@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: q5tg8hdoe95sntqai45e5nom4jac9pr4 X-HE-Tag: 1669821205-40938 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 11/30/22 00:34, Huang, Kai wrote: > On Wed, 2022-11-30 at 11:35 +0800, Binbin Wu wrote: >> On 11/21/2022 8:26 AM, Kai Huang wrote: >>> After the array of TDMRs and the global KeyID are configured to the TDX >>> module, use TDH.SYS.KEY.CONFIG to configure the key of the global KeyID >>> on all packages. >>> >>> TDH.SYS.KEY.CONFIG must be done on one (any) cpu for each package. And >>> it cannot run concurrently on different CPUs. Implement a helper to >>> run SEAMCALL on one cpu for each package one by one, and use it to >>> configure the global KeyID on all packages. >>> >>> Intel hardware doesn't guarantee cache coherency across different >>> KeyIDs. The kernel needs to flush PAMT's dirty cachelines (associated >>> with KeyID 0) before the TDX module uses the global KeyID to access the >>> PAMT. 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. >>> >>> Note if any TDH.SYS.KEY.CONFIG fails, the TDX module may already have >>> used the global KeyID to write any PAMT. Therefore, need to use WBINVD >>> to flush cache before freeing the PAMTs back to the kernel. Note using >>> MOVDIR64B (which changes the page's associated KeyID from the old TDX >>> private KeyID back to KeyID 0, which is used by the kernel) >> >> It seems not accurate to say MOVDIR64B changes the page's associated KeyID. >> It just uses the current KeyID for memory operations. > > The "write" to the memory changes the page's associated KeyID to the KeyID that > does the "write". A more accurate expression perhaps should be MOVDIR64B + > MFENSE, but I think it doesn't matter in changelog. Just delete it from the changelog. It's a distraction. I'm not even sure it's *necessary* to do any memory content conversion after the TDX module has written gunk. There won't be any integrity issues because integrity errors don't do anything for KeyID-0 (no #MC). I _think_ the reads of the page using KeyID-0 will see abort page semantics. That's *FINE*.