From patchwork Mon Mar 6 21:03:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vernon Yang X-Patchwork-Id: 659662 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 194B6C64EC4 for ; Mon, 6 Mar 2023 21:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjCFVDw (ORCPT ); Mon, 6 Mar 2023 16:03:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjCFVDo (ORCPT ); Mon, 6 Mar 2023 16:03:44 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3834E37579; Mon, 6 Mar 2023 13:03:43 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id n5so6736686pfv.11; Mon, 06 Mar 2023 13:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678136622; 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=ohhBlm5/EvdaRANIY+/17hlHt7n4eAlMQRKCzUzJefs=; b=jddwh84zwUpSQuatvj4c7Dpgl/B68lIc/yasenGO6pdLPdPi5mYHxG8eXh62Yz++wr 64vwB8kutOmKeAyu9i2kM3ICs828b7TCLH1GK0jUbMwkeQbvl0Ii8ptdMYZhXHMuzIPL V+3uMHRGAOPTgIkB94ykDqXF8VeLLXqH/ZMXQi8Ve4saIO0PImMGq3bxlmzsZFS15pQG NoIWQlxj3IqaCV7yHbxIrQ0fa/vPWBV4XKjFE5PjiYzL8MaaZyakd/MKhl/WaZ1C7mch 4IobHwykjv/5tIFUOenW8tcEBFDD+ZAL/zwr9gNMnLbPmDRDzCnw+cfg89CxNO266/// ye2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678136622; 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=ohhBlm5/EvdaRANIY+/17hlHt7n4eAlMQRKCzUzJefs=; b=5xJOZXxGTqRNiTItWUbWSyA+Rg+ivxenKGFFToOnYeije+/pRjR1jCtopC7w08g8WW fJpnms4CNnI9NWfobQFwrtC7z/vJ7MjxZhNOcT2tsNF8gGDOk4gpkbCTOujE3qZ+1jl3 FLmDR80YljX8nkyrxf4mp/H6aL74sJbTW4lua6usu6e54hb1lCkIoel8hblhMuW3mUFA Y3hSV+oUjUII/mrI43t/5YKZTiVHsXEIYotgiUI95+IJaZBHeaTrGH7fr4lV1R4l+fLs wwBwopvLDRMgb0nJebp3x0xiNmS7WCDU45xIwst2JOM8oDLj28vWFGA/Kn5WriDUITJ9 Hpkw== X-Gm-Message-State: AO0yUKWv8toMaT8r+Lb/SNSE0Ml5Ry1nui/vVdEr2/ItZfOiCHxd84Vf HCUgtdZnHQGvQtdZBNxGwBU= X-Google-Smtp-Source: AK7set9C+GX1uA5tZkGP2zTQMIs94EYIBwyVaiOu7iZSR8QoXhcin7YC0GzM7XQYnpJ1bW1BZLgToQ== X-Received: by 2002:a62:5105:0:b0:593:ed9c:9f07 with SMTP id f5-20020a625105000000b00593ed9c9f07mr11960629pfb.27.1678136622631; Mon, 06 Mar 2023 13:03:42 -0800 (PST) Received: from vernon-pc.. ([49.67.2.142]) by smtp.gmail.com with ESMTPSA id 3-20020aa79143000000b005810c4286d6sm6706760pfi.0.2023.03.06.13.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:03:42 -0800 (PST) From: Vernon Yang To: torvalds@linux-foundation.org, tytso@mit.edu, Jason@zx2c4.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jejb@linux.ibm.com, martin.petersen@oracle.com, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, james.smart@broadcom.com, dick.kennedy@broadcom.com Cc: linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-scsi@vger.kernel.org, Vernon Yang Subject: [PATCH v2 1/4] random: fix try_to_generate_entropy() if no further cpus set Date: Tue, 7 Mar 2023 05:03:09 +0800 Message-Id: <20230306210312.2614988-2-vernon2gm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306210312.2614988-1-vernon2gm@gmail.com> References: <20230306210312.2614988-1-vernon2gm@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When cpumask_next() the return value is greater than or equal to nr_cpu_ids, it indicates invalid. Before commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), when cpumask_next() returned an invalid cpu, the driver used the judgment equal to nr_cpu_ids to indicate the invalid cpu, so it happened to work normally, but this is the wrong approach. After commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), these incorrect practices actively buggy, so fix it to correctly. Signed-off-by: Vernon Yang --- drivers/char/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index ce3ccd172cc8..253f2ddb8913 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1311,7 +1311,7 @@ static void __cold try_to_generate_entropy(void) /* Basic CPU round-robin, which avoids the current CPU. */ do { cpu = cpumask_next(cpu, &timer_cpus); - if (cpu == nr_cpumask_bits) + if (cpu >= nr_cpu_ids) cpu = cpumask_first(&timer_cpus); } while (cpu == smp_processor_id() && num_cpus > 1); From patchwork Mon Mar 6 20:47:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vernon Yang X-Patchwork-Id: 659663 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 EFA30C64EC4 for ; Mon, 6 Mar 2023 20:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjCFUsN (ORCPT ); Mon, 6 Mar 2023 15:48:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbjCFUsK (ORCPT ); Mon, 6 Mar 2023 15:48:10 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31A0672B3B; Mon, 6 Mar 2023 12:47:57 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id u5so11848138plq.7; Mon, 06 Mar 2023 12:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678135676; 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=MGmtZmnDs5ASNE58FlHEoRflz4j5hRXcFcWdJp13C10=; b=qYRs34Gk9hUvTs5ooXKPKoymdDDp1qyJBx1E+sIY2JvW1s22DJk2X7y1vFmfMeNrya jjiZs95ll3Deo94LJL0MIxxSzm3AWRXtvMwqww3eAIRMZv1we4kFFe5CoNGogyjud4lu pXxem8c/aN7PvEOkXxjWSMGHwMbKX563gMIWEEC8S196B2+ltQLn/Qz0WDJ+GiwYyu4/ v7TN1sQjBcS/3bHO/fl8LNr5VGX4MBH5kONmDgLJUmrWf5YzB0akr/Oq91jAVYUCyxPi Lo/fnlVTqlRZPMUY2RyW7pa2rGqTEbKBIuL4RiQYRZ9a6C+RYptbZSpYXQaxMI9QmYTH ru9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678135676; 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=MGmtZmnDs5ASNE58FlHEoRflz4j5hRXcFcWdJp13C10=; b=7v+DGIXDLuUQ7NhQBJWM8rUyQ1nX+4MHDPgHAieFzgqidJAZwGf9qnJCOVGVVDUAzN Ds54AIO13UjO6cTD2dAO3A+u95F5tSw5byIa2EbGYLXvroOqtF3yHb3fYttafvo3dmwO qA9caNdbPPrOK/Jr7UtHWpYYhky/voUTDBfebr7pnwtjAgiH1C28nIfJ3KOLfUGrgXAw RSHK7ZuH6ncw0GH/aYEFc5naSFuSrEHQWE2rUYFr6X2DzcygHhCoElU6MJNVompGlpoZ 5tiriI/vCSJ5Yw6HDCod9Q0nzpXf5nIPBa0mVtyvT+b/v6xKDLATZVcMpk0PTLOOfGea OVBA== X-Gm-Message-State: AO0yUKWIYDY7j4iR3NjmlBMsRPOlXkpQBqP1JbaDSppSvSI7u21E3mNi vkHnCcUNjuimckN0JMZtpB0= X-Google-Smtp-Source: AK7set/FIMLWtnvm1jz8Ak/Nanv3uUTjVLkFSHhdcorkKHDqQ6eoh1Z+NIyFSpqTUVyNVTkxCTNMkA== X-Received: by 2002:a05:6a20:1e61:b0:cb:a0e3:4598 with SMTP id cy33-20020a056a201e6100b000cba0e34598mr11460370pzb.43.1678135676488; Mon, 06 Mar 2023 12:47:56 -0800 (PST) Received: from vernon-pc.. ([49.67.2.142]) by smtp.gmail.com with ESMTPSA id e23-20020aa78c57000000b005a75d85c0c7sm6699772pfd.51.2023.03.06.12.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 12:47:56 -0800 (PST) From: Vernon Yang To: torvalds@linux-foundation.org, tytso@mit.edu, Jason@zx2c4.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jejb@linux.ibm.com, martin.petersen@oracle.com, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, james.smart@broadcom.com, dick.kennedy@broadcom.com Cc: linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-scsi@vger.kernel.org, Vernon Yang Subject: [PATCH v2 2/4] wireguard: fix wg_cpumask_choose_online() if no further cpus set Date: Tue, 7 Mar 2023 04:47:21 +0800 Message-Id: <20230306204723.2584724-3-vernon2gm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306204723.2584724-1-vernon2gm@gmail.com> References: <20230306204723.2584724-1-vernon2gm@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When cpumask_next() the return value is greater than or equal to nr_cpu_ids, it indicates invalid. Before commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), when cpumask_next() returned an invalid cpu, the driver used the judgment equal to nr_cpu_ids to indicate the invalid cpu, so it happened to work normally, but this is the wrong approach. After commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), these incorrect practices actively buggy, so fix it to correctly. Signed-off-by: Vernon Yang --- drivers/net/wireguard/queueing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireguard/queueing.h b/drivers/net/wireguard/queueing.h index 583adb37ee1e..125284b346a7 100644 --- a/drivers/net/wireguard/queueing.h +++ b/drivers/net/wireguard/queueing.h @@ -106,7 +106,7 @@ static inline int wg_cpumask_choose_online(int *stored_cpu, unsigned int id) { unsigned int cpu = *stored_cpu, cpu_index, i; - if (unlikely(cpu == nr_cpumask_bits || + if (unlikely(cpu >= nr_cpu_ids || !cpumask_test_cpu(cpu, cpu_online_mask))) { cpu_index = id % cpumask_weight(cpu_online_mask); cpu = cpumask_first(cpu_online_mask); From patchwork Mon Mar 6 21:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vernon Yang X-Patchwork-Id: 659661 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 82FFEC61DA4 for ; Mon, 6 Mar 2023 21:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjCFVEF (ORCPT ); Mon, 6 Mar 2023 16:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjCFVEA (ORCPT ); Mon, 6 Mar 2023 16:04:00 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 669932CC4C; Mon, 6 Mar 2023 13:03:53 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id y10so6736508pfi.8; Mon, 06 Mar 2023 13:03:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678136633; 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=owzTi2WIrDoJ2tUDhRyb29KrwMVbrS1C/TJgwosgU78=; b=YjMSjNXKfSQ5CrOSsj61TknVLEJ2Ck8oiqxUfixqm9jTDETQ3EcQrRCUDZ8tnIfw98 JQymHl5Buh+924x8uGeQddKpVyL5EVQGBiw4/MN4Pslp2/TCR+RT1ofy/cfWTSTo95ZJ dK1BzqKLyktWh29KorGBUrSMOv4M7GerwtKm0pZ/6HylKW6/EWoYF78GdMGf2XlGs2MV ttdtwZFbh1OebAVywUYYgwFaA6kRa3lE6TaNOr4b8NcFIjoDo6VcjqoaCLlCgPF6LzU/ FH//CMZdP0c9oXOerTrS3BZ3qh2Z7lE+Bqeomv5K/np2eKkQ5S/ENAbC0ZGI5EQDwVm0 qPFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678136633; 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=owzTi2WIrDoJ2tUDhRyb29KrwMVbrS1C/TJgwosgU78=; b=jpq7lUBSDNFP5/nFgGkZJHtCnrYXlh7k6PHoOg6qulxL5pVGuiiHmhgmhMpwlIAl1Y mKlGE/pscnW+LjF53CdQ4vbR+jrH7ZSHfBT0Ch95vEmIua5oa17HinDeMtuX+zVgY6/o X9PF0auH+Tnq0uVUEJoykO6sx9MgV4jkAcRnmCE143/lZqNH/KbeiV1X/REzduaD/uO7 iU1hEfFPvVjnuV1iFzbY3DjUVon4Z0oxutq+hcxNkmn/ucp8MnxOGujM0OmSbYrAgmf5 WCdgqjjOfsnskg4SeDS5SQE73LEBFdNZ4117b+pkhfMZIbAj3cdOIhSPM3Hh/2vxJlTI cKLA== X-Gm-Message-State: AO0yUKU0dG11cn7faQwH0yJYVo7Nr3ANrCpFyv6oISzhnXV5+xsIcQQI isICdegsrmUGQW9jxZPfEIg= X-Google-Smtp-Source: AK7set9i2UM7diB4lzv9/1oeYY77meyAKEBYgbqmgaG7P75rOHMznZ36mGqdngTWVMk9b212VmLlLA== X-Received: by 2002:a62:8453:0:b0:60a:e919:51ef with SMTP id k80-20020a628453000000b0060ae91951efmr13232719pfd.9.1678136632678; Mon, 06 Mar 2023 13:03:52 -0800 (PST) Received: from vernon-pc.. ([49.67.2.142]) by smtp.gmail.com with ESMTPSA id 3-20020aa79143000000b005810c4286d6sm6706760pfi.0.2023.03.06.13.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:03:52 -0800 (PST) From: Vernon Yang To: torvalds@linux-foundation.org, tytso@mit.edu, Jason@zx2c4.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jejb@linux.ibm.com, martin.petersen@oracle.com, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, james.smart@broadcom.com, dick.kennedy@broadcom.com Cc: linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-scsi@vger.kernel.org, Vernon Yang Subject: [PATCH v2 3/4] scsi: lpfc: fix lpfc_cpu_affinity_check() if no further cpus set Date: Tue, 7 Mar 2023 05:03:11 +0800 Message-Id: <20230306210312.2614988-4-vernon2gm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306210312.2614988-1-vernon2gm@gmail.com> References: <20230306210312.2614988-1-vernon2gm@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When cpumask_next() the return value is greater than or equal to nr_cpu_ids, it indicates invalid. Before commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), when cpumask_next() returned an invalid cpu, the driver used the judgment equal to nr_cpu_ids to indicate the invalid cpu, so it happened to work normally, but this is the wrong approach. After commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), these incorrect practices actively buggy, so fix it to correctly. Signed-off-by: Vernon Yang --- drivers/scsi/lpfc/lpfc_init.c | 43 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 61958a24a43d..acfffdbe9ba1 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12473,6 +12473,16 @@ lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) } } +static inline int lpfc_next_present_cpu(int n, int first_cpu) +{ + n = cpumask_next(n, cpu_present_mask); + + if (n >= nr_cpu_ids) + n = first_cpu; + + return n; +} + /** * lpfc_cpu_affinity_check - Check vector CPU affinity mappings * @phba: pointer to lpfc hba data structure. @@ -12561,10 +12571,8 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && (new_cpup->phys_id == cpup->phys_id)) goto found_same; - new_cpu = cpumask_next( - new_cpu, cpu_present_mask); - if (new_cpu == nr_cpumask_bits) - new_cpu = first_cpu; + + new_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); } /* At this point, we leave the CPU as unassigned */ continue; @@ -12576,9 +12584,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) * chance of having multiple unassigned CPU entries * selecting the same IRQ. */ - start_cpu = cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu == nr_cpumask_bits) - start_cpu = first_cpu; + start_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "3337 Set Affinity: CPU %d " @@ -12611,10 +12617,8 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) goto found_any; - new_cpu = cpumask_next( - new_cpu, cpu_present_mask); - if (new_cpu == nr_cpumask_bits) - new_cpu = first_cpu; + + new_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); } /* We should never leave an entry unassigned */ lpfc_printf_log(phba, KERN_ERR, LOG_INIT, @@ -12630,9 +12634,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) * chance of having multiple unassigned CPU entries * selecting the same IRQ. */ - start_cpu = cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu == nr_cpumask_bits) - start_cpu = first_cpu; + start_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "3338 Set Affinity: CPU %d " @@ -12703,9 +12705,8 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) new_cpup->core_id == cpup->core_id) { goto found_hdwq; } - new_cpu = cpumask_next(new_cpu, cpu_present_mask); - if (new_cpu == nr_cpumask_bits) - new_cpu = first_cpu; + + new_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); } /* If we can't match both phys_id and core_id, @@ -12718,9 +12719,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) new_cpup->phys_id == cpup->phys_id) goto found_hdwq; - new_cpu = cpumask_next(new_cpu, cpu_present_mask); - if (new_cpu == nr_cpumask_bits) - new_cpu = first_cpu; + new_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); } /* Otherwise just round robin on cfg_hdw_queue */ @@ -12729,9 +12728,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) goto logit; found_hdwq: /* We found an available entry, copy the IRQ info */ - start_cpu = cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu == nr_cpumask_bits) - start_cpu = first_cpu; + start_cpu = lpfc_next_present_cpu(new_cpu, first_cpu); cpup->hdwq = new_cpup->hdwq; logit: lpfc_printf_log(phba, KERN_INFO, LOG_INIT, From patchwork Mon Mar 6 21:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vernon Yang X-Patchwork-Id: 660982 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 8163FC64EC4 for ; Mon, 6 Mar 2023 21:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbjCFVE1 (ORCPT ); Mon, 6 Mar 2023 16:04:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjCFVEV (ORCPT ); Mon, 6 Mar 2023 16:04:21 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E24D67017; Mon, 6 Mar 2023 13:03:58 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id a9so11877057plh.11; Mon, 06 Mar 2023 13:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678136637; 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=z+JZSTuFczC5mo7PEY3yBvoy/91ay9ZlZhiG7/0/jdU=; b=J0G/0FbeicKyFQgCtYlOOk4T3oRqyNdGAmPLsHhC+AQzhfqNm09l3mAHs8IQpeDEK5 tXW5R82OI7u7bhUdeK8PTTb/Xa9tmNRW7An5ryNY/VlLVIorS/f6VDFNRkHmqPkgNexd 2V3nsdCrTizVcd32Nzq54QHft2pumYH/7g99jp8KyqObk62dxUAhMUOvzYwk4eHeaqYi mFS8sQLnUlwEgOfm+7KQW3KulkPpElt6qFYGnOKeiXEHNGxbOKze1nQsgpi92CJ1qwSo 3KKUgdfecQl+4WpkS+onsXDqnrl4hRx53yIXhebFwMkVPogmwvrypbhF/nK3UGyGfLIU dnAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678136637; 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=z+JZSTuFczC5mo7PEY3yBvoy/91ay9ZlZhiG7/0/jdU=; b=I2qoBWXpa7O4XHvL+4BqWsTXf61fQc0nTX5d8q86t1XaYhxWqccn3O+xWMmQt3dQPJ AClu9wxJEvO+10BjZT+VwnxwHajmVzyimSSHAISOGECMw8ArPTz/Pn9Y9ZDmsxgSm1DE tUk/T3aElUkjFkAwMXuNbHaiLDdgg3cVkLrPf4CJ28HwTyVX8+jAXPA3MyXfJwTB+8L1 sA1CpIXHr+YNnEOHCRpzlokix/nKt4f4WnSov/UASoreOH2zlglqnLOYC26Vu3NJFkSj 4gTkLskhH8ZnO6IsGOkh+dOH1J+6CYxax9k06Et2szm0vwDNBRzsxY22qHPIyWagX62Z 1g6g== X-Gm-Message-State: AO0yUKX5lWfXzIA0Vl7rtvkn0ZuRLACTgXcawkLpDzcZgd2exl7xoMua OLpkUIrgdrVfSdyYJIfFRD0= X-Google-Smtp-Source: AK7set9bJ+RZpctLL9LNRn8+W3MRhstsXchoF/02mRPZgh29TAeFmlavfd29dFchZTN62FY8teR5EQ== X-Received: by 2002:a05:6a20:394f:b0:bc:8254:ddff with SMTP id r15-20020a056a20394f00b000bc8254ddffmr15220080pzg.1.1678136637715; Mon, 06 Mar 2023 13:03:57 -0800 (PST) Received: from vernon-pc.. ([49.67.2.142]) by smtp.gmail.com with ESMTPSA id 3-20020aa79143000000b005810c4286d6sm6706760pfi.0.2023.03.06.13.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:03:57 -0800 (PST) From: Vernon Yang To: torvalds@linux-foundation.org, tytso@mit.edu, Jason@zx2c4.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jejb@linux.ibm.com, martin.petersen@oracle.com, yury.norov@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, james.smart@broadcom.com, dick.kennedy@broadcom.com Cc: linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com, netdev@vger.kernel.org, linux-scsi@vger.kernel.org, Vernon Yang Subject: [PATCH v2 4/4] scsi: lpfc: fix lpfc_nvmet_setup_io_context() if no further cpus set Date: Tue, 7 Mar 2023 05:03:12 +0800 Message-Id: <20230306210312.2614988-5-vernon2gm@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306210312.2614988-1-vernon2gm@gmail.com> References: <20230306210312.2614988-1-vernon2gm@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When cpumask_next() the return value is greater than or equal to nr_cpu_ids, it indicates invalid. Before commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), when cpumask_next() returned an invalid cpu, the driver used the judgment equal to nr_cpu_ids to indicate the invalid cpu, so it happened to work normally, but this is the wrong approach. After commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"), these incorrect practices actively buggy, so fix it to correctly. Signed-off-by: Vernon Yang --- drivers/scsi/lpfc/lpfc_nvmet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c index 7517dd55fe91..3ae7f330f827 100644 --- a/drivers/scsi/lpfc/lpfc_nvmet.c +++ b/drivers/scsi/lpfc/lpfc_nvmet.c @@ -1621,7 +1621,7 @@ lpfc_nvmet_setup_io_context(struct lpfc_hba *phba) continue; } cpu = cpumask_next(cpu, cpu_present_mask); - if (cpu == nr_cpu_ids) + if (cpu >= nr_cpu_ids) cpu = cpumask_first(cpu_present_mask); }