All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n
@ 2021-11-29 21:43 ` Sean Christopherson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-11-29 21:43 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-riscv, linux-kernel, Adam Borowski, Anup Patel,
	Sean Christopherson

Use what is currently the SMP=y version of riscv_cpuid_to_hartid_mask()
for both SMP=y and SMP=n to fix a build failure with KVM=m and SMP=n due
to boot_cpu_hartid not being exported.  This also fixes a second bug
where the SMP=n version assumes the sole CPU in the system is in the
incoming mask, which may not hold true in kvm_riscv_vcpu_sbi_ecall() if
the KVM guest VM has multiple vCPUs (on a SMP=n system).

Fixes: 1ef46c231df4 ("RISC-V: Implement new SBI v0.2 extensions")
Reported-by: Adam Borowski <kilobyte@angband.pl>
Cc: stable@vger.kernel.org
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/riscv/include/asm/smp.h | 10 ++--------
 arch/riscv/kernel/setup.c    | 10 ++++++++++
 arch/riscv/kernel/smp.c      | 10 ----------
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h
index a7d2811f3536..62d0e6e61da8 100644
--- a/arch/riscv/include/asm/smp.h
+++ b/arch/riscv/include/asm/smp.h
@@ -43,7 +43,6 @@ void arch_send_call_function_ipi_mask(struct cpumask *mask);
 void arch_send_call_function_single_ipi(int cpu);
 
 int riscv_hartid_to_cpuid(int hartid);
-void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
 
 /* Set custom IPI operations */
 void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);
@@ -85,13 +84,6 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
 	return boot_cpu_hartid;
 }
 
-static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
-					      struct cpumask *out)
-{
-	cpumask_clear(out);
-	cpumask_set_cpu(boot_cpu_hartid, out);
-}
-
 static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops)
 {
 }
@@ -102,6 +94,8 @@ static inline void riscv_clear_ipi(void)
 
 #endif /* CONFIG_SMP */
 
+void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
+
 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
 bool cpu_has_hotplug(unsigned int cpu);
 #else
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index b42bfdc67482..63241abe84eb 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -59,6 +59,16 @@ atomic_t hart_lottery __section(".sdata")
 unsigned long boot_cpu_hartid;
 static DEFINE_PER_CPU(struct cpu, cpu_devices);
 
+void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
+{
+	int cpu;
+
+	cpumask_clear(out);
+	for_each_cpu(cpu, in)
+		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
+}
+EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
+
 /*
  * Place kernel memory regions on the resource tree so that
  * kexec-tools can retrieve them from /proc/iomem. While there
diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
index 2f6da845c9ae..b5d30ea92292 100644
--- a/arch/riscv/kernel/smp.c
+++ b/arch/riscv/kernel/smp.c
@@ -59,16 +59,6 @@ int riscv_hartid_to_cpuid(int hartid)
 	return -ENOENT;
 }
 
-void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
-{
-	int cpu;
-
-	cpumask_clear(out);
-	for_each_cpu(cpu, in)
-		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
-}
-EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
-
 bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
 {
 	return phys_id == cpuid_to_hartid_map(cpu);
-- 
2.34.0.rc2.393.gf8c9666880-goog


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* [PATCH] RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n
@ 2021-11-29 21:43 ` Sean Christopherson
  0 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-11-29 21:43 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-riscv, linux-kernel, Adam Borowski, Anup Patel,
	Sean Christopherson

Use what is currently the SMP=y version of riscv_cpuid_to_hartid_mask()
for both SMP=y and SMP=n to fix a build failure with KVM=m and SMP=n due
to boot_cpu_hartid not being exported.  This also fixes a second bug
where the SMP=n version assumes the sole CPU in the system is in the
incoming mask, which may not hold true in kvm_riscv_vcpu_sbi_ecall() if
the KVM guest VM has multiple vCPUs (on a SMP=n system).

Fixes: 1ef46c231df4 ("RISC-V: Implement new SBI v0.2 extensions")
Reported-by: Adam Borowski <kilobyte@angband.pl>
Cc: stable@vger.kernel.org
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/riscv/include/asm/smp.h | 10 ++--------
 arch/riscv/kernel/setup.c    | 10 ++++++++++
 arch/riscv/kernel/smp.c      | 10 ----------
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h
index a7d2811f3536..62d0e6e61da8 100644
--- a/arch/riscv/include/asm/smp.h
+++ b/arch/riscv/include/asm/smp.h
@@ -43,7 +43,6 @@ void arch_send_call_function_ipi_mask(struct cpumask *mask);
 void arch_send_call_function_single_ipi(int cpu);
 
 int riscv_hartid_to_cpuid(int hartid);
-void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
 
 /* Set custom IPI operations */
 void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);
@@ -85,13 +84,6 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
 	return boot_cpu_hartid;
 }
 
-static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
-					      struct cpumask *out)
-{
-	cpumask_clear(out);
-	cpumask_set_cpu(boot_cpu_hartid, out);
-}
-
 static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops)
 {
 }
@@ -102,6 +94,8 @@ static inline void riscv_clear_ipi(void)
 
 #endif /* CONFIG_SMP */
 
+void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
+
 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
 bool cpu_has_hotplug(unsigned int cpu);
 #else
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index b42bfdc67482..63241abe84eb 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -59,6 +59,16 @@ atomic_t hart_lottery __section(".sdata")
 unsigned long boot_cpu_hartid;
 static DEFINE_PER_CPU(struct cpu, cpu_devices);
 
+void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
+{
+	int cpu;
+
+	cpumask_clear(out);
+	for_each_cpu(cpu, in)
+		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
+}
+EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
+
 /*
  * Place kernel memory regions on the resource tree so that
  * kexec-tools can retrieve them from /proc/iomem. While there
diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
index 2f6da845c9ae..b5d30ea92292 100644
--- a/arch/riscv/kernel/smp.c
+++ b/arch/riscv/kernel/smp.c
@@ -59,16 +59,6 @@ int riscv_hartid_to_cpuid(int hartid)
 	return -ENOENT;
 }
 
-void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
-{
-	int cpu;
-
-	cpumask_clear(out);
-	for_each_cpu(cpu, in)
-		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
-}
-EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
-
 bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
 {
 	return phys_id == cpuid_to_hartid_map(cpu);
-- 
2.34.0.rc2.393.gf8c9666880-goog


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

* Re: [PATCH] RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n
  2021-11-29 21:43 ` Sean Christopherson
@ 2022-01-09 21:38   ` Palmer Dabbelt
  -1 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-01-09 21:38 UTC (permalink / raw)
  To: seanjc
  Cc: Paul Walmsley, aou, linux-riscv, linux-kernel, kilobyte, anup, seanjc

On Mon, 29 Nov 2021 13:43:42 PST (-0800), seanjc@google.com wrote:
> Use what is currently the SMP=y version of riscv_cpuid_to_hartid_mask()
> for both SMP=y and SMP=n to fix a build failure with KVM=m and SMP=n due
> to boot_cpu_hartid not being exported.  This also fixes a second bug
> where the SMP=n version assumes the sole CPU in the system is in the
> incoming mask, which may not hold true in kvm_riscv_vcpu_sbi_ecall() if
> the KVM guest VM has multiple vCPUs (on a SMP=n system).
>
> Fixes: 1ef46c231df4 ("RISC-V: Implement new SBI v0.2 extensions")
> Reported-by: Adam Borowski <kilobyte@angband.pl>
> Cc: stable@vger.kernel.org
> Reviewed-by: Anup Patel <anup.patel@wdc.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

This is on for-next, thanks!

> ---
>  arch/riscv/include/asm/smp.h | 10 ++--------
>  arch/riscv/kernel/setup.c    | 10 ++++++++++
>  arch/riscv/kernel/smp.c      | 10 ----------
>  3 files changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h
> index a7d2811f3536..62d0e6e61da8 100644
> --- a/arch/riscv/include/asm/smp.h
> +++ b/arch/riscv/include/asm/smp.h
> @@ -43,7 +43,6 @@ void arch_send_call_function_ipi_mask(struct cpumask *mask);
>  void arch_send_call_function_single_ipi(int cpu);
>
>  int riscv_hartid_to_cpuid(int hartid);
> -void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
>
>  /* Set custom IPI operations */
>  void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);
> @@ -85,13 +84,6 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
>  	return boot_cpu_hartid;
>  }
>
> -static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
> -					      struct cpumask *out)
> -{
> -	cpumask_clear(out);
> -	cpumask_set_cpu(boot_cpu_hartid, out);
> -}
> -
>  static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops)
>  {
>  }
> @@ -102,6 +94,8 @@ static inline void riscv_clear_ipi(void)
>
>  #endif /* CONFIG_SMP */
>
> +void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
> +
>  #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
>  bool cpu_has_hotplug(unsigned int cpu);
>  #else
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index b42bfdc67482..63241abe84eb 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -59,6 +59,16 @@ atomic_t hart_lottery __section(".sdata")
>  unsigned long boot_cpu_hartid;
>  static DEFINE_PER_CPU(struct cpu, cpu_devices);
>
> +void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
> +{
> +	int cpu;
> +
> +	cpumask_clear(out);
> +	for_each_cpu(cpu, in)
> +		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
> +}
> +EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
> +
>  /*
>   * Place kernel memory regions on the resource tree so that
>   * kexec-tools can retrieve them from /proc/iomem. While there
> diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
> index 2f6da845c9ae..b5d30ea92292 100644
> --- a/arch/riscv/kernel/smp.c
> +++ b/arch/riscv/kernel/smp.c
> @@ -59,16 +59,6 @@ int riscv_hartid_to_cpuid(int hartid)
>  	return -ENOENT;
>  }
>
> -void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
> -{
> -	int cpu;
> -
> -	cpumask_clear(out);
> -	for_each_cpu(cpu, in)
> -		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
> -}
> -EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
> -
>  bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
>  {
>  	return phys_id == cpuid_to_hartid_map(cpu);

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

* Re: [PATCH] RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n
@ 2022-01-09 21:38   ` Palmer Dabbelt
  0 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-01-09 21:38 UTC (permalink / raw)
  To: seanjc
  Cc: Paul Walmsley, aou, linux-riscv, linux-kernel, kilobyte, anup, seanjc

On Mon, 29 Nov 2021 13:43:42 PST (-0800), seanjc@google.com wrote:
> Use what is currently the SMP=y version of riscv_cpuid_to_hartid_mask()
> for both SMP=y and SMP=n to fix a build failure with KVM=m and SMP=n due
> to boot_cpu_hartid not being exported.  This also fixes a second bug
> where the SMP=n version assumes the sole CPU in the system is in the
> incoming mask, which may not hold true in kvm_riscv_vcpu_sbi_ecall() if
> the KVM guest VM has multiple vCPUs (on a SMP=n system).
>
> Fixes: 1ef46c231df4 ("RISC-V: Implement new SBI v0.2 extensions")
> Reported-by: Adam Borowski <kilobyte@angband.pl>
> Cc: stable@vger.kernel.org
> Reviewed-by: Anup Patel <anup.patel@wdc.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

This is on for-next, thanks!

> ---
>  arch/riscv/include/asm/smp.h | 10 ++--------
>  arch/riscv/kernel/setup.c    | 10 ++++++++++
>  arch/riscv/kernel/smp.c      | 10 ----------
>  3 files changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h
> index a7d2811f3536..62d0e6e61da8 100644
> --- a/arch/riscv/include/asm/smp.h
> +++ b/arch/riscv/include/asm/smp.h
> @@ -43,7 +43,6 @@ void arch_send_call_function_ipi_mask(struct cpumask *mask);
>  void arch_send_call_function_single_ipi(int cpu);
>
>  int riscv_hartid_to_cpuid(int hartid);
> -void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
>
>  /* Set custom IPI operations */
>  void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);
> @@ -85,13 +84,6 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
>  	return boot_cpu_hartid;
>  }
>
> -static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
> -					      struct cpumask *out)
> -{
> -	cpumask_clear(out);
> -	cpumask_set_cpu(boot_cpu_hartid, out);
> -}
> -
>  static inline void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops)
>  {
>  }
> @@ -102,6 +94,8 @@ static inline void riscv_clear_ipi(void)
>
>  #endif /* CONFIG_SMP */
>
> +void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
> +
>  #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
>  bool cpu_has_hotplug(unsigned int cpu);
>  #else
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index b42bfdc67482..63241abe84eb 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -59,6 +59,16 @@ atomic_t hart_lottery __section(".sdata")
>  unsigned long boot_cpu_hartid;
>  static DEFINE_PER_CPU(struct cpu, cpu_devices);
>
> +void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
> +{
> +	int cpu;
> +
> +	cpumask_clear(out);
> +	for_each_cpu(cpu, in)
> +		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
> +}
> +EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
> +
>  /*
>   * Place kernel memory regions on the resource tree so that
>   * kexec-tools can retrieve them from /proc/iomem. While there
> diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
> index 2f6da845c9ae..b5d30ea92292 100644
> --- a/arch/riscv/kernel/smp.c
> +++ b/arch/riscv/kernel/smp.c
> @@ -59,16 +59,6 @@ int riscv_hartid_to_cpuid(int hartid)
>  	return -ENOENT;
>  }
>
> -void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
> -{
> -	int cpu;
> -
> -	cpumask_clear(out);
> -	for_each_cpu(cpu, in)
> -		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
> -}
> -EXPORT_SYMBOL_GPL(riscv_cpuid_to_hartid_mask);
> -
>  bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
>  {
>  	return phys_id == cpuid_to_hartid_map(cpu);

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2022-01-09 21:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 21:43 [PATCH] RISC-V: Use common riscv_cpuid_to_hartid_mask() for both SMP=y and SMP=n Sean Christopherson
2021-11-29 21:43 ` Sean Christopherson
2022-01-09 21:38 ` Palmer Dabbelt
2022-01-09 21:38   ` Palmer Dabbelt

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.