linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Alexei Starovoitov <ast@plumgrid.com>,
	Will Drewry <wad@chromium.org>, Kees Cook <keescook@chromium.org>,
	X86 ML <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] move offsetofend() from vfio.h to stddef.h
Date: Mon, 09 Mar 2015 09:44:14 -0600	[thread overview]
Message-ID: <1425915854.4675.108.camel@redhat.com> (raw)
In-Reply-To: <20150309152822.GA21219@gmail.com>

On Mon, 2015-03-09 at 16:28 +0100, Ingo Molnar wrote:
> * Denys Vlasenko <vda.linux@googlemail.com> wrote:
> 
> > On Mon, Mar 9, 2015 at 3:58 PM, Ingo Molnar <mingo@kernel.org> wrote:
> > >> -/**
> > >> - * offsetofend(TYPE, MEMBER)
> > >> - *
> > >> - * @TYPE: The type of the structure
> > >> - * @MEMBER: The member within the structure to get the end offset of
> > >> - *
> > >> - * Simple helper macro for dealing with variable sized structures passed
> > >> - * from user space.  This allows us to easily determine if the provided
> > >> - * structure is sized to include various fields.
> > >> - */
> > >> -#define offsetofend(TYPE, MEMBER) \
> > >> -     (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
> > >
> > > So I like it, and because it is not particularly trivial when to use
> > > this primitive it was explained nicely in a description in the vfio.h
> > > version.
> > >
> > > But you lost that nice description during the code move!!
> > 
> > That description was clearly specific to how that macro is used in
> > drivers/vfio/*.c, along the lines of
> > 
> >                 minsz = offsetofend(struct vfio_eeh_pe_op, op);
> 
> Hm, but here 'minsz' == sizeof(struct vfio_eeh_pe_op), so the vfio 
> usage does not seem to be justified.
> 
> >                 if (copy_from_user(&op, (void __user *)arg, minsz))
> >                         return -EFAULT;
> >                 if (op.argsz < minsz || op.flags)
> >                         return -EINVAL;
> > 
> > But the macro is generic, it has many other uses besides this one.
> 
> So I might be missing something, but what generic uses does it have, 
> beyond structures that have some rare size related weirdness, such as 
> alignment attributes? In 99% of the cases:
> 
>    sizeof(struct) == offsetofend(struct, last_member)
> 
> right?

The idea in the vfio code is to allow the structure to evolve over time
while maintaining compatibility.  We effectively create a header in the
structure with the base functionality and flags and structure size can
tell us what optional fields are present.  A better examples is
drivers/vfio/pci/vfio_pci.c:vfio_pci_ioctl(), particularly
VFIO_DEVICE_SET_IRQS where we read what's being provided in the "header"
and then read beyond the minimum structure size if directed.  Thanks,

Alex

> > Nevertheless, I can resend a version where comment survives if you 
> > want...
> 
> So maybe extend it to a description that you think describes its uses 
> correctly? People will keep wondering about when to use this.
> 
> Thanks,
> 
> 	Ingo
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/




  parent reply	other threads:[~2015-03-09 15:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 14:52 [PATCH 1/2] move offsetofend() from vfio.h to stddef.h Denys Vlasenko
2015-03-09 14:52 ` [PATCH 2/2 v2] x86: make 32-bit "emergency stack" better documented Denys Vlasenko
2015-03-09 15:16   ` Andy Lutomirski
2015-03-14 16:00   ` Pavel Machek
2015-03-14 17:24     ` Brian Gerst
2015-03-16 12:10   ` [tip:x86/asm] x86/asm/entry/32: Document the 32-bit SYSENTER " emergency stack" better tip-bot for Denys Vlasenko
2015-03-17  8:46   ` tip-bot for Denys Vlasenko
2015-03-09 14:58 ` [PATCH 1/2] move offsetofend() from vfio.h to stddef.h Ingo Molnar
2015-03-09 15:15   ` Denys Vlasenko
2015-03-09 15:28     ` Ingo Molnar
2015-03-09 15:30       ` Andy Lutomirski
2015-03-09 15:45         ` Ingo Molnar
2015-03-09 15:44       ` Alex Williamson [this message]
2015-03-09 16:16 ` Linus Torvalds
2015-03-16 12:10 ` [tip:x86/asm] include/stddef.h: Move offsetofend() from vfio.h to a generic kernel header tip-bot for Denys Vlasenko
2015-03-17  8:46 ` tip-bot for Denys Vlasenko

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=1425915854.4675.108.camel@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=ast@plumgrid.com \
    --cc=bp@alien8.de \
    --cc=dvlasenk@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vda.linux@googlemail.com \
    --cc=wad@chromium.org \
    --cc=x86@kernel.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).