From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF1FCC28B28 for ; Sat, 15 Mar 2025 04:54:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC78D280003; Sat, 15 Mar 2025 00:54:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A75B7280002; Sat, 15 Mar 2025 00:54:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 916BE280003; Sat, 15 Mar 2025 00:54:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6F108280002 for ; Sat, 15 Mar 2025 00:54:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E011E1411AC for ; Sat, 15 Mar 2025 04:54:16 +0000 (UTC) X-FDA: 83222568912.01.E265C18 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf08.hostedemail.com (Postfix) with ESMTP id 00689160008 for ; Sat, 15 Mar 2025 04:54:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=mqtd67zN; spf=none (imf08.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742014454; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mQhJm5J645ymleMXzmsLIqdcp5cZsngAWaCVY5IJcSs=; b=gV/KsaWbqF8mPj/ko1t8NyuT7GxaOd9BFXh7RzcnHHYp+Nqerl7RuWz9HTMAXHq4OBMOnD E+YP6huywmrKVy/acYxYE3rOrZHrfPX00eze3RU19VZ9Qp6FoF/hAVNmncXQAjhUHwvoYg ROwWT+oagV055d7mAnAd2dVmsHVuhCQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=mqtd67zN; spf=none (imf08.hostedemail.com: domain of rdunlap@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=rdunlap@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742014454; a=rsa-sha256; cv=none; b=IOEQzuJM9dJC2WlliTNJSKx8dTA/6Mo7gBGvnFtjH9H+8r1gLZn6pcx6mNxmhUGsTpfgF7 bctpyoJHh/s/aaT9sOTQXUzLwIMLT1fHXAAZfFsGxCuUdymXZIrk8pRFMYgLT6tC7h1teJ nir6k9wLb1ngYLvoislIjDGn6hvROtc= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID: Sender:Reply-To:Content-ID:Content-Description; bh=mQhJm5J645ymleMXzmsLIqdcp5cZsngAWaCVY5IJcSs=; b=mqtd67zNyJUoUFSs7XIGr5xFoJ mscSRcTffByeTyIAvzLMxBfoOfWy7K5r3StiTmBZ1Arbty+J7EGX+I0onfk7rxJfjd2Ut6WtZsjVc jE8X4+ML4TKxY5UXsXA4J4chq+AgGvkNgKm7czCQ9ZSVIKNXhiklRwUjiTCbP2CGQp++vmBxiXZ+U yqGAF98jhSOvpcYlzc9/i//rvH51voF9nO+HBq6nY/MOdiYrDmaAZXufutswWt92Orf9JnL78CZEk j+4WDLiz96mKNT/Ow2Frfj5NZhJ1AQAxOA7P2qxk2fy7fpDpkiUwbxRxiGTtRSDWi26lcOaFwIc07 v0WfOg6A==; Received: from [50.53.2.24] (helo=[192.168.254.17]) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1ttJWw-0000000338B-2bOV; Sat, 15 Mar 2025 04:53:51 +0000 Message-ID: <03d69156-1cee-43bc-901b-5f85f3aa7575@infradead.org> Date: Fri, 14 Mar 2025 21:53:41 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/2] compiler_types: Introduce __flex_counter() and family To: Kees Cook , Vlastimil Babka Cc: Miguel Ojeda , "Gustavo A. R. Silva" , Nathan Chancellor , Peter Zijlstra , Nick Desaulniers , Marco Elver , Przemek Kitszel , linux-hardening@vger.kernel.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Bill Wendling , Justin Stitt , Jann Horn , Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Jonathan Corbet , Jakub Kicinski , Yafang Shao , Tony Ambardar , Alexander Lobakin , Jan Hendrik Farr , Alexander Potapenko , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, llvm@lists.linux.dev References: <20250315025852.it.568-kees@kernel.org> <20250315031550.473587-1-kees@kernel.org> Content-Language: en-US From: Randy Dunlap In-Reply-To: <20250315031550.473587-1-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 00689160008 X-Rspamd-Server: rspam08 X-Stat-Signature: p7b18dmdx1gwmifbp5fnt6dccuyezayb X-HE-Tag: 1742014453-285115 X-HE-Meta: U2FsdGVkX18PBQCcMVDZ8Kz5IQHu5TqWWZYLd9v9E6gwkIE9Rr0AQ99Kxi/4S9PxbpjPJ1rXdU0A6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Fyi2wR5CVD2HIvigHNqgjTuvKGnPqDSkbm29Y9wktXfFrVtN65eIDoF6bfCcxeRebiJ1l78f+NdevcCyzOs7enzUgxwBmOUzy06FtWVgjPyG7XsH4d1eQ4z19MOumK+xC2VbpUnyeb7PVuTJBdmhJ7uU88aYaP/fNKbXt45aNyA41xyXc1V8A9Y4wdkC/2xoU7duzISmTw/R7fduh4PI2ndsp4wTonO/CSBn2g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Kees, On 3/14/25 8:15 PM, Kees Cook wrote: > diff --git a/include/linux/overflow.h b/include/linux/overflow.h > index 0c7e3dcfe867..e2b81cb5576e 100644 > --- a/include/linux/overflow.h > +++ b/include/linux/overflow.h > @@ -440,4 +440,40 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) > #define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT) \ > _DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .obj.COUNTER = COUNT, }) > > +/** > + * typeof_flex_counter() - Return the type of the counter variable of a given > + * flexible array member annotated by __counted_by(). > + * @FAM: Pointer to the flexible array member within a given struct. > + * > + * Returns "size_t" if no annotation exists. Please use * Returns: instead so that kernel-doc can make a special doc section for it. Same for patch 2/2. > + */ > +#define typeof_flex_counter(FAM) \ > + typeof(_Generic(__flex_counter(FAM), \ > + void *: (size_t)0, \ > + default: *__flex_counter(FAM))) > + > +/** can_set_flex_counter() - Check if the counter associated with the given Needs a newline between /** and the function name, as in set_flex_counter() below. > + * flexible array member can represent a value. > + * @FAM: Pointer to the flexible array member within a given struct. > + * @COUNT: Value to check against the __counted_by annotated @FAM's counter. > + */ > +#define can_set_flex_counter(FAM, COUNT) \ > + (!overflows_type(COUNT, typeof_flex_counter(FAM))) > + > +/** > + * set_flex_counter() - Set the counter associated with the given flexible > + * array member that has been annoated by __counted_by(). > + * @FAM: Pointer to the flexible array member within a given struct. > + * @COUNT: Value to store to the __counted_by annotated @FAM's counter. > + * > + * This is a no-op if no annotation exists. Count needs to be checked with > + * can_set_flex_counter(FAM, COUNT) before using this function. > + */ > +#define set_flex_counter(FAM, COUNT) \ > +({ \ > + *_Generic(__flex_counter(FAM), \ > + void *: &(size_t){ 0 }, \ > + default: __flex_counter(FAM)) = (COUNT); \ > +}) > + > #endif /* __LINUX_OVERFLOW_H */ -- ~Randy