Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4124724pxt; Tue, 10 Aug 2021 21:10:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz14dObv6TxuD63f0fReJv4wqIWukcyModl+GzJmZj8aicS4xhL6tARiYdfLQfrcOUuFC7Z X-Received: by 2002:a50:d6db:: with SMTP id l27mr8993229edj.309.1628655010066; Tue, 10 Aug 2021 21:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628655010; cv=none; d=google.com; s=arc-20160816; b=XHw/++kXS7SBVu0IU0Oa3gUmpRMMWQwND5Ibgb/Y27v2HBcJfEiUVaDGOQM8+tcHpx 6mMkZRSH6MWQGmUi8Mnrt276M6dY3HIMvvqIUvLE2k+Rw2RinhJJVyMMH2Jk4YQzCMfa FhpUvXZRiNfRD2BolKFhdHMZHVJk5U/pw5eHvRoEj3QUgcBumiNYyOV/s0Q2nhI4+iXl CzH6SuC1Q8ULwG0vQi8ER7CCPeW5mV/qvNkDa3zTxQHD77ydzS0WbKHhm+BrXyLuTKp0 klLl3+d+HqBx2i1pQYcsjc6veKVw62YUOHB2sdelTK/4g8Q2jUqCcjkIJOQ7dM1Em0PK 5czw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=q0GrcJF80QgEWmAkthY86vwIzlIDzXoi6ve2UjkHZ3w=; b=07fkZvpd1nUTHUZsK2zuTEe+URYQZxNya3R/MnCekiVBvZwgLFA5o7Ypgpxx61jSiy 5qVljwRY+9+CofEj1NY86F328Evk8aQKFFfdp3SQ26I4aNW2XoyiV7hCAmal5+1Mn8Qw 8+Ll5mA6msFvCeZiFHQYpCnnVk6dC97OC0KJ0B5wViyYOI8QmK2EYmLkHHl/n867jPlF Uz75n5YWHNoZgCxt/97OHgI98e4laB7Vea4NFU42tuyYAuanfCN7VwdgACnDFttY2Dej YEQLik924CZ0NY3PtIvqHlVP3P1hplnFhjD4qsUgp5nC6JjLDKBAxkpim2zvUpI3Lhik hmPA== ARC-Authentication-Results: i=1; mx.google.com; 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 n14si22802739ejc.276.2021.08.10.21.09.45; Tue, 10 Aug 2021 21:10:10 -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; 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 S229730AbhHKEHf (ORCPT + 99 others); Wed, 11 Aug 2021 00:07:35 -0400 Received: from smtprelay0095.hostedemail.com ([216.40.44.95]:34382 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229554AbhHKEHe (ORCPT ); Wed, 11 Aug 2021 00:07:34 -0400 Received: from omf11.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id B2245181CC1B7; Wed, 11 Aug 2021 04:07:09 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA id B927C20A296; Wed, 11 Aug 2021 04:07:08 +0000 (UTC) Message-ID: Subject: Re: [PATCH] netlink: NL_SET_ERR_MSG - remove local static array From: Joe Perches To: Jakub Kicinski Cc: netdev , Johannes Berg , Jonathan Toppins , LKML Date: Tue, 10 Aug 2021 21:07:07 -0700 In-Reply-To: <20210810133058.0c7f0736@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> References: <1f99c69f4e640accaf7459065e6625e73ec0f8d4.camel@perches.com> <20210810133058.0c7f0736@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.82 X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: B927C20A296 X-Stat-Signature: erbj8ue88trry6nswhxoahbaokjr61fi X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+6DgYlB/FaT7vkiYsQX+R3g2pF1EQooxU= X-HE-Tag: 1628654828-659544 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-08-10 at 13:30 -0700, Jakub Kicinski wrote: > On Mon, 09 Aug 2021 10:04:00 -0700 Joe Perches wrote: > > The want was to have some separate object section for netlink messages > > so all netlink messages could be specifically listed by some tool but > > the effect is duplicating static const char arrays in the object code. > > > > It seems unused presently so change the macro to avoid the local static > > declarations until such time as these actually are wanted and used. > > > > This reduces object size ~8KB in an x86-64 defconfig without modules. [] > > diff --git a/include/linux/netlink.h b/include/linux/netlink.h [] > > @@ -89,13 +89,12 @@ struct netlink_ext_ack { > > ??* to the lack of an output buffer.) > > ??*/ > > ?#define NL_SET_ERR_MSG(extack, msg) do { \ > > - static const char __msg[] = msg; \ > > ? struct netlink_ext_ack *__extack = (extack); \ > > ? \ > > - do_trace_netlink_extack(__msg); \ > > + do_trace_netlink_extack(msg); \ > > ? \ > > ? if (__extack) \ > > - __extack->_msg = __msg; \ > > + __extack->_msg = msg; \ > > ?} while (0) > > But you've made us evaluate msg multiple times now. > Given extack is carefully evaluated only once this stands out. msg is always a const char array so no evaluation is done. It's just a pointer. In fact, this could either become a static inline or a simple function call to reduce object size even further. For instance: $ size vmlinux.o.nl_func.* text data bss dec hex filename 19974564 3457991 741312 24173867 170dd2b vmlinux.o.nl_func.new 19992097 3457967 741312 24191376 1712190 vmlinux.o.nl_func.old --- include/linux/netlink.h | 29 ++++++++++------------------- net/netlink/af_netlink.c | 13 +++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index 61b1c7fcc401e..fe80c2704cc23 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -82,21 +82,16 @@ struct netlink_ext_ack { u8 cookie_len; }; +void netlink_set_err_msg(struct netlink_ext_ack *extack, const char *msg); /* Always use this macro, this allows later putting the * message into a separate section or such for things * like translation or listing all possible messages. * Currently string formatting is not supported (due * to the lack of an output buffer.) */ -#define NL_SET_ERR_MSG(extack, msg) do { \ - static const char __msg[] = msg; \ - struct netlink_ext_ack *__extack = (extack); \ - \ - do_trace_netlink_extack(__msg); \ - \ - if (__extack) \ - __extack->_msg = __msg; \ -} while (0) + +#define NL_SET_ERR_MSG(extack, msg) \ + netlink_set_err_msg(extack, msg) #define NL_SET_ERR_MSG_MOD(extack, msg) \ NL_SET_ERR_MSG((extack), KBUILD_MODNAME ": " msg) @@ -110,16 +105,12 @@ struct netlink_ext_ack { #define NL_SET_BAD_ATTR(extack, attr) NL_SET_BAD_ATTR_POLICY(extack, attr, NULL) -#define NL_SET_ERR_MSG_ATTR_POL(extack, attr, pol, msg) do { \ - static const char __msg[] = msg; \ - struct netlink_ext_ack *__extack = (extack); \ - \ - do_trace_netlink_extack(__msg); \ - \ - if (__extack) { \ - __extack->_msg = __msg; \ - __extack->bad_attr = (attr); \ - __extack->policy = (pol); \ +#define NL_SET_ERR_MSG_ATTR_POL(extack, attr, pol, msg) \ +do { \ + netlink_set_err_msg(extack, msg); \ + if (extack) { \ + extack->bad_attr = (attr); \ + extack->policy = (pol); \ } \ } while (0) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 24b7cf447bc55..b6d035f0d343b 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -2561,6 +2561,19 @@ int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 portid, } EXPORT_SYMBOL(nlmsg_notify); +/** + * nl_set_err_msg - + */ + +void netlink_set_err_msg(struct netlink_ext_ack *extack, const char *msg) +{ + do_trace_netlink_extack(msg); + + if (extack) + extack->_msg = msg; +} +EXPORT_SYMBOL(netlink_set_err_msg); + #ifdef CONFIG_PROC_FS struct nl_seq_iter { struct seq_net_private p;