Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp59829lfe; Fri, 15 Apr 2022 19:28:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHCp3l2I41ndey+xUZ6Oq5laIbaZ+qLeM/5OC+pQGeG0/OjexyKkXQg8dnZgB6L9JfdKPz X-Received: by 2002:a05:6a00:178e:b0:508:2073:f635 with SMTP id s14-20020a056a00178e00b005082073f635mr1728899pfg.10.1650076113199; Fri, 15 Apr 2022 19:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076113; cv=none; d=google.com; s=arc-20160816; b=d7qG3muCwnE91xgAJdH/DOK/L/ZoUdEfO9KIErF83nTrhOKdGL7pld9RTS5pYxuHD2 W0PfCgZB0IIokpfZzaHmmLWIbd3miNAb20XwCCBy+NdqWgkFcy1E2OGPsS7ht3OOiTwZ mz4XC/hWOVKoe5SQgu/j4wRxs0wxhclOdrM5ke8P8aIp393STdmteuapxYaktENyNVs+ stImTF7JSRO7iJJWb78r+B+tfskYsteNyNiHTSBkiFERmYciUpT8JT6H1BbTGxG6H5Pu +3hBzRHBNx8m0oRJ+1NL32y6Q4uHSlFvlPYwSAdgO3oH1WIyyjdV2PNkjCGgz6JyKLGw Py/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=gD40bE7CA3nEbFCC4RvOWqz3pW6a2RcS6zm8BhERlxo=; b=iLZCtYbMBV/3/QUaEmZvVLOd4RY9MHCBfkoK6eac8rWlNQsgT8ehl2n/PtdgusIytB UMR7KNvvX9/IKoCdyRdAFImT18+2rzVw2zui+xC/UFILn2yWu+BEcNIGe4QZS9xcPYF2 m96G++usCZZfJ6GTGiWmI9wLK8ogEf3etRnMvdXFSsXpMFj9vj25IF3loSfANNhb2R2E WypQQFNEFtH1S6aSDH2OaMUCoZB/MyoMTdxh6RMbf50MaNAHo550fupPdQ0iir8O5z1D YwvHBV9eSiho7EczBOWas7h8M5xwKLlwMERvppwSmGRvpNf5kfEunk812N8HAWGGJC1c nrwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=C1aVC6ih; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s140-20020a632c92000000b003a2ece8b92bsi3034088pgs.219.2022.04.15.19.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:28:33 -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=@pm.me header.s=protonmail2 header.b=C1aVC6ih; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68739162196; Fri, 15 Apr 2022 18:40:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347312AbiDNWtU (ORCPT + 99 others); Thu, 14 Apr 2022 18:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347288AbiDNWtR (ORCPT ); Thu, 14 Apr 2022 18:49:17 -0400 X-Greylist: delayed 98 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 14 Apr 2022 15:46:49 PDT Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D74C6F32; Thu, 14 Apr 2022 15:46:49 -0700 (PDT) Date: Thu, 14 Apr 2022 22:46:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1649976407; bh=gD40bE7CA3nEbFCC4RvOWqz3pW6a2RcS6zm8BhERlxo=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=C1aVC6ihmrjtj8lQuyquB9RBqnf8GaT44/TGR+XaxR8nMZ6x6GWtkAvp8QODJgNz8 vAJmQjrWys4Iqn092ieJH35uZoJF5SgB4ShAOb5Wk/eHnQ3gyj9uwuyxK2+Oyygvkt DtJvm1Cscy0q8/NH2foPjX32AXJIIN+clYH+TL/n4wLU6NUng5qdiKwFFVhmrhlxDE YzrkoThbgG/wTXEJm6NoxJ7B6CVsgDl9P8LXzlU8dmjKuD6TXAPVgPFPiwdrtcp/kO 7RPD+732T0+G/q+rw91CjFDWYvqbPLM80ceEDcuL/Qm2Yw8HUVPPmYEb6WnbcwPiyI RmmdX98keMNzA== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= , Magnus Karlsson , Jonathan Lemon , Nathan Chancellor , Nick Desaulniers , Alexander Lobakin , Dmitrii Dolgov <9erthalion6@gmail.com>, Quentin Monnet , Tiezhu Yang , Kumar Kartikeya Dwivedi , Chenbo Feng , Willem de Bruijn , Daniel Wagner , Thomas Graf , Ong Boon Leong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Reply-To: Alexander Lobakin Subject: [PATCH bpf-next 08/11] samples: bpf: fix shifting unsigned long by 32 positions Message-ID: <20220414223704.341028-9-alobakin@pm.me> In-Reply-To: <20220414223704.341028-1-alobakin@pm.me> References: <20220414223704.341028-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 32 bit systems, shifting an unsigned long by 32 positions yields the following warning: samples/bpf/tracex2_kern.c:60:23: warning: shift count >=3D width of type [= -Wshift-count-overflow] unsigned int hi =3D v >> 32; ^ ~~ The usual way to avoid this is to shift by 16 two times (see upper_32_bits() macro in the kernel). Use it across the BPF sample code as well. Fixes: d822a1926849 ("samples/bpf: Add counting example for kfree_skb() fun= ction calls and the write() syscall") Fixes: 0fb1170ee68a ("bpf: BPF based latency tracing") Fixes: f74599f7c530 ("bpf: Add tests and samples for LWT-BPF") Signed-off-by: Alexander Lobakin --- samples/bpf/lathist_kern.c | 2 +- samples/bpf/lwt_len_hist_kern.c | 2 +- samples/bpf/tracex2_kern.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bpf/lathist_kern.c b/samples/bpf/lathist_kern.c index 4adfcbbe6ef4..9744ed547abe 100644 --- a/samples/bpf/lathist_kern.c +++ b/samples/bpf/lathist_kern.c @@ -53,7 +53,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; diff --git a/samples/bpf/lwt_len_hist_kern.c b/samples/bpf/lwt_len_hist_ker= n.c index 1fa14c54963a..bf32fa04c91f 100644 --- a/samples/bpf/lwt_len_hist_kern.c +++ b/samples/bpf/lwt_len_hist_kern.c @@ -49,7 +49,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; =09else diff --git a/samples/bpf/tracex2_kern.c b/samples/bpf/tracex2_kern.c index 5bc696bac27d..6bf22056ff95 100644 --- a/samples/bpf/tracex2_kern.c +++ b/samples/bpf/tracex2_kern.c @@ -57,7 +57,7 @@ static unsigned int log2(unsigned int v) static unsigned int log2l(unsigned long v) { -=09unsigned int hi =3D v >> 32; +=09unsigned int hi =3D (v >> 16) >> 16; =09if (hi) =09=09return log2(hi) + 32; =09else -- 2.35.2