From patchwork Thu Oct 13 23:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13006567 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54682C433FE for ; Thu, 13 Oct 2022 23:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229723AbiJMXnz (ORCPT ); Thu, 13 Oct 2022 19:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbiJMXnx (ORCPT ); Thu, 13 Oct 2022 19:43:53 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F4018C432; Thu, 13 Oct 2022 16:43:52 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id s3so2747816qtn.12; Thu, 13 Oct 2022 16:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G18TrD4h2uU6xMEPcn2BmBrOSK5xUMCgwUorehbNn3E=; b=hV7m+NkbyGPgklf1+F/DT1pwowFUEIzGPV+HojphrU4JWEjDGD77e3CsoEfEsEGpD3 sGMgx0IUVx48mJwTNlN9xSwqnLG/YgHLLNgkpkKjlvkBP1UzcVx9yn/Niu3xCzFo6k+9 FR/ZKm9Ks+ycqm6iSlE4yWFmzBTTdSr0FI/B2CAqdQGBpZ3CgApBQbbBd4c0OeFS+ZgN lmmk0Jv/294mbF08MjFXuMNrPqvR283fWg58K2IgwilDxCdWIvWYoL3C3VMTQVC0/Lcd rV5lwKq9Db87iL/DplecX/Dz9fd8H4sgL85ks0oOwh8XrWeguXT6zNqfVDK7Dbvze5c0 EjaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G18TrD4h2uU6xMEPcn2BmBrOSK5xUMCgwUorehbNn3E=; b=4xCkm0B+kY5UUz02lY58D0aF5H9OjjLOBQeuhGUFPWjXgGvDSgHA3Zw08X8tbUDAA+ XM4gkNMoGqmRRUqQJ2KnMEQg92N2UMp5UDEMqPzfe5U03q+wQWlpB7iie6eys5VcqfbL TAx6AQ9qzQM+ZUsNMN6r0KFORFtNoxBHBCTxLZxWrk9A003PJjhj831nam1FZUOsKEcp M5zwhARk2loyWBJPP4WbaSijOO0VgFiAPAOVBtUJt9JV1bO2hxbooScLz3z2o08wV/L7 /h2C1Nae+rjGs9ZyE9zHKmhKLxtAzPeuA/8d2Tgo6nn4mxZlaROsgSmGbxKqPHorC2AF 8Idg== X-Gm-Message-State: ACrzQf22yKEczTthuYLgpe/EEcsgRXen5zteUUhOntjP7BB82mfDim9Z EInLhfE8FCe8/eqnFz5AkVdWBnG1jVI= X-Google-Smtp-Source: AMsMyM4/+TX3wlhpVD7Bfm5EEEjy0nM9y8rYWjsJy8B/2eaSUzza3HspCgI9qGM+2fzB/PW+9cgabg== X-Received: by 2002:a05:622a:10a:b0:39c:c4fd:4c6e with SMTP id u10-20020a05622a010a00b0039cc4fd4c6emr2032962qtw.441.1665704631669; Thu, 13 Oct 2022 16:43:51 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:ec49:7545:4026:a70a]) by smtp.gmail.com with ESMTPSA id o16-20020a05620a2a1000b006e6a7c2a269sm1106212qkp.22.2022.10.13.16.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 16:43:51 -0700 (PDT) From: Yury Norov To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sebastian Andrzej Siewior , Menglong Dong , Kuniyuki Iwashima , Petr Machata , Guo Ren , "Michael S . Tsirkin" Cc: Yury Norov , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] net: move setup code out of mutex in __netif_set_xps_queue() Date: Thu, 13 Oct 2022 16:43:45 -0700 Message-Id: <20221013234349.1165689-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013234349.1165689-1-yury.norov@gmail.com> References: <20221013234349.1165689-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org maps_sz, nr_ids and online_mask may be set out of the mutex. Signed-off-by: Yury Norov --- net/core/dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index fa53830d0683..70fa12c6551c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2563,9 +2563,6 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, return -EINVAL; } - mutex_lock(&xps_map_mutex); - - dev_maps = xmap_dereference(dev->xps_maps[type]); if (type == XPS_RXQS) { maps_sz = XPS_RXQ_DEV_MAPS_SIZE(num_tc, dev->num_rx_queues); nr_ids = dev->num_rx_queues; @@ -2579,6 +2576,10 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, if (maps_sz < L1_CACHE_BYTES) maps_sz = L1_CACHE_BYTES; + mutex_lock(&xps_map_mutex); + + dev_maps = xmap_dereference(dev->xps_maps[type]); + /* The old dev_maps could be larger or smaller than the one we're * setting up now, as dev->num_tc or nr_ids could have been updated in * between. We could try to be smart, but let's be safe instead and only From patchwork Thu Oct 13 23:43:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13006569 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20E7FC43217 for ; Thu, 13 Oct 2022 23:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbiJMXn4 (ORCPT ); Thu, 13 Oct 2022 19:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiJMXny (ORCPT ); Thu, 13 Oct 2022 19:43:54 -0400 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BF1D18C420; Thu, 13 Oct 2022 16:43:53 -0700 (PDT) Received: by mail-qv1-xf30.google.com with SMTP id i9so2334046qvo.0; Thu, 13 Oct 2022 16:43:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZQAqY2iBEAF+eHjrg4p1Q7JBNhxxMmTUjqoLxsrSWas=; b=aznCgpDPTh35a7GcoUgO1SyOcJ08mbe2AMMouLB+ymCrGnO2LK3l8RLG3Jne2HwKem 1/EH6fj8XeH6BqxSWclUUusYc5WaTd5wmEuEM49rJn7XVnpdRilUcejawkOQjCNmnZHz 9KC7VTcXx5o+tBja51juWpavfI1qptDviM/Ou73nCyTX0hCjyB6feboCr+cpJoMcAhkz qQORGbNEF+sHddZd+7+JBDHLZqIa5KcWJbX6sx4oEwnaG1u9xQfWRYy4ksKQojazOoNj Wx5RQpVA8NEPqY3DCghc4Gvo/gBVUv6dqDy3kcptztvxORbtJxF8yuS5bSjBeWaAh09e rrhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZQAqY2iBEAF+eHjrg4p1Q7JBNhxxMmTUjqoLxsrSWas=; b=RvICdhfPbh78lYX0FoHuvPV9aqrSyxpSCnPnyvnGPMYKAV3fUF45/XlUAxuq+X8r2e 7IJ93s2AWuyNeinT37v9vXOz5fVjZkGu/0SCkTRu/2rx9HVEj6HRJ3+pHuYNvSo+0sjX bxcl+IwbFN1i/UMMLcy9aTnVV4u+RTraQ51Cawr9h7yxFC5ALM2ag0+jrNNkyUdPSHWo azYjYa2gHtYZBwmLVP3SZWSx1++3t6dVVsxxweNlK7NGcPPSONtpxeCBwDGf7HSnjE9n 6D8u18Uork4T+WAAFN7czIsT/Qt77310v9e/cVMozBcE0cL0X4sTF+fqrU2GAKZ5q760 7F3w== X-Gm-Message-State: ACrzQf35CinxiFQbCXQeivHeyiD1grORRMUHlBv5aBbeooUSf/rP6l2m H8kD0N+RPbiIDztDCYOjk2y9M9N4RNI= X-Google-Smtp-Source: AMsMyM5d0WGLq0eD43VmHqzvR93znPmQAN53P+QMH2r28rkhP4ZajzhlpCUfzcCBQUyeg2enRskVzw== X-Received: by 2002:a05:6214:1c47:b0:4b1:8ee7:9fb0 with SMTP id if7-20020a0562141c4700b004b18ee79fb0mr2228838qvb.42.1665704632492; Thu, 13 Oct 2022 16:43:52 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:ec49:7545:4026:a70a]) by smtp.gmail.com with ESMTPSA id y11-20020ac8524b000000b0039bde72b14asm876687qtn.92.2022.10.13.16.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 16:43:52 -0700 (PDT) From: Yury Norov To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sebastian Andrzej Siewior , Menglong Dong , Kuniyuki Iwashima , Petr Machata , Guo Ren , "Michael S . Tsirkin" Cc: Yury Norov , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] net: merge XPS_CPU_DEV_MAPS_SIZE and XPS_RXQ_DEV_MAPS_SIZE macros Date: Thu, 13 Oct 2022 16:43:46 -0700 Message-Id: <20221013234349.1165689-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013234349.1165689-1-yury.norov@gmail.com> References: <20221013234349.1165689-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The macros are used in a single place, and merging them would simplify the code. Signed-off-by: Yury Norov --- include/linux/netdevice.h | 7 ++----- net/core/dev.c | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index a36edb0ec199..53d738f66159 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -825,11 +825,8 @@ struct xps_dev_maps { struct xps_map __rcu *attr_map[]; /* Either CPUs map or RXQs map */ }; -#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \ - (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *))) - -#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\ - (_rxqs * (_tcs) * sizeof(struct xps_map *))) +#define XPS_DEV_MAPS_SIZE(_tcs, nr) (sizeof(struct xps_dev_maps) +\ + ((nr) * (_tcs) * sizeof(struct xps_map *))) #endif /* CONFIG_XPS */ diff --git a/net/core/dev.c b/net/core/dev.c index 70fa12c6551c..9dc6fcb0d48a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2564,15 +2564,14 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, } if (type == XPS_RXQS) { - maps_sz = XPS_RXQ_DEV_MAPS_SIZE(num_tc, dev->num_rx_queues); nr_ids = dev->num_rx_queues; } else { - maps_sz = XPS_CPU_DEV_MAPS_SIZE(num_tc); if (num_possible_cpus() > 1) online_mask = cpumask_bits(cpu_online_mask); nr_ids = nr_cpu_ids; } + maps_sz = XPS_DEV_MAPS_SIZE(num_tc, nr_ids); if (maps_sz < L1_CACHE_BYTES) maps_sz = L1_CACHE_BYTES; From patchwork Thu Oct 13 23:43:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13006568 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03D66C4332F for ; Thu, 13 Oct 2022 23:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiJMXn6 (ORCPT ); Thu, 13 Oct 2022 19:43:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiJMXnz (ORCPT ); Thu, 13 Oct 2022 19:43:55 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA0818C434; Thu, 13 Oct 2022 16:43:54 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id i9so2334060qvo.0; Thu, 13 Oct 2022 16:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kwG+9wq4H/ajQFHnHol/XkFDuB13Bjyau0OIo4dYrHg=; b=CMIHpFdUR5W6pPnxGWURT78iCHQoH6PUNtbjbZYwupfb38uVFND/cuhtNztdDo8kJ4 +5D0M69jODJpBkPsZs6GC0ChV6mzglk9MdkVdqjs2iMUSgqrpRrRk/0EnyfulQtqBUrK 4gBvyNT+XTNha8hIp9vT+Jwl0gcl23OEymTG2vp+wQF3tC3HC/tYLMGT7FKmhxSz+s3R 9LxTdZU0pFCkF+V/ymL3HomjKs3d9hLWBAeUx70yp2EUKZTlvfAdyLKFRi4snRMUzq07 ArWW15Y43sDZGFzCG1KpW5F0pzOWQHazvSmFebjutnHNwIggm/uJ6Q4LNyze8keS1IWK mNzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kwG+9wq4H/ajQFHnHol/XkFDuB13Bjyau0OIo4dYrHg=; b=ayhZ5WynPYwXRXwbU173SGbOGOJS3y5SNVHw6r8/FIByydoHf/m71gaF4i7ietccKa 945Y/A9aie2Josc2wBDZw+YnfcZobPnLyKRzSphmsF83fcMFt9P8Z9OWYNZ7a9+gRtag eDFIgtDVhZ6ojt3fPVVkeb1BIfnDLxDVptsNtRaLDbH/Nr2Ke5Dv9I2yQPFo04jC0cQR c4LwhQIYV/Wk3fVg4BD1tA+LUjthVvB1yLctiqf8P5SjvFAt15Fvp75A6mHdIDSNL3jY nooaGtitK+uMZ2GUSGvnqUIoJ07aux0OL8+KT5dhIcQzZGkvFvfX0nwgOkVUR6KqSsyP 0T6A== X-Gm-Message-State: ACrzQf0Xq4eHxk7j9DTFd96LwlnTpKPWWf1Svf3/n3FxDQLh0C+BHcpw VAxr85nnNtgxkTlCwNaOhEz3nEu5lcM= X-Google-Smtp-Source: AMsMyM6RWZXGuOmTYl6sh6I373ubmMMijLvqy5KP8ESaMTvM9bRYfXRjennY8uhiLfjX94H5w96Gsg== X-Received: by 2002:ad4:5dee:0:b0:4b4:b8a:78db with SMTP id jn14-20020ad45dee000000b004b40b8a78dbmr1976060qvb.12.1665704633224; Thu, 13 Oct 2022 16:43:53 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:ec49:7545:4026:a70a]) by smtp.gmail.com with ESMTPSA id x5-20020ac84a05000000b0039a08c0a594sm952928qtq.82.2022.10.13.16.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 16:43:53 -0700 (PDT) From: Yury Norov To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sebastian Andrzej Siewior , Menglong Dong , Kuniyuki Iwashima , Petr Machata , Guo Ren , "Michael S . Tsirkin" Cc: Yury Norov , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] net: initialize online_mask unconditionally in __netif_set_xps_queue() Date: Thu, 13 Oct 2022 16:43:47 -0700 Message-Id: <20221013234349.1165689-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013234349.1165689-1-yury.norov@gmail.com> References: <20221013234349.1165689-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If the mask is initialized unconditionally, it's possible to use bitmap API to traverse it, which is done in the following patch. Signed-off-by: Yury Norov --- net/core/dev.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 9dc6fcb0d48a..8049e2ff11a5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2542,7 +2542,7 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, u16 index, enum xps_map_type type) { struct xps_dev_maps *dev_maps, *new_dev_maps = NULL, *old_dev_maps = NULL; - const unsigned long *online_mask = NULL; + const unsigned long *online_mask; bool active = false, copy = false; int i, j, tci, numa_node_id = -2; int maps_sz, num_tc = 1, tc = 0; @@ -2565,9 +2565,12 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, if (type == XPS_RXQS) { nr_ids = dev->num_rx_queues; + online_mask = bitmap_alloc(nr_ids, GFP_KERNEL); + if (!online_mask) + return -ENOMEM; + bitmap_fill(online_mask, nr_ids); } else { - if (num_possible_cpus() > 1) - online_mask = cpumask_bits(cpu_online_mask); + online_mask = cpumask_bits(cpu_online_mask); nr_ids = nr_cpu_ids; } @@ -2593,10 +2596,8 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, j < nr_ids;) { if (!new_dev_maps) { new_dev_maps = kzalloc(maps_sz, GFP_KERNEL); - if (!new_dev_maps) { - mutex_unlock(&xps_map_mutex); - return -ENOMEM; - } + if (!new_dev_maps) + goto err_out; new_dev_maps->nr_ids = nr_ids; new_dev_maps->num_tc = num_tc; @@ -2718,7 +2719,8 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, out_no_maps: mutex_unlock(&xps_map_mutex); - + if (type == XPS_RXQS) + bitmap_free(online_mask); return 0; error: /* remove any maps that we added */ @@ -2733,8 +2735,10 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, } } +err_out: mutex_unlock(&xps_map_mutex); - + if (type == XPS_RXQS) + bitmap_free(online_mask); kfree(new_dev_maps); return -ENOMEM; } From patchwork Thu Oct 13 23:43:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13006570 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7850DC4167B for ; Thu, 13 Oct 2022 23:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbiJMXoB (ORCPT ); Thu, 13 Oct 2022 19:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiJMXn4 (ORCPT ); Thu, 13 Oct 2022 19:43:56 -0400 Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD0318C43F; Thu, 13 Oct 2022 16:43:54 -0700 (PDT) Received: by mail-qv1-xf2b.google.com with SMTP id de14so2300623qvb.5; Thu, 13 Oct 2022 16:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/YPjj/+mYMhRlZ2E9EjM0QB8fHYgSe8UWol/kOphzlw=; b=O4quyDE29K+3M6oNzJuBdcA5bA7uqLpZc9RUDQsHZBKDIkSrlZw4vANQ3w1jDzorpz 7WKe9j3ny5ZwMaJDh4yukguMAjUkF947Hmv26iCLnCcO4j8nXuHr8DrHOH1oOKQhMS71 Ky9CBYJKPchchJjRSZjjcp5pe1nFU7f7jiR9vx9wyqeKbi1hMIIOAHPjDk5/NaOiTPzK Y3rinmaKwkWzuIwwMrNxDmEUjobbXyF3Rf4wdCh8olJeTX5iF1nN1I7zLhcGmgug3DjN DEr7PlRaik7R1GntS6ZtakVVuEUp3GoBLTYjKjZqDHGRnVWPyoWhBZ7N78d/ZR5perIy TfAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/YPjj/+mYMhRlZ2E9EjM0QB8fHYgSe8UWol/kOphzlw=; b=HWJbXT1B9Jz6FNxJ16rW22/r2R8vQ9NOtpfgIu4cVO4MzFSaEIJ0jf5yXgnPDt2f6G Y3vT+pI0e53kZ5T6b0v8tawW+Jg+rq9NWKxftFmDFjrJwQJVTIZwWuC1rfPH43WvQZMW DOrqdaVFKY91xFc5MYyicZXnyqFPrPbR7zRQUmCJSFYujcd049VEVDVUtosx2IxUHFjD kSwWvTOfommq6FNe5PYHAwq3q8q45G48jwAGVoHSAjym4byxYDrw5ZAcpcH/KvDVCuMC 9nJhId+4it7k7FBlI8LJmmoBWYmXNBYAxleYVJqtyP1QuqtKLeIVZnL4wli5rx3gsXon 1Knw== X-Gm-Message-State: ACrzQf2wUuNP4zNiXN6A+fUW81jG9/GDMrgNPzHhAElAUFoSi1mDX0De BC3E5ALpHa5Nuwzh5Ui86N4VDrl0SJg= X-Google-Smtp-Source: AMsMyM61vCajgGmDZzBGu9YK0FXDaRoCwCzw8bi7Hhflshg6GE2WlnNRvLFg0ozNcsWC+TkUtEMkiw== X-Received: by 2002:a0c:ab12:0:b0:4b1:9467:1948 with SMTP id h18-20020a0cab12000000b004b194671948mr2213318qvb.80.1665704633897; Thu, 13 Oct 2022 16:43:53 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:ec49:7545:4026:a70a]) by smtp.gmail.com with ESMTPSA id l4-20020a37f904000000b006ced5d3f921sm925793qkj.52.2022.10.13.16.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 16:43:53 -0700 (PDT) From: Yury Norov To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Sebastian Andrzej Siewior , Menglong Dong , Kuniyuki Iwashima , Petr Machata , Guo Ren , "Michael S . Tsirkin" Cc: Yury Norov , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] net: fix opencoded for_each_and_bit() in __netif_set_xps_queue() Date: Thu, 13 Oct 2022 16:43:48 -0700 Message-Id: <20221013234349.1165689-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013234349.1165689-1-yury.norov@gmail.com> References: <20221013234349.1165689-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Replace opencoded bitmap traversing and drop unused netif_attrmask_next*() functions Signed-off-by: Yury Norov --- include/linux/netdevice.h | 46 --------------------------------------- net/core/dev.c | 3 +-- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 53d738f66159..5db2b6de7308 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3648,52 +3648,6 @@ static inline bool netif_attr_test_online(unsigned long j, return (j < nr_bits); } - -/** - * netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask - * @n: CPU/Rx queue index - * @srcp: the cpumask/Rx queue mask pointer - * @nr_bits: number of bits in the bitmask - * - * Returns >= nr_bits if no further CPUs/Rx queues set. - */ -static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp, - unsigned int nr_bits) -{ - /* n is a prior cpu */ - cpu_max_bits_warn(n + 1, nr_bits); - - if (srcp) - return find_next_bit(srcp, nr_bits, n + 1); - - return n + 1; -} - -/** - * netif_attrmask_next_and - get the next CPU/Rx queue in \*src1p & \*src2p - * @n: CPU/Rx queue index - * @src1p: the first CPUs/Rx queues mask pointer - * @src2p: the second CPUs/Rx queues mask pointer - * @nr_bits: number of bits in the bitmask - * - * Returns >= nr_bits if no further CPUs/Rx queues set in both. - */ -static inline int netif_attrmask_next_and(int n, const unsigned long *src1p, - const unsigned long *src2p, - unsigned int nr_bits) -{ - /* n is a prior cpu */ - cpu_max_bits_warn(n + 1, nr_bits); - - if (src1p && src2p) - return find_next_and_bit(src1p, src2p, nr_bits, n + 1); - else if (src1p) - return find_next_bit(src1p, nr_bits, n + 1); - else if (src2p) - return find_next_bit(src2p, nr_bits, n + 1); - - return n + 1; -} #else static inline int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask, diff --git a/net/core/dev.c b/net/core/dev.c index 8049e2ff11a5..b0fb592d51da 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2592,8 +2592,7 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, copy = true; /* allocate memory for queue storage */ - for (j = -1; j = netif_attrmask_next_and(j, online_mask, mask, nr_ids), - j < nr_ids;) { + for_each_and_bit(j, online_mask, mask ? : online_mask, nr_ids) { if (!new_dev_maps) { new_dev_maps = kzalloc(maps_sz, GFP_KERNEL); if (!new_dev_maps)