Re: [PATCH] tpm: track the response read position internally, not via the file offset

From: Jarkko Sakkinen

Date: Thu Nov 19 2026 - 13:13:27 EST


On Fri, Nov 20, 2026 at 12:49:37AM +0700, Rustam Mustafin wrote:
> On Wed, Nov 18, 2026 at 9:33 PM Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
> > I wrote that out of my memory. I did not expect to be exactly out.
> >
> > Block uring.
>
> Hi Jarkko,
>
> I looked at three ways to do it:
>
> 1. ->read_iter and ->write_iter that just return -EINVAL.
>
> Simple, but readv() and single-iovec writev() stop working.

So. What would be the use case for this?

>
> 2. ->read_iter and ->write_iter that keep readv()/writev() working
> and fail with:
>
> if (!is_sync_kiocb(iocb) ||
> (iocb->ki_flags & IOCB_NOWAIT) ||
> (current->flags & PF_IO_WORKER))
> return -EINVAL;
>
> The first check catches normal io_uring reads/writes and AIO. The
> other two are for IORING_OP_READ_MULTISHOT, which uses a sync kiocb.

So given how TPM works (reserved for only one process) I tend to prefer
this. But -EIO should be used. It's as IO failure as it gets.

>
> 3. A new per-request flag set by io_uring and checked by TPM.
>
> Needs io_uring/VFS changes and is harder to backport.
>
> With 2 and 3, vfs_iter_read() callers such as Coda (which forwards
> reads to a file passed in by its userspace daemon) can reach
> tpm_common_read() with their own offset. Today these calls fail,
> because the TPM files have no ->read_iter.

2 is a bug fix, enabling is a feature. I guess this is the confusion.

>
> I have 2 implemented and tested. It would also need a check of *off
> in tpm_common_read(), because of the above.
>
> Which one do you prefer?
>
> Br,
> Rustam


/Jarkko