From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 CE5B3279DAF for ; Tue, 5 Aug 2025 15:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754408171; cv=none; b=F/1/alvEQrCaJ2QJ7LUx2J+Lf128cBxfNdut5l0yBR/xOr6zLYYiwX/5C3Ad2gVenffDhHysFOsckjq5JzEfZ40j7x0q3WYiGGoIFwbntk1zBdpus/Lk0+VmsIkS3SoxHAjJ/CB5h+n4QJASVWQKbmbhwPFcanxEHvy3Pur+0B8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754408171; c=relaxed/simple; bh=wdxaYDaFuQGcdWab2u1vRWh6ubZ0FBcIJSPOHoprdZM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MQM8lxJGzmhwuUHZfBX/3iyopIdriD3LltNOJiCPugxYnVOHkXxU38CeFVy9JzAMju7FlpxRLdFv+6c9D8EmeEvZrHOqKzZtuK7VCjjRW/pDyA1jTfIBy3N+RSiJSJbp8Wte6LvWk0h4VZZ3Ze/sDVQ5YN9nQgQG0OhYOa6J/JI= 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=jKWtRJ5c; arc=none smtp.client-ip=209.85.222.172 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="jKWtRJ5c" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7e182e4171bso470719585a.3 for ; Tue, 05 Aug 2025 08:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1754408168; x=1755012968; darn=lists.linux.dev; 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=N1MKz8dfPt28HzEOpdUPkfZENcnUFV9NfsoMVTYwzbE=; b=jKWtRJ5cNi7qO1iofyQXR4XuKL5GQ45NzFVBOWTsZMwXpcTdNTXmGpNoDhmsrHn3Vi eG2U2Sp5sMYwpwS/v04ouHSF/QiQM4YE/aBu2FI/oNeaZM0XMw9XSqDR/YzsiNeM9zfy wXqfAC1Wo0XE7Q7nbkEKezAUKz81RiYnjxGu9kaQK/tUJymo+80srF6cD3XlCtROyWIb HcJ2hWLoW4bJHWdKC1t1Xm83VeXKejZ0gWSJSLBhqzc6QyYrb30WB79oDdNYhyXunTT9 EnxXy/zPC2If4lS8G/0i0Yg8WdbiB1UYw0Vfly7ZSdBzSEfOXHaxEArPXnwABc0PSUwA SOrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754408168; x=1755012968; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=N1MKz8dfPt28HzEOpdUPkfZENcnUFV9NfsoMVTYwzbE=; b=czkfkz3opjZoxwF7fzbKhx3dmEJxh2BQqvxM1mie08H44WxDBB6vJSLTMnfzLTxx66 //5yAB43JSrWqmtWCc/gCiw/MP8Br3E35JTgH8i2w/SQggL1wsM3IwlH6kmLi9hVpbDi YOrnqIQ7Xb/qK8rkjEru2MCkCb8sys5Nv8IVPFVlgL8XOKC+Mc1jAJHcglQEm80xtnvi xLPjm/OZnqoPTI7CXpDqz+BAa8Qpj1yE7FyYuAiOIc8whcbK1z3vNLYom+RjIDfmrIGI Gj0VVs96JkL1hbP8d47/nMV/7Kmey0K/iMFyqc5qUemkiLEtszdbbp2wBn5vOsSYhkE6 ZH4w== X-Forwarded-Encrypted: i=1; AJvYcCUWZZm7NnXFDULxDNTORp35fnJ9mxHYMtzUvdQ2RZmxs+KMlBCUefqbdfsH8U01pjiOfh7TJQ==@lists.linux.dev X-Gm-Message-State: AOJu0Yw1RoLhIU2zYB2r1PNymBIDz48owy+wqIipTrYIp2bU6i7OKpTY fAvKg0nrdrJbW+PfgtEb8Vrj6neK3nRzbwMUX3zqpxLUhPuWAh4fDeLwMKeOuMhqmJM= X-Gm-Gg: ASbGncssFtcoQ1A9TZ7oMz0z9gsr3rNRq8olXA6DhoKXmi0Ge/x5z+xV4C+UplYGcFY nhfKh92LOT8rnfacmHERNcJhzWlyPAN1XiigauAj6zjhrsT50lABDTekKjhqLlJLu8X6Clwj+oe rX5mfioKp+K+C5EnY8x9ZrCh3F9JLCRyT8zZ9VGy+QgBhATpGwonRVQzNQ0uC3+DmZeEfgtI/vw xy/uTRUO74qtoYsVakbwX8aKX/T24Dfai3zE01d8jslz+0KlcasV4yPrs9IP8A8G5cQ3CI3on6U /qYcmtiKW7TAhiM6dfBhRHVEYViTb6VghheulnDpiCHyWNgAvWsy6DIAojfCw3Fu0dZKpxOd9R/ KMHddwB1JVI7eqpHvaPiJk+jWagbkQ2ZLnNQP3jUT5NjXOjF6Ob/EUz088HhT2b1xquQn+xu1lf oNZuY= X-Google-Smtp-Source: AGHT+IF1+3bX6DUQCrRo5YyM2fp0OCvjM/jusyZc5iy/VSCxNo0II2PGkJ9MrYPb1oYSw7F9hqkESg== X-Received: by 2002:a05:620a:12c6:b0:7e6:8f41:2055 with SMTP id af79cd13be357-7e6962e0c1bmr1733279285a.21.1754408168128; Tue, 05 Aug 2025 08:36:08 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-47-55-120-4.dhcp-dynamic.fibreop.ns.bellaliant.net. [47.55.120.4]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e67f5cd63fsm689744985a.39.2025.08.05.08.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Aug 2025 08:36:07 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1ujJhu-00000001YWx-3rSt; Tue, 05 Aug 2025 12:36:06 -0300 Date: Tue, 5 Aug 2025 12:36:06 -0300 From: Jason Gunthorpe To: Matthew Wilcox Cc: Robin Murphy , Marek Szyprowski , Christoph Hellwig , Leon Romanovsky , Jonathan Corbet , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Joerg Roedel , Will Deacon , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Masami Hiramatsu , Mathieu Desnoyers , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, iommu@lists.linux.dev, virtualization@lists.linux.dev, kasan-dev@googlegroups.com, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 0/8] dma-mapping: migrate to physical address-based API Message-ID: <20250805153606.GR26511@ziepe.ca> References: <35df6f2a-0010-41fe-b490-f52693fe4778@samsung.com> <20250627170213.GL17401@unreal> <20250630133839.GA26981@lst.de> <69b177dc-c149-40d3-bbde-3f6bad0efd0e@samsung.com> <20250803155906.GM26511@ziepe.ca> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Aug 04, 2025 at 04:37:56AM +0100, Matthew Wilcox wrote: > On Sun, Aug 03, 2025 at 12:59:06PM -0300, Jason Gunthorpe wrote: > > Matthew, do you think it makes sense to introduce types to make this > > clearer? We have two kinds of values that a phys_addr_t can store - > > something compatible with kmap_XX_phys(), and something that isn't. > > I was with you up until this point. And then you said "What if we have > a raccoon that isn't a raccoon" and my brain derailed. I though it was clear.. kmap_local_pfn(phys >> PAGE_SHIFT) phys_to_virt(phys) Does not work for all values of phys. It definately illegal for non-cachable MMIO. Agree? There is a subset of phys that is cachable and has struct page that is usable with kmap_local_pfn()/etc phys is always this: > - CPU untranslated. This is the "physical" address. Physical address > 0 is what the CPU sees when it drives zeroes on the memory bus. But that is a pure HW perspective. It doesn't say which of our SW APIs are allowed to use this address. We have callchains in DMA API land that want to do a kmap at the bottom. It would be nice to mark the whole call chain that the phys_addr being passed around is actually required to be kmappable. Because if you pass a non-kmappable MMIO backed phys it will explode in some way on some platforms. > > We clearly have these two different ideas floating around in code, > > page tables, etc. > No. No, we don't. I've never heard of this asininity before. Welcome to the fun world of cachable and non-cachable memory. Consider, today we can create struct pages of type MEMORY_DEVICE_PCI_P2PDMA for non-cachable MMIO. I think today you "can" use kmap to establish a cachable mapping in the vmap. But it is *illegal* to establish a cachable CPU mapping of MMIO. Archs are free to MCE if you do this - speculative cache line load of MMIO can just error in HW inside the interconnect. So, the phys_addr is always a "CPU untranslated physical address" but the cachable/non-cachable cases, or DRAM vs MMIO, are sometimes semantically very different things for the SW! Jason