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 8621DC433F5 for ; Tue, 28 Sep 2021 19:09:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0020C61209 for ; Tue, 28 Sep 2021 19:08:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0020C61209 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7F6C26B0071; Tue, 28 Sep 2021 15:08:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A5FA6B0072; Tue, 28 Sep 2021 15:08:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6952C900002; Tue, 28 Sep 2021 15:08:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 5A16A6B0071 for ; Tue, 28 Sep 2021 15:08:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 13C6618025597 for ; Tue, 28 Sep 2021 19:08:59 +0000 (UTC) X-FDA: 78637919598.24.F802A00 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) by imf10.hostedemail.com (Postfix) with ESMTP id B00AD600198B for ; Tue, 28 Sep 2021 19:08:58 +0000 (UTC) Received: by mail-il1-f179.google.com with SMTP id j15so120029ila.6 for ; Tue, 28 Sep 2021 12:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EfElY477shD06prhcbkdx9dsGqBCwQCmB0C4j8bm7NE=; b=T7zH3yMi0g6yEhgmUnd7mO+Ur7OBh77wHEh6ggvhef5YbyC4wX4RRbWTB44KDdyQtC f+qApcKyr3n5Kl16eVfFgQ9tfeyRrR6Elwq6FGHKyACe8YimAJpy7cusTx0oBV41JMIt 0Hs8ot7T3se64OIay27dLlQhOUiTQMVr0mnUblHvHoq8r+teZ7l8U9BnX5pxcEi+Yk7z s5RWLMvLxN8MPYR7eAYwtVLxanwLKsVahoBd3UvKp/b3/2FYvFg85dCO3UV5z34pnkRJ KVDkFetoYUVS2clKM8AdqWOtNoT0d0PPUr+04NJyaKP+HVSyA1Hg4mIqDJ4dKgMV/XBl XsnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EfElY477shD06prhcbkdx9dsGqBCwQCmB0C4j8bm7NE=; b=upl6LqSk1C3/o6F4hDp3SgYb/zmA0WqZP7DGkXYEHvbILO/61C9GjoSyTX7t3QPC0o NgQFLvPdzJUDvAkHUCKdbUWwkbhXdZSwzs+PN1yfijh8TNT8R16niXqvbN9TUMaJtH0j 6Z1e+W82SqxKGJsCHzHlHClcU5Y40VGJmj2leEShgIqN+eYGFGkr7lfvZgkUN1qqaIid QTY2KmVHMQ2VMupQB5V6fsVKyKyt/4D/wIgtaepawsN4GXVjmTRwYriI7Y9vb5wJ7J2h zDZcb/zdQiTXLoxDZjlqRyBtW3ED4w19dydqRwjdhWcEHATobh1pBvPLZI+WGWIutUTF shng== X-Gm-Message-State: AOAM532ANW8E7ZZxPgsXB1ZuwQex8pLXZz1y+9ALhylCcQHD28AMPgbh EMQU6Jzl5eYFH15/Yb1DpEPN5g== X-Google-Smtp-Source: ABdhPJwirdzukaEVpQtEHLEaN9P3HDIpr/EdIl+V+c/21A4I82mQWg8qeJs2PajODuEvNoAg4jE0MQ== X-Received: by 2002:a05:6e02:1a6b:: with SMTP id w11mr5790685ilv.21.1632856137729; Tue, 28 Sep 2021 12:08:57 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id r13sm12324375ilh.80.2021.09.28.12.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 12:08:57 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mVITI-007Fut-4V; Tue, 28 Sep 2021 16:08:56 -0300 Date: Tue, 28 Sep 2021 16:08:56 -0300 From: Jason Gunthorpe 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 , Christian =?utf-8?B?S8O2bmln?= , 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 Subject: Re: [PATCH v3 06/20] dma-direct: support PCI P2PDMA pages in dma-direct map_sg Message-ID: <20210928190856.GN3544071@ziepe.ca> References: <20210916234100.122368-1-logang@deltatee.com> <20210916234100.122368-7-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210916234100.122368-7-logang@deltatee.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B00AD600198B X-Stat-Signature: o3o5f38ea8h34s5uw6hptncn9dounynt Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=T7zH3yMi; dmarc=none; spf=pass (imf10.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.166.179 as permitted sender) smtp.mailfrom=jgg@ziepe.ca X-HE-Tag: 1632856138-717514 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 16, 2021 at 05:40:46PM -0600, Logan Gunthorpe wrote: > Add PCI P2PDMA support for dma_direct_map_sg() so that it can map > PCI P2PDMA pages directly without a hack in the callers. This allows > for heterogeneous SGLs that contain both P2PDMA and regular pages. > > A P2PDMA page may have three possible outcomes when being mapped: > 1) If the data path between the two devices doesn't go through the > root port, then it should be mapped with a PCI bus address > 2) If the data path goes through the host bridge, it should be mapped > normally, as though it were a CPU physical address > 3) It is not possible for the two devices to communicate and thus > the mapping operation should fail (and it will return -EREMOTEIO). > > SGL segments that contain PCI bus addresses are marked with > sg_dma_mark_pci_p2pdma() and are ignored when unmapped. > > Signed-off-by: Logan Gunthorpe > kernel/dma/direct.c | 44 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 38 insertions(+), 6 deletions(-) > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index 4c6c5e0635e3..fa8317e8ff44 100644 > +++ b/kernel/dma/direct.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include "direct.h" > > /* > @@ -421,29 +422,60 @@ void dma_direct_sync_sg_for_cpu(struct device *dev, > arch_sync_dma_for_cpu_all(); > } > > +/* > + * Unmaps segments, except for ones marked as pci_p2pdma which do not > + * require any further action as they contain a bus address. > + */ > void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sgl, > int nents, enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > > - for_each_sg(sgl, sg, nents, i) > - dma_direct_unmap_page(dev, sg->dma_address, sg_dma_len(sg), dir, > - attrs); > + for_each_sg(sgl, sg, nents, i) { > + if (sg_is_dma_pci_p2pdma(sg)) { > + sg_dma_unmark_pci_p2pdma(sg); > + } else { > + dma_direct_unmap_page(dev, sg->dma_address, > + sg_dma_len(sg), dir, attrs); > + } If the main usage of this SGL bit is to indicate if it has been DMA mapped, or not, I think it should be renamed to something clearer. p2pdma is being used for lots of things now, it feels very counter-intuitive that P2PDMA pages are not flagged with something called sg_is_dma_pci_p2pdma(). How about sg_is_dma_unmapped_address() ? > > for_each_sg(sgl, sg, nents, i) { > + if (is_pci_p2pdma_page(sg_page(sg))) { > + map = pci_p2pdma_map_segment(&p2pdma_state, dev, sg); > + switch (map) { > + case PCI_P2PDMA_MAP_BUS_ADDR: > + continue; > + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > + /* > + * Mapping through host bridge should be > + * mapped normally, thus we do nothing > + * and continue below. > + */ > + break; > + default: > + ret = -EREMOTEIO; > + goto out_unmap; > + } > + } > + > sg->dma_address = dma_direct_map_page(dev, sg_page(sg), > sg->offset, sg->length, dir, attrs); dma_direct_map_page() can trigger swiotlb and I didn't see this series dealing with that? It would probably be fine for now to fail swiotlb_map() for p2p pages? Jason