public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
@ 2018-02-14  4:58 Anshuman Khandual
  2018-02-14  8:32 ` Johannes Thumshirn
  2018-02-14 16:03 ` Bart Van Assche
  0 siblings, 2 replies; 6+ messages in thread
From: Anshuman Khandual @ 2018-02-14  4:58 UTC (permalink / raw)
  To: linux-kernel, gregkh, bart.vanassche, jthumshirn, axboe, chris,
	tvrtko.ursulin
  Cc: khandual

This replaces scatterlist->page_link LSB encodings with SG_CHAIN and
SG_EMARK definitions without any functional change.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
---
 include/linux/scatterlist.h | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 22b2131bcdcd..63d00bdb2fb3 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -65,16 +65,18 @@ struct sg_table {
  */
 
 #define SG_MAGIC	0x87654321
+#define SG_CHAIN	0x01
+#define SG_EMARK	0x02
 
 /*
  * 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 scatterlist.
  * Those low bits are there for everyone! (thanks mason :-)
  */
-#define sg_is_chain(sg)		((sg)->page_link & 0x01)
-#define sg_is_last(sg)		((sg)->page_link & 0x02)
+#define sg_is_chain(sg)		((sg)->page_link & SG_CHAIN)
+#define sg_is_last(sg)		((sg)->page_link & SG_EMARK)
 #define sg_chain_ptr(sg)	\
-	((struct scatterlist *) ((sg)->page_link & ~0x03))
+	((struct scatterlist *) ((sg)->page_link & ~(SG_CHAIN | SG_EMARK)))
 
 /**
  * sg_assign_page - Assign a given page to an SG entry
@@ -88,13 +90,13 @@ struct sg_table {
  **/
 static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
 {
-	unsigned long page_link = sg->page_link & 0x3;
+	unsigned long page_link = sg->page_link & (SG_CHAIN | SG_EMARK);
 
 	/*
 	 * 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 & 0x03);
+	BUG_ON((unsigned long) page & (SG_CHAIN | SG_EMARK));
 #ifdef CONFIG_DEBUG_SG
 	BUG_ON(sg->sg_magic != SG_MAGIC);
 	BUG_ON(sg_is_chain(sg));
@@ -130,7 +132,7 @@ static inline struct page *sg_page(struct scatterlist *sg)
 	BUG_ON(sg->sg_magic != SG_MAGIC);
 	BUG_ON(sg_is_chain(sg));
 #endif
-	return (struct page *)((sg)->page_link & ~0x3);
+	return (struct page *)((sg)->page_link & ~(SG_CHAIN | SG_EMARK));
 }
 
 /**
@@ -178,7 +180,8 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
 	 * Set lowest bit to indicate a link pointer, and make sure to clear
 	 * the termination bit if it happens to be set.
 	 */
-	prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02;
+	prv[prv_nents - 1].page_link = ((unsigned long) sgl | SG_CHAIN)
+					& ~SG_EMARK;
 }
 
 /**
@@ -198,8 +201,8 @@ static inline void sg_mark_end(struct scatterlist *sg)
 	/*
 	 * Set termination bit, clear potential chain bit
 	 */
-	sg->page_link |= 0x02;
-	sg->page_link &= ~0x01;
+	sg->page_link |= SG_EMARK;
+	sg->page_link &= ~SG_CHAIN;
 }
 
 /**
@@ -215,7 +218,7 @@ static inline void sg_unmark_end(struct scatterlist *sg)
 #ifdef CONFIG_DEBUG_SG
 	BUG_ON(sg->sg_magic != SG_MAGIC);
 #endif
-	sg->page_link &= ~0x02;
+	sg->page_link &= ~SG_EMARK;
 }
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
  2018-02-14  4:58 [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings Anshuman Khandual
@ 2018-02-14  8:32 ` Johannes Thumshirn
  2018-02-14 16:11   ` Tvrtko Ursulin
  2018-02-14 16:03 ` Bart Van Assche
  1 sibling, 1 reply; 6+ messages in thread
From: Johannes Thumshirn @ 2018-02-14  8:32 UTC (permalink / raw)
  To: Anshuman Khandual, linux-kernel, gregkh, bart.vanassche, axboe,
	chris, tvrtko.ursulin

On Wed, 2018-02-14 at 10:28 +0530, Anshuman Khandual wrote:
> This replaces scatterlist->page_link LSB encodings with SG_CHAIN and
> SG_EMARK definitions without any functional change.
> 
> Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
> ---
>  include/linux/scatterlist.h | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/include/linux/scatterlist.h
> b/include/linux/scatterlist.h
> index 22b2131bcdcd..63d00bdb2fb3 100644
> --- a/include/linux/scatterlist.h
> +++ b/include/linux/scatterlist.h
> @@ -65,16 +65,18 @@ struct sg_table {
>   */
>  
>  #define SG_MAGIC	0x87654321
> +#define SG_CHAIN	0x01
> +#define SG_EMARK	0x02

SG_EMARK sounds strange, what about SG_END?

-- 
Johannes Thumshirn                                          Storage
jthu
mshirn@suse.de                                +49 911 74053 689
SUSE
LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane
Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38
9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
  2018-02-14  4:58 [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings Anshuman Khandual
  2018-02-14  8:32 ` Johannes Thumshirn
@ 2018-02-14 16:03 ` Bart Van Assche
  2018-02-15  2:54   ` Anshuman Khandual
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2018-02-14 16:03 UTC (permalink / raw)
  To: chris@chris-wilson.co.uk, linux-kernel@vger.kernel.org,
	tvrtko.ursulin@intel.com, jthumshirn@suse.de,
	khandual@linux.vnet.ibm.com, gregkh@linuxfoundation.org,
	axboe@kernel.dk

On Wed, 2018-02-14 at 10:28 +0530, Anshuman Khandual wrote:
> +#define SG_CHAIN	0x01
> +#define SG_EMARK	0x02

Hello Anshuman,

As you probably know constants that do not have a suffix are of type int. Please
consider to add suffix "UL" to these constants to avoid that the compiler could
take an undesired decision when e.g. converting ~SG_CHAIN from int to unsigned
long.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
  2018-02-14  8:32 ` Johannes Thumshirn
@ 2018-02-14 16:11   ` Tvrtko Ursulin
  2018-02-15  2:53     ` Anshuman Khandual
  0 siblings, 1 reply; 6+ messages in thread
From: Tvrtko Ursulin @ 2018-02-14 16:11 UTC (permalink / raw)
  To: Johannes Thumshirn, Anshuman Khandual, linux-kernel, gregkh,
	bart.vanassche, axboe, chris, tvrtko.ursulin


On 14/02/18 08:32, Johannes Thumshirn wrote:
> On Wed, 2018-02-14 at 10:28 +0530, Anshuman Khandual wrote:
>> This replaces scatterlist->page_link LSB encodings with SG_CHAIN and
>> SG_EMARK definitions without any functional change.
>>
>> Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
>> ---
>>   include/linux/scatterlist.h | 23 +++++++++++++----------
>>   1 file changed, 13 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/linux/scatterlist.h
>> b/include/linux/scatterlist.h
>> index 22b2131bcdcd..63d00bdb2fb3 100644
>> --- a/include/linux/scatterlist.h
>> +++ b/include/linux/scatterlist.h
>> @@ -65,16 +65,18 @@ struct sg_table {
>>    */
>>   
>>   #define SG_MAGIC	0x87654321
>> +#define SG_CHAIN	0x01
>> +#define SG_EMARK	0x02
> 
> SG_EMARK sounds strange, what about SG_END?

+1 on SG_END.

Btw, just a cleanup for readability or you have further work in this area?

Regards,

Tvrtko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
  2018-02-14 16:11   ` Tvrtko Ursulin
@ 2018-02-15  2:53     ` Anshuman Khandual
  0 siblings, 0 replies; 6+ messages in thread
From: Anshuman Khandual @ 2018-02-15  2:53 UTC (permalink / raw)
  To: Tvrtko Ursulin, Johannes Thumshirn, linux-kernel, gregkh,
	bart.vanassche, axboe, chris, tvrtko.ursulin

On 02/14/2018 09:41 PM, Tvrtko Ursulin wrote:
> 
> On 14/02/18 08:32, Johannes Thumshirn wrote:
>> On Wed, 2018-02-14 at 10:28 +0530, Anshuman Khandual wrote:
>>> This replaces scatterlist->page_link LSB encodings with SG_CHAIN and
>>> SG_EMARK definitions without any functional change.
>>>
>>> Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
>>> ---
>>>   include/linux/scatterlist.h | 23 +++++++++++++----------
>>>   1 file changed, 13 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/include/linux/scatterlist.h
>>> b/include/linux/scatterlist.h
>>> index 22b2131bcdcd..63d00bdb2fb3 100644
>>> --- a/include/linux/scatterlist.h
>>> +++ b/include/linux/scatterlist.h
>>> @@ -65,16 +65,18 @@ struct sg_table {
>>>    */
>>>     #define SG_MAGIC    0x87654321
>>> +#define SG_CHAIN    0x01
>>> +#define SG_EMARK    0x02
>>
>> SG_EMARK sounds strange, what about SG_END?
> 
> +1 on SG_END.
> 
> Btw, just a cleanup for readability or you have further work in this area?

Sure, will replace with SG_END. I was trying something else on virtio drivers
on POWER platform and just came across this. 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings
  2018-02-14 16:03 ` Bart Van Assche
@ 2018-02-15  2:54   ` Anshuman Khandual
  0 siblings, 0 replies; 6+ messages in thread
From: Anshuman Khandual @ 2018-02-15  2:54 UTC (permalink / raw)
  To: Bart Van Assche, chris@chris-wilson.co.uk,
	linux-kernel@vger.kernel.org, tvrtko.ursulin@intel.com,
	jthumshirn@suse.de, gregkh@linuxfoundation.org, axboe@kernel.dk

On 02/14/2018 09:33 PM, Bart Van Assche wrote:
> On Wed, 2018-02-14 at 10:28 +0530, Anshuman Khandual wrote:
>> +#define SG_CHAIN	0x01
>> +#define SG_EMARK	0x02
> 
> Hello Anshuman,
> 
> As you probably know constants that do not have a suffix are of type int. Please
> consider to add suffix "UL" to these constants to avoid that the compiler could
> take an undesired decision when e.g. converting ~SG_CHAIN from int to unsigned
> long.

Sure, will do.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-15  2:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-14  4:58 [PATCH] lib/scatterlist: Add SG_CHAIN and SG_EMARK macros for LSB encodings Anshuman Khandual
2018-02-14  8:32 ` Johannes Thumshirn
2018-02-14 16:11   ` Tvrtko Ursulin
2018-02-15  2:53     ` Anshuman Khandual
2018-02-14 16:03 ` Bart Van Assche
2018-02-15  2:54   ` Anshuman Khandual

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox