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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 569BDC433F5 for ; Mon, 27 Sep 2021 18:50:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AA8D60E09 for ; Mon, 27 Sep 2021 18:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236350AbhI0SwS (ORCPT ); Mon, 27 Sep 2021 14:52:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236296AbhI0SwQ (ORCPT ); Mon, 27 Sep 2021 14:52:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CDAE961058; Mon, 27 Sep 2021 18:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632768638; bh=C5XC6h6Q1qc5Qf6BQUNRzYX2mM+5Ej8TnIc335MIf3Y=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=sxhqG2OwJcmYiPbgyuP+0xu6/gEhxQlRDh6b0Q4SBqBqsN4nn+REtn//Bigm2XegR ltuanBZSrm5Dt6GJFsiwiA23f1AVvAUrGESKtat3QIvJZJcdHhUShJO+a3JDGkAcOZ hBm+bbjGjp1eJ3L8+BW1Hvy5k/t+DXjcmafsp4Qwiq5fz+FPcHdN7cSv1nVdS+iH5j 4+kUSasJvEa4tLbjzHFbG61XTE6v9SW+4inMLS7Rk3O6gACDrFD9x0m5Kg3tADTBv7 oK+UBQkgmZxlMMOwZ7wxWruTgiS8aySMoZgqahsIPVSzl9H8IY1XOu/MeIQNBzPO5O hg5kqidrgvEnw== Date: Mon, 27 Sep 2021 13:50:36 -0500 From: Bjorn Helgaas To: Logan Gunthorpe 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 , Christian =?iso-8859-1?Q?K=F6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni Subject: Re: [PATCH v3 02/20] PCI/P2PDMA: attempt to set map_type if it has not been set Message-ID: <20210927185036.GA668115@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210916234100.122368-3-logang@deltatee.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu, Sep 16, 2021 at 05:40:42PM -0600, Logan Gunthorpe wrote: > 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 Acked-by: Bjorn Helgaas Capitalize subject line. > --- > 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 >