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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93405C2D0A3 for ; Mon, 9 Nov 2020 17:13:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1950920809 for ; Mon, 9 Nov 2020 17:13:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="e7umH4xw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TjU+/c1N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1950920809 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qqFc3UoYLszlOLTfbXx+Fq8xoSsk6bkXuo9yzHDa4R0=; b=e7umH4xw7Ce1VH8tv9TREoZKf MbYamWI9/Xs6tgck+ToNXk9PAcEU3cj7pITRNCdALeTP0AbG02GBNPoyN016XTUsCs1BZ0HSd/Ubt qTHUkoiyX/kHdcjieuu9qZ2Pk/ln97T7glgGI7JBhAZnIAafiADcaLXKEEhdYjTMeYts9v3pcUNeV +SIYzoUHWmRRRz+0jUB33yHKMjrGijkEytNv+Sxsblx4io8yFuNn8zuI8wtrBNZaniFUcstXwcAOE pKyqgy6H0wnY+uNQXSTRfFmeEiIUuGmBeo8W5HkGP29jgm+ktH8ennLioyfEjtfrjzyswU0pXVLHc T11YNjcMg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcAhz-0001UZ-MT; Mon, 09 Nov 2020 17:11:59 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcAhx-0001Tz-U9 for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 17:11:58 +0000 Received: by mail-qk1-x743.google.com with SMTP id h15so8579529qkl.13 for ; Mon, 09 Nov 2020 09:11:57 -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=jemYJ6c567MDm2TimN7FFD6ow5VgmaYL33gvP4f0b4A=; b=TjU+/c1N6d4B9oD89/JF4NOz89XUenVS4+hDi5vHyQhiTNhfD8ISptXq025NNRELjQ cZO8cc4A1ESMxwEPhrkWEx6C6yT/Ld5jU6CKsWYYkIe45dxZxAlZWCIkMzExG5qJPr+l 1iNnVWD5vgUbayq0JsyA9kOGYWg/v9naFTYzbJ7dPEXaopuf8cN6fB7vojS8YiZTfLp8 mvz8m7Vyuu4/xuET8aT6Dc8oqz6gK0BPrGcUAYB2fq2HlhSgyA6HfQXA4xm5e/rqBf8H N4xn3asZ97gE7LCyR1oBQNJy5489Q+fIdzdNbWG06aDttXPE45VtHd4Wh7UoYUi2dPts Ai5A== 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=jemYJ6c567MDm2TimN7FFD6ow5VgmaYL33gvP4f0b4A=; b=C3nlPGyjoddzgRGFRFbAq9QpEPSmxzmz8QUO2vNPDG/KRTsVzZpJ8sVxtNJ6WyfhRP VQVtbzZhbjAMOpin/4AFQ+SaHmV9Edj6Subfg06hlxTThURD//2menh13HMUYoTcTVzR tkSa2SQYef4RtxSGDMT2qLeKTCLCkFCioyHjJvQKsjAwSEsLMsY2yqon7Xt80czjeCIs Pm9NU71nMoKUQUj7jswukuXSZJJHn5w0/P3BCd2sXNOURMA7IU46bukhwEXPFuFxJrKJ jwOWyso+MQEkwLnpjrqvIYnbhjUH8ZYngej5/FBvCuDNOWuaQy744ElKzaFZlG4XhEh5 Ch9A== X-Gm-Message-State: AOAM530vRGKgpbO8zEoG8VwhVVnvt4P0C868uEd51HfWTXtcmD8ZIOW6 v02F9XTIq0hZ87ePokdqYCo= X-Google-Smtp-Source: ABdhPJxughf8rmNrRiOSBmr+3ei5BiDxcYpXyFFompc+fdahWGIGjKj2CZf5Hw3zmJMXIxb419kUCw== X-Received: by 2002:a37:4f51:: with SMTP id d78mr14568557qkb.445.1604941916201; Mon, 09 Nov 2020 09:11:56 -0800 (PST) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id j25sm6193040qtk.79.2020.11.09.09.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 09:11:55 -0800 (PST) Date: Mon, 9 Nov 2020 12:11:40 -0500 From: William Breathitt Gray To: Syed Nayyar Waris Subject: Re: [PATCH v12 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Message-ID: <20201109171140.GA14045@shinobu> References: <15a044d3ba23f00c31fd09437bdd3e5924bb91cd.1603055402.git.syednwaris@gmail.com> <20201101150033.GA68138@shinobu> <20201109123411.GA19869@syed> <20201109134128.GA5596@shinobu> <20201109164529.GA28710@syed.domain.name> MIME-Version: 1.0 In-Reply-To: <20201109164529.GA28710@syed.domain.name> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_121157_992983_E6A3F013 X-CRM114-Status: GOOD ( 32.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Bartosz Golaszewski , Linus Walleij , Michal Simek , "linux-kernel@vger.kernel.org" , "open list:GPIO SUBSYSTEM" , Andrew Morton , Andy Shevchenko , Linux ARM Content-Type: multipart/mixed; boundary="===============2827868553701403666==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============2827868553701403666== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 09, 2020 at 10:15:29PM +0530, Syed Nayyar Waris wrote: > On Mon, Nov 09, 2020 at 03:41:53PM +0100, Arnd Bergmann wrote: > > On Mon, Nov 9, 2020 at 2:41 PM William Breathitt Gray > > wrote: > > > On Mon, Nov 09, 2020 at 06:04:11PM +0530, Syed Nayyar Waris wrote: > > > > > > One of my concerns is that we're incurring the latency two additional > > > conditional checks just to suppress a compiler warning about a case t= hat > > > wouldn't occur in the actual use of bitmap_set_value(). I'm hoping > > > there's a way for us to suppress these warnings without adding onto t= he > > > latency of this function; given that bitmap_set_value() is intended to > > > be used in loops, conditionals here could significantly increase late= ncy > > > in drivers. > >=20 > > At least for this caller, the size check would be a compile-time > > constant that can be eliminated. > >=20 > > > I wonder if array_index_nospec() might have the side effect of > > > suppressing these warnings for us. For example, would this work: > > > > > > static inline void bitmap_set_value(unsigned long *map, > > > unsigned long value, > > > unsigned long start, unsigned lon= g nbits) > > > { > > > const unsigned long offset =3D start % BITS_PER_LONG; > > > const unsigned long ceiling =3D round_up(start + 1, BITS_PER_= LONG); > > > const unsigned long space =3D ceiling - start; > > > size_t index =3D BIT_WORD(start); > > > > > > value &=3D GENMASK(nbits - 1, 0); > > > > > > if (space >=3D nbits) { > > > index =3D array_index_nospec(index, index + 1); > > > > > > map[index] &=3D ~(GENMASK(nbits - 1, 0) << offset); > > > map[index] |=3D value << offset; > > > } else { > > > index =3D array_index_nospec(index, index + 2); > > > > > > map[index + 0] &=3D ~BITMAP_FIRST_WORD_MASK(start); > > > map[index + 0] |=3D value << offset; > > > map[index + 1] &=3D ~BITMAP_LAST_WORD_MASK(start + nb= its); > > > map[index + 1] |=3D value >> space; > > > } > > > } > > > > > > Or is this going to produce the same warning because we're not using = an > > > explicit check against the map array size? > >=20 > > https://godbolt.org/z/fxnsG9 > >=20 > > It still warns about the 'map[index + 1]' access: from all I can tell, > > gcc mainly complains because it cannot rule out that 'space < nbits', > > and then it knows the size of 'DECLARE_BITMAP(old, 64)' and finds > > that if 'index + 0' is correct, then 'index + 1' overflows that array. > >=20 > > Arnd >=20 > Hi Arnd, >=20 > As suggested by William, sharing another solution to suppress the=20 > compiler warning. Please let me know your views on the below fix. Thanks. >=20 > If its alright, I shall submit a (new) v13 patchset soon. Let me know. >=20 > @@ -1,5 +1,5 @@ > static inline void bitmap_set_value(unsigned long *map, > - unsigned long value, > + unsigned long value, const size_t le= ngth, > unsigned long start, unsigned long n= bits) > { > const size_t index =3D BIT_WORD(start); > @@ -15,6 +15,10 @@ static inline void bitmap_set_value(unsigned long *map, > } else { > map[index + 0] &=3D ~BITMAP_FIRST_WORD_MASK(start); > map[index + 0] |=3D value << offset; > + > + if (index + 1 >=3D length) > + __builtin_unreachable(); > + > map[index + 1] &=3D ~BITMAP_LAST_WORD_MASK(start + nbits= ); > map[index + 1] |=3D value >> space; > } Hi Syed, Let's rename 'length' to 'nbits' as Arnd suggested, and rename 'nbits' to value_width. William Breathitt Gray --CE+1k2dSO48ffgeK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl+peEIACgkQhvpINdm7 VJKuwRAAv3CriLlQm8FH9ceCU6mjo550MQi3VOeLqk9As6Rya4KvxJh5RdPVcT3Y c8AvYbKjncicuUKBZu5t5VV3HOSPsbj3CoFS7IZW829XDbx64uTVkCu4YEDm4N22 Ad5cX5BeXaT9SesC3+OkY+cIrHrN5E80WrMnvKXmw4QY6S+35EmraKTxH8KQ5ew9 GpUWOLpwcx+I7Wls3/GZdwA8EHOa1K1wX/r2EFJ9DAUfdfTWuQFlVUIUWoyPxRYd BMFSvFJDtMiW+wS1KWImzuCmuiEoeqAq9k5Vw10eFFFyLqmF3tzudM5dXnTi+FV2 0BBRXoTHEocLgTahLBRGtv/NW7FlmVlMps94Pz8IKJYX0XtlP+plzqWU0FngF4xN 3KrKt27qUPGGWKWN7y9wVjNg06BT0ZfdVl4KLTZD43wp2Qs48G9i+ulnSyYGI9UY 5p0n8spoSjHPlepBp81sNMNAAmJPAM1S0o9cAYKRtCujNuBpQDY6fMyDumSYw4KK HNylvAIIjZCP3O9qgb1053L+i6bB40m40hKud0A99mICLFD/cD5vujclTVmB7YGm yjgIzAGVVXGjEqMW5QJh0gppuaQC6j8S97dXXZ19bOE50U5Iei9yHLt6x1sVwHTH kerChebZOZsbEEO2rs/0Zvv7QIBfSxm/0bltRsRFhbMhHrMgQnE= =/fUf -----END PGP SIGNATURE----- --CE+1k2dSO48ffgeK-- --===============2827868553701403666== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============2827868553701403666==--