Skip to contentSkip to conversation

block: sysfs fix mismatched queue_var_{store,show} in 64bit kernel

PATCH Superseded Xiaotian Feng 4 participants 8 messages Jul 14, 2009 – Jul 17, 2009 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: sysfs fix mismatched queue_var_{store,show} in 64bit kernel

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

	# echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
	# cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value
---
 block/blk-sysfs.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
block/blk-sysfs.c +7 -6
index b1cd040..e177eb3 100644
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
 };
 
 static ssize_t
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
 {
-	return sprintf(page, "%d\n", var);
+	return sprintf(page, "lu\n", var);
 }
 
 static ssize_t
@@ -77,7 +77,8 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_ra_show(struct request_queue *q, char *page)
 {
-	int ra_kb = q->backing_dev_info.ra_pages << (PAGE_CACHE_SHIFT - 10);
+	unsigned long ra_kb = q->backing_dev_info.ra_pages <<
+					(PAGE_CACHE_SHIFT - 10);
 
 	return queue_var_show(ra_kb, (page));
 }
@@ -95,7 +96,7 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
 {
-	int max_sectors_kb = queue_max_sectors(q) >> 1;
+	unsigned long max_sectors_kb = queue_max_sectors(q) >> 1;
 
 	return queue_var_show(max_sectors_kb, (page));
 }
@@ -140,7 +141,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
 {
-	int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
+	unsigned long max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
 
 	return queue_var_show(max_hw_sectors_kb, (page));
 }
@@ -189,7 +190,7 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
 
 static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
 {
-	unsigned int set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
+	unsigned long set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
 
 	return queue_var_show(set != 0, page);
 }
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 21 lines · Xiaotian Feng

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

       # echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
       # cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value

---
 block/blk-sysfs.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
block/blk-sysfs.c +0 -0
index b1cd040..e177eb3 100644
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
  };
 

 static ssize_t

block/blk-sysfs.c +1 -1
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
Quoted 3 lines

 {
-       return sprintf(page, "%d\n", var);
+       return sprintf(page, "lu\n", var);

%lu

block/blk-sysfs.c queue_requests_store(struct request_queue *q, const char *page, size_t count) · line 81

Quoted 10 lines

 }

 static ssize_t

block/blk-sysfs.c +2 -1
@@ -77,7 +77,8 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
 
  static ssize_t queue_ra_show(struct request_queue *q, char *page)
  {
-       int ra_kb = q->backing_dev_info.ra_pages << (PAGE_CACHE_SHIFT - 10);
+       unsigned long ra_kb = q->backing_dev_info.ra_pages <<
+                                       (PAGE_CACHE_SHIFT - 10);

It looks like that your email client replaces tab's with spaces.

author
#2 lore raw
Quoted 19 lines · Américo Wang
Quoted 18 lines · Xiaotian Feng

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

       # echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
       # cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value
---
 block/blk-sysfs.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
block/blk-sysfs.c +0 -0
index b1cd040..e177eb3 100644
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
 };
 
Quoted 10 lines

block/blk-sysfs.c struct queue_sysfs_entry { · line 21

Quoted 6 lines
block/blk-sysfs.c +2 -2
 static ssize_t
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
 {
-       return sprintf(page, "%d\n", var);
+       return sprintf(page, "lu\n", var);

%lu

My mistake, correct in V2. Thank you.

Quoted 5 lines
Quoted 5 lines
block/blk-sysfs.c +0 -0
  }
 
  static ssize_t
@@ -77,7 +77,8 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
 
Quoted 8 lines

block/blk-sysfs.c queue_requests_store(struct request_queue *q, const char *page, size_t count) · line 81

Quoted 5 lines
block/blk-sysfs.c +2 -1
  static ssize_t queue_ra_show(struct request_queue *q, char *page)
  {
-       int ra_kb = q->backing_dev_info.ra_pages<<  (PAGE_CACHE_SHIFT - 10);
+       unsigned long ra_kb = q->backing_dev_info.ra_pages<<
+                                       (PAGE_CACHE_SHIFT - 10);

It looks like that your email client replaces tab's with spaces.

I use git send-email, and in my thunderbird, they're all tabs...

#3 lore raw
In reply to Xiaotian Feng
Quoted 16 lines · Xiaotian Feng

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

	# echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
	# cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value
---
 block/blk-sysfs.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
block/blk-sysfs.c +0 -0
index b1cd040..e177eb3 100644

block/blk-sysfs.c struct queue_sysfs_entry { · line 21

Quoted 8 lines
block/blk-sysfs.c +2 -2
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
 };
 
 static ssize_t
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
 {
-	return sprintf(page, "%d\n", var);
+	return sprintf(page, "lu\n", var);

%lu, I guess?

#4 lore raw

PATCH v2 1/1 block: sysfs fix mismatched queue_var_{store,show} in 64bit kernel

In reply to Xiaotian Feng

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

	# echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
	# cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value
---
 block/blk-sysfs.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
block/blk-sysfs.c +7 -6
index b1cd040..e177eb3 100644
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
 };
 
 static ssize_t
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
 {
-	return sprintf(page, "%d\n", var);
+	return sprintf(page, "%lu\n", var);
 }
 
 static ssize_t
@@ -77,7 +77,8 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_ra_show(struct request_queue *q, char *page)
 {
-	int ra_kb = q->backing_dev_info.ra_pages << (PAGE_CACHE_SHIFT - 10);
+	unsigned long ra_kb = q->backing_dev_info.ra_pages <<
+					(PAGE_CACHE_SHIFT - 10);
 
 	return queue_var_show(ra_kb, (page));
 }
@@ -95,7 +96,7 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
 {
-	int max_sectors_kb = queue_max_sectors(q) >> 1;
+	unsigned long max_sectors_kb = queue_max_sectors(q) >> 1;
 
 	return queue_var_show(max_sectors_kb, (page));
 }
@@ -140,7 +141,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
 {
-	int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
+	unsigned long max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
 
 	return queue_var_show(max_hw_sectors_kb, (page));
 }
@@ -189,7 +190,7 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
 
 static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
 {
-	unsigned int set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
+	unsigned long set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
 
 	return queue_var_show(set != 0, page);
 }
Signature · 1 line
1.6.2.5
#5 lore raw

Hello, Xiaotian.

block/blk-sysfs.c queue_requests_store(struct request_queue *q, const char *page, size_t count) · line 84

Quoted 8 lines · Xiaotian Feng

static ssize_t queue_ra_show(struct request_queue *q, char *page) {

block/blk-sysfs.c +2 -1
-	int ra_kb = q->backing_dev_info.ra_pages << (PAGE_CACHE_SHIFT - 10);
+	unsigned long ra_kb = q->backing_dev_info.ra_pages <<
+					(PAGE_CACHE_SHIFT - 10);
 
 	return queue_var_show(ra_kb, (page));
 }

Nice.

Quoted 10 lines
block/blk-sysfs.c +1 -1
@@ -95,7 +96,7 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
 {
-	int max_sectors_kb = queue_max_sectors(q) >> 1;
+	unsigned long max_sectors_kb = queue_max_sectors(q) >> 1;
 
 	return queue_var_show(max_sectors_kb, (page));
 }

block/blk-sysfs.c queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) · line 147

Quoted 8 lines
block/blk-sysfs.c +1 -1
@@ -140,7 +141,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
 {
-	int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
+	unsigned long max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
 
 	return queue_var_show(max_hw_sectors_kb, (page));
 }

The above two aren't necessary but well why not.

block/blk-sysfs.c static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, · line 196

Quoted 9 lines
block/blk-sysfs.c +1 -1
@@ -189,7 +190,7 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
 
 static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
 {
-	unsigned int set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
+	unsigned long set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
 
 	return queue_var_show(set != 0, page);
 }

Wouldn't it be better to make it "bool set = " and then remove the "!= 0"?

Thanks.

Signature · 1 line
tejun
author
#6 lore raw

Hello, Tejun:

Thank you very much for the review, I've attached v3 patch follow
your advices, please help me review.

Another thing on block sysfs is that we can echo some invalid value
(e.g 123abc), should sysfs return -EINVAL for those?

Regards

Quoted 48 lines · Tejun Heo

Hello, Xiaotian.

Review

Quoted 8 lines · Xiaotian Feng
  static ssize_t queue_ra_show(struct request_queue *q, char *page)
  {
(quoted diff) +2 -1
-	int ra_kb = q->backing_dev_info.ra_pages<<  (PAGE_CACHE_SHIFT - 10);
+	unsigned long ra_kb = q->backing_dev_info.ra_pages<<
+					(PAGE_CACHE_SHIFT - 10);
 
  	return queue_var_show(ra_kb, (page));
  }

Nice.

Quoted 10 lines
(quoted diff) +1 -1
@@ -95,7 +96,7 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count)
 
  static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
  {
-	int max_sectors_kb = queue_max_sectors(q)>>  1;
+	unsigned long max_sectors_kb = queue_max_sectors(q)>>  1;
 
  	return queue_var_show(max_sectors_kb, (page));
  }

Review queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) · line 147

Quoted 8 lines
(quoted diff) +1 -1
@@ -140,7 +141,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
 
  static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
  {
-	int max_hw_sectors_kb = queue_max_hw_sectors(q)>>  1;
+	unsigned long max_hw_sectors_kb = queue_max_hw_sectors(q)>>  1;
 
  	return queue_var_show(max_hw_sectors_kb, (page));
  }

The above two aren't necessary but well why not.

Review static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, · line 196

Quoted 9 lines
(quoted diff) +1 -1
@@ -189,7 +190,7 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
 
  static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
  {
-	unsigned int set = test_bit(QUEUE_FLAG_SAME_COMP,&q->queue_flags);
+	unsigned long set = test_bit(QUEUE_FLAG_SAME_COMP,&q->queue_flags);
 
  	return queue_var_show(set != 0, page);
  }

Wouldn't it be better to make it "bool set = " and then remove the "!= 0"?

Quoted 4 lines

Thanks.

From c3c0a8a6db9ff124d700b6d4ebf56bb4069f42c0 Mon Sep 17 00:00:00 2001

From: Xiaotian Feng <[email protected]>
Date: Fri, 17 Jul 2009 15:26:26 +0800
Subject: [PATCH V3] block: sysfs fix mismatched queue_var_{store,show} in 64bit kernel

In blk-sysfs.c, queue_var_store uses unsigned long to store data, but queue_var_show uses unsigned int to show data. This causes,

	# echo 70000000000 > /sys/block/<dev>/queue/read_ahead_kb
	# cat /sys/block/<dev>/queue/read_ahead_kb => get wrong value
---
 block/blk-sysfs.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
block/blk-sysfs.c +6 -5
index b1cd040..418d636 100644
@@ -16,9 +16,9 @@ struct queue_sysfs_entry {
 };
 
 static ssize_t
-queue_var_show(unsigned int var, char *page)
+queue_var_show(unsigned long var, char *page)
 {
-	return sprintf(page, "%d\n", var);
+	return sprintf(page, "%lu\n", var);
 }
 
 static ssize_t
@@ -77,7 +77,8 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)
 
 static ssize_t queue_ra_show(struct request_queue *q, char *page)
 {
-	int ra_kb = q->backing_dev_info.ra_pages << (PAGE_CACHE_SHIFT - 10);
+	unsigned long ra_kb = q->backing_dev_info.ra_pages <<
+					(PAGE_CACHE_SHIFT - 10);
 
 	return queue_var_show(ra_kb, (page));
 }
@@ -189,9 +190,9 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
 
 static ssize_t queue_rq_affinity_show(struct request_queue *q, char *page)
 {
-	unsigned int set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
+	bool set = test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags);
 
-	return queue_var_show(set != 0, page);
+	return queue_var_show(set, page);
 }
 
 static ssize_t
Signature · 1 line
1.6.2.5
#7 lore raw

Hello,

Quoted 2 lines · Danny Feng

Thank you very much for the review, I've attached v3 patch follow
your advices, please help me review.

Thanks. I queued the patch on the following temp block tree.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git tj-block-for-linus

Quoted 2 lines

Another thing on block sysfs is that we can echo some invalid value
(e.g 123abc), should sysfs return -EINVAL for those?

sysfs nodes are only accessible from root and it's customary to not invest too much into safe guarding the input. So, leaving as it is should be fine, I think.

Signature · 1 line
tejun