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=-5.0 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,USER_AGENT_SANE_1 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 A2158C388F7 for ; Mon, 9 Nov 2020 16:46:24 +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 428B42074F for ; Mon, 9 Nov 2020 16:46:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SGUwk1DY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dFGCRp4H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 428B42074F 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-Transfer-Encoding: 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-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9W0sr/Nde6WiUy2HoPoFQQH1Xw3JhPT+azG7A3PIWk0=; b=SGUwk1DYsOfZzbqe37t0cZQsV wJPnoQpnkEzZQstJuSp8XnpjtwpiFzHlFH+sEpoHD+NcQct6S/v8VAOiP3HCixyLP5JYGmNZG5pU8 FhjR5k0xuMBxm1tQY0Mr9ktMElFduyJTL1uhm9+wUlE+BwuHDr1BQsXS592cEy73HDqjzpYkW5mqR FKQAaL8rJ+7wyQVkXRXLfvGWiaqQm9bR8fuXlMwa2eKu36eGHEloXI+kq1JtKnLYC5I9rzaVfcoHu oW7nP4Uc0eBgAg2Z71rQVDAItJP+VX/uSn52ZQ/1iOS7f/6NQvYEkbIQrngOfnfO0dHuSQhDhtFW6 uh3Vx+EFw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcAId-0004pm-CP; Mon, 09 Nov 2020 16:45:47 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcAIa-0004p3-Eu for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 16:45:45 +0000 Received: by mail-pf1-x441.google.com with SMTP id q10so8705459pfn.0 for ; Mon, 09 Nov 2020 08:45:43 -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:user-agent; bh=71ZA6fbBt/FYq9Yhv+Sw9ZIQkG6/ePxg0ItPs/D9GHo=; b=dFGCRp4HQO2QC53KqPkIOGuKPiTb0MMC+WaFg+uMtDK1oksOXt3Y1c0HQUxtVjOxtt gvy8L27H6qCKEPKY08LIHUuaXdwjWebNkTqKNTS//oAVPDlDPZV5zAU3hWnrafy830Db OYMi+aZqgKS6nIAEU5BJ6KquRDJDcRzIR/6y3gBqGzxyAefFpun5/Z8fjNQ3GlTGdDiY Zpj9pRXkPXX2I9Pzu4OTB8FkueM8e+Hvc0zWrKUpDb5gwZ1i/DaoZGS+yoa9Wg2yt7hf oj0/lbKp8fhdTSGFpGrk/DSl9L4TWz6lmv8HLDu+ZA1rP+ai2pLgBVcv5rAzO7wUSVeX 1B2A== 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:user-agent; bh=71ZA6fbBt/FYq9Yhv+Sw9ZIQkG6/ePxg0ItPs/D9GHo=; b=oiaXrI2xA/Rhp1Qq+AzdJLyQjSYa9BMFKkO6eEic/8sGdu6KRyPdZFF3QvOKgH1Kz2 rMxf95d4OarazWjvij5kibo847JiVlLO/FoMq5ZSGkFQVarHT7pZOTYgcpthBYhh6rrg uEUXa+mx3a2jK/qrmqLebJ4V08Lg7R1H83lXEIS57hHSVT4jiujTch1YZKzeJOk4Hs4p O5D13a/xFly8d7rNSY47VuMPUviBWjBIQwqALtA9INSxNRPk0TmvAt9jBvjlTjOKdckV F6VE8yJypfTWxhyLL8Hn2XD35dGfYezMRVBgNJc6fks8mpntLExSYywS+uns5ikv8MEC a+ug== X-Gm-Message-State: AOAM532SmQLG7EaGWDSZ1XdOEaRJJQ879nZFiWZs3uEfFHFTmE652NnF YXlmcFMF8yXCrszD9Tzvhug= X-Google-Smtp-Source: ABdhPJyEigPHxinw9lcZASoyZh54Ipx/Vyh6HNx1mgZ52ds7e8/f3SY+ZA2LYWRcNIVEWTw2bHRGbQ== X-Received: by 2002:a63:d357:: with SMTP id u23mr13835450pgi.106.1604940342272; Mon, 09 Nov 2020 08:45:42 -0800 (PST) Received: from syed.domain.name ([103.201.127.51]) by smtp.gmail.com with ESMTPSA id p188sm10796880pgp.65.2020.11.09.08.45.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2020 08:45:41 -0800 (PST) Date: Mon, 9 Nov 2020 22:15:29 +0530 From: Syed Nayyar Waris To: Arnd Bergmann Subject: Re: [PATCH v12 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Message-ID: <20201109164529.GA28710@syed.domain.name> References: <15a044d3ba23f00c31fd09437bdd3e5924bb91cd.1603055402.git.syednwaris@gmail.com> <20201101150033.GA68138@shinobu> <20201109123411.GA19869@syed> <20201109134128.GA5596@shinobu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_114544_523536_6A339FE0 X-CRM114-Status: GOOD ( 30.60 ) 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: Bartosz Golaszewski , "linux-kernel@vger.kernel.org" , Linus Walleij , Michal Simek , William Breathitt Gray , "open list:GPIO SUBSYSTEM" , Andrew Morton , Andy Shevchenko , Linux ARM 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 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 that > > 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 the > > latency of this function; given that bitmap_set_value() is intended to > > be used in loops, conditionals here could significantly increase latency > > in drivers. > > At least for this caller, the size check would be a compile-time > constant that can be eliminated. > > > 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 long nbits) > > { > > const unsigned long offset = start % BITS_PER_LONG; > > const unsigned long ceiling = round_up(start + 1, BITS_PER_LONG); > > const unsigned long space = ceiling - start; > > size_t index = BIT_WORD(start); > > > > value &= GENMASK(nbits - 1, 0); > > > > if (space >= nbits) { > > index = array_index_nospec(index, index + 1); > > > > map[index] &= ~(GENMASK(nbits - 1, 0) << offset); > > map[index] |= value << offset; > > } else { > > index = array_index_nospec(index, index + 2); > > > > map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start); > > map[index + 0] |= value << offset; > > map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > > map[index + 1] |= value >> space; > > } > > } > > > > Or is this going to produce the same warning because we're not using an > > explicit check against the map array size? > > https://godbolt.org/z/fxnsG9 > > 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. > > Arnd Hi Arnd, As suggested by William, sharing another solution to suppress the compiler warning. Please let me know your views on the below fix. Thanks. If its alright, I shall submit a (new) v13 patchset soon. Let me know. @@ -1,5 +1,5 @@ static inline void bitmap_set_value(unsigned long *map, - unsigned long value, + unsigned long value, const size_t length, unsigned long start, unsigned long nbits) { const size_t index = BIT_WORD(start); @@ -15,6 +15,10 @@ static inline void bitmap_set_value(unsigned long *map, } else { map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start); map[index + 0] |= value << offset; + + if (index + 1 >= length) + __builtin_unreachable(); + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); map[index + 1] |= value >> space; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel