From patchwork Fri Mar 1 11:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 208788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1007906dyb; Fri, 1 Mar 2024 03:21:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWx71h2kh9jyTDSe/lLvyMLO5UCqu0R8a/deMPE9I0M7cE4EwhRf1Ke8UDfMDXGkNLWHQBxLf34/my7R/fMdFuRWpld6A== X-Google-Smtp-Source: AGHT+IH6CmGJSTqOymMewQS8R09D+/M+94G7xV2Mc/7M16qdUQdJ3px1b6r+b7jbuJK/f0dWixZN X-Received: by 2002:a05:6808:2082:b0:3c1:cb68:1f20 with SMTP id s2-20020a056808208200b003c1cb681f20mr1829345oiw.3.1709292109257; Fri, 01 Mar 2024 03:21:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292109; cv=pass; d=google.com; s=arc-20160816; b=ubndePGOymDxaJyKCL+LAStEHrIhTZGrOh5C5So7VhRuHZR/POFn0C09ZSxsX8cRZo 0ylPy46YIteIUFd0yktXmmLdI5Oi80JaLahrijmf8XsHmJC8qitnVxiCm7iHDho+WpHo A9vXJO+HJWQP7+LKqsArvRWkIhM2CZvihj9IcRu0thsKi7Zc92qbreSkuT5losDxIL1K i1gKZ6UlfDeWY0ctd6IfFsFGWgrVMiPCir+jAlAkJ8J1zO4DR/D87bptxgZePOslnWgR AfIQ56yMMK5ysA/wriVSBX2s/jpTNTtvvq00IUyhIX0tYkaJPoq/fR+CnheJY2huxIGu ew9Q== 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=E4hNpBzDR64zpJa4nUepmr5ddEej7YzhQBmt6IC7ECk=; fh=SNirUdkKHR93c4vQEHw73adUAE5UKXjSGs0zqjyJP7c=; b=rU0xRQo9ua/Ljg9WJ9k2VNiGlT3oOVPgeezYbKndpbO1zqOgU5fdn+mb70+Mj30ckD CiFuM9M3+r9DJX0HUBpPcNPnKpGGpfXZFynnMaXmUTiJ6vspJUdJ0aJsaaW4w1OR8LPF MHne+IooVuV+Mc8xQ7wOIEQr8EHyI4K/E51uqzNACv8BdZyvzcmj81MoXHe+zdLKQurT USBdDoOMRvYRY7tnQp1uwxUsJCLTL1zNwK14wmxt+XVpnPsFhfVW2Dh8TFv1ia9TZokj J3tq+/NAn56u6hTvDVEtnNmfKliSqdksBtFxJjtLGwmqLRz9zfaIpO8hTEWiaKpgNGzK usOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ap+wXX4d; 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-88324-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88324-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h27-20020aa79f5b000000b006e5ad30334dsi1971629pfr.69.2024.03.01.03.21.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:21:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88324-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ap+wXX4d; 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-88324-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88324-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0CE93B22DB7 for ; Fri, 1 Mar 2024 11:21:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0F536D1CE; Fri, 1 Mar 2024 11:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ap+wXX4d" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 219BD6CBF7; Fri, 1 Mar 2024 11:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292059; cv=none; b=T7HXNreFL+hXZnMO4b/Ry0qc1tY0V3HE0NY9uXzLp9lyQGJ+2sIWAFOiYV3iAz4YkXkppenqOAUtdaepGfRH6fIWQWqv0kVfbUUbYJQ56OUlhMMM2NBIK+ddzw+hLImVv9lQUQTcXyH11Qvg/31GDvFm9Ukc5ka09+0k5FPindQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292059; c=relaxed/simple; bh=RvFOMtve6JbPnJm8Y06EMADvK3SIt9TrmBxajx/qPAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aVei3dHE64z9cktfMl3R47V/dyJs8cdjlRhkyJTlOKUv1bGuY4W9UVoVPEMvby95vOKVNMRTS6I9b6BaaPWK/HjAFdVTbvBjrzhDfvG4CChqNmbpiO4tMJ8YyBCmAlikvPtiWGV/ri9eH6bRsmMEztmkPNqSgopIt/Ws9aa8Eb0= 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=ap+wXX4d; arc=none smtp.client-ip=192.198.163.11 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=1709292057; x=1740828057; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RvFOMtve6JbPnJm8Y06EMADvK3SIt9TrmBxajx/qPAA=; b=ap+wXX4dblhEZmOZqQ7QsltO2h6M6LFHj4H/I9xb7ewzpZ8QXDvfztdg lEb16nKG5TUJomJNi7R3tDvvpBvgafZtJdN+rLsCcWy94pcxQs6S3zusJ b1odKNqejbYbTSUcjKI9CbNcOSlmuSQVV8aAJgIssfUbxhBpJ7p6O855w EzDYPwqa5Sxexi2OFWuZSlJ7zybkEnTq0av8DmNtLogDEhcv3RaznugHD 163DYXdvuAsUQat3M3K85AiYjytcHHYT+Rk0hj1T5Zy7irHlBJ2LjCT2R ZtBm0DB5UYQzLorkdSegabqJDUEJXkkfs0s3xYgDs9267JZrFQovQYT6d A==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="14465032" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="14465032" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:20:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="31350675" Received: from rcaudill-mobl3.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.48.180]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:20:53 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, jgross@suse.com, kai.huang@intel.com Subject: [PATCH 1/5] x86/virt/tdx: Rename _offset to _member for TD_SYSINFO_MAP() macro Date: Sat, 2 Mar 2024 00:20:33 +1300 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792322682395003456 X-GMAIL-MSGID: 1792322682395003456 TD_SYSINFO_MAP() macro actually takes the member of the 'struct tdx_tdmr_sysinfo' as the second argument and uses the offsetof() to calculate the offset for that member. Rename the macro argument _offset to _member to reflect this. Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov --- arch/x86/virt/vmx/tdx/tdx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 4d6826a76f78..2aee64d2f27f 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -297,9 +297,9 @@ struct field_mapping { int offset; }; -#define TD_SYSINFO_MAP(_field_id, _offset) \ +#define TD_SYSINFO_MAP(_field_id, _member) \ { .field_id = MD_FIELD_ID_##_field_id, \ - .offset = offsetof(struct tdx_tdmr_sysinfo, _offset) } + .offset = offsetof(struct tdx_tdmr_sysinfo, _member) } /* Map TD_SYSINFO fields into 'struct tdx_tdmr_sysinfo': */ static const struct field_mapping fields[] = { From patchwork Fri Mar 1 11:20:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 208789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1007931dyb; Fri, 1 Mar 2024 03:21:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWCZQ2bAod1iJ/1aQC/wOB+suwTWUaxj/JoGJseAdAszTfVB9d1P7Xxe+OdkxSEPT2cx1zWBQA4pT66aw4FOuS8EqCxug== X-Google-Smtp-Source: AGHT+IEZFeAh6WAE87E59ihjaBgrYMdI6ch58KaGXCoCngEK7sF3WGrP2aSP9hsz34Bw/ubVq0mk X-Received: by 2002:aa7:dcd6:0:b0:565:7bca:eebe with SMTP id w22-20020aa7dcd6000000b005657bcaeebemr1231720edu.13.1709292113890; Fri, 01 Mar 2024 03:21:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292113; cv=pass; d=google.com; s=arc-20160816; b=Fr9CP1o+jZMR6vodHhrC7fQ8zGOwEFLKncZC5jC3Q/k1d8d9RT1pY4SGE90BHM5uRN LquB3dGp2EV5iinHkL8aP93V79ZpTBZovQ4VQ7Khj4BQfy17S/ARVbWBXtNz1G9oSGXn oVZhNTAr2e5Rle4DLxM3yRbzIzHU0vB2NowaxODUjy97FZfWge/hqwH6LsvYIlYb8rWq QR6tcxrwcMXdAO5O/3E9OfH3RYUlD7ztFKKVSyPbJMmw2DHAsn/p+0WbDixMnobfTxvB 0Cnae9jL1fnLv+rMvNmyJ2qgCbGc1zc/PebO60y5HsOyDqfBPWYEOKpvfORBT4TP0hLV 5jKA== 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=i7ltfNxB57xaKuBABnsPU8ozpqjkiPjHOQseWmBWjtY=; fh=SNirUdkKHR93c4vQEHw73adUAE5UKXjSGs0zqjyJP7c=; b=txEi7TNoMm3femXp8mD8gcvuDg8BD1cPo7TevZKPH8GOhuSMmTIizqlzg+oUvIH0Ob NC9hcTA4sMP0AtJhWsj3kwD4JFjvMENdHYjCh7D4jo0QpImqJE3zJeCD800Eqw9oGesL 4eZpMZRHU/vV326VGuONBWHRhmyn45QHLpaJkS92J5dc5fHRZZhIkGIu3PEaivoaZ9EQ vWpvpVZGpc38EQz7GE1heZ7j1AIBlnd4+MEz+enyM/guMRT7uBebmNd+nPVEiUHd8P43 8PtAPaG+gCQ6GKFlitjIS/5yll0eoy3XNLrdCFgr+AYY+MAUcEQgQmLT3aN46dan9fYo bwcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RGpNaqUA; 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-88325-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88325-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a7-20020a05640233c700b005647bed43cfsi1332320edc.427.2024.03.01.03.21.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:21:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88325-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RGpNaqUA; 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-88325-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88325-ouuuleilei=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 7E68D1F210E5 for ; Fri, 1 Mar 2024 11:21:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E8376E2B3; Fri, 1 Mar 2024 11:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RGpNaqUA" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 5C9D76D1BD; Fri, 1 Mar 2024 11:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292064; cv=none; b=gXU1UH+aukfFFl1lLfJJ77kHWh4CGzgNQmdQzbNx/THL2p7LXFEsmErxLBRrnUXtd1gMu0R8TthNp2yB5oiVtqq1pZTwE0U/I5a8TpMxGZdSj4QkK85rSYjHeZFrZVwv06lWR5SSz29gwJ0r3zUMwenAk4EJD55V4JZn4x5ARFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292064; c=relaxed/simple; bh=ZH9yB3+bAlFuB6GdzN5jxW35ykjB3p90w+ZXJYVkg3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZRzGB//GaoonOoEnN/tYtiqXsQaon/UNYxPFj9Q6LT6JUG/DGU/uut46HwXTNAo+qYBvhoa5h3vJhptXkLMHlB5oCsR64c22594diUVMZDJunIEKsexpYpIG6D3IBaBJtgZPQ6QAV1FtbrQgXY6CSgMz3IPDDgcxIbJJCGgPhv8= 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=RGpNaqUA; arc=none smtp.client-ip=192.198.163.11 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=1709292061; x=1740828061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZH9yB3+bAlFuB6GdzN5jxW35ykjB3p90w+ZXJYVkg3Y=; b=RGpNaqUA2FJOrM+F4mQO0Jt6d/Zi4HXJ8/IJ3FEMHO0Nr2ErjkBzqTe6 lm7AzBo29TUqdkH4rLI2XO9XQ8UJZ5FqF3HxefToPOEiugP6EZe9Tmvtd 7bD6tuo9M0DkOUvLvHMNJeevsF4lVNV3/I7XGfWqLUTIK9fUTnukgUTah dn22XfifS88cs8HKhZkq04MkQ9wtUGcmRYWVrzO2oQSC4aBcubXimusoc 71VpSczSwuTwnPi7uhcbvt7YbkieRdOjUpVkwvZKis1ygFQiT+Ikrc+g5 hHEZRGk/jh2l7sjBpgsQXMzF4rhJU+A34jgwBJPK3wLz39jx4yrRefxie A==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="14465047" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="14465047" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="31350684" Received: from rcaudill-mobl3.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.48.180]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:20:57 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, jgross@suse.com, kai.huang@intel.com Subject: [PATCH 2/5] x86/virt/tdx: Move TDMR metadata fields map table to local variable Date: Sat, 2 Mar 2024 00:20:34 +1300 Message-ID: <41cd371d8a9caadf183e3ab464c57f9f715184d3.1709288433.git.kai.huang@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792322687135721851 X-GMAIL-MSGID: 1792322687135721851 The kernel reads all TDMR related global metadata fields based on a table which maps the metadata fields to the corresponding members of 'struct tdx_tdmr_sysinfo'. Currently this table is a static variable. But this table is only used by the function which reads these metadata fields and becomes useless after reading is done. Change the table to function local variable. This also saves the storage of the table from the kernel image. Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov --- arch/x86/virt/vmx/tdx/tdx.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 2aee64d2f27f..cdcb3332bc5d 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -301,17 +301,16 @@ struct field_mapping { { .field_id = MD_FIELD_ID_##_field_id, \ .offset = offsetof(struct tdx_tdmr_sysinfo, _member) } -/* Map TD_SYSINFO fields into 'struct tdx_tdmr_sysinfo': */ -static 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]), -}; - 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]), + }; int ret; int i; From patchwork Fri Mar 1 11:20:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 208790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1008089dyb; Fri, 1 Mar 2024 03:22:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWfpIh/AWjiw7jzBPffYfpHZU2C8jETww8QxvwK5aQfrS/szwsGpuhkoj7jAy6wwlcwAmtoFgMKLiJHNt7Gp9sQIZFJSA== X-Google-Smtp-Source: AGHT+IGbKLN3XRNhC34To41Mohkn5izh505sS6u91LFPdV94AKn+NhdA47sSmziaYtq36cpVMvuA X-Received: by 2002:a05:622a:243:b0:42e:c2fd:5748 with SMTP id c3-20020a05622a024300b0042ec2fd5748mr1574867qtx.0.1709292132074; Fri, 01 Mar 2024 03:22:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292132; cv=pass; d=google.com; s=arc-20160816; b=LYcAT3hL8H5uNlU7TLKPrVW6Hmk1O25pE4P/Ag8z83mZdMtzg249FLbLtrAPisQh1D Oa0ImiNwCLcvVqtxRSdHT+XQvmQwlYJ6CX91slxWfRG3D6VFW6hXWUoefsQtb+k0Q/kr hm12+yZfbRx5lRE1ZRbPi2ftronwqkl+2/k1JVl1GMKVIGW89qbFGcgbfDu24xoDYO/A Maq7piXVAxzzbmr7jU9wxARBi2ZY5bwsMmB/mzPpHdKnUQef+071ZusnmvwVujURc4C6 Ff1hNW7YFSiUPEVFCyH8BeuaikRWvN6osCfzQR6cEetFJsMkM8Sy1qhV+KGwyb6b9Znc 8HjQ== 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=AH9C+fRgIHP1OMwoIVmvQP3VhnlIiUYAmHsGKuMv6Vg=; fh=SNirUdkKHR93c4vQEHw73adUAE5UKXjSGs0zqjyJP7c=; b=LsU+NfqE7C9Cf4Zj3a+OEAc28F6Zj8anxaugKAq99+F8YLFnklivggB0jKnp5iignh aKzX/XZdcR9ktDK0CFInll91pwdj2mnmTmnvWxSd9J1UetjED1aWwikQUXOscGHF/HF3 i/5Q/dBmnixnqfqGibr/hOKraIs2HSDnMQw+BHqvbA/mZ4ZBkR+4ogcGUEVT2d2FIU+M 5gxBw02Y+B3pI5gLPxr1zn7Lg4aiHTdhPZFOtA00thd1k1TJTTrmaGCgSgzkR/rgUusG +64E1EkyW1SkaAJ26ZCnh2bMp/6sEK+/qyfbuKac3GLm8NWHw8rDBcpueJGzza+KlHxg MNVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DwQQzOQO; 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-88326-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88326-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e16-20020ac85990000000b0042e4e7909b0si3588188qte.95.2024.03.01.03.22.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:22:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88326-ouuuleilei=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=DwQQzOQO; 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-88326-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88326-ouuuleilei=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 CCD521C213EC for ; Fri, 1 Mar 2024 11:22:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD10A6E61C; Fri, 1 Mar 2024 11:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DwQQzOQO" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 9AFB86BFDA; Fri, 1 Mar 2024 11:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292067; cv=none; b=t97KbDj1Ec2MHYELKCw0HK5k4GoD8SUESUrQAPogcsbDKKINfUeRZXd6KqLM1KnynoFJVSZsbYrcFvN8706tKLGNYMXCrMsMpFcHO6whOjUiKE9M7h8lJPcly/xD0NmhtwprP7sP3J9tI8F1+OxLaHAAqlcO6VeFuqe/6Ha8rHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292067; c=relaxed/simple; bh=k3U4KpAsrlXajeTnJ0yhCURtBSDCFFQmd56PG+VaflI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FQ5liugsoBM4eTHSXfHbNFR5gYwfoYFopTRzg0R32FUu0Z+xt/mC749QlFRnunKOI/AF3VhBT7l/OFwrF5YBDJ+Zrc/9VKmIT9wLfdKcwf+GNTiQkFXNxgUBiRVtWhoBtnskdCl/rx9YVqIWd16Lj79ysPwPanmKczo87xOmzio= 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=DwQQzOQO; arc=none smtp.client-ip=192.198.163.11 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=1709292065; x=1740828065; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k3U4KpAsrlXajeTnJ0yhCURtBSDCFFQmd56PG+VaflI=; b=DwQQzOQOJQBLy9XwfPVoFfHBHu8lT4ZTNNAnuTxBRPSfvUvgzX8eCElF RPUSMn8rzwumwxdZtAHHYHlLvXQcJ+jNhco+s3t62EKjnGftmgWkeCudZ SEdLeCDlXhPxEPCIs/8ZtN9H3fRLnMPlycMl9N9LR3CpuMvljblUL6pg0 SNlyEQbc1scOuOfK3o+cnUtuTlHXjxjz63UFXi5UcmxEcg5IFN+kjH/Qf S/rTnryf46Bm31HkUtdabv5DgrMvHnwVL8JAX9DNCBX3DZovc0cXSp8/d 26BmLtjMGEqU9k9EqqycIm+d6zaS0IgvAZj3kgAOm2ELTNfSsx8gCpKho Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="14465057" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="14465057" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="31350694" Received: from rcaudill-mobl3.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.48.180]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:01 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, jgross@suse.com, kai.huang@intel.com Subject: [PATCH 3/5] x86/virt/tdx: Unbind global metadata read with 'struct tdx_tdmr_sysinfo' Date: Sat, 2 Mar 2024 00:20:35 +1300 Message-ID: <393931ee1d8f0dfb199b3e81aa660f2af0351129.1709288433.git.kai.huang@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792322706661793940 X-GMAIL-MSGID: 1792322706661793940 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 --- 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; From patchwork Fri Mar 1 11:20:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 208791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1008240dyb; Fri, 1 Mar 2024 03:22:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXP0Lss/l3p0As6A/HCBdrCnxrt8oHg5VL2N1yReMY3x/fIonCVu8VlGC5AO3Pr5/AzVFobsxrpHCKkHy0ukdSCkqHRnA== X-Google-Smtp-Source: AGHT+IGvINRKhxqSH7AEt4duyMzwFkNMOkO9Wq7lHUZ8gpjTk8fdGSXuQDsbAfGeveOENVpbuhWC X-Received: by 2002:a17:90a:9a98:b0:29a:6cf0:57a3 with SMTP id e24-20020a17090a9a9800b0029a6cf057a3mr1221774pjp.8.1709292152098; Fri, 01 Mar 2024 03:22:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292152; cv=pass; d=google.com; s=arc-20160816; b=u0aQx0GhY2Q7Gmkeg5nq8G7P4HnsvRIfow3H5lsYoZpYzyXl9SPs3E3hn0f2M0guPO /47YviWVBrgoklwhGhjH0TAFu2JdlrMJDzSQW7sysEbitDVEgfLC8N5s6fyo+sEdeEYa hJkF8c6ZCn7JqFbX0Gt0akFpc8IKNXAkaNU5oV2qi+JCZppXIBNVkYo05uAfZvJWiyHi OAv+umnXus65miWpraXXxTvF1uveafwppXZdLNxKbxobmTIxBIPr+hDzOjZZlmMEAHUM 00EY7n8MLwc80jl9HtX/xSSt/V3fUeaDymxY5scNdAmfH9O5N5Lscy9INJXNWDEKSmtI E+KA== 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=ezSPprSW8twkA4wZE7oA2S0cxn+vjZo0wNtwM8GFtcY=; fh=SNirUdkKHR93c4vQEHw73adUAE5UKXjSGs0zqjyJP7c=; b=fXLmXbIcyteAfWXE3Rr/mnGCkeROpTEmVpW4kJtywN/e9o7CCS4aa1+EOMsgKO3y6L oqdGUK8lUPsC8r6wWSaogDzShsUGxKDSKtH0xqs9z1oC5gF/NBJGzFDs1xXj+rfI3bDS ceNAmC8fNq35L9nU9ezazeIWxT9RUMJrxuG/Rwmq6H4oScEFLtTTOYy+Iac57rmCN06/ MRQMUDHn037rbYmO5vE2goGvBgcdsxx6prZGKyqc5mHHtVVhcXz/Vhs4fSdRtvmzWinJ oyXF9XqJ7V0xt7+Me/vHIL/IXP/raMGIRs/wppIeV4m0ukj8zJ0ToUNMI3zqgS8BgWzk CDAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AgNqAzDq; 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-88327-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88327-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id oc4-20020a17090b1c0400b0029aacf544c0si3580806pjb.92.2024.03.01.03.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:22:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88327-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AgNqAzDq; 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-88327-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88327-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DE34328208E for ; Fri, 1 Mar 2024 11:22:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAC296EB60; Fri, 1 Mar 2024 11:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AgNqAzDq" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 CD0DD6EB40; Fri, 1 Mar 2024 11:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292072; cv=none; b=ms9HWRWiCgGEE7E2nEqMn0tsX3vplI8AzlkvtjcyPcZZN9KInpgkDQyCI0HFwIo+dcBNVjgNugH7J0bjCeikYygXDMuPTqhXF9tq6ugkNyYIwjnH1pgTEdejNlvKoPDTpommYnbKgcj/r7n0kwMYWE5LteMnp7YHvM+w//rNhGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292072; c=relaxed/simple; bh=0eBX029BCiLTue40MgYy0Z6NggPwsRuK/phCsbkLIbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c90jdFdMWrCa+m0DrDqN69O/N3joKWQMdIdiLnm6v9UKw3J1ub7zAIuRuuIRhQBDfcrJyPQE9aubLEqnZz3Mb7b0Wp/lYzlPR9RaurbomTcnugjwfum/n8m6JD3B1hf4Q6mTIhHSfGL8Z8fPXE999mCKl3i3KEiRjicyk6PPzoQ= 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=AgNqAzDq; arc=none smtp.client-ip=192.198.163.11 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=1709292070; x=1740828070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0eBX029BCiLTue40MgYy0Z6NggPwsRuK/phCsbkLIbo=; b=AgNqAzDqs3QZEMq5EdT+05FsY5YFH3QQtU0TVG76OjTjxEKqEo5ha5cx /QTnJJ4HMAmo6eyzP5QzSimH2jK6YbQpD0Db+Cos5IReBO1SuTD/92jr/ GcOaKrWz+rszEQxam6jtMY0RzSgZ9489kHKgZPqmnLmPBGxsp+lScKTY+ AkxKNNdyJtrVbQczKumE1brCWfJuY68RY7dqO7HgCGdk/C78HQ7GRO6f4 uFdgzuP3tV5YQ8DLNR1Os2DRx5nmQEg4TIsIxeE4tLXdNfJe0BwFnmJfJ 40O0uuLUSubXErsW9iecrAJXoqOBwq3z9TLk9clzeVF+e3xg/vzBBRk/z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="14465071" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="14465071" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="31350707" Received: from rcaudill-mobl3.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.48.180]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:05 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, jgross@suse.com, kai.huang@intel.com Subject: [PATCH 4/5] x86/virt/tdx: Support global metadata read for all element sizes Date: Sat, 2 Mar 2024 00:20:36 +1300 Message-ID: <17f1c66ae6360b14f175c45aa486f4bdcf6e0a20.1709288433.git.kai.huang@intel.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792322727507201383 X-GMAIL-MSGID: 1792322727507201383 For now the kernel only reads TDMR related global metadata fields for module initialization. All these fields are 16-bits, and the kernel only supports reading 16-bits fields. 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 supports reading all 8/16/32/64 bits element sizes. Extend the metadata read to support reading all these element sizes. Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov --- arch/x86/virt/vmx/tdx/tdx.c | 59 +++++++++++++++++++++++++------------ arch/x86/virt/vmx/tdx/tdx.h | 2 -- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index eb208da4ff63..4ee4b8cf377c 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -271,23 +271,35 @@ static int read_sys_metadata_field(u64 field_id, u64 *data) return 0; } -static int read_sys_metadata_field16(u64 field_id, - int offset, - void *stbuf) +/* Return the metadata field element size in bytes */ +static int get_metadata_field_bytes(u64 field_id) { - u16 *st_member = stbuf + offset; + /* + * TDX supports 8/16/32/64 bits metadata field element sizes. + * TDX module determines the metadata element size based on the + * "element size code" encoded in the field ID (see the comment + * of MD_FIELD_ID_ELE_SIZE_CODE macro for specific encodings). + */ + return 1 << MD_FIELD_ID_ELE_SIZE_CODE(field_id); +} + +static int stbuf_read_sys_metadata_field(u64 field_id, + int offset, + int bytes, + void *stbuf) +{ + void *st_member = stbuf + offset; u64 tmp; int ret; - if (WARN_ON_ONCE(MD_FIELD_ID_ELE_SIZE_CODE(field_id) != - MD_FIELD_ID_ELE_SIZE_16BIT)) + if (WARN_ON_ONCE(get_metadata_field_bytes(field_id) != bytes)) return -EINVAL; ret = read_sys_metadata_field(field_id, &tmp); if (ret) return ret; - *st_member = tmp; + memcpy(st_member, &tmp, bytes); return 0; } @@ -295,11 +307,30 @@ static int read_sys_metadata_field16(u64 field_id, struct field_mapping { u64 field_id; int offset; + int size; }; #define TD_SYSINFO_MAP(_field_id, _struct, _member) \ { .field_id = MD_FIELD_ID_##_field_id, \ - .offset = offsetof(_struct, _member) } + .offset = offsetof(_struct, _member), \ + .size = sizeof(typeof(((_struct *)0)->_member)) } + +static int read_sys_metadata(const struct field_mapping *fields, int nr_fields, + void *stbuf) +{ + int i, ret; + + for (i = 0; i < nr_fields; i++) { + ret = stbuf_read_sys_metadata_field(fields[i].field_id, + fields[i].offset, + fields[i].size, + stbuf); + if (ret) + return ret; + } + + return 0; +} #define TD_SYSINFO_MAP_TDMR_INFO(_field_id, _member) \ TD_SYSINFO_MAP(_field_id, struct tdx_tdmr_sysinfo, _member) @@ -314,19 +345,9 @@ static int get_tdx_tdmr_sysinfo(struct tdx_tdmr_sysinfo *tdmr_sysinfo) 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; /* Populate 'tdmr_sysinfo' fields using the mapping structure above: */ - for (i = 0; i < ARRAY_SIZE(fields); i++) { - ret = read_sys_metadata_field16(fields[i].field_id, - fields[i].offset, - tdmr_sysinfo); - if (ret) - return ret; - } - - return 0; + return read_sys_metadata(fields, ARRAY_SIZE(fields), tdmr_sysinfo); } /* Calculate the actual TDMR size */ diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index b701f69485d3..4c32c8bf156a 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -53,8 +53,6 @@ #define MD_FIELD_ID_ELE_SIZE_CODE(_field_id) \ (((_field_id) & GENMASK_ULL(33, 32)) >> 32) -#define MD_FIELD_ID_ELE_SIZE_16BIT 1 - struct tdmr_reserved_area { u64 offset; u64 size; From patchwork Fri Mar 1 11:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 208793 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1008714dyb; Fri, 1 Mar 2024 03:23:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUlOQAtYimtUy0h4/oj9z3TXG1jT7X4DjIJOL20BzZ+qUJUCWvqOrB09HRG0vACGwPK8KAq7UeBK4GbJGnGx9x6n6phiw== X-Google-Smtp-Source: AGHT+IGqhrXNK+z+r0lbb0Ps+ataqR0GKzeJa2Y1mW3TiGGl9LGXBzwmctnrEKiDAfp1cHDjdJT6 X-Received: by 2002:a54:470e:0:b0:3c1:5377:78 with SMTP id k14-20020a54470e000000b003c153770078mr1282213oik.23.1709292215230; Fri, 01 Mar 2024 03:23:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709292215; cv=pass; d=google.com; s=arc-20160816; b=wwTamzjdB4eEzSgcgljvEPuGvA/V73SixsF4Au3329nM27CSlP3tbp/dX8+F+sdB/T b6CNQX2chniUag3cQBAiO/OhpCt7oGlbuauyGfCi8J5vusNMtkEMvBFQ7EhOHU6tshYw f5NLT4Bb9R4HLLI1ZqGOdf4O5W5Y9eYU1RxpmmpBT58Wf/uSp3w0x7n++Ie8N2KfJu9j Wlnc3QkVWXnViW+so0uDThvQx4RPiIUkCD1RzZVZiOyRn6T37lNuoVhqQDmAHGD+8Y9G c348KwoxKZqEzKeajlNewvJOblBirBNRCvVHTeQOaUS+BjPzloG+FlMIEPNWtl4+e9jc WzvQ== 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=tDireqfpmLf8N5U4BZGZSHL+kPNbSzH96ZxbEV+0g+U=; fh=SNirUdkKHR93c4vQEHw73adUAE5UKXjSGs0zqjyJP7c=; b=uvCJt5akZBEbtJ9iH2urdGRO9lNiDYUByublyQ6W9G/Ydw+eazb31SKBC3G0qLB2Yc S651quumbnKMT539A7YwLrkNLGbGF5IhksFDn3rSY4kAeU/aJcIodhYNBfqIEs9+bjcx 6DJ2Fk87xgVsLejPjbaUy1WkqFT26ulo0uQKzppzaqV3BHtwl7Egb8450BxarjvQ3RiN lxVV/DEPaZpup2sEp73fv5P8lai5rFqVE0QKpjj3op80g3Xjjipq7UdBiP6PBZ/A10V+ 9DGULQFNtVbtOWoRBLLW8CUp3MqNPrw4DZL/ivBCKI8AK23CI1jBQxNEtShAHbXxri5Y mcQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M5atMBfF; 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-88328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88328-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q23-20020a631f57000000b005d6c2958481si3340972pgm.639.2024.03.01.03.23.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:23:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=M5atMBfF; 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-88328-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88328-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B59C4B22B23 for ; Fri, 1 Mar 2024 11:23:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B97FD6F07C; Fri, 1 Mar 2024 11:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="M5atMBfF" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 06A316EB59; Fri, 1 Mar 2024 11:21:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292075; cv=none; b=tJRPMbON52Tu/HBuyM6Ypp4+3hjvcXxH/F21839fiABrrbs7oyVjjH5YBMVYsk6uqHcUoygO5+WT1Wtv3yeE1bcC5wzsfF+z4vo54xV6iWEFRQhmmJEit3KcCEThbAbcaKFVB1JeI4NAjHADscrd0RgivU9RL/nA6ooiTvsjIFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709292075; c=relaxed/simple; bh=emqtL0+dXzwOhy3Q+tmmc3fBKAMADFr0JjYEl1DTI0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKjUoH/vZkQ/tgl6himqU/VZtZ6gqz7wbo26cruPTkq4eT/mhn9k8LXw00CsiAXPvuNXyBD5PFj7FAAuWsxKVhF9V5/XeLZwWgLccDbo7KiywIwcS2hUiX1TpBfWqcmhgEciJMjqz4e+qk81jfx5ZUjoElYMFQgHaQ3bHYdlCEI= 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=M5atMBfF; arc=none smtp.client-ip=192.198.163.11 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=1709292074; x=1740828074; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=emqtL0+dXzwOhy3Q+tmmc3fBKAMADFr0JjYEl1DTI0I=; b=M5atMBfF5+FeSERIaDCFTcgtaCz72PRyF02eZyrJNJc8q6625fcM++kw pNFvADh3ODFRYxUn/7ppOg6rn7/Fvy8g7DSzP097eMl0geroOZq9W1lBT 0DUsqZecT7MToGynVvbv2yxR3Y153lKr7pri7BSJdQ3pVEtnjEN8zjq2B K0T9CWG7HgLVz7qjjd+kMDrsRTIVb5ZTl+sHuViceHJtRQmXZ8Mxxt2bz bYg4BLmiPRDk/GZC20PK5I6WlmZYDBcA4iovbSvCFoDyVLK/ZIQCdIdw4 MSVbD7nroccoz6zSmOjece7DlXX0kR5Gz8sCp7+2mz4xyvnypYW+VcMr4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10999"; a="14465081" X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="14465081" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,196,1705392000"; d="scan'208";a="31350730" Received: from rcaudill-mobl3.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.209.48.180]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 03:21:10 -0800 From: Kai Huang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, jgross@suse.com, kai.huang@intel.com Subject: [PATCH 5/5] x86/virt/tdx: Export global metadata read infrastructure Date: Sat, 2 Mar 2024 00:20:37 +1300 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792322793695638656 X-GMAIL-MSGID: 1792322793695638656 KVM will need to read a bunch of non-TDMR related metadata to create and run TDX guests. Export the metadata read infrastructure for KVM to use. Specifically, export two helpers: 1) The helper which reads multiple metadata fields to a buffer of a structure based on the "field ID -> structure member" mapping table. 2) The low level helper which just reads a given field ID. The two helpers cover cases when the user wants to cache a bunch of metadata fields to a certain structure and when the user just wants to query a specific metadata field on demand. They are enough for KVM to use (and also should be enough for other potential users). Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov --- arch/x86/include/asm/tdx.h | 22 ++++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx.c | 25 ++++++++----------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index eba178996d84..709b9483f9e4 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -116,6 +116,28 @@ static inline u64 sc_retry(sc_func_t func, u64 fn, int tdx_cpu_enable(void); int tdx_enable(void); const char *tdx_dump_mce_info(struct mce *m); + +struct tdx_metadata_field_mapping { + u64 field_id; + int offset; + int size; +}; + +#define TD_SYSINFO_MAP(_field_id, _struct, _member) \ + { .field_id = MD_FIELD_ID_##_field_id, \ + .offset = offsetof(_struct, _member), \ + .size = sizeof(typeof(((_struct *)0)->_member)) } + +/* + * Read multiple global metadata fields to a buffer of a structure + * based on the "field ID -> structure member" mapping table. + */ +int tdx_sys_metadata_read(const struct tdx_metadata_field_mapping *fields, + int nr_fields, void *stbuf); + +/* Read a single global metadata field */ +int tdx_sys_metadata_field_read(u64 field_id, u64 *data); + #else static inline void tdx_init(void) { } static inline int tdx_cpu_enable(void) { return -ENODEV; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 4ee4b8cf377c..dc21310776ab 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -251,7 +251,7 @@ static int build_tdx_memlist(struct list_head *tmb_list) return ret; } -static int read_sys_metadata_field(u64 field_id, u64 *data) +int tdx_sys_metadata_field_read(u64 field_id, u64 *data) { struct tdx_module_args args = {}; int ret; @@ -270,6 +270,7 @@ static int read_sys_metadata_field(u64 field_id, u64 *data) return 0; } +EXPORT_SYMBOL_GPL(tdx_sys_metadata_field_read); /* Return the metadata field element size in bytes */ static int get_metadata_field_bytes(u64 field_id) @@ -295,7 +296,7 @@ static int stbuf_read_sys_metadata_field(u64 field_id, if (WARN_ON_ONCE(get_metadata_field_bytes(field_id) != bytes)) return -EINVAL; - ret = read_sys_metadata_field(field_id, &tmp); + ret = tdx_sys_metadata_field_read(field_id, &tmp); if (ret) return ret; @@ -304,19 +305,8 @@ static int stbuf_read_sys_metadata_field(u64 field_id, return 0; } -struct field_mapping { - u64 field_id; - int offset; - int size; -}; - -#define TD_SYSINFO_MAP(_field_id, _struct, _member) \ - { .field_id = MD_FIELD_ID_##_field_id, \ - .offset = offsetof(_struct, _member), \ - .size = sizeof(typeof(((_struct *)0)->_member)) } - -static int read_sys_metadata(const struct field_mapping *fields, int nr_fields, - void *stbuf) +int tdx_sys_metadata_read(const struct tdx_metadata_field_mapping *fields, + int nr_fields, void *stbuf) { int i, ret; @@ -331,6 +321,7 @@ static int read_sys_metadata(const struct field_mapping *fields, int nr_fields, return 0; } +EXPORT_SYMBOL_GPL(tdx_sys_metadata_read); #define TD_SYSINFO_MAP_TDMR_INFO(_field_id, _member) \ TD_SYSINFO_MAP(_field_id, struct tdx_tdmr_sysinfo, _member) @@ -338,7 +329,7 @@ static int read_sys_metadata(const struct field_mapping *fields, int nr_fields, 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[] = { + const struct tdx_metadata_field_mapping fields[] = { 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]), @@ -347,7 +338,7 @@ static int get_tdx_tdmr_sysinfo(struct tdx_tdmr_sysinfo *tdmr_sysinfo) }; /* Populate 'tdmr_sysinfo' fields using the mapping structure above: */ - return read_sys_metadata(fields, ARRAY_SIZE(fields), tdmr_sysinfo); + return tdx_sys_metadata_read(fields, ARRAY_SIZE(fields), tdmr_sysinfo); } /* Calculate the actual TDMR size */