From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 B454A207E02 for ; Wed, 19 Mar 2025 17:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742407124; cv=none; b=Bjk8oFWKliNg8hXxTnw0TIVRjfmO3ukTwCX81HyCrppOHq8VGuNWQuAlYMZ0LK6XNTKC0yVTaMCUl+zENt8e6NEvSAgyJvYxSQGeoN7J6N2hj5djeZsyB9M+sEOlLrNBYJbQVfBD3/6uFyw8yaPEyMvLE/VuSSZM8zN/5iqXDF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742407124; c=relaxed/simple; bh=O1aeb0KFlrkj4Yiw1nWYiPzizeq56+6Mn3GDJKk7WrE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DqSCf9xEfppRrlgkAIbht10ur8YDrOCIp9gQdzD7GnCTG4kwCWlyFhDRi1bW2asPsGAJhi9A7DbZ+gvcGZZ4Mufru+nl5J/f8NscXBwBFI3up8f3d5d8alFvTzvmOApqnY/kxeFZIbd9BVqfor21hQfGziHpmqSZcW6in6Yv9B0= 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=JswssZao; arc=none smtp.client-ip=209.85.222.180 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="JswssZao" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7c542ffec37so707132285a.2 for ; Wed, 19 Mar 2025 10:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1742407121; x=1743011921; 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=tk5ycb3N9meE73NCm46CD0AtZuFHAdivFMZfwt24RPU=; b=JswssZaoSvcGZ3Nb3HuBG6yTTepkbVvops9jz8GX0QPSsMZFW5TAmeqJyqUmyrXh5e 9yd0D5+xit2h+NbfDPGcgydDHXSJ2ZawWNZlNKWiPsbscwgJO3I/D/ccaEd6sXaQefXL P8IaxLiPCwfg4vuJ9yijo8Qifjg8jhUnuqW3o6y37oeE1UjF0yLhoJ0ffNsqWWhVLzbx 03eQ6VGcXdRNbfKzRLeEWywvgzyxONJ2hS86uSYluPzy0M0PxKuFPIYJfQH/xuM5OYQ5 s5XDR6OMjA+U7S70WxOERiIXTMPnvEsyw3TOvGC0iyLiroIrIpuMe5vEkwUAUWF5OZqs GzCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742407121; x=1743011921; 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=tk5ycb3N9meE73NCm46CD0AtZuFHAdivFMZfwt24RPU=; b=h7dkC2UB+tKoNVZ4XRcZakcgcqlYxc0Olp+jh+1ZQ2pcIoqjmvBF8A+CklerJKWY63 m9M1M3dMrupdeeKof2N1UTnn1fNKAeTInYT8fzEWELjVcm4J5SJDU1umwmGUhNSk5+gV Le22UzK6Fhw4trA2aAaFT29VHV5wwg+H0YSfIdJETU2Az1iBsTVTVhm4huBmp6Y6ZCpd H5BKf/Ky6SEwMtao94uhlqWr4kFlmQRopBGoCTCCk7m9fhBmIby7sKLPYtTMtxmfxN2P DJ1XNDY6EAGe0i+fqdQiXy9o6CBZX7o1zwmjFlXCDZEZK+sRrZ9cPCU7L5xmxgfFIkHw ZpnQ== X-Forwarded-Encrypted: i=1; AJvYcCV90EHnCy4xNr3n25TWz7CcX9Jt3aR+aoBxQFfapMiTF+y8bG2qVjeUH+z0ssLB/RFc46cPqASrL11hocA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5oNYuTogqNWzSXGR1AfBqP1iKHhrreJhqfDr8R0cmBbVVlKdT O2XyK01rTJOSxmC2Id1zN4ZTqO/SglPdbmfJ4luA5qYc8yEb63RetPCFpSOv12c= X-Gm-Gg: ASbGncsftGPIPbBH7C/NhD2gu+HQSN/+yh9oa1X963MLJDKryoRPXfQBD4Tf96WMVCC Jlp9YZSV0Te6Q8j958qBFEGd9nxkoBXOjlkeBhGTmgVuaPjJJRVf77RSURAbc2MlaQ2lgTBkeos l0H8bSsW5LR9QevAKX5yAuHJ6nY0qZFCnxhWMHZsbGg3V2N+mK7dQG9uOZYEZMH5JLTgKdXO9Dh yaMO4SIK2t0ecIXqa4c6qZXwPaAEo01H57H+/xjAmLflmyo/OGDB5dPLkga+PleD1r01Nw/sW1d 5weT897uVDRtXm9NGTT7BLEe3RYlBPLHqBYTr+eslfS0lS3D5NFo0oQEU6fTdQMveBcaGyf60+7 eXFcMs/vKgc0uUxOxkg== X-Google-Smtp-Source: AGHT+IH//pIx1EBbRFqDU6QPhXC6odo+Ppd2dshOt/mNgQMR0e3nRHsssO7Vo2UonDgQd/fB3+YCbw== X-Received: by 2002:a05:620a:3189:b0:7c5:5154:cb2 with SMTP id af79cd13be357-7c5a839688cmr568357985a.15.1742407121681; Wed, 19 Mar 2025 10:58:41 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-128-5.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.128.5]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c573d8a62asm885096585a.96.2025.03.19.10.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 10:58:40 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1tuxge-00000000Wns-1mXJ; Wed, 19 Mar 2025 14:58:40 -0300 Date: Wed, 19 Mar 2025 14:58:40 -0300 From: Jason Gunthorpe To: Marek Szyprowski Cc: Leon Romanovsky , Robin Murphy , Christoph Hellwig , Jens Axboe , Joerg Roedel , Will Deacon , Sagi Grimberg , Keith Busch , Bjorn Helgaas , Logan Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Andrew Morton , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, Randy Dunlap Subject: Re: [PATCH v7 00/17] Provide a new two step DMA mapping API Message-ID: <20250319175840.GG10600@ziepe.ca> References: <20250220124827.GR53094@unreal> <1166a5f5-23cc-4cce-ba40-5e10ad2606de@arm.com> <20250312193249.GI1322339@unreal> 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: On Fri, Mar 14, 2025 at 11:52:58AM +0100, Marek Szyprowski wrote: > > The only way to do so is to use dma_map_sg_attrs(), which relies on SG > > (the one that we want to remove) to map P2P pages. > > That's something I don't get yet. How P2P pages can be used with > dma_map_sg_attrs(), but not with dma_map_page_attrs()? Both operate > internally on struct page pointer. It is a bit subtle, I ran in to this when exploring enabling proper P2P for dma_map_resource() too. The API signatures are: dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, size_t size, enum dma_data_direction dir, unsigned long attrs); void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir, unsigned long attrs); The thing to notice immediately is that the unmap path does not get passed a struct page. So, lets think about the flow when the iommu is turned on. For normal struct page memory: - dma_map_page_attrs() allocates some IOVA and returns it in the dma_addr_t and then maps the struct page to the iommu page table - dma_unmap_page_attrs() frees the IOVA from the given dma_addr_t If we think about P2P now: - dma_map_page_attrs() can inspect the struct page and determine it is P2P. It computes a bus address which is not an IOVA, and does not transit through the IOMMU. No IOVA allocation is performed. the bus address is returned as the dma_addr_t - dma_unmap_page_attrs() ... is impossible. We just get this dma_addr_t that doesn't have enough information to tell anymore if the address is a P2P bus address or not, so we can't tell if we should unmap an iova from the dma_addr_t :\ The sg path fixes this because it introduced a new flag in the scatterlist, SG_DMA_BUS_ADDRESS, that allows the sg map path to record the information for the unmap path so it can do the right thing. Leon's approach fixes this by putting an overarching transaction state around the DMA operation so that map and unmap operations can look in the state and determine if this is a P2P or non P2P map and then know how to unmap. For some background here, Christoph gave me this idea back at LSF/MM in Vancouver (two years ago now). At the time I was looking at replacing scatterlist and giving new DMA API ops to operate on a "scatterlist v2" structure. Christoph's vision was to make a performance DMA API path that could be used to implement any scatterlist-like data structure very efficiently without having to teach the DMA API about all sorts of scatterlist-like things. Jason