Message ID | 20230418114730.3674657-2-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2785402vqo; Tue, 18 Apr 2023 04:58:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ajpoEVJb6dq9HIFo2inBmtw5HPeJbqp3dsgHHYZHQIwac8AS0sLFhLAN8fHbCGV7FPmNBr X-Received: by 2002:a17:90a:bf08:b0:249:6098:b068 with SMTP id c8-20020a17090abf0800b002496098b068mr1661052pjs.45.1681819110385; Tue, 18 Apr 2023 04:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681819110; cv=none; d=google.com; s=arc-20160816; b=Tn4+aIc9HEV8V1AJFh5wmrJdN6qCLuzZOEp7T6RNuqU7sc4Y1biHbaBpPhV7Pm6Mu5 eTSoFEBytvWaUHPNHB1E/EOcH3DDC1ums/Em4Q98rbnct/9D70qKIXCmpgj9D2UMD/DT Du9YBe+VvWqHV7s4BotfTu7whf+u3tvaUS9/2LierH98RzlR2QGx+FM3kwSwUQVt2u5y aqpgsiaK47zLMx+1TkcQf4qn2aU3Wq4DpU/IhncHNWmyZCifk1Vps1VSy83EKaQSmta7 MRU93M5zUcGbfmvrWFZ8gyaaOiWokm03/JWUeS2rLNWI7i+KEBaN6NT3h54T05D0pVN+ T1qQ== 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:date:subject:cc:to:from :dkim-signature; bh=SVDY1VkWxnFCVTvcE/0Lu0AjE+r8PA/4cUtLSjZLJDY=; b=wIzn77vjbUarCS/q2bAO3tKNd8EMswlHAlnffFi1I1emiTCMPloQ5c8A5nhvEnWORn qnBPU7hjtuNqlRbHfSUVwbvlItVPzJpB2Jwyei/4fcHAd4uYxzTEw9mZQU0qUbITBr/2 A+64OwU8NOSXBpXkevvSoxFACFl2uLmfvf5uVYDlYEXsvH5Ab2IgyhitslrLMtL5bOcC XahR6e23QwmEgu9s/eZquzyTGPeS1GECnK9+HAn7Xh/MpLHh4uLOA3wv7SyY+LMckxfr yIQelXxer+BrGn7iKPMxAvNpEI5w8LDuL/iIpGtCrDxeYTkkhmq4cWOCB26ZdoRbw5Hc QO+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pYx+tjHw; 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 m9-20020a654389000000b0051f04512a26si2765197pgp.393.2023.04.18.04.58.18; Tue, 18 Apr 2023 04:58:30 -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=pYx+tjHw; 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 S231216AbjDRLuR (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 18 Apr 2023 07:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjDRLuO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Apr 2023 07:50:14 -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 4E32FAF02; Tue, 18 Apr 2023 04:49:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E20DD630C2; Tue, 18 Apr 2023 11:47:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEFF5C433D2; Tue, 18 Apr 2023 11:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681818477; bh=sX2PTY2QQR91FYj3Fp+THVg06q2dBOjIrndLtKeG1dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pYx+tjHwWXX/SbXLPifTRDMy7wfU1VOul+jnE4V1lTDxXvwtQCsjilBVKWruaRc4W lhc4rASBFjWQV4lobZNQP9Zj3AlVuIWmPMoS5Hwblym3TNDPMxrprC+NQxca5lzp13 CmpKFYJQe1dNJgEUQm9oDNAPF4vnOpWzxSex3FrJzdoeUnIpDENQTWbBmbwAjt0qq7 gZpTFkV0qt9t6ooD8bohkBiIZ73x5QCAWa4sK1koAFDZba2UPt9MwxzMkFy5hlfEu3 RGdYq69nwHD0GvJDmxwumQCeNB9ymQRjGObW9z15L23ibhCpe36EL/NpfFD46qK1R9 gQe038vEx8Okw== From: Arnd Bergmann <arnd@kernel.org> To: Yishai Hadas <yishaih@nvidia.com>, Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>, Tariq Toukan <tariqt@nvidia.com> Cc: Arnd Bergmann <arnd@arndb.de>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/2] net/mlx4: avoid overloading user/kernel pointers Date: Tue, 18 Apr 2023 13:47:12 +0200 Message-Id: <20230418114730.3674657-2-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418114730.3674657-1-arnd@kernel.org> References: <20230418114730.3674657-1-arnd@kernel.org> 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?1763515155394510310?= X-GMAIL-MSGID: =?utf-8?q?1763515155394510310?= |
Series |
[1/2] net/mlx4: fix build error from usercopy size check
|
|
Commit Message
Arnd Bergmann
April 18, 2023, 11:47 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The mlx4_ib_create_cq() and mlx4_init_user_cqes() functions cast between kernel pointers and user pointers, which is confusing and can easily hide bugs. Change the code to use use the correct address spaces consistently and use separate pointer variables in mlx4_cq_alloc() to avoid mixing them. Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- I ran into this while fixing the link error in the first patch, and decided it would be useful to clean up. --- drivers/infiniband/hw/mlx4/cq.c | 11 +++++++---- drivers/net/ethernet/mellanox/mlx4/cq.c | 17 ++++++++--------- include/linux/mlx4/device.h | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-)
Comments
On 18/04/2023 14:47, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The mlx4_ib_create_cq() and mlx4_init_user_cqes() functions cast > between kernel pointers and user pointers, which is confusing > and can easily hide bugs. > > Change the code to use use the correct address spaces consistently > and use separate pointer variables in mlx4_cq_alloc() to avoid > mixing them. > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > I ran into this while fixing the link error in the first > patch, and decided it would be useful to clean up. > --- > drivers/infiniband/hw/mlx4/cq.c | 11 +++++++---- > drivers/net/ethernet/mellanox/mlx4/cq.c | 17 ++++++++--------- > include/linux/mlx4/device.h | 2 +- missed the mlx4_cq_alloc usage in drivers/net/ethernet/mellanox/mlx4/en_cq.c. > 3 files changed, 16 insertions(+), 14 deletions(-) > > diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c > index 4cd738aae53c..b12713fdde99 100644 > --- a/drivers/infiniband/hw/mlx4/cq.c > +++ b/drivers/infiniband/hw/mlx4/cq.c > @@ -180,7 +180,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, > struct mlx4_ib_dev *dev = to_mdev(ibdev); > struct mlx4_ib_cq *cq = to_mcq(ibcq); > struct mlx4_uar *uar; > - void *buf_addr; > + void __user *ubuf_addr; > + void *kbuf_addr; > int err; > struct mlx4_ib_ucontext *context = rdma_udata_to_drv_context( > udata, struct mlx4_ib_ucontext, ibucontext); > @@ -209,7 +210,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, > goto err_cq; > } > > - buf_addr = (void *)(unsigned long)ucmd.buf_addr; > + ubuf_addr = u64_to_user_ptr(ucmd.buf_addr); > + kbuf_addr = NULL; > err = mlx4_ib_get_cq_umem(dev, &cq->buf, &cq->umem, > ucmd.buf_addr, entries); > if (err) > @@ -235,7 +237,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, > if (err) > goto err_db; > > - buf_addr = &cq->buf.buf; > + ubuf_addr = NULL; > + kbuf_addr = &cq->buf.buf; Now we should maintain the values of the two pointers before any call. I'm not sure this is less error-prune. One can mistakenly update kbuf_addr for example without nullifying ubuf_addr. Also, I'm not a big fan of passing two pointers when exactly one of them is effectively used. We can think maybe of passing a union of both types, and a boolean indicating which pointer type is to be used. > > uar = &dev->priv_uar; > cq->mcq.usage = MLX4_RES_USAGE_DRIVER; > @@ -248,7 +251,7 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, > &cq->mcq, vector, 0, > !!(cq->create_flags & > IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION), > - buf_addr, !!udata); > + ubuf_addr, kbuf_addr); > if (err) > goto err_dbmap; > > diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c > index 020cb8e2883f..22216f4e409b 100644 > --- a/drivers/net/ethernet/mellanox/mlx4/cq.c > +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c > @@ -287,7 +287,7 @@ static void mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn) > __mlx4_cq_free_icm(dev, cqn); > } > > -static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) > +static int mlx4_init_user_cqes(void __user *buf, int entries, int cqe_size) > { > int entries_per_copy = PAGE_SIZE / cqe_size; > size_t copy_size = array_size(entries, cqe_size); > @@ -307,7 +307,7 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) > > if (copy_size > PAGE_SIZE) { > for (i = 0; i < entries / entries_per_copy; i++) { > - err = copy_to_user((void __user *)buf, init_ents, PAGE_SIZE) ? > + err = copy_to_user(buf, init_ents, PAGE_SIZE) ? > -EFAULT : 0; > if (err) > goto out; > @@ -315,8 +315,7 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) > buf += PAGE_SIZE; > } > } else { > - err = copy_to_user((void __user *)buf, init_ents, > - copy_size) ? > + err = copy_to_user(buf, init_ents, copy_size) ? > -EFAULT : 0; > } > > @@ -343,7 +342,7 @@ static void mlx4_init_kernel_cqes(struct mlx4_buf *buf, > int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, > struct mlx4_mtt *mtt, struct mlx4_uar *uar, u64 db_rec, > struct mlx4_cq *cq, unsigned vector, int collapsed, > - int timestamp_en, void *buf_addr, bool user_cq) > + int timestamp_en, void __user *ubuf_addr, void *kbuf_addr) > { > bool sw_cq_init = dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SW_CQ_INIT; > struct mlx4_priv *priv = mlx4_priv(dev); > @@ -391,13 +390,13 @@ int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, > cq_context->db_rec_addr = cpu_to_be64(db_rec); > > if (sw_cq_init) { > - if (user_cq) { > - err = mlx4_init_user_cqes(buf_addr, nent, > + if (ubuf_addr) { > + err = mlx4_init_user_cqes(ubuf_addr, nent, > dev->caps.cqe_size); > if (err) > sw_cq_init = false; > - } else { > - mlx4_init_kernel_cqes(buf_addr, nent, > + } else if (kbuf_addr) { > + mlx4_init_kernel_cqes(kbuf_addr, nent, > dev->caps.cqe_size); > } > } > diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h > index 6646634a0b9d..dd8f3396dcba 100644 > --- a/include/linux/mlx4/device.h > +++ b/include/linux/mlx4/device.h > @@ -1126,7 +1126,7 @@ void mlx4_free_hwq_res(struct mlx4_dev *mdev, struct mlx4_hwq_resources *wqres, > int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt, > struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq, > unsigned int vector, int collapsed, int timestamp_en, > - void *buf_addr, bool user_cq); > + void __user *ubuf_addr, void *kbuf_addr); > void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq); > int mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align, > int *base, u8 flags, u8 usage);
On Wed, Apr 19, 2023, at 09:09, Tariq Toukan wrote: > On 18/04/2023 14:47, Arnd Bergmann wrote: > > Now we should maintain the values of the two pointers before any call. > I'm not sure this is less error-prune. One can mistakenly update > kbuf_addr for example without nullifying ubuf_addr. That would cause a compiler warning about the uninitialized variable. > Also, I'm not a big fan of passing two pointers when exactly one of them > is effectively used. > We can think maybe of passing a union of both types, and a boolean > indicating which pointer type is to be used. This is basically what you have today. I've dropped this patch from my randconfig tree and will ignore the problem. Arnd
Hi Arnd, kernel test robot noticed the following build warnings: [auto build test WARNING on soc/for-next] [also build test WARNING on linus/master v6.3-rc7 next-20230421] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/20230418114730.3674657-2-arnd%40kernel.org patch subject: [PATCH 2/2] net/mlx4: avoid overloading user/kernel pointers config: sparc-randconfig-s052-20230423 (https://download.01.org/0day-ci/archive/20230423/202304232230.hFVK5ix1-lkp@intel.com/config) compiler: sparc-linux-gcc (GCC) 12.1.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # apt-get install sparse # sparse version: v0.6.4-39-gce1a6720-dirty # https://github.com/intel-lab-lkp/linux/commit/1389cdaec07839abb7b8aacb2b16f37d4affd8d3 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238 git checkout 1389cdaec07839abb7b8aacb2b16f37d4affd8d3 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=sparc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=sparc SHELL=/bin/bash drivers/net/ethernet/mellanox/mlx4/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304232230.hFVK5ix1-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: sparse: incorrect type in argument 10 (different address spaces) @@ expected void [noderef] __user *ubuf_addr @@ got struct mlx4_buf * @@ drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: expected void [noderef] __user *ubuf_addr drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: got struct mlx4_buf * >> drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:74: sparse: sparse: Using plain integer as NULL pointer vim +141 drivers/net/ethernet/mellanox/mlx4/en_cq.c c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 88 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 89 int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq, 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 90 int cq_idx) c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 91 { c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 92 struct mlx4_en_dev *mdev = priv->mdev; 80a62deedf9d44 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 93 int irq, err = 0; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 94 int timestamp_en = 0; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 95 bool assigned_eq = false; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 96 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 97 cq->dev = mdev->pndev[priv->port]; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 98 cq->mcq.set_ci_db = cq->wqres.db.db; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 99 cq->mcq.arm_db = cq->wqres.db.db + 1; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 100 *cq->mcq.set_ci_db = 0; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 101 *cq->mcq.arm_db = 0; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 102 memset(cq->buf, 0, cq->buf_size); c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 103 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 104 if (cq->type == RX) { c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 105 if (!mlx4_is_eq_vector_valid(mdev->dev, priv->port, c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 106 cq->vector)) { de1618034ae570 drivers/net/ethernet/mellanox/mlx4/en_cq.c Ido Shamay 2015-05-31 107 cq->vector = cpumask_first(priv->rx_ring[cq->ring]->affinity_mask); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 108 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 109 err = mlx4_assign_eq(mdev->dev, priv->port, c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 110 &cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 111 if (err) { b0f6446377e72b drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 112 mlx4_err(mdev, "Failed assigning an EQ to CQ vector %d\n", b0f6446377e72b drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 113 cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 114 goto free_eq; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 115 } 35f6f45368632f drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2014-06-29 116 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 117 assigned_eq = true; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 118 } 80a62deedf9d44 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 119 irq = mlx4_eq_get_irq(mdev->dev, cq->vector); 197d2370772957 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 120 cq->aff_mask = irq_get_effective_affinity_mask(irq); 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 121 } else { 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 122 /* For TX we use the same irq per 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 123 ring we assigned for the RX */ 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 124 struct mlx4_en_cq *rx_cq; 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 125 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 126 cq_idx = cq_idx % priv->rx_ring_num; 41d942d56cfd21 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 127 rx_cq = priv->rx_cq[cq_idx]; 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 128 cq->vector = rx_cq->vector; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 129 } 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 130 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 131 if (cq->type == RX) 41d942d56cfd21 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 132 cq->size = priv->rx_ring[cq->ring]->actual_size; 38aab07c14adbf drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2009-05-24 133 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 134 if ((cq->type != RX && priv->hwtstamp_config.tx_type) || ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 135 (cq->type == RX && priv->hwtstamp_config.rx_filter)) ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 136 timestamp_en = 1; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 137 f3301870161ca2 drivers/net/ethernet/mellanox/mlx4/en_cq.c Moshe Shemesh 2017-06-21 138 cq->mcq.usage = MLX4_RES_USAGE_DRIVER; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 139 err = mlx4_cq_alloc(mdev->dev, cq->size, &cq->wqres.mtt, ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 140 &mdev->priv_uar, cq->wqres.db.dma, &cq->mcq, e45678973dcbb1 drivers/net/ethernet/mellanox/mlx4/en_cq.c Daniel Jurgens 2018-11-21 @141 cq->vector, 0, timestamp_en, &cq->wqres.buf, false); c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 142 if (err) c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 143 goto free_eq; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 144 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 145 cq->mcq.event = mlx4_en_cq_event; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 146 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 147 switch (cq->type) { 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 148 case TX: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 149 cq->mcq.comp = mlx4_en_tx_irq; 16d083e28f1a4f drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-05-04 150 netif_napi_add_tx(cq->dev, &cq->napi, mlx4_en_poll_tx_cq); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 151 napi_enable(&cq->napi); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 152 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 153 case RX: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 154 cq->mcq.comp = mlx4_en_rx_irq; b48b89f9c189d2 drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-09-27 155 netif_napi_add(cq->dev, &cq->napi, mlx4_en_poll_rx_cq); 0276a330617a0c drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 156 napi_enable(&cq->napi); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 157 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 158 case TX_XDP: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 159 /* nothing regarding napi, it's shared with rx ring */ 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 160 cq->xdp_busy = false; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 161 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 162 } 0276a330617a0c drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 163 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 164 return 0; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 165 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 166 free_eq: c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 167 if (assigned_eq) c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 168 mlx4_release_eq(mdev->dev, cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 169 cq->vector = mdev->dev->caps.num_comp_vectors; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 170 return err; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 171 } c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 172
Hi Arnd,
kernel test robot noticed the following build warnings:
[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v6.3 next-20230428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238
base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link: https://lore.kernel.org/r/20230418114730.3674657-2-arnd%40kernel.org
patch subject: [PATCH 2/2] net/mlx4: avoid overloading user/kernel pointers
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20230502/202305020739.Q8ObXAba-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/1389cdaec07839abb7b8aacb2b16f37d4affd8d3
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238
git checkout 1389cdaec07839abb7b8aacb2b16f37d4affd8d3
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/firmware/ drivers/hwmon/ drivers/mfd/ drivers/net/ethernet/mellanox/mlx4/ drivers/pinctrl/ drivers/power/supply/ drivers/staging/media/atomisp/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202305020739.Q8ObXAba-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:53: warning: expression which evaluates to zero treated as a null pointer constant of type 'void *' [-Wnon-literal-null-conversion]
cq->vector, 0, timestamp_en, &cq->wqres.buf, false);
^~~~~
1 warning generated.
vim +141 drivers/net/ethernet/mellanox/mlx4/en_cq.c
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 88
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 89 int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 90 int cq_idx)
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 91 {
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 92 struct mlx4_en_dev *mdev = priv->mdev;
80a62deedf9d449 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 93 int irq, err = 0;
ec693d47010e830 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 94 int timestamp_en = 0;
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 95 bool assigned_eq = false;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 96
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 97 cq->dev = mdev->pndev[priv->port];
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 98 cq->mcq.set_ci_db = cq->wqres.db.db;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 99 cq->mcq.arm_db = cq->wqres.db.db + 1;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 100 *cq->mcq.set_ci_db = 0;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 101 *cq->mcq.arm_db = 0;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 102 memset(cq->buf, 0, cq->buf_size);
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 103
ccc109b8ed24c6a drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 104 if (cq->type == RX) {
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 105 if (!mlx4_is_eq_vector_valid(mdev->dev, priv->port,
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 106 cq->vector)) {
de1618034ae5704 drivers/net/ethernet/mellanox/mlx4/en_cq.c Ido Shamay 2015-05-31 107 cq->vector = cpumask_first(priv->rx_ring[cq->ring]->affinity_mask);
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 108
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 109 err = mlx4_assign_eq(mdev->dev, priv->port,
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 110 &cq->vector);
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 111 if (err) {
b0f6446377e72bc drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 112 mlx4_err(mdev, "Failed assigning an EQ to CQ vector %d\n",
b0f6446377e72bc drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 113 cq->vector);
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 114 goto free_eq;
1fb9876e9bf895e drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 115 }
35f6f45368632f2 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2014-06-29 116
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 117 assigned_eq = true;
1fb9876e9bf895e drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 118 }
80a62deedf9d449 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 119 irq = mlx4_eq_get_irq(mdev->dev, cq->vector);
197d23707729579 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 120 cq->aff_mask = irq_get_effective_affinity_mask(irq);
1fb9876e9bf895e drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 121 } else {
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 122 /* For TX we use the same irq per
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 123 ring we assigned for the RX */
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 124 struct mlx4_en_cq *rx_cq;
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 125
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 126 cq_idx = cq_idx % priv->rx_ring_num;
41d942d56cfd210 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 127 rx_cq = priv->rx_cq[cq_idx];
76532d0c7e74249 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 128 cq->vector = rx_cq->vector;
1fb9876e9bf895e drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 129 }
1fb9876e9bf895e drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 130
ccc109b8ed24c6a drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 131 if (cq->type == RX)
41d942d56cfd210 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 132 cq->size = priv->rx_ring[cq->ring]->actual_size;
38aab07c14adbf3 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2009-05-24 133
ccc109b8ed24c6a drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 134 if ((cq->type != RX && priv->hwtstamp_config.tx_type) ||
ccc109b8ed24c6a drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 135 (cq->type == RX && priv->hwtstamp_config.rx_filter))
ec693d47010e830 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 136 timestamp_en = 1;
ec693d47010e830 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 137
f3301870161ca29 drivers/net/ethernet/mellanox/mlx4/en_cq.c Moshe Shemesh 2017-06-21 138 cq->mcq.usage = MLX4_RES_USAGE_DRIVER;
ec693d47010e830 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 139 err = mlx4_cq_alloc(mdev->dev, cq->size, &cq->wqres.mtt,
ec693d47010e830 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 140 &mdev->priv_uar, cq->wqres.db.dma, &cq->mcq,
e45678973dcbb13 drivers/net/ethernet/mellanox/mlx4/en_cq.c Daniel Jurgens 2018-11-21 @141 cq->vector, 0, timestamp_en, &cq->wqres.buf, false);
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 142 if (err)
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 143 goto free_eq;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 144
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 145 cq->mcq.event = mlx4_en_cq_event;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 146
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 147 switch (cq->type) {
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 148 case TX:
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 149 cq->mcq.comp = mlx4_en_tx_irq;
16d083e28f1a4f6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-05-04 150 netif_napi_add_tx(cq->dev, &cq->napi, mlx4_en_poll_tx_cq);
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 151 napi_enable(&cq->napi);
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 152 break;
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 153 case RX:
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 154 cq->mcq.comp = mlx4_en_rx_irq;
b48b89f9c189d24 drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-09-27 155 netif_napi_add(cq->dev, &cq->napi, mlx4_en_poll_rx_cq);
0276a330617a0cf drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 156 napi_enable(&cq->napi);
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 157 break;
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 158 case TX_XDP:
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 159 /* nothing regarding napi, it's shared with rx ring */
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 160 cq->xdp_busy = false;
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 161 break;
6c78511b0503c9b drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 162 }
0276a330617a0cf drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 163
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 164 return 0;
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 165
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 166 free_eq:
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 167 if (assigned_eq)
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 168 mlx4_release_eq(mdev->dev, cq->vector);
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 169 cq->vector = mdev->dev->caps.num_comp_vectors;
c66fa19c405a366 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 170 return err;
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 171 }
c27a02cd94d6695 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 172
Hi Arnd, kernel test robot noticed the following build warnings: [auto build test WARNING on soc/for-next] [also build test WARNING on linus/master v6.4-rc1 next-20230508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/20230418114730.3674657-2-arnd%40kernel.org patch subject: [PATCH 2/2] net/mlx4: avoid overloading user/kernel pointers config: loongarch-randconfig-s043-20230507 (https://download.01.org/0day-ci/archive/20230508/202305081441.iME4qFhY-lkp@intel.com/config) compiler: loongarch64-linux-gcc (GCC) 12.1.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # apt-get install sparse # sparse version: v0.6.4-39-gce1a6720-dirty # https://github.com/intel-lab-lkp/linux/commit/1389cdaec07839abb7b8aacb2b16f37d4affd8d3 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Arnd-Bergmann/net-mlx4-avoid-overloading-user-kernel-pointers/20230418-195238 git checkout 1389cdaec07839abb7b8aacb2b16f37d4affd8d3 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=loongarch olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=loongarch SHELL=/bin/bash drivers/net/ethernet/mellanox/mlx4/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202305081441.iME4qFhY-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: sparse: incorrect type in argument 10 (different address spaces) @@ expected void [noderef] __user *ubuf_addr @@ got struct mlx4_buf * @@ drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: expected void [noderef] __user *ubuf_addr drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:59: sparse: got struct mlx4_buf * >> drivers/net/ethernet/mellanox/mlx4/en_cq.c:141:74: sparse: sparse: Using plain integer as NULL pointer vim +141 drivers/net/ethernet/mellanox/mlx4/en_cq.c c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 88 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 89 int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq, 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 90 int cq_idx) c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 91 { c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 92 struct mlx4_en_dev *mdev = priv->mdev; 80a62deedf9d44 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 93 int irq, err = 0; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 94 int timestamp_en = 0; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 95 bool assigned_eq = false; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 96 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 97 cq->dev = mdev->pndev[priv->port]; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 98 cq->mcq.set_ci_db = cq->wqres.db.db; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 99 cq->mcq.arm_db = cq->wqres.db.db + 1; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 100 *cq->mcq.set_ci_db = 0; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 101 *cq->mcq.arm_db = 0; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 102 memset(cq->buf, 0, cq->buf_size); c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 103 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 104 if (cq->type == RX) { c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 105 if (!mlx4_is_eq_vector_valid(mdev->dev, priv->port, c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 106 cq->vector)) { de1618034ae570 drivers/net/ethernet/mellanox/mlx4/en_cq.c Ido Shamay 2015-05-31 107 cq->vector = cpumask_first(priv->rx_ring[cq->ring]->affinity_mask); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 108 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 109 err = mlx4_assign_eq(mdev->dev, priv->port, c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 110 &cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 111 if (err) { b0f6446377e72b drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 112 mlx4_err(mdev, "Failed assigning an EQ to CQ vector %d\n", b0f6446377e72b drivers/net/ethernet/mellanox/mlx4/en_cq.c Carol L Soto 2015-08-27 113 cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 114 goto free_eq; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 115 } 35f6f45368632f drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2014-06-29 116 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 117 assigned_eq = true; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 118 } 80a62deedf9d44 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 119 irq = mlx4_eq_get_irq(mdev->dev, cq->vector); 197d2370772957 drivers/net/ethernet/mellanox/mlx4/en_cq.c Thomas Gleixner 2020-12-10 120 cq->aff_mask = irq_get_effective_affinity_mask(irq); 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 121 } else { 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 122 /* For TX we use the same irq per 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 123 ring we assigned for the RX */ 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 124 struct mlx4_en_cq *rx_cq; 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 125 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 126 cq_idx = cq_idx % priv->rx_ring_num; 41d942d56cfd21 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 127 rx_cq = priv->rx_cq[cq_idx]; 76532d0c7e7424 drivers/net/ethernet/mellanox/mlx4/en_cq.c Alexander Guller 2011-10-09 128 cq->vector = rx_cq->vector; 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 129 } 1fb9876e9bf895 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2011-03-22 130 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 131 if (cq->type == RX) 41d942d56cfd21 drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-11-07 132 cq->size = priv->rx_ring[cq->ring]->actual_size; 38aab07c14adbf drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2009-05-24 133 ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 134 if ((cq->type != RX && priv->hwtstamp_config.tx_type) || ccc109b8ed24c6 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2016-11-02 135 (cq->type == RX && priv->hwtstamp_config.rx_filter)) ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 136 timestamp_en = 1; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 137 f3301870161ca2 drivers/net/ethernet/mellanox/mlx4/en_cq.c Moshe Shemesh 2017-06-21 138 cq->mcq.usage = MLX4_RES_USAGE_DRIVER; ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 139 err = mlx4_cq_alloc(mdev->dev, cq->size, &cq->wqres.mtt, ec693d47010e83 drivers/net/ethernet/mellanox/mlx4/en_cq.c Amir Vadai 2013-04-23 140 &mdev->priv_uar, cq->wqres.db.dma, &cq->mcq, e45678973dcbb1 drivers/net/ethernet/mellanox/mlx4/en_cq.c Daniel Jurgens 2018-11-21 @141 cq->vector, 0, timestamp_en, &cq->wqres.buf, false); c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 142 if (err) c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 143 goto free_eq; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 144 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 145 cq->mcq.event = mlx4_en_cq_event; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 146 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 147 switch (cq->type) { 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 148 case TX: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 149 cq->mcq.comp = mlx4_en_tx_irq; 16d083e28f1a4f drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-05-04 150 netif_napi_add_tx(cq->dev, &cq->napi, mlx4_en_poll_tx_cq); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 151 napi_enable(&cq->napi); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 152 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 153 case RX: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 154 cq->mcq.comp = mlx4_en_rx_irq; b48b89f9c189d2 drivers/net/ethernet/mellanox/mlx4/en_cq.c Jakub Kicinski 2022-09-27 155 netif_napi_add(cq->dev, &cq->napi, mlx4_en_poll_rx_cq); 0276a330617a0c drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 156 napi_enable(&cq->napi); 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 157 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 158 case TX_XDP: 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 159 /* nothing regarding napi, it's shared with rx ring */ 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 160 cq->xdp_busy = false; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 161 break; 6c78511b0503c9 drivers/net/ethernet/mellanox/mlx4/en_cq.c Tariq Toukan 2017-06-15 162 } 0276a330617a0c drivers/net/ethernet/mellanox/mlx4/en_cq.c Eugenia Emantayev 2013-12-19 163 c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 164 return 0; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 165 c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 166 free_eq: c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 167 if (assigned_eq) c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 168 mlx4_release_eq(mdev->dev, cq->vector); c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 169 cq->vector = mdev->dev->caps.num_comp_vectors; c66fa19c405a36 drivers/net/ethernet/mellanox/mlx4/en_cq.c Matan Barak 2015-05-31 170 return err; c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 171 } c27a02cd94d669 drivers/net/mlx4/en_cq.c Yevgeny Petrilin 2008-10-22 172
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c index 4cd738aae53c..b12713fdde99 100644 --- a/drivers/infiniband/hw/mlx4/cq.c +++ b/drivers/infiniband/hw/mlx4/cq.c @@ -180,7 +180,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, struct mlx4_ib_dev *dev = to_mdev(ibdev); struct mlx4_ib_cq *cq = to_mcq(ibcq); struct mlx4_uar *uar; - void *buf_addr; + void __user *ubuf_addr; + void *kbuf_addr; int err; struct mlx4_ib_ucontext *context = rdma_udata_to_drv_context( udata, struct mlx4_ib_ucontext, ibucontext); @@ -209,7 +210,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, goto err_cq; } - buf_addr = (void *)(unsigned long)ucmd.buf_addr; + ubuf_addr = u64_to_user_ptr(ucmd.buf_addr); + kbuf_addr = NULL; err = mlx4_ib_get_cq_umem(dev, &cq->buf, &cq->umem, ucmd.buf_addr, entries); if (err) @@ -235,7 +237,8 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, if (err) goto err_db; - buf_addr = &cq->buf.buf; + ubuf_addr = NULL; + kbuf_addr = &cq->buf.buf; uar = &dev->priv_uar; cq->mcq.usage = MLX4_RES_USAGE_DRIVER; @@ -248,7 +251,7 @@ int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, &cq->mcq, vector, 0, !!(cq->create_flags & IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION), - buf_addr, !!udata); + ubuf_addr, kbuf_addr); if (err) goto err_dbmap; diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c index 020cb8e2883f..22216f4e409b 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cq.c +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c @@ -287,7 +287,7 @@ static void mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn) __mlx4_cq_free_icm(dev, cqn); } -static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) +static int mlx4_init_user_cqes(void __user *buf, int entries, int cqe_size) { int entries_per_copy = PAGE_SIZE / cqe_size; size_t copy_size = array_size(entries, cqe_size); @@ -307,7 +307,7 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) if (copy_size > PAGE_SIZE) { for (i = 0; i < entries / entries_per_copy; i++) { - err = copy_to_user((void __user *)buf, init_ents, PAGE_SIZE) ? + err = copy_to_user(buf, init_ents, PAGE_SIZE) ? -EFAULT : 0; if (err) goto out; @@ -315,8 +315,7 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) buf += PAGE_SIZE; } } else { - err = copy_to_user((void __user *)buf, init_ents, - copy_size) ? + err = copy_to_user(buf, init_ents, copy_size) ? -EFAULT : 0; } @@ -343,7 +342,7 @@ static void mlx4_init_kernel_cqes(struct mlx4_buf *buf, int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt, struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq, unsigned vector, int collapsed, - int timestamp_en, void *buf_addr, bool user_cq) + int timestamp_en, void __user *ubuf_addr, void *kbuf_addr) { bool sw_cq_init = dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SW_CQ_INIT; struct mlx4_priv *priv = mlx4_priv(dev); @@ -391,13 +390,13 @@ int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, cq_context->db_rec_addr = cpu_to_be64(db_rec); if (sw_cq_init) { - if (user_cq) { - err = mlx4_init_user_cqes(buf_addr, nent, + if (ubuf_addr) { + err = mlx4_init_user_cqes(ubuf_addr, nent, dev->caps.cqe_size); if (err) sw_cq_init = false; - } else { - mlx4_init_kernel_cqes(buf_addr, nent, + } else if (kbuf_addr) { + mlx4_init_kernel_cqes(kbuf_addr, nent, dev->caps.cqe_size); } } diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h index 6646634a0b9d..dd8f3396dcba 100644 --- a/include/linux/mlx4/device.h +++ b/include/linux/mlx4/device.h @@ -1126,7 +1126,7 @@ void mlx4_free_hwq_res(struct mlx4_dev *mdev, struct mlx4_hwq_resources *wqres, int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt, struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq, unsigned int vector, int collapsed, int timestamp_en, - void *buf_addr, bool user_cq); + void __user *ubuf_addr, void *kbuf_addr); void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq); int mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align, int *base, u8 flags, u8 usage);