From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F444C001B0 for ; Wed, 19 Jul 2023 06:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4hbWoEP0ap1mIz4K6spWsoL8BxH2yGRAuOwICH3rlSE=; b=XXASPgFEWC/F/G cCf63gx4nj7qPPjJF1nuUwvR2BLxMb/42JDS0t+pnedov/BE7nr8R/Y+8LS2c4BcBxYKWZYrSKZg8 Vdk+97ET6jEaJmAs9RwT8UCXQw7MaztmFCvcoizqJuuWtB9J/F6gmzLSTxkrdOjYRxNBol9UCCX3c WRcPMhUq9YeBswv8mnFtrsZdh84XG+DdwLvPIWVlZ8z86p6xOmcoujuka2YfEcGsOa5/FRaaIIh7T g4lLgdL82OY/mJj2/a3Nwk9ohb4366h0dkVbsKNKEsHjOuqlqPM+asLq0sQarH5DoE90kaHXIPvoB 72WEOzF6A+NnmeqxXZZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0hn-005kt3-2g; Wed, 19 Jul 2023 06:30:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0hm-005ksJ-2g for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jul 2023 06:30:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=h67C4KTdML8o9sSFjnZ94msk8NidoNA3koVZ/2cPPDE=; b=j7YNkGSMa1q92GTtSN/z20+ccR LsR4dEzk/6xUdqDn3LkZva1m20ABJGRF6T3V6owL2ZliOWQwgfdbPwc8ogkORWXqK67w5fKkKPpYy Vpj3KAxPTNIAdtg1WgYTtEwXVt5TaIU7N6bAcXTAo4EKcN/0kB7NRbxjDEZSoN6OXYYUoIOyTyyJt odGWpEEN/Sacp12P9nw2XjhAs1vVsCGrVseUOyrgMey/txmIV7oyZzJAIq2/eb8OeOXkSo/fCbaaL AkNR8iw3kWQukLvtBF0q9w0uhOu5bMRyruVvDimxwicEoAB+0+qVWtlUapeyoT+A/ZZOoggBxc9Q7 CkXo9g0A==; Received: from mga05.intel.com ([192.55.52.43]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLoOM-00BoWC-2U for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2023 17:21:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689700902; x=1721236902; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=gU6GXU89DoVEPPGhanKObMgejkXt3Pfm1XjHlWHVMrg=; b=NWvO6aUkerfnVjWN6WOWHF8zOn4NdcM2q+W5nPGk3bU7jSc9Hr5mYJin pXExyNqhOgg58umi1YIswup/TRYjEcWKu5xsKzr7WjA5EnTRkirYDdvgT RejZm151jeEMPWFvSTKvUbopXoIfIaeHzJqdoiOeK/nX9tlmOrLYSkUIE t3Pf5CEEGMUkzM16leehNu2/ifZ5w/jEiDH+e2y92/P1goEH6cNdu4vGl OLehMSM6b+NiqCxgwFvpW5AqWEi/Og9p9OhsaQlexgkrHLVhYuqLTPSpa TPNObQP4VyP/3cslyOohKBskbii68hM3HCQ1C5xgZT9Z95AgNoh/R7NPk w==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="452644694" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="452644694" 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-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_182143_246684_071780A0 X-CRM114-Status: GOOD ( 21.27 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel