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 2C9B6C433EF for ; Tue, 28 Sep 2021 18:32:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB2B5610E6 for ; Tue, 28 Sep 2021 18:32:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BB2B5610E6 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 589416B0071; Tue, 28 Sep 2021 14:32:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 538C56B0072; Tue, 28 Sep 2021 14:32:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42751900002; Tue, 28 Sep 2021 14:32:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 2F7236B0071 for ; Tue, 28 Sep 2021 14:32:22 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E839718135C5C for ; Tue, 28 Sep 2021 18:32:21 +0000 (UTC) X-FDA: 78637827282.01.19372A3 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf11.hostedemail.com (Postfix) with ESMTP id 9DEC3F0000B8 for ; Tue, 28 Sep 2021 18:32:21 +0000 (UTC) Received: by mail-qv1-f41.google.com with SMTP id o15so1600674qvq.4 for ; Tue, 28 Sep 2021 11:32:21 -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:content-transfer-encoding:in-reply-to; bh=bg5/FXYy6+0jcxwwe7U26Md8Qo1QDW6vkKmJYeX4i1Y=; b=Hl/E00tVRRsG4VyZTxHCUyfFppftH6aDIraQlh7Zo4b85gvTNF+AYqXgzSNwc5/npf l06458g+lvnyddemEzX90uBn/bHB8RYcKfeo1e7FpLjMI+74Dzz/0g/94z+f7GzW+0Zd CfpRY5E+W8e1NS+sbJ1/ugjuNMbciPIgxXLMQk1vyLzXxq0uHenjiyziZ6R3dyiq9JVL p4sfE2H5q8AjNru6j9eT1fchBVmabhTgc0UQSbcACR3kakx5Tj48HjTa5txeDIwD47Yn QqR/fi/0MROMXY9kXIbtoFfIdbEtX3H3w3iXU5cvYHfX3miyrcJhnWwRC/Xh64nSBvuk yGrA== 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:content-transfer-encoding :in-reply-to; bh=bg5/FXYy6+0jcxwwe7U26Md8Qo1QDW6vkKmJYeX4i1Y=; b=ukd9KPi1Ml6Q2I5bi+nTsz9eSpmSlH27ihUjzB0DXZ5o+T6h61Pu3ZDHsQFmsdrmww VvqIGkE/QNXJIeBv+BwdqJ1TiSY/TKYWWpa/vU3ZZZcnlRTNSk/CmAf0lR4YP2pxgbhe guir2lV/cm0BIS9J5XgF38ak5g3+NUIOAyySCsxHqiMHCA8p0T0JU3MUiB8E2tJyqP3j xjCPvIAfgcOsADbJJ/06AoHljKaH3uf2W1fBSeUy3JaBFmtAN4P7fxep5jjLU9rPNyEY 0UXDfvJ1+bXyb4OSPqWZVojxPdGeNSpRiyDqoHowH8Vu17N4LoBbi2jJ0FkqvIzuudqY 0axQ== X-Gm-Message-State: AOAM533qE3tIRAPN4wnLKwwNe7GjUNW6uP4fU9pZY4+TxvKIH4QwBzBR 7eS29zmSC5tEFP/ajBrKjQcDaA== X-Google-Smtp-Source: ABdhPJzfCJn9TE545S5oPvfgJD/DrRXSPKUbE0avVhY8SKIQnFw2dHzYLn+zJmKsF3kZryoXkBtS0Q== X-Received: by 2002:ad4:4652:: with SMTP id y18mr7157907qvv.2.1632853940961; Tue, 28 Sep 2021 11:32:20 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id w185sm16014000qkd.30.2021.09.28.11.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 11:32:20 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mVHtr-007FEl-RE; Tue, 28 Sep 2021 15:32:19 -0300 Date: Tue, 28 Sep 2021 15:32:19 -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 01/20] lib/scatterlist: add flag for indicating P2PDMA segments in an SGL Message-ID: <20210928183219.GJ3544071@ziepe.ca> References: <20210916234100.122368-1-logang@deltatee.com> <20210916234100.122368-2-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210916234100.122368-2-logang@deltatee.com> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9DEC3F0000B8 X-Stat-Signature: b7kpouhgu915d9h9hy9d4ofc5xpkxt96 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b="Hl/E00tV"; dmarc=none; spf=pass (imf11.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.219.41 as permitted sender) smtp.mailfrom=jgg@ziepe.ca X-HE-Tag: 1632853941-514065 Content-Transfer-Encoding: quoted-printable 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:41PM -0600, Logan Gunthorpe wrote: > Make use of the third free LSB in scatterlist's page_link on 64bit syst= ems. >=20 > The extra bit will be used by dma_[un]map_sg_p2pdma() to determine when= a > given SGL segments dma_address points to a PCI bus address. > dma_unmap_sg_p2pdma() will need to perform different cleanup when a > segment is marked as P2PDMA. >=20 > Using this bit requires adding an additional dependency on CONFIG_64BIT= to > CONFIG_PCI_P2PDMA. This should be acceptable as the majority of P2PDMA > use cases are restricted to newer root complexes and roughly require th= e > extra address space for memory BARs used in the transactions. >=20 > Signed-off-by: Logan Gunthorpe > Reviewed-by: John Hubbard > drivers/pci/Kconfig | 2 +- > include/linux/scatterlist.h | 50 ++++++++++++++++++++++++++++++++++--- > 2 files changed, 47 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig > index 0c473d75e625..90b4bddb3300 100644 > +++ b/drivers/pci/Kconfig > @@ -163,7 +163,7 @@ config PCI_PASID > =20 > config PCI_P2PDMA > bool "PCI peer-to-peer transfer support" > - depends on ZONE_DEVICE > + depends on ZONE_DEVICE && 64BIT Perhaps a comment to explain what the 64bit is doing? > select GENERIC_ALLOCATOR > help > Enable=D1=95 drivers to do PCI peer-to-peer transactions to and fro= m > diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h > index 266754a55327..e62b1cf6386f 100644 > +++ b/include/linux/scatterlist.h > @@ -64,6 +64,21 @@ struct sg_append_table { > #define SG_CHAIN 0x01UL > #define SG_END 0x02UL > =20 > +/* > + * bit 2 is the third free bit in the page_link on 64bit systems which > + * is used by dma_unmap_sg() to determine if the dma_address is a PCI > + * bus address when doing P2PDMA. > + * Note: CONFIG_PCI_P2PDMA depends on CONFIG_64BIT because of this. > + */ > + > +#ifdef CONFIG_PCI_P2PDMA > +#define SG_DMA_PCI_P2PDMA 0x04UL Add a=20 static_assert(__alignof__(void *) =3D=3D 8); ? > +#else > +#define SG_DMA_PCI_P2PDMA 0x00UL > +#endif > + > +#define SG_PAGE_LINK_MASK (SG_CHAIN | SG_END | SG_DMA_PCI_P2PDMA) > + > /* > * We overload the LSB of the page pointer to indicate whether it's > * a valid sg entry, or whether it points to the start of a new scatte= rlist. > @@ -72,7 +87,9 @@ struct sg_append_table { > #define sg_is_chain(sg) ((sg)->page_link & SG_CHAIN) > #define sg_is_last(sg) ((sg)->page_link & SG_END) > #define sg_chain_ptr(sg) \ > - ((struct scatterlist *) ((sg)->page_link & ~(SG_CHAIN | SG_END))) > + ((struct scatterlist *)((sg)->page_link & ~SG_PAGE_LINK_MASK)) > + > +#define sg_is_dma_pci_p2pdma(sg) ((sg)->page_link & SG_DMA_PCI_P2PDMA) I've been encouraging people to use static inlines more.. static inline unsigned int __sg_flags(struct scatterlist *sg) { return sg->page_link & SG_PAGE_LINK_MASK; } static inline bool sg_is_chain(struct scatterlist *sg) { return __sg_flags(sg) & SG_CHAIN; } static inline bool sg_is_last(struct scatterlist *sg) { return __sg_flags(sg) & SG_END; } static inline bool sg_is_dma_pci_p2pdma(struct scatterlist *sg) { return __sg_flags(sg) & SG_DMA_PCI_P2PDMA; } > /** > * sg_assign_page - Assign a given page to an SG entry > @@ -86,13 +103,13 @@ struct sg_append_table { > **/ > static inline void sg_assign_page(struct scatterlist *sg, struct page = *page) > { > - unsigned long page_link =3D sg->page_link & (SG_CHAIN | SG_END); > + unsigned long page_link =3D sg->page_link & SG_PAGE_LINK_MASK; I think this should just be '& SG_END', sg_assign_page() doesn't look like it should ever be used on a sg_chain entry, so this is just trying to preserve the end stamp. Anyway, this looks OK Reviewed-by: Jason Gunthorpe Jason