Message ID | 20211117215410.3695-2-logang@deltatee.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Userspace P2PDMA with O_DIRECT NVMe devices | expand |
On 11/17/21 1:53 PM, Logan Gunthorpe wrote: > Convert the sg_is_chain(), sg_is_last() and sg_chain_ptr() macros > into static inline functions. There's no reason for these to be macros > and static inline are generally preferred these days. > > Also introduce the SG_PAGE_LINK_MASK define so the P2PDMA work, which is > adding another bit to this mask, can do so more easily. > > Suggested-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Logan Gunthorpe <logang@deltatee.com> > --- Looks good. Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
On Wed, Nov 17, 2021 at 02:53:48PM -0700, Logan Gunthorpe wrote: > Convert the sg_is_chain(), sg_is_last() and sg_chain_ptr() macros > into static inline functions. There's no reason for these to be macros > and static inline are generally preferred these days. > > Also introduce the SG_PAGE_LINK_MASK define so the P2PDMA work, which is > adding another bit to this mask, can do so more easily. > > Suggested-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Looks fine: Reviewed-by: Christoph Hellwig <hch@lst.de> scatterlist.h doesn't have a real maintainer, do you want me to pick this up through the DMA tree?
On 2021-12-21 2:00 a.m., Christoph Hellwig wrote: > On Wed, Nov 17, 2021 at 02:53:48PM -0700, Logan Gunthorpe wrote: >> Convert the sg_is_chain(), sg_is_last() and sg_chain_ptr() macros >> into static inline functions. There's no reason for these to be macros >> and static inline are generally preferred these days. >> >> Also introduce the SG_PAGE_LINK_MASK define so the P2PDMA work, which is >> adding another bit to this mask, can do so more easily. >> >> Suggested-by: Jason Gunthorpe <jgg@nvidia.com> >> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> > > Looks fine: > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > scatterlist.h doesn't have a real maintainer, do you want me to pick > this up through the DMA tree? Sure, that would be great! Thanks, Logan
On Tue, Dec 21, 2021 at 10:23:24AM -0700, Logan Gunthorpe wrote: > > scatterlist.h doesn't have a real maintainer, do you want me to pick > > this up through the DMA tree? > > Sure, that would be great! Done.
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 266754a55327..7ff9d6386c12 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -69,10 +69,27 @@ struct sg_append_table { * a valid sg entry, or whether it points to the start of a new scatterlist. * Those low bits are there for everyone! (thanks mason :-) */ -#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))) +#define SG_PAGE_LINK_MASK (SG_CHAIN | SG_END) + +static inline unsigned int __sg_flags(struct scatterlist *sg) +{ + return sg->page_link & SG_PAGE_LINK_MASK; +} + +static inline struct scatterlist *sg_chain_ptr(struct scatterlist *sg) +{ + return (struct scatterlist *)(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; +} /** * sg_assign_page - Assign a given page to an SG entry @@ -92,7 +109,7 @@ static inline void sg_assign_page(struct scatterlist *sg, struct page *page) * In order for the low bit stealing approach to work, pages * must be aligned at a 32-bit boundary as a minimum. */ - BUG_ON((unsigned long) page & (SG_CHAIN | SG_END)); + BUG_ON((unsigned long)page & SG_PAGE_LINK_MASK); #ifdef CONFIG_DEBUG_SG BUG_ON(sg_is_chain(sg)); #endif @@ -126,7 +143,7 @@ static inline struct page *sg_page(struct scatterlist *sg) #ifdef CONFIG_DEBUG_SG BUG_ON(sg_is_chain(sg)); #endif - return (struct page *)((sg)->page_link & ~(SG_CHAIN | SG_END)); + return (struct page *)((sg)->page_link & ~SG_PAGE_LINK_MASK); } /**
Convert the sg_is_chain(), sg_is_last() and sg_chain_ptr() macros into static inline functions. There's no reason for these to be macros and static inline are generally preferred these days. Also introduce the SG_PAGE_LINK_MASK define so the P2PDMA work, which is adding another bit to this mask, can do so more easily. Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Logan Gunthorpe <logang@deltatee.com> --- include/linux/scatterlist.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)