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 EB99CC433FE for ; Wed, 23 Nov 2022 23:57:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AE226B0071; Wed, 23 Nov 2022 18:57:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45C2C6B0072; Wed, 23 Nov 2022 18:57:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3238C6B0074; Wed, 23 Nov 2022 18:57:02 -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 1F8416B0071 for ; Wed, 23 Nov 2022 18:57:02 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F0DC4A05C8 for ; Wed, 23 Nov 2022 23:57:01 +0000 (UTC) X-FDA: 80166370242.13.8CA7275 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf01.hostedemail.com (Postfix) with ESMTP id 96C3740002 for ; Wed, 23 Nov 2022 23:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669247818; x=1700783818; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=CFET33j4BltTpLTUFtSwfx+NssCIekeUgbWNJ9vumtw=; b=jSauMQ0WSHpDjzvS1vN9S6FeKwWRDbr8R8zmFUgajjoOY6vkMLq3LOxr 6n8rr6jodcK6PM1/83nsNtpevOL4H7s1I3nSC6iL5qkvJ+WykqZDHLuCG a1dnjnHgfuk7osggDvMIbYTocWYZHReNHuyXpYZlQE2FkPrMVxkBz/cJZ lK1iko5ss3N9QY9MtDID6CAWU5V1WXrgw2rDPIXmvbitXwrinkInTjsU7 hKdWhERoV4xio1Oev1ikgbicNa63qi6BIPdupxEPH/wS+GWd6ITy5+BqF f9ri++qbKXew+bHH62Y9LggizTRp7ihPIZ7MAbBRLMzv6kDCvdEBa4e2I w==; X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="294567304" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="294567304" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2022 15:56:57 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10540"; a="747991633" X-IronPort-AV: E=Sophos;i="5.96,187,1665471600"; d="scan'208";a="747991633" Received: from vcbudden-mobl3.amr.corp.intel.com (HELO [10.212.129.67]) ([10.212.129.67]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2022 15:56:55 -0800 Message-ID: <301184ce-05e5-871c-7a6c-4298a0cbd1ae@intel.com> Date: Wed, 23 Nov 2022 15:56:54 -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 16/20] x86/virt/tdx: Configure TDX module with TDMRs and global KeyID Content-Language: en-US To: Kai Huang , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: linux-mm@kvack.org, seanjc@google.com, pbonzini@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, peterz@infradead.org, 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 References: <344234642a5eb9dc1aa34410f641f596ec428ea5.1668988357.git.kai.huang@intel.com> From: Dave Hansen In-Reply-To: <344234642a5eb9dc1aa34410f641f596ec428ea5.1668988357.git.kai.huang@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669247819; a=rsa-sha256; cv=none; b=etPn0D+S6lKpjY83sVH/8/oFJAzO1kztQpQ+hhxhsnBObOU0BgjMmYXcSXWs+SZSAxLJr9 sh67W2Z4siPOUI2C/WIuvd2yR7E6+iUyenVPBDpTCFZ/SP4gfOMjCF993SvfElkIJ8tRLa rtczVFfvO+r6BPxAFXIt1lZHhEAoIAY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jSauMQ0W; spf=pass (imf01.hostedemail.com: domain of dave.hansen@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669247819; 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=O38WN11zx5SbVhwmIfy21OW0/zzAzOK3eG+Mi0wfqKI=; b=MjdOA4oAF2VuvxHdGOll+ivL5MzUduYyG9k/Co+MGD635ziM7hakmcxnq7D6pzQhmB6mj0 SEE5zlhdUymzLcUZEfUMiiZ9VauwKjJRDd0Cc/MTSgV/twvvGwtMRS25nIpPbUZPHkgRGY QoxklX0FsB60iNMD7OCOamPKereHd/0= X-Stat-Signature: tq7fzbnfj43p7717q4o1xfz8n6hchh8h X-Rspamd-Queue-Id: 96C3740002 X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=jSauMQ0W; spf=pass (imf01.hostedemail.com: domain of dave.hansen@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam02 X-HE-Tag: 1669247818-670067 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/20/22 16:26, Kai Huang wrote: > After the TDX-usable memory regions are constructed in an array of TDMRs > and the global KeyID is reserved, configure them to the TDX module using > TDH.SYS.CONFIG SEAMCALL. TDH.SYS.CONFIG can only be called once and can > be done on any logical cpu. > > Reviewed-by: Isaku Yamahata > Signed-off-by: Kai Huang > --- > arch/x86/virt/vmx/tdx/tdx.c | 37 +++++++++++++++++++++++++++++++++++++ > arch/x86/virt/vmx/tdx/tdx.h | 2 ++ > 2 files changed, 39 insertions(+) > > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c > index e2cbeeb7f0dc..3a032930e58a 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.c > +++ b/arch/x86/virt/vmx/tdx/tdx.c > @@ -979,6 +979,37 @@ static int construct_tdmrs(struct tdmr_info *tdmr_array, int *tdmr_num) > return ret; > } > > +static int config_tdx_module(struct tdmr_info *tdmr_array, int tdmr_num, > + u64 global_keyid) > +{ > + u64 *tdmr_pa_array; > + int i, array_sz; > + u64 ret; > + > + /* > + * TDMR_INFO entries are configured to the TDX module via an > + * array of the physical address of each TDMR_INFO. TDX module > + * requires the array itself to be 512-byte aligned. Round up > + * the array size to 512-byte aligned so the buffer allocated > + * by kzalloc() will meet the alignment requirement. > + */ Aagh. Return of (a different) 512-byte aligned structure. > + array_sz = ALIGN(tdmr_num * sizeof(u64), TDMR_INFO_PA_ARRAY_ALIGNMENT); > + tdmr_pa_array = kzalloc(array_sz, GFP_KERNEL); Just to be clear, all that chatter about alignment is because the *START* of the array has to be aligned. Right? I see alignment for 'array_sz', but that's not the start of the array. tdmr_pa_array is the start of the array. Where is *THAT* aligned? How does rounding up the size make kzalloc() magically know how to align the *START* of the allocation? Because I'm actually questioning my own sanity at this point, I went and double-checked the docs (Documentation/core-api/memory-allocation.rst): > The address of a chunk allocated with `kmalloc` is aligned to at least > ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of two, the > alignment is also guaranteed to be at least the respective size. Hint #1: ARCH_KMALLOC_MINALIGN is way less than 512. Hint #2: tdmr_num is not guaranteed to be a power of two. Hint #3: Comments don't actually affect the allocation