Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3975906pxf; Tue, 16 Mar 2021 02:33:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK+gOv6Ah71ZnfKk3meSc38EQMERv9l84Ws1sdUXmwgF3oGGeINMoxVcj3WmYOiAH4VfDj X-Received: by 2002:a05:6402:1517:: with SMTP id f23mr35735378edw.272.1615887189177; Tue, 16 Mar 2021 02:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615887189; cv=none; d=google.com; s=arc-20160816; b=G3/O42DYcR7GA8nG1ebw9IytawFYszM5erfMNRqi2azc2YQmAH5chGGOP6O7rdYhrX K7BLjJAj9kugXbNR5FIK6lRk+HhQHzan4SWELy5RCqu0+KJKR2QdfYW+LHTTyME1I6Lg L5ANg2SPkj7PVHajY3TDsgCRn+X9SRAIGeShPzNeWXyZv6tBvYi4V60JxrEg/aurWFsf LFA8gP6uiLeiM5vedXNHNAt76JCxH3PzkdStJOd1SpgG7yl53uHmdI/r0K8UFo34nKGE vmn0MASZR6FFCRApknGKs8htaJZI0INg0NedLsSpTXUpliQksE33SmSLfFti8LHFjrHa QDGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=HQV0aAlB1ZnqNG5JRrfj8MVEh9PNcDZzGQYLexWk0Wo=; b=FJZU8Tnsb8EGjHC3oIRfkJBmel1jusOfMu9xM0mTUXgNQ61Y67441xuIkJtKBYE6PX dUDXzoxz9FkLe9b/9LnZ9YRX5v3Ec+HcD4372NT5cU3j0k6pIFFRgscaA6Y2uWVcLgRh AJWpjj/jtpZIS3RA5HUrzdmWFx5mHRYn55HCbudue6bGu1pcLfR4uVH8sTVVSsd6J3F5 tgFKexhDQquFv5FWadFE2jxtHPC1F36VOpF1OiZiqQ0t1ors0gIj5R75fZKJ6ft2TzUL WdP8isEbQncPtUxcGOPQQdkWu0SeEvXWM9PJKB1TLf82Ehju5UIJXz8PqSaxs/lpsWLm ar1g== ARC-Authentication-Results: i=1; mx.google.com; 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 rl1si12650187ejb.115.2021.03.16.02.32.46; Tue, 16 Mar 2021 02:33:09 -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; 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 S234225AbhCPIMa (ORCPT + 99 others); Tue, 16 Mar 2021 04:12:30 -0400 Received: from verein.lst.de ([213.95.11.211]:58982 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234220AbhCPIME (ORCPT ); Tue, 16 Mar 2021 04:12:04 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 68EB168C4E; Tue, 16 Mar 2021 09:11:57 +0100 (CET) Date: Tue, 16 Mar 2021 09:11:56 +0100 From: Christoph Hellwig 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?= , Ira Weiny , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin Subject: Re: [RFC PATCH v2 06/11] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg Message-ID: <20210316081156.GA16595@lst.de> References: <20210311233142.7900-1-logang@deltatee.com> <20210311233142.7900-7-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210311233142.7900-7-logang@deltatee.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 11, 2021 at 04:31:36PM -0700, Logan Gunthorpe wrote: > for_each_sg(sgl, sg, nents, i) { > + if (is_pci_p2pdma_page(sg_page(sg))) { > + if (sg_page(sg)->pgmap != pgmap) { > + pgmap = sg_page(sg)->pgmap; > + map = pci_p2pdma_dma_map_type(dev, pgmap); > + bus_off = pci_p2pdma_bus_offset(sg_page(sg)); > + } > + > + if (map < 0) { > + sg->dma_address = DMA_MAPPING_ERROR; > + ret = -EREMOTEIO; > + goto out_unmap; > + } > + > + if (map) { > + sg->dma_address = sg_phys(sg) + sg->offset - > + bus_off; > + sg_dma_len(sg) = sg->length; > + sg_mark_pci_p2pdma(sg); > + continue; > + } > + } This code needs to go into a separate noinline helper to reduce the impact on the fast path. Also as Robin noted the offset is already accounted for in sg_phys. We also don't ever set the dma_address in the scatterlist to DMA_MAPPING_ERROR, that is just a return value for the single entry mapping routines.