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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C4AD5B14E for ; Mon, 28 Oct 2024 20:59:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC2596B00A7; Mon, 28 Oct 2024 16:59:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B71716B00A8; Mon, 28 Oct 2024 16:59:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A39866B00A9; Mon, 28 Oct 2024 16:59:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 807F76B00A7 for ; Mon, 28 Oct 2024 16:59:08 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 311EAABAF4 for ; Mon, 28 Oct 2024 20:59:08 +0000 (UTC) X-FDA: 82724225682.02.5DA3D1D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 27EC21C000F for ; Mon, 28 Oct 2024 20:58:55 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YHWCjZnS; spf=pass (imf18.hostedemail.com: domain of helgaas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=helgaas@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730149066; a=rsa-sha256; cv=none; b=aL10TGsV2pVC8uF8h5algzIV655yEfcEMKsErzQYS90KOWK3Gp8UfsKXmlaVAFqGYMovib zo6fLgRrKM0FWBSKwdlQk+XGfnTf3+D7L8JrvjZeb19CggZ840hQfNqTjyg9p2gTGcV0oI 69zjai3SPNubOvwTaNxJkwOPtLVubR8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YHWCjZnS; spf=pass (imf18.hostedemail.com: domain of helgaas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=helgaas@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730149066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:dkim-signature; bh=7+9/DynagSBshpDkDEO/Qo39ekOeeQhW1Ny/1R9HdQo=; b=ien4cmee2Tb7RHcsUfcWAMJMkrpHmR5rEpSO2O2NYEHaW+dK+zA8O8hXTSZTiddPzRFf7N X2W2s+53M3FQwlrPHYfa6nEiBOFEysiNe36R+MtFezsyfKZxMEUifaOEd23Tut1a9+fnZp JFISJNzW7uNjGB/ehWVe581i0cYBR/k= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2DE955C5B58; Mon, 28 Oct 2024 20:58:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8324C4CEC3; Mon, 28 Oct 2024 20:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730149144; bh=XDchRQtmy6pHQo4VldmyUQn5KpIMSBE9FuRx/IQ/fLc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=YHWCjZnSvGD0FLXm38frIZRba2sQQ98rHEmaoqo7+IGWHJUxibwDnNsBZgESkMQf2 TsIZgg66kDAZi3cQ/raC0xLCHxFt/n+Q+GfpSPikoPYWogMwVVkT2YGGo6r+mvlpQs LYcYZiWraEirilGEQRB7r1dSqxIlLl6PnIyzBEG69k5H5ZL/4V51yCX9ue/AQ9hoao YtQPx9n4wU6TLKUu3BMoGWW4nbSLG6WcdHPvYzg+727B9k+tQFNcmm7b2B+OIclaEr WoCdB/gjnaxlHYJSzABbNThj3fTHRWtRg5gmc802RNwzAtTGyuBAMLTzhdJzsWVOka YksEeTIOFMwbA== Date: Mon, 28 Oct 2024 15:59:02 -0500 From: Bjorn Helgaas To: Leon Romanovsky Cc: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg , Keith Busch , Bjorn Helgaas , Logan Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , Marek Szyprowski , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Andrew Morton , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 01/18] PCI/P2PDMA: refactor the p2pdma mapping helpers Message-ID: <20241028205902.GA1114413@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: yyto85zzas85msznzx4jr4yu95xad5ni X-Rspamd-Queue-Id: 27EC21C000F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1730149135-420352 X-HE-Meta: U2FsdGVkX1937Y+p2XI5B12hojoNiJEp5oT00mechV43RElzaCSF3iZH1PxkD0NGuOb3sfjK/kqqIYrC6QScojwVEaZEW5Cbgj07s36L395M7Sv1lYnjI10oHqylzMCqtXBDOyt6NVA9mm4II+BRdbYAO2pqMtrOw1lDylU55KvVbFm+LadYu5Jx+p0dexbhuq2DSKYS4PRVNmJNY6p2o1SVAI6PYISSEp1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ender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Prefer subject capitalization in drivers/pci: PCI/P2PDMA: Refactor ... On Sun, Oct 27, 2024 at 04:21:01PM +0200, Leon Romanovsky wrote: > From: Christoph Hellwig > > The current scheme with a single helper to determine the P2P status > and map a scatterlist segment force users to always use the map_sg > helper to DMA map, which we're trying to get away from because they > are very cache inefficient. > ... Acked-by: Bjorn Helgaas A couple minor nits below. > @@ -1412,28 +1411,29 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, > size_t s_length = s->length; > size_t pad_len = (mask - iova_len + 1) & mask; > > - if (is_pci_p2pdma_page(sg_page(s))) { > - map = pci_p2pdma_map_segment(&p2pdma_state, dev, s); > - switch (map) { > - case PCI_P2PDMA_MAP_BUS_ADDR: > - /* > - * iommu_map_sg() will skip this segment as > - * it is marked as a bus address, > - * __finalise_sg() will copy the dma address > - * into the output segment. > - */ > - continue; > - case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > - /* > - * Mapping through host bridge should be > - * mapped with regular IOVAs, thus we > - * do nothing here and continue below. > - */ > - break; > - default: > - ret = -EREMOTEIO; > - goto out_restore_sg; > - } > + switch (pci_p2pdma_state(&p2pdma_state, dev, sg_page(s))) { > + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > + /* > + * Mapping through host bridge should be mapped with > + * regular IOVAs, thus we do nothing here and continue > + * below. > + */ I guess this is technically not a fall-through to the next case because there's no executable code here, but since the comment separates these two cases, I would find it easier to read if you included the break here explicitly. > + case PCI_P2PDMA_MAP_NONE: > + break; > +void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state, > + struct device *dev, struct page *page); > + > +/** > + * pci_p2pdma_state - check the P2P transfer state of a page > + * @state: P2P state structure Checkpatch complains about space before tab here. > + * pci_p2pdma_bus_addr_map - map a PCI_P2PDMA_MAP_BUS_ADDR P2P transfer > + * @state: P2P state structure And here. > @@ -462,34 +462,32 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, > enum dma_data_direction dir, unsigned long attrs) > { > 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) { > - case PCI_P2PDMA_MAP_BUS_ADDR: > - continue; > - case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > - /* > - * Any P2P mapping that traverses the PCI > - * host bridge must be mapped with CPU physical > - * address and not PCI bus addresses. This is > - * done with dma_direct_map_page() below. > - */ > - break; > - default: > - ret = -EREMOTEIO; > + switch (pci_p2pdma_state(&p2pdma_state, dev, sg_page(sg))) { > + case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: > + /* > + * Any P2P mapping that traverses the PCI host bridge > + * must be mapped with CPU physical address and not PCI > + * bus addresses. > + */ Same fall-through comment. > + case PCI_P2PDMA_MAP_NONE: > + sg->dma_address = dma_direct_map_page(dev, sg_page(sg), > + sg->offset, sg->length, dir, attrs); > + if (sg->dma_address == DMA_MAPPING_ERROR) { > + ret = -EIO; > goto out_unmap; > } > - }