Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp63254iof; Sun, 5 Jun 2022 21:12:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqpSBQIeAvBz1i62lYq78jGT7ZaZhQ+z+CYi+/hh79zaLjvu79MB9BEVeuuGHCArHu+je3 X-Received: by 2002:a17:90a:ab90:b0:1da:375f:2f44 with SMTP id n16-20020a17090aab9000b001da375f2f44mr24243435pjq.33.1654488726121; Sun, 05 Jun 2022 21:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654488726; cv=none; d=google.com; s=arc-20160816; b=FTjj6trrpgso3wPEfvty2omTDauwiF0iquwCocZfGiulBlXiN8OWFiUBAQiMz6wuae p8uDfZKyhI/XJ5TjkVy1Vbp65y4fj1Ker/JmmUtJOSpXb00WqVQszgNH4Au0V4iaLgkZ Cw7zJB2BuQOFySY6Iss+UGEPf32cfX9rVbzgXaYrfygTXJgDsqrZii7C5RuZZbONUANv bLxv9BU6NMR6exriLd7ZTHOSr885ayg9AVe440ORSTRD1k29G/NIyBlM+HGO/K1VFhQC R0/HW9iQMV8qQh+ciSOl1NQ2HNQJ6fczpM6vViSBD89ZLivLMl5Nmr9RFfqtCf5aPDIl 9tdA== 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=eO43q8JT8AT25MGSbylOq4L/CpABvSv2du0djS6sehA=; b=Hr8JHRP2vSoZOzVaty/JyXFApuaO3BwZ5lOAzU9Pq67/uKqydn5ZRi1fZ47NJelqQ7 ZvnuGCY1V70Wh/h5kFG6pDG1trh1fmE+KIPhLb6IQnniIp3rLPxKZ9F37KTiBY6ZHdzO fe0nbyCJEuNGLJhBkVrYuYNr5h//o531WwkMdFWmmpG3Mo8LCcprJFO3ZC9hEIsmKnp0 yHheJLXYCa9lBVxBtcQZOaxj8Mcj6wMqVuaM6LlVrEdaEeX7MfI88AJNnDSBDpiz6ihh D222wOhEHKvn5RcC68CzKdnEyrEj8nmuHaohDhBZwbWmDtORtT1QEdVkFv7NhhzKWwPc E46A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="P/97q019"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id my17-20020a17090b4c9100b001e8637cb83dsi7166811pjb.89.2022.06.05.21.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:12:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="P/97q019"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A514F7222C; Sun, 5 Jun 2022 20:50:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240788AbiFCFfe (ORCPT + 99 others); Fri, 3 Jun 2022 01:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbiFCFfb (ORCPT ); Fri, 3 Jun 2022 01:35:31 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A468C38DB6; Thu, 2 Jun 2022 22:35:30 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id o15so7353069ljp.10; Thu, 02 Jun 2022 22:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eO43q8JT8AT25MGSbylOq4L/CpABvSv2du0djS6sehA=; b=P/97q019CzWcs+L2gPt9QiGVXh/uYt7kgeU0EIf4p6CoyrGqwWo7y9/z73AdNyH83L glFYiP6OYRhOUoF20JGcoqmVZv5VGrLDGdnM8rGi9NW0DuAdTmT4L20EmFLZv+UzHzJ+ h7tPFYxfOVkNjJbO2WjnxiqOx1zdycWQRHVQYrCOkqtMtGVupShAB8PQxYRLsb7DT+Qw n7dF039HfS5z47CrgfJDgxMYGr4oFKFi1FjnBFySjArdEc8fNsfHjBz02F2tRoWkI7L5 e9kxAFfLPkRSJ/loHG2XlH3TBs1iel1x5oVeImHKgZt2Pqe9EpCIoZ2yzEoIrYukV/Ov zr2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eO43q8JT8AT25MGSbylOq4L/CpABvSv2du0djS6sehA=; b=r5AATzNNuPFbrG0/1jo3JOm/8x8N6l9PVkHHNH1dSixRNeUYYGqbeoeZXibGpxCvkB 8BUMHSGgifm2ocUxg86GyQjIONwLQAL5uGUjGdDIzHB7NEGN6VBFR7cjQwuiLHlQd1ma BNqkuWcwcm5evYaEn4O1m7eqmtSEgvpRtLkErSP58yDM2tXVeR63VXxoMWXQDFJpMivu 62Vm73nyzKf9UFb3KEoQl1foazFRX66Qq4Ba4ESNyBu8HF8V8Ipnbgr9MuVTQWPnFcZe QOwbgYkgvVpENqx8pOS5jRfNix50gsDWDxFkW70Ssyp55DahgIgGfNZSa0hwveP6/DJy pmfQ== X-Gm-Message-State: AOAM531QKQ8ggdqJCFsIppOx4R0DzCJ8rQp/JNF6/o1zdXVAwZhVZmg2 R2bNX1RkymV+41Wgp+oYU98ymrTL+9O5I2YCBQ0= X-Received: by 2002:a2e:a7c5:0:b0:253:ee97:f9b7 with SMTP id x5-20020a2ea7c5000000b00253ee97f9b7mr31934085ljp.472.1654234528865; Thu, 02 Jun 2022 22:35:28 -0700 (PDT) MIME-Version: 1.0 References: <20220603041701.2799595-1-irogers@google.com> In-Reply-To: From: Andrii Nakryiko Date: Thu, 2 Jun 2022 22:35:17 -0700 Message-ID: Subject: Re: [PATCH] libbpf: Fix is_pow_of_2 To: Zvi Effron Cc: Ian Rogers , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list , Yuze Chi Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 2, 2022 at 10:33 PM Andrii Nakryiko wrote: > > On Thu, Jun 2, 2022 at 9:31 PM Zvi Effron wrote: > > > > On Thu, Jun 2, 2022 at 9:17 PM Ian Rogers wrote: > > > > > > From: Yuze Chi > > > > > > There is a missing not. Consider a power of 2 number like 4096: > > > > > > x && (x & (x - 1)) > > > 4096 && (4096 & (4096 - 1)) > > > 4096 && (4096 & 4095) > > > 4096 && 0 > > > 0 > > > > > > with the not this is: > > > x && !(x & (x - 1)) > > > 4096 && !(4096 & (4096 - 1)) > > > 4096 && !(4096 & 4095) > > > 4096 && !0 > > > 4096 && 1 > > > 1 > > > > > > Reported-by: Yuze Chi > > > Signed-off-by: Yuze Chi > > > Signed-off-by: Ian Rogers also can you please add Fixes: tag? > > > --- > > > tools/lib/bpf/libbpf.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > > index 3f4f18684bd3..fd0414ea00df 100644 > > > --- a/tools/lib/bpf/libbpf.c > > > +++ b/tools/lib/bpf/libbpf.c > > > @@ -4956,7 +4956,7 @@ static void bpf_map__destroy(struct bpf_map *map); > > > > > > static bool is_pow_of_2(size_t x) > > > { > > > - return x && (x & (x - 1)); > > > + return x && !(x & (x - 1)); > > ugh... *facepalm* > > > > > No idea if anyone cares about the consistency, but in linker.c (same directory) > > the same static function is defined using == 0 at the end instead of using the > > not operator. > > > > Aside from the consistency issue, personally I find the == 0 version a little > > bit easier to read and understand because it's a bit less dense (and a "!" next > > to a "(" is an easy character to overlook). > > > > I agree, even more so, logical not used with arbitrary integer (not a > pointer or bool) is a mental stumbling block for me, so much so that I > avoid doing !strcmp(), for example. > > But in this case, I'm not sure why I copy/pasted is_pow_of_2() instead > of moving the one from linker.c into libbpf_internal.h as static > inline. Let's do that instead? > > > > } > > > > > > static size_t adjust_ringbuf_sz(size_t sz) > > > -- > > > 2.36.1.255.ge46751e96f-goog > > >