From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C4232F3C34 for ; Wed, 21 Jan 2026 07:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768980551; cv=none; b=VEOR9yWSUV/OBrdrrHbSt6MXp+qgy3QwP56mo/u/Eo37eK2F2mQLqnKo+FL6n7mewYlACVeTf4c+EqYuXBzxYDgZzEq5BiNIJMXmdmXjjtL2moHmA0X7lzLuPAQeRx5TDnAIsPB3XuuJm+OeqeyedYOovETUY9oUQ+uxF7wKRDc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768980551; c=relaxed/simple; bh=sZC9/40ABxh7RwSmrB46lUvB8P+jEp+Zte5qlGC9bCA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b2+cjZOw0bYyjsZrE9312kIdDqP5t9G6BpHVyXTMqCqxgL4NuFZcOkPvhczsb8blyj0Zw0AG5cIbq2tXc2ebbkN8WMBd/Y31rJ7VjuxEzNcVBDdD8oOlt3C+rGLLJ2uWJUtjr/u0PAq+ER1SQ+HKOmgNXry0AKVTGq/vcgQj6J4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YVBT6Bjd; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YVBT6Bjd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1768980547; x=1800516547; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=sZC9/40ABxh7RwSmrB46lUvB8P+jEp+Zte5qlGC9bCA=; b=YVBT6BjdGNvthqP0HoKyWwhgGnYrEBvHeDc66a64ODC1NczPDolMWbSv wlMY14JI2cWd5hWzJi2E5NIFvOP3brdntwMii/QS/1DKD21A+qGLScI52 21TtbT4munOydXe+N8/KLQjE6hF2FLMd5gwlxZ+go4uIUPFWeUfl3umGH virHz0l2sF6QxPz39cqHAiADdN8Xcp/OwmL8obBgsGQtYtv97zIpw/amJ /EIPSm0nBSdzOoFRj4hC9gGpgE2zkBNsvjnvMn98QD8nDUh/Llzn6J/iN EiXsXI9gQDC9lYye2a/eOmx63hM/9OB0qtQ9ln9pgsPoIwVA44+H07RyS A==; X-CSE-ConnectionGUID: DopZhcoMSCSJO5BoTkqiKw== X-CSE-MsgGUID: T9/gUD4rSkCRGtQXsOARXg== X-IronPort-AV: E=McAfee;i="6800,10657,11677"; a="70256544" X-IronPort-AV: E=Sophos;i="6.21,242,1763452800"; d="scan'208";a="70256544" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2026 23:29:03 -0800 X-CSE-ConnectionGUID: ydZNN5eMRzy5an+ZTsmi2Q== X-CSE-MsgGUID: 7RtRJt/FSuGbzTdpQP39VQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,242,1763452800"; d="scan'208";a="206289920" Received: from allen-sbox.sh.intel.com (HELO [10.239.159.30]) ([10.239.159.30]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2026 23:29:01 -0800 Message-ID: Date: Wed, 21 Jan 2026 15:28:55 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/3] iommu/vt-d: Clear Present bit before tearing down context entry To: "Tian, Kevin" , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe Cc: Dmytro Maluka , Samiullah Khawaja , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" References: <20260120061816.2132558-1-baolu.lu@linux.intel.com> <20260120061816.2132558-3-baolu.lu@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/21/26 14:23, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Tuesday, January 20, 2026 2:18 PM >> >> When tearing down a context entry, the current implementation zeros the >> entire 128-bit entry using multiple 64-bit writes. This creates a window >> where the hardware can fetch a "torn" entry — where some fields are >> already zeroed while the 'Present' bit is still set — leading to >> unpredictable behavior or spurious faults. >> >> While x86 provides strong write ordering, the compiler may reorder writes >> to the two 64-bit halves of the context entry. Even without compiler >> reordering, the hardware fetch is not guaranteed to be atomic with >> respect to multiple CPU writes. >> >> Align with the "Guidance to Software for Invalidations" in the VT-d spec >> (Section 6.5.3.3) by implementing the recommended ownership handshake: >> >> 1. Clear only the 'Present' (P) bit of the context entry first to >> signal the transition of ownership from hardware to software. >> 2. Use dma_wmb() to ensure the cleared bit is visible to the IOMMU. >> 3. Perform the required cache and context-cache invalidation to ensure >> hardware no longer has cached references to the entry. >> 4. Fully zero out the entry only after the invalidation is complete. >> >> Also, add a dma_wmb() to context_set_present() to ensure the entry >> is fully initialized before the 'Present' bit becomes visible. >> >> Fixes: ba39592764ed2 ("Intel IOMMU: Intel IOMMU driver") >> Reported-by: Dmytro Maluka >> Closes: https://lore.kernel.org/all/aTG7gc7I5wExai3S@google.com/ >> Signed-off-by: Lu Baolu > > Reviewed-by: Kevin Tian > > btw there is a context_clear_entry() for copied context entry in > device_pasid_table_setup(), but this patch doesn't touch that > path. It seems to assume that no in-flight DMA will exist at that > point: > > if (context_copied(iommu, bus, devfn)) { > context_clear_entry(context); > ... > /* > * At this point, the device is supposed to finish reset at > * its driver probe stage, so no in-flight DMA will exist, > * and we don't need to worry anymore hereafter. > */ > clear_context_copied(iommu, bus, devfn); > > Is that guaranteed by all devices? from kdump feature p.o.v. if > that assumption is broken it just means potential DMA errors > in this transition window. But regarding to the issue which this > patch tries to fix, in-fly DMAs may lead to undesired behaviors > including memory corruption etc. > > So, should it be fixed too? This path is triggered when the device driver has probed the device (ensuring it has been reset) and then calls the kernel DMA API for the first time. At this stage, there should be no in-flight DMAs. We can apply the same logic here to improve code readability, but this is not a bug that requires a fix. Or not? Thanks, baolu