Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1171581rbb; Mon, 26 Feb 2024 00:29:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXhODzGvt0oih8dOu8wYBeDr3G+nholQGoPjZX9BNzh64pwzHBAERF7NDGIcddEmIZzWQJIs5UJTqqxlXyv+htoFoz3+t2Rt3udsMtcZQ== X-Google-Smtp-Source: AGHT+IFe56H6hGXTyxK4hoP9YPb6147YL13KuaF0AEU3Fkp9E9VBKGuO9PjwibXtLgm6eyBherq7 X-Received: by 2002:a0c:e184:0:b0:68f:e6db:85c with SMTP id p4-20020a0ce184000000b0068fe6db085cmr7394129qvl.23.1708936189945; Mon, 26 Feb 2024 00:29:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708936189; cv=pass; d=google.com; s=arc-20160816; b=x+TjfVecR9+57Fa9ut6U7ZyHXifkUN2Pp2T0rnkF25Y82KQDPwVWQfFqaC4GG1rDe1 RWDJkWMWq7QV0Nq5rQAVtVCgNYRqdnmTCO3FEmWdAKZ7mWloL6Ceawd0RxOpCGKbRYXB Q9ul2rj6uNyPr7Pv+9bMDNDpePIdh1Bnd6Vto6f3tfGnst3jSNRs+CFuocmvgpmbu/FR bi+Il1UW4PqZfr2SF423yYG9NeiUmHhc9p8hhwXtd21zQ13EF5ubnRzWNRlEguJuBCZr AoHHkiV3aEE8q8ngmvxZ23S6foGFqAujiypcPHNuM50Tr2n+irxF27DtaGd9+Z7j3zFj 4l6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=z1weJRQLbFW/ttOeDm35sqGk0OWKU9ubWhc8yGT1i8E=; fh=wfzf/8eWbe9eyxhcv3ArurOzI8Y6mCaD4zS1Rilq9io=; b=qVOzReKcgFO9hUEaWmoCkAa2nNTLD7tsM4gISND1my3mzUUIzGs1s6WnZJ/0HIp1Ee 7o1iPdEJ1MDTHXo9+gFDVl8PGKMidG3TRwDqOJ2wbKZJ2KVGZdd+HTA4qWsUO7Kic/i+ cPEojRN4U3NGkCyG5sjLWwVYVcydMc1PQts7U4VDAahLs/IOAi5rLxCImpjFTcCw2zzI 2V5GuPJA+dVtEqggkgEZMDz2flyAZBl0obpx58onzS6myZD0R9GpsVfniOwA/IW4kPuU RTNZbLV9DJSzmXyl+9MrtzA/IFBGWlAZvzebekKRC45SdINBrfdNKPKX+DvnjCsETcBB /lQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BYFQ0Z3s; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g8-20020a0562140ac800b0068f5c7d73absi4749167qvi.161.2024.02.26.00.29.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 00:29:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BYFQ0Z3s; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-80765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80765-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B1D201C22BB2 for ; Mon, 26 Feb 2024 08:29:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 056982C869; Mon, 26 Feb 2024 08:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BYFQ0Z3s" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 529801EB5B; Mon, 26 Feb 2024 08:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936060; cv=none; b=tfLTV6l7Pxt3gb9+dWhzIYuniN0f2+V+Sl2fUD8i6j4LQnXU0vmRPxTeK8Rdim88dX3Uku/hG6N801R7ejZmYP27KTpKwxnTGkaQBSaZnOoWAcncq4ZjUrWxwBgQkc3wAKQfz6wsxGr+l+jWvAvf1gE8o1bwtE8aK4VIT3gIGOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936060; c=relaxed/simple; bh=Ipwvsm7XmA6ghvLHLEgf7+RqG0jtiV2UhCk6lJOoMpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QRHUuKBmxinpY3egpJ8uNXmwoe7bWr3RuzCFDN2GHlaHvjrDy4lXm+bnhGrfXXtmj3x/29JgRKt1lgf4p9cv3g0s4mmdnxktwhxelA1C7FbxLY/9EZsKp4MDOCl2GYWqfp/hs8J79wIq8D4bU6mEX5H6dLEF3l1TYaFgeJmxYxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BYFQ0Z3s; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708936058; x=1740472058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ipwvsm7XmA6ghvLHLEgf7+RqG0jtiV2UhCk6lJOoMpU=; b=BYFQ0Z3stVG43PiQHxUs2lAS3NHq02vxRFzADqa1Fk92Sq25HoWKOwIO pTiSqKjwch9jzABzydlFcQMHZPLwslA1bFm3jl/ovKvQfb0yOcKErqtoC 25PEtDECxF0pYdCZQ9OqllCaVuRaFnheEVMGxQJE/HNzKMSjPdvL7AqZ2 j7Ko1gqTWG/HHwgh0qX5Hjjrbt3shxcWkLG0ebhtbDfPdfbcfoehBtkp0 OGOVvO3t39wfMXjg+/xQoqWoZ0kbjHNkQTkHEpStTSHuPSRFXVOXvYiQz 3g5JIPURH0MHinG5kZlFKH+OzDdhsDD4xNEIr7giQc+NZY/epLcsF58zx Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3340702" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3340702" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="7020055" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:27:35 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, 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" Subject: [PATCH v19 003/130] x86/virt/tdx: Unbind global metadata read with 'struct tdx_tdmr_sysinfo' Date: Mon, 26 Feb 2024 00:25:05 -0800 Message-Id: <96c21cc1d283cf59ecba003cd5a19bfbce83675d.1708933498.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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; -- 2.25.1