From: "Huang, Kai" <kai.huang@intel.com>
To: "kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>,
"jgross@suse.com" <jgross@suse.com>,
"Hansen, Dave" <dave.hansen@intel.com>
Cc: "bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"x86@kernel.org" <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>
Subject: Re: [PATCH] x86/kvm/tdx: Save %rbp in TDX_MODULE_CALL
Date: Thu, 23 May 2024 12:26:43 +0000 [thread overview]
Message-ID: <a9bbb31e6660343e95d3351febc6e3b9661a7944.camel@intel.com> (raw)
In-Reply-To: <2e07ebc774bf176ebfab40e6ba8bc14ae6a94e0c.camel@intel.com>
[-- Attachment #1: Type: text/plain, Size: 3074 bytes --]
On Thu, 2024-05-23 at 10:30 +0000, Huang, Kai wrote:
> On Thu, 2024-05-23 at 07:56 +0200, Jürgen Groß wrote:
> > On 20.05.24 13:54, Huang, Kai wrote:
> > > On Fri, 2024-05-17 at 09:48 -0700, Dave Hansen wrote:
> > > > On 5/17/24 08:58, Juergen Gross wrote:
> > > > > On 17.05.24 17:52, Dave Hansen wrote:
> > > > ..
> > > > > > Once we have the specific TDX module version, we can go ask the folks
> > > > > > who write it if there were any RBP clobbering bugs.
> > > > >
> > > > > Okay, how to get the TDX module version?
> > > >
> > > > You need something like this:
> > > >
> > > > > https://lore.kernel.org/all/20231012134136.1310650-1-yi.sun@intel.com/
> > >
> > > This one prints TDX version info in the TDX guest, but not host.
> > >
> > > The attached diff prints the TDX version (something like below) during
> > > module initialization, and should meet Juergen's needs for temporary use:
> > >
> > > [ 113.543538] virt/tdx: module verson: major 1, minor 5, internal 0
> > >
> > > >
> > > > .. and yeah, this needs to be upstream.
> > > >
> > >
> > > From this thread I think it makes sense to add code to the TDX host code
> > > to print the TDX version during module initialization. I'll start to work
> > > on this.
> > >
> > > One thing is from the spec TDX has "4 versions": major, minor, update,
> > > internal. They are all 16-bit, and the overall version can be written in:
> > >
> > > <Major>.<Minor>.<Update>.<Internal>, e.g., 1.5.05.01
> > >
> > > (see TDX module 1.5 API spec, section 3.3.2 "TDX Module Version".)
> > >
> > > The attached diff only prints major, minor and internal, but leaves the
> > > update out because I believe it is for module runtime update (yet to
> > > confirm).
> > >
> > > Given there are 4 versions, I think it makes sense to implement reading
> > > them based on this patchset ...
> > >
> > > https://lore.kernel.org/kvm/6940c326-bfca-4c67-badf-ab5c086bf492@intel.com/T/
> > >
> > > ... which extends the global metadata reading code to support any
> > > arbitrary struct and all element sizes (although all 4 versions are 16-
> > > bit)?
> >
> > With that I got:
> >
> > [ 29.328484] virt/tdx: module verson: major 1, minor 5, internal 0
> >
> >
>
> Let me check TDX module guys on this and get back to you.
Hi Jurgen,
I was told the module starting with "1.5.06." has NO_RBP_MOD support.
And I think I was wrong about the <update> part of the version, and we
need that to determine the third part of the module version.
I was also told the 1.5.06 module hasn't been released to public yet, so I
guess your module doesn't support it.
I did another patch (attached) to check NO_RBP_MOD and reject module
initialization if it is not supported, and print out module version:
[ 146.566641] virt/tdx: NO_RBP_MOD feature is not supported
[ 146.572797] virt/tdx: module verson: 1.5.0.0
[ 146.577731] virt/tdx: module initialization failed (-22)
You can have another try to verify at your side, if that helps.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: check_no_rbp_mod.diff --]
[-- Type: text/x-patch; name="check_no_rbp_mod.diff", Size: 2708 bytes --]
commit e3907269b34e4f488284f35716f231da7bc3e6b3
Author: Kai Huang <kai.huang@intel.com>
Date: Thu May 23 23:17:28 2024 +1200
x86/virt/tdx: check NO_RBP_MOD and print module version
Signed-off-by: Kai Huang <kai.huang@intel.com>
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 4d6826a76f78..ffc1c27b9134 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -1097,11 +1097,60 @@ static int init_tdmrs(struct tdmr_info_list *tdmr_list)
return 0;
}
+static int check_module_compatibility(void)
+{
+ u64 tdx_features0;
+ int ret;
+
+ ret = read_sys_metadata_field(MD_FIELD_ID_TDX_FEATURES0,
+ &tdx_features0);
+
+ if (ret)
+ return ret;
+
+ if (!(tdx_features0 & TDX_FEATURES0_NO_RBP_MOD)) {
+ pr_err("NO_RBP_MOD feature is not supported\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void print_tdx_version(void)
+{
+ u64 major, minor, update, internal;
+ int ret;
+
+ ret = read_sys_metadata_field(MD_FIELD_ID_MAJOR_VERSION, &major);
+ if (ret)
+ return;
+
+ ret = read_sys_metadata_field(MD_FIELD_ID_MINOR_VERSION, &minor);
+ if (ret)
+ return;
+
+ ret = read_sys_metadata_field(MD_FIELD_ID_UPDATE_VERSION, &update);
+ if (ret)
+ return;
+
+ ret = read_sys_metadata_field(MD_FIELD_ID_INTERNAL_VERSION, &internal);
+ if (ret)
+ return;
+
+ pr_info("module verson: %u.%u.%u.%u\n",
+ (u16)major, (u16)minor, (u16)update, (u16)internal);
+}
+
static int init_tdx_module(void)
{
struct tdx_tdmr_sysinfo tdmr_sysinfo;
int ret;
+ /* Make sure TDX module meets kernel's expectation */
+ ret = check_module_compatibility();
+ if (ret)
+ goto out;
+
/*
* To keep things simple, assume that all TDX-protected memory
* will come from the page allocator. Make sure all pages in the
@@ -1155,6 +1204,10 @@ static int init_tdx_module(void)
* Lock out memory hotplug code while building it.
*/
put_online_mems();
+
+out:
+ print_tdx_version();
+
return ret;
err_reset_pamts:
diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
index b701f69485d3..13ad52352e35 100644
--- a/arch/x86/virt/vmx/tdx/tdx.h
+++ b/arch/x86/virt/vmx/tdx/tdx.h
@@ -37,6 +37,14 @@
#define MD_FIELD_ID_PAMT_2M_ENTRY_SIZE 0x9100000100000011ULL
#define MD_FIELD_ID_PAMT_1G_ENTRY_SIZE 0x9100000100000012ULL
+#define MD_FIELD_ID_TDX_FEATURES0 0x0A00000300000008ULL
+#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18)
+
+#define MD_FIELD_ID_MINOR_VERSION 0x0800000100000003ULL
+#define MD_FIELD_ID_MAJOR_VERSION 0x0800000100000004ULL
+#define MD_FIELD_ID_UPDATE_VERSION 0x0800000100000005ULL
+#define MD_FIELD_ID_INTERNAL_VERSION 0x0800000100000006ULL
+
/*
* Sub-field definition of metadata field ID.
*
next prev parent reply other threads:[~2024-05-23 12:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 12:14 [PATCH] x86/kvm/tdx: Save %rbp in TDX_MODULE_CALL Juergen Gross
2024-05-17 13:55 ` Kirill A. Shutemov
2024-05-17 14:08 ` Juergen Gross
2024-05-17 14:39 ` Kirill A. Shutemov
2024-05-17 14:41 ` Kirill A. Shutemov
2024-05-17 14:44 ` Juergen Gross
2024-05-17 15:16 ` Dave Hansen
2024-05-17 15:27 ` Jürgen Groß
2024-05-17 15:43 ` Dave Hansen
2024-05-17 15:48 ` Juergen Gross
2024-05-17 15:52 ` Dave Hansen
2024-05-17 15:58 ` Juergen Gross
2024-05-17 16:48 ` Dave Hansen
2024-05-20 11:54 ` Huang, Kai
2024-05-23 5:56 ` Jürgen Groß
2024-05-23 10:30 ` Huang, Kai
2024-05-23 12:26 ` Huang, Kai [this message]
2024-05-23 12:43 ` Jürgen Groß
2024-05-23 22:34 ` Huang, Kai
2024-05-23 23:28 ` Huang, Kai
2024-05-24 5:46 ` Jürgen Groß
2024-05-17 16:12 ` Sean Christopherson
2024-05-17 16:34 ` Dave Hansen
2024-05-17 17:01 ` Kirill A. Shutemov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a9bbb31e6660343e95d3351febc6e3b9661a7944.camel@intel.com \
--to=kai.huang@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox