From: "Stefan Berger" <stefanb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Jarkko Sakkinen
<jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH v3 09/11] tpm: Driver for supporting multiple emulated TPMs
Date: Tue, 23 Feb 2016 07:09:44 -0500 [thread overview]
Message-ID: <201602231210.u1NCADWB008643@d03av03.boulder.ibm.com> (raw)
In-Reply-To: <20160223102211.GA9474-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 6119 bytes --]
Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> wrote on 02/23/2016
05:22:11 AM:
>
> On Fri, Feb 19, 2016 at 07:42:06AM -0500, Stefan Berger wrote:
> > This patch implements a driver for supporting multiple emulated TPMs
in a
> > system.
> >
> > The driver implements a device /dev/vtpmx that is used to created
> > a client device pair /dev/tpmX (e.g., /dev/tpm10) and a server side
that
> > is accessed using a file descriptor returned by an ioctl.
> > The device /dev/tpmX is the usual TPM device created by the core TPM
> > driver. Applications or kernel subsystems can send TPM commands to it
> > and the corresponding server-side file descriptor receives these
> > commands and delivers them to an emulated TPM.
> >
> > Signed-off-by: Stefan Berger <stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> > ---
> > drivers/char/tpm/Kconfig | 10 +
> > drivers/char/tpm/Makefile | 1 +
> > drivers/char/tpm/tpm-vtpm.c | 543 +++++++++++++++++++++++++++++++
> +++++++++++++
> > include/uapi/linux/Kbuild | 1 +
> > include/uapi/linux/vtpm.h | 38 ++++
> > 5 files changed, 593 insertions(+)
> > create mode 100644 drivers/char/tpm/tpm-vtpm.c
> > create mode 100644 include/uapi/linux/vtpm.h
> >
> > diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> > index 3b84a8b..4c4e843 100644
> > --- a/drivers/char/tpm/Kconfig
> > +++ b/drivers/char/tpm/Kconfig
> > @@ -122,5 +122,15 @@ config TCG_CRB
> > from within Linux. To compile this driver as a module, choose
> > M here; the module will be called tpm_crb.
> >
> > +
> > +struct vtpm_dev {
> > + struct tpm_chip *chip;
> > +
> > + u32 flags; /* public API flags */
> > +
> > + long state;
> > +#define STATE_OPENED_BIT 0
> > +#define STATE_WAIT_RESPONSE_BIT 1 /* waiting for emulator to
> give response */
>
> I'd prefer something like this before declaring the struct:
>
> enum vtpm_dev_states {
> VTPM_DEV_OPENED = BIT(0),
> VTPM_DEV_WAITING_FOR_RESPONSE = BIT(1),
> };
>
> This whole use of set/clear_bit macros when you don't have variable
> number of bits just makes code less transparent.
Though read-modify-writes with the bit ops are atomic and need no spinlock
protection to avoid concurrency mess. Now we would need a spinlock for
such ops.
>
> > +
> > + spinlock_t buf_lock; /* lock for buffers */
> > +
> > + wait_queue_head_t wq;
> > +
> > + size_t req_len; /* length of queued TPM request */
> > + size_t resp_len; /* length of queued TPM response */
> > + u8 buffer[TPM_BUFSIZE]; /* request/response buffer */
>
> I'd use alloc_page() with GFP_USERHIGH in order to be a better citizen
> in 32-bit environments. You can kmap() it when you need it.
>
> > +};
> > +
> > +
> > +static void vtpm_delete_device_pair(struct vtpm_dev *vtpm_dev);
> > +
> > +/*
> > + * Functions related to 'server side'
> > + */
> > +
> > +/**
> > + * vtpm_fops_read - Read TPM commands on 'server side'
> > + *
> > + * Return value:
> > + * Number of bytes read or negative error code
> > + */
> > +static ssize_t vtpm_fops_read(struct file *filp, char __user *buf,
> > + size_t count, loff_t *off)
> > +{
> > + struct vtpm_dev *vtpm_dev = filp->private_data;
> > + size_t len;
> > + int sig, rc;
> > +
> > + sig = wait_event_interruptible(vtpm_dev->wq, vtpm_dev->req_len !=
0);
> > + if (sig)
> > + return -EINTR;
> > +
> > + spin_lock(&vtpm_dev->buf_lock);
> > +
> > + len = vtpm_dev->req_len;
> > +
> > + if (count < len) {
> > + spin_unlock(&vtpm_dev->buf_lock);
> > + pr_debug("Invalid size in recv: count=%zd, req_len=%zd\n",
> > + count, len);
> > + return -EIO;
> > + }
> > +
> > + rc = copy_to_user(buf, vtpm_dev->buffer, len);
> > + memset(vtpm_dev->buffer, 0, len);
> > + vtpm_dev->req_len = 0;
>
> I saw already Jason's comment but maybe you could just use a mutex
> instead of a spinlock?
I'll let Jason respond to it whether it's the difference between spinlock
and mutex or just no locking at all. If no locking, I'd be inclined to
work with two buffers, one for requests and one for responses.
> > +
> > +/*
> > + * Called when core TPM driver reads TPM responses from 'server side'
> > + *
> > + * Return value:
> > + * Number of TPM response bytes read, negative error value
otherwise
> > + */
> > +static int vtpm_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t
count)
> > +{
> > + struct vtpm_dev *vtpm_dev = chip->vendor.priv;
> > + int sig;
> > + size_t len;
> > +
> > + if (!vtpm_dev)
> > + return -EIO;
> > +
> > + /* wait for response or responder gone */
> > + sig = wait_event_interruptible(vtpm_dev->wq,
> > + (vtpm_dev->resp_len != 0
> > + || !test_bit(STATE_OPENED_BIT, &vtpm_dev->state)));
> > +
> > + if (sig)
> > + return -EINTR;
With us not operating this driver in interrupt mode, we don't need the
wait_event_interruptible if we make another change further below:
> > +
> > +static u8 vtpm_tpm_op_status(struct tpm_chip *chip)
> > +{
> > + return 0;
> > +}
I modified this to
static u8 vtpm_tpm_op_status(struct tpm_chip *chip)
{
return (chip->resp_len) ? VTPM_REQ_COMPLETE_FLAG : 0;
}
> > +
> > +static bool vtpm_tpm_req_canceled(struct tpm_chip *chip, u8 status)
> > +{
> > + return (status == 0);
> > +}
This will have to remain like this.
> > +
> > +static const struct tpm_class_ops vtpm_tpm_ops = {
> > + .recv = vtpm_tpm_op_recv,
> > + .send = vtpm_tpm_op_send,
> > + .cancel = vtpm_tpm_op_cancel,
> > + .status = vtpm_tpm_op_status,
> > + .req_complete_mask = 0,
> > + .req_complete_val = 0,
.req_complete_mask = VTPM_REQ_COMPLETE_FLAG,
.req_complete_val = VTPM_REQ_COMPLETE_FLAG,
with
#define VTPM_REQ_COMPLETE_FLAG BIT(0)
Agreed?
Stefan
[-- Attachment #1.2: Type: text/html, Size: 9332 bytes --]
[-- Attachment #2: Type: text/plain, Size: 413 bytes --]
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
[-- Attachment #3: Type: text/plain, Size: 192 bytes --]
_______________________________________________
tpmdd-devel mailing list
tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel
next prev parent reply other threads:[~2016-02-23 12:09 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-19 12:41 [PATCH v3 00/11] Multi-instance vTPM driver Stefan Berger
2016-02-19 12:41 ` [PATCH v3 01/11] tpm: fix the cleanup of struct tpm_chip Stefan Berger
[not found] ` <1455885728-10315-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-19 12:41 ` [PATCH v3 02/11] tpm: Get rid of chip->pdev Stefan Berger
[not found] ` <1455885728-10315-3-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:25 ` Jarkko Sakkinen
2016-02-19 12:42 ` [PATCH v3 03/11] tpm: Get rid of devname Stefan Berger
[not found] ` <1455885728-10315-4-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:19 ` Jason Gunthorpe
[not found] ` <20160222181929.GB22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-22 19:42 ` Jarkko Sakkinen
[not found] ` <20160222194202.GC32667-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 19:58 ` Jason Gunthorpe
[not found] ` <20160222195816.GL22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-22 20:34 ` Jason Gunthorpe
2016-02-23 0:22 ` Stefan Berger
2016-02-19 12:42 ` [PATCH v3 04/11] tpm: Provide strong locking for device removal Stefan Berger
[not found] ` <1455885728-10315-5-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 21:08 ` Jarkko Sakkinen
[not found] ` <20160222210844.GA3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:20 ` Jason Gunthorpe
[not found] ` <20160222222017.GC27228-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 19:40 ` Jarkko Sakkinen
[not found] ` <20160223194014.GA5241-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-23 19:52 ` Jason Gunthorpe
[not found] ` <20160223195246.GC389-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 20:36 ` Jarkko Sakkinen
2016-02-23 20:43 ` Jarkko Sakkinen
2016-02-19 12:42 ` [PATCH v3 05/11] tpm: Get rid of module locking Stefan Berger
[not found] ` <1455885728-10315-6-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:22 ` Jason Gunthorpe
[not found] ` <20160222182245.GC22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 0:26 ` Stefan Berger
2016-02-22 21:11 ` Jarkko Sakkinen
[not found] ` <20160222211141.GB3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:15 ` Jason Gunthorpe
2016-02-19 12:42 ` [PATCH v3 06/11] tpm: Split out the devm stuff from tpmm_chip_alloc Stefan Berger
[not found] ` <1455885728-10315-7-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:24 ` Jason Gunthorpe
2016-02-22 21:14 ` Jarkko Sakkinen
[not found] ` <20160222211414.GC3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:13 ` Jason Gunthorpe
[not found] ` <20160222221328.GA27228-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 0:45 ` Stefan Berger
2016-02-23 11:31 ` Jarkko Sakkinen
2016-02-19 12:42 ` [PATCH v3 07/11] tpm: Replace device number bitmap with IDR Stefan Berger
[not found] ` <1455885728-10315-8-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:06 ` Jason Gunthorpe
[not found] ` <201602230116.u1N1G4iu012263@d03av02.boulder.ibm.com>
[not found] ` <201602230116.u1N1G4iu012263-nNA/7dmquNI+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23 2:16 ` Jason Gunthorpe
[not found] ` <20160223021606.GC26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 23:04 ` Stefan Berger
[not found] ` <201602232305.u1NN521L020589@d03av01.boulder.ibm.com>
[not found] ` <201602232305.u1NN521L020589-Rn83F4s8Lwc+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23 23:18 ` Jason Gunthorpe
[not found] ` <20160222190629.GE22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 1:15 ` Stefan Berger
2016-02-23 2:16 ` Stefan Berger
[not found] ` <201602230217.u1N2HIJT003183@d03av05.boulder.ibm.com>
[not found] ` <201602230217.u1N2HIJT003183-3MP/CPU4Muo+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23 2:18 ` Jason Gunthorpe
2016-02-19 12:42 ` [PATCH v3 08/11] tpm: Introduce TPM_CHIP_FLAG_VIRTUAL Stefan Berger
[not found] ` <1455885728-10315-9-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:19 ` Jason Gunthorpe
[not found] ` <20160222191922.GH22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 1:20 ` [PATCH v3 08/11] tpm: IntroduceTPM_CHIP_FLAG_VIRTUAL Stefan Berger
2016-02-23 1:21 ` Stefan Berger
[not found] ` <201602230121.u1N1LYk2024786@d01av01.pok.ibm.com>
[not found] ` <201602230121.u1N1LYk2024786-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23 2:05 ` Jason Gunthorpe
[not found] ` <20160223020515.GA26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 3:40 ` Stefan Berger
[not found] ` <201602230116.u1N1Ghac006778@d01av05.pok.ibm.com>
[not found] ` <201602230116.u1N1Ghac006778-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23 2:06 ` Jason Gunthorpe
2016-02-19 12:42 ` [PATCH v3 09/11] tpm: Driver for supporting multiple emulated TPMs Stefan Berger
[not found] ` <1455885728-10315-10-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:27 ` Jason Gunthorpe
[not found] ` <20160222192741.GI22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 1:45 ` Stefan Berger
[not found] ` <201602230142.u1N1gSuF029481@d01av05.pok.ibm.com>
[not found] ` <201602230142.u1N1gSuF029481-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23 2:17 ` Jason Gunthorpe
[not found] ` <20160223021730.GD26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-24 23:10 ` Stefan Berger
[not found] ` <201602242306.u1ON6qGP030251-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-25 13:17 ` Jarkko Sakkinen
[not found] ` <20160225131732.GA20860-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-25 14:12 ` Stefan Berger
[not found] ` <201602251409.u1PE98LH012367@d01av05.pok.ibm.com>
[not found] ` <201602251409.u1PE98LH012367-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-25 17:39 ` Jason Gunthorpe
[not found] ` <20160225173956.GA1407-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-25 18:42 ` Stefan Berger
[not found] ` <201602251842.u1PIgEuL014249@d03av03.boulder.ibm.com>
[not found] ` <201602251842.u1PIgEuL014249-MijUUJkLaQs+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-25 20:31 ` Jason Gunthorpe
[not found] ` <20160225203117.GA22984-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-25 22:11 ` Stefan Berger
2016-02-23 10:22 ` Jarkko Sakkinen
[not found] ` <20160223102211.GA9474-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-23 12:09 ` Stefan Berger [this message]
[not found] ` <201602231210.u1NCAD6D017196@d01av03.pok.ibm.com>
[not found] ` <201602231210.u1NCAD6D017196-CUdSWdNILC7ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23 18:36 ` Jarkko Sakkinen
2016-02-19 12:42 ` [PATCH v3 10/11] tpm: Initialize TPM and get durations and timeouts Stefan Berger
2016-02-19 12:42 ` [PATCH v3 11/11] A test program for vTPM device creation Stefan Berger
2016-02-22 19:20 ` [PATCH v3 00/11] Multi-instance vTPM driver Jarkko Sakkinen
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=201602231210.u1NCADWB008643@d03av03.boulder.ibm.com \
--to=stefanb-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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 NNTP newsgroup(s).