Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp449677lqc; Fri, 8 Mar 2024 02:11:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWuXud/htfvGsLs3m/mh/8ezA3cp/RUg3lvklzpmi1RN7kGYRXzC304iDSaCB/hHR9DZ/9RsPjHRgA5mUdQuqzAzPTTBdK9mey4GIaqRA== X-Google-Smtp-Source: AGHT+IFnyRedA08v82pUNdRwHsV+JlRFx3ASFYLeXu3BAaTVpwTXNbWHLQhv6dsO+ZqfWx86OPPg X-Received: by 2002:a17:906:ca92:b0:a45:c8fe:395c with SMTP id js18-20020a170906ca9200b00a45c8fe395cmr3039808ejb.76.1709892708811; Fri, 08 Mar 2024 02:11:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709892708; cv=pass; d=google.com; s=arc-20160816; b=Fzg76NrlXrpEN3ReyYwCj6biM74hnJWeyp70tUs0hO1GTUSRBObt72oX9kmHw/sWwr xjStc2hdCllapnTbipixWgi3f9ojxiyAMe5sf5gpHUnsXN2q9zp9o1q9xT049licZ+Vd yMyBwjLRa1nxMlMWXn9+34Jut5w2p9QQ9mMt6UZ2pT+dZ9o9Okgo7detFFT5vA8XmU6d loTTedlJ1uGQwnQ45JA3ZOJ0EVEvUZi4KJumTfKLM08TLPA/Jd35xys1/mSU8M96fDrV nWqvLSiGQkP3LKvDp2tO/ODXTghcVsxAFdM2fF6K/hzzd1y4dQSvZgB9Ph6JOZM4wfcO PbSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=Tuw73pvGy3jgqrzb2ZyqaXGeQ72V7oHaRGQogF694Qg=; fh=L/tkX2cOqHKwWqIWddzRExEvwgd471IJL29QYab3GZo=; b=zWo/4e32ieDU15b8bfCNxbDOFoJCYaeAlrio14tXgAb4+CPgLu/urLzfO36DGqL21S dayTm0aAZYx4AyGy8PZQY5LTr6IOpsfpDRfAdmKUCoqAV4ceZImekwB/TgVKtNU9IpOX wwt2h6O9pwuBOprjJBDJM4mO/V1Dw26AjstPaOJnpOraATVU8BY05cD+PNk8PihGEeY7 tpfZ5g+dOsDO/ieRAvJ6jblvLX5OvRlIz+nPN5PCs7jtpbLSbgh5NAOobYO6DbLRBKXP 2Wf1Ljn5nK7KA0NNT5y7VXi43VLO7RoITbMMf4HP1MQ3gBTV8+1/bk4R46PKeeCZlTP9 Q+NA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QiaBxAH8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-96599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96599-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id le3-20020a170907170300b00a43b0e7d8cbsi7620487ejc.584.2024.03.08.02.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 02:11:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QiaBxAH8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-96599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96599-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0D3B31F238D2 for ; Fri, 8 Mar 2024 07:46:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C6334F881; Fri, 8 Mar 2024 07:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QiaBxAH8" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 885654EB2F; Fri, 8 Mar 2024 07:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709883972; cv=none; b=Qs3hdVZ1WTs418knTQ6Z2q8DcItVZkDbjbqDh0LJdiPcoHJh+DUKJOZl4cFfnHqz4jevDrpms5oOhly/aLuYeVq0ezBRzYnyNlGFz/nYdTDxLfPbWv7S+tjkyPOeYZA/1F2HEan60Fv5fE9p11tmq8YWAaK7ygWN2SG57WHLzQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709883972; c=relaxed/simple; bh=SU/y7eEP7nRNmSd87woC458+unvPZtN0wfjyjyZJNHM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=r08WJbuTTTtGhggDHTDTg5hnAHD9HegJ+8kV8ERzdyLOym8dgfVfAqg9aqV4Esu0O1rfAOlyFu6AC9JnhbFHAEQyFf6JxsFmPU9k/6VwzBH/LV3HEjfeN6x7nWaJeiul/x3Xwsq9oynYxBgx1HbIap5+mPisyhLr0zKad7opywc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QiaBxAH8; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709883971; x=1741419971; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=SU/y7eEP7nRNmSd87woC458+unvPZtN0wfjyjyZJNHM=; b=QiaBxAH8pyk1cMUOdLc8WBHy1WIL33ZPg4CvK84WBQpWGuhnk/nRU4sZ KkfvMiq+yPOH2X/4wdW3Si3GE7ACMBYJ3ZzcKdVTYn24fowxQrmnZth0T dHVDoflmH6KApRTGboaRTJkquzzIoLZxae/F4zjWVEO13xJ9/Sp3EZ9qY lTved9XeJmkZzl4iebZ7NAJPEaZy15YRqdTPArH10qi697OsUdrGXnU1t 5F0wZ72yrRvj4Ouvt7sApIoE0pzBQqv31JDa710tCSQB7YUsilTF2YMlE K95mRgivmnm+bRNtFvad1QUFD2xEz9X/ZhLv6vWCtcPOW9vK5ISGdh9G8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,11006"; a="4474766" X-IronPort-AV: E=Sophos;i="6.07,108,1708416000"; d="scan'208";a="4474766" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2024 23:46:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,108,1708416000"; d="scan'208";a="14968970" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.124.242.47]) ([10.124.242.47]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2024 23:46:06 -0800 Message-ID: <5af738d6-626d-49d5-9bf9-e2140ac50155@linux.intel.com> Date: Fri, 8 Mar 2024 15:46:04 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 003/130] x86/virt/tdx: Unbind global metadata read with 'struct tdx_tdmr_sysinfo' To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, "Kirill A . Shutemov" References: <96c21cc1d283cf59ecba003cd5a19bfbce83675d.1708933498.git.isaku.yamahata@intel.com> From: Binbin Wu In-Reply-To: <96c21cc1d283cf59ecba003cd5a19bfbce83675d.1708933498.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/26/2024 4:25 PM, isaku.yamahata@intel.com wrote: > From: Kai Huang > > For now the kernel only reads TDMR related global metadata fields for > module initialization, and the metadata read code only works with the > 'struct tdx_tdmr_sysinfo'. > > KVM will need to read a bunch of non-TDMR related metadata to create and > run TDX guests. It's essential to provide a generic metadata read > infrastructure which is not bound to any specific structure. > > To start providing such infrastructure, unbound the metadata read with > the 'struct tdx_tdmr_sysinfo'. > > Signed-off-by: Kai Huang > Reviewed-by: Kirill A. Shutemov > Signed-off-by: Isaku Yamahata Reviewed-by: Binbin Wu > --- > arch/x86/virt/vmx/tdx/tdx.c | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c > index cdcb3332bc5d..eb208da4ff63 100644 > --- a/arch/x86/virt/vmx/tdx/tdx.c > +++ b/arch/x86/virt/vmx/tdx/tdx.c > @@ -273,9 +273,9 @@ static int read_sys_metadata_field(u64 field_id, u64 *data) > > static int read_sys_metadata_field16(u64 field_id, > int offset, > - struct tdx_tdmr_sysinfo *ts) > + void *stbuf) > { > - u16 *ts_member = ((void *)ts) + offset; > + u16 *st_member = stbuf + offset; > u64 tmp; > int ret; > > @@ -287,7 +287,7 @@ static int read_sys_metadata_field16(u64 field_id, > if (ret) > return ret; > > - *ts_member = tmp; > + *st_member = tmp; > > return 0; > } > @@ -297,19 +297,22 @@ struct field_mapping { > int offset; > }; > > -#define TD_SYSINFO_MAP(_field_id, _member) \ > - { .field_id = MD_FIELD_ID_##_field_id, \ > - .offset = offsetof(struct tdx_tdmr_sysinfo, _member) } > +#define TD_SYSINFO_MAP(_field_id, _struct, _member) \ > + { .field_id = MD_FIELD_ID_##_field_id, \ > + .offset = offsetof(_struct, _member) } > + > +#define TD_SYSINFO_MAP_TDMR_INFO(_field_id, _member) \ > + TD_SYSINFO_MAP(_field_id, struct tdx_tdmr_sysinfo, _member) > > static int get_tdx_tdmr_sysinfo(struct tdx_tdmr_sysinfo *tdmr_sysinfo) > { > /* Map TD_SYSINFO fields into 'struct tdx_tdmr_sysinfo': */ > const struct field_mapping fields[] = { > - TD_SYSINFO_MAP(MAX_TDMRS, max_tdmrs), > - TD_SYSINFO_MAP(MAX_RESERVED_PER_TDMR, max_reserved_per_tdmr), > - TD_SYSINFO_MAP(PAMT_4K_ENTRY_SIZE, pamt_entry_size[TDX_PS_4K]), > - TD_SYSINFO_MAP(PAMT_2M_ENTRY_SIZE, pamt_entry_size[TDX_PS_2M]), > - TD_SYSINFO_MAP(PAMT_1G_ENTRY_SIZE, pamt_entry_size[TDX_PS_1G]), > + TD_SYSINFO_MAP_TDMR_INFO(MAX_TDMRS, max_tdmrs), > + TD_SYSINFO_MAP_TDMR_INFO(MAX_RESERVED_PER_TDMR, max_reserved_per_tdmr), > + TD_SYSINFO_MAP_TDMR_INFO(PAMT_4K_ENTRY_SIZE, pamt_entry_size[TDX_PS_4K]), > + TD_SYSINFO_MAP_TDMR_INFO(PAMT_2M_ENTRY_SIZE, pamt_entry_size[TDX_PS_2M]), > + TD_SYSINFO_MAP_TDMR_INFO(PAMT_1G_ENTRY_SIZE, pamt_entry_size[TDX_PS_1G]), > }; > int ret; > int i;