From patchwork Thu Nov 3 21:25:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 15213 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp1126679dyb; Thu, 3 Nov 2022 14:35:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7f6Y/NqAKKEeQnKIu3KB68wyLEj5K4JUuYec6pwasuoDIMj30J5Uhz6I0ealbbxxRDbFBu X-Received: by 2002:aa7:888e:0:b0:56c:f16d:2eb0 with SMTP id z14-20020aa7888e000000b0056cf16d2eb0mr32218169pfe.19.1667511340748; Thu, 03 Nov 2022 14:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667511340; cv=none; d=google.com; s=arc-20160816; b=rulOOKSDfcM7XgILGseCuuMKFpFHpEI2tZZXl1VJTJnPmp2Ob/0oART1jC4epZT5E8 SBzLGiegP85rz2zS+Fj9aCWJzVEge1jO9JydLe7tdPzdxPF9MoFhi5LcTCBpUjddZSL7 NAv10e9TI86MJsZidCWagQVi23YB8M0IGe0B2DaU+1mcHAcoWI0YG0mIY5t4SNgmnXvr Fwvf7QZlR+a2lG3sXKz09a3iPFsKwmMd5sKJnNVE7ODXNVwzmPcDkswoczfAwEGghFCt E8aAOrwWylbaUjKYXDV1CICXQz4Ziap3Lcx8+6qxUPbDS7wE0yxJsPpziaE+r0lw3WDD AoDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U6S2ZuEt0qgPUGG0AsxALXCScYxrmWzDM+6UP32zeuQ=; b=CQPYdfS8TpfU/TgdkFnZDOYzsMmuwKMWjLvxZ5IPnU/jdWcP8i1X+3wh3/ltCPcPXH x/xcV1CuhKOmgHSpUMY5P7QyyLpQBvVKlTPnua2ew3/tKhWQvh9GelQHBzUhdUz76084 xOSZ/zhG6GQjKmFC7RSDGPXb5OclhTyqojT3qQW4gkw1lSg71l1h4uuA0JWZjZhKjMR2 +TXxR2EaFzEM+rtqtunXqRQbcIe03PuVPvCN2+cFuodji/fPZcC/5JlJTaCQsyzJZuZj Iu0gLatGhrfa8CZVd6FjIxSsN4L2TrAVjoJv+hJtgYoA6RwwwuMfzK+1HuUhUuN2WEz4 sDjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=fa588U08; 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=arista.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h13-20020a170902f54d00b00176bccea71esi2259013plf.57.2022.11.03.14.35.28; Thu, 03 Nov 2022 14:35:40 -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=@arista.com header.s=google header.b=fa588U08; 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=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbiKCVZl (ORCPT + 99 others); Thu, 3 Nov 2022 17:25:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbiKCVZf (ORCPT ); Thu, 3 Nov 2022 17:25:35 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9818820357 for ; Thu, 3 Nov 2022 14:25:34 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id p16so1942764wmc.3 for ; Thu, 03 Nov 2022 14:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U6S2ZuEt0qgPUGG0AsxALXCScYxrmWzDM+6UP32zeuQ=; b=fa588U08aZVtksAr+gYqOxxYcKUoAQbyf6hqFyde0R9jc6mJqGkUElkSV19yh8wm2V BYtD7MoE/9JFWnZ2oTOMFwSYs1pEHNicUINDb3w22/NZfCE6MEGWiEqz6ORR8MAKz0hC JrJGsA0aZsT49K5vTQwU0UBXpM3qOkGdU7tSWD2TcPjwlbyxMrEuuvHw0HhN/yK7Z/UG sLtGOJvP25h9lcR02tNgi2A2CBXLJIkbspY1usDF50IsqvvjTVEDfN6V74v3640VCGBn DzCDfDutQY1VRKdXLtk2ch8ZoF1N/cdFsrQ6K0LZajNGZ1kb3W9bYa7VroHa4DwMQ2rk rtow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U6S2ZuEt0qgPUGG0AsxALXCScYxrmWzDM+6UP32zeuQ=; b=ntGmSnrp4trY+/5PEbfzIm/Ni7XM/w4cmqVZOYVDhyefhJzqpMcX9muEBjEU7fqX2m jAfjehsyXkOKgG34cPfuuJ95iFvg8qTBKCTeyKUP9XcXmpQ7lif0kln9Z92fN9SPGEeM BxKEchD0r0wd1tzAievJSHRGssTyO2rbdLYFPRjx8SjTxbzY1LoWSS5kFEVgM/SXYhFz TJUu5ETpwmhD1mnBXZrU17gS+zzRtmUH1Y1o7JNO412wMQi7VtLokGarwDqtKkOaLqP7 YTu9p3VPsDlNhY4Js/wNPIF4ihIFbbrcWglow8ICMC3MtkKJp2AFjZlm/cPmin1vvYUt YKPA== X-Gm-Message-State: ACrzQf0a7s6c2aHSQmX8HgHyV3Ubj3tMvC0IPf+1ZWhqhIiFmNEq9dKW mM1rsyEXzKedaKliRDornOqn4mcl3MLRxw== X-Received: by 2002:a1c:a4c5:0:b0:3cf:56dc:fd14 with SMTP id n188-20020a1ca4c5000000b003cf56dcfd14mr20431140wme.180.1667510732944; Thu, 03 Nov 2022 14:25:32 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id t18-20020a05600c199200b003a601a1c2f7sm1038652wmq.19.2022.11.03.14.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 14:25:32 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet Cc: Dmitry Safonov , Bob Gilligan , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jakub Kicinski , Paolo Abeni , Salam Noureddine , netdev@vger.kernel.org, Ard Biesheuvel , Jason Baron , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt Subject: [PATCH v2 1/3] jump_label: Add static_key_fast_inc() Date: Thu, 3 Nov 2022 21:25:22 +0000 Message-Id: <20221103212524.865762-2-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221103212524.865762-1-dima@arista.com> References: <20221103212524.865762-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748512371559714396?= X-GMAIL-MSGID: =?utf-8?q?1748512371559714396?= A helper to add another user for an existing enabled static key. Cc: Ard Biesheuvel Cc: Jason Baron Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Steven Rostedt Suggested-by: Eric Dumazet Signed-off-by: Dmitry Safonov --- include/linux/jump_label.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index 570831ca9951..cb6c722c4816 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -75,6 +75,8 @@ #include #include +#include +#include extern bool static_key_initialized; @@ -235,6 +237,21 @@ extern void static_key_enable_cpuslocked(struct static_key *key); extern void static_key_disable_cpuslocked(struct static_key *key); extern enum jump_label_type jump_label_init_type(struct jump_entry *entry); +/*** + * static_key_fast_inc - adds a user for a static key + * @key: static key that must be already enabled + * + * The caller must make sure that the static key can't get disabled while + * in this function. It doesn't patch jump labels, only adds a user to + * an already enabled static key. + */ +static inline void static_key_fast_inc(struct static_key *key) +{ + STATIC_KEY_CHECK_USE(key); + WARN_ON_ONCE(atomic_read(&key->enabled) < 1); + atomic_inc(&key->enabled); +} + /* * We should be using ATOMIC_INIT() for initializing .enabled, but * the inclusion of atomic.h is problematic for inclusion of jump_label.h @@ -251,9 +268,6 @@ extern enum jump_label_type jump_label_init_type(struct jump_entry *entry); #else /* !CONFIG_JUMP_LABEL */ -#include -#include - static __always_inline int static_key_count(struct static_key *key) { return arch_atomic_read(&key->enabled); @@ -290,6 +304,7 @@ static inline void static_key_slow_dec(struct static_key *key) atomic_dec(&key->enabled); } +#define static_key_fast_inc(key) static_key_slow_inc(key) #define static_key_slow_inc_cpuslocked(key) static_key_slow_inc(key) #define static_key_slow_dec_cpuslocked(key) static_key_slow_dec(key)