From patchwork Tue Mar 30 20:57:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12173713 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=-21.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 8EE94C433C1 for ; Tue, 30 Mar 2021 21:01:20 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EF6E619B1 for ; Tue, 30 Mar 2021 21:01:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2EF6E619B1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LkgS3CY9Q4oEb/64XiSFlIzSgogvN/68nhTe8LDmGgM=; b=iH9OR6Xq89EfxT82Ct7bcX8lc oBrtoIUXebdqqr5xUfNsuuraxlPqa/yn414MDi2rL6xN0o4s4Nhnf7WhwpgZd/QPf17D8I8UlaAyE NNB3NCJpB/y9SOJ0AofoFeI/7fZNWjD0NWlhgq9etAA4ybk/ey5AavXIW+iGq3JduCjZVScLKy1Lr mcjr5piDM+CliDKtTC333XLSFfWVv8q2fCHuMp/pmMKvEHyHvkzbNa1hjZscFwXilvQl8e8+YsALL 023Bvj8xfEYLFtVER7U6w2kkn/SAhxQmPtb964Nqv19mbnUw8DhLaQ40sgGtKSQjesdi6+eSFj/Eh cYNKix81g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lRLR8-004qas-OI; Tue, 30 Mar 2021 20:58:11 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lRLQx-004qUG-P9 for linux-arm-kernel@lists.infradead.org; Tue, 30 Mar 2021 20:57:59 +0000 Received: by mail-pl1-x62b.google.com with SMTP id o2so6791302plg.1 for ; Tue, 30 Mar 2021 13:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9ijlYcKqhmRnIjh3GfaZu6VzSGgGwccaBk76YZfh88U=; b=FE7kn9uccaNwZUZ65DKIqMMeCF4L8T5uHj+6rAX1M16+hIAiROMPCoW0ANbpyvkauA zNm2OopXkQ6LAOsRPbIK640iKsOLSDOOggNsbZdq6eYIsT34pwdagUeVUvG7xjxhyCBj zo84r5YxnuOMKbimr0OM8w19pz/qkGBGzGeOI= 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=9ijlYcKqhmRnIjh3GfaZu6VzSGgGwccaBk76YZfh88U=; b=iisE8bsBYvLypd6NTVxZYnNJzo0tsAXgznmBqJnO1J3SFaHrIAWiFz2/r60SlXQf31 iWI7/kxLdMFNh+fDaTv8k2IM/OPN2+tanCGs4heYXyKk1izy1WWOTXX8U21+NZ7T6WPL 6peYldccIxBcWvjdC3wRsSifz6pfZkHHl8jUHvFGLal6CMeRoBbfEPBBoA4gvZD4CdCq TkmNCnsRLdkl5p6kTe7wgwVzU9E58R1KP27c74acLCVw9zodyKOO+dzQUy6jyEpAfYKB XnHGDSiX5dsvV4mszH6ufF9lLkW2QE2/I65oDknHvI8Uc4Q4ekuKfZ5rfpx4lbYgd9V7 Q4zw== X-Gm-Message-State: AOAM531B1GFmSQF/o1wW0mMCSTWWRcN9BBA4rq52y2cD5nnm/WyitWll HPXV+uZudr3F4VKYBTYGULeySQ== X-Google-Smtp-Source: ABdhPJxKiSYrHQGcEilxb2Xm7psWt7RDOXuAoFkC/UflndAY9YjgBstIUNwwje4/jGjMrGhbk14LkA== X-Received: by 2002:a17:90b:38f:: with SMTP id ga15mr170436pjb.149.1617137874107; Tue, 30 Mar 2021 13:57:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w23sm106967pgi.63.2021.03.30.13.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 13:57:53 -0700 (PDT) From: Kees Cook To: Thomas Gleixner Cc: Kees Cook , Peter Zijlstra , Elena Reshetova , x86@kernel.org, Andy Lutomirski , Catalin Marinas , Will Deacon , Mark Rutland , Alexander Potapenko , Alexander Popov , Ard Biesheuvel , Jann Horn , Vlastimil Babka , David Hildenbrand , Mike Rapoport , Andrew Morton , Jonathan Corbet , Randy Dunlap , kernel-hardening@lists.openwall.com, linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 1/6] jump_label: Provide CONFIG-driven build state defaults Date: Tue, 30 Mar 2021 13:57:45 -0700 Message-Id: <20210330205750.428816-2-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210330205750.428816-1-keescook@chromium.org> References: <20210330205750.428816-1-keescook@chromium.org> MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; g=aa54c44d1d71b9550d6015efc734f667917094a1; i=Vishx6UyAXwYzcnoSyP+eBB3iQyx+/i5smsbQfc0cnA=; m=vc4sSYlf+uaSlLSFP5TpbQv56VaSRpBLpRuMltXaB4Q=; p=mNH2Bo/K9vrGz9sBtTDV8UFO0eJ8yv8BbR/DeIaO1es= X-Patch-Sig: m=pgp; i=keescook@chromium.org; s=0x0x8972F4DFDC6DC026; b=iQIzBAABCgAdFiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmBjkMwACgkQiXL039xtwCaWexAAp34 ok/GqKys22n/+Xt+9QrE/sBFj+uvgYjI14mqH/xkZoouYd5+myYJn0h/B8R83n48nwB7KdYtukzVv nSela//6I+ohCNhjgEt1TmUc81qTISl5q5mxbq/+IAPNVqlXEYCpTcSFkBbr5tbXOoOrbkI87vrja az8w6YyJGWbCBm/PpNK/FqvgxnWKMmJbomwDiBeWSgEfJUSD/M/r6PV1RhbK2mt7AniDqOPJ/oRG0 VB6GcbfW106hXfwKjmeqoce8yTv7YrC4mYL5sKA0yV/H62mmU9vkUtd+/0x07Cg1iXFAbg3bkDu/i hQkdH1ZBkjnjcWQJ6pvYBfHR+5Fblp8ibFwpPJc/hJmGkzxTde5pAlM3s4FMdtv++qD7bvL2tdXIS kzkw4HJRrjKMET9L3sAWvlSZgUTAip8wslmfIZUVea7HUy5ypoFIvSxHL5BNOGiTBp0zWwvXAzNt1 PTrOAP9fZKIsGI0Nj6laG2wpUdzjTpYcjfNxIPtygIIqheWGFwHwPYpWV0g8700cR/heR7qoBa0zt nrQX1WU7AUkaYROLg1QVWr13bMVlZZuDsSPfvsu3yo8alzHhY8xaryuKCwuTzY8ResHzU6XIqkmJb J1b8qCZ973eAn1T3KbVOk18YcqsShZ8C4SwIbyGOuesFrhes7bPZf/GqTx2MNcoU= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210330_215756_185310_8CE25230 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As shown in jump_label.h[1], choosing the initial state of static branches changes the assembly layout. If the condition is expected to be likely it's inline, and if unlikely it is out of line via a jump. A few places in the kernel use (or could be using) a CONFIG to choose the default state, which would give a small performance benefit to their compile-time declared default. Provide the infrastructure to do this. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/jump_label.h?h=v5.11#n398 Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/lkml/20200324220641.GT2452@worktop.programming.kicks-ass.net/ Signed-off-by: Kees Cook --- include/linux/jump_label.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index d92691262f51..05f5554d860f 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -382,6 +382,21 @@ struct static_key_false { [0 ... (count) - 1] = STATIC_KEY_FALSE_INIT, \ } +#define _DEFINE_STATIC_KEY_1(name) DEFINE_STATIC_KEY_TRUE(name) +#define _DEFINE_STATIC_KEY_0(name) DEFINE_STATIC_KEY_FALSE(name) +#define DEFINE_STATIC_KEY_MAYBE(cfg, name) \ + __PASTE(_DEFINE_STATIC_KEY_, IS_ENABLED(cfg))(name) + +#define _DEFINE_STATIC_KEY_RO_1(name) DEFINE_STATIC_KEY_TRUE_RO(name) +#define _DEFINE_STATIC_KEY_RO_0(name) DEFINE_STATIC_KEY_FALSE_RO(name) +#define DEFINE_STATIC_KEY_MAYBE_RO(cfg, name) \ + __PASTE(_DEFINE_STATIC_KEY_RO_, IS_ENABLED(cfg))(name) + +#define _DECLARE_STATIC_KEY_1(name) DECLARE_STATIC_KEY_TRUE(name) +#define _DECLARE_STATIC_KEY_0(name) DECLARE_STATIC_KEY_FALSE(name) +#define DECLARE_STATIC_KEY_MAYBE(cfg, name) \ + __PASTE(_DECLARE_STATIC_KEY_, IS_ENABLED(cfg))(name) + extern bool ____wrong_branch_error(void); #define static_key_enabled(x) \ @@ -482,6 +497,10 @@ extern bool ____wrong_branch_error(void); #endif /* CONFIG_JUMP_LABEL */ +#define static_branch_maybe(config, x) \ + (IS_ENABLED(config) ? static_branch_likely(x) \ + : static_branch_unlikely(x)) + /* * Advanced usage; refcount, branch is enabled when: count != 0 */