From 497ca4ccad0a8d74cdc6aa165398f53352809983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Wed, 9 Sep 2026 18:23:15 +0200 Subject: [PATCH] lib: rpmi: add TSA annotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Thread Safety Analysis (TSA) annotations for the RPMI mailbox implementation. This includes indicating which fields are protected by a spinlock, and annotating which functions must be called under a spinlock. Exclude rpmi_shmem_transport_init(), as the spinlock cannot be acquired before it is initialized. Signed-off-by: Carlos López Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20260909162322.29778-8-carlos.lopezr4096@gmail.com Signed-off-by: Anup Patel --- lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c index 521e0673..cf975658 100644 --- a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c +++ b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c @@ -113,9 +113,9 @@ struct smq_queue_ctx { /* Type of queue - REQ or ACK */ enum rpmi_queue_type queue_type; /* Pointers to the queue shared memory */ - volatile le32_t *headptr; - volatile le32_t *tailptr; - volatile uint8_t *buffer; + volatile le32_t *headptr PT_GUARDED_BY(&queue_lock); + volatile le32_t *tailptr PT_GUARDED_BY(&queue_lock); + volatile uint8_t *buffer PT_GUARDED_BY(&queue_lock); /* Name of the queue */ char name[RPMI_NAME_CHARS_MAX]; }; @@ -154,12 +154,14 @@ struct rpmi_shmem_mbox_controller { /**************** Shared Memory Queues Helpers **************/ static bool __smq_queue_full(struct smq_queue_ctx *qctx) + MUST_HOLD(&qctx->queue_lock) { return ((le32_to_cpu(*qctx->tailptr) + 1) % qctx->num_slots == le32_to_cpu(*qctx->headptr)) ? true : false; } static bool __smq_queue_empty(struct smq_queue_ctx *qctx) + MUST_HOLD(&qctx->queue_lock) { return (le32_to_cpu(*qctx->headptr) == le32_to_cpu(*qctx->tailptr)) ? true : false; @@ -167,6 +169,7 @@ static bool __smq_queue_empty(struct smq_queue_ctx *qctx) static int __smq_rx(struct smq_queue_ctx *qctx, u32 slot_size, u32 service_group_id, struct mbox_xfer *xfer) + MUST_HOLD(&qctx->queue_lock) { void *dst, *src; struct rpmi_message *msg; @@ -250,7 +253,7 @@ static int __smq_rx(struct smq_queue_ctx *qctx, u32 slot_size, static int __smq_tx(struct smq_queue_ctx *qctx, struct rpmi_mb_regs *mb_regs, u32 a2p_doorbell_value, u32 slot_size, u32 service_group_id, - struct mbox_xfer *xfer) + struct mbox_xfer *xfer) MUST_HOLD(&qctx->queue_lock) { u32 i, tailidx; void *dst, *src; @@ -583,7 +586,8 @@ static void rpmi_shmem_mbox_free_chan(struct mbox_controller *mbox, extern struct fdt_mailbox fdt_mailbox_rpmi_shmem; static int rpmi_shmem_transport_init(struct rpmi_shmem_mbox_controller *mctl, - const void *fdt, int nodeoff) + const void *fdt, + int nodeoff) NO_THREAD_SAFETY_ANALYSIS { const char *name; const fdt32_t *prop;