From nobody Sat Apr 11 11:54:53 2026 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 DA401C6FD1B for ; Mon, 6 Mar 2023 21:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbjCFVDy (ORCPT ); Mon, 6 Mar 2023 16:03:54 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D cpumask_next(cpu, &timer_cpus); - if (cpu =3D=3D nr_cpumask_bits) + if (cpu >=3D nr_cpu_ids) cpu =3D cpumask_first(&timer_cpus); } while (cpu =3D=3D smp_processor_id() && num_cpus > 1); =20 --=20 2.34.1 From nobody Sat Apr 11 11:54:53 2026 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 7D14BC6FD1A for ; Mon, 6 Mar 2023 21:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbjCFVD5 (ORCPT ); Mon, 6 Mar 2023 16:03:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjCFVDw (ORCPT ); Mon, 6 Mar 2023 16:03:52 -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 569E047416; Mon, 6 Mar 2023 13:03:48 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id x7so4776524pff.7; Mon, 06 Mar 2023 13:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678136628; 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=EzJCZDBXCZQBtCcs+i2Sd8VIIl3ZxMoIHVX47PVzHkX/80N6AnpWho3ip+JfnBNkcU DRhP9WEmyqgTb7amsutb8jjVfZKWRhNRIMWGGgmyyhv9j8c2hrsORGdruJ0fVdMJWBgb 54pxkz2GPiUV5Nqz4U8SiiVXj4uu2mBEyUAnWR30Zr73qhKA+PGvs3PHaehLzCVwJojn K7uwJxuujTPDCN0YMmOI2hZ+jbdZibY7uHOme+hcHCxERz8ZbNdHj1XJisFrX+r9OfRl rC3DrdZJO9MyRn7lS6cz6LFV2u5iTdJLlqy2n3bEQThJca7tcLrCPHdznlHVWZJn1WsI 9e6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678136628; 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=4oVDBZZY4lIyNujx/5OjVFWIFn5uShYN6Uof1gp414DO3ZWEaSavajYljEozgzsO7O UfAFWwVEYFz0l26aY2kGPMw/u01HAWZuje8oK1YtBjgksD3EiXK8fjmoDIK2YYRJHaTk 1A5wfwUHPcHhcoVBkVgkLLzIeW/haqS+OYqKyo7KByznnUrgyVFyE82pjCwzDQT6aqoM fQ8QK6ZJf5g5pc5n/bk2ftTQF1PlSJJpbsavrRFfL4o9WhvTvgw0Vhgiyg86y10A/kME +AHDr2h9TeZ5GDIx0tJxLEqQNl9UxipTMHSx+hFp8ezBHMu3Q5+GvHdqBrrInyhYX9TE 2NAA== X-Gm-Message-State: AO0yUKU4ziqQPU0Lti4ps5KbjTViLo7OLXiqo1QIKSSwRUzmswudHnFc ZnkKCqs/CU/jADO31UXyfJE= X-Google-Smtp-Source: AK7set9SgjU99y7UTZCA7R51uGEBr/FGuhsJ2xk/AqVt+5KthhS3T7GPuQ5t/T6C74NazCaB8bgX8g== X-Received: by 2002:a62:844c:0:b0:5db:db1c:37f9 with SMTP id k73-20020a62844c000000b005dbdb1c37f9mr13680453pfd.10.1678136627797; Mon, 06 Mar 2023 13:03:47 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 13:03:47 -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 05:03:10 +0800 Message-Id: <20230306210312.2614988-3-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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/queue= ing.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 =3D *stored_cpu, cpu_index, i; =20 - if (unlikely(cpu =3D=3D nr_cpumask_bits || + if (unlikely(cpu >=3D nr_cpu_ids || !cpumask_test_cpu(cpu, cpu_online_mask))) { cpu_index =3D id % cpumask_weight(cpu_online_mask); cpu =3D cpumask_first(cpu_online_mask); --=20 2.34.1 From nobody Sat Apr 11 11:54:53 2026 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 8317AC6FD1A for ; Mon, 6 Mar 2023 21:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbjCFVEH (ORCPT ); Mon, 6 Mar 2023 16:04:07 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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) } } =20 +static inline int lpfc_next_present_cpu(int n, int first_cpu) +{ + n =3D cpumask_next(n, cpu_present_mask); + + if (n >=3D nr_cpu_ids) + n =3D 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 !=3D LPFC_VECTOR_MAP_EMPTY) && (new_cpup->phys_id =3D=3D cpup->phys_id)) goto found_same; - new_cpu =3D cpumask_next( - new_cpu, cpu_present_mask); - if (new_cpu =3D=3D nr_cpumask_bits) - new_cpu =3D first_cpu; + + new_cpu =3D 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 =3D cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu =3D=3D nr_cpumask_bits) - start_cpu =3D first_cpu; + start_cpu =3D lpfc_next_present_cpu(new_cpu, first_cpu); =20 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 !=3D LPFC_VECTOR_MAP_EMPTY)) goto found_any; - new_cpu =3D cpumask_next( - new_cpu, cpu_present_mask); - if (new_cpu =3D=3D nr_cpumask_bits) - new_cpu =3D first_cpu; + + new_cpu =3D 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 =3D cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu =3D=3D nr_cpumask_bits) - start_cpu =3D first_cpu; + start_cpu =3D lpfc_next_present_cpu(new_cpu, first_cpu); =20 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 =3D=3D cpup->core_id) { goto found_hdwq; } - new_cpu =3D cpumask_next(new_cpu, cpu_present_mask); - if (new_cpu =3D=3D nr_cpumask_bits) - new_cpu =3D first_cpu; + + new_cpu =3D lpfc_next_present_cpu(new_cpu, first_cpu); } =20 /* 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 =3D=3D cpup->phys_id) goto found_hdwq; =20 - new_cpu =3D cpumask_next(new_cpu, cpu_present_mask); - if (new_cpu =3D=3D nr_cpumask_bits) - new_cpu =3D first_cpu; + new_cpu =3D lpfc_next_present_cpu(new_cpu, first_cpu); } =20 /* 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 =3D cpumask_next(new_cpu, cpu_present_mask); - if (start_cpu =3D=3D nr_cpumask_bits) - start_cpu =3D first_cpu; + start_cpu =3D lpfc_next_present_cpu(new_cpu, first_cpu); cpup->hdwq =3D new_cpup->hdwq; logit: lpfc_printf_log(phba, KERN_INFO, LOG_INIT, --=20 2.34.1 From nobody Sat Apr 11 11:54:53 2026 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 75B7EC6FD1A for ; Mon, 6 Mar 2023 21:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjCFVE2 (ORCPT ); Mon, 6 Mar 2023 16:04:28 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D cpumask_next(cpu, cpu_present_mask); - if (cpu =3D=3D nr_cpu_ids) + if (cpu >=3D nr_cpu_ids) cpu =3D cpumask_first(cpu_present_mask); =20 } --=20 2.34.1