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 X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53C38C433B4 for ; Fri, 14 May 2021 13:57:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA7B56101A for ; Fri, 14 May 2021 13:57:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA7B56101A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5A5F16B0036; Fri, 14 May 2021 09:57:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 555E16B006E; Fri, 14 May 2021 09:57:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41D886B0070; Fri, 14 May 2021 09:57:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id 15DE96B0036 for ; Fri, 14 May 2021 09:57:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9C9641807E792 for ; Fri, 14 May 2021 13:57:16 +0000 (UTC) X-FDA: 78139988472.09.9AB5972 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf17.hostedemail.com (Postfix) with ESMTP id AB77240002CE for ; Fri, 14 May 2021 13:57:15 +0000 (UTC) Received: by verein.lst.de (Postfix, from userid 2407) id 176846736F; Fri, 14 May 2021 15:57:13 +0200 (CEST) Date: Fri, 14 May 2021 15:57:12 +0200 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?= , 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 Subject: Re: [PATCH v2 15/22] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg Message-ID: <20210514135712.GD4715@lst.de> References: <20210513223203.5542-1-logang@deltatee.com> <20210513223203.5542-16-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210513223203.5542-16-logang@deltatee.com> User-Agent: Mutt/1.5.17 (2007-11-01) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=none (imf17.hostedemail.com: domain of hch@lst.de has no SPF policy when checking 213.95.11.211) smtp.mailfrom=hch@lst.de X-Stat-Signature: 56mtnsh8bwq3md7k9xud11ygpejastxq X-Rspamd-Queue-Id: AB77240002CE X-Rspamd-Server: rspam02 X-HE-Tag: 1621000635-151123 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: > + for_each_sg(sgl, sg, nents, i) { > + if (sg_is_dma_pci_p2pdma(sg)) { > + sg_dma_unmark_pci_p2pdma(sg); > + } else { Double space here. We also don't really need the curly braces to start with. > + struct pci_p2pdma_map_state p2pdma_state = {}; > + enum pci_p2pdma_map_type map; > struct scatterlist *sg; > + int i, ret; > > 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) { Why not just: switch (pci_p2pdma_map_segment(&p2pdma_state, dev, sg)) { (even better with a shorter name for p2pdma_state so that it all fits on a single line)? > + 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. > + */ I have a bit of a hard time parsing this comment. > + if (sg->dma_address == DMA_MAPPING_ERROR) { > + ret = -EINVAL; > goto out_unmap; > + } > sg_dma_len(sg) = sg->length; > } > > @@ -411,7 +443,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, > > out_unmap: > dma_direct_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > - return -EINVAL; > + return ret; Maybe just initialize ret to -EINVAL at declaration time to simplify this a bit?