From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13ACA606A31A for ; Mon, 30 Nov 2026 20:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1xM0UtZp; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jrqDA7ED DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=l/+aYUmYk3Q1W9u+aFdHVWHhyKh/l+YpnvDb4V487bo=; b=1xM0UtZpBOz3kZ JdcghDWIZLC0l4BrFXfexk/sxC2PqTA/JNy1RqJgXVH0+f0SOPXfP+VH6poOXyKYrQU8BlVGb2Wfj kdgJxxyJa5W/gXKftUTOO9pPq20g2aTotos9edOSNp5zgY5ufZzLx6MMLVY7r7CHjUx8RCw3A0wgU U5sfMOeexz0Nb8REz2heyfI86ff2NtbUAe2AmieMo9h59RP7GtRfqW9Jguu4/UpCTK5owoA1kxq4A Q6pAqrjdPJIrK9fhGg/XFIVq6qvBCbIX8QobT/l/Q4ZeweCmCQHwWESOsSdljfUtH6aZxarQUMP04 hLe9l5qSXC9QhBokHewA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY7gp-00000005mLj-1kfW; Mon, 30 Nov 2026 20:09:31 +0000 Received: from mgamail.intel.com ([198.175.65.12]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY7gO-00000005mCz-3JwN for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 20:09:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796069344; x=1827605344; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l/+aYUmYk3Q1W9u+aFdHVWHhyKh/l+YpnvDb4V487bo=; b=jrqDA7EDvLXwm3qy8D/Cv9Z91NuPhCkTAEVM4mY853Nw2d2YqTgTtc8W bpSnrg/+rlyicBLMxNHkJOJmPVmEbKXn4D1CX6/dTjC0r5kBOB1zuYNEG 3qp9bYobmFUmdlsPAG4qSXY4hMIUKNlwdswdusqJdqN8v2vln05K5izFt NSoSNZmJiRlsd5kvGgg/TuK7R2alnfcaMuk0bHVP2uRCJFFEsj6wCo/B3 PjDZ1TwSVYA0Gk16TAyM/Vnd6rwcfsYn5JwzVm13gmEL4jnTlI2hwNnpO KYeLtgvD3nEumtzTXZErl69u8v9XpP8YvylhcQQmDMggETC+9HZYUBkoR w==; X-CSE-ConnectionGUID: oCVDOkf0QWepub9BNbTIRw== X-CSE-MsgGUID: xzAvBCrjR5OD2xBxiBWCTw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4824834" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4824834" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 12:09:02 -0800 X-CSE-ConnectionGUID: 7d3Cy1JPS5OuVbZoqD3k8A== X-CSE-MsgGUID: lZQ54LaJTu2F85gb6NxqlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13402889" Received: from jf5300-15a101203tc.jf.intel.com (HELO meta-crater2c.jf.intel.com) ([10.54.113.49]) by orviesa009.jf.intel.com with ESMTP; 30 Nov 2026 12:09:03 -0800 From: Daniel Byrne To: Dave Jiang Cc: Daniel Byrne , Vinod Koul , Fenghua Yu , Vinicius Costa Gomes , Jonathan Corbet , Ludovic Desroches , dmaengine@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] dmaengine: idxd: generation-number transaction status Date: Mon, 30 Nov 2026 12:02:48 -0800 Message-ID: <20261130200248.1903384-1-daniel1.byrne@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <20261019150632.4026424-3-daniel1.byrne@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_120904_960970_902943C7 X-CRM114-Status: GOOD ( 21.36 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-8.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, 19 Oct 2026 18:53:11 +0000, Dave Jiang wrote: > LLM suggests possible race: > 1. Recording the count too early. idxd_dma_tx_submit() saves the reset count into desc->epoch (dma.c:321) before calling idxd_submit_desc(). Until __idxd_submit_desc() checks idxd->state (submit.c:230) and takes wq_active, the submitter holds no lock and no reference. > > 2. The halt doesn't wait for this submitter. idxd_halt() (irq.c:509-529) sets HALTED and increments reset_epoch, then calls idxd_wqs_halt_flush(idxd, true). That flush's idxd_wq_kill() waits only for submitters holding wq_active, so it never waits on ours. It then revives wq_active and queues idxd_device_reinit(). > > 3. Recovery finishes. idxd_device_reinit() (irq.c:32-70) resets, configures and enables the device, which sets ENABLED (device.c:810). It then re-enables the queue (device.c:217). Nothing in this path touches the descriptors or desc->epoch. > > 4. The descriptor runs on the new device. The submitter resumes and passes both state checks and the tryget. It then posts the descriptor, which still carries the old count, and the reset device runs it. > > 5. The poll frees it early. The first poll after the post sees status 0, and the descriptor matches the cookie. The desc->epoch != reset_epoch branch (dma.c:264-267) then calls idxd_dma_complete_txd(..., true, ...), which frees the slot. It returns DMA_ERROR while the copy is still running. > > 6. The late write corrupts the next user. __get_desc() clears the completion record when the slot is reused (submit.c:19). The device then writes its record to the same dener can see a result for a transfer that hasn't run. > > LLM suggested fix: > Move the reset-count read (desc->epoch) out of idxd_dma_tx_submit() and into __idxd_submit_desc(), after the submitter holds wq_active and before the second state check. On the halt side, order the state store before the count store. > > --- a/drivers/dma/idxd/dma.c > +++ b/drivers/dma/idxd/dma.c > @@ static dma_cookie_t idxd_dma_tx_submit(struct dma_async_tx_descriptor *tx) > tx->cookie = cookie; > - desc->epoch = READ_ONCE(wq->idxd->reset_epoch); > > rc = idxd_submit_desc(wq, desc); > --- a/drivers/dma/idxd/submit.c > +++ b/drivers/dma/idxd/submit.c > @@ static int __idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc, > smp_rmb(); > + /* > + * Stamp under wq_active: a halt that bumps the epoch after this > + * read waits in idxd_wq_kill() for the reference, so an old stamp > + * proves the post came before that halt's flush. A halt stores its > + * state before its bump, so a bumped stamp fails the check below. > + */ > + desc->epoch = READ_ONCE(idxd->reset_epoch); > + smp_rmb(); > if (idxd->state != IDXD_DEV_ENABLED) { > percpu_ref_put(&wq->wq_active); > return -EIO; > } > --- a/drivers/dma/idxd/irq.c > +++ b/drivers/dma/idxd/irq.c > @@ static irqreturn_t idxd_halt(struct idxd_device *idxd) > if (gensts.state == IDXD_DEVICE_STATE_HALT) { > idxd->state = IDXD_DEV_HALTED; > + /* Pairs with the smp_rmb() after the submit's epoch stamp. */ > + smp_wmb(); > /* > * Every descriptor submitted before this point is dead: the Yes, that race is real in v1. For v2, we use suggested flow: the epoch is stamped in __idxd_submit_desc() after the wq_active try get and before the queue-state gate, and idxd_halt() stores the state before it bumps the epoch, with the smp_wmb()/smp_rmb() pair between them. idxd_device_fail() bumps the epoch the same way. A halt that bumps after the stamp waits in idxd_wq_kill() for the reference, so a descriptor cannot post to a reset device with an old stamp, and a stamp taken after the bump fails the gate. I tested with KCSAN (default and STRICT with WEAK_MEMORY), submitters running while a simulated halt bumps the epoch. No report on the stamp/bump pair and every parked submitter returned. Thanks, Daniel