lib: sbi: Allow relaxed MMIO writes in device ipi_clear() callback
authorAnup Patel <apatel@ventanamicro.com>
Tue, 21 Nov 2023 10:22:17 +0000 (15:52 +0530)
committerAnup Patel <anup@brainfault.org>
Sun, 26 Nov 2023 13:15:08 +0000 (18:45 +0530)
Currently, there are no barriers before or after the ipi_clear()
device callback which forces ipi_clear() device callback to always
use non-relaxed MMIO writes.

Instead of above, we use wmb() in after the ipi_clear() device
callback which pairs with the wmb() done before the ipi_send()
device callback. This also allows device ipi_clear() callback
to use relaxed MMIO writes.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reported-by: Bo Gan <ganboing@gmail.com>
lib/sbi/sbi_ipi.c
lib/utils/ipi/aclint_mswi.c

index 1694a23fd8cb680db9741807dd2c4e9e5545431b..0bf446a046e707cd0595fd191abfd718e04bcfde 100644 (file)
@@ -220,8 +220,7 @@ void sbi_ipi_process(void)
        u32 hartindex = sbi_hartid_to_hartindex(current_hartid());
 
        sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD);
-       if (ipi_dev && ipi_dev->ipi_clear)
-               ipi_dev->ipi_clear(hartindex);
+       sbi_ipi_raw_clear(hartindex);
 
        ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0);
        ipi_event = 0;
@@ -247,6 +246,8 @@ int sbi_ipi_raw_send(u32 hartindex)
         * or MMIO writes done by the ipi_send() device
         * callback. This also allows the ipi_send() device
         * callback to use relaxed MMIO writes.
+        *
+        * This pairs with the wmb() in sbi_ipi_raw_clear().
         */
        wmb();
 
@@ -258,6 +259,17 @@ void sbi_ipi_raw_clear(u32 hartindex)
 {
        if (ipi_dev && ipi_dev->ipi_clear)
                ipi_dev->ipi_clear(hartindex);
+
+       /*
+        * Ensure that memory or MMIO writes after this
+        * function returns are not observed before the
+        * memory or MMIO writes done by the ipi_clear()
+        * device callback. This also allows ipi_clear()
+        * device callback to use relaxed MMIO writes.
+        *
+        * This pairs with the wmb() in sbi_ipi_raw_send().
+        */
+       wmb();
 }
 
 const struct sbi_ipi_device *sbi_ipi_get_device(void)
index bfd6a45b88eba51c9f4e49c104fbd477d72ad585..4ae6bb1c322728d1038be571b37d5ed3aa777e54 100644 (file)
@@ -61,7 +61,7 @@ static void mswi_ipi_clear(u32 hart_index)
 
        /* Clear ACLINT IPI */
        msip = (void *)mswi->addr;
-       writel(0, &msip[sbi_hartindex_to_hartid(hart_index) -
+       writel_relaxed(0, &msip[sbi_hartindex_to_hartid(hart_index) -
                        mswi->first_hartid]);
 }