From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-security-module@vger.kernel.org,
tpmdd-devel@lists.sourceforge.net,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [tpmdd-devel] [RFC] tpm2-space: add handling for global session exhaustion
Date: Thu, 19 Jan 2017 07:59:04 -0500 [thread overview]
Message-ID: <1484830744.3140.17.camel@HansenPartnership.com> (raw)
In-Reply-To: <20170119122533.d7h5rgatpwl3qmcl@intel.com>
On Thu, 2017-01-19 at 14:25 +0200, Jarkko Sakkinen wrote:
> On Wed, Jan 18, 2017 at 03:48:09PM -0500, James Bottomley wrote:
> > In a TPM2, sessions can be globally exhausted once there are
> > TPM_PT_ACTIVE_SESSION_MAX of them (even if they're all context
> > saved).
> > The Strategy for handling this is to keep a global count of all the
> > sessions along with their creation time. Then if we see the TPM
> > run
> > out of sessions (via the TPM_RC_SESSION_HANDLES) we first wait for
> > one
> > to become free, but if it doesn't, we forcibly evict an existing
> > one.
> > The eviction strategy waits until the current command is repeated
> > to
> > evict the session which should guarantee there is an available
> > slot.
> >
> > On the force eviction case, we make sure that the victim session is
> > at
> > least SESSION_TIMEOUT old (currently 2 seconds). The wait queue
> > for
> > session slots is a FIFO one, ensuring that once we run out of
> > sessions, everyone will get a session in a bounded time and once
> > they
> > get one, they'll have SESSION_TIMEOUT to use it before it may be
> > subject to eviction.
> >
> > Signed-off-by: James Bottomley <
> > James.Bottomley@HansenPartnership.com>
>
> I didn't yet read the code properly. I'll do a more proper review
> once I have v4 of my patch set together. This comment is solely
> based on your commit message.
>
> I'm just thinking that do we need this complicated timeout stuff
> or could you just kick a session out in LRU fashion as we run
> out of them?
>
> Or one variation of what you are doing: couldn't the session that
> needs a session handle to do something sleep for 2 seconds and then
> take the oldest session? It would have essentially the same effect
> but no waitqueue needed.
>
> Yeah, as I said, this is just commentary based on the description.
If you don't have a wait queue you lose fairness in resource allocation
on starvation. What happens is that you get RC_SESSION_HANDLES and
sleep for 2s and retry. Meanwhile someone frees a session, then next
user grabs it while you were sleeping and when you wake you still get
RC_SESSION_HANDLES. I can basically DoS your process if I understand
this. The only way to make the resource fairly allocated: i.e. the
first person to sleep waiting for a session is the one who gets it when
they wake is to make sure that you wake one waiter as soon as a free
session comes in so probabalistically, they get the session. If you
look, there are two mechanisms for ensuring fairness: one is the FIFO
wait queue (probabalistic) and the other is the reserved session which
really ensures it belongs to you when you wake (deterministic but
expensive, so this is only activated on the penultimate go around).
James
next prev parent reply other threads:[~2017-01-19 13:00 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 20:48 [RFC] tpm2-space: add handling for global session exhaustion James Bottomley
2017-01-19 12:25 ` [tpmdd-devel] " Jarkko Sakkinen
2017-01-19 12:41 ` Jarkko Sakkinen
[not found] ` <o6gdhu$li$1@blaine.gmane.org>
2017-01-27 21:59 ` James Bottomley
2017-01-19 12:59 ` James Bottomley [this message]
2017-01-20 13:40 ` Jarkko Sakkinen
[not found] ` <o6gese$pev$1@blaine.gmane.org>
2017-01-27 22:04 ` James Bottomley
2017-01-27 23:35 ` Jason Gunthorpe
2017-01-27 23:48 ` James Bottomley
2017-01-30 0:52 ` Ken Goldman
2017-01-30 16:04 ` [tpmdd-devel] " James Bottomley
2017-01-30 21:58 ` Jarkko Sakkinen
2017-01-30 22:13 ` James Bottomley
2017-01-31 13:31 ` Jarkko Sakkinen
[not found] ` <o6qog0$30l$1@blaine.gmane.org>
2017-01-31 19:55 ` James Bottomley
-- strict thread matches above, loose matches on Subject: below --
2017-02-09 9:06 Dr. Greg Wettstein
2017-02-09 15:19 ` Jarkko Sakkinen
2017-02-09 19:04 ` Jason Gunthorpe
2017-02-09 19:29 ` James Bottomley
2017-02-09 21:54 ` Jason Gunthorpe
2017-02-10 8:48 ` Jarkko Sakkinen
2017-02-09 19:24 ` James Bottomley
2017-02-09 20:05 ` James Bottomley
2017-02-10 10:03 Dr. Greg Wettstein
2017-02-10 16:46 ` James Bottomley
2017-02-12 20:29 ` Ken Goldman
[not found] ` <OFA049276F.2B32440E-ON852580C3.00742287-852580C3.00748E6B@notes.na.collabserv.com>
2017-02-14 14:38 ` Dr. Greg Wettstein
2017-02-14 16:47 ` James Bottomley
[not found] ` <71dc0e80-6678-a124-9184-1f93c8532d09@linux.vnet.ibm.com>
2017-02-16 20:06 ` Dr. Greg Wettstein
2017-02-16 20:33 ` Jarkko Sakkinen
2017-02-17 9:56 ` Dr. Greg Wettstein
2017-02-17 12:37 ` Jarkko Sakkinen
2017-02-17 22:37 ` Dr. Greg Wettstein
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=1484830744.3140.17.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=tpmdd-devel@lists.sourceforge.net \
/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