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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B29B9CD5BC9 for ; Mon, 25 May 2026 16:24:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DECA610E3B0; Mon, 25 May 2026 16:24:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.b="VZHNJ2GT"; dkim-atps=neutral Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F8B610E3B0 for ; Mon, 25 May 2026 16:24:12 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-44b330c5cc6so7448748f8f.1 for ; Mon, 25 May 2026 09:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1779726251; x=1780331051; darn=lists.freedesktop.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WThGrJlj0+d9TTzzXLAp8aZigkvM5HszOOE/MfwSIgg=; b=VZHNJ2GTrl43XFDDSt9YfqTICh80PrFMFg2kLEQCoEUGMDLoNCvANX0XPmCJFg71j+ JPL1y+JcB0IF3oqHslsDrCAHCGSSoA/qepLvJUw/xxAeFReDhC5JyG1IAXoB6SM/ww4j 3SPj70IoeFKHx0iNO/d/yMq4Lb8DKSzYolG1QRyUVrSVqWyp3WgyrFWm24q+hs1eMhpm 4IiU3H86re1AB90ThjoUjNtM+X6Ux0L6AVfQ9Vhl0WyQcOm1LnRLZaISvHiLvswOKmQH 8M9IDEiZ38gwN2qzwHnRoYDQcetU566KapQi/hFdJFU9oKwkZDjQtXk2BGYouocCEO+Y HdQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779726251; x=1780331051; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WThGrJlj0+d9TTzzXLAp8aZigkvM5HszOOE/MfwSIgg=; b=s9pxsXV4YJWHWs8EMDIyBKG319soNKKPUhwXlR+dMSJVntXzKPTjAN9Sa1/L032iSQ vprPN7g2YmpzUgoCA8j849tlTNSjLibhs8vkw4cK9J+oMcEN0kS0yhs3fjJaEUkXv0ku RmjbZLdcOcsciI+CKIDXH777HzUNlVGNapBVLTqPQctb5SZ0ij6k+iBFtn/Tc5/mJUp7 bhJglz1SuwfMTeTHXe6o3Z4Gd8d7cvDAlbU7Zh2tHVZyQLwwUXbR5fVVwNla5E27Da3L Xh/mo82mFRFl3z9UMyHE9792e/NTFLaYYQrokfvcuPG6oYLas6jvAftP80+nFDJudemU pcmQ== X-Forwarded-Encrypted: i=1; AFNElJ+ryqrAsCQTCn5GfomL1n+JeVm8GPKJP0qVIzqeYr5zdddsT2+cX6WOY2vCuhHgWndcExEBHMpFxII=@lists.freedesktop.org X-Gm-Message-State: AOJu0YwZPptydSj85TYiK/bNhOfL/gEqcDptQ1Lcuhz+ziyVDjj9vriV WjCP8vGW5MaPIlVCOR7Y7cShhlxtoHL28rXmyjzNTa7F9lWFgaysr2afGwVPD8N3HiM= X-Gm-Gg: Acq92OHP/LyRoSc8Uv/snOQefsgxCddUGkh+d7Rq0UtyFqBWS3GDQ28smFjbqR5Drz4 xheRGAEwj/Fuw6dZZW6kC6xE1yR4fZUg/hLahsZQZ2jk4qaH4Fhdyz+kUJ6Iba66Lw4x6gkEDNZ e+9CYfmLCbXI1QeF6igwfdtZETuFRkOxGZn5EbMZlvNMidfZIB44uYcGUjKMKtRTtAjaAYj1o65 XO/ydos8ui1dkaYtSXR3jRs8moR8hlHycrPfMWUSANOtNvhqnWj1KQRXkBiJMh7JaJesgSAp8rS C34MwxHT5ENu7FUHo4KdLG+7IWUZuSgKejYfL4AXcrYEfpKH/38cJKijODomCEo5At8SNoGn1ra Uk4+pdutNzmUGCCNloF31K7NYW//gGCw1NQWO+1JyEjhhxmUrkkHpi5zZmzuR+Rquu6T0FqXXNb FHXGh+g2EUy1FOY10qbRzFebH3Fh2NTT3hXAVcPMz+vWINAKd3i+8z/z4dWPl0rxhTAvpCWzol7 gnryz7QnqP5SoD7H5drXrxV+ov3Qm+F8wW4fqH33jv29f7VSw/vDii8irxw3JlSiRL7hg== X-Received: by 2002:a05:6000:26cf:b0:45e:b215:12e9 with SMTP id ffacd0b85a97d-45eb368903emr24724531f8f.6.1779726250728; Mon, 25 May 2026 09:24:10 -0700 (PDT) Received: from ?IPV6:2a00:1028:838d:271e:8e3b:4aff:fe4c:a100? (dynamic-2a00-1028-838d-271e-8e3b-4aff-fe4c-a100.ipv6.o2.cz. [2a00:1028:838d:271e:8e3b:4aff:fe4c:a100]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d47b82sm28202483f8f.19.2026.05.25.09.24.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 09:24:10 -0700 (PDT) Message-ID: <4e54ae4a-4f7b-451d-9b37-97f30b8fefba@suse.com> Date: Mon, 25 May 2026 18:24:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 07/11] moduleparam: Route DEFINE_KERNEL_PARAM_OPS get pointer via _Generic To: Kees Cook Cc: Luis Chamberlain , Pengpeng Hou , Richard Weinberger , Anton Ivanov , Johannes Berg , "Rafael J. Wysocki" , Len Brown , Corey Minyard , Gabriel Somlo , "Michael S. Tsirkin" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Bjorn Helgaas , Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Greg Kroah-Hartman , Jiri Slaby , Alan Stern , Jason Wang , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Jason Baron , Jim Cromie , Tiwei Bie , Benjamin Berg , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , "David E. Box" , "Maciej W. Rozycki" , Srinivas Pandruvada , Peter Zijlstra , Heiko Carstens , Vasily Gorbik , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vinod Koul , Frank Li , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Andy Shevchenko , Georgia Garcia , kvm@vger.kernel.org, dmaengine@vger.kernel.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, linux-acpi@vger.kernel.org, openipmi-developer@lists.sourceforge.net, qemu-devel@nongnu.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20260521133315.work.845-kees@kernel.org> <20260521133326.2465264-7-kees@kernel.org> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260521133326.2465264-7-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 5/21/26 3:33 PM, Kees Cook wrote: > Make the DEFINE_KERNEL_PARAM_OPS family route their _get argument to > either .get (struct seq_buf *) or .get_str (char *) at compile time > based on the pointer's actual function signature. Two helper macros > do the routing: > > _KERNEL_PARAM_OPS_GET - return the pointer if it has the seq_buf > signature, otherwise NULL of that type > _KERNEL_PARAM_OPS_GET_STR - mirror image for the char * signature > > Both use _Generic; only the two valid function-pointer types are > listed, so any third-party type is a compile error rather than > silently falling through. > > Now a callback whose body has been migrated from char * to struct > seq_buf * needs no change at its kernel_param_ops initialization site, > because the macro picks up the new type automatically and assigns to > the correct field. > > Signed-off-by: Kees Cook > --- > include/linux/moduleparam.h | 33 ++++++++++++++++++++++++++------- > 1 file changed, 26 insertions(+), 7 deletions(-) > > diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h > index c52120f6ac28..795bc7c654ef 100644 > --- a/include/linux/moduleparam.h > +++ b/include/linux/moduleparam.h > @@ -85,15 +85,32 @@ struct kernel_param_ops { > * > * static DEFINE_KERNEL_PARAM_OPS(my_ops, my_set, my_get); > * > - * Routing the @_set and @_get function pointers through the macro > - * (rather than naming the struct fields at every call site) lets the > - * field layout change in one place when callbacks are migrated to a > - * new signature. > + * @_get may be either of: > + * int (*)(struct seq_buf *, const struct kernel_param *) (seq_buf) > + * int (*)(char *, const struct kernel_param *) (legacy) > + * > + * The macro uses _Generic to route the function pointer to the > + * matching field (.get or .get_str) at compile time, leaving the > + * other field NULL. Each helper matches the wrong prototype signature > + * and returns NULL, falling through to the default branch otherwise; > + * if @_get has neither expected signature the assignment to the > + * fields gets a normal compile-time type-mismatch error. > */ > +#define _KERNEL_PARAM_OPS_GET(_get) \ > + _Generic((_get), \ > + int (*)(char *, const struct kernel_param *): NULL, \ > + default: (_get)) > + > +#define _KERNEL_PARAM_OPS_GET_STR(_get) \ > + _Generic((_get), \ > + int (*)(struct seq_buf *, const struct kernel_param *): NULL, \ > + default: (_get)) > + > #define DEFINE_KERNEL_PARAM_OPS(_name, _set, _get) \ > const struct kernel_param_ops _name = { \ > .set = (_set), \ > - .get_str = (_get), \ > + .get = _KERNEL_PARAM_OPS_GET(_get), \ > + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ > } > > /* As DEFINE_KERNEL_PARAM_OPS, with KERNEL_PARAM_OPS_FL_NOARG set. */ > @@ -101,14 +118,16 @@ struct kernel_param_ops { > const struct kernel_param_ops _name = { \ > .flags = KERNEL_PARAM_OPS_FL_NOARG, \ > .set = (_set), \ > - .get_str = (_get), \ > + .get = _KERNEL_PARAM_OPS_GET(_get), \ > + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ > } > > /* As DEFINE_KERNEL_PARAM_OPS, with an additional .free callback. */ > #define DEFINE_KERNEL_PARAM_OPS_FREE(_name, _set, _get, _free) \ > const struct kernel_param_ops _name = { \ > .set = (_set), \ > - .get_str = (_get), \ > + .get = _KERNEL_PARAM_OPS_GET(_get), \ > + .get_str = _KERNEL_PARAM_OPS_GET_STR(_get), \ > .free = (_free), \ > } > Reviewed-by: Petr Pavlu -- Petr