From patchwork Mon Jun 28 13:50:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tanner Love X-Patchwork-Id: 468631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE2D8C49361 for ; Mon, 28 Jun 2021 13:50:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D689561C80 for ; Mon, 28 Jun 2021 13:50:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232332AbhF1Nwt (ORCPT ); Mon, 28 Jun 2021 09:52:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbhF1Nwj (ORCPT ); Mon, 28 Jun 2021 09:52:39 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7751C061574; Mon, 28 Jun 2021 06:50:12 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id q16so5945017qke.10; Mon, 28 Jun 2021 06:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mXC3FkdhPxDYuYzI3537RFiPRTI+dFbNXu8uhPWaU8Y=; b=MsF9+pKNK0nQfmeDSM1Exb7gLY8IpP5oELoFkfyqGDqNUSIR5f/sttgEEN6ygp1fER 5IbEnR/aLuoidceLYoEEdqNkaYEpH/VXmdcGxd9MUL4zlMMrIRDjMhFW97bhWJ9Ap4tS bq7S15hpVhTl37Y5iJYQpxw4/BvQS6fqqe/shQxHUaRTrKyI8Vrecl33VHUeYbiK2+yX KPV1HdRKCA92LfIvqXWIuKuw9XHD+WRP7W8UVizp4bZwRxnWz9oZQM6srN8gMVCA/1XI z3EgoT+1C30UJS+dq7xkJ7FdwehqqFqiaRcMCwjN8vPDqeBC/WxQayjOLxDcz5xzTuqg +FRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mXC3FkdhPxDYuYzI3537RFiPRTI+dFbNXu8uhPWaU8Y=; b=nbbEjFCaliTCE4FpNZx5SSNmy7PGi9eeWP5Sa+UVwsdzIv/T5pY+UiZnFzU8asAdgG vPnYXkEsOa9G/5guikXz1HCEPloNeReZrikVuln0nreWfNOhkjHgUhc1+s8LkguRT1Cl UBfv2FiWDECrTgaPJzWT/fvL34Q1RZ1t81rKs8tdNhxp/KxYKu+PBhcczVBUK4u32nUG WeE+wb1Zv8j7q3bC/byT+6klTmMChkaiZQzc2gEr4XsDxrQRdoGRnrgIWA+C39siVJuy +mc+5lOc6CdxbOE0FCHrAnmezwTNDnxiijhq/nUG52HPlRbuTAEwhs7Gbs0kssvuyTH4 NlmA== X-Gm-Message-State: AOAM531l5I+TM1WzDPi9mLLI0i/6p+HLGKNPv9/8gCofnj0X2XpXqlSx c96GQV8lhq52BL3k2MiRJkroDRqpw3U= X-Google-Smtp-Source: ABdhPJwX80vF5oNJOYHJQCw85dqifYuexJspeS6wu+PBMWLbKDfzMrRAMoQCvxERHtfJnAhA3FBMAg== X-Received: by 2002:a37:ac14:: with SMTP id e20mr9647808qkm.362.1624888211942; Mon, 28 Jun 2021 06:50:11 -0700 (PDT) Received: from tannerlove.nyc.corp.google.com ([2620:0:1003:1000:8502:d4aa:337:d4d]) by smtp.gmail.com with ESMTPSA id f19sm10760518qkg.70.2021.06.28.06.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 06:50:11 -0700 (PDT) From: Tanner Love To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, "David S . Miller" , Eric Dumazet , Mahesh Bandewar , "Darrick J . Wong" , Arnd Bergmann , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , Ingo Molnar , Jakub Kicinski , Andrii Nakryiko , Antoine Tenart , Alexander Lobakin , Wei Wang , Taehee Yoo , Yunsheng Lin , Willem de Bruijn , Tanner Love Subject: [PATCH net-next v3 1/2] once: implement DO_ONCE_LITE for non-fast-path "do once" functionality Date: Mon, 28 Jun 2021 09:50:06 -0400 Message-Id: <20210628135007.1358909-2-tannerlove.kernel@gmail.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210628135007.1358909-1-tannerlove.kernel@gmail.com> References: <20210628135007.1358909-1-tannerlove.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tanner Love Certain uses of "do once" functionality reside outside of fast path, and so do not require jump label patching via static keys, making existing DO_ONCE undesirable in such cases. Replace uses of __section(".data.once") with DO_ONCE_LITE(_IF)? This patch changes the return values of xfs_printk_once, printk_once, and printk_deferred_once. Before, they returned whether the print was performed, but now, they always return true. This is okay because the return values of the following macros are entirely ignored throughout the kernel: - xfs_printk_once - xfs_warn_once - xfs_notice_once - xfs_info_once - printk_once - pr_emerg_once - pr_alert_once - pr_crit_once - pr_err_once - pr_warn_once - pr_notice_once - pr_info_once - pr_devel_once - pr_debug_once - printk_deferred_once - orc_warn Changes v3: - Expand commit message to explain why changing return values of xfs_printk_once, printk_once, printk_deferred_once is benign v2: - Fix i386 build warnings Signed-off-by: Tanner Love Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- fs/xfs/xfs_message.h | 13 +++---------- include/asm-generic/bug.h | 37 +++++++------------------------------ include/linux/once_lite.h | 24 ++++++++++++++++++++++++ include/linux/printk.h | 23 +++-------------------- kernel/trace/trace.h | 13 +++---------- 5 files changed, 40 insertions(+), 70 deletions(-) create mode 100644 include/linux/once_lite.h diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h index 7ec1a9207517..bb9860ec9a93 100644 --- a/fs/xfs/xfs_message.h +++ b/fs/xfs/xfs_message.h @@ -2,6 +2,8 @@ #ifndef __XFS_MESSAGE_H #define __XFS_MESSAGE_H 1 +#include + struct xfs_mount; extern __printf(2, 3) @@ -41,16 +43,7 @@ do { \ } while (0) #define xfs_printk_once(func, dev, fmt, ...) \ -({ \ - static bool __section(".data.once") __print_once; \ - bool __ret_print_once = !__print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - func(dev, fmt, ##__VA_ARGS__); \ - } \ - unlikely(__ret_print_once); \ -}) + DO_ONCE_LITE(func, dev, fmt, ##__VA_ARGS__) #define xfs_emerg_ratelimited(dev, fmt, ...) \ xfs_printk_ratelimited(xfs_emerg, dev, fmt, ##__VA_ARGS__) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index b402494883b6..bafc51f483c4 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -4,6 +4,7 @@ #include #include +#include #define CUT_HERE "------------[ cut here ]------------\n" @@ -140,39 +141,15 @@ void __warn(const char *file, int line, void *caller, unsigned taint, }) #ifndef WARN_ON_ONCE -#define WARN_ON_ONCE(condition) ({ \ - static bool __section(".data.once") __warned; \ - int __ret_warn_once = !!(condition); \ - \ - if (unlikely(__ret_warn_once && !__warned)) { \ - __warned = true; \ - WARN_ON(1); \ - } \ - unlikely(__ret_warn_once); \ -}) +#define WARN_ON_ONCE(condition) \ + DO_ONCE_LITE_IF(condition, WARN_ON, 1) #endif -#define WARN_ONCE(condition, format...) ({ \ - static bool __section(".data.once") __warned; \ - int __ret_warn_once = !!(condition); \ - \ - if (unlikely(__ret_warn_once && !__warned)) { \ - __warned = true; \ - WARN(1, format); \ - } \ - unlikely(__ret_warn_once); \ -}) +#define WARN_ONCE(condition, format...) \ + DO_ONCE_LITE_IF(condition, WARN, 1, format) -#define WARN_TAINT_ONCE(condition, taint, format...) ({ \ - static bool __section(".data.once") __warned; \ - int __ret_warn_once = !!(condition); \ - \ - if (unlikely(__ret_warn_once && !__warned)) { \ - __warned = true; \ - WARN_TAINT(1, taint, format); \ - } \ - unlikely(__ret_warn_once); \ -}) +#define WARN_TAINT_ONCE(condition, taint, format...) \ + DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format) #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG diff --git a/include/linux/once_lite.h b/include/linux/once_lite.h new file mode 100644 index 000000000000..861e606b820f --- /dev/null +++ b/include/linux/once_lite.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_ONCE_LITE_H +#define _LINUX_ONCE_LITE_H + +#include + +/* Call a function once. Similar to DO_ONCE(), but does not use jump label + * patching via static keys. + */ +#define DO_ONCE_LITE(func, ...) \ + DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__) +#define DO_ONCE_LITE_IF(condition, func, ...) \ + ({ \ + static bool __section(".data.once") __already_done; \ + bool __ret_do_once = !!(condition); \ + \ + if (unlikely(__ret_do_once && !__already_done)) { \ + __already_done = true; \ + func(__VA_ARGS__); \ + } \ + unlikely(__ret_do_once); \ + }) + +#endif /* _LINUX_ONCE_LITE_H */ diff --git a/include/linux/printk.h b/include/linux/printk.h index fe7eb2351610..885379a1c9a1 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -8,6 +8,7 @@ #include #include #include +#include extern const char linux_banner[]; extern const char linux_proc_banner[]; @@ -436,27 +437,9 @@ extern int kptr_restrict; #ifdef CONFIG_PRINTK #define printk_once(fmt, ...) \ -({ \ - static bool __section(".data.once") __print_once; \ - bool __ret_print_once = !__print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - printk(fmt, ##__VA_ARGS__); \ - } \ - unlikely(__ret_print_once); \ -}) + DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__) #define printk_deferred_once(fmt, ...) \ -({ \ - static bool __section(".data.once") __print_once; \ - bool __ret_print_once = !__print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - printk_deferred(fmt, ##__VA_ARGS__); \ - } \ - unlikely(__ret_print_once); \ -}) + DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__) #else #define printk_once(fmt, ...) \ no_printk(fmt, ##__VA_ARGS__) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index cd80d046c7a5..d5d8c088a55d 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef CONFIG_FTRACE_SYSCALLS #include /* For NR_SYSCALLS */ @@ -99,16 +100,8 @@ enum trace_type { #include "trace_entries.h" /* Use this for memory failure errors */ -#define MEM_FAIL(condition, fmt, ...) ({ \ - static bool __section(".data.once") __warned; \ - int __ret_warn_once = !!(condition); \ - \ - if (unlikely(__ret_warn_once && !__warned)) { \ - __warned = true; \ - pr_err("ERROR: " fmt, ##__VA_ARGS__); \ - } \ - unlikely(__ret_warn_once); \ -}) +#define MEM_FAIL(condition, fmt, ...) \ + DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__) /* * syscalls are special, and need special handling, this is why From patchwork Mon Jun 28 13:50:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tanner Love X-Patchwork-Id: 468191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E9DDC2B9F4 for ; Mon, 28 Jun 2021 13:50:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 770E661C78 for ; Mon, 28 Jun 2021 13:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232366AbhF1Nw4 (ORCPT ); Mon, 28 Jun 2021 09:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbhF1Nwo (ORCPT ); Mon, 28 Jun 2021 09:52:44 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85896C061760; Mon, 28 Jun 2021 06:50:14 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id 65so9985058qko.5; Mon, 28 Jun 2021 06:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jgGEFkMArwto/hguJ5jTwXsSU4L7A/FJ08JPCBZFdjo=; b=QplwyV5rzaOnfqkvF1RDY68wW2yI1YFYhMRcU7pWOqgNs/N/bZvgTUibr8EterCWA4 Ekg4bqUy8nZitFIyD419HvXNIRp46zq4M5rpXAU1sTVnIHOB/jZcNETK1LaVya0ndlz/ 2jURLQCARDMBzkUm73devoFH3rv3GVs0S9EuwybXuNTlIkt9SjGd5YnIcQ8p1zQ5C4WA tHGfcXJdoX8RM98TqBtqr4tQAM+TmEZ1uZHacFdNgH27MCoKwYMmfQ6XmMcXb6OULz9i 3v5uvBtUZPWB6F0S9ahtFlX2goc73mwKRU5f6BJSq6pyCNLIN/hOL5tlTDzI+fma8VN+ x5Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jgGEFkMArwto/hguJ5jTwXsSU4L7A/FJ08JPCBZFdjo=; b=te+7dZ2Oe1NaC50X1ojoarY4fP7S0U2KwAH3q5AVzZEAT83B85s2rqCxJYKiLo6rQR HwZlV/cYvDtpaO3AdiWprn3+1gOLwBFS3QA/iLBKlLizmH63srKror/4WMArd/YyNYox rOEHolKV+P43Pimg+YmjJTuJtsh8v7gMtR3Ru6a7BpW0HErfpr7fwl9sDfsh3CRxTpGY uEqq6xQDifJIisEx3XzLEbmPi/rKaBYBtrJ/wbEY2YW6/tcfBejDu4KZMIHDGrodq8DR odrOulEsPnHLIZy2DbZxJFIXqkRx42fB+y80BQaXgM5NhWKI91Dt++YNNyUBfxbxiUSX ijbw== X-Gm-Message-State: AOAM532SDzDzBQsZ0SRGWRpmlbFvU4lDvjjqx2Nn5ituExgAe0y1KMR8 wuRs93+Vs9kyk2rGYuxZ29QxadUxLgo= X-Google-Smtp-Source: ABdhPJzmqYPGHZdApMOX5+0nI7tsbDj4KOUWei4oAqv0gB0IybDgSBjUSm8hGAP3XRTJk4pw3udWYg== X-Received: by 2002:a37:b8b:: with SMTP id 133mr8863456qkl.44.1624888213665; Mon, 28 Jun 2021 06:50:13 -0700 (PDT) Received: from tannerlove.nyc.corp.google.com ([2620:0:1003:1000:8502:d4aa:337:d4d]) by smtp.gmail.com with ESMTPSA id f19sm10760518qkg.70.2021.06.28.06.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 06:50:13 -0700 (PDT) From: Tanner Love To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, "David S . Miller" , Eric Dumazet , Mahesh Bandewar , "Darrick J . Wong" , Arnd Bergmann , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , Ingo Molnar , Jakub Kicinski , Andrii Nakryiko , Antoine Tenart , Alexander Lobakin , Wei Wang , Taehee Yoo , Yunsheng Lin , Willem de Bruijn , Tanner Love Subject: [PATCH net-next v3 2/2] net: update netdev_rx_csum_fault() print dump only once Date: Mon, 28 Jun 2021 09:50:07 -0400 Message-Id: <20210628135007.1358909-3-tannerlove.kernel@gmail.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210628135007.1358909-1-tannerlove.kernel@gmail.com> References: <20210628135007.1358909-1-tannerlove.kernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tanner Love Printing this stack dump multiple times does not provide additional useful information, and consumes time in the data path. Printing once is sufficient. Changes v2: Format indentation properly Signed-off-by: Tanner Love Acked-by: Eric Dumazet Acked-by: Mahesh Bandewar --- net/core/dev.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 991d09b67bd9..d609366da95c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -148,6 +148,7 @@ #include #include #include +#include #include "net-sysfs.h" @@ -3487,13 +3488,16 @@ EXPORT_SYMBOL(__skb_gso_segment); /* Take action when hardware reception checksum errors are detected. */ #ifdef CONFIG_BUG +static void do_netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb) +{ + pr_err("%s: hw csum failure\n", dev ? dev->name : ""); + skb_dump(KERN_ERR, skb, true); + dump_stack(); +} + void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb) { - if (net_ratelimit()) { - pr_err("%s: hw csum failure\n", dev ? dev->name : ""); - skb_dump(KERN_ERR, skb, true); - dump_stack(); - } + DO_ONCE_LITE(do_netdev_rx_csum_fault, dev, skb); } EXPORT_SYMBOL(netdev_rx_csum_fault); #endif