From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387851; b=aeCRm2fGrSLk62aXFJz0OXA+tqpw9UQ3jdiZeoIMejeSXvesjwDjW7DC8QY6dCS6+nbX tAkm1WKXdG/lomzwqWqWiELCJDLvQ8C8qFQ80W5zf3ehImqrmpRVDo2r/xMEg0LWpasFj jCHVBx0ggEDbyVIZaWLkBKOrpWRMTDuWv+8UvIHMqZGSyeLMPD+ccacMpz4rhpDIQxmw6 j5oPUnmBoClRKpCcccPHf5ECJuedqywxvzrts4CG18rqCDLxEqniQ3epMbRtlHGnWwgSy EqfP7MPT1FzGdBiwT/ltfOQVtPJYA35AVuDxVmjP4YmLNLAXyR/AFJhJhWNpUULZ8JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387851; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YexHBHsDblN55lmUHmba/TntpIYuTlyDVlvY0vROuNw=; b=bCtXXWExw73nZncbgtSeklkSZIDATnkNusGwwm59rbvELDriQit2+4rPQTDdh29Zna5O 7mYZDvaw5KszLqdscU9et+FDGu2mWJsjv/d6CMJmHjcVzs01a61FLOkolqKqYu+6gfod9 SIOf3grQdgZuY1AdxTltUNZkxWAoAgkIw7Xyo43BQYygW9N2IaS8NNX9Kf41/u9HKT3SB MLpgAw6+BFYSyM78Fbejnx1tj+gADfBIarEk3j5Hse8PNQr6bqWhiIv+NLJ2/bivzFJXN HfX4jb1a1/QXSKasB/Bk8YRXZDi2T2ONXS0Ac7ann68RDwKFZuq6JMmk04Xx3u3TJrg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hznKYS1T; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1445606A32C; Fri, 4 Dec 2026 12:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hznKYS1T Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45D471F000C2; Fri, 4 Dec 2026 12:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387851; bh=YexHBHsDblN55lmUHmba/TntpIYuTlyDVlvY0vROuNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hznKYS1TUvakUTgqetzzIygI7lgIVS037yt4JUWpVjfe8xmaPCPuZ5Z+4MsSUmCzL nfb/DU8NkJf6HVBoE65eDdadyhY6366mtdR/3K4Uaqhp7Yhn2HJY+r5ZZfXg/Kb6Ki GmLcsWYWhhMywNufrQsPrNmDiRz3O3JUZAs9F00E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Margolin , Tom Sela , Yonatan Nachum , Leon Romanovsky , Sasha Levin Subject: [PATCH 6.1 0384/1059] RDMA/efa: Fix race between admin command timeout and completion Date: Fri, 4 Dec 2026 18:58:35 +0900 Message-ID: <20261204100654.248620821@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yonatan Nachum [ Upstream commit 466612f8a8020c6b3af6377c730775a4c630f12c ] An admin command that times out can race with the interrupt handler processing its completion, in two ways. The timeout path releases the completion context without synchronizing against the handler. A handler that has already seen the command as submitted then copies the CQE into the caller's response buffer after the waiter returned and that buffer went out of scope. The waiter can also observe the command as completed before the CQE was copied, since the status is published first. It decodes its own uninitialized response buffer, returns success with garbage contents and leaks stack data to the caller. Both wait paths read the status without the CQ lock. Add a timed-out state and publish it under the CQ lock in both wait paths before returning, so the handler, which only completes commands in submitted state, cannot act on an abandoned context. In the interrupt wait path test the return value of the wait instead of the status: the handler signals the completion after copying the CQE, so a successful wait implies a valid response. Read the status in the polling wait path inside the critical section that drains the CQ, which also lets a completion arriving on the last iteration be honored instead of reported as a timeout. Fixes: 0420e542569b ("RDMA/efa: Implement functions that submit and complete admin commands") Reviewed-by: Michael Margolin Reviewed-by: Tom Sela Signed-off-by: Yonatan Nachum Link: https://patch.msgid.link/20261012165113.576899-1-ynachum@amazon.com Signed-off-by: Leon Romanovsky [ sashal: Context lines differ from upstream (no EFA_CMD_ALLOCATED state, an older log format string, and int err declared at function scope), but the changed lines match upstream. ] Signed-off-by: Sasha Levin --- drivers/infiniband/hw/efa/efa_com.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/efa/efa_com.c b/drivers/infiniband/hw/efa/efa_com.c index 00e339abc2c13..fab32b1da93fb 100644 --- a/drivers/infiniband/hw/efa/efa_com.c +++ b/drivers/infiniband/hw/efa/efa_com.c @@ -23,6 +23,7 @@ enum efa_cmd_status { EFA_CMD_SUBMITTED, EFA_CMD_COMPLETED, + EFA_CMD_TIMED_OUT, }; struct efa_comp_ctx { @@ -497,6 +498,7 @@ static int efa_com_comp_status_to_errno(u8 comp_status) static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_ctx, struct efa_com_admin_queue *aq) { + bool comp_timeout = false; unsigned long timeout; unsigned long flags; int err; @@ -506,12 +508,19 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_c while (1) { spin_lock_irqsave(&aq->cq.lock, flags); efa_com_handle_admin_completion(aq); - spin_unlock_irqrestore(&aq->cq.lock, flags); - - if (comp_ctx->status != EFA_CMD_SUBMITTED) + if (comp_ctx->status != EFA_CMD_SUBMITTED) { + spin_unlock_irqrestore(&aq->cq.lock, flags); break; + } if (time_is_before_jiffies(timeout)) { + comp_ctx->status = EFA_CMD_TIMED_OUT; + comp_timeout = true; + } + + spin_unlock_irqrestore(&aq->cq.lock, flags); + + if (comp_timeout) { ibdev_err_ratelimited( aq->efa_dev, "Wait for completion (polling) timeout\n"); @@ -535,11 +544,12 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_c static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *comp_ctx, struct efa_com_admin_queue *aq) { - unsigned long flags; + unsigned long flags, remaining_jiffies; + bool completed; int err; - wait_for_completion_timeout(&comp_ctx->wait_event, - usecs_to_jiffies(aq->completion_timeout)); + remaining_jiffies = wait_for_completion_timeout( + &comp_ctx->wait_event, usecs_to_jiffies(aq->completion_timeout)); /* * In case the command wasn't completed find out the root cause. @@ -547,14 +557,16 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com * 1) No completion (timeout reached) * 2) There is completion but the device didn't get any msi-x interrupt. */ - if (comp_ctx->status == EFA_CMD_SUBMITTED) { + if (remaining_jiffies == 0) { spin_lock_irqsave(&aq->cq.lock, flags); efa_com_handle_admin_completion(aq); + completed = (comp_ctx->status == EFA_CMD_COMPLETED); + comp_ctx->status = EFA_CMD_TIMED_OUT; spin_unlock_irqrestore(&aq->cq.lock, flags); atomic64_inc(&aq->stats.no_completion); - if (comp_ctx->status == EFA_CMD_COMPLETED) + if (completed) ibdev_err_ratelimited( aq->efa_dev, "The device sent a completion but the driver didn't receive any MSI-X interrupt for admin cmd %s(%d) status %d (ctx: 0x%p, sq producer: %d, sq consumer: %d, cq consumer: %d)\n", -- 2.53.0