* [PATCH 1/3] RISC-V: paravirt: steal_time should be static
2024-01-31 12:05 [PATCH 0/3] RISC-V: Fix sparse warnings Andrew Jones
@ 2024-01-31 12:05 ` Andrew Jones
2024-01-31 19:44 ` Atish Patra
2024-01-31 12:05 ` [PATCH 2/3] RISC-V: paravirt: Use correct restricted types Andrew Jones
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-01-31 12:05 UTC (permalink / raw)
To: kvm-riscv, linux-riscv; +Cc: anup, atishp, paul.walmsley, palmer, aou
steal_time is not used outside paravirt.c, make it static,
as sparse suggested.
Fixes: fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kernel/paravirt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c
index 8e114f5930ce..15c5d4048db5 100644
--- a/arch/riscv/kernel/paravirt.c
+++ b/arch/riscv/kernel/paravirt.c
@@ -41,7 +41,7 @@ static int __init parse_no_stealacc(char *arg)
early_param("no-steal-acc", parse_no_stealacc);
-DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64);
+static DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64);
static bool __init has_pv_steal_clock(void)
{
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/3] RISC-V: paravirt: steal_time should be static
2024-01-31 12:05 ` [PATCH 1/3] RISC-V: paravirt: steal_time should be static Andrew Jones
@ 2024-01-31 19:44 ` Atish Patra
0 siblings, 0 replies; 8+ messages in thread
From: Atish Patra @ 2024-01-31 19:44 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm-riscv, linux-riscv, anup, paul.walmsley, palmer, aou
On Wed, Jan 31, 2024 at 4:05 AM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> steal_time is not used outside paravirt.c, make it static,
> as sparse suggested.
>
> Fixes: fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> ---
> arch/riscv/kernel/paravirt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c
> index 8e114f5930ce..15c5d4048db5 100644
> --- a/arch/riscv/kernel/paravirt.c
> +++ b/arch/riscv/kernel/paravirt.c
> @@ -41,7 +41,7 @@ static int __init parse_no_stealacc(char *arg)
>
> early_param("no-steal-acc", parse_no_stealacc);
>
> -DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64);
> +static DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64);
>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
> static bool __init has_pv_steal_clock(void)
> {
> --
> 2.43.0
>
--
Regards,
Atish
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] RISC-V: paravirt: Use correct restricted types
2024-01-31 12:05 [PATCH 0/3] RISC-V: Fix sparse warnings Andrew Jones
2024-01-31 12:05 ` [PATCH 1/3] RISC-V: paravirt: steal_time should be static Andrew Jones
@ 2024-01-31 12:05 ` Andrew Jones
2024-01-31 19:45 ` Atish Patra
2024-01-31 12:05 ` [PATCH 3/3] RISC-V: KVM: " Andrew Jones
2024-02-02 15:57 ` [PATCH 0/3] RISC-V: Fix sparse warnings Anup Patel
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-01-31 12:05 UTC (permalink / raw)
To: kvm-riscv, linux-riscv
Cc: anup, atishp, paul.walmsley, palmer, aou, kernel test robot
__le32 and __le64 types should be used with le32_to_cpu() and
le64_to_cpu(), as sparse helpfully points out.
Fixes: fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401011933.hL9zqmKo-lkp@intel.com/
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kernel/paravirt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c
index 15c5d4048db5..0d6225fd3194 100644
--- a/arch/riscv/kernel/paravirt.c
+++ b/arch/riscv/kernel/paravirt.c
@@ -91,8 +91,8 @@ static int pv_time_cpu_down_prepare(unsigned int cpu)
static u64 pv_time_steal_clock(int cpu)
{
struct sbi_sta_struct *st = per_cpu_ptr(&steal_time, cpu);
- u32 sequence;
- u64 steal;
+ __le32 sequence;
+ __le64 steal;
/*
* Check the sequence field before and after reading the steal
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/3] RISC-V: paravirt: Use correct restricted types
2024-01-31 12:05 ` [PATCH 2/3] RISC-V: paravirt: Use correct restricted types Andrew Jones
@ 2024-01-31 19:45 ` Atish Patra
0 siblings, 0 replies; 8+ messages in thread
From: Atish Patra @ 2024-01-31 19:45 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm-riscv, linux-riscv, anup, paul.walmsley, palmer, aou,
kernel test robot
On Wed, Jan 31, 2024 at 4:05 AM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> __le32 and __le64 types should be used with le32_to_cpu() and
> le64_to_cpu(), as sparse helpfully points out.
>
> Fixes: fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202401011933.hL9zqmKo-lkp@intel.com/
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> ---
> arch/riscv/kernel/paravirt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kernel/paravirt.c b/arch/riscv/kernel/paravirt.c
> index 15c5d4048db5..0d6225fd3194 100644
> --- a/arch/riscv/kernel/paravirt.c
> +++ b/arch/riscv/kernel/paravirt.c
> @@ -91,8 +91,8 @@ static int pv_time_cpu_down_prepare(unsigned int cpu)
> static u64 pv_time_steal_clock(int cpu)
> {
> struct sbi_sta_struct *st = per_cpu_ptr(&steal_time, cpu);
> - u32 sequence;
> - u64 steal;
> + __le32 sequence;
> + __le64 steal;
>
> /*
> * Check the sequence field before and after reading the steal
> --
> 2.43.0
>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
--
Regards,
Atish
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] RISC-V: KVM: Use correct restricted types
2024-01-31 12:05 [PATCH 0/3] RISC-V: Fix sparse warnings Andrew Jones
2024-01-31 12:05 ` [PATCH 1/3] RISC-V: paravirt: steal_time should be static Andrew Jones
2024-01-31 12:05 ` [PATCH 2/3] RISC-V: paravirt: Use correct restricted types Andrew Jones
@ 2024-01-31 12:05 ` Andrew Jones
2024-01-31 19:46 ` Atish Patra
2024-02-02 15:57 ` [PATCH 0/3] RISC-V: Fix sparse warnings Anup Patel
3 siblings, 1 reply; 8+ messages in thread
From: Andrew Jones @ 2024-01-31 12:05 UTC (permalink / raw)
To: kvm-riscv, linux-riscv
Cc: anup, atishp, paul.walmsley, palmer, aou, kernel test robot
__le32 and __le64 types should be used with le32_to_cpu() and
le64_to_cpu() and __user is needed for pointers referencing
guest memory, as sparse helpfully points out.
Fixes: e9f12b5fff8a ("RISC-V: KVM: Implement SBI STA extension")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401020142.lwFEDK5v-lkp@intel.com/
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
index 01f09fe8c3b0..d8cf9ca28c61 100644
--- a/arch/riscv/kvm/vcpu_sbi_sta.c
+++ b/arch/riscv/kvm/vcpu_sbi_sta.c
@@ -26,8 +26,12 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
{
gpa_t shmem = vcpu->arch.sta.shmem;
u64 last_steal = vcpu->arch.sta.last_steal;
- u32 *sequence_ptr, sequence;
- u64 *steal_ptr, steal;
+ __le32 __user *sequence_ptr;
+ __le64 __user *steal_ptr;
+ __le32 sequence_le;
+ __le64 steal_le;
+ u32 sequence;
+ u64 steal;
unsigned long hva;
gfn_t gfn;
@@ -47,22 +51,22 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
return;
}
- sequence_ptr = (u32 *)(hva + offset_in_page(shmem) +
+ sequence_ptr = (__le32 __user *)(hva + offset_in_page(shmem) +
offsetof(struct sbi_sta_struct, sequence));
- steal_ptr = (u64 *)(hva + offset_in_page(shmem) +
+ steal_ptr = (__le64 __user *)(hva + offset_in_page(shmem) +
offsetof(struct sbi_sta_struct, steal));
- if (WARN_ON(get_user(sequence, sequence_ptr)))
+ if (WARN_ON(get_user(sequence_le, sequence_ptr)))
return;
- sequence = le32_to_cpu(sequence);
+ sequence = le32_to_cpu(sequence_le);
sequence += 1;
if (WARN_ON(put_user(cpu_to_le32(sequence), sequence_ptr)))
return;
- if (!WARN_ON(get_user(steal, steal_ptr))) {
- steal = le64_to_cpu(steal);
+ if (!WARN_ON(get_user(steal_le, steal_ptr))) {
+ steal = le64_to_cpu(steal_le);
vcpu->arch.sta.last_steal = READ_ONCE(current->sched_info.run_delay);
steal += vcpu->arch.sta.last_steal - last_steal;
WARN_ON(put_user(cpu_to_le64(steal), steal_ptr));
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/3] RISC-V: KVM: Use correct restricted types
2024-01-31 12:05 ` [PATCH 3/3] RISC-V: KVM: " Andrew Jones
@ 2024-01-31 19:46 ` Atish Patra
0 siblings, 0 replies; 8+ messages in thread
From: Atish Patra @ 2024-01-31 19:46 UTC (permalink / raw)
To: Andrew Jones
Cc: kvm-riscv, linux-riscv, anup, paul.walmsley, palmer, aou,
kernel test robot
On Wed, Jan 31, 2024 at 4:05 AM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> __le32 and __le64 types should be used with le32_to_cpu() and
> le64_to_cpu() and __user is needed for pointers referencing
> guest memory, as sparse helpfully points out.
>
> Fixes: e9f12b5fff8a ("RISC-V: KVM: Implement SBI STA extension")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202401020142.lwFEDK5v-lkp@intel.com/
> Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> ---
> arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
> index 01f09fe8c3b0..d8cf9ca28c61 100644
> --- a/arch/riscv/kvm/vcpu_sbi_sta.c
> +++ b/arch/riscv/kvm/vcpu_sbi_sta.c
> @@ -26,8 +26,12 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
> {
> gpa_t shmem = vcpu->arch.sta.shmem;
> u64 last_steal = vcpu->arch.sta.last_steal;
> - u32 *sequence_ptr, sequence;
> - u64 *steal_ptr, steal;
> + __le32 __user *sequence_ptr;
> + __le64 __user *steal_ptr;
> + __le32 sequence_le;
> + __le64 steal_le;
> + u32 sequence;
> + u64 steal;
> unsigned long hva;
> gfn_t gfn;
>
> @@ -47,22 +51,22 @@ void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
> return;
> }
>
> - sequence_ptr = (u32 *)(hva + offset_in_page(shmem) +
> + sequence_ptr = (__le32 __user *)(hva + offset_in_page(shmem) +
> offsetof(struct sbi_sta_struct, sequence));
> - steal_ptr = (u64 *)(hva + offset_in_page(shmem) +
> + steal_ptr = (__le64 __user *)(hva + offset_in_page(shmem) +
> offsetof(struct sbi_sta_struct, steal));
>
> - if (WARN_ON(get_user(sequence, sequence_ptr)))
> + if (WARN_ON(get_user(sequence_le, sequence_ptr)))
> return;
>
> - sequence = le32_to_cpu(sequence);
> + sequence = le32_to_cpu(sequence_le);
> sequence += 1;
>
> if (WARN_ON(put_user(cpu_to_le32(sequence), sequence_ptr)))
> return;
>
> - if (!WARN_ON(get_user(steal, steal_ptr))) {
> - steal = le64_to_cpu(steal);
> + if (!WARN_ON(get_user(steal_le, steal_ptr))) {
> + steal = le64_to_cpu(steal_le);
> vcpu->arch.sta.last_steal = READ_ONCE(current->sched_info.run_delay);
> steal += vcpu->arch.sta.last_steal - last_steal;
> WARN_ON(put_user(cpu_to_le64(steal), steal_ptr));
> --
> 2.43.0
>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
--
Regards,
Atish
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] RISC-V: Fix sparse warnings
2024-01-31 12:05 [PATCH 0/3] RISC-V: Fix sparse warnings Andrew Jones
` (2 preceding siblings ...)
2024-01-31 12:05 ` [PATCH 3/3] RISC-V: KVM: " Andrew Jones
@ 2024-02-02 15:57 ` Anup Patel
3 siblings, 0 replies; 8+ messages in thread
From: Anup Patel @ 2024-02-02 15:57 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm-riscv, linux-riscv, atishp, paul.walmsley, palmer, aou
On Wed, Jan 31, 2024 at 5:35 PM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> After the steal-time series was merged, LKP sent me mail with sparse
> warnings for the lack of using appropriate restricted types and a
> local variable not being static. This series makes the fixups
> necessary to appease sparse for 64-bit compiles. Changes to
> __get_user_8() and __put_user_8() are needed to completely quiet
> sparse for 32-bit compiles. I'll address those 32-bit sparse warnings
> separately, since it's not 100% clear how best to approach a couple of
> them.
>
> Thanks,
> drew
>
>
> Andrew Jones (3):
> RISC-V: paravirt: steal_time should be static
> RISC-V: paravirt: Use correct restricted types
> RISC-V: KVM: Use correct restricted types
Queued this series as fixes for Linux-6.8
Thanks,
Anup
>
> arch/riscv/kernel/paravirt.c | 6 +++---
> arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++--------
> 2 files changed, 15 insertions(+), 11 deletions(-)
>
> --
> 2.43.0
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 8+ messages in thread