Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp8637064pxu; Sun, 27 Dec 2020 14:05:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDe50KtIDYpZoUzCxnQKIjftUiqDYCPHMi1n/joYJITlj8sBL0asm+/VAEBwASFHW+uJh9 X-Received: by 2002:a50:8744:: with SMTP id 4mr36099491edv.362.1609106746728; Sun, 27 Dec 2020 14:05:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609106746; cv=none; d=google.com; s=arc-20160816; b=yqggSJjVsFwGqPw96qVR9f6zEvw79pYAK0kbEtkyuZSc3mTCcnmldvmlRlyes/0n1N onEyd0mt7XdhZGR2ZlWdvpK09zklKjP+k075L4/qebGr76pOn1NWoFTA/wkTIO4+Nleg 9j5gj3+795RsRsYata0HvEvbgQ79kJykitxAH0M3Ws0v2dl7kSB2RYOkJ3U/ogudCd// V4LDSkkgxBhuCqcKR9slVH01VAUDr30dPA/DbAftdIX2R2B00fh1eeP+A3y7ETXFI7iH /5LexI679+u8lN3L8GnHmx2P6bxbdwDwl81NwnZj1gXWuLC397uAeQm2l6EaZ/RLP6H3 zn6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8c1a+MkZI+yg2u0PZMWR4c+8Ydr9W0h4lalZM8sUpaw=; b=YYd5WHPV54dTyir0EH1gGG0w5cmjyJ/WllZ0kEWkidkHE+zLb0L6xykIiHrhqerDMD WgQTeOVNE2wUH9k4fZmhJsC8YXcNkotnNZG+0XlYzAmTvKVZABU3Nh1mcv9SJEHuG7k9 dvGt/UAPd0tte0FGv6vXdRU2iFD/zK80FP7FLpMlgSS+Qb/zS8X1tIbiSPxGJWVPmEQK GcM0KbdZ5v+FJKGYz/ts5ZOG9e8VuC9ejXQnFy0UvGCWbtBmlPYV8N/ufaavGLONgOq6 PYxq+LE6VDjBxkO4+oJ6Cnowg54D8GJiJTjBLQZbi19XfLrhZM9461jEwL0JzshuMoRL HctQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eP3I77v/"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si19997764ejd.607.2020.12.27.14.05.24; Sun, 27 Dec 2020 14:05:46 -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=@kernel.org header.s=k20201202 header.b="eP3I77v/"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726276AbgL0WEE (ORCPT + 99 others); Sun, 27 Dec 2020 17:04:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:42066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgL0WEE (ORCPT ); Sun, 27 Dec 2020 17:04:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 313262242A; Sun, 27 Dec 2020 22:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609106603; bh=gQ23fPbegXnDwD7TFyM8SYshRz6kzvTEijfM7w8+3s0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eP3I77v/R0SuCfmOw5xMVPxQnv7vqNSHyEb7kTOVyaOZ56khQIC881SVGrCvmRuK/ OnGKFQmEba8jgBZfYtBJesyyezVYlmLJBBG5TbALHXgihg0mgp9u2ugEiaJYvE8LHh 21A0ExJ0hASZRD8stNtGn1jR15j6gRyE4V6d5calcnUKi9ph1/hg7PXnZokDkU9Sid a2SxFj7ukZSCw1ttAyk6DXtPfKYYCohivw5nxHOOPg6tf6O4JZDuV2H0FJzVPDYGzC stWxbH8KXccygJLVdQnwgqfZbDZgv6R7PK/PHxxP+2vN1AVylU6Xip5xt/VWhKO/F5 FZHmn9dBUPs+w== Received: by mail-ot1-f51.google.com with SMTP id n42so7770925ota.12; Sun, 27 Dec 2020 14:03:23 -0800 (PST) X-Gm-Message-State: AOAM532R4llhtRLxOWgVET0xMYZu5SJnsiCH5LkX7MO+h6bZ9At8DG4N 9h+slvgjWzmcDqIWZFRRt2N3G8Q0t0WbcD7pzdE= X-Received: by 2002:a9d:7a4b:: with SMTP id z11mr31374431otm.305.1609106602554; Sun, 27 Dec 2020 14:03:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Sun, 27 Dec 2020 23:03:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] clump_bits: Introduce the for_each_set_clump macro To: Syed Nayyar Waris Cc: Linus Walleij , Andy Shevchenko , William Breathitt Gray , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. 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. Arnd