Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp899597ybm; Fri, 29 May 2020 15:11:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXTH2C8nctLtMCql9kN2gl8jg7cutZtDCify43AsWQ9AkONirQfWJ8iU+7CJJo6qM5cD7J X-Received: by 2002:a17:906:2e1a:: with SMTP id n26mr9331371eji.425.1590790284833; Fri, 29 May 2020 15:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590790284; cv=none; d=google.com; s=arc-20160816; b=g4PE8sSe3zB7XVsjBJk53GnRhE4tAIobBA/ZonWnVewZpChqIZX62FbfEMA7BZq/wr +5x/N5o7lqdi4Ht3iTCu2NzwlAyP/0tY55gaH+2zYdBJAJF2dJStFliKoOKCQk7lGWTS Rm3AMqgeVNdXziFRJK66qcIO5HjFwv8fTKYAhPm9/iEJ/jWDBQSiy1vaUc0O1MX7fhpH UcIIb9jBtTf6DtRKD+LPQTalhZKjQjRLs5nJwnxK9efZy4zW3202/TYiCMSOvJGq3FwQ mHoJ3eNSP8GWl5k3bum5Kk9ZN288stCRrxJ9VlP6vuUQguO+yCy61IgDs7NZHb9wtQJB LLZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+bIMpCJ94S64iX9SZqFBI3aKlDTVQaJmor4Ew0nG9Zo=; b=xwLwnR8n5/iHD0bkvj2YJk3iT2R8RHtYJ3HGzxFO55Xy1PtilKDkFiFbJAoDdDfrhZ 10uW92uRICo+yS0znDBOuWiDB7MsYO4DRSROz4kVh8NCoxLuuZli0eOlJxyA9vbCGqfQ MjcnEfGOuTxc4TAd2qrnIp2OQp6mnD1fA5a8CSLWkqUzH1G9ZC/6N7qjpDyiwyAuQcEF KG7lQFlf8pPCwOa7AG965CMrjq4ghgbN+EtVyuQKlzzFEl2tPtc1eXOwEANJ0oB9qi6i 8jTBwqHPjvIIizSvhFI6xPEGN7BSt9KiWVDVNRdYYPCvBAiHP9mPAXalGsSoSXP69f/o nm3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T08vu+Xt; 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 z3si6591411edj.437.2020.05.29.15.11.01; Fri, 29 May 2020 15:11:24 -0700 (PDT) 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=T08vu+Xt; 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 S1728449AbgE2WII (ORCPT + 99 others); Fri, 29 May 2020 18:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728071AbgE2WII (ORCPT ); Fri, 29 May 2020 18:08:08 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA8EC03E969; Fri, 29 May 2020 15:08:08 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id x11so1762751plv.9; Fri, 29 May 2020 15:08:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+bIMpCJ94S64iX9SZqFBI3aKlDTVQaJmor4Ew0nG9Zo=; b=T08vu+XtVe9OQSO2ckBP6WY2pRv3eb/PC2L+RP5iv9/lwDNlaN+S0TpbowBQmUiEOI RBphKLbkSXp/JxXjWerxz3YvnyGEdJ6aijOnRjBY5aKckjkSzrHtHbWrQf9FXCUsIGEZ AsxfkoqOKfo/UyTd7oc0Wwui7IwuWwiktQaRDV2tMFFNppg4kjhQOcU84onyXVWSzsRs DTe1oSRh2TczeWxEhBKfB9rzCpKi7plebo6ejSnBI8l5VuowQxhYBkZIovfmxinBqIe4 2rk9wXs+w2dP5FRYVTLhbjzyqGHn0X+PEECz/5DWl1FhSsmc3aUMs+bUjycDvqKzW+yn y6mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+bIMpCJ94S64iX9SZqFBI3aKlDTVQaJmor4Ew0nG9Zo=; b=uB6LLdSf855FML9zAFEaxcBTXIzLsk7dBWg1Qx3t5BLqq6JxfWRX751aYx74im5N76 GPRUQhzSuQT/vCfgZZVwLz0bGNLWSsyAQC3QACb1JAGOq2Eng53T6lDI/Eb/RwBOZDxr 42x9CXQED+InZLKofVYBTPhFfyh6mNlnPYJNWSiG3ycGaiNELkNeMJZcNk8YuZd6zjW6 m9MoUe2I/qNbpDnh4Mrqlw8yTjxcoSjBlxEfbeiVDGySDJL/xLfFytuxe8R7DztC7EVP /yH65x60f0fU7p8VgWoczhtUU9/UwxGtuPWPjWL+kQruwY0xsV6scItLpHE8uWOOdnZY d3pw== X-Gm-Message-State: AOAM532/w7NI6BFrlD63vGLzg91PPKEqg6XyrwWkb+Fy2oo6vwK4359S tVC88KS7RiLoev9LTeOIAUZZREyoEzB9FK8lY30= X-Received: by 2002:a17:902:ea8a:: with SMTP id x10mr10688473plb.255.1590790087561; Fri, 29 May 2020 15:08:07 -0700 (PDT) MIME-Version: 1.0 References: <17cb2b080b9c4c36cf84436bc5690739590acc53.1590017578.git.syednwaris@gmail.com> <202005242236.NtfLt1Ae%lkp@intel.com> <20200529183824.GW1634618@smile.fi.intel.com> In-Reply-To: From: Andy Shevchenko Date: Sat, 30 May 2020 01:07:51 +0300 Message-ID: Subject: Re: [PATCH v7 1/4] bitops: Introduce the the for_each_set_clump macro To: Syed Nayyar Waris Cc: Andy Shevchenko , Linus Walleij , Andrew Morton , William Breathitt Gray , Arnd Bergmann , Linux-Arch , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 30, 2020 at 12:42 AM Andy Shevchenko wrote: > On Fri, May 29, 2020 at 11:07 PM Syed Nayyar Waris wrote: > > On Sat, May 30, 2020 at 12:08 AM Andy Shevchenko > > wrote: ... > > Explanation: > > Actually when nbits (clump size) is 64 (BITS_PER_LONG is 64 on my computer), > > (BIT(nbits) - 1) > > gives a value of zero and when this zero is ANDed with any value, it > > makes it full zero. This is unexpected and incorrect calculation happening. > > > > What actually happens is in the macro expansion of BIT(64), that is 1 > > << 64, the '1' overflows from leftmost bit position (most significant > > bit) and re-enters at the rightmost bit position (least significant > > bit), therefore 1 << 64 becomes '0x1', and when another '1' is > > subtracted from this, the final result becomes 0. > > > > Since this macro is being used in both bitmap_get_value and > > bitmap_set_value functions, it will give unexpected results when nbits or clump > > size is BITS_PER_LONG (32 or 64 depending on arch). > > I see, something like > https://elixir.bootlin.com/linux/latest/source/include/linux/dma-mapping.h#L139 > should be done. > But yes, let's try to fix GENMASK(). > > So, if we modify the following > > #define GENMASK_INPUT_CHECK(h, l) \ > (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > __builtin_constant_p((l) > (h)), (l) > (h), 0))) > > to be > > #define GENMASK_INPUT_CHECK(h, l) \ > (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > __builtin_constant_p((l) > (h)), (l) ? (l) > (h) : 0, 0))) > > would it work? Actually it needs an amendment for signed types... (l) ? (l) > (h) : !((h) > 0) ...but today is Friday night, so, mistakes are warranted :-) -- With Best Regards, Andy Shevchenko