PCI: hv: Refactor hv_irq_unmask() to use hv_vpset and cpumask_to_vpset()
cover PCI: hv: Refactor hv_irq_unmask() to use hv_vpset and cpumask_to_vpset()
This patchset removes a duplicate definition of VP set (hv_vp_set) and uses the common definition (hv_vpset) that is used in other places. It also removes the duplicate implementation of cpumask_to_vpset() and uses the shared implementation. Finally, it exports hv_max_vp_index, which is required by cpumask_to_vpset().
Maya Nakamura (2):
PCI: hv: Replace hv_vp_set with hv_vpset
PCI: hv: Refactor hv_irq_unmask() to use cpumask_to_vpset()
arch/x86/hyperv/hv_init.c | 1 + drivers/pci/controller/pci-hyperv.c | 60 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 32 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 PCI: hv: Replace hv_vp_set with hv_vpset
Remove a duplicate definition of VP set (hv_vp_set) and use the common definition (hv_vpset) that is used in other places.
--- drivers/pci/controller/pci-hyperv.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/pci/controller/pci-hyperv.c +12 -13
@@ -393,12 +393,6 @@ struct hv_interrupt_entry {#define HV_VP_SET_BANK_COUNT_MAX 5/* current implementation limit */ -struct hv_vp_set { -u64 format;/* 0 (HvGenericSetSparse4k) */ -u64 valid_banks; -u64 masks[HV_VP_SET_BANK_COUNT_MAX ]; -}; -/* * flags for hv_device_interrupt_target.flags */
@@ -410,7 +404,7 @@ struct hv_device_interrupt_target {u32 flags;union {u64 vp_mask; -struct hv_vp_set vp_set; +struct hv_vpset vp_set; }; };
@@ -460,12 +454,16 @@ struct hv_pcibus_device {struct msi_controller msi_chip;struct irq_domain *irq_domain; -/* hypercall arg, must not cross page boundary */ -struct retarget_msi_interrupt retarget_msi_interrupt_params; -spinlock_t retarget_msi_interrupt_lock;struct workqueue_struct *wq; + +/* hypercall arg, must not cross page boundary */ +struct retarget_msi_interrupt retarget_msi_interrupt_params; + +/* +* Don't put anything here: retarget_msi_interrupt_params must be last +*/ };/*
@@ -955,12 +953,13 @@ static void hv_irq_unmask(struct irq_data *data)*/ params->int_target.flags |=HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET ; - params->int_target.vp_set.valid_banks = + params->int_target.vp_set.valid_bank_mask = (1ull <<HV_VP_SET_BANK_COUNT_MAX ) -1 ;/* * var-sized hypercall, var-size starts after vp_mask (thus -* vp_set.format does not count, but vp_set.valid_banks does). +* vp_set.format does not count, but vp_set.valid_bank_mask +* does). */ var_size =1 +HV_VP_SET_BANK_COUNT_MAX ;
@@ -974,7 +973,7 @@ static void hv_irq_unmask(struct irq_data *data) goto exit_unlock; } - params->int_target.vp_set.masks[cpu_vmbus /64 ] |= + params->int_target.vp_set.bank_contents[cpu_vmbus /64 ] |= (1ULL << (cpu_vmbus &63 )); } }else {
Signature · 1 line
2.17.1
Re: [PATCH 1/2] PCI: hv: Replace hv_vp_set with hv_vpset
Quoted 41 lines · Maya Nakamura
Remove a duplicate definition of VP set (
hv_vp_set) and use the common definition (hv_vpset) that is used in other places.Signed-off-by Maya Nakamura <[email protected]>--- drivers/pci/controller/pci-hyperv.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)drivers/pci/controller/pci-hyperv.c +1
-10@@ -393,12 +393,6 @@ struct hv_interrupt_entry {#define HV_VP_SET_BANK_COUNT_MAX 5/* current implementation limit */ -struct hv_vp_set { -u64 format;/* 0 (HvGenericSetSparse4k) */ -u64 valid_banks; -u64 masks[HV_VP_SET_BANK_COUNT_MAX ]; -}; -/* * flags for hv_device_interrupt_target.flags */ @@ -410,7 +404,7 @@ struct hv_device_interrupt_target {u32 flags;union {u64 vp_mask; -struct hv_vp_set vp_set; +struct hv_vpset vp_set; }; };@@ -460,12 +454,16 @@ struct hv_pcibus_device {struct msi_controller msi_chip;struct irq_domain *irq_domain; -/* hypercall arg, must not cross page boundary */ -struct retarget_msi_interrupt retarget_msi_interrupt_params; -
drivers/pci/controller/pci-hyperv.c struct hv_pcibus_device { · line 466
Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +7
-0spinlock_t retarget_msi_interrupt_lock;struct workqueue_struct *wq; + +/* hypercall arg, must not cross page boundary */ +struct retarget_msi_interrupt retarget_msi_interrupt_params; + +/* +* Don't put anything here: retarget_msi_interrupt_params must be last +*/
This change seems to be unrelated and not anyhow described in the commit message - or did I miss something?
Quoted 28 lines
drivers/pci/controller/pci-hyperv.c +4
-3};/* @@ -955,12 +953,13 @@ static void hv_irq_unmask(struct irq_data *data)*/ params->int_target.flags |=HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET ; - params->int_target.vp_set.valid_banks = + params->int_target.vp_set.valid_bank_mask = (1ull <<HV_VP_SET_BANK_COUNT_MAX ) -1 ;/* * var-sized hypercall, var-size starts after vp_mask (thus -* vp_set.format does not count, but vp_set.valid_banks does). +* vp_set.format does not count, but vp_set.valid_bank_mask +* does). */ var_size =1 +HV_VP_SET_BANK_COUNT_MAX ;@@ -974,7 +973,7 @@ static void hv_irq_unmask(struct irq_data *data) goto exit_unlock; } - params->int_target.vp_set.masks[cpu_vmbus /64 ] |= + params->int_target.vp_set.bank_contents[cpu_vmbus /64 ] |= (1ULL << (cpu_vmbus &63 )); } }else {
Signature · 1 line
Vitaly
Re: [PATCH 1/2] PCI: hv: Replace hv_vp_set with hv_vpset
Quoted 11 lines · Vitaly Kuznetsov
Quoted 9 lines · Maya Nakamura
drivers/pci/controller/pci-hyperv.c +0
-3@@ -460,12 +454,16 @@ struct hv_pcibus_device {struct msi_controller msi_chip;struct irq_domain *irq_domain; -/* hypercall arg, must not cross page boundary */ -struct retarget_msi_interrupt retarget_msi_interrupt_params; -spinlock_t retarget_msi_interrupt_lock;
Quoted 12 lines
drivers/pci/controller/pci-hyperv.c struct hv_pcibus_device { · line 466
Quoted 8 lines
drivers/pci/controller/pci-hyperv.c +7
-0struct workqueue_struct *wq; + +/* hypercall arg, must not cross page boundary */ +struct retarget_msi_interrupt retarget_msi_interrupt_params; + +/* +* Don't put anything here: retarget_msi_interrupt_params must be last +*/ This change seems to be unrelated and not anyhow described in the commit message - or did I miss something?
Thank you for pointing that out. I will add why it was moved in v2.
Maya
Quoted 3 lines
Signature · 2 lines
-- Vitaly
PATCH 2/2 PCI: hv: Refactor hv_irq_unmask() to use cpumask_to_vpset()
In reply to Maya NakamuraRemove the duplicate implementation of cpumask_to_vpset() and use the shared implementation. Export hv_max_vp_index, which is required by cpumask_to_vpset().
--- arch/x86/hyperv/hv_init.c | 1 + drivers/pci/controller/pci-hyperv.c | 39 +++++++++++++---------------- 2 files changed, 19 insertions(+), 21 deletions(-)
arch/x86/hyperv/hv_init.c +1 -0
@@ -96,6 +96,7 @@ void __percpu **hyperv_pcpu_input_arg;EXPORT_SYMBOL_GPL (hyperv_pcpu_input_arg);u32 hv_max_vp_index; +EXPORT_SYMBOL_GPL (hv_max_vp_index);static int hv_cpu_init (unsigned int cpu) {
drivers/pci/controller/pci-hyperv.c +18 -21
@@ -391,8 +391,6 @@ struct hv_interrupt_entry {u32 data; }; -#define HV_VP_SET_BANK_COUNT_MAX 5/* current implementation limit */ -/* * flags for hv_device_interrupt_target.flags */
@@ -908,12 +906,12 @@ static void hv_irq_unmask(struct irq_data *data)struct retarget_msi_interrupt *params;struct hv_pcibus_device *hbus;struct cpumask *dest; +cpumask_var_t tmp;struct pci_bus *pbus;struct pci_dev *pdev;unsigned long flags;u32 var_size =0 ; -int cpu_vmbus; -int cpu; +int cpu, nr_bank =0 ;u64 res; dest =irq_data_get_effective_affinity_mask (data);
@@ -953,29 +951,28 @@ static void hv_irq_unmask(struct irq_data *data)*/ params->int_target.flags |=HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET ; - params->int_target.vp_set.valid_bank_mask = - (1ull <<HV_VP_SET_BANK_COUNT_MAX ) -1 ; + +if (!alloc_cpumask_var (&tmp,GFP_KERNEL )) { +dev_err (&hbus->hdev->device,"out of memory" ); +return ; + } + +cpumask_and (tmp, dest, cpu_online_mask); + nr_bank =cpumask_to_vpset (¶ms->int_target.vp_set, tmp); +free_cpumask_var (tmp); + +if (!nr_bank) { +dev_err (&hbus->hdev->device,"too high CPU" ); + res =1 ; + goto exit_unlock; + }/* * var-sized hypercall, var-size starts after vp_mask (thus * vp_set.format does not count, but vp_set.valid_bank_mask * does). */ - var_size =1 +HV_VP_SET_BANK_COUNT_MAX ; - -for_each_cpu_and (cpu, dest, cpu_online_mask) { - cpu_vmbus =hv_cpu_number_to_vp_number (cpu); - -if (cpu_vmbus >=HV_VP_SET_BANK_COUNT_MAX *64 ) { -dev_err (&hbus->hdev->device, -"too high CPU %d" , cpu_vmbus); - res =1 ; - goto exit_unlock; - } - - params->int_target.vp_set.bank_contents[cpu_vmbus /64 ] |= - (1ULL << (cpu_vmbus &63 )); - } + var_size =1 + nr_bank; }else {for_each_cpu_and (cpu, dest, cpu_online_mask) { params->int_target.vp_mask |=
Signature · 1 line
2.17.1
Re: [PATCH 2/2] PCI: hv: Refactor hv_irq_unmask() to use cpumask_to_vpset()
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 914
Quoted 12 lines · Maya Nakamura
drivers/pci/controller/pci-hyperv.c +2
-2@@ -908,12 +906,12 @@ static void hv_irq_unmask(struct irq_data *data)struct retarget_msi_interrupt *params;struct hv_pcibus_device *hbus;struct cpumask *dest; +cpumask_var_t tmp;struct pci_bus *pbus;struct pci_dev *pdev;unsigned long flags;u32 var_size =0 ; -int cpu_vmbus; -int cpu; +int cpu, nr_bank =0 ;
^^^^^
No need to initialize this to a bogus value. It's misleading and it turns off GCC's uninitialized variable warning so it can lead to bugs.
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 956
Quoted 12 lines
drivers/pci/controller/pci-hyperv.c +3
-2u64 res; dest =irq_data_get_effective_affinity_mask (data);@@ -953,29 +951,28 @@ static void hv_irq_unmask(struct irq_data *data)*/ params->int_target.flags |=HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET ; - params->int_target.vp_set.valid_bank_mask = - (1ull <<HV_VP_SET_BANK_COUNT_MAX ) -1 ; + +if (!alloc_cpumask_var (&tmp,GFP_KERNEL )) { +dev_err (&hbus->hdev->device,"out of memory" );
No need for this error message. alloc_cpumask_var() already has better debug messages built in.
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 957
Quoted 1 line
drivers/pci/controller/pci-hyperv.c +1
-0+return ;
We can't return directly. We need to unlock first.
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 965
Quoted 8 lines
drivers/pci/controller/pci-hyperv.c +8
-0+ } + +cpumask_and (tmp, dest, cpu_online_mask); + nr_bank =cpumask_to_vpset (¶ms->int_target.vp_set, tmp); +free_cpumask_var (tmp); + +if (!nr_bank) { +dev_err (&hbus->hdev->device,"too high CPU" );
This error message is not useful.
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 968
Quoted 3 lines
drivers/pci/controller/pci-hyperv.c +3
-0+ res =1 ; + goto exit_unlock; + }
regards,
dan carpenter
Re: [PATCH 2/2] PCI: hv: Refactor hv_irq_unmask() to use cpumask_to_vpset()
Quoted 14 lines · Dan Carpenter
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 914
Quoted 12 lines · Maya Nakamura
drivers/pci/controller/pci-hyperv.c +2
-2@@ -908,12 +906,12 @@ static void hv_irq_unmask(struct irq_data *data)struct retarget_msi_interrupt *params;struct hv_pcibus_device *hbus;struct cpumask *dest; +cpumask_var_t tmp;struct pci_bus *pbus;struct pci_dev *pdev;unsigned long flags;u32 var_size =0 ; -int cpu_vmbus; -int cpu; +int cpu, nr_bank =0 ;^^^^^
Quoted 3 lines
No need to initialize this to a bogus value. It's misleading and it turns off GCC's uninitialized variable warning so it can lead to bugs.
Thank you for pointing that out. I will remove its initialization in v2.
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +0
-1@@ -953,29 +951,28 @@ static void hv_irq_unmask(struct irq_data *data)*/ params->int_target.flags |=HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET ; - params->int_target.vp_set.valid_bank_mask =
Quoted 9 lines
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 956
Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +3
-1- (1ull <<HV_VP_SET_BANK_COUNT_MAX ) -1 ; + +if (!alloc_cpumask_var (&tmp,GFP_KERNEL )) { +dev_err (&hbus->hdev->device,"out of memory" );No need for this error message.
alloc_cpumask_var()already has better debug messages built in.
I will delete this dev_err() in v2.
Quoted 4 lines
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 957
Quoted 1 line
drivers/pci/controller/pci-hyperv.c +1
-0+return ;We can't return directly. We need to unlock first.
I will unlock in v2.
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c static void hv_irq_unmask(struct irq_data *data) · line 965
Quoted 2 lines
drivers/pci/controller/pci-hyperv.c +2
-0+if (!nr_bank) { +dev_err (&hbus->hdev->device,"too high CPU" );This error message is not useful.
I will delete this dev_err() in v2.
Maya
Quoted 4 lines
regards,
dan carpenter