Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7149115rwp; Tue, 18 Jul 2023 10:44:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGfAkWQhjAtrmBSeKGGScl0Nhvdc7MDoB6E5XKIQlvWWyI7q41W2a0CTUMDYirMFJIZ+xpC X-Received: by 2002:a17:906:748c:b0:988:f9ba:e18d with SMTP id e12-20020a170906748c00b00988f9bae18dmr6137864ejl.6.1689702255855; Tue, 18 Jul 2023 10:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689702255; cv=none; d=google.com; s=arc-20160816; b=Z7019DClxs3RI0h3WxT7wuRtsCxL7kQaFB5HJgxLYrSkZtKAEZtW6Nk+A7Y4GvvLcV pzthP/I7ae5AA2AoLVBJePEfISe9IDWdjdQdyvqlGC0N23ATlwikOxv9ZX/s/1CPrwia pX7lAkUI2/2F624RrsYcHykYy62CCKzc0OBlRbPtTxa8oq7I/0j+8CIOiewxKqlvEn0Y Wyyex+HHDJ+aDRpJ+yIDQbXMZNWZ2slddcVqaCKQfHdAo5RNXRGY9rSLNavuY6ywF7QD WFIWfkulpdeGZFaAzUyM8/NjMyjkQFHfuEA08wChJYmt0BBm80tj/pgmdvj9XiM1MULt 8BkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=h67C4KTdML8o9sSFjnZ94msk8NidoNA3koVZ/2cPPDE=; fh=AfyCxmQhhQ3+J+YCNtoFIprutFv+rX7XRcVIGr667s0=; b=O0KMVzcxpfJjjzw62zGV8J3nzgHwTgKTr1Mvcxg+U0sai+MsLoB/wXqPSeDkks22sP k52E9q/+LHJYkxfy6VQ2iOC3nMtFXAJ9H6pj6DaInTyXFnA63m2nZauhZH69Xn7yLAta tRX0a01ncc1/rYPgcXn+AQeU5hUe+KNIafJq2RvR0t6IXblhBEI1rANwrU40SgR4G2NW 9JGPlA655uGynd+yONO0gCS3ReMJLILe48sDLhY6OtikIuim1zP51ZJtVg6RyewG6r5p VEGeRF1hBDIw6jmu6SzYulGz5koyCL7t1KLJahgE113dKRHg/bttf6z+U0oWDXwKWbqL jXWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MX196G+M; 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 f22-20020a170906049600b00987383af65asi1391964eja.582.2023.07.18.10.43.51; Tue, 18 Jul 2023 10:44: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=@intel.com header.s=Intel header.b=MX196G+M; 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 S230284AbjGRRUz (ORCPT + 99 others); Tue, 18 Jul 2023 13:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233096AbjGRRUj (ORCPT ); Tue, 18 Jul 2023 13:20:39 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61836BE for ; Tue, 18 Jul 2023 10:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689700838; x=1721236838; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=gU6GXU89DoVEPPGhanKObMgejkXt3Pfm1XjHlWHVMrg=; b=MX196G+M1h1A7W9TC5o4vVleEyOA9iCw/Jkk6/Zr6C6fz1Nl3kGPKGiO ghMEmI/U9Zz37DFDk0d85F6+5NVMI2zzrLWTjmcuZtNyB2D7aO5CYT4ck BBhIIGVgixJeRV8+H+AMHH/px2S6oML6w1pjdw9p9sfuKk1/FiMLpHjeh VUK0G96Q/8j7GzZ7ndSA1SugqOGLddoQ1XhPHfAu9A/ku6pEbYJszDp0Z FGOB4Irp46+qAsD8L65waR8BP1ZMRZfg3xQKzBuFdM5jJXJT+mVLohQtY 8UwxmUnl72Eg7+JCm7x0/g404tgTyKGpPEn3H/jtYsrB4BfCutOMatsC3 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="452644692" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="452644692" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 10:20:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="753407725" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="753407725" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga008.jf.intel.com with ESMTP; 18 Jul 2023 10:20:34 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qLoND-005W4T-39; Tue, 18 Jul 2023 20:20:31 +0300 Date: Tue, 18 Jul 2023 20:20:31 +0300 From: Andy Shevchenko To: Yury Norov Cc: Alexander Potapenko , catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org, Arnd Bergmann Subject: Re: [PATCH v3 1/5] lib/bitmap: add bitmap_{set,get}_value() Message-ID: References: <20230717113709.328671-1-glider@google.com> <20230717113709.328671-2-glider@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On Tue, Jul 18, 2023 at 10:03:25AM -0700, Yury Norov wrote: > On Tue, Jul 18, 2023 at 05:01:28PM +0300, Andy Shevchenko wrote: > > On Tue, Jul 18, 2023 at 11:30:00AM +0200, Alexander Potapenko wrote: ... > > The idea behind is to eliminate the code completely for the cases nbits != 0. > > In your case the dynamic check will be there. That's what we want to avoid. > > Alexander is right - we can't avoid testing against 0 if we need to > test for 0... In case of other functions we have inline and outline > implementations, controlled by small_const_nbits(). > > As you can see, the small_const_nbits() tests against 0 explicitly, > although it's free at compile time. But if nbits == 0, we pick > outline version of a function regardless. > > On their turn, outline versions again do their test against nbits == 0, > but most of the time implicitly. > > In case of bitmap_set_val, we are touching at max 2 words, and there's > no reason for outline version, so we have to test nbits against 0 > inside inline code. > > Having all that in mind, and because nbits == 0 is most likely an > error we'd follow the following rules: > - no memory must be touched as we're potentially in error condition, > and pointer may be corrupted; > - the cost of the check must be as minimal as possible. > > So I suggest: > > if (unlikely(nbits == 0)) > return; > > For readers that would literally mean: we don't expect that, and we find > it suspicious, but we'll handle that as correct as we can. Okay, thank you for elaborated answer. -- With Best Regards, Andy Shevchenko