Re: [PATCH] f2fs: fix the assign logic of iocb

From: Google
Date: Mon Oct 24 2022 - 01:07:40 EST


On Fri, 21 Oct 2022 10:30:46 +0530
Pavan Kondeti <quic_pkondeti@xxxxxxxxxxx> wrote:

> Hi Mukesh,
>
> On Wed, Oct 19, 2022 at 09:47:57PM +0530, Mukesh Ojha wrote:
> > commit 18ae8d12991b ("f2fs: show more DIO information in tracepoint")
> > introduces iocb field in 'f2fs_direct_IO_enter' trace event
> > And it only assigns the pointer and later it accesses its field
> > in trace print log.
> >
> > Fix it by correcting data type and memcpy the content of iocb.
> >
> > Fixes: 18ae8d12991b ("f2fs: show more DIO information in tracepoint")
> > Signed-off-by: Mukesh Ojha <quic_mojha@xxxxxxxxxxx>
> > ---
> > include/trace/events/f2fs.h | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
> > index c6b3724..7727ec9 100644
> > --- a/include/trace/events/f2fs.h
> > +++ b/include/trace/events/f2fs.h
> > @@ -940,7 +940,7 @@ TRACE_EVENT(f2fs_direct_IO_enter,
> > TP_STRUCT__entry(
> > __field(dev_t, dev)
> > __field(ino_t, ino)
> > - __field(struct kiocb *, iocb)
> > + __field_struct(struct kiocb, iocb)
> > __field(unsigned long, len)
> > __field(int, rw)
> > ),
> > @@ -948,17 +948,17 @@ TRACE_EVENT(f2fs_direct_IO_enter,
> > TP_fast_assign(
> > __entry->dev = inode->i_sb->s_dev;
> > __entry->ino = inode->i_ino;
> > - __entry->iocb = iocb;
> > + memcpy(&__entry->iocb, iocb, sizeof(*iocb));
> > __entry->len = len;
> > __entry->rw = rw;
> > ),
> >
>
> Why copy the whole structure (48 bytes)? cache the three members you
> need.

+1. If this only prints ki_pos, ki_flags and ki_ioprio, I recommend you
to save those 3 fields to the entry. It should not expose in-kernel
data structure because it can be changed.

Thank you,

>
> Thanks,
> Pavan


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>