All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lpfc: size cpu map by last cpu id set
@ 2019-11-21 17:55 James Smart
  2019-11-21 22:11 ` Ewan D. Milne
  2019-11-22  1:51 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: James Smart @ 2019-11-21 17:55 UTC (permalink / raw)
  To: linux-scsi; +Cc: James Smart, Dick Kennedy

Currently the lpfc driver sizes its cpu_map array based on
num_possible_cpus(). However, that can be a value that is less
than the highest cpu id bit that is set. As such, if a thread
runs on a cpu with a larger cpu id, or for_each_possible_cpu()
is used, the driver could index off the end of the array and
return garbage or GPF.

The driver maintains it's own internal copy of the "num_possible"
cpu value and sizes arrays by it.

Fix by setting the driver's value to the value of the last cpu id
bit set in the possible_mask - plus 1. Thus cpu_map will be sized
to allow access by any cpu id possible.

Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
---
 drivers/scsi/lpfc/lpfc_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index e9323889f199..cd83617354a1 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -6460,7 +6460,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
 	u32 if_fam;
 
 	phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
-	phba->sli4_hba.num_possible_cpu = num_possible_cpus();
+	phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
 	phba->sli4_hba.curr_disp_cpu = 0;
 	lpfc_cpumask_of_node_init(phba);
 
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lpfc: size cpu map by last cpu id set
  2019-11-21 17:55 [PATCH] lpfc: size cpu map by last cpu id set James Smart
@ 2019-11-21 22:11 ` Ewan D. Milne
  2019-11-22  1:51 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Ewan D. Milne @ 2019-11-21 22:11 UTC (permalink / raw)
  To: James Smart, linux-scsi; +Cc: Dick Kennedy

On Thu, 2019-11-21 at 09:55 -0800, James Smart wrote:
> Currently the lpfc driver sizes its cpu_map array based on
> num_possible_cpus(). However, that can be a value that is less
> than the highest cpu id bit that is set. As such, if a thread
> runs on a cpu with a larger cpu id, or for_each_possible_cpu()
> is used, the driver could index off the end of the array and
> return garbage or GPF.
> 
> The driver maintains it's own internal copy of the "num_possible"
> cpu value and sizes arrays by it.
> 
> Fix by setting the driver's value to the value of the last cpu id
> bit set in the possible_mask - plus 1. Thus cpu_map will be sized
> to allow access by any cpu id possible.
> 
> Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
> Signed-off-by: James Smart <jsmart2021@gmail.com>
> ---
>  drivers/scsi/lpfc/lpfc_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index e9323889f199..cd83617354a1 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -6460,7 +6460,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
>  	u32 if_fam;
>  
>  	phba->sli4_hba.num_present_cpu = lpfc_present_cpu;
> -	phba->sli4_hba.num_possible_cpu = num_possible_cpus();
> +	phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1;
>  	phba->sli4_hba.curr_disp_cpu = 0;
>  	lpfc_cpumask_of_node_init(phba);
>  

Reviewed-by: Ewan D. Milne <emilne@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lpfc: size cpu map by last cpu id set
  2019-11-21 17:55 [PATCH] lpfc: size cpu map by last cpu id set James Smart
  2019-11-21 22:11 ` Ewan D. Milne
@ 2019-11-22  1:51 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2019-11-22  1:51 UTC (permalink / raw)
  To: James Smart; +Cc: linux-scsi, Dick Kennedy


James,

> Currently the lpfc driver sizes its cpu_map array based on
> num_possible_cpus(). However, that can be a value that is less than
> the highest cpu id bit that is set. As such, if a thread runs on a cpu
> with a larger cpu id, or for_each_possible_cpu() is used, the driver
> could index off the end of the array and return garbage or GPF.

Applied to 5.5/scsi-queue, thanks.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-22  1:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21 17:55 [PATCH] lpfc: size cpu map by last cpu id set James Smart
2019-11-21 22:11 ` Ewan D. Milne
2019-11-22  1:51 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.