From: Justin Tee <justintee8345@gmail.com>
To: Vernon Yang <vernon2gm@gmail.com>
Cc: 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,
linux-kernel@vger.kernel.org, wireguard@lists.zx2c4.com,
netdev@vger.kernel.org, linux-scsi@vger.kernel.org,
Justin Tee <justin.tee@broadcom.com>
Subject: Re: [PATCH v2 3/4] scsi: lpfc: fix lpfc_cpu_affinity_check() if no further cpus set
Date: Tue, 7 Mar 2023 16:40:28 -0800 [thread overview]
Message-ID: <CABPRKS-DRvmZpoXBTogjEf5Q+oL5GR71nSVRgmVo5vWx-9OQow@mail.gmail.com> (raw)
In-Reply-To: <20230306210312.2614988-4-vernon2gm@gmail.com>
Hi Vernon,
Is it possible to move the new helper routine lpfc_next_present_cpu
into the lpfc.h header file around where lpfc_next_online_cpu is
defined?
Also, with slight modifications we could use the new
lpfc_next_present_cpu helper routine for the
lpfc_nvmet_setup_io_context() patch as well so that we can contain all
lpfc changes within one patch.
---
drivers/scsi/lpfc/lpfc.h | 20 ++++++++++++++++++++
drivers/scsi/lpfc/lpfc_init.c | 31 +++++++------------------------
drivers/scsi/lpfc/lpfc_nvmet.c | 5 +----
3 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index cf55f8e3bd9f..f342d6bc5726 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -1737,6 +1737,26 @@ lpfc_next_online_cpu(const struct cpumask
*mask, unsigned int start)
return cpu_it;
}
+
+/**
+ * lpfc_next_present_cpu - Finds next present CPU after n
+ * @n: the cpu prior to search
+ *
+ * Note: If no next present cpu, then fallback to first present cpu.
+ *
+ **/
+static inline unsigned int lpfc_next_present_cpu(int n)
+{
+ unsigned int cpu;
+
+ cpu = cpumask_next(n, cpu_present_mask);
+
+ if (cpu >= nr_cpu_ids)
+ cpu = cpumask_first(cpu_present_mask);
+
+ return cpu;
+}
+
/**
* lpfc_sli4_mod_hba_eq_delay - update EQ delay
* @phba: Pointer to HBA context object.
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 3e1e1d17b2b4..f28af338341f 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12560,10 +12560,7 @@ 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);
}
/* At this point, we leave the CPU as unassigned */
continue;
@@ -12575,9 +12572,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);
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
"3337 Set Affinity: CPU %d "
@@ -12610,10 +12605,7 @@ 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);
}
/* We should never leave an entry unassigned */
lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
@@ -12629,9 +12621,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);
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
"3338 Set Affinity: CPU %d "
@@ -12702,9 +12692,7 @@ 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);
}
/* If we can't match both phys_id and core_id,
@@ -12716,10 +12704,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba
*phba, int vectors)
if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
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);
}
/* Otherwise just round robin on cfg_hdw_queue */
@@ -12728,9 +12713,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);
cpup->hdwq = new_cpup->hdwq;
logit:
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 7517dd55fe91..2d8ac2ceb6f3 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -1620,10 +1620,7 @@ lpfc_nvmet_setup_io_context(struct lpfc_hba *phba)
cpu = cpumask_first(cpu_present_mask);
continue;
}
- cpu = cpumask_next(cpu, cpu_present_mask);
- if (cpu == nr_cpu_ids)
- cpu = cpumask_first(cpu_present_mask);
-
+ cpu = lpfc_next_present_cpu(cpu);
}
for_each_present_cpu(i) {
--
2.38.0
Thanks,
Justin
On Mon, Mar 6, 2023 at 1:10 PM Vernon Yang <vernon2gm@gmail.com> wrote:
>
> 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 <vernon2gm@gmail.com>
> ---
> 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,
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-03-10 10:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 21:03 [PATCH v2 0/4] fix call cpumask_next() " Vernon Yang
2023-03-06 21:03 ` [PATCH v2 1/4] random: fix try_to_generate_entropy() " Vernon Yang
2023-03-06 21:03 ` [PATCH v2 2/4] wireguard: fix wg_cpumask_choose_online() " Vernon Yang
2023-03-06 21:03 ` [PATCH v2 3/4] scsi: lpfc: fix lpfc_cpu_affinity_check() " Vernon Yang
2023-03-08 0:40 ` Justin Tee [this message]
2023-03-06 21:03 ` [PATCH v2 4/4] scsi: lpfc: fix lpfc_nvmet_setup_io_context() " Vernon Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABPRKS-DRvmZpoXBTogjEf5Q+oL5GR71nSVRgmVo5vWx-9OQow@mail.gmail.com \
--to=justintee8345@gmail.com \
--cc=Jason@zx2c4.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dick.kennedy@broadcom.com \
--cc=edumazet@google.com \
--cc=james.smart@broadcom.com \
--cc=jejb@linux.ibm.com \
--cc=justin.tee@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=martin.petersen@oracle.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=vernon2gm@gmail.com \
--cc=wireguard@lists.zx2c4.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).