From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796069343; b=ZbIJ7Q3jAyDP2t9CngFUelfGATNIyE5WCoUvrEjcji3Eqwt15k/iVZhOC8G8eXMEYQ0C tLVp0jDvm5ZEFE4EtEQ/+tdkNcX03qzEun1MZ3MIS/VV8DDRX+IUVkSp+8nr8wMeMosLt 1sj8DNpgk6DGIaHr2kqco39xNIBEVhaf8XmlyND9BZ9c6kaGnEB+3G+XKupFEnX/qMnIc qF1keEPCj8CMHXqvfz6kaJBSxKB8VTYxun5579pztZgc7+y4cait5OHzjwo/9Nf5xYflE cezFDtW/YBdbcsquvFD7tndfatVgg0QALuH8v5HzIR7wLQDAZEnv8JJlDMZ6qtlXNRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796069343; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=l/+aYUmYk3Q1W9u+aFdHVWHhyKh/l+YpnvDb4V487bo=; b=eo27R0Vv/ht+fONeBJJ/zFUwLGcR5QUsVQiOFRQRvoeJrXooPzqu5eEBPkjvtj0MYm9H 6cr6l9uwojDqnPnwrZg8M2p5jYhovoypU9xyH28npnRClB1Kz8z9fbBGw1R7bLK/j2lwS ydidDzIwd3Bi1ioprUAwcWEe5E2A0+rw63BNFwy+eWmdpL3QG0PaNlBvSdX3wgOGjw/d3 CGnxGYWns8REqDHWGNVJEA458HPnfFxU6A9/rGYjI17gBxYU+iHvZWqi6+z4gARR0Uxvy bYiFA7M9/N6pRO2HHfwVKO1EpVFrGw2qLm0Okbyrp5XLNNY5nElgY7wthvIbt4kf+4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=NU+8Fqx+; arc=none smtp.remote-ip=198.175.65.12 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 115C7606A325; Mon, 30 Nov 2026 20:09:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 115C7606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=NU+8Fqx+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796069343; x=1827605343; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l/+aYUmYk3Q1W9u+aFdHVWHhyKh/l+YpnvDb4V487bo=; b=NU+8Fqx+64PprMSy4W9fXUEiWZ7PzVcTTTLzrJVX517fabf2RT9nSPRu eV/anulMaQT56n5X0+dSwKXnF3QD9M6+qCe/A20dlDry8ZpfEf6bazTEn pqDhbHhGwjogdbOkt7yYtY+hzbnC4Idjr216CXvlquaNeMMvvlEcCgjQO 8pp0Fe1hTJBljoD2+egUyAXTu3dJhijrfeaTqAwKCeOD8Gxwix5hRvdw0 IG79pNM1SYgg5aN2Xn+6ZDx509oSkUEgXD+V3djQYwnzUk0QExPhsEvWB VohAyLUvwlAannWjibz2oBydWvQD/Kah3i6JRNvXea+g6xNsoihrst9RU A==; X-CSE-ConnectionGUID: D4qO5VneQqe6vmxaM0PqVg== X-CSE-MsgGUID: vNJYpfAIR8mrinyUwCaZMw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4824831" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4824831" 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-Mailing-List: linux-kernel@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 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