All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Rick P Edgecombe <rick.p.edgecombe@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	 Isaku Yamahata <isaku.yamahata@intel.com>,
	Kai Huang <kai.huang@intel.com>,
	 "federico.parola@polito.it" <federico.parola@polito.it>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	 "isaku.yamahata@gmail.com" <isaku.yamahata@gmail.com>,
	"dmatlack@google.com" <dmatlack@google.com>,
	 "michael.roth@amd.com" <michael.roth@amd.com>
Subject: Re: [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY
Date: Tue, 16 Apr 2024 16:00:45 -0700	[thread overview]
Message-ID: <Zh8DHbb8FzoVErgX@google.com> (raw)
In-Reply-To: <CABgObfZq9dzvq3tsPMM3D+Zn-c77QrVd2Z1gW5ZKfb5fPu_8WA@mail.gmail.com>

On Tue, Apr 16, 2024, Paolo Bonzini wrote:
> On Mon, Apr 15, 2024 at 11:17 PM Sean Christopherson <seanjc@google.com> wrote:
> > The first question to answer is, do we want to return an error or "silently"
> > install mappings for !SMM, !guest_mode.  And so this option becomes relevant only
> > _if_ we want to unconditionally install mappings for the 'base" mode.
> >
> > > > - Return error on guest mode or SMM mode:  Without this patch.
> > > >   Pros: No additional patch.
> > > >   Cons: Difficult to use.
> > >
> > > Hmm... For the non-TDX use cases this is just an optimization, right? For TDX
> > > there shouldn't be an issue. If so, maybe this last one is not so horrible.
> 
> It doesn't even have to be ABI that it gives an error. As you say,
> this ioctl can just be advisory only for !confidential machines. Even
> if it were implemented, the shadow MMU can drop roots at any moment

Sure, but there's a difference between KVM _potentially_ dropping roots and
guaranteed failure because userspace is trying to do something that's unsupported.
But I think this is a non-issue, because it should really just be as simple as:

	if (!mmu->pre_map_memory)
		return -EOPNOTSUPP;

Hmm, or probably this to avoid adding an MMU hook for a single MMU flavor:

	if (!tdp_mmu_enabled || !mmu->root_role.direct)
		return -EOPNOTSUPP;

> and/or kill the mapping via the shrinker.

Ugh, we really need to kill that code.

> That said, I can't fully shake the feeling that this ioctl should be
> an error for !TDX and that TDX_INIT_MEM_REGION wasn't that bad. The
> implementation was ugly but the API was fine. 

Hmm, but IMO the implementation was ugly in no small part because of the contraints
put on KVM by the API.  Mapping S-EPT *and* doing TDH.MEM.PAGE.ADD in the same
ioctl() forced KVM to operate on vcpu0, and necessitated shoving temporary data
into a per-VM structure in order to get the source contents into TDH.MEM.PAGE.ADD.

We could eliminate the vcpu0 grossness, but it would require a massive refactor,
which is also not a problem per se, but it's obviously not free.  Eliminating
kvm_tdx.source_page is also doable, but it's not clear to me that end result would
be a net positive.

If userspace pre-maps the S-EPT entries ahead of time, then KVM should have a
straight shot to PAGE.ADD, i.e. doesn't need to "pass" the source page via a
scratch field in kvm_tdx, and I think/hope would avoid the need to grab vcpu0
in order to get at an MMU to build the S-EPT.

And stating the obvious, TDX_INIT_MEM_REGION also doesn't allow pre-mapping memory,
which is generally useful, and can be especially beneficial for confidential VMs
(and TDX in particular) due to the added cost of a page fault VM-Exit.

I'm not dead set on this generic ioctl(), but unless it ends up being a train wreck
for userspace, I think it will allow for cleaner and more reusable code in KVM.

  reply	other threads:[~2024-04-16 23:00 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 22:07 [PATCH v2 00/10] KVM: Guest Memory Pre-Population API isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 01/10] KVM: Document KVM_MAP_MEMORY ioctl isaku.yamahata
2024-04-15 23:27   ` Edgecombe, Rick P
2024-04-15 23:47     ` Isaku Yamahata
2024-04-17 11:56     ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 02/10] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory isaku.yamahata
2024-04-16 14:20   ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 03/10] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() isaku.yamahata
2024-04-16  8:22   ` Chao Gao
2024-04-16 23:43     ` Isaku Yamahata
2024-04-16 14:36   ` Edgecombe, Rick P
2024-04-16 23:52     ` Isaku Yamahata
2024-04-17 15:41       ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 04/10] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level isaku.yamahata
2024-04-16 14:40   ` Edgecombe, Rick P
2024-04-16 23:59     ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 05/10] KVM: x86/mmu: Introduce kvm_tdp_map_page() to populate guest memory isaku.yamahata
2024-04-16 14:46   ` Edgecombe, Rick P
2024-04-17 18:39     ` Isaku Yamahata
2024-04-17  7:04   ` Chao Gao
2024-04-17 18:44     ` Isaku Yamahata
2024-04-10 22:07 ` [PATCH v2 06/10] KVM: x86: Implement kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 15:12   ` Edgecombe, Rick P
2024-04-17  7:20   ` Chao Gao
2024-04-17 12:18   ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 07/10] KVM: x86: Always populate L1 GPA for KVM_MAP_MEMORY isaku.yamahata
2024-04-15 19:12   ` Edgecombe, Rick P
2024-04-15 21:17     ` Sean Christopherson
2024-04-15 21:36       ` Edgecombe, Rick P
2024-04-15 22:59         ` Sean Christopherson
2024-04-16  1:49       ` Isaku Yamahata
2024-04-16 14:22         ` Sean Christopherson
2024-04-16 21:41       ` Paolo Bonzini
2024-04-16 23:00         ` Sean Christopherson [this message]
2024-04-17 10:28           ` Paolo Bonzini
2024-04-15 19:37   ` Edgecombe, Rick P
2024-04-16 17:11   ` Edgecombe, Rick P
2024-04-10 22:07 ` [PATCH v2 08/10] KVM: x86: Add a hook in kvm_arch_vcpu_map_memory() isaku.yamahata
2024-04-16 14:57   ` Edgecombe, Rick P
2024-04-17 12:26   ` Paolo Bonzini
2024-04-10 22:07 ` [PATCH v2 09/10] KVM: SVM: Implement pre_mmu_map_page() to refuse KVM_MAP_MEMORY isaku.yamahata
2024-04-10 22:07 ` [PATCH v2 10/10] KVM: selftests: x86: Add test for KVM_MAP_MEMORY isaku.yamahata

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=Zh8DHbb8FzoVErgX@google.com \
    --to=seanjc@google.com \
    --cc=dmatlack@google.com \
    --cc=federico.parola@polito.it \
    --cc=isaku.yamahata@gmail.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.