public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiaoyao Li <xiaoyao.li@intel.com>
To: Sean Christopherson <seanjc@google.com>,
	Rick P Edgecombe <rick.p.edgecombe@intel.com>
Cc: "davidskidmore@google.com" <davidskidmore@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"srutherford@google.com" <srutherford@google.com>,
	"pankaj.gupta@amd.com" <pankaj.gupta@amd.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	Isaku Yamahata <isaku.yamahata@intel.com>,
	Wei W Wang <wei.w.wang@intel.com>
Subject: Re: [ANNOUNCE] PUCK Notes - 2024.04.03 - TDX Upstreaming Strategy
Date: Thu, 11 Apr 2024 23:16:19 +0800	[thread overview]
Message-ID: <2c11bb62-874e-4e9e-89b1-859df5b560bc@intel.com> (raw)
In-Reply-To: <ZhfyNLKsTBUOI7Vp@google.com>

On 4/11/2024 10:22 PM, Sean Christopherson wrote:
> On Thu, Apr 11, 2024, Rick P Edgecombe wrote:
>> On Tue, 2024-04-09 at 09:26 -0700, Sean Christopherson wrote:
>>>> Haha, if this is the confusion, I see why you reacted that way to "JSON".
>>>> That would be quite the curious choice for a TDX module API.
>>>>
>>>> So it is easy to convert it to a C struct and embed it in KVM. It's just not
>>>> that useful because it will not necessarily be valid for future TDX modules.
>>>
>>> No, I don't want to embed anything in KVM, that's the exact same as hardcoding
>>> crud into KVM, which is what I want to avoid.  I want to be able to roll out a
>>> new TDX module with any kernel changes, and I want userspace to be able to
>>> assert
>>> that, for a given TDX module, the effective guest CPUID configuration aligns
>>> with
>>> userspace's desired the vCPU model, i.e. that the value of fixed bits match up
>>> with the guest CPUID that userspace wants to define.
>>>
>>> Maybe that just means converting the JSON file into some binary format that
>>> the
>>> kernel can already parse.  But I want Intel to commit to providing that
>>> metadata
>>> along with every TDX module.
>>
>> Oof. It turns out in one of the JSON files there is a description of a different
>> interface (TDX module runtime interface) that provides a way to read CPUID data
>> that is configured in a TD, including fixed bits. It works like:
>> 1. VMM queries which CPUID bits are directly configurable.
>> 2. VMM provides directly configurable CPUID bits, along with XFAM and
>> ATTRIBUTES, via TDH.MNG.INIT. (KVM_TDX_INIT_VM)
>> 3. Then VMM can use this other interface via TDH.MNG.RD, to query the resulting
>> values of specific CPUID leafs.
>>
>> This does not provide a way to query the fixed bits specifically, it tells you
>> what ended up getting configuring in a specific TD, which includes the fixed
>> bits and anything else. So we need to do KVM_TDX_INIT_VM before KVM_SET_CPUID in
>> order to have something to check against. But there was discussion of
>> KVM_SET_CPUID on CPU0 having the CPUID state to pass to KVM_TDX_INIT_VM. So that
>> would need to be sorted.
>>
>> If we pass the directly configurable values with KVM_TDX_INIT_VM, like we do
>> today, then the data provided by this interface should allow us to check
>> consistency between KVM_SET_CPUID and the actual configured TD CPUID behavior.
> 
> I think it would be a good (optional?) sanity check, e.g. KVM_BUG_ON() if the
> post-KVM_TDX_INIT_VM CPUID set doesn't match KVM's internal data.  But that alone
> provides a terrible experience for userspace.
> 
>   - The VMM would still need to hardcode knowledge of fixed bits, without a way
>     to do a sanity check of its own.

Maybe we can do it this way to avoid hardcode:

1. KVM can get the configurable CPUID bits from TDX module with 
TDH.SYS.RD (they are the old info of TD_SYSINFO.CPUID_CONFIG[]), and 
report them to userspace;

2. userspace configures the configurable CPUID bits and pass them to KVM 
to init TD.

3. After TD is initialized via TDH.MNG.INIT, KVM can get a full CPUID 
list of TD via TDH.MNG.RD. KVM provides interface to report the full 
CPUID list to userspace.

4. Userspace can sanity check the full CPUID list.
    - the configurable bits reported in #1 should be what they have been 
configured;
    - the dynamic bits and other special bits will be checked case by case;
    - the rest bits should be fixed. If the value is not what user 
wants, userspace prints error to user and stop.

Does it sounds reasonable?

>   - Lack of a sanity check means the VMM can't fail VM creation early.
> 
>   - KVM_SET_CPUID2 doesn't have a way to inform userspace _which_ CPUID bits are
>     "bad".
> 
>   - Neither userspace nor KVM can programming detect when bits are fixed vs.
>     flexible.  E.g. it's not impossible that userspace would want to do X if a
>     feature is fixed, but Y if it's flexible.

flexible (configurable) bits is known to VMM (KVM and userspace) because 
TDX module has interface to report them. So we can treat a bit as fixed 
if it is not reported in the flexible group. (of course the dynamic bits 
are special and excluded.)

  reply	other threads:[~2024-04-11 15:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 16:58 [ANNOUNCE] PUCK Notes - 2024.04.03 - TDX Upstreaming Strategy Sean Christopherson
2024-04-07  3:15 ` Xiaoyao Li
2024-04-08 16:20   ` Sean Christopherson
2024-04-08 17:42     ` Edgecombe, Rick P
2024-04-08 18:51       ` Sean Christopherson
2024-04-08 21:56         ` Edgecombe, Rick P
2024-04-08 22:36           ` Sean Christopherson
2024-04-08 23:46             ` Edgecombe, Rick P
2024-04-09  1:37               ` Sean Christopherson
2024-04-09 14:46                 ` Edgecombe, Rick P
2024-04-09 15:23                   ` Sean Christopherson
2024-04-09 15:49                     ` Edgecombe, Rick P
2024-04-09 16:13                       ` Xiaoyao Li
2024-04-09 16:18                         ` Xiaoyao Li
2024-04-10  1:05                           ` Huang, Kai
2024-04-09 16:26                       ` Sean Christopherson
2024-04-11  1:13                         ` Edgecombe, Rick P
2024-04-11 14:22                           ` Sean Christopherson
2024-04-11 15:16                             ` Xiaoyao Li [this message]
2024-04-11 15:26                               ` Sean Christopherson
2024-04-11 15:41                                 ` Xiaoyao Li
2024-04-11 18:52                                 ` Edgecombe, Rick P
2024-04-12  8:40                                   ` Xiaoyao Li
2024-04-12 17:39                                     ` Isaku Yamahata
2024-04-12 20:05                                       ` Edgecombe, Rick P
2024-04-15 21:04                                         ` Isaku Yamahata
2024-04-10  1:12         ` Isaku Yamahata
2024-04-10 14:03           ` Huang, Kai
2024-04-11  1:03             ` Isaku Yamahata
2024-04-11  3:46               ` Isaku Yamahata
2024-04-11 13:39                 ` Huang, Kai
2024-04-09  2:57     ` Xiaoyao Li
2024-04-09 14:01       ` Sean Christopherson
2024-04-09 14:15         ` Xiaoyao Li

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=2c11bb62-874e-4e9e-89b1-859df5b560bc@intel.com \
    --to=xiaoyao.li@intel.com \
    --cc=davidskidmore@google.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pankaj.gupta@amd.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=srutherford@google.com \
    --cc=wei.w.wang@intel.com \
    /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