Skip to contentSkip to conversation

riscv: remove unused SBI helpers and exports

PATCH In review Christoph Hellwig 4 participants 8 messages May 27, 2021 – May 31, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: remove unused SBI helpers and exports

Except for sbi_console_getchar and sbi_console_putchar none of the SBI helpers are used in modular code, and many are not used at all or only inside of sbi.c. Remove the dead wood.

---
 arch/riscv/include/asm/sbi.h |  17 ------
 arch/riscv/kernel/sbi.c      | 103 +----------------------------------
 2 files changed, 2 insertions(+), 118 deletions(-)
arch/riscv/include/asm/sbi.h +0 -17
index 0d42693cb65e..c051556d5bbc 100644
@@ -101,9 +101,6 @@ long sbi_get_mvendorid(void);
 long sbi_get_marchid(void);
 long sbi_get_mimpid(void);
 void sbi_set_timer(uint64_t stime_value);
-void sbi_shutdown(void);
-void sbi_clear_ipi(void);
-int sbi_send_ipi(const unsigned long *hart_mask);
 int sbi_remote_fence_i(const unsigned long *hart_mask);
 int sbi_remote_sfence_vma(const unsigned long *hart_mask,
 			   unsigned long start,
@@ -113,20 +110,6 @@ int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
 				unsigned long start,
 				unsigned long size,
 				unsigned long asid);
-int sbi_remote_hfence_gvma(const unsigned long *hart_mask,
-			   unsigned long start,
-			   unsigned long size);
-int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask,
-				unsigned long start,
-				unsigned long size,
-				unsigned long vmid);
-int sbi_remote_hfence_vvma(const unsigned long *hart_mask,
-			   unsigned long start,
-			   unsigned long size);
-int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
-				unsigned long start,
-				unsigned long size,
-				unsigned long asid);
 int sbi_probe_extension(int ext);
 
 /* Check if current SBI specification version is 0.1 or not */
arch/riscv/kernel/sbi.c +2 -101

163 lines not on this page · raw message

Signature · 7 lines
2.30.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 59 lines · Christoph Hellwig

Except for sbi_console_getchar and sbi_console_putchar none of the SBI helpers are used in modular code, and many are not used at all or only inside of sbi.c. Remove the dead wood.

---
 arch/riscv/include/asm/sbi.h |  17 ------
 arch/riscv/kernel/sbi.c      | 103 +----------------------------------
 2 files changed, 2 insertions(+), 118 deletions(-)
arch/riscv/include/asm/sbi.h +0 -17
index 0d42693cb65e..c051556d5bbc 100644
@@ -101,9 +101,6 @@ long sbi_get_mvendorid(void);
 long sbi_get_marchid(void);
 long sbi_get_mimpid(void);
 void sbi_set_timer(uint64_t stime_value);
-void sbi_shutdown(void);
-void sbi_clear_ipi(void);
-int sbi_send_ipi(const unsigned long *hart_mask);
 int sbi_remote_fence_i(const unsigned long *hart_mask);
 int sbi_remote_sfence_vma(const unsigned long *hart_mask,
                           unsigned long start,
@@ -113,20 +110,6 @@ int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
                                unsigned long start,
                                unsigned long size,
                                unsigned long asid);
-int sbi_remote_hfence_gvma(const unsigned long *hart_mask,
-                          unsigned long start,
-                          unsigned long size);
-int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask,
-                               unsigned long start,
-                               unsigned long size,
-                               unsigned long vmid);
-int sbi_remote_hfence_vvma(const unsigned long *hart_mask,
-                          unsigned long start,
-                          unsigned long size);
-int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
-                               unsigned long start,
-                               unsigned long size,
-                               unsigned long asid);
 int sbi_probe_extension(int ext);
 
 /* Check if current SBI specification version is 0.1 or not */
arch/riscv/kernel/sbi.c +0 -1
index 7402a417f38e..c152c0c43358 100644
@@ -12,7 +12,6 @@
 
 /* default SBI version is 0.1 */
 unsigned long sbi_spec_version __ro_after_init = SBI_SPEC_VERSION_DEFAULT;
-EXPORT_SYMBOL(sbi_spec_version);
 
 static void (*__sbi_set_timer)(uint64_t stime) __ro_after_init;
 static int (*__sbi_send_ipi)(const unsigned long *hart_mask) __ro_after_init;

arch/riscv/kernel/sbi.c struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, · line 47

Quoted 4 lines
arch/riscv/kernel/sbi.c +0 -1
@@ -44,7 +43,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
 
        return ret;
 }
-EXPORT_SYMBOL(sbi_ecall);

This is used by the SBI HSM based CPU Idle driver which is under review.

Atish's SBI PMU based driver also uses sbi_ecall().

arch/riscv/kernel/sbi.c int sbi_err_map_linux_errno(int err) · line 66

Quoted 8 lines
arch/riscv/kernel/sbi.c +0 -1
 int sbi_err_map_linux_errno(int err)
 {
@@ -63,7 +61,6 @@ int sbi_err_map_linux_errno(int err)
                return -ENOTSUPP;
        };
 }
-EXPORT_SYMBOL(sbi_err_map_linux_errno);

Even this is used by the SBI HSM based CPU Idle driver and SBI PMU based PMU driver which are under review.

arch/riscv/kernel/sbi.c EXPORT_SYMBOL(sbi_console_getchar); · line 105

Quoted 13 lines
arch/riscv/kernel/sbi.c +1 -2
 #ifdef CONFIG_RISCV_SBI_V01
 /**
@@ -98,22 +95,10 @@ EXPORT_SYMBOL(sbi_console_getchar);
  *
  * Return: None
  */
-void sbi_shutdown(void)
+static void sbi_shutdown(void)
 {
        sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0);
 }
-EXPORT_SYMBOL(sbi_shutdown);

This one is fine.

arch/riscv/kernel/sbi.c EXPORT_SYMBOL(sbi_console_getchar); · line 116

Quoted 11 lines
arch/riscv/kernel/sbi.c +0 -11
-
-/**
- * sbi_clear_ipi() - Clear any pending IPIs for the calling hart.
- *
- * Return: None
- */
-void sbi_clear_ipi(void)
-{
-       sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0);
-}
-EXPORT_SYMBOL(sbi_clear_ipi);

Even this one is fine.

arch/riscv/kernel/sbi.c void sbi_set_timer(uint64_t stime_value) · line 371

Quoted 13 lines
arch/riscv/kernel/sbi.c +1 -2
 /**
  * __sbi_set_timer_v01() - Program the timer for next timer event.
@@ -364,11 +349,10 @@ void sbi_set_timer(uint64_t stime_value)
  *
  * Return: 0 on success, appropriate linux error code otherwise.
  */
-int sbi_send_ipi(const unsigned long *hart_mask)
+static int sbi_send_ipi(const unsigned long *hart_mask)
 {
        return __sbi_send_ipi(hart_mask);
 }
-EXPORT_SYMBOL(sbi_send_ipi);

This is fine as well.

Quoted 93 lines
arch/riscv/kernel/sbi.c +0 -72
 /**
  * sbi_remote_fence_i() - Execute FENCE.I instruction on given remote harts.
@@ -381,7 +365,6 @@ int sbi_remote_fence_i(const unsigned long *hart_mask)
        return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_FENCE_I,
                            hart_mask, 0, 0, 0, 0);
 }
-EXPORT_SYMBOL(sbi_remote_fence_i);
 
 /**
  * sbi_remote_sfence_vma() - Execute SFENCE.VMA instructions on given remote
@@ -399,7 +382,6 @@ int sbi_remote_sfence_vma(const unsigned long *hart_mask,
        return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
                            hart_mask, start, size, 0, 0);
 }
-EXPORT_SYMBOL(sbi_remote_sfence_vma);
 
 /**
  * sbi_remote_sfence_vma_asid() - Execute SFENCE.VMA instructions on given
@@ -420,86 +402,6 @@ int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
        return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
                            hart_mask, start, size, asid, 0);
 }
-EXPORT_SYMBOL(sbi_remote_sfence_vma_asid);
-
-/**
- * sbi_remote_hfence_gvma() - Execute HFENCE.GVMA instructions on given remote
- *                        harts for the specified guest physical address range.
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the guest physical address
- * @size: Total size of the guest physical address range.
- *
- * Return: None
- */
-int sbi_remote_hfence_gvma(const unsigned long *hart_mask,
-                          unsigned long start,
-                          unsigned long size)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
-                           hart_mask, start, size, 0, 0);
-}
-EXPORT_SYMBOL_GPL(sbi_remote_hfence_gvma);
-
-/**
- * sbi_remote_hfence_gvma_vmid() - Execute HFENCE.GVMA instructions on given
- * remote harts for a guest physical address range belonging to a specific VMID.
- *
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the guest physical address
- * @size: Total size of the guest physical address range.
- * @vmid: The value of guest ID (VMID).
- *
- * Return: 0 if success, Error otherwise.
- */
-int sbi_remote_hfence_gvma_vmid(const unsigned long *hart_mask,
-                               unsigned long start,
-                               unsigned long size,
-                               unsigned long vmid)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
-                           hart_mask, start, size, vmid, 0);
-}
-EXPORT_SYMBOL(sbi_remote_hfence_gvma_vmid);
-
-/**
- * sbi_remote_hfence_vvma() - Execute HFENCE.VVMA instructions on given remote
- *                          harts for the current guest virtual address range.
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the current guest virtual address
- * @size: Total size of the current guest virtual address range.
- *
- * Return: None
- */
-int sbi_remote_hfence_vvma(const unsigned long *hart_mask,
-                          unsigned long start,
-                          unsigned long size)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
-                           hart_mask, start, size, 0, 0);
-}
-EXPORT_SYMBOL(sbi_remote_hfence_vvma);
-
-/**
- * sbi_remote_hfence_vvma_asid() - Execute HFENCE.VVMA instructions on given
- * remote harts for current guest virtual address range belonging to a specific
- * ASID.
- *
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the current guest virtual address
- * @size: Total size of the current guest virtual address range.
- * @asid: The value of address space identifier (ASID).
- *
- * Return: None

arch/riscv/kernel/sbi.c int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, · line 502

Quoted 10 lines
arch/riscv/kernel/sbi.c +0 -10
- */
-int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
-                               unsigned long start,
-                               unsigned long size,
-                               unsigned long asid)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
-                           hart_mask, start, size, asid, 0);
-}
-EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);

All sbi_remote_hfence_xyz() calls are used by KVM RISC-V module.

arch/riscv/kernel/sbi.c int sbi_probe_extension(int extid) · line 522

Quoted 8 lines
arch/riscv/kernel/sbi.c +0 -1
 /**
  * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
@@ -519,7 +421,6 @@ int sbi_probe_extension(int extid)
 
        return -ENOTSUPP;
 }
-EXPORT_SYMBOL(sbi_probe_extension);

This is used by SBI HSM based cpuidle driver.

This is also used by SBI PMU based PMU driver.

Quoted 11 lines
arch/riscv/kernel/sbi.c +0 -1
 static long __sbi_base_ecall(int fid)
 {
--

2.30.2

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Regards,
Anup

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 15 lines · Anup Patel
Quoted 15 lines
arch/riscv/kernel/sbi.c +0 -15
-
-/**
- * sbi_remote_hfence_vvma_asid() - Execute HFENCE.VVMA instructions on given
- * remote harts for current guest virtual address range belonging to a specific
- * ASID.
- *
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the current guest virtual address
- * @size: Total size of the current guest virtual address range.
- * @asid: The value of address space identifier (ASID).
- *
- * Return: None
- */
-int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
-                               unsigned long start,
Quoted 9 lines

arch/riscv/kernel/sbi.c int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, · line 502

Quoted 7 lines
arch/riscv/kernel/sbi.c +0 -7
-                               unsigned long size,
-                               unsigned long asid)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
-                           hart_mask, start, size, asid, 0);
-}
-EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);

All sbi_remote_hfence_xyz() calls are used by KVM RISC-V module.

Why aren't all these added by the series that add the module (not talking about KVM only)?

Paolo

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Paolo Bonzini
Quoted 3 lines
Quoted 1 line

-EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);

All sbi_remote_hfence_xyz() calls are used by KVM RISC-V module.

Why aren't all these added by the series that add the module (not talking about KVM only)?

Yes, that is the way to do it.

Actually SBI v0.2 RFENCE extension defines all these calls hence Atish added it as part of SBI v0.2 patches.

All sbi_remote_hfence_xyz() are primarily for hypervisors only.

Regards,
Anup

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#5 lore raw
Quoted 10 lines · On Thu, 27 May 2021 06:24:10 PDT (-0700), [email protected] wrote:
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Paolo Bonzini
Quoted 3 lines
Quoted 1 line

-EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);

All sbi_remote_hfence_xyz() calls are used by KVM RISC-V module.

Why aren't all these added by the series that add the module (not talking about KVM only)?

Quoted 6 lines
Quoted 1 line

Yes, that is the way to do it.

Actually SBI v0.2 RFENCE extension defines all these calls hence Atish added it as part of SBI v0.2 patches.

All sbi_remote_hfence_xyz() are primarily for hypervisors only.

We took them early as a way to help make it easier to handle the KVM patches, as at the time these were the only things touching files outside of arch/riscv/kvm.

I know the general rule is to only take code with callers, but these are defined by the SBI so I figured we'd make everyone's lives a bit easier by just keeping them around.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#6 lore raw
Quoted 3 lines · Palmer Dabbelt

I know the general rule is to only take code with callers, but these are defined by the SBI so I figured we'd make everyone's lives a bit easier by just keeping them around.

Keeping unused code never helps anyone. Adding code without any known users like some of the others is even worse. And given that sbi_ecall is exported (and just a trivial inline asm wrapper) there is no point in having most of the helpers at all, but that is another story.

So for now I'd suggest to merge my patch, and changing any new code to just use sbi_ecall instead of the remove wrappes as there is no point in bloating the core kernel with trivial wrappers only used by a single module.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw
In reply to Paolo Bonzini
Quoted 27 lines · Paolo Bonzini
Quoted 15 lines · Anup Patel
Quoted 15 lines
arch/riscv/kernel/sbi.c +0 -15
-
-/**
- * sbi_remote_hfence_vvma_asid() - Execute HFENCE.VVMA instructions on given
- * remote harts for current guest virtual address range belonging to a specific
- * ASID.
- *
- * @hart_mask: A cpu mask containing all the target harts.
- * @start: Start of the current guest virtual address
- * @size: Total size of the current guest virtual address range.
- * @asid: The value of address space identifier (ASID).
- *
- * Return: None
- */
-int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
-                               unsigned long start,
Quoted 9 lines

arch/riscv/kernel/sbi.c int sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, · line 502

Quoted 7 lines
arch/riscv/kernel/sbi.c +0 -7
-                               unsigned long size,
-                               unsigned long asid)
-{
-       return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
-                           hart_mask, start, size, asid, 0);
-}
-EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);

All sbi_remote_hfence_xyz() calls are used by KVM RISC-V module.

Quoted 2 lines

Why aren't all these added by the series that add the module (not talking about KVM only)?

These calls are part of SBI v0.2 spec hence were added as part of SBI v0.2 support patches.

Regards,
Anup

Quoted 3 lines

Paolo

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv