From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 552B873463 for ; Mon, 30 Mar 2026 20:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774903668; cv=none; b=WVhI625kJV8WkGa/T6/kq5mcxtBViZkWO1RjCzehwFSgrA/4GDiESBeq3sr1jZkw+QJAKf5r1vZApu2erH9Ea8IMOnOUamZoy7WFG9+BU1OO+c+BxFbJy1XM8WZP38q9FzfTQgkUnMxPTccc1MSsIE5TMlwaZcsKbq1XXJZGCgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774903668; c=relaxed/simple; bh=Hou+me8HfuI76FTptX1DixhTUGk7MTiUgtviBJ4fq+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bW38A1IIzLGPXjr/F2/w8ScC5ykHbCquJQvF/3HuZveWsduJzuA3/qwkHPgVShKMJ8ybeQJbGGKyLJGj+wzSsAAZVKdGf83TkFR/NSn0Yy+nViOZzDRkjh2dyLl/6n1CWPZJ9fsCKArpJatzgT+laf0BfDhK7X/jGYmwD5kTIjs= 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=KqOb3UeO; arc=none smtp.client-ip=209.85.128.44 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="KqOb3UeO" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4852ef20fe8so8175e9.1 for ; Mon, 30 Mar 2026 13:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774903666; x=1775508466; 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=FIHNqZQXtp9wsLCa78FxciShL8BdTRPShRaGpgvoypA=; b=KqOb3UeOCjOIao0hnaGq/s90zKCDxbaKgCcfaaA+IQnryvpG0JxdmQN9Tba0pRWOs4 h+rhcsDmGNeIe3F0NTlgJKGw6Am3nm6KgdcbqhYSbkdA2eoOLg5fcgQJx7lLqOOX5Nav GZqFixLUsacktW/ndxOt1QrdUCvkyc8PD3I4MPELY7fa/MuC7J8lJwTMxPg76q1cOyB+ vhsVTL1E5Q3ANtWMAwOKDptxmW5AIshrz82n9yz+mwcVLTo6n/bVqtNx+i40Iui8lOA7 qKHkeXp7JJ394Tvym5pcZncobYvB96n2SaQwRbM6d477BtAbthQOe8eBpxlLmEjWoy8T kL7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774903666; x=1775508466; 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=FIHNqZQXtp9wsLCa78FxciShL8BdTRPShRaGpgvoypA=; b=d0YXGqLYlFxWEGoNf2QfgKs0xApxVkKx0lkq9PERddBpOWQgkBSDNljNmi8hGlg5Z5 1QubKxhikeDkVtj5hnB4NIMTqPrujy5+oOc5z5PzSPlnSQjvTmXwOKOvO6bQ18zJD+9s Cy/ZjH0O7381NtLp4C371c4XUVM3rWl07LO8183+MQ6xC4PKtifhLwg8J3i2dg+rg9uV 3NyjPEgzL4WZHU/p5Tx+2/+iiW5zJ1xjnyIAwVkh24KFDlNN4bMBzdf9UzRmqAXIfJDH 4OHYtbHsQsXsRHaJ//oMMtE7AkYFVmAdTIMTGDOXrofw0N1wuAmSO9PDZGHaPIFTUypr Qd+w== X-Forwarded-Encrypted: i=1; AJvYcCW+mWsm9mEUakf74IuvVJHlz1GE17ltB7A36qYIAips3aa/V17J+9CS3HyHTR+CUHNEscx8JtrMnF8vgjY=@vger.kernel.org X-Gm-Message-State: AOJu0YxaxP0Yls7yQbmRdnbwo3n+QQCsQxDL1MOulN0wZaTvS2lBJsXd pbXBIhthEdtxsMdCoh6tBzrvWLkNXdGCII2tpMHSbssVe7XabzSP14M71JIcdp+lOQ== X-Gm-Gg: ATEYQzykvwIbnXetoaw/vGFAuOB4PsVGGxFgzXQyOCEhFj/csqC4a5nLIDvWHyu9Y2U 5cYAJ+RolR0RVHddqTHRzUQNYoqObpTib4C8uuEcU905s16y2328C4NgCcPI5kmFLCBdiy+UPF3 jxPisdeNiVyYQazK9fFxUvivj/X8roRKX1FuV+f6smW9uVajHJw56B1rrUzklAEJkouMpBYQPe0 zYlXgyGc/XleDjojTCQz1uobnvGY6v1JzM9NoUo5pjDpnH3N73BMaWhIE9jLcnqGhrDi+WRR7SA cOrvkyXf04cwrOnuOgF3nT61I5gwJHJeUpmSd+XploOg6IduQZb3u6JfNZand40FUavob0rpSq9 C6lL7JxvCOlhsE2+ka/QUlRKQIMfzPvsBmU6QLdsNZnf0UWPSmnYdlJWj6i3X7JS0cF86D5pdRS 3iSL6m9rfUkiU8lXTuNRl2ZmbJftAGUye5kFHqW0lWIvYh17bj3LxyMS5B X-Received: by 2002:a05:600c:6dcc:b0:485:b6e4:9808 with SMTP id 5b1f17b1804b1-4887b199a15mr15845e9.1.1774903665327; Mon, 30 Mar 2026 13:47:45 -0700 (PDT) Received: from google.com (8.181.38.34.bc.googleusercontent.com. [34.38.181.8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487351fb38csm224098685e9.4.2026.03.30.13.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 13:47:44 -0700 (PDT) Date: Mon, 30 Mar 2026 20:47:41 +0000 From: Mostafa Saleh To: Jason Gunthorpe Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, robin.murphy@arm.com, m.szyprowski@samsung.com, will@kernel.org, maz@kernel.org, suzuki.poulose@arm.com, catalin.marinas@arm.com, jiri@resnulli.us, aneesh.kumar@kernel.org Subject: Re: [RFC PATCH v2 2/5] dma-mapping: Use the correct phys_to_dma() for DMA_RESTRICTED_POOL Message-ID: References: <20260330145043.1586623-1-smostafa@google.com> <20260330145043.1586623-3-smostafa@google.com> <20260330150903.GB809900@ziepe.ca> 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: <20260330150903.GB809900@ziepe.ca> On Mon, Mar 30, 2026 at 12:09:03PM -0300, Jason Gunthorpe wrote: > On Mon, Mar 30, 2026 at 02:50:40PM +0000, Mostafa Saleh wrote: > > As restricted dma pools are always decrypted, in swiotlb.c it uses > > phys_to_dma_unencrypted() for address conversion. > > > > However, in DMA-direct, calls to phys_to_dma_direct() with > > force_dma_unencrypted() returning false, will fallback to > > phys_to_dma() which is inconsistent for memory allocated from > > restricted dma pools. > > > > Fixes: f4111e39a52a ("swiotlb: Add restricted DMA alloc/free support") > > Signed-off-by: Mostafa Saleh > > --- > > kernel/dma/direct.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > > index 27d804f0473f..1a402bb956d9 100644 > > --- a/kernel/dma/direct.c > > +++ b/kernel/dma/direct.c > > @@ -26,7 +26,7 @@ u64 zone_dma_limit __ro_after_init = DMA_BIT_MASK(24); > > static inline dma_addr_t phys_to_dma_direct(struct device *dev, > > phys_addr_t phys) > > { > > - if (force_dma_unencrypted(dev)) > > + if (force_dma_unencrypted(dev) || is_swiotlb_for_alloc(dev)) > > return phys_to_dma_unencrypted(dev, phys); > > Same remark, I think the force_dma_unencrypted() was a hack to make up > for a flag here. In these lower layers we need to annotate if phys is > encrypted/decrypted and take the proper action universially. > > The force_dma_unencrypted() should only be done way up the call chain > where we decide to get a phys that is decrypted. Once we have a > decrypted phys it should be carried with an annotation throughout all > the other places. Can you please clarify what you mean by annotation in this context? As I believe any tracking in the vmemmap is a big NO. As replied to the first patch I can attempt to implement this approach (by passing a flag around) and see how intrusive it would be. Thanks, Mostafa > > Then this is more like: > > if (flags & FLAG_DECRYPTED) > return phys_to_dma_unencrypted(dev, phys); > > Jason