Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4398104pxb; Tue, 10 Nov 2020 15:48:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzI6cWbjoc2ls6yTNepqxoFyXmu08+X3NanfRcuZ1Aj/+NegZikMQnHZeIYgTL//+2rEzt1 X-Received: by 2002:a17:906:8603:: with SMTP id o3mr3244696ejx.333.1605052099356; Tue, 10 Nov 2020 15:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605052099; cv=none; d=google.com; s=arc-20160816; b=IBR5dNSXwOaMN9vwdHu/n9d2hKoBS7ZlCOR3UGYIkwOF78CZmUkVV47R80wOSiVtT2 dT4UvLmOpOVRt9gOfnP4u+Iz80cH2FJ/ub4bApoP82x6LvOhummbgl2qcot+C+ke7RiF cz2atxjYbIdrQ/cQ5qzFuE0zUCalnY2w4brpPsn1Fqe2FFT2zbA8BamX3lEunBSyWmKP fZbj6lg3abHVocq7JGgOP1GAcgLFGqvhxRPSodVWUad67KyO57nPBHgM7qrDO9JVPsRq arEhtoxlwg9cCq1PWqDKQDzWu2Vi0//Bh2mltCTe3rLBCvfcaY74N95dhMtV1ao2su3v bDhQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:dkim-signature; bh=dq7zEId0NdZdINMNT6Dmw/UdigbwtVpJA5sVRfmfofg=; b=XB3gj4OQUDucDAcDTcLYTEOQtwyA5LcLX9rXgCYhd827wCEqK91RUia+SbypSm8raT wnX6OfYldZSoDH5WJgrexsZeVLSXioA9R/3mxzF5rqmRSFmLglKeC5UrCIJOmsdB1qZF ypoxuI4d+GgSBuKEvVpBnC79KLWhj9/UWl8yUZlSMZRnIT/AMbgP+EDkcUuF0dcTW9BH 9hx656OmI1tISwMsxXVnMitzNT4a8Xz+esu5qzuxaTcXXr09mZvTXA+iiTFiBAI++RH3 kM0eQO1uL61au4jgtqJq7zyMmYB5w5iwZcoEaOJmyAWcIfXIRdeb8a0LH1BrVi+Dfete QICA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=OGkZy1Uy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si178592edt.488.2020.11.10.15.47.41; Tue, 10 Nov 2020 15:48:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@deltatee.com header.s=20200525 header.b=OGkZy1Uy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732496AbgKJXmf (ORCPT + 99 others); Tue, 10 Nov 2020 18:42:35 -0500 Received: from ale.deltatee.com ([204.191.154.188]:47714 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732465AbgKJXm1 (ORCPT ); Tue, 10 Nov 2020 18:42:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dq7zEId0NdZdINMNT6Dmw/UdigbwtVpJA5sVRfmfofg=; b=OGkZy1Uyl96LErvRAxZGS3VLh2 UFPnmL68iQiGa7WAKcronB92llBdP3YlqIU+7eGuFKbqGjkT01WWufQfvYhwJQWb5f4Chtvv5u50S ehGDDouQf07lLymZnuvKlNikGX0MG5kw18tbF+W0I0l1dYdqjxKHukHshhL/MTMWuMcU1rwtN+iYD MX/dMQFi6k6B6yzwa4oKcYK28+bCU9oc5m4af9qikpCqZDiTpCgHOzow/uqJ6YsHG16ieCLyHb+Qi Uefg2Nrk14j0VCvqrjysb0S8rgDpYRYKseTyjfXOJtFFb2JZ0gOPhivVU3VIxjdTMfibx68jS04pG vJLX6QZg==; Received: from guinness.priv.deltatee.com ([172.16.1.162]) by ale.deltatee.com with esmtp (Exim 4.92) (envelope-from ) id 1kcdH8-0000kz-29; Tue, 10 Nov 2020 16:42:11 -0700 To: Bjorn Helgaas Cc: 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, Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?Q?Christian_K=c3=b6nig?= , Ira Weiny , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter References: <20201110232513.GA705726@bjorn-Precision-5520> From: Logan Gunthorpe Message-ID: Date: Tue, 10 Nov 2020 16:42:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20201110232513.GA705726@bjorn-Precision-5520> Content-Type: text/plain; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 172.16.1.162 X-SA-Exim-Rcpt-To: daniel.vetter@ffwll.ch, willy@infradead.org, ddutile@redhat.com, jhubbard@nvidia.com, iweiny@intel.com, christian.koenig@amd.com, jgg@ziepe.ca, dan.j.williams@intel.com, hch@lst.de, sbates@raithlin.com, iommu@lists.linux-foundation.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, helgaas@kernel.org X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,NICE_REPLY_A,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [RFC PATCH 03/15] PCI/P2PDMA: Introduce pci_p2pdma_should_map_bus() and pci_p2pdma_bus_offset() X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-11-10 4:25 p.m., Bjorn Helgaas wrote: > On Fri, Nov 06, 2020 at 10:00:24AM -0700, Logan Gunthorpe wrote: >> Introduce pci_p2pdma_should_map_bus() which is meant to be called by >> dma map functions to determine how to map a given p2pdma page. > > s/dma/DMA/ for consistency (also below in function comment) > >> pci_p2pdma_bus_offset() is also added to allow callers to get the bus >> offset if they need to map the bus address. >> >> Signed-off-by: Logan Gunthorpe >> --- >> drivers/pci/p2pdma.c | 46 ++++++++++++++++++++++++++++++++++++++ >> include/linux/pci-p2pdma.h | 11 +++++++++ >> 2 files changed, 57 insertions(+) >> >> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c >> index ea8472278b11..9961e779f430 100644 >> --- a/drivers/pci/p2pdma.c >> +++ b/drivers/pci/p2pdma.c >> @@ -930,6 +930,52 @@ void pci_p2pdma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, >> } >> EXPORT_SYMBOL_GPL(pci_p2pdma_unmap_sg_attrs); >> >> +/** >> + * pci_p2pdma_bus_offset - returns the bus offset for a given page >> + * @page: page to get the offset for >> + * >> + * Must be passed a pci p2pdma page. > > s/pci/PCI/ > >> + */ >> +u64 pci_p2pdma_bus_offset(struct page *page) >> +{ >> + struct pci_p2pdma_pagemap *p2p_pgmap = to_p2p_pgmap(page->pgmap); >> + >> + WARN_ON(!is_pci_p2pdma_page(page)); >> + >> + return p2p_pgmap->bus_offset; >> +} >> +EXPORT_SYMBOL_GPL(pci_p2pdma_bus_offset); >> + >> +/** >> + * pci_p2pdma_should_map_bus - determine if a dma mapping should use the >> + * bus address >> + * @dev: device doing the DMA request >> + * @pgmap: dev_pagemap structure for the mapping >> + * >> + * Returns 1 if the page should be mapped with a bus address, 0 otherwise >> + * and -1 the device should not be mapping P2PDMA pages. > > I think this is missing a word. > > I'm not really sure how to interpret the "should" in > pci_p2pdma_should_map_bus(). If this returns -1, does that mean the > patches *cannot* be mapped? They *could* be mapped, but you really > *shouldn't*? Something else? > > 1 means page should be mapped with bus address. 0 means ... what, > exactly? It should be mapped with some different address? 1 means it must be mapped with a bus address 0 means it may be mapped normally (through the IOMMU or just with a direct physical address) -1 means it cannot be mapped and should fail (ie. if it must go through the IOMMU, but the IOMMU is not in the whitelist). > Sorry these are naive questions because I don't know how all this > works. Thanks for the review. Definitely points out some questionable language that I used. I'll reword this if/when it goes further. Logan