Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2518254rwb; Wed, 30 Nov 2022 07:34:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4MdMHfvorbQag7NUWA4r5Bm525gn4lLBBr/GO9HRB92wgZzs/O1UFP2qaeqQa/TPcqZEag X-Received: by 2002:a05:6402:1684:b0:46b:1396:e132 with SMTP id a4-20020a056402168400b0046b1396e132mr15768184edv.421.1669822480360; Wed, 30 Nov 2022 07:34:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669822480; cv=none; d=google.com; s=arc-20160816; b=mbofjJtcVbwfss1Mve36JAc2u4QmaD5UIxDec5ZL49yNKv5XqVgWumn+3ObkL/lcNc 91jQ0a2x+2BL/HmUhZhDGYdFHfTB5gKSHXaFT0vKmYrqLJdy4Pab76EqS2HLufE5DkEY 5lOeFJqD89O0mTgUwQYdxRQkRIHhYOZu4UCxT+fraMZuCkl2qad+jaarKjtjXY8pSp4k r0HofGPrgRExFeA+WG+/OrzEj/x+i4P4g5wn9jCplmOTIqOOmvFZ3sdp92iW2ekECatr qf8ra4POZXG9E+VU7L3ltS3/+wTg0D4BzFtRhUfD2KB2wXMtSR3Reml0IMO1wZD35qr+ pk9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=17YPLQhuXZi4TQjsNSz3lzh4/Eeozts4q4bNdm1iKq4=; b=HV3LMV7wcu9UMfvHAhIf/GUE7Bp9fyTwytF+HGU/9UmvZgQ9WGd0YStSdtkihRtoZ5 6nTTSAyZHLDg3YKW8eduS21xHIpKFsd689l/BAvAryy3y3ks6Rp0NNZh/iMRs6M8Z+pq tX/zCISOCnqc0Ok+c1L42BKpkIt9Xz1KWShu6Si1QzvU1s3w15aRECuV61d5LKPquRjY f3Pe/GOQotMnUbA2ooGW5Fc7DO9TCYd9FTQaz9MsASkBcvysAFVZu60PdqETC6+DCIka 5ylHmXekeiFGujxb5uxAgqCJHr9cx+p6ag3eyj0cdwGVR/S+6gmwKglJ+Z5UMM2ZBLA/ MP7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FT9tDUKJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw19-20020a170906479300b007b889a69895si1754602ejc.589.2022.11.30.07.34.19; Wed, 30 Nov 2022 07:34:40 -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=@intel.com header.s=Intel header.b=FT9tDUKJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbiK3PN3 (ORCPT + 84 others); Wed, 30 Nov 2022 10:13:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiK3PNY (ORCPT ); Wed, 30 Nov 2022 10:13:24 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47C52F65F; Wed, 30 Nov 2022 07:13:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669821203; x=1701357203; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=t0g+VAX2SuLcI7520dAKthU0OO4VL8H7Rn6/w+sOkno=; b=FT9tDUKJfiM7NyOmarAFSAjxAF/cOFK9BBgv0Wam+6eU0521qH6eIoSz brYSQiXoVqTnHFNBh/fVTJ4b5kXmeXZCkidmQdhdKotwwLSU0IEF9ZBQr rqVhyo4fKyFZwQoOInl0omAOQnIwAvL3nCMQLk1Vc54OxvJp1InDLwgY+ 2LCv5OSFLj3VG+HjEe2728HV7JxA3DGTCDPUdtoAVZrjwxqOEGUBx9lC9 moEiRwy89HWDBlCyEdVcPpwhFM5fxxSU/NWZltQyVviINfNQsvsakgksC CgiMusfondnydi6sJI8Evm7lELp6asbox+FxLZTozO9idGv8gPjY7AnLh w==; X-IronPort-AV: E=McAfee;i="6500,9779,10547"; a="377578171" X-IronPort-AV: E=Sophos;i="5.96,206,1665471600"; d="scan'208";a="377578171" 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:23 -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 X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 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*.