Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp343074iog; Fri, 24 Jun 2022 05:15:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4BUf0g8IbSOyHkYnnkTKL5Gc140RzJVpj09TOUhAv1vSB4NveNQ1x8jGQ9vAzB1k46G/R X-Received: by 2002:a17:90a:6b0d:b0:1ec:93e5:c61b with SMTP id v13-20020a17090a6b0d00b001ec93e5c61bmr3694338pjj.189.1656072955703; Fri, 24 Jun 2022 05:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656072955; cv=none; d=google.com; s=arc-20160816; b=quB5mV2BzkMNLxdqQYP4axDMOHFYZGVB73jikWqcilMBJNtgXIpvv0LkNBqI/rVcy7 qAxsjtHwiQGtBgU+F9RmEW1N/RphQkxHVgNPeipJpy7jIHjeysF/15EKwIfARL0MHSCW 4gI/Ynew4/0vy1wCDi8u3C8/oISAFg3UdDFiknSKOgSF+uYnRqhc4m4n50xQKd3oNR1c k3r3XfECaY3yviCKmI9tsZPeO4GhaIfkz2ddMfOgoiES5Kj5juPeCiea5fhRwIEe0jQe BVvmjRDvdd2PbY1fQg3OG8rhdW1vbyc+c7wrq6uKhz5K/2X4jG3Bwnqbub6rTANSOjqh Mjzw== 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=LyYzwPY00aaZ428rRlljDRyZ2sri6u19jYPz3eh3yMw=; b=OGHBxzcZCC1yHqmxxtRQjVQj8ctkZ02Mzg2i4GnQplQcFA8tkR9TfCahNlhqk/M8OC oAxT4LscReIO9VRMBSO+bBGe/9MnJdpB5X9ypZav+mHSCQZx0bJ5ncd6kpkfRH4VNKhx JRVH99DwwamsWXl5xrV16sVyz/OvtvS7fmgfDbPRuUBpguJ31LUyH9Ii9HV3cgK/9z0B 4MEl+j+tKxxxqnl/31UflO7wJYFfqTtm3fY612QV14WFZw76sYruA5YOsvHeAxvgFwUX VZ0zvb+P8CfGhKcenOTCYNrQov6i9Tr4PfukECfnNeDhnYO3JEJauAqYBW2mKCrwCyvd t+1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OTR8kwk8; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a632a10000000b0040d91e5254esi1127855pgq.513.2022.06.24.05.15.42; Fri, 24 Jun 2022 05:15:55 -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=@intel.com header.s=Intel header.b=OTR8kwk8; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232171AbiFXMOb (ORCPT + 99 others); Fri, 24 Jun 2022 08:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232079AbiFXMN6 (ORCPT ); Fri, 24 Jun 2022 08:13:58 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F8D22BE5; Fri, 24 Jun 2022 05:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656072818; x=1687608818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UwGnL3cKrVpIYdUCZi0g8IIvLiuF1HHfK1nv3YKvvvI=; b=OTR8kwk8G6qwygQIVU7DL7WOO1p+YBBOIoTHAu6jphg7NHpi4vcr41Lx XyT+QhnziYKbP++UZdYnZ4si4YXsKezzuoLPPDMgyNteQsR9DywDO8ga+ 3FGyDP+EP5DfuN25xHiI4Fi0wLW7DUV9np7F+GmXPv0qWG47032dpt9ak q+1t3DvOX1KeeN7hp33TUw2URRbHTpOsnwJHrEo4nbuRZSB7m8FiyhJn9 DTv1LQcUXyT+3F/lluDCoRLiiSYdV3T9yONZ+dKVXhBMonZVt6g/ykmY6 azzNJDE7wkSNXGlvBmb1Zdxg3qkpFsYx9uJivQ4Xkda20ShRRR0UxGQms g==; X-IronPort-AV: E=McAfee;i="6400,9594,10387"; a="264027543" X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="264027543" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2022 05:13:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,218,1650956400"; d="scan'208";a="765726377" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga005.jf.intel.com with ESMTP; 24 Jun 2022 05:13:30 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25OCDEo8014999; Fri, 24 Jun 2022 13:13:28 +0100 From: Alexander Lobakin To: Arnd Bergmann , Yury Norov Cc: Alexander Lobakin , Andy Shevchenko , Mark Rutland , Matt Turner , Brian Cain , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , "David S. Miller" , Kees Cook , "Peter Zijlstra (Intel)" , Marco Elver , Borislav Petkov , Tony Luck , Maciej Fijalkowski , Jesse Brandeburg , Greg Kroah-Hartman , Nathan Chancellor , Nick Desaulniers , Tom Rix , kernel test robot , linux-alpha@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 8/9] bitmap: don't assume compiler evaluates small mem*() builtins calls Date: Fri, 24 Jun 2022 14:13:12 +0200 Message-Id: <20220624121313.2382500-9-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220624121313.2382500-1-alexandr.lobakin@intel.com> References: <20220624121313.2382500-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Intel kernel bot triggered the build bug on ARC architecture that in fact is as follows: DECLARE_BITMAP(bitmap, BITS_PER_LONG); bitmap_clear(bitmap, 0, BITS_PER_LONG); BUILD_BUG_ON(!__builtin_constant_p(*bitmap)); which can be expanded to: unsigned long bitmap[1]; memset(bitmap, 0, sizeof(*bitmap)); BUILD_BUG_ON(!__builtin_constant_p(*bitmap)); In most cases, a compiler is able to expand small/simple mem*() calls to simple assignments or bitops, in this case that would mean: unsigned long bitmap[1] = { 0 }; BUILD_BUG_ON(!__builtin_constant_p(*bitmap)); and on most architectures this works, but not on ARC, despite having -O3 for every build. So, to make this work, in case when the last bit to modify is still within the first long (small_const_nbits()), just use plain assignments for the rest of bitmap_*() functions which still use mem*(), but didn't receive such compile-time optimizations yet. This doesn't have the same coverage as compilers provide, but at least something to start: text: add/remove: 3/7 grow/shrink: 43/78 up/down: 1848/-3370 (-1546) data: add/remove: 1/11 grow/shrink: 0/8 up/down: 4/-356 (-352) notably cpumask_*() family when NR_CPUS <= BITS_PER_LONG: netif_get_num_default_rss_queues 38 4 -34 cpumask_copy 90 - -90 cpumask_clear 146 - -146 and the abovementioned assertion started passing. Signed-off-by: Alexander Lobakin --- include/linux/bitmap.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 2e6cd5681040..a0f4f3af8d30 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -238,20 +238,32 @@ extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp, static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memset(dst, 0, len); + + if (small_const_nbits(nbits)) + *dst = 0; + else + memset(dst, 0, len); } static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) { unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memset(dst, 0xff, len); + + if (small_const_nbits(nbits)) + *dst = ~0UL; + else + memset(dst, 0xff, len); } static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, unsigned int nbits) { unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memcpy(dst, src, len); + + if (small_const_nbits(nbits)) + *dst = *src; + else + memcpy(dst, src, len); } /* @@ -431,6 +443,8 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, { if (__builtin_constant_p(nbits) && nbits == 1) __set_bit(start, map); + else if (small_const_nbits(start + nbits)) + *map |= GENMASK(start + nbits - 1, start); else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && __builtin_constant_p(nbits & BITMAP_MEM_MASK) && @@ -445,6 +459,8 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, { if (__builtin_constant_p(nbits) && nbits == 1) __clear_bit(start, map); + else if (small_const_nbits(start + nbits)) + *map &= ~GENMASK(start + nbits - 1, start); else if (__builtin_constant_p(start & BITMAP_MEM_MASK) && IS_ALIGNED(start, BITMAP_MEM_ALIGNMENT) && __builtin_constant_p(nbits & BITMAP_MEM_MASK) && -- 2.36.1