From patchwork Thu Oct 20 03:20:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 5970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp47082wrs; Wed, 19 Oct 2022 20:53:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7XyG8Jx/pvrl1RGdSiCJ4/OkHFkD+523OSdltpl8Xre77DX9I1fGmgoZz2fBE/OHIFv9o/ X-Received: by 2002:a17:907:2c74:b0:78d:845a:1cf9 with SMTP id ib20-20020a1709072c7400b0078d845a1cf9mr9117016ejc.359.1666238024578; Wed, 19 Oct 2022 20:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666238024; cv=none; d=google.com; s=arc-20160816; b=CMAYRat6wCX8EA9zLWTnzeJiyltb6Fe7XITqt0ijFuH0MIwiiGlU31W9aQNqcbH8Yv N/TBNU6gW3e0cYHgaFzDfc8SfgQuOOJJdhboqX5nluDUGrH5sQtlTFdvLiTrOXuzfDGx 5r5hYlkMEYXArqqgODRx4lgf5oIgSs0Vp/h+8I00Iq+mP+7S34NCnoZ8hKEHT1oFV3yU V+CJC/Szdd8C9KMZqf3kyEu0lR7ccaJ/XAyWAZ+Trs85kZH1kxHDvXLZiCyBLXYa63qh ayRt3LPzEvaTOSh0RYb6YZ5u39nQR8k68DXJ9A3oAIxnTuR7vEDyYKSCbbMGZIeUbFqG PPyA== 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=OczjChBmGkUsoBfYt2005Z8T2ggpJvwmMFUd3PcsLKA=; b=Lw2jlIPtIt4ZSm9DYIv8tSxlztcHTpXRc4Uj5tr7GCS3bJtTFSRFRG1ekOK0Kv7y9Z SRFKUgQ4gtkMGL35tZN7E7k07VMIh38FcvPC1VQxbSmohmR0tSEyvwpRv3xqQQ7oCqwY Vv2exvoE7Md5bypasLD0aDPpCRFVWFBZx6iAHMm3SwdHtBAAVIIKHsPJELrLSo/JtKQi FArQ3fTDS6rGz/MzAfTSDDQ/nVMb3Jvkx9GADz9Y+w2IGSn3BPCY/yZnh1YRUZWU52uJ R94o8yTpih9JmSRVfepjuxmAfTW8c506aNUHoZmvGwUkyl8W/BPHFjCzISKJN/Ia653n EQYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Tc1hvzFM; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a1709062b8400b0073155abc1b8si13257325ejg.154.2022.10.19.20.53.17; Wed, 19 Oct 2022 20:53:44 -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=@gmail.com header.s=20210112 header.b=Tc1hvzFM; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbiJTDZB (ORCPT + 99 others); Wed, 19 Oct 2022 23:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiJTDY6 (ORCPT ); Wed, 19 Oct 2022 23:24:58 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3900342D6B for ; Wed, 19 Oct 2022 20:24:56 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id n130so21481722oia.6 for ; Wed, 19 Oct 2022 20:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=OczjChBmGkUsoBfYt2005Z8T2ggpJvwmMFUd3PcsLKA=; b=Tc1hvzFMF23lt+BFLnxI7WX4sMpYoLkFxJzxHhJETh1MSfcQuJmAP341e2KQwFTJsJ EmLReN2GxQD4lz92lcUHSQnuNWQr+mBaXao4mrC+eJMAnpohWbG/2WgPmvzOzZWHP9wH 6y5TEKgsLspmLNtSj9KNcWSRSj7Z8e8+O1Mq6mXoC8pfEJhSTLc1v96I+wIo4/qn6tsh Y/p71MWFrA/EB1d1oVFjdb10h2jTvoId9QBa67aCSbWtUNWbJSY/syidxU0LOd2jj0qi Z7ElXW8pg1UF7dTM0vhyEWbpSjd3/yZWoC4ApPo5xsHPCego3IonNbj+cWRTaZVgR0tl 1sxA== 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=OczjChBmGkUsoBfYt2005Z8T2ggpJvwmMFUd3PcsLKA=; b=t/9fn/lelGXNp8Kx6fe72kmoDF/cPzlAVKtE6qlcfB9WwBfytNauvxCfJzXmef+Yiy Z6+5xGv7KNRT/SMF5Y6F1P0zBkKuRZ5+O+BRhtuZU9Lyqw8pVSV3aBsVx21oegUhLj/L sHALfVSmnMV/7e7BsDJNF2TyO1G84gba6Jl5CL+NvjYqb+9pqJSwHI/52Pen7u8YsB+G 77KqbfvjSdd+HmftQUjikxNdE8qDYyY7eGRzbSc9EllMiJcSWIDC7KHIsaue53pOfdyF B0UMs8drQsZd1Dh8B+reUhFJarxRTg3F8362hP0UI3E9uZFBs2yPWGwD8nUWqp4DjZwa rSMg== X-Gm-Message-State: ACrzQf1fpYLH942fsUz8t/7cC8yzwjG3NuhYxzMKO0CSUUxg6LHiWDK8 4QOwkjCNPyiKPXpj/L4YElY= X-Received: by 2002:aca:df8b:0:b0:350:e9a8:1627 with SMTP id w133-20020acadf8b000000b00350e9a81627mr20314745oig.68.1666236295217; Wed, 19 Oct 2022 20:24:55 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id y3-20020a056870418300b0011f400edb17sm8450627oac.4.2022.10.19.20.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 20:24:54 -0700 (PDT) From: Yury Norov To: "Russell King (Oracle)" , Catalin Marinas , Mark Rutland , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Linux Kernel Mailing List , Alexey Klimov , Andy Shevchenko , Andy Whitcroft , Dennis Zhou , Geert Uytterhoeven , Guenter Roeck , Kees Cook , Linus Torvalds , Rasmus Villemoes Subject: [PATCH 1/2] bitmap: add sanity check function for find_bit() Date: Wed, 19 Oct 2022 20:20:23 -0700 Message-Id: <20221020032024.1804535-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221020032024.1804535-1-yury.norov@gmail.com> References: <20221020032024.1804535-1-yury.norov@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1747177202739688063?= X-GMAIL-MSGID: =?utf-8?q?1747177202739688063?= find_bit() requires a pointer aligned to it's size. However some subsystems (fs, for example) cast char* variables to unsigned long* before passing them to find_bit(). Many architectures allow unaligned pointers with the cost of performance degradation. This patch adds runtime check for the pointers to be aligned. Signed-off-by: Yury Norov --- include/linux/find.h | 35 +++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/find.h b/include/linux/find.h index ccaf61a0f5fd..2d8f5419d787 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -7,6 +7,7 @@ #endif #include +#include unsigned long _find_next_bit(const unsigned long *addr1, unsigned long nbits, unsigned long start); @@ -35,6 +36,14 @@ unsigned long _find_next_bit_le(const unsigned long *addr, unsigned long size, unsigned long offset); #endif +static __always_inline +void check_find_bit(const unsigned long *addr) +{ +#ifdef CONFIG_DEBUG_BITMAP + WARN_ON_ONCE(!IS_ALIGNED((unsigned long)addr, sizeof(unsigned long))); +#endif +} + #ifndef find_next_bit /** * find_next_bit - find the next set bit in a memory region @@ -49,6 +58,8 @@ static inline unsigned long find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val; @@ -79,6 +90,9 @@ unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, unsigned long offset) { + check_find_bit(addr1); + check_find_bit(addr2); + if (small_const_nbits(size)) { unsigned long val; @@ -138,6 +152,8 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val; @@ -164,6 +180,8 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val = *addr & GENMASK(size - 1, 0); @@ -270,6 +288,9 @@ unsigned long find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size) { + check_find_bit(addr1); + check_find_bit(addr2); + if (small_const_nbits(size)) { unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0); @@ -292,6 +313,8 @@ unsigned long find_first_and_bit(const unsigned long *addr1, static inline unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val = *addr | ~GENMASK(size - 1, 0); @@ -313,6 +336,8 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) static inline unsigned long find_last_bit(const unsigned long *addr, unsigned long size) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val = *addr & GENMASK(size - 1, 0); @@ -417,18 +442,24 @@ extern unsigned long find_next_clump8(unsigned long *clump, static inline unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + return find_next_zero_bit(addr, size, offset); } static inline unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + return find_next_bit(addr, size, offset); } static inline unsigned long find_first_zero_bit_le(const void *addr, unsigned long size) { + check_find_bit(addr); + return find_first_zero_bit(addr, size); } @@ -439,6 +470,8 @@ static inline unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val = *(const unsigned long *)addr; @@ -472,6 +505,8 @@ static inline unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset) { + check_find_bit(addr); + if (small_const_nbits(size)) { unsigned long val = *(const unsigned long *)addr; diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 3fc7abffc7aa..1c7dcd33fc2a 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -543,6 +543,13 @@ endmenu # "Compiler options" menu "Generic Kernel Debugging Instruments" +config DEBUG_BITMAP + bool "Debug bitmaps" + help + Say Y here if you want to check bitmap functions parameters at + the runtime. Enable CONFIG_DEBUG_BITMAP only for debugging because + it may affect performance. + config MAGIC_SYSRQ bool "Magic SysRq key" depends on !UML From patchwork Thu Oct 20 03:20:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 5971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp47460wrs; Wed, 19 Oct 2022 20:55:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6V5RKF7f+ganOtyilBlMp0vVQb0Rxti4cViL42u3qwTbrBgzRPQEOJDQOOyESsLiVmmss8 X-Received: by 2002:a17:907:7f25:b0:78d:e76a:ef18 with SMTP id qf37-20020a1709077f2500b0078de76aef18mr9151440ejc.378.1666238115190; Wed, 19 Oct 2022 20:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666238115; cv=none; d=google.com; s=arc-20160816; b=nkCflVKWQPQKB+hn9u/VeoZrXfRaOwQbxq8cNs6+qGQzm3OmVIMVfQ0dOCd388pl3K ZO7DNQeor9hjgQngQVwpmTJqJyGyFvFCvNftKg6w1q6LYz06eTPzB6PeZZd0nykgJBS+ klIgcAoeEmvMaAbatwF6s1/9l30YrGlmYa+Dt61Iu/65JftkKET6J56GS6Qmr//QBZst HO1SR+hP9hWMOvWmfr8GzkNaoZh8m5L1A7SHZyqdIcdz5iHxRMcWmimPxzzhAdxoaCjg BQGUKIIcaVOMgXuKk+zb8eBrXMLPQXJpHg3Ar9vAFcW3ZBVDozE506OdowuF/6zdCr9B Qw/A== 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=LrTrr/AbOZpQ6QHnwNWQS/WlfAPQBvIDtPQnyjJ/xrI=; b=Lqanr1yIy2e+A9gySyUSIJcOrBnhhRck4QUoP7/loQZXvtMDVP0kyiPhs7Qj3FANh0 8kxQVn/9f3smXQEe5Ptga+zCazHRyg/z5ZCCpR2XmuMPvpzKXIgZbPI9VcWO+BGq8YcB pptkbimJMKyAnmegfqdjyhWhWDWSBWAJQQ18bIEMLiEbMKFGRps2ByhNwfN12o0PNDex t2MR9LrDGsmbSUzh+2kZbZ4Lsl2UZsoBOE0wU7H24oSp3EOjlBJ00XYGNFEfJ6pARNXo yWyfhIwyncegrXGYBjCdXNergK3o3eMM7IuYfUywAXKhbduzDpDW3qse6A5f9NZO5MIg L7Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z2p3UItq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du17-20020a17090772d100b00783ca4d1c74si16324244ejc.520.2022.10.19.20.54.51; Wed, 19 Oct 2022 20:55:15 -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=@gmail.com header.s=20210112 header.b=Z2p3UItq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229659AbiJTD1K (ORCPT + 99 others); Wed, 19 Oct 2022 23:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbiJTD1I (ORCPT ); Wed, 19 Oct 2022 23:27:08 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7B216E286 for ; Wed, 19 Oct 2022 20:27:07 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id w74so21543011oie.0 for ; Wed, 19 Oct 2022 20:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=LrTrr/AbOZpQ6QHnwNWQS/WlfAPQBvIDtPQnyjJ/xrI=; b=Z2p3UItqZ5oQssgEbNAIUAQcyChFU6Ml9yFLtFvHDFLBras8kWTXQ5dvU7auQrQ+rA 7PIwcACmz41UbdFXofMB5rrPDDEFtZgk9KdMeaJAC9LyGgoJby/sn5m4NUgSH9vFndSn QYwd7Ylrztp+ax2tVGAKKBD1PWZlBE825Y+QCoSIP+cEPfrSqXVZMgvDDw4wiPFjyH4j glCgMR5tkbI/tpImqb5yJWYbeabrIpwQfcpJa8zRYpNl9ob3mmz7HH/D6Gm5DNFK68DI WOsoEECAZ4qpFSyFBGcnDIuXZxOuKPmqvmWRy4ODGcaKVg5tLgznlUbdrnKWaXWBlpw+ kfbw== 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=LrTrr/AbOZpQ6QHnwNWQS/WlfAPQBvIDtPQnyjJ/xrI=; b=vlLIXnFigxcI5maVx8KgH5aM/EA3s/kWQPoG0JaBEdRTRw6d3C4QfFt8mX+x4V5Cwt szYya+RtimUuAqL+17blWP8VB4szWnc6GuLqqCNVbINZ0RlrPYxz65VuRzy6yCuuNcVo mh2NrItk4MsvdcFqXUWvK8KEbJgq6vtZM5inmBC8df8m3mCyuOyhYVNiK5FyHue+4y/V E94ccyb4w82X8+f1SbOe6nEE8D/oQLpBvMdUvS54Pyzkras/rNJG9+nS+iXeMcjtGFcL x1d+cUuMGK3S+TAkcuZjifzWTtwkMZkmT2CIv+78OFSFrQejEMitSDioBYSSqqtMe+lt mYAg== X-Gm-Message-State: ACrzQf1NdhZAUi1GNe5QJuTIpXdy5tC4mqmaLuEN0h4mHDHFJwaXqLq0 lGlciQ6mn/P4AFb8/68rVIQ= X-Received: by 2002:a05:6808:1587:b0:355:3525:8ed with SMTP id t7-20020a056808158700b00355352508edmr6340031oiw.153.1666236426316; Wed, 19 Oct 2022 20:27:06 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id x17-20020a056830245100b006393ea22c1csm7642057otr.16.2022.10.19.20.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 20:27:05 -0700 (PDT) From: Yury Norov To: "Russell King (Oracle)" , Catalin Marinas , Mark Rutland , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Yury Norov , Linux Kernel Mailing List , Alexey Klimov , Andy Shevchenko , Andy Whitcroft , Dennis Zhou , Geert Uytterhoeven , Guenter Roeck , Kees Cook , Linus Torvalds , Rasmus Villemoes Subject: [PATCH 2/2] arm: drop arch implementation for find_bit() functions Date: Wed, 19 Oct 2022 20:20:24 -0700 Message-Id: <20221020032024.1804535-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221020032024.1804535-1-yury.norov@gmail.com> References: <20221020032024.1804535-1-yury.norov@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1747177297626334243?= X-GMAIL-MSGID: =?utf-8?q?1747177297626334243?= Generic code works on par with arch or better, according to my testing, and with recent improvements merged in v6.1, it should be even faster. ARM already uses many generic find_bit() functions - those that it doesn't implement. So we are talking about migrating a subset of the API; most of find_bit() family has only generic implementation on ARM. This patch switches ARM to generic find_bit() entirely. CC: Guenter Roeck CC: Dennis Zhou CC: Russell King CC: Catalin Marinas CC: linux-arm-kernel@lists.infradead.org Reported-by: Guenter Roeck Suggested-by: Linus Torvalds Signed-off-by: Yury Norov --- arch/arm/include/asm/bitops.h | 63 ----------- arch/arm/kernel/armksyms.c | 11 -- arch/arm/lib/Makefile | 2 +- arch/arm/lib/findbit.S | 193 ---------------------------------- 4 files changed, 1 insertion(+), 268 deletions(-) delete mode 100644 arch/arm/lib/findbit.S diff --git a/arch/arm/include/asm/bitops.h b/arch/arm/include/asm/bitops.h index 714440fa2fc6..23a7cde3422e 100644 --- a/arch/arm/include/asm/bitops.h +++ b/arch/arm/include/asm/bitops.h @@ -157,24 +157,6 @@ extern int _test_and_set_bit(int nr, volatile unsigned long * p); extern int _test_and_clear_bit(int nr, volatile unsigned long * p); extern int _test_and_change_bit(int nr, volatile unsigned long * p); -/* - * Little endian assembly bitops. nr = 0 -> byte 0 bit 0. - */ -unsigned long _find_first_zero_bit_le(const unsigned long *p, unsigned long size); -unsigned long _find_next_zero_bit_le(const unsigned long *p, - unsigned long size, unsigned long offset); -unsigned long _find_first_bit_le(const unsigned long *p, unsigned long size); -unsigned long _find_next_bit_le(const unsigned long *p, unsigned long size, unsigned long offset); - -/* - * Big endian assembly bitops. nr = 0 -> byte 3 bit 0. - */ -unsigned long _find_first_zero_bit_be(const unsigned long *p, unsigned long size); -unsigned long _find_next_zero_bit_be(const unsigned long *p, - unsigned long size, unsigned long offset); -unsigned long _find_first_bit_be(const unsigned long *p, unsigned long size); -unsigned long _find_next_bit_be(const unsigned long *p, unsigned long size, unsigned long offset); - #ifndef CONFIG_SMP /* * The __* form of bitops are non-atomic and may be reordered. @@ -195,26 +177,6 @@ unsigned long _find_next_bit_be(const unsigned long *p, unsigned long size, unsi #define test_and_clear_bit(nr,p) ATOMIC_BITOP(test_and_clear_bit,nr,p) #define test_and_change_bit(nr,p) ATOMIC_BITOP(test_and_change_bit,nr,p) -#ifndef __ARMEB__ -/* - * These are the little endian, atomic definitions. - */ -#define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz) -#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off) -#define find_first_bit(p,sz) _find_first_bit_le(p,sz) -#define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off) - -#else -/* - * These are the big endian, atomic definitions. - */ -#define find_first_zero_bit(p,sz) _find_first_zero_bit_be(p,sz) -#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_be(p,sz,off) -#define find_first_bit(p,sz) _find_first_bit_be(p,sz) -#define find_next_bit(p,sz,off) _find_next_bit_be(p,sz,off) - -#endif - #if __LINUX_ARM_ARCH__ < 5 #include @@ -237,35 +199,10 @@ unsigned long _find_next_bit_be(const unsigned long *p, unsigned long size, unsi #endif #include - #include - #include #include #include - -#ifdef __ARMEB__ - -static inline int find_first_zero_bit_le(const void *p, unsigned size) -{ - return _find_first_zero_bit_le(p, size); -} -#define find_first_zero_bit_le find_first_zero_bit_le - -static inline int find_next_zero_bit_le(const void *p, int size, int offset) -{ - return _find_next_zero_bit_le(p, size, offset); -} -#define find_next_zero_bit_le find_next_zero_bit_le - -static inline int find_next_bit_le(const void *p, int size, int offset) -{ - return _find_next_bit_le(p, size, offset); -} -#define find_next_bit_le find_next_bit_le - -#endif - #include /* diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c index 82e96ac83684..10130987d388 100644 --- a/arch/arm/kernel/armksyms.c +++ b/arch/arm/kernel/armksyms.c @@ -150,17 +150,6 @@ EXPORT_SYMBOL(_clear_bit); EXPORT_SYMBOL(_test_and_clear_bit); EXPORT_SYMBOL(_change_bit); EXPORT_SYMBOL(_test_and_change_bit); -EXPORT_SYMBOL(_find_first_zero_bit_le); -EXPORT_SYMBOL(_find_next_zero_bit_le); -EXPORT_SYMBOL(_find_first_bit_le); -EXPORT_SYMBOL(_find_next_bit_le); - -#ifdef __ARMEB__ -EXPORT_SYMBOL(_find_first_zero_bit_be); -EXPORT_SYMBOL(_find_next_zero_bit_be); -EXPORT_SYMBOL(_find_first_bit_be); -EXPORT_SYMBOL(_find_next_bit_be); -#endif #ifdef CONFIG_FUNCTION_TRACER EXPORT_SYMBOL(__gnu_mcount_nc); diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 6d2ba454f25b..8b152b1a3014 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -7,7 +7,7 @@ lib-y := changebit.o csumipv6.o csumpartial.o \ csumpartialcopy.o csumpartialcopyuser.o clearbit.o \ - delay.o delay-loop.o findbit.o memchr.o memcpy.o \ + delay.o delay-loop.o memchr.o memcpy.o \ memmove.o memset.o setbit.o \ strchr.o strrchr.o \ testchangebit.o testclearbit.o testsetbit.o \ diff --git a/arch/arm/lib/findbit.S b/arch/arm/lib/findbit.S deleted file mode 100644 index 7fd3600db8ef..000000000000 --- a/arch/arm/lib/findbit.S +++ /dev/null @@ -1,193 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * linux/arch/arm/lib/findbit.S - * - * Copyright (C) 1995-2000 Russell King - * - * 16th March 2001 - John Ripley - * Fixed so that "size" is an exclusive not an inclusive quantity. - * All users of these functions expect exclusive sizes, and may - * also call with zero size. - * Reworked by rmk. - */ -#include -#include - .text - -/* - * Purpose : Find a 'zero' bit - * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit); - */ -ENTRY(_find_first_zero_bit_le) - teq r1, #0 - beq 3f - mov r2, #0 -1: - ARM( ldrb r3, [r0, r2, lsr #3] ) - THUMB( lsr r3, r2, #3 ) - THUMB( ldrb r3, [r0, r3] ) - eors r3, r3, #0xff @ invert bits - bne .L_found @ any now set - found zero bit - add r2, r2, #8 @ next bit pointer -2: cmp r2, r1 @ any more? - blo 1b -3: mov r0, r1 @ no free bits - ret lr -ENDPROC(_find_first_zero_bit_le) - -/* - * Purpose : Find next 'zero' bit - * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset) - */ -ENTRY(_find_next_zero_bit_le) - cmp r2, r1 - bhs 3b - ands ip, r2, #7 - beq 1b @ If new byte, goto old routine - ARM( ldrb r3, [r0, r2, lsr #3] ) - THUMB( lsr r3, r2, #3 ) - THUMB( ldrb r3, [r0, r3] ) - eor r3, r3, #0xff @ now looking for a 1 bit - movs r3, r3, lsr ip @ shift off unused bits - bne .L_found - orr r2, r2, #7 @ if zero, then no bits here - add r2, r2, #1 @ align bit pointer - b 2b @ loop for next bit -ENDPROC(_find_next_zero_bit_le) - -/* - * Purpose : Find a 'one' bit - * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit); - */ -ENTRY(_find_first_bit_le) - teq r1, #0 - beq 3f - mov r2, #0 -1: - ARM( ldrb r3, [r0, r2, lsr #3] ) - THUMB( lsr r3, r2, #3 ) - THUMB( ldrb r3, [r0, r3] ) - movs r3, r3 - bne .L_found @ any now set - found zero bit - add r2, r2, #8 @ next bit pointer -2: cmp r2, r1 @ any more? - blo 1b -3: mov r0, r1 @ no free bits - ret lr -ENDPROC(_find_first_bit_le) - -/* - * Purpose : Find next 'one' bit - * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset) - */ -ENTRY(_find_next_bit_le) - cmp r2, r1 - bhs 3b - ands ip, r2, #7 - beq 1b @ If new byte, goto old routine - ARM( ldrb r3, [r0, r2, lsr #3] ) - THUMB( lsr r3, r2, #3 ) - THUMB( ldrb r3, [r0, r3] ) - movs r3, r3, lsr ip @ shift off unused bits - bne .L_found - orr r2, r2, #7 @ if zero, then no bits here - add r2, r2, #1 @ align bit pointer - b 2b @ loop for next bit -ENDPROC(_find_next_bit_le) - -#ifdef __ARMEB__ - -ENTRY(_find_first_zero_bit_be) - teq r1, #0 - beq 3f - mov r2, #0 -1: eor r3, r2, #0x18 @ big endian byte ordering - ARM( ldrb r3, [r0, r3, lsr #3] ) - THUMB( lsr r3, #3 ) - THUMB( ldrb r3, [r0, r3] ) - eors r3, r3, #0xff @ invert bits - bne .L_found @ any now set - found zero bit - add r2, r2, #8 @ next bit pointer -2: cmp r2, r1 @ any more? - blo 1b -3: mov r0, r1 @ no free bits - ret lr -ENDPROC(_find_first_zero_bit_be) - -ENTRY(_find_next_zero_bit_be) - cmp r2, r1 - bhs 3b - ands ip, r2, #7 - beq 1b @ If new byte, goto old routine - eor r3, r2, #0x18 @ big endian byte ordering - ARM( ldrb r3, [r0, r3, lsr #3] ) - THUMB( lsr r3, #3 ) - THUMB( ldrb r3, [r0, r3] ) - eor r3, r3, #0xff @ now looking for a 1 bit - movs r3, r3, lsr ip @ shift off unused bits - bne .L_found - orr r2, r2, #7 @ if zero, then no bits here - add r2, r2, #1 @ align bit pointer - b 2b @ loop for next bit -ENDPROC(_find_next_zero_bit_be) - -ENTRY(_find_first_bit_be) - teq r1, #0 - beq 3f - mov r2, #0 -1: eor r3, r2, #0x18 @ big endian byte ordering - ARM( ldrb r3, [r0, r3, lsr #3] ) - THUMB( lsr r3, #3 ) - THUMB( ldrb r3, [r0, r3] ) - movs r3, r3 - bne .L_found @ any now set - found zero bit - add r2, r2, #8 @ next bit pointer -2: cmp r2, r1 @ any more? - blo 1b -3: mov r0, r1 @ no free bits - ret lr -ENDPROC(_find_first_bit_be) - -ENTRY(_find_next_bit_be) - cmp r2, r1 - bhs 3b - ands ip, r2, #7 - beq 1b @ If new byte, goto old routine - eor r3, r2, #0x18 @ big endian byte ordering - ARM( ldrb r3, [r0, r3, lsr #3] ) - THUMB( lsr r3, #3 ) - THUMB( ldrb r3, [r0, r3] ) - movs r3, r3, lsr ip @ shift off unused bits - bne .L_found - orr r2, r2, #7 @ if zero, then no bits here - add r2, r2, #1 @ align bit pointer - b 2b @ loop for next bit -ENDPROC(_find_next_bit_be) - -#endif - -/* - * One or more bits in the LSB of r3 are assumed to be set. - */ -.L_found: -#if __LINUX_ARM_ARCH__ >= 5 - rsb r0, r3, #0 - and r3, r3, r0 - clz r3, r3 - rsb r3, r3, #31 - add r0, r2, r3 -#else - tst r3, #0x0f - addeq r2, r2, #4 - movne r3, r3, lsl #4 - tst r3, #0x30 - addeq r2, r2, #2 - movne r3, r3, lsl #2 - tst r3, #0x40 - addeq r2, r2, #1 - mov r0, r2 -#endif - cmp r1, r0 @ Clamp to maxbit - movlo r0, r1 - ret lr -