From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753635AbbCIPoz (ORCPT ); Mon, 9 Mar 2015 11:44:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51130 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbbCIPow (ORCPT ); Mon, 9 Mar 2015 11:44:52 -0400 Message-ID: <1425915854.4675.108.camel@redhat.com> Subject: Re: [PATCH 1/2] move offsetofend() from vfio.h to stddef.h From: Alex Williamson To: Ingo Molnar Cc: Denys Vlasenko , Denys Vlasenko , Andy Lutomirski , Linus Torvalds , Steven Rostedt , Borislav Petkov , "H. Peter Anvin" , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , X86 ML , Linux Kernel Mailing List Date: Mon, 09 Mar 2015 09:44:14 -0600 In-Reply-To: <20150309152822.GA21219@gmail.com> References: <1425912738-559-1-git-send-email-dvlasenk@redhat.com> <20150309145844.GA19511@gmail.com> <20150309152822.GA21219@gmail.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2015-03-09 at 16:28 +0100, Ingo Molnar wrote: > * Denys Vlasenko wrote: > > > On Mon, Mar 9, 2015 at 3:58 PM, Ingo Molnar 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/