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 0416C3254B3 for ; Fri, 8 May 2026 17:36:32 +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=1778261794; cv=none; b=JviCUKbFhj22CBGqP4w/7LHw+weMzgBkAI4ggJBXTqYujBepZGVYxDjtDzIDYAz67qUjZlCjJi+DkVVGs7DdxWI2Md8qpSKxaJsm5rMJs//PafAy+bX7RuFxWAmAtRJJ6mGLWLhzkxrxKAAqq1fV/TIbO1l939yDTXallUn7HkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778261794; c=relaxed/simple; bh=OU1gxYIqGS+hUlkKXFu7H/zFbRvTyfjfeFJIkBy9t/M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JMSA1pqY2fi5TUtWHKBtDU+XZ7aykP6qY5Co+OZeNWK8ujANf6m0KJ+49va2U8yiYnEkcG1wX4vKps28AnJsRRe6L5ZHIKBHWNm0qUpBx0t8v3iJALwajN/d5bDHlkt9muwUCfmagL50q0Hx/35pb0qsOHbM1vf8Whj0+BnIN5g= 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=jJT2dfwz; 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="jJT2dfwz" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-8f231f3b130so171946385a.3 for ; Fri, 08 May 2026 10:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1778261792; x=1778866592; 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=uxmQhUJsbyd70+Vusdx4W/KBVOYgLDyj/k4cRH8CB0E=; b=jJT2dfwzzmnNHr8nKif7tHrlY992Qyyjjx/BeI1636SbSC7Dmq98dqN9YqP4NT6CuM d+/1U8Se4VCiiRKLSy/Rgly1biEqqgF+acK9k6ZIzkY675dEhjGr435VxhM4I7Z6meZ2 4dCe5FWjntMLAkKIguKU/wwQ7NkIr+Xdmpmve2Ub2cVqc47nxNLQxlqTro5ftE0P4/G7 q5Hfex3kYgb6FaPEZuEVOwZECF0oUINJyuiJiNjliC2URqtt67Jdtvy/p+j0CQsjLj7B n3i9yGU1YeGwUfOUHHIatxYoOnsyrnFRoumIyL1Sw2ca1Vv2s4kKlHIVpefBamB8y5CZ uksw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778261792; x=1778866592; 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=uxmQhUJsbyd70+Vusdx4W/KBVOYgLDyj/k4cRH8CB0E=; b=IiEdmBtHB25ci0pGNuYEYX/Xqli/VjiHMuIkovYUYK6MvEdhib7BvlsaGCFSjgBkQP uB6ovVuAIjShfqRfHG1hMLhgtPM7S0OguwGCPH3hSWSFrC2k/pIsrQNe5XHcMbgXNXen BuojsUIJRKalObVQi+G5LuqAYkxXKPVLsZ3cerr+ZfIde9dQ7pK/J3lvpitN2buqF43j blCqjcN6qjjHEX5Mle4lNZPbJBlZejxtAT6LKWIus2Kqom/MTi/LjWy4/CgNeTu/qpFO mk/0ud0x8zli4PouEk2yEvsK1UloRDtKjgYrXqp4za3lUzDUKdKh5HYorFVPxy2xHxZY zERA== X-Forwarded-Encrypted: i=1; AFNElJ+qkiSwFiH3J0QE3VfRLOqN3AvT4rV7H8UWLgIH3OoSDHI9s+9uAWXTs1vSSTB7JgMKwMzYv3aRVu7hmaY=@vger.kernel.org X-Gm-Message-State: AOJu0YyEzgbTytggvSHQa8FW85cfmJCwGNdlGGY5Yk08QaAYGiFujoLZ 0VVtO2EgYPt91kBb0XS6GlWY9dEdgq/YEQSGbH6o4Kv6iwyNC0uC2PiH+evco43L8PU= X-Gm-Gg: AeBDievwjtB3ASVoORL4aWDUJPYoIp1JzuxZzs8ViOjlpPyv7nOzl0FAjDJILfldLXd 3OjV1O4RqGmugbhS/w6+O9QF+vh4f7jptQvdcChDcJuRsA8+3mt3fMBjMAoZ2P0sF72MmQ/Ud1P ZWywCNGhrwLtcZ8eRPJkNXheBr638BM6rcG3Bf7RkR2eDJbjYP6NzPcfkknGhdb6qshWk8z0qGb inOAykUGZ0ESLjweh8DJnCZD0xUVDAOuUB4c07ydhfE5pw6ZkIjWCVNOPAtVjRzxI5OpOZUfFDm tnSZMg9o5m6C1yWyBPpF8VJQjV2L1Z7eXJHKFvkQC8Hz0z4EtVV6NkoFJvEHjp6R4B8wkSBzjZr CalJGDp++zbO9SLmq6pju32Kwx6Vypg2FrPlYKH32Scc2SgvBAhj71Mrav7qenvZz9pHw0jPhsK o9x6f14OS0pXTVXUP20NZznzAYymwfr46TWSwC/6AL4WrG/23nRXg3OEWV3bseDOhgX4WZHK2qC M/rYQ== X-Received: by 2002:a05:620a:179e:b0:8cf:d88d:c46e with SMTP id af79cd13be357-904d69d8ef1mr1994373485a.48.1778261791849; Fri, 08 May 2026 10:36:31 -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-8fc2cd04c68sm2315053685a.46.2026.05.08.10.36.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 10:36:31 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wLP7m-00000000Cx5-2s34; Fri, 08 May 2026 14:36:30 -0300 Date: Fri, 8 May 2026 14:36:30 -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: <20260508173630.GC9285@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> <20260508151857.GB9285@ziepe.ca> <4134fcd9-7d12-4e76-955d-5a679916a0c0@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: <4134fcd9-7d12-4e76-955d-5a679916a0c0@arm.com> On Fri, May 08, 2026 at 05:04:31PM +0100, Robin Murphy wrote: > On 2026-05-08 4:18 pm, Jason Gunthorpe wrote: > > 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. > > But surely anything with a ZONE_DEVICE page is "memory" to the degree that > mapping it with DMA_ATTR_MMIO would be wrong, no? If the ZONE_DEVICE subtype is MEMORY_DEVICE_PCI_P2PDMA it is mapped as MMIO and must be used with DMA_ATTR_MMIO. > However, IIRC ZONE_DEVICE pages _are_ reserved, so still wouldn't > warn whether we'd like it or not. I didn't think that was the case for PCI_P2PDMA, but yes it does look like the reserved flag remains set. > I'm confused as to what you're objecting to... I don't want to see a warning, if it turns out it doesn't then it's fine, but it certainly isn't obvious that it was going to be OK for phys and I explained what we were worried about when we had left this behind in map resource. So this should all be summarized in the commit message moving the check Jason