From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 28E053F210E for ; Fri, 8 May 2026 15:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778253544; cv=none; b=deHN/2l1SxiEV62QvGp9LxpQXZtxCIXr4nzTqtb3yh/GihY1Img3qNhFIPtTlkuTbeCXZic8TOSH1cTsXI2Gdh4MhhQq/78GVEP3XKU04aEKE8bIHbCnv/xnsUFE5lZyu83vbjKYTjvm+ye7O6X8Ze8OhYJf+ih+w8vVKRhGuLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778253544; c=relaxed/simple; bh=LON1iquaiFHI7bg0xydIs2bUhPqLAJ5Vqe7yyQhb+/o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p6OGpxArFD7RChOd5456HVHH0P39gEAxxHbT6JBftKZaic6FPrRPKzxAgOUyk1O4KQkjdtyhKW9d+XTIlcdcj8QI8RSBB5z3Nua4KcJvsxRn46HwzLm33rB3mwopSY9OFD5FAAL5yseEa/yYlikmpJbIpVkYHEhvv7L5CaIRfgk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=cNyJlpsL; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cNyJlpsL" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-8eb5ad01402so209870985a.2 for ; Fri, 08 May 2026 08:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1778253539; x=1778858339; 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=YTG/PpueXCgEiXRYtBi+EBDI0e9SJXMCHTk8qLEhxGk=; b=cNyJlpsLEJYG+3wflLwE56Pa4MvWl89pUrP95uuOd/W/nsAuMx8Zpavwnkgv/OtCrr 6ZmsDUQhLjVR2NEelyVcqnVbhPOtAoJ6EgZ9Aan9X+GUwN+epqU22yzKH27RY/WEUuAD pMze8VWpDcPbrPXAspveibzLCTSPa4EVOWfd2htHgpg038cuuQqIykyYHIYXPKVLiMjb dszAWv6OaJX9BnUBHP5m3RqXAXSF1sK3AiFvua6T2gXPrp+/dTeUaF359qOQBwW2JPaw W4pEXRQR/UbPum/BNqzGG9X884qPBS7hiddKejRxU+9misqOIeGNdNnOWK2IpJhxrFM0 4CUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778253539; x=1778858339; 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=YTG/PpueXCgEiXRYtBi+EBDI0e9SJXMCHTk8qLEhxGk=; b=Im+xm3AXf7FL1k26Ul7yQq7deUdl0bwScN673IcmX855IO65qYetZGEM4dD6hguV38 nH7Hwt1Fem/snPjC37/BH19xIRKHwuYgHZ0TYyHuzZHqwvXJkDrkm8C1xVypSfFeotfK 1kyzUrXrBGjLBazOVp4APGeWCxoB6GTqUdolrRvXTK7ZQ5+vM7rErNpiN/V/OctKu1sO 6S9on+PF2q9Dfvhj/ZcC6re/UT2wZxUkudumycGP6vcfCeA7gKWN6IdwTA07k7yKvb1k +zhd6nNsUVGLoxB4APK9jdmooIeelVpBPWZOwC8BxNNirDIfmVhfyPg1NdtnCiuamdo2 RUfA== X-Forwarded-Encrypted: i=1; AFNElJ9wVxVGqWNuRhjZJXeHfI847WPbXaitFRIfbUOsTFqKizfqguIqxbEPTr3xiLeCJVPWmY1kx3xZUG/WBxY=@vger.kernel.org X-Gm-Message-State: AOJu0YxytLE+I6D/dF7oJLkC6s5UKI4vRra25cO+ZHf0T4npjyqwMG69 y2ahgQRS/clozjpKc3meqLMhGVoXXT9AodkGrUXySAmnELxBIOohghh9X10ZZtR6QT8= X-Gm-Gg: AeBDiev/qQEB46Vlo9SwbUaSu3S41O+LWis556KZmxxqRdI60E8Qx763WJjpQdSExKg rSGUa8PnOEfBBSllvWebayRsKmluO8ReqkOMPbZityIYlj+ngylmT0lf32Te/qfSjv/wFrede1p GYuKvMD4Z1AL7+8eptg7alhQ8Pxz3TAQ8ZnbjQrnhLMbX87Wdn2KeVqA0HGJG48sPaS0QL65Xtb vT78cpntnBrGAIFUrryLMARMN1dYy6i6hPnvTsXCLzgocsN7nTo5u4/4o5+8oKS34VVnU/CXdRl zHniqsv7Huy6Fd8hI6x1gwMMoNRy+EvHw2CPsyG9161JcI4HkN0j/Km6P3uZcKu72Dpmlilg6NJ fbLSCoDGwccl/vGFQVDW90n8cPChXY8oTzXfRsoEdWE0eR8FMutn/zEaPsgC+gdHtMbhNunUCNm VfwrYqJifu/7E5p62H54INmY/nI2em6IE2Y8cVf5RYDCnT0kfCCqgI6AQyKETHTzWAPfjV2BO9l I2uiA== X-Received: by 2002:a05:620a:7017:b0:8cf:d6f8:599f with SMTP id af79cd13be357-904d6fcd75bmr1893999785a.57.1778253539091; Fri, 08 May 2026 08:18:59 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8fc2c91dd48sm2251446985a.38.2026.05.08.08.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 08:18:58 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wLMyf-00000000Afi-40Nx; Fri, 08 May 2026 12:18:57 -0300 Date: Fri, 8 May 2026 12:18:57 -0300 From: Jason Gunthorpe To: Robin Murphy Cc: Jianpeng Chang , m.szyprowski@samsung.com, leon@kernel.org, kbusch@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] dma-mapping: remove bogus test for pfn_valid from dma_map_resource Message-ID: <20260508151857.GB9285@ziepe.ca> References: <20260507032120.4072283-1-jianpeng.chang.cn@windriver.com> <2dcc29d6-a4a9-4fdf-861d-312941ab0f07@arm.com> <89094011-fe78-40f9-9695-d50ee19167c5@windriver.com> <20260508113100.GA9285@ziepe.ca> <662fdf07-6475-4807-94b0-54b3b439ae1c@arm.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: <662fdf07-6475-4807-94b0-54b3b439ae1c@arm.com> On Fri, May 08, 2026 at 01:16:25PM +0100, Robin Murphy wrote: > On 2026-05-08 12:31 pm, Jason Gunthorpe wrote: > > On Fri, May 08, 2026 at 06:01:01PM +0800, Jianpeng Chang wrote: > > > > As I said last time, I think pfn_valid() && !PageReserved(pfn_to_page()) > > > > would be enough for what we want here, although now it's strictly under > > > > CONFIG_DMA_API_DEBUG, perhaps the overhead of memblock_is_map_memory() > > > > might be less of an issue. Either way though, now that it's all > > > > channelled through the single dma_map_phys() path, it would probably > > > > make sense to consolidate any MMIO sanity-checking into > > > > dma_debug_map_phys() anyway :/ > > > > > Thanks for the suggestion. Move the check into debug_dma_map_phys() is > > > indeed better, and I will replace pfn_valid() with pfn_valid() && > > > !PageReserved() as you suggested. > > > > I'm not sure that is right. IIRC pfn_valid() is true for ZONE_DEVICE > > P2P pages that are used with map_phys but never with map_resource. > > > > PageReserved isn't enough to fix it. > > It fixes the false-positive on non-reserved pages, which is the important > thing. Yes, we'll get false-negatives on reserved ZONE_DEVICE pages and > similar, but that's still an improvement over getting false-negatives on > _everything_ by not checking at all. Realistically, dma-debug can never be > exhaustive and 100% accurate, but there's still value in catching as much > obvious misuse as is straightforward to do. I'm saying I think the new expression still has a false positive for the common case of map_phys with ZONE_DEVICE P2P, and I don't want to see debugging logging for normal as-designed scenarios in map_phys. So we either need to narrow the expression further somehow, or leave it in map_resource which has fewer users and doesn't accept ZONE_DEVICE anyhow. Jason