Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4975282rwb; Wed, 17 Aug 2022 08:58:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dslmCBMypaRx2RgA0uuOHjTngw3IHGlEsWhcJMAo+U8tiDHTqcAI/d919CkfBhAdoMJnT X-Received: by 2002:a17:906:4790:b0:738:4c1c:ec60 with SMTP id cw16-20020a170906479000b007384c1cec60mr10209621ejc.523.1660751903207; Wed, 17 Aug 2022 08:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660751903; cv=none; d=google.com; s=arc-20160816; b=dJalYTw3qLvtw/1fAYytYnaf/khGI/aKP6t3I143GbO+e52AfIL6APAl1YCMV8aj6M xABaYWAVR4B2HC/lhSjhanxjEpJqs9druaLzgt564hHawiuxI8KgABQB/adUK+wt6eND CByBxetRu+L3+YKtpkwqE8SDtVqC5vQI4skq7GiDXV1moD4tQVpVDbJEgOy3TiGTOZ0c ZbO8ULdxVVC02lLMM6aQjrsG/kbJrXpSmyeZyPhmin+KRg1fA79EQEi0rqN4T0efM9Hm oMzKHXcR/G83Jb+GpTiWerUqsYYn6zygOIHpNJc0zOE6YsA9esya6Im4HT/JMq1veyNU L1QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ozn+S1pTAHnt4MIbe0EOjsoOdiS7sDbU2zMN4FKTa90=; b=oryMptkiTZ0766ZdUwcMQ3lNGSFRyUxPJkcUrglJEE56nnlpHRl2q6tfpT4UvPA1/t wrHxT+C81wjpjF+ukelYJ/pk+xN1DtmsBR88Y1ndXDPJacHiYo5iR/YY4TS4xymQOo3q vD/P/izrycerjWeBt2AItu1a/7dIZgHg9KEfKs/IYs5/fc5taAfRT4FXUbB1obBItdkt +s7jpLIUXtx4GazC+bTPiJWFfDafQES5+n1dxBIy7EEMXTYK9IkW8uMeLj/X1T75L9QZ yYe1PsNACowtR3Ep5JKe8EuQS+vpelwcazLM6vTgqH9eACy3+3QIl8QSi9gAq2d2TdHN J+kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="UWt/yJz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a056402280b00b0043d9ceda904si16221868ede.535.2022.08.17.08.57.57; Wed, 17 Aug 2022 08:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="UWt/yJz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239616AbiHQPzF (ORCPT + 99 others); Wed, 17 Aug 2022 11:55:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239066AbiHQPzC (ORCPT ); Wed, 17 Aug 2022 11:55:02 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48AA598A6F for ; Wed, 17 Aug 2022 08:55:00 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id l21so13975063ljj.2 for ; Wed, 17 Aug 2022 08:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=ozn+S1pTAHnt4MIbe0EOjsoOdiS7sDbU2zMN4FKTa90=; b=UWt/yJz/MYKNe5t7CV8M2TbodbwAY3LVJCR1FDZulb4GlH9kltdhlRv21r/gNeqMTm uLlAij2opRCx5vA86ZGHOvtwovTW+DhPjHUIkdcvLH9ByT+Z6paRRFEQuJlDLOsTQDgN HaMTRsLZGJZI/SQI26cJi6a2T5E2UKhoNgChQbmx7dZLf3SFS8C5o3LXVLgNuFY8rNEq JEWo0S777lIANC1QVb7UMfa0edCSc6Vt3GXEdLCxYADzJiidXynnrWFCgGsj9wGKTdzg VxC/NzHM+o+ZFcII/pOS6nnNZB95T54Kt+TH8kAewYo1+YSYgOx5+vxpHWB1Z2WqLMWH ZiNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=ozn+S1pTAHnt4MIbe0EOjsoOdiS7sDbU2zMN4FKTa90=; b=qk/spU5KsVgFNAe48T2+E2+3PcrxXAaaBCw6wpF/YP7BGn9EG8BKQya2zoJOuDyShu S31b8QFJ1NJrCmFUFFlGyCSWqAyRuqshs1KKToJgokk0qi3f1da+w8E2V403cANOpobG yyEA/m1jc4BIrtN80z++zuVCwgrmfkYfyYcokrBMzHaJTw6ARNAPQJ17eYkC9ThN/7Y7 24jk4hExEzm/IBtEr+YtaqkChz8E9nclZjuxqEqEWI+SzH5HWEOKt7CA53lLRFGlAuZ0 UplsdgVRbdX3JnYf4sA7cqx+oFsnCJExSyxbW6JdrTi6umubMVM8z03AwNJ32bRDoWUS SRuA== X-Gm-Message-State: ACgBeo28uL6eHDLecZ6Cgawm5OvUkGgpgADcYghnOhhsn+z5F3nJcoPL FHIfYKYdfYcISOKVmqekEXrSAcWzpozjGagyFP/kog== X-Received: by 2002:a2e:9dc5:0:b0:25e:6fa0:1243 with SMTP id x5-20020a2e9dc5000000b0025e6fa01243mr8638554ljj.513.1660751698380; Wed, 17 Aug 2022 08:54:58 -0700 (PDT) MIME-Version: 1.0 References: <20220816032846.2579217-1-imagedong@tencent.com> In-Reply-To: <20220816032846.2579217-1-imagedong@tencent.com> From: Nick Desaulniers Date: Wed, 17 Aug 2022 08:54:44 -0700 Message-ID: Subject: Re: [PATCH net-next v4] net: skb: prevent the split of kfree_skb_reason() by gcc To: menglong8.dong@gmail.com Cc: kuba@kernel.org, miguel.ojeda.sandonis@gmail.com, ojeda@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, asml.silence@gmail.com, imagedong@tencent.com, luiz.von.dentz@intel.com, vasily.averin@linux.dev, jk@codeconstruct.com.au, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kernel test robot , linux-toolchains Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 15, 2022 at 8:29 PM wrote: > > From: Menglong Dong > > Sometimes, gcc will optimize the function by spliting it to two or > more functions. In this case, kfree_skb_reason() is splited to > kfree_skb_reason and kfree_skb_reason.part.0. However, the > function/tracepoint trace_kfree_skb() in it needs the return address > of kfree_skb_reason(). Does the existing __noclone function attribute help at all here? If not, surely there's an attribute that's more precise than "disable most optimization outright." https://unix.stackexchange.com/questions/223013/function-symbol-gets-part-suffix-after-compilation https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noclone-function-attribute Perhaps noipa might also work here? > > This split makes the call chains becomes: > kfree_skb_reason() -> kfree_skb_reason.part.0 -> trace_kfree_skb() > > which makes the return address that passed to trace_kfree_skb() be > kfree_skb(). > > Therefore, prevent this kind of optimization to kfree_skb_reason() by > making the optimize level to "O1". I think these should be better > method instead of this "O1", but I can't figure it out...... > > This optimization CAN happen, which depend on the behavior of gcc. > I'm not able to reproduce it in the latest kernel code, but it happens > in my kernel of version 5.4.119. Maybe the latest code already do someting > that prevent this happen? > > Signed-off-by: Menglong Dong > Reported-by: kernel test robot > Reported-by: Miguel Ojeda > --- > v4: > - move the definition of __nofnsplit to compiler_attributes.h > > v3: > - define __nofnsplit only for GCC > - add some document > > v2: > - replace 'optimize' with '__optimize__' in __nofnsplit, as Miguel Ojeda > advised. > --- > include/linux/compiler_attributes.h | 19 +++++++++++++++++++ > net/core/skbuff.c | 3 ++- > 2 files changed, 21 insertions(+), 1 deletion(-) > > diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h > index 445e80517cab..968cbafa2421 100644 > --- a/include/linux/compiler_attributes.h > +++ b/include/linux/compiler_attributes.h > @@ -270,6 +270,25 @@ > */ > #define __noreturn __attribute__((__noreturn__)) > > +/* > + * Optional: not supported by clang. > + * Optional: not supported by icc. > + * > + * Prevent function from being splited to multiple part. As what the > + * document says in gcc/ipa-split.cc, single function will be splited > + * when necessary: > + * > + * https://github.com/gcc-mirror/gcc/blob/master/gcc/ipa-split.cc > + * > + * This optimization seems only take effect on O2 and O3 optimize level. > + * Therefore, make the optimize level to O1 to prevent this optimization. > + */ > +#if __has_attribute(__optimize__) > +# define __nofnsplit __attribute__((__optimize__("O1"))) > +#else > +# define __nofnsplit > +#endif > + > /* > * Optional: not supported by gcc. > * Optional: not supported by icc. > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 974bbbbe7138..ff9ccbc032b9 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -777,7 +777,8 @@ EXPORT_SYMBOL(__kfree_skb); > * hit zero. Meanwhile, pass the drop reason to 'kfree_skb' > * tracepoint. > */ > -void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) > +void __nofnsplit > +kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) > { > if (!skb_unref(skb)) > return; > -- > 2.36.1 > -- Thanks, ~Nick Desaulniers