From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 703B4C43334 for ; Wed, 29 Jun 2022 18:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbiF2SYx (ORCPT ); Wed, 29 Jun 2022 14:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiF2SYr (ORCPT ); Wed, 29 Jun 2022 14:24:47 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64B0B255AB; Wed, 29 Jun 2022 11:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:In-Reply-To:From:References:Cc:To: MIME-Version:Date:Message-ID:content-disposition; bh=6f/hfdoWC+PgJWoBH5fqwFGRbVxwuN3ohOs8yiOPg/w=; b=KqlIdYHpF5kcUd1uj3HgVczqN5 +LiC/fe4thV0n4GWyYvjongR/yShAMienfuQ1vSKr2dlutBWKxI1nszo45XAnij64gY60aWl25yKn 9yS7YZF5VmQ5saw9wKgfKuTqMswh1/nBQISRAQ25FYKkr6Le3Ih3GarYYS3dES6F4h5ipa5KBXImW +5AYt7ZvYxGywfXkmA46cmlkEvd9ckJZYnEqkIBKI2tycRJV07BzAnX9mR41JUrGOel82aqdx3sqr 111sVLF6oie65Xr6Z42l/GsfBOMAbGWd8Y9f26Frw8Cb4XUZDZkK9lUUkK39WvPZjSo78/eCvKrz8 ZKirfsHg==; Received: from s0106ac1f6bb1ecac.cg.shawcable.net ([70.73.163.230] helo=[192.168.11.155]) by ale.deltatee.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1o6cMk-002URm-20; Wed, 29 Jun 2022 12:24:43 -0600 Message-ID: <9725fc38-cbe6-f660-8d5f-6ceb983e6976@deltatee.com> Date: Wed, 29 Jun 2022 12:24:36 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-US To: Robin Murphy , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?Q?Christian_K=c3=b6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Chaitanya Kulkarni References: <20220615161233.17527-1-logang@deltatee.com> <20220615161233.17527-2-logang@deltatee.com> From: Logan Gunthorpe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.73.163.230 X-SA-Exim-Rcpt-To: robin.murphy@arm.com, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, sbates@raithlin.com, hch@lst.de, dan.j.williams@intel.com, jgg@ziepe.ca, christian.koenig@amd.com, jhubbard@nvidia.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, dave.b.minturn@intel.com, jason@jlekstrand.net, dave.hansen@linux.intel.com, jianxin.xiong@intel.com, helgaas@kernel.org, ira.weiny@intel.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.com, rcampbell@nvidia.com, kch@nvidia.com X-SA-Exim-Mail-From: logang@deltatee.com Subject: Re: [PATCH v7 01/21] lib/scatterlist: add flag for indicating P2PDMA segments in an SGL X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-06-29 12:02, Robin Murphy wrote: > On 2022-06-29 16:39, Logan Gunthorpe wrote: >> On 2022-06-29 03:05, Robin Murphy wrote: >>> On 2022-06-15 17:12, Logan Gunthorpe wrote: >>> Does this serve any useful purpose? If a page is determined to be device >>> memory, it's not going to suddenly stop being device memory, and if the >>> underlying sg is recycled to point elsewhere then sg_assign_page() will >>> still (correctly) clear this flag anyway. Trying to reason about this >>> beyond superficial API symmetry - i.e. why exactly would a caller need >>> to call it, and what would the implications be of failing to do so - >>> seems to lead straight to confusion. >>> >>> In fact I'd be inclined to have sg_assign_page() be responsible for >>> setting the flag automatically as well, and thus not need >>> sg_dma_mark_bus_address() either, however I can see the argument for >>> doing it this way round to not entangle the APIs too much, so I don't >>> have any great objection to that. >> >> Yes, I think you misunderstand what this is for. The SG_DMA_BUS_ADDDRESS >> flag doesn't mark the segment for the page, but for the dma address. It >> cannot be set in sg_assign_page() seeing it's not a property of the page >> but a property of the dma_address in the sgl. >> >> It's not meant for use by regular SG users, it's only meant for use >> inside DMA mapping implementations. The purpose is to know whether a >> given dma_address in the SGL is a bus address or regular memory because >> the two different types must be unmapped differently. We can't rely on >> the page because, as you know, many dma_map_sg() the dma_address entry >> in the sgl does not map to the same memory as the page. Or to put it >> another way: is_pci_p2pdma_page(sg->page) does not imply that >> sg->dma_address points to a bus address. >> >> Does that make sense? > > Ah, you're quite right, in trying to take in the whole series at once > first thing in the morning I did fail to properly grasp that detail, so > indeed the sg_assign_page() thing couldn't possibly work, but as I said > that's fine anyway. I still think the lifecycle management is a bit off > though - equivalently, a bus address doesn't stop being a bus address, > so it would seem appropriate to update this flag appropriately whenever > sg_dma_address() is assigned to, and not when it isn't. Yes, that's pretty much the way the code is now. The only two places sg_dma_mark_bus_address() is called are in the two pci_p2pdma helpers that set the dma address to the bus address. The lines before both calls set the dma_address and dma_len. Logan