diff options
author | Atish Patra <atish.patra@wdc.com> | 2019-08-14 18:02:14 -0700 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2019-08-16 08:42:55 +0530 |
commit | 897a97a6af31174eb2c6058c6ceb9d3ccc6c6e3c (patch) | |
tree | e667994b5a11efdef3a2b3be8a8bf27a32b018b0 /lib/sbi/sbi_ecall.c | |
parent | f6e13e0dd30b164eb444bc08c70fa1b8576e0bca (diff) |
lib: Fix race conditions in tlb fifo access.
Linux kernel expects tlb flush SBI call to be completely synchronous i.e.
the SBI call should only return once corresponding *fence* instruction is
executed.
OpenSBI manages the outstanding TLB flush requests by keeping them in a
per hart based fifo. However, there are few corner cases that may lead to
race conditions while updating the fifo.
Currently, the caller hart waits for IPI acknowledgement via clint
address which is not a very good method as synchronization on MMIO may not
be supported in every platform. Moreover, the waiter doesn't have any way of
identifying if the IPI is received for specific tlb flush request or any
other IPI. This may lead to unpredictable behavior in supervisor/user space.
Fix this by waiting on individual fifo entries rather than MMIO address.
Currently, a relaxed loop is being used because wfi again involves MMIO write
which would be slower compared to relaxed loop. To avoid deadlock, fifo
is processed every time a hart loops for fifo enqueue or fifo sync to consume
the tlb flush requests sent by other harts.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_ecall.c')
-rw-r--r-- | lib/sbi/sbi_ecall.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index 50c05d6..c6ec76e 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -16,6 +16,7 @@ #include <sbi/sbi_timer.h> #include <sbi/sbi_tlb.h> #include <sbi/sbi_trap.h> +#include <sbi/sbi_hart.h> #define SBI_ECALL_VERSION_MAJOR 0 #define SBI_ECALL_VERSION_MINOR 1 @@ -36,6 +37,7 @@ int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs, int ret = SBI_ENOTSUPP; struct unpriv_trap uptrap; struct sbi_tlb_info tlb_info; + u32 source_hart = sbi_current_hartid(); switch (regs->a7) { case SBI_ECALL_SET_TIMER: @@ -64,13 +66,18 @@ int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs, SBI_IPI_EVENT_SOFT, NULL); break; case SBI_ECALL_REMOTE_FENCE_I: + tlb_info.start = 0; + tlb_info.size = 0; + tlb_info.type = SBI_ITLB_FLUSH; + tlb_info.shart_mask = 1UL << source_hart; ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)regs->a0, - SBI_IPI_EVENT_FENCE_I, NULL); + SBI_IPI_EVENT_FENCE_I, &tlb_info); break; case SBI_ECALL_REMOTE_SFENCE_VMA: tlb_info.start = (unsigned long)regs->a1; tlb_info.size = (unsigned long)regs->a2; tlb_info.type = SBI_TLB_FLUSH_VMA; + tlb_info.shart_mask = 1UL << source_hart; ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)regs->a0, SBI_IPI_EVENT_SFENCE_VMA, &tlb_info); @@ -80,6 +87,7 @@ int sbi_ecall_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs, tlb_info.size = (unsigned long)regs->a2; tlb_info.asid = (unsigned long)regs->a3; tlb_info.type = SBI_TLB_FLUSH_VMA_ASID; + tlb_info.shart_mask = 1UL << source_hart; ret = sbi_ipi_send_many(scratch, &uptrap, (ulong *)regs->a0, SBI_IPI_EVENT_SFENCE_VMA_ASID, |