All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: David Tolnay <dtolnay@gmail.com>
Cc: Peter Huewe <peterhuewe@gmx.de>,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	linux-integrity@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	virtualization@lists.linux-foundation.org, dgreid@chromium.org,
	apronin@chromium.org
Subject: Re: [PATCH] tpm: Add driver for TPM over virtio
Date: Sun, 24 Feb 2019 08:30:19 -0800	[thread overview]
Message-ID: <1551025819.3106.25.camel@HansenPartnership.com> (raw)
In-Reply-To: <bc11d2e8-1b67-8210-6750-d24d36eb7d87@gmail.com>

On Fri, 2019-02-22 at 18:41 -0800, David Tolnay wrote:
> On 2/22/19 5:34 PM, James Bottomley wrote:
> > On Fri, 2019-02-22 at 16:45 -0800, David Tolnay wrote:
[...]
> > >  It implements the TPM-specific TIS interface (QEMU's tpm_tis.c)
> > > as well as CRB interface (QEMU's tpm_crb.c) which require Linux's
> > > TIS driver (Linux's tpm_tis.c) and CRB driver (Linux's tpm_crb.c)
> > > respectively. Both of those are based on ACPI.
> > 
> > That's right, QEMU implements the device interface emulation, but
> > it passes the actual TPM communication packets to the vTPM outside
> > QEMU.
> 
> Could you clarify what you mean by a TPM communication packet since I
> am less familiar with TPM and QEMU?

Like most standards defined devices, TPMs have a defined protocol, in
this case defined by the trusted computing group.  It's a
request/response model.  The job of the kernel is to expose this
request response packet interface.  The device manufacturers don't get
any flexibility, so their devices have to implement it and the only
freedom they get is how the device is attached to the hardware.

>  I don't see "packet" terminology being used in drivers/char/tpm. Is
> a packet equivalent to a fully formed TPM command / response or is it
> a lower level aspect of the device interface than that?

It's a request/response corresponding to a command and its completion
or error.

> More concretely, would you say that a hypervisor necessarily needs to
> implement TPM device interface emulation (TIS and/or CRB) in order to
> expose a TPM running on the host to its guest OS? I can see QEMU has
> those things.

A hypervisor is needed to implement discovery, and whether its
discovery over a virtual or physical bus, that part is required.

> > > As far as I can tell, QEMU does not provide a mode in which the
> > > tpm_vtpm_proxy driver would be involved *in the guest*.
> > 
> > It doesn't need to.  the vTPM proxy can itself do all of that using
> > the guest Linux kernel.  There's no hypervisor or host
> > involvement.  This is analagous to the vTPM for container use case,
> > except that to get both running in a guest you'd use no
> > containment, so the vtpm client and server run in the guest
> > together:
> > 
> > https://www.kernel.org/doc/html/v4.16/security/tpm/tpm_vtpm_proxy.h
> > tml
> 
> I apologize for still not grasping how this would apply. You bring up
> a vtpm proxy that runs in the guest Linux kernel with no hypervisor
> or host involvement, with the vtpm client and server running in the
> guest together. But host involvement is specifically what we want
> since only the host is trusted to run the software TPM implementation
> or interact with a hardware TPM. I am missing a link in the chain:

Well, in your previous email you asked how you would run the emulator
in the guest.  This is how.  If you're actually not interested in that
use case we don't need to discuss it further.

> - guest userspace makes TPM call (through tpm2-tss or however else);
> - guest kernel receives the call in tpm-dev-common / tpm-interface;
> - tpm-interface delegates to a tpm-chip implementation (which one?
>   vtpm_proxy_tpm_ops?);
> - ???
> - a host daemon triages and eventually performs the TPM operation.
> 
> 
> > > Certainly you could use a vtpm proxy driver *on the host* but
> > > would still need some other TPM driver running in the guest for
> > > communication with the host, possibly virtio. If this second
> > > approach is what you have in mind, let me know but I don't think
> > > it is applicable to the Chrome OS use case.
> > 
> > Actually, the vTPM on-host use case doesn't use the in kernel vtpm
> > proxy driver, it uses a plain unix socket.  That's what the
> > original website tried to explain: you set up swtpm in socket mode,
> > you point the qemu tpm emulation at the socket and you boot up your
> > guest.
> 
> Okay. If I understand correctly, the vTPM on-host use case operates
> through TIS and/or CRB implemented in QEMU and the tpm_tis / tpm_crb
> driver in the guest. Do I have it right?

No, vTPM operates purely at the packet level over various interfaces. 
Microsoft defines an actual network packet interface called socsim, but
this can also run over unix sockets, which is what the current QEMU
uses..

QEMU implements a virtual hardware emulation for discovery, but once
discovered all the packet communication is handed off to the vTPM
socket.

The virtual hardware emulation can be anything we have a driver for. 
TIS is the simplest, which is why I think they used it.  TIS is
actually a simple interface specification, it supports discovery over
anything, but the discovery implemented in standard guest drivers is
over ACPI, OF and PNP.  If you want more esoteric discovery methods, we
also support i2c.  However, that latter is really only for embedded.  I
think QEMU chose TIS because it works seamlessly on both Linux and
Windows guests.


> All of this is what I would like to avoid by using a virtio driver.

How? Discovery is the part that you have to do, whether it's using
emulated physical mechanisms or virtual bus discovery.

If you want to make this more concrete: I once wrote a pure socsim
packet TPM driver:

https://patchwork.ozlabs.org/patch/712465/

Since you just point it at the network socket, it does no discovery at
all and works in any Linux environment that has net.  I actually still
use it because a socsim TPM is easier to debug from the outside. 
However it was 230 lines.  Your device is 460 so that means about half
your driver is actually about discovery.

The only reasons I can see to use a virtual bus is either because its
way more efficient (the storage/network use case) or because you've
stripped down the hypervisor so far that it's incapable of emulating
any physical device (the firecracker use case).

James


  reply	other threads:[~2019-02-24 16:30 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22  2:14 [PATCH] tpm: Add driver for TPM over virtio David Tolnay
2019-02-22  5:51 ` Michael S. Tsirkin
2019-02-22  5:51   ` Michael S. Tsirkin
2019-02-22 21:40   ` David Tolnay
2019-02-22 22:24     ` Michael S. Tsirkin
2019-02-22 22:24       ` Michael S. Tsirkin
2019-02-23  1:23       ` David Tolnay
2019-02-25  9:58   ` Jarkko Sakkinen
2019-02-22 10:26 ` Jarkko Sakkinen
2019-02-22 15:23   ` Michael S. Tsirkin
2019-02-22 15:23     ` Michael S. Tsirkin
2019-02-22 19:31     ` Jarkko Sakkinen
2019-02-22 19:33       ` Jarkko Sakkinen
2019-02-22 21:25         ` Michael S. Tsirkin
2019-02-22 21:25           ` Michael S. Tsirkin
2019-02-22 21:50           ` Jarkko Sakkinen
2019-02-22 22:24             ` David Tolnay
2019-02-22 22:36               ` Jarkko Sakkinen
2019-02-22 23:05                 ` Michael S. Tsirkin
2019-02-22 23:05                   ` Michael S. Tsirkin
2019-02-24  9:33                   ` Jarkko Sakkinen
2019-02-22 20:55       ` Michael S. Tsirkin
2019-02-22 20:55         ` Michael S. Tsirkin
2019-02-22 21:30         ` Jarkko Sakkinen
2019-02-22 10:30 ` Jarkko Sakkinen
2019-02-22 15:30 ` James Bottomley
2019-02-22 21:16   ` Michael S. Tsirkin
2019-02-22 21:16     ` Michael S. Tsirkin
2019-02-22 21:31     ` Jason Gunthorpe
2019-02-22 21:59       ` Jarkko Sakkinen
2019-02-22 22:07         ` Michael S. Tsirkin
2019-02-22 22:07           ` Michael S. Tsirkin
2019-02-22 22:14           ` Jarkko Sakkinen
2019-02-22 22:00   ` David Tolnay
2019-02-22 22:18     ` James Bottomley
2019-02-23  0:45       ` David Tolnay
2019-02-23  1:34         ` James Bottomley
2019-02-23  2:41           ` David Tolnay
2019-02-24 16:30             ` James Bottomley [this message]
2019-02-24 17:51               ` Jarkko Sakkinen
2019-02-24 22:12               ` David Tolnay
2019-02-25  9:55                 ` Jarkko Sakkinen
2019-02-25 15:36                 ` James Bottomley
2019-02-25 19:17                   ` Matthew Garrett
2019-02-25 19:54                     ` Jarkko Sakkinen
2019-02-25 20:20                     ` James Bottomley
2019-02-25 21:00                       ` Matthew Garrett
2019-02-25 21:02                         ` Matthew Garrett
2019-02-25 22:14                         ` James Bottomley
2019-02-25 22:24                           ` Matthew Garrett
2019-02-25 22:32                             ` James Bottomley
2019-02-25 22:43                               ` Matthew Garrett
2019-02-25 22:51                                 ` James Bottomley
2019-02-25 23:02                                   ` Matthew Garrett
2019-02-25 23:09                                     ` James Bottomley
2019-02-25 21:05                       ` Jarkko Sakkinen
2019-02-25 22:24                         ` James Bottomley

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=1551025819.3106.25.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=apronin@chromium.org \
    --cc=dgreid@chromium.org \
    --cc=dtolnay@gmail.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=peterhuewe@gmx.de \
    --cc=virtualization@lists.linux-foundation.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 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.