Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Andrew Bresticker <abrestic@rivosinc.com>
To: Anup Patel <apatel@ventanamicro.com>
Cc: "Atish Kumar Patra" <atishp@rivosinc.com>,
	"Dave Hansen" <dave.hansen@intel.com>,
	linux-kernel@vger.kernel.org,
	"Rajnesh Kanwal" <rkanwal@rivosinc.com>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Anup Patel" <anup@brainfault.org>,
	"Atish Patra" <atishp@atishpatra.org>,
	"Björn Töpel" <bjorn@rivosinc.com>,
	"Suzuki K Poulose" <suzuki.poulose@arm.com>,
	"Will Deacon" <will@kernel.org>, "Marc Zyngier" <maz@kernel.org>,
	"Sean Christopherson" <seanjc@google.com>,
	linux-coco@lists.linux.dev, "Dylan Reid" <dylan@rivosinc.com>,
	"Samuel Ortiz" <sameo@rivosinc.com>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Guo Ren" <guoren@kernel.org>, "Heiko Stuebner" <heiko@sntech.de>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	kvm-riscv@lists.infradead.org, kvm@vger.kernel.org,
	linux-mm@kvack.org, linux-riscv@lists.infradead.org,
	"Mayuresh Chitale" <mchitale@ventanamicro.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Paul Walmsley" <paul.walmsley@sifive.com>,
	"Uladzislau Rezki" <urezki@gmail.com>
Subject: Re: [RFC 45/48] RISC-V: ioremap: Implement for arch specific ioremap hooks
Date: Wed, 26 Apr 2023 09:55:17 -0400	[thread overview]
Message-ID: <CALE4mHqjvmx-mdHJ8pV5ramCeYz0eOEu75-PHfnh1NWePbthDA@mail.gmail.com> (raw)
In-Reply-To: <CAK9=C2XwPx-0jqE+Wz+zYja9oPkTF+7CD8baBYYLpOWLeCpeXQ@mail.gmail.com>

On Wed, Apr 26, 2023 at 6:30 AM Anup Patel <apatel@ventanamicro.com> wrote:
>
> On Wed, Apr 26, 2023 at 1:32 PM Atish Kumar Patra <atishp@rivosinc.com> wrote:
> >
> > On Tue, Apr 25, 2023 at 6:40 PM Dave Hansen <dave.hansen@intel.com> wrote:
> > >
> > > On 4/25/23 01:00, Atish Kumar Patra wrote:
> > > > On Mon, Apr 24, 2023 at 7:18 PM Dave Hansen <dave.hansen@intel.com> wrote:
> > > >> On 4/21/23 12:24, Atish Kumar Patra wrote:
> > > >> I'm not _quite_ sure what "guest initiated" means.  But SEV and TDX
> > > >> don't require an ioremap hook like this.  So, even if they *are* "guest
> > > >> initiated", the question still remains how they work without this patch,
> > > >> or what they are missing without it.
> > > >
> > > > Maybe I misunderstood your question earlier. Are you concerned about guests
> > > > invoking any MMIO region specific calls in the ioremap path or passing
> > > > that information to the host ?
> > >
> > > My concern is that I don't know why this patch is here.  There should be
> > > a very simple answer to the question: Why does RISC-V need this patch
> > > but x86 does not?
> > >
> > > > Earlier, I assumed the former but it seems you are also concerned
> > > > about the latter as well. Sorry for the confusion in that case.
> > > > The guest initiation is necessary while the host notification can be
> > > > made optional.
> > > > The "guest initiated" means the guest tells the TSM (equivalent of TDX
> > > > module in RISC-V) the MMIO region details.
> > > > The TSM keeps a track of this and any page faults that happen in that
> > > > region are forwarded
> > > > to the host by the TSM after the instruction decoding. Thus TSM can
> > > > make sure that only ioremapped regions are
> > > > considered MMIO regions. Otherwise, all memory outside the guest
> > > > physical region will be considered as the MMIO region.
> > >
> > > Ahh, OK, that's a familiar problem.  I see the connection to device
> > > filtering now.
> > >
> > > Is this functionality in the current set?  I went looking for it and all
> > > I found was the host notification side.
> > >
> >
> > The current series doesn't have the guest filtering feature enabled.
> > However, we implemented guest filtering and is maintained in a separate tree
> >
> > https://github.com/rivosinc/linux/tree/cove-integration-device-filtering
> >
> > We did not include those in this series because the tdx patches are
> > still undergoing
> > development. We are planning to rebase our changes once the revised
> > patches are available.
> >
> > > Is this the only mechanism by which the guest tells the TSM which parts
> > > of the guest physical address space can be exposed to the host?
> > >
> >
> > This is the current approach defined in CoVE spec. Guest informs about both
> > shared memory & mmio regions via dedicated SBI calls (
> > e.g sbi_covg_[add/remove]_mmio_region and
> > sbi_covg_[share/unshare]_memory_region)
> >
> > > For TDX and SEV, that information is inferred from a bit in the page
> > > tables.  Essentially, there are dedicated guest physical addresses that
> > > tell the hardware how to treat the mappings: should the secure page
> > > tables or the host's EPT/NPT be consulted?
> > >
> >
> > Yes. We don't have such a mechanism defined in CoVE yet.
> > Having said that, there is nothing in ISA to prevent that and it is doable.
> > Some specific bits in the PTE entry can also be used to encode for
> > shared & mmio physical memory addresses.
> > The TSM implementation will probably need to implement a software page
> > walker in that case.
>
> We can certainly use PTE bits defined by Svpmbt extension to
> differentiate between IO and memory. Also, we can use the PTE
> SW bits to differentiate between shared and non-shared memory.
>
> >
> > Are there any performance advantages between the two approaches ?
> > As per my understanding, we are saving some boot time privilege
> > transitions & less ABIs but
> > adds the cost of software walk at runtime faults.
>
> Performance wise both approaches will be the same because in
> case of PTE based approach, the TSM can on-demand map the
> shared memory and do software walk upon first access.

For MMIO sure, we can use Svpbmt or an RSW bit in the VS-stage PTE.
Performance-wise the difference is a few fetches from guest memory by
the TSM vs a lookup by the TSM in an internal data-structure.

It's a little more complicated for shared <-> private conversion,
though. If we were to emulate what TDX does with separate Shared vs
Secure EPTs, we could use the MSB of the GPA to divide GPA space in
half between private vs shared. But then we need to enable the host to
reclaim the private pages on a private -> shared conversion: either
the TSM must track which parts of GPA space have been converted (which
gets complicated in the presence of hugepages), or we let the host
remove whatever private pages it wants. For the latter we'd then need
an "accept" flow -- we don't have a #VE equivalent on RISC-V, but I
suppose we could use access fault exceptions for this purpose.

-Andrew
>
> >
> > > If that mechanism is different for RISC-V, it would go a long way to
> > > explaining why RISC-V needs this patch.
> > >
> > > > In the current CoVE implementation, that MMIO region information is also
> > > > passed to the host to provide additional flexibility. The host may
> > > > choose to do additional
> > > > sanity check and bail if the fault address does not belong to
> > > > requested MMIO regions without
> > > > going to the userspace. This is purely an optimization and may not be mandatory.
> > >
> > > Makes sense, thanks for the explanation.
> > >
> > > >>> It can be a subset of the region's host provided the layout. The
> > > >>> guest device filtering solution is based on this idea as well [1].
> > > >>>
> > > >>> [1] https://lore.kernel.org/all/20210930010511.3387967-1-sathyanarayanan.kuppuswamy@linux.intel.com/
> > > >>
> > > >> I don't really see the connection.  Even if that series was going
> > > >> forward (I'm not sure it is) there is no ioremap hook there.  There's
> > > >> also no guest->host communication in that series.  The guest doesn't
> > > >> _tell_ the host where the MMIO is, it just declines to run code for
> > > >> devices that it didn't expect to see.
> > > >
> > > > This is a recent version of the above series from tdx github. This is
> > > > a WIP as well and has not been posted to
> > > > the mailing list. Thus, it may be going under revisions as well.
> > > > As per my understanding the above ioremap changes for TDX mark the
> > > > ioremapped pages as shared.
> > > > The guest->host communication happen in the #VE exception handler
> > > > where the guest converts this to a hypercall by invoking TDG.VP.VMCALL
> > > > with an EPT violation set. The host would emulate an MMIO address if
> > > > it gets an VMCALL with EPT violation.
> > > > Please correct me if I am wrong.
> > >
> > > Yeah, TDX does:
> > >
> > > 1. Guest MMIO access
> > > 2. Guest #VE handler (if the access faults)
> > > 3. Guest hypercall->host
> > > 4. Host fixes the fault
> > > 5. Hypercall returns, guest returns from #VE via IRET
> > > 6. Guest retries MMIO instruction
> > >
> > > From what you said, RISC-V appears to do:
> > >
> > > 1. Guest MMIO access
> > > 2. Host MMIO handler
> > > 3. Host handles the fault, returns
> > > 4. Guest retries MMIO instruction
> > >
> > > In other words, this mechanism does the same thing but short-circuits
> > > the trip through #VE and the hypercall.
> > >
> >
> > Yes. Thanks for summarizing the tdx approach.
> >
> > > What happens if this ioremap() hook is not in place?  Does the hardware
> > > (or TSM) generate an exception like TDX gets?  If so, it's probably
> > > possible to move this "notify the TSM" code to that exception handler
> > > instead of needing an ioremap() hook.
> > >
> >
> > We don't have a #VE like exception mechanism in RISC-V.
> >
> > > I'm not saying that it's _better_ to do that, but it would allow you to
> > > get rid of this patch for now and get me to shut up. :)
> > >
> > > > As I said above, the objective here is to notify the TSM where the
> > > > MMIO is. Notifying the host is just an optimization that we choose to
> > > > add. In fact, in this series the KVM code doesn't do anything with
> > > > that information. The commit text probably can be improved to clarify
> > > > that.
> > >
> > > Just to close the loop here, please go take a look at
> > > pgprot_decrypted().  That's where the x86 guest page table bit gets to
> > > tell the hardware that the mapping might cause a #VE and is under the
> > > control of the host.  That's the extent of what x86 does at ioremap() time.
> > >
> > > So, to summarize, we have:
> > >
> > > x86:
> > > 1. Guest page table bit to mark shared (host) vs. private (guest)
> > >    control
> > > 2. #VE if there is a fault on a shared mapping to call into the host
> > >
> > > RISC-V:
> > > 1. Guest->TSM call to mark MMIO vs. private
> > > 2. Faults in the MMIO area are then transparent to the guest
> > >
> >
> > Yup. This discussion raised a very valid design aspect of the CoVE spec.
> > To summarize, we need to investigate whether using PTE bits instead of
> > additional ABI
> > for managing shared/confidential/ioremapped pages makes more sense.
> >
> > Thanks for putting up with my answers and the feedback :).
>
> I think we should re-evaluate the PTE (or software walk) based approach
> for CoVE spec. It is better to keep the CoVE spec as minimal as possible
> and define SBI calls only if absolutely required.
>
> >
> > > That design difference would, indeed, help explain why this patch is
> > > here.  I'm still not 100% convinced that the patch is *required*, but I
> > > at least understand how we arrived here.
>
> Regards,
> Anup

  reply	other threads:[~2023-04-26 13:55 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19 22:16 [RFC 00/48] RISC-V CoVE support Atish Patra
2023-04-19 22:16 ` [RFC 01/48] mm/vmalloc: Introduce arch hooks to notify ioremap/unmap changes Atish Patra
2023-04-20 19:42   ` Lorenzo Stoakes
2023-04-20 22:01     ` Atish Kumar Patra
2023-04-19 22:16 ` [RFC 02/48] RISC-V: KVM: Improve KVM error reporting to the user space Atish Patra
2023-04-19 22:16 ` [RFC 03/48] RISC-V: KVM: Invoke aia_update with preempt disabled/irq enabled Atish Patra
2023-04-19 22:16 ` [RFC 04/48] RISC-V: KVM: Add a helper function to get pgd size Atish Patra
2023-04-19 22:16 ` [RFC 05/48] RISC-V: Add COVH SBI extensions definitions Atish Patra
2023-04-19 22:16 ` [RFC 06/48] RISC-V: KVM: Implement COVH SBI extension Atish Patra
2023-04-19 22:16 ` [RFC 07/48] RISC-V: KVM: Add a barebone CoVE implementation Atish Patra
2023-04-19 22:16 ` [RFC 08/48] RISC-V: KVM: Add UABI to support static memory region attestation Atish Patra
2023-04-19 22:16 ` [RFC 09/48] RISC-V: KVM: Add CoVE related nacl helpers Atish Patra
2023-04-19 22:16 ` [RFC 10/48] RISC-V: KVM: Implement static memory region measurement Atish Patra
2023-04-20 15:17   ` Sean Christopherson
2023-04-21 18:50     ` Atish Kumar Patra
2023-04-19 22:16 ` [RFC 11/48] RISC-V: KVM: Use the new VM IOCTL for measuring pages Atish Patra
2023-04-19 22:16 ` [RFC 12/48] RISC-V: KVM: Exit to the user space for trap redirection Atish Patra
2023-04-19 22:16 ` [RFC 13/48] RISC-V: KVM: Return early for gstage modifications Atish Patra
2023-04-19 22:16 ` [RFC 14/48] RISC-V: KVM: Skip dirty logging updates for TVM Atish Patra
2023-04-19 22:16 ` [RFC 15/48] RISC-V: KVM: Add a helper function to trigger fence ops Atish Patra
2023-04-19 22:16 ` [RFC 16/48] RISC-V: KVM: Skip most VCPU requests for TVMs Atish Patra
2023-04-19 22:16 ` [RFC 17/48] RISC-V : KVM: Skip vmid/hgatp management " Atish Patra
2023-04-19 22:16 ` [RFC 18/48] RISC-V: KVM: Skip TLB " Atish Patra
2023-04-19 22:16 ` [RFC 19/48] RISC-V: KVM: Register memory regions as confidential " Atish Patra
2023-04-19 22:16 ` [RFC 20/48] RISC-V: KVM: Add gstage mapping " Atish Patra
2023-04-19 22:16 ` [RFC 21/48] RISC-V: KVM: Handle SBI call forward from the TSM Atish Patra
2023-04-19 22:16 ` [RFC 22/48] RISC-V: KVM: Implement vcpu load/put functions for CoVE guests Atish Patra
2023-04-19 22:16 ` [RFC 23/48] RISC-V: KVM: Wireup TVM world switch Atish Patra
2023-04-19 22:16 ` [RFC 24/48] RISC-V: KVM: Update timer functionality for TVMs Atish Patra
2023-04-19 22:16 ` [RFC 25/48] RISC-V: KVM: Skip HVIP update " Atish Patra
2023-04-19 22:16 ` [RFC 26/48] RISC-V: Add COVI extension definitions Atish Patra
2023-04-19 22:16 ` [RFC 27/48] RISC-V: KVM: Implement COVI SBI extension Atish Patra
2023-04-19 22:16 ` [RFC 28/48] RISC-V: KVM: Add interrupt management functions for TVM Atish Patra
2023-04-19 22:16 ` [RFC 29/48] RISC-V: KVM: Skip AIA CSR updates for TVMs Atish Patra
2023-04-19 22:16 ` [RFC 30/48] RISC-V: KVM: Perform limited operations in hardware enable/disable Atish Patra
2023-04-19 22:16 ` [RFC 31/48] RISC-V: KVM: Indicate no support user space emulated IRQCHIP Atish Patra
2023-04-19 22:17 ` [RFC 32/48] RISC-V: KVM: Add AIA support for TVMs Atish Patra
2023-04-19 22:17 ` [RFC 33/48] RISC-V: KVM: Hookup TVM VCPU init/destroy Atish Patra
2023-04-19 22:17 ` [RFC 34/48] RISC-V: KVM: Initialize CoVE Atish Patra
2023-04-19 22:17 ` [RFC 35/48] RISC-V: KVM: Add TVM init/destroy calls Atish Patra
2023-04-19 22:17 ` [RFC 36/48] RISC-V: KVM: Read/write gprs from/to shmem in case of TVM VCPU Atish Patra
2023-04-19 22:17 ` [RFC 37/48] RISC-V: Add COVG SBI extension definitions Atish Patra
2023-04-19 22:17 ` [RFC 38/48] RISC-V: Add CoVE guest config and helper functions Atish Patra
2023-04-19 22:17 ` [RFC 39/48] RISC-V: Implement COVG SBI extension Atish Patra
2023-04-19 22:17 ` [RFC 40/48] RISC-V: COVE: Add COVH invalidate, validate, promote, demote and remove APIs Atish Patra
2023-04-19 22:17 ` [RFC 41/48] RISC-V: KVM: Add host side support to handle COVG SBI calls Atish Patra
2023-04-19 22:17 ` [RFC 42/48] RISC-V: Allow host to inject any ext interrupt id to a CoVE guest Atish Patra
2023-04-19 22:17 ` [RFC 43/48] RISC-V: Add base memory encryption functions Atish Patra
2023-04-19 22:17 ` [RFC 44/48] RISC-V: Add cc_platform_has() for RISC-V for CoVE Atish Patra
2023-04-19 22:17 ` [RFC 45/48] RISC-V: ioremap: Implement for arch specific ioremap hooks Atish Patra
2023-04-20 22:15   ` Dave Hansen
2023-04-21 19:24     ` Atish Kumar Patra
2023-04-24 13:48       ` Dave Hansen
2023-04-25  8:00         ` Atish Kumar Patra
2023-04-25 13:10           ` Dave Hansen
2023-04-26  8:02             ` Atish Kumar Patra
2023-04-26 10:30               ` Anup Patel
2023-04-26 13:55                 ` Andrew Bresticker [this message]
2023-04-19 22:17 ` [RFC 46/48] riscv/virtio: Have CoVE guests enforce restricted virtio memory access Atish Patra
2023-04-19 22:17 ` [RFC 47/48] RISC-V: Add shared bounce buffer to support DBCN for CoVE Guest Atish Patra
2023-04-19 22:17 ` [RFC 48/48] drivers/hvc: sbi: Disable HVC console for TVMs Atish Patra
2023-04-19 22:58 ` [RFC 00/48] RISC-V CoVE support Atish Patra
2023-04-20 16:30 ` Sean Christopherson
2023-04-20 19:13   ` Atish Kumar Patra
2023-04-20 20:21     ` Sean Christopherson
2023-04-21 15:35   ` Michael Roth
2023-04-24 12:23 ` Christophe de Dinechin

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=CALE4mHqjvmx-mdHJ8pV5ramCeYz0eOEu75-PHfnh1NWePbthDA@mail.gmail.com \
    --to=abrestic@rivosinc.com \
    --cc=ajones@ventanamicro.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=anup@brainfault.org \
    --cc=apatel@ventanamicro.com \
    --cc=atishp@atishpatra.org \
    --cc=atishp@rivosinc.com \
    --cc=bjorn@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=dave.hansen@intel.com \
    --cc=dylan@rivosinc.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guoren@kernel.org \
    --cc=hch@infradead.org \
    --cc=heiko@sntech.de \
    --cc=jirislaby@kernel.org \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=mchitale@ventanamicro.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=pbonzini@redhat.com \
    --cc=rkanwal@rivosinc.com \
    --cc=sameo@rivosinc.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=urezki@gmail.com \
    --cc=will@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).