RISC-V: Fix sparse warnings
Subsystems (3)
cover RISC-V: Fix sparse warnings
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
arch/riscv/kernel/paravirt.c | 6 +++--- arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 RISC-V: paravirt: steal_time should be static
steal_time is not used outside paravirt.c, make it static, as sparse suggested.
--- arch/riscv/kernel/paravirt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/paravirt.c +1 -1
@@ -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 ) {
Signature · 1 line
2.43.0
PATCH 2/3 RISC-V: paravirt: Use correct restricted types
In reply to Andrew Jones__le32 and __le64 types should be used with le32_to_cpu() and le64_to_cpu(), as sparse helpfully points out.
--- arch/riscv/kernel/paravirt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/paravirt.c +2 -2
@@ -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
Signature · 1 line
2.43.0
PATCH 3/3 RISC-V: KVM: Use correct restricted types
In reply to Andrew Jones__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.
--- arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
arch/riscv/kvm/vcpu_sbi_sta.c +12 -8
@@ -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));
Signature · 1 line
2.43.0
PATCH 1/3 RISC-V: paravirt: steal_time should be static
In reply to Andrew JonesQuoted 15 lines · On Wed, Jan 31, 2024 at 4:05?AM Andrew Jones <[email protected]> wrote:
steal_timeis not used outsideparavirt.c, make it static, as sparse suggested.Fixes fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/paravirt.c +0
-0
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 45
Quoted 6 lines
arch/riscv/kernel/paravirt.c +1
-1@@ -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);
Quoted 5 lines
arch/riscv/kernel/paravirt.c +0
-1static bool __init has_pv_steal_clock (void ) { --2.43.0
Signature · 2 lines
Regards, Atish
PATCH 2/3 RISC-V: paravirt: Use correct restricted types
In reply to Andrew JonesQuoted 28 lines · On Wed, Jan 31, 2024 at 4:05?AM Andrew Jones <[email protected]> wrote:
__le32and__le64types should be used withle32_to_cpu()andle64_to_cpu(), as sparse helpfully points out.Fixes fdf68acccfc6 ("RISC-V: paravirt: Implement steal-time support")Reported-by kernel test robot <[email protected]>Closes https://lore.kernel.org/oe-kbuild-all/202401011933.hL9zqmKo-lkp at intel.com/Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/paravirt.c +2
-3@@ -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 --
Quoted 2 lines
2.43.0
Signature · 2 lines
Regards, Atish
PATCH 3/3 RISC-V: KVM: Use correct restricted types
In reply to Andrew JonesQuoted 62 lines · On Wed, Jan 31, 2024 at 4:05?AM Andrew Jones <[email protected]> wrote:
__le32and__le64types should be used withle32_to_cpu()andle64_to_cpu()and__useris 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 <[email protected]>Closes https://lore.kernel.org/oe-kbuild-all/202401020142.lwFEDK5v-lkp at intel.com/Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)arch/riscv/kvm/vcpu_sbi_sta.c +12
-9@@ -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)); --
Quoted 2 lines
2.43.0
Signature · 2 lines
Regards, Atish
Anup Patel
maintainercover RISC-V: Fix sparse warnings
In reply to Andrew JonesQuoted 10 lines · On Wed, Jan 31, 2024 at 5:35?PM Andrew Jones <[email protected]> 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.
Quoted 8 lines
Thanks,
drewAndrew Jones (3):
RISC-V: paravirt:steal_timeshould 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
Quoted 8 lines
arch/riscv/kernel/paravirt.c | 6 +++--- arch/riscv/kvm/vcpu_sbi_sta.c | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-)--
2.43.0