Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp826779pxj; Thu, 13 May 2021 18:51:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxluqO+f1fsL+t0wsTCRleN5KuNwSJoxnCnKEQjhgQJmOxj44C/8tXtozFDe9glxyX0uP5q X-Received: by 2002:a17:906:5285:: with SMTP id c5mr45561054ejm.282.1620957106889; Thu, 13 May 2021 18:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620957106; cv=none; d=google.com; s=arc-20160816; b=SZnXIwW0+CUzkXL+I9rZSo/pL5AiRFc82ChUJkIv3u2RdJ/EYJQFzrL3N3hN1wUCIR Xl77sD1d0NBzCaY44QCh6ji8ZOMKAB5uVIhCgHz7ib0PVM09hwnUsKxpt7SVQRdSVII1 qk1t0EEqFdjPHWsnx0ns0+T/nMoFNxiMgWKFpDt6uoTOaULFZErrsv0eLDk9pM/J7Uj3 ui5uskOQAzEcfTEO48SWnJas1DRhl96jJOfTbTD7KxA35m7pEJ0elhg721qYxTt+b9ch e3jj/BAEqf0FjFo3zH+lN6CeAp/rChMWogLx02rRu8MriUVXsYWJNHN9pmmqBkRhVOl3 14wg== 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:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=MJtJPcG0fF8m+oZ5nuPZLN5xMdgwBh0nL1w0XXUciF4=; b=hPGXeY7TguOT7VCJrfoeXAL00G3ny84v0E1vPKF9t3o+v3gLxzB7tnJ2WTkFex0BwF POHIuWyHEsd7CCsiZ+E66qnAKKSFARPhmsg9q8c78y6bxXzseCi64WhCC19Kcy2/XvdO /krYPEXbH5xPvgvWCMI/9xHad1KyBlj3lHjCLv9LopZV3mGfDWovjpSypaBSAxtkf3LD fVPK5g8YrvM6iNrQfNyEiOvhlVTJ+k1kGMIST8XBfhhyuOD7acx13KluSPE/98IJvTxO V3uZgK/ftecb2sV7HXT7B2DNZKT/Nl0BCxi03WPfpVgMlUbXJLFLHqRu4PAfLlceihsN 8Btw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=KhehgNUQ; 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 k22si4793003edv.285.2021.05.13.18.51.10; Thu, 13 May 2021 18:51:46 -0700 (PDT) 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=pass header.i=@deltatee.com header.s=20200525 header.b=KhehgNUQ; 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 S231154AbhEMWe0 (ORCPT + 99 others); Thu, 13 May 2021 18:34:26 -0400 Received: from ale.deltatee.com ([204.191.154.188]:59360 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbhEMWdh (ORCPT ); Thu, 13 May 2021 18:33:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=MJtJPcG0fF8m+oZ5nuPZLN5xMdgwBh0nL1w0XXUciF4=; b=KhehgNUQfbKxcU2m3W8rqM+Fyk CjabbsFD9rkYNC7V2+qltnF0wYzfQsdGRe76sAMxSzzwe+SMYDh/cp9xbS8S0LYC/oZvAZKTVPUSu IkEiaPoaDtuxif2iP0NnVUXaenSix8GYzoyk0oZZthSq8INNeG3BCVLn00pkcjpCvDDqYEHNN5vLh IKnBa0gKCf9xeigxwK6oqqB9caYrSK1ET4CeFH0N+I4dEhl4eQeXIWH1fb0ocmEOsKUmTEiV81N+r XcbiMJfxS1ncC88/FdMdNHe0Xv1YKi1m9dHgYsvNfNYgn7EKg+g7XEdgVhOwSJaoosEbcDm6RJXqn jC9YZ0yw==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lhJsY-0000nE-CJ; Thu, 13 May 2021 16:32:27 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1lhJsG-0001Sk-E8; Thu, 13 May 2021 16:32:08 -0600 From: Logan Gunthorpe To: 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=20K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Logan Gunthorpe Date: Thu, 13 May 2021 16:31:47 -0600 Message-Id: <20210513223203.5542-7-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210513223203.5542-1-logang@deltatee.com> References: <20210513223203.5542-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.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, jgg@ziepe.ca, christian.koenig@amd.com, jhubbard@nvidia.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, helgaas@kernel.org, dan.j.williams@intel.com, andrzej.jakowski@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@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=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH v2 06/22] PCI/P2PDMA: Attempt to set map_type if it has not been set 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 Attempt to find the mapping type for P2PDMA pages on the first DMA map attempt if it has not been done ahead of time. Previously, the mapping type was expected to be calculated ahead of time, but if pages are to come from userspace then there's no way to ensure the path was checked ahead of time. With this change it's no longer invalid to call pci_p2pdma_map_sg() before the mapping type is calculated so drop the WARN_ON when that is the case. Signed-off-by: Logan Gunthorpe --- drivers/pci/p2pdma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 0e0b2218eacd..4034ffa0eb06 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -847,11 +847,17 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_publish); static enum pci_p2pdma_map_type pci_p2pdma_map_type(struct pci_dev *provider, struct pci_dev *client) { + enum pci_p2pdma_map_type ret; + if (!provider->p2pdma) return PCI_P2PDMA_MAP_NOT_SUPPORTED; - return xa_to_value(xa_load(&provider->p2pdma->map_types, - map_types_idx(client))); + ret = xa_to_value(xa_load(&provider->p2pdma->map_types, + map_types_idx(client))); + if (ret == PCI_P2PDMA_MAP_UNKNOWN) + return calc_map_type_and_dist_warn(provider, client, NULL); + + return ret; } static int __pci_p2pdma_map_sg(struct pci_p2pdma_pagemap *p2p_pgmap, @@ -899,7 +905,6 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg, case PCI_P2PDMA_MAP_BUS_ADDR: return __pci_p2pdma_map_sg(p2p_pgmap, dev, sg, nents); default: - WARN_ON_ONCE(1); return 0; } } -- 2.20.1