Message ID | 20230622101525.3321642-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4966330vqr; Thu, 22 Jun 2023 03:36:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fXLjpAYCO0Me4+KOsdJTkZJiqfdo9E8/RSMwMQoVU1NpxObKWUee7H0JGAq+orEhKew5y X-Received: by 2002:a05:6808:2810:b0:398:4761:20d with SMTP id et16-20020a056808281000b003984761020dmr18043691oib.19.1687430194564; Thu, 22 Jun 2023 03:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687430194; cv=none; d=google.com; s=arc-20160816; b=hhslY4hkyWd8MVwZdkudWzgaxXwGrhZHbic9MODftqCvDE9Wxi5PJoObgFiGM+jVhL iadkkZBfaqtx5OfW8pA5coV/XQcUNBhivEBYf8OsogaRl3T3DjovgvF5vpe28jjKcqrh Hfr265O63Qhl85v+jKNAfAoFWgTSv2hUDzGazJbb6daJyhAj1HHgYmiZ0i+DEKIb0Uif AwOFbjq4ux51pefdr3ic+Kw/XUyKPH/iIvLCtWdqOm/Gv5OjP8d8+UUsKWYY/PLab5lm 3+kNOqLcEydWGbYK/vaPTwu3EWR/U+4mMsw6JgtFDKX4fBtATfzlp4uOT3n9YyqN0aL0 ADFw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=1z6O6BfFnnLx77Pzmi+lY9/uXbeutcwdIx3ThhgsR3o=; b=bpkFt6xeDWpVlt40bOxNeWVKImdtzlzoYV+uPL5HgcqO/PEyn/loklCea1QSkprJ2E vzjgs+WGV8Xg2p+U1Oh7/pXBfMacXHSydpgp6HoI3ANJHsnkAzNZOrVNFwZcgY2Wfswo +1ZhxHUEZsINPmbtgYJ+qC9HVyL8OoB67DClUyn7vMghadNOgyAXwiEdZCgpaFRdVpUY 27DYlleJIEvxhyrT+ymUX43U3fztVrSSVsgVJTt6c9man7kYlI1R0jyXccH5sNrK1Zvw rZCwYP1Kjjq/MlzrNpcez6Jn0fsxqZ1e/vFVW4yfcVQrjFSHihAs/VOuvFdbPXoBoFXh OY6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AfDR9xsG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ob18-20020a17090b391200b0025698fca606si6881175pjb.109.2023.06.22.03.36.18; Thu, 22 Jun 2023 03:36:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AfDR9xsG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230494AbjFVKPu (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Thu, 22 Jun 2023 06:15:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231446AbjFVKPj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 22 Jun 2023 06:15:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B9421B4; Thu, 22 Jun 2023 03:15:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D2BA7616CB; Thu, 22 Jun 2023 10:15:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4208C433C0; Thu, 22 Jun 2023 10:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687428932; bh=ddwNq7oMVHZRi+PxOrJpIvndAOCIW9Xj14GqlgpwMA0=; h=From:To:Cc:Subject:Date:From; b=AfDR9xsGjodZLtdc65RB5nqBaVJu06rRUp21I7Hw3wetmfaWPNi5vdgNf3cKJBu8H wMZFvpAjv3u2x+bNi7eJ8BvWZWlyz/JE98CtHOH6xXFwIKcDSHvB7mezD7Gf7nIDud UX3pVYcs3yx6tjdW/kJIxuu7k5MF2OPL6AKGmdG/0pEoOYr5B1npe5I2VelDSACJdK MvgcTNwzAnG0s8LZVrTalK5QshnpzfVoPY/dXX8dZEi8olKSURfIUwzlzm1Aw4sMMf oIPXM+hczyzpELBKEMapdd7lRZO4iUzlWI2X31WaWhvwIEGX1Y3cnc9svGRVYLlGtc VTVqaOnaQ6XdA== From: Arnd Bergmann <arnd@kernel.org> To: Saeed Mahameed <saeedm@nvidia.com>, Leon Romanovsky <leon@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Arnd Bergmann <arnd@arndb.de>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Tariq Toukan <tariqt@nvidia.com>, Maxim Mikityanskiy <maxtram95@gmail.com>, Adham Faris <afaris@nvidia.com>, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] mlx5: avoid integer overflow warning for large page size Date: Thu, 22 Jun 2023 12:15:02 +0200 Message-Id: <20230622101525.3321642-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769398803294479033?= X-GMAIL-MSGID: =?utf-8?q?1769398803294479033?= |
Series |
mlx5: avoid integer overflow warning for large page size
|
|
Commit Message
Arnd Bergmann
June 22, 2023, 10:15 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de> Build testing with 'make LLVM=1 W=1' shows a warning about a condition that is always true on configurations with 64KB pages: drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare] Change the condition in a way that lets clang know this is intentional. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Thu, 22 Jun 2023 at 12:15:02 +0200, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > Build testing with 'make LLVM=1 W=1' shows a warning about a > condition that is always true on configurations with 64KB > pages: > > drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c:32:22: error: result of comparison of constant 65536 with expression of type 'u16' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare] > > Change the condition in a way that lets clang know this > is intentional. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c > index 36826b5824847..b9f62e531bd4c 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c > @@ -29,7 +29,8 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params, > struct mlx5_core_dev *mdev) > { > /* AF_XDP doesn't support frames larger than PAGE_SIZE. */ > - if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) { > + if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE) > + || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) { I recall you already sent a fix to silence this warning before: https://lore.kernel.org/netdev/20211015152056.2434853-1-arnd@kernel.org/ I prefer that old one, as it's more future-proof to cast to size_t here in place (chunk_size won't be bigger than size_t for sure). With your new patch, if chunk_size is ever changed from u16 to u32, it's likely that this place will be unnoticed, and a bug will be introduced. > mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size, > MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE); > return false; > -- > 2.39.2 >
On Thu, Jun 22, 2023, at 13:23, Maxim Mikityanskiy wrote: > On Thu, 22 Jun 2023 at 12:15:02 +0200, Arnd Bergmann wrote: > > I recall you already sent a fix to silence this warning before: > > https://lore.kernel.org/netdev/20211015152056.2434853-1-arnd@kernel.org/ > > I prefer that old one, as it's more future-proof to cast to size_t here > in place (chunk_size won't be bigger than size_t for sure). With your > new patch, if chunk_size is ever changed from u16 to u32, it's likely > that this place will be unnoticed, and a bug will be introduced. > >> mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size, >> MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE); Indeed, I don't know why I no longer had the old patch in my randconfig tree, I completely forgot about that. The old patch is also ok. Arnd
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c index 36826b5824847..b9f62e531bd4c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c @@ -29,7 +29,8 @@ bool mlx5e_validate_xsk_param(struct mlx5e_params *params, struct mlx5_core_dev *mdev) { /* AF_XDP doesn't support frames larger than PAGE_SIZE. */ - if (xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) { + if ((PAGE_SIZE < U16_MAX && xsk->chunk_size > PAGE_SIZE) + || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) { mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size, MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE); return false;