Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9006787pxu; Mon, 28 Dec 2020 04:12:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJtarH9hU8QFxUwYfxPxPVHVxcYLpzPjGbOLETp8pYCCh6Yo5j56a8VHTKCjDRinaNgW42 X-Received: by 2002:aa7:c891:: with SMTP id p17mr14292661eds.309.1609157568352; Mon, 28 Dec 2020 04:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609157568; cv=none; d=google.com; s=arc-20160816; b=hGQ9ooPYuQa7djOIDwM0pChw9TyyjVHhsOl8IzkK3edT4YEdcDIIjll0LwZtm0eVOR VNKRvKpl4Ddwsc6IHnODw1SUYi/7ANNVbTiVnHgHmIDOsR3YtPVdW5XNg2JU6NoKyTMV sxrg4sa5W9zhQ5w8L58nCEi90RIYIWMrSzcnlbiupp2xI6IpxJRCduKYp8qXj8W1Ciug o4xcTDA5+GIaYJ3fDlkaBo1m5oBx2E/a7Pu9vugHCvRaA8LjpxgDqFNXcOCBtwQ/JwF2 DTEq3u70ZD3BWcgCUVP8Lja6fjd0I23LpUfpKRRHkYbjUGS7V7KKD1JLajoBsCvWglJF XoZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=n3AT6TDkcYOgoqXitcYuftfnSMBgPOjVyKdhjDG6q98=; b=lRULwDRJKKwAHJRmn9TJwGUnP+R/vScE0rpbkpvUkrvKmZboq+Hv9hQwoef4KJ/Hle 4mk8Baai46e3lg4tgITS+VJN8N+y3rM95cA18wJsFBquoRETHolM8FH3QRgdwhXdqY14 0Gafc/G/9fJP8J88JicmA+YBfOkO5o+s0yRXCiYb5pPMAT7HMtQQY+FIwkXOgTd9VBPZ iZf+E8fL0hsRHnYmPDlkvlirza67toAwYE1DpRGAaqlk5zzKXqP28Zh+ljW+8PTkXjHN blNg5VSMZvmDxLppreJHG2fZ4MmzlP3MPkIhNaV9+Ke9lqOjtlYbQEnrSAsWA0pw6V4E YrYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J1zm2pYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs18si20912716ejb.435.2020.12.28.04.12.25; Mon, 28 Dec 2020 04:12:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J1zm2pYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727700AbgL1MLq (ORCPT + 99 others); Mon, 28 Dec 2020 07:11:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727234AbgL1MLp (ORCPT ); Mon, 28 Dec 2020 07:11:45 -0500 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 953B3C06179B; Mon, 28 Dec 2020 04:10:59 -0800 (PST) Received: by mail-qk1-x72c.google.com with SMTP id p14so8587860qke.6; Mon, 28 Dec 2020 04:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=n3AT6TDkcYOgoqXitcYuftfnSMBgPOjVyKdhjDG6q98=; b=J1zm2pYkcwwgV3idpyV51/hd6OLd3cUy1dOzgyZLHS+FqU6Zp9Z7IP4KCwC0pyefgF +F8Ua+oVw5ubQlnsCWMOUEdVg6txT62/4DgMs0TyjA/sRNmq7risll2xB6UOF5H5/ICW eQ37vjgb0rObWr5xKSgO+8j/aH57V6hjKkMOPxfseNLl0yNnD89Iq5esifqFqeTKYTal khpreON5T50lGDPsmPqHQ+WhIDjaT36oOqAiGqnQEA+Qer5DzUCHnqUWGdw1NjWjQ1ZA 2dF4FIP9TPbwmBZIGP/syv560pQsbvZcOgPFPkEPjscLxqMR4cKfldLuZzlRllycsLdH XI4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=n3AT6TDkcYOgoqXitcYuftfnSMBgPOjVyKdhjDG6q98=; b=iG5Z2lJZhHEKFknoRJNDzsRGJujLYNMpWn3kbc1Dz07AY3/fR5lmtZJNzV4cLMaUrO MGGR3GytTKWeNALrniEhoKMS7n2oGYbhgxOJzIf7vJ6yjLJfT03NcsG1dYGnL9tFuMlu NFhmEzVVOJjVUYoIrfFumiR0GWv4BeC+m9J/hHH9Si++fEesUFtImJ5ApMHuzO17ETqA 4CmWQczPbljcTLZ9WgOhIY7nLHOrMwKIFkXaAfeqXVQ+zjZCN8fy1YowqgygORA5KZ1i ateQEZXtZYhstshr0aWU8RAOw1oabjO4FG52CpKG0q/nL7ogMcLmO9whQMfAV2cPU8sZ UKLA== X-Gm-Message-State: AOAM531ivykVyR4Vdcew1PwjgGMiswpOEjtZjdDDt0hVVTSH0NA2vVmi /n6B1C0PCUj7rrOoAM4mynw= X-Received: by 2002:a37:73c6:: with SMTP id o189mr44162144qkc.169.1609157458688; Mon, 28 Dec 2020 04:10:58 -0800 (PST) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id z15sm23611656qkz.103.2020.12.28.04.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:10:57 -0800 (PST) Date: Mon, 28 Dec 2020 07:10:55 -0500 From: William Breathitt Gray To: Arnd Bergmann Cc: Syed Nayyar Waris , Linus Walleij , Andy Shevchenko , Michal Simek , Arnd Bergmann , Robert Richter , Bartosz Golaszewski , Masahiro Yamada , Andrew Morton , Zhang Rui , Daniel Lezcano , Amit Kucheria , linux-arch , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Linux ARM , Linux PM list Subject: Re: [PATCH 1/5] clump_bits: Introduce the for_each_set_clump macro Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="jvtA3Yi9DvLrtiYs" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --jvtA3Yi9DvLrtiYs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 27, 2020 at 11:03:06PM +0100, Arnd Bergmann wrote: > On Sat, Dec 26, 2020 at 7:42 AM Syed Nayyar Waris = wrote: > > > > This macro iterates for each group of bits (clump) with set bits, > > within a bitmap memory region. For each iteration, "start" is set to > > the bit offset of the found clump, while the respective clump value is > > stored to the location pointed by "clump". Additionally, the > > bitmap_get_value() and bitmap_set_value() functions are introduced to > > respectively get and set a value of n-bits in a bitmap memory region. > > The n-bits can have any size from 1 to BITS_PER_LONG. size less > > than 1 or more than BITS_PER_LONG causes undefined behaviour. > > Moreover, during setting value of n-bit in bitmap, if a situation arise > > that the width of next n-bit is exceeding the word boundary, then it > > will divide itself such that some portion of it is stored in that word, > > while the remaining portion is stored in the next higher word. Similar > > situation occurs while retrieving the value from bitmap. > > > > GCC gives warning in bitmap_set_value(): https://godbolt.org/z/rjx34r > > Add explicit check to see if the value being written into the bitmap > > does not fall outside the bitmap. > > The situation that it is falling outside would never be possible in the > > code because the boundaries are required to be correct before the > > function is called. The responsibility is on the caller for ensuring the > > boundaries are correct. > > The code change is simply to silence the GCC warning messages > > because GCC is not aware that the boundaries have already been checked. > > As such, we're better off using __builtin_unreachable() here because we > > can avoid the latency of the conditional check entirely. >=20 > Didn't the __builtin_unreachable() end up leading to an objtool > warning about incorrect stack frames for the code path that leads > into the undefined behavior? I thought I saw a message from the 0day > build bot about that and didn't expect to see it again after that. >=20 > Can you actually measure any performance difference compared > to BUG_ON() that avoids the undefined behavior? Practically > all CPUs from the past 20 years have branch predictors that should > completely hide measurable overhead from this. >=20 > Arnd When I initially recommended using __builtin_unreachable(), I was anticipating the use of bitmap_set_value() in kernel at large -- so the possible performance hit from a conditional check was a concern for me. However, now that we're restricting the scope of bitmap_set_value() to only the GPIO subsystem, such optimization is no longer a major concern I feel: gpio-xilinx is the only driver utilizing bitmap_set_value() -- and we know it won't be called in a loop -- so whatever hypothetical performance hit there might be is inconsequential in the end. Instead, we should focus on code clarity now. I believe it makes sense given the new scope of this function to revert back to the earlier suggestion of passing in and checking the boundary explicitly, and to remove the __builtin_unreachable() call for now. If bitmap_set_value() becomes available to the rest of the kernel in the future, we can reconsider whether or not to use __builtin_unreachable(). William Breathitt Gray --jvtA3Yi9DvLrtiYs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl/py08ACgkQhvpINdm7 VJJdtA//cR1YiOviFw5k9cxcAoNFUWhX1LfFPSZzBwGgXnPNVUeQDxCYt9Zo7m48 bEcIumIHZBm0W8tySv4BlQBBSTEiiBFOWKfNHRpLJES2oVBXaYJppe6nMMjHcb0v 5gZKxeFTC+51ZZKw238Csned7xNCUDiYDOjwvFCWuccF0tadOWWKNLqWYpl2LlwX VcOe64W7/N7Wd2X7zCg/6jwIEu5RNR7I1oSt5DMNCraQjwBBRpKxoTRwb5sT/60x xWQCJYA7qg3jseisk0n2xyAAh3nA8JWCDx/XF7qnt0+vz37Q7sia3mJKZiL3j2Ad yTgBDbddWPn2f4qEMpFijgfRRFzJ1jKHwwWG4n086aeC3Ql608QEMU4arJInAzgK 3NxrdoY01mKqNye7dSac9JyvGu1KZLc6QPiZ5//sxdYG91yEnaqf9xpHgft8wobp 5/C2dMFbZjktcFNuepxgLjPNuB+J202lEifiwAMI2sL8h9hCfyWi/U8O9WDuFosY 9KChwHyjV4eG2GMqnIhxAG0bA94xuJNp8avH3+8CAB5mc+05RFw3nwS4fFG4YsbS a4XY1+wtAkyI2aqpoRa606RlaVvoBRzMWt0LEc2+Fy6Ab/98svG26coD8GcZ/RUN /ElXNOM7mq1Jl2utzF5v86oTEtK0K1cvz+XDrRqYsYObM1yC+ts= =uoh3 -----END PGP SIGNATURE----- --jvtA3Yi9DvLrtiYs--