Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1488663pxk; Fri, 18 Sep 2020 14:02:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeUD9IbeAvI6FOjKMnn31ocFOSPLiHSsYs5cnVzfNACewfCb9e1KA6HvQY94IbWaK0QEU8 X-Received: by 2002:a50:a694:: with SMTP id e20mr40384763edc.114.1600462937997; Fri, 18 Sep 2020 14:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600462937; cv=none; d=google.com; s=arc-20160816; b=O8nHwwq5Y16H3z0rCUPGYwaoePnBLxySqSTKMlaQvdduOa1PyguVv9m/PxlB/TKUB9 rmRU4Tv0/aX81rZXnyWyLwZzdtnlxD9rSTFlaNk2rq53Q/CDb7DRHRvW6w6ojMVBQjCL gIgRDyku2xhEdSe/V23j7+apxouNA92Xluuuv6f/TJIw4za2T7d6iOG3sxzWjU5R4Mce 1lom6Eaa6msXwBM4d2tcNNl9EDMN1YJ3ZRXv53IDnlbW0k47Ev4+oZmwzTmK5Ju6pW09 7DT+iHTrNiCtaXkZ1b2hqdcq5JQskzdmBqXwjw4x065C5Qpczs6yawKxqzKltkz3uyr0 1m6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:sender:dkim-signature; bh=ZJ8zmvc17bX9xj6+//ug0LM49mqv1RsrDk1L3tNk8ec=; b=XJq1I0cK1ZP0NsgZc1xynfuZnI2wyFlSX1zF/wy7oJIwwJ+9hvs8kpWOGMs4mtI4Ok J0KduRYRmdyDjx1oZ6JEX0sVK5ytYVZj3tIEciWpViCp4dI7t/NqtmjthUZVMtg9Q+qC ORbKaGeLo9qiYyueLCVXpA4IzPwgGERaQpVdyEhqSiNz5XJypjA49kHbuaCNpiejDXgO 2b/mfcritCRn6Gx2xnE4I17eYaL09dygiC7bJWbW2uNQ9GWSeIodvyfzgPXAQSifN6EJ d1oRjoUGSb0Uc3pozPGkx9W8HiKIl1ltT37vKLQcA6NCsOEtGI9LgxFLHoJ0ZZstezZr eY/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iy16vZfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si3077850ejz.365.2020.09.18.14.01.54; Fri, 18 Sep 2020 14:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iy16vZfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbgIRVAy (ORCPT + 99 others); Fri, 18 Sep 2020 17:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgIRVAx (ORCPT ); Fri, 18 Sep 2020 17:00:53 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31FDC0613CE for ; Fri, 18 Sep 2020 14:00:53 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id cy2so3704979qvb.0 for ; Fri, 18 Sep 2020 14:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZJ8zmvc17bX9xj6+//ug0LM49mqv1RsrDk1L3tNk8ec=; b=iy16vZfUztyOxKq/IfHgI7kJQtwerpgo53nlcxG4i0DEjyExYJZzcnvYLRZ7dv41C/ uaQhCPGAqENb++afLCD1je++48JWOwmrzYv5ZAFoyTwgXdm9/MfkK+nNwmlrqsPEUIFS zpCLZ5gN6euxSAl7cguwqsDnmWIOHXSTa7tWW9LroF3wpSYyN9+nqnEuCdJHyxsWH8b4 B3L5cm6Ix6jRaOz5BL3uee+vaatoD1sR8m0nUX1jABVjFRbamQg1/5dhtEb+DPXQbdfa CXkwTnbSwjfJoV7dqbHFgbgUyf/wpRRr1YFNZiUoCyNmUm7jcQCOJ/xUpUVxo8z42uUm p+Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ZJ8zmvc17bX9xj6+//ug0LM49mqv1RsrDk1L3tNk8ec=; b=nT3k7oD0Tml6S9O9a2xlvYPzCjVzidxMXSTkqoswdUc8T742etVV8/xpMXbfQcinm8 e+pMQygpbflA1Me4p+dd1n7VW1hbH6DO860UBukmN2gTJJHbUlSMWaPTdqkV7DvWt36N ia6j52io/ancPAW+myEPU0x5MTVOlYOmWKdawK7V6KcAryacv9VknEng0yNF466mygz2 F0WXD6uSL44soYXipvcOPLB8UZ3L+5lnkO9RTSPEYemnp/o/PQI3UbVpXDynkRISvXkL v0DZIpd3aKSayLJCm/rHaHCvj9hjazVpWwMsKIO3OU/XR/r2S4ujIRzGeOX0IH7anku1 BKRg== X-Gm-Message-State: AOAM532UNq7l4gWi80CxCT6iFVI3C71ZIm3yFPOpZuquDRE/l+gHxIzH VTXkhB76vH/iohTS/3Ch/m0= X-Received: by 2002:a0c:8246:: with SMTP id h64mr19332976qva.54.1600462852729; Fri, 18 Sep 2020 14:00:52 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id y69sm2877429qkb.52.2020.09.18.14.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 14:00:52 -0700 (PDT) Sender: Arvind Sankar From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 18 Sep 2020 17:00:50 -0400 To: Linus Torvalds Cc: Arvind Sankar , Matthew Wilcox , "Gustavo A. R. Silva" , Dennis Zhou , Tejun Heo , Christoph Lameter , Linux-MM , Linux Kernel Mailing List , Kees Cook Subject: Re: [GIT PULL] percpu fix for v5.9-rc6 Message-ID: <20200918210050.GA2953017@rani.riverdale.lan> References: <20200917204514.GA2880159@google.com> <20200918162305.GB25599@embeddedor> <20200918193426.GA15213@embeddedor> <20200918200252.GH32101@casper.infradead.org> <20200918202909.GA2946008@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2020 at 01:40:44PM -0700, Linus Torvalds wrote: > On Fri, Sep 18, 2020 at 1:29 PM Arvind Sankar wrote: > > > > In general (i.e. outside the implementation of the macro itself), what > > is the preferred way of getting the size of just the header? > > 1) offsetof(typeof(s),flex) > > 2) struct_size(s, flex, 0) > > I think those two should end up being equivalent. Yeah, but it would be good to standardize on one of them. > > > 3) sizeof(s) > > This works right now, but exactly *because* it works, we're not seeing > the questionable cases. > > Of course, _also_ exactly because it just silently works, I also don't > know if there may be thousands of perfectly fine uses where people > really do want the header, and a "sizeof()" is simpler than > alternatives 1-2. > > It's possible that there really are a lot of "I want to know just the > header size" cases. It sounds odd, but I could _imagine_ situations > like that, even though no actual case comes to mind. I'm asking because I just added an instance of (3) and want to know if I should change it :) The case was when you have a function that got passed a pointer and a size, and wants to verify that the size covers the structure before accessing its fields. If the function only needs the "fixed" fields, it feels a little unnatural to use (1) or (2) when the flex member is otherwise not going be accessed at all. > > > 4) new macro that's easier to read than 1 or 2, but makes it clear > > what you're doing? > > I don't think this would have any real advantage, would it? The advantage is documenting that you do mean the header size, i.e. something like struct_header_size(s). > > Now what might be good is if we can make "struct_size()" also actually > verify that the member that is passed in is that last non-sized > member. I'm not sure how to do that. > > I know how to check that it's *not* that last unsized member (just do > "sizeof(s->flex)", and it should error), but I don't see how to assert > the reverse of that). > > Because that kind of "yes, we actually pass in the right member" check > would be good to have too. > > Linus You could just assert that offsetof(typeof(s),flex) == sizeof(s), no? It would also make sure that someone doesn't try to use struct_size() with a 1-sized array member.