From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC1F838D3FB for ; Tue, 2 Jun 2026 04:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780372913; cv=none; b=GNuRSfv/ay+3lO93jotX314VKsybCqGzlSAfg/a2wdOm/iyfOqFCxoWSzscv9pfiecMZOrakhBmGQjmEyLvMUgj7vcmkojLJK2M0i+72p99hwiCio8vnC2+W6G6aOJSjlo9q2GR6vT9RrrPLOTKCjqupTQcq2qtTCJoIkE+/+qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780372913; c=relaxed/simple; bh=y1Z50JCC0kbirV2odlz6oDYRSM/Z8bPShu5Du2Sxb/k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gs6k1otN4yRNxLm04iQCMyXLAXzHYlDZu183mnm7XYoZ/n6wF3tcHv46OQawOb8yE1AAwATQva/TbJq5M3wR5Bfy90meUSijzsOM6m8YnareRnqY0vzavmLa5SJDXTgge2ZiZaizBbywNOKDvAl78cCjPJsaclfXwBKXGE965/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KbpSh11+; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KbpSh11+" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2bf2d865383so1135ad.1 for ; Mon, 01 Jun 2026 21:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780372911; x=1780977711; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8zzoO5ZfBSeXc58zl83ql5q86WDqT67vRVNbMImi2Ms=; b=KbpSh11+Qh0mvXRStRSOSIbCA/x9T3qtLeb00c5L0+NLlH7sQzFNgM46dfCvplBFHT 06Nbx7em5d+AbC3YRFIn9B/v1QpY/0o0Va6d26kOvs32POzJNEeiXOlp7ggJk+Kl3Ep6 76MQiOGNRxbTZGbVsyy+bNYw7E10TnGh5+YT0Zn4TUp5Q32ZzwfhP0DzJDwbcRe37OCN 3sfXlf/YUILkCDuvV+AWAsTZOAFJkzq1AFx32ot7iJlL/ZG48QKQ9IY1JMTUEtYHsowl yP4tpPX6tLnQmxsQ3l7BVa3DJGgoh96LmJEO8rPQxFvOi5+I78iSSX4oWQA9SLhjA/Dy i4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780372911; x=1780977711; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8zzoO5ZfBSeXc58zl83ql5q86WDqT67vRVNbMImi2Ms=; b=HG1o/tgdkg05xpet+T+39TbGrD3wrQ8+R36QmAU/UQrN9N8HsE4dXEYPr9/B81ji+Y sEvLDVAPygHRBAlYap5EsKSAfkb5OeJEff+dPe/UnryyET2nqz4/dNky7ZE77ReCBV8s HF7cuHLkZ19eIM57RE6GXjk8PlSNAEvJ0QeHqCFP7Uf4zfKqJ7T3zVDzCVqFUtjDqfM6 h6zTsh1bx92oXyUp6ErTqUHdx1/ILNGU/6sRKQt0yrozMCW0jZhQtmCxLKMo2P/Q1vAi lpkf4su329S5gZKNmik9hYgi+AgYIjiku/8gKR4fQx1Xkw3USS32YeYg3SHxVL425tzJ rZHg== X-Forwarded-Encrypted: i=1; AFNElJ+nLTPXq6+qtSpwzmku3EzgE3pynbKr8SjYN6qS8wWIHLn3KvguErtDUPgN+O8P5JegvbPnOjDmn/KJy9I=@vger.kernel.org X-Gm-Message-State: AOJu0YyPdMtzFonu8XCp301CkbyySC5OQAw9vtLGibouNXLfPZcgV/b8 UAxir+jcscsWpgnH9slJn9cLYCvknH1juVr80Xv7WD+ftIVcjtYdIjz9RkxMIcqRUw== X-Gm-Gg: Acq92OGF22A0+ST8yrrLIdloEz0M2NnMulgywY9ZuPUnOYyVo4nYDhsxMvJmzkCGoWS okpX3kDbZ5I+6YLlsx4zh5RSUsIWD+wthnaJxzf8yQAPM0U2v1mmre9LbwycEmAZ2HouVPEhYro WVwflFEegoLivlkYHcrNyDAHY+2Ec2kxQHKUGYf6v/cCOtPzpFKDNZzfJPueWfdqnnhQrT8PU/R LcKVwscEFv22AIfqgNX4Zt5VGTWPhyC480c4ZV/XAsod3niqn6VSwNAaoOGz+cNCz/jCZT4j6au 9ZxWUyE+Rf0nQKm62l66RLCtHTASOuL6bOMbvwSWMNfW2BkhcbOgw77JPG/bTWcisTiU4Cvmr21 ZcUZY/31ZCcJuXOmc5XvQXmyIDkaU3M99y5xBJZLhiS47ylXOeDtMVGudC42TqnDOml83MUYM7a 9pcDNBaq1OGM4nLZA1IAN8FpwsiYg6nVoEoaOAt22pUWHg7UbnVUC+TDqZhHHmNESj8SaUfi4= X-Received: by 2002:a17:903:2288:b0:2bd:3c1b:3073 with SMTP id d9443c01a7336-2c10eb2b907mr1518505ad.16.1780372910379; Mon, 01 Jun 2026 21:01:50 -0700 (PDT) Received: from google.com (199.255.142.34.bc.googleusercontent.com. [34.142.255.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bf23915adcsm115280955ad.0.2026.06.01.21.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 21:01:49 -0700 (PDT) Date: Tue, 2 Jun 2026 04:01:43 +0000 From: Pranjal Shrivastava To: Jason Gunthorpe Cc: iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel , Suravee Suthikulpanit , Vasant Hegde , Ankit Soni , Bjorn Helgaas , Samiullah Khawaja , sashiko-bot@kernel.org Subject: Re: [PATCH 2/6] iommu/amd: Clear DTE with update_dte256 in iommu_ignore_device() Message-ID: References: <20260601134204.2150602-1-praan@google.com> <20260601134204.2150602-3-praan@google.com> <20260601141956.GQ3195266@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260601141956.GQ3195266@nvidia.com> On Mon, Jun 01, 2026 at 11:19:56AM -0300, Jason Gunthorpe wrote: > On Mon, Jun 01, 2026 at 01:42:00PM +0000, Pranjal Shrivastava wrote: > > The iommu_ignore_device() function currently uses memset() to clear > > the Device Table Entry (DTE), which risks torn writes because the > > hardware reads DTEs as atomic 256-bit qwords. Fix this by using > > update_dte256() to perform a hardware-safe atomic clear when a live > > dev_data entry is available. > > > > Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table") > > Reported-by: sashiko-bot@kernel.org > > Closes: https://lore.kernel.org/all/20260529153216.2AD1E1F00899@smtp.kernel.org/ > > Signed-off-by: Pranjal Shrivastava > > --- > > drivers/iommu/amd/iommu.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > > index a94de66a885e..9b5861e241d7 100644 > > --- a/drivers/iommu/amd/iommu.c > > +++ b/drivers/iommu/amd/iommu.c > > @@ -750,7 +750,16 @@ static void iommu_ignore_device(struct amd_iommu *iommu, struct device *dev) > > setup_aliases(iommu, dev); > > > > pci_seg->rlookup_table[devid] = NULL; > > - memset(&dev_table[devid], 0, sizeof(struct dev_table_entry)); > > + > > + /* Clear DTE if we have a live entry */ > > + if (dev_data) { > > + struct dev_table_entry new = {}; > > + > > + amd_iommu_make_clear_dte(dev_data, &new); > > + update_dte256(iommu, dev_data, &new); > > + } else { > > + memset(&dev_table[devid], 0, sizeof(struct dev_table_entry)); > > + } > > This seems a little weird, an ignored device shouldn't have a dev_data > really, or it will soon be freed. > > I think you are better to replace the memset with a dedicated function > > /* Cannot not be used on a probe'd device with a live dev_data */ > disable_dte(..) > { > struct dev_table_entry new = {}; > > write_dte_lower128(ptr, new); > write_dte_upper128(ptr, new); > } > > And then this new ordering breaks the clone_aliases flow, it was > supposed to copy the 0 from the current DTE to the aliases.. Ack.. I'll fix it. Thanks, Praan