Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2186014pxb; Fri, 17 Sep 2021 04:22:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzA5DjGsKytt+pbchhbbSgiV+m6BLoCi6vBK0H/Zu6NdAeI5BUb58EfV/3op2yMKvkPCOAv X-Received: by 2002:a05:6402:13d0:: with SMTP id a16mr11713190edx.155.1631877754627; Fri, 17 Sep 2021 04:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631877754; cv=none; d=google.com; s=arc-20160816; b=s9ZA8jbjQ162zhblAhhMMHvSTDsVfgv7RtVOMI5fbR///sC5KBkAqCfa4KNWgEsqyT QDwdxo1/o+n/hfw+UqVW4v9/fgB/sCCSYGvegpUVAC7d746FsTdShcDtmbjS8aFUjHMY 8oX3OX0sLlkrvtMH/kTj160xIpAnkQgZ8fOZ4oEakjd517hJ9AOT14advm/QphWTj4w+ RA/3NpveOYASjVJFGxPXxlDf2CcjKsKrroxIJ1wRDRf5n+53a/RZwtWTwGMQJ0LZffbP kQQWf+QC0oe/BjVAk6yC3Soa6oCao9BW/x2jvYI5chZWVomwjBl3yfZOtXezVX335T09 BflQ== 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=qfb2+eMQOk7Gk06URJPXi58+6EBzc1Ujn8WpPDlaGV8=; b=yYD5D1pvA7o6oMXoCToXoahyHqfXqovG6lEOx3g9f6R3PL4Itdc6haAxsY3XGQFLCH XJxOHFBNF5PU3ZL9GLXVD0RyvImqw2ML0zX//OL3S9mzWwSPmYOgTDYHBJzSnEd/yeoY stSnNZKWdhZizAq3QRdJWX62WD5zyHLUaqZAt2vbGJH5Ljc11rc1GFX4wXZtbwYw0rEc IAKjMIghTFzbYiaPKF2vAmCbWbIfcEACb101jLcG2RSyQ5IaJSQ473uevqIXg/GqsUYI ma0KMTkqvnl98O/bSFdhneAHAHcQOaqVaSY2BxZuFVmLUbsvmFm0U97f1LcDKsOD6zmz CICA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=AtzMXLuO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ee26si7524933edb.511.2021.09.17.04.21.45; Fri, 17 Sep 2021 04:22:34 -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=AtzMXLuO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241521AbhIPXmd (ORCPT + 99 others); Thu, 16 Sep 2021 19:42:33 -0400 Received: from ale.deltatee.com ([204.191.154.188]:40594 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238479AbhIPXmc (ORCPT ); Thu, 16 Sep 2021 19:42:32 -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=qfb2+eMQOk7Gk06URJPXi58+6EBzc1Ujn8WpPDlaGV8=; b=AtzMXLuOD/lGI+R9FeomHGL2iD Hn0FauNr2vSIqkgDwJDxgCv89v//2LEskR3Bh9d4H9VptSy9Oe0wotK/cWeRyP14BcwX11GHkamuT 02QviJzcXrEq7zP7XiqMW8zKC+i5KcfciLXcYQKgeInS1xd4ClzTDdgwfs86Wjwlgkh2fdmXCdKY3 K/0ofQKEvo7/KIZujvhobuJd1E2Krld2YLgpXMaC+pqWlZI596p12dP6XNdE1qwUHB5SO4/ZOZK8H 0eCJOhuSkxmLuJdOZz1AZ7vu9QeeRfjLvz6IRGTvhzEYEz/CkKCMcg0pITwD0rqMrjsO2EMoQTlr+ /+ZZBNag==; 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 1mR107-0008I1-JS; Thu, 16 Sep 2021 17:41:10 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1mR103-000Vqs-OU; Thu, 16 Sep 2021 17:41:03 -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 , Martin Oliveira , Chaitanya Kulkarni , Logan Gunthorpe Date: Thu, 16 Sep 2021 17:40:42 -0600 Message-Id: <20210916234100.122368-3-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210916234100.122368-1-logang@deltatee.com> References: <20210916234100.122368-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, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.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 v3 02/20] 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 50cdde3e9a8b..1192c465ba6d 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -848,6 +848,7 @@ static enum pci_p2pdma_map_type pci_p2pdma_map_type(struct dev_pagemap *pgmap, struct pci_dev *provider = to_p2p_pgmap(pgmap)->provider; struct pci_dev *client; struct pci_p2pdma *p2pdma; + int dist; if (!provider->p2pdma) return PCI_P2PDMA_MAP_NOT_SUPPORTED; @@ -864,6 +865,10 @@ static enum pci_p2pdma_map_type pci_p2pdma_map_type(struct dev_pagemap *pgmap, type = xa_to_value(xa_load(&p2pdma->map_types, map_types_idx(client))); rcu_read_unlock(); + + if (type == PCI_P2PDMA_MAP_UNKNOWN) + return calc_map_type_and_dist(provider, client, &dist, false); + return type; } @@ -906,7 +911,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.30.2