Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp864730iog; Wed, 29 Jun 2022 11:45:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFseywOQAZ+4zhJgA+qvmFHntOaJ+4G8AlZvrP31EWQq1EGnqI0TT/QG+uiW3oFQnFVezg X-Received: by 2002:a63:4726:0:b0:3fd:9e47:6b3f with SMTP id u38-20020a634726000000b003fd9e476b3fmr4091692pga.321.1656528311163; Wed, 29 Jun 2022 11:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656528311; cv=none; d=google.com; s=arc-20160816; b=RW9V4cDAle4izKAkgiVi/+/zemVWP2PD+QF+4SRa3Gq6j7bZ8nhjUQd01oEA+KqB4Z 2ZOOWpB88hXgBv+WJWCR4sf5A4GzypXq28y1F/AuwObAqcqnTtyMJlRKNM/pDyWIqTtF ydSWjDj2j086HYKURL4+MTQjRob+pfKJcghkIVGeoYiA1N81mvIapSuCi2qNjiDVmgN8 XZVqa1vlfX4tRPWTojCFn2ZwejNWqeshBMNLvODY1Vi2cUD964yMInjFrr61VMeHA7/s Bnj0bL2sdspeqwQDM3DVf85ZVcTYP2cnuoM/7rrNxdIVNsEZaFgpAnt0ebGIPcKdT+Ms h11Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:in-reply-to :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=6f/hfdoWC+PgJWoBH5fqwFGRbVxwuN3ohOs8yiOPg/w=; b=u2wsr1RlkkxYkGeNTzLpQ2KFypvBDAO42Wt0rPME/xK6dLO+nmw7OP5BZRm3Z3eigS hZPDzvIWt9GQsEMUH3G0wfnCPv0ah3bghUXdxasD+jpwRRids5hDA+Q0V0n9F97twAeK tgfckTyJ4s07Co2InLzsH8DC5AVfPXQGI+Z+jAC08sTT8DDgxPPc8yNkI4TTBgKh+4ma oWF6aIvZInhoILvsAZ68QdombN1cDZYO2j7YVH3qLOjusNdQ22ZqdBOiUN7Hv8e4rbGb B3KdvUxcHHaVfIxzcfIYvFzbVY9M3k7eibech33bnEgXvOVClMSHDIrwe6ItzRmZorfb 7s0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=KqlIdYHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s11-20020a170902a50b00b00158f777bbbfsi21405312plq.559.2022.06.29.11.44.58; Wed, 29 Jun 2022 11:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=KqlIdYHp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbiF2SYt (ORCPT + 99 others); Wed, 29 Jun 2022 14:24:49 -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 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 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