Skip to contentSkip to conversation

ext4: signedness bug breaks ext4_inode_touch_time_cmp()

PATCH In review Dan Carpenter 3 participants 4 messages Jun 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: signedness bug breaks ext4_inode_touch_time_cmp()

"diff" is unsigned so this doesn't sort the LRU list correctly.

---
This was introduced in 6480bad916be "ext4: improve extent cache shrink mechanism to avoid to burn CPU time"

fs/ext4/extents_status.c +1 -1
index e0190f6..79e097d 100644
@@ -880,7 +880,7 @@ static int ext4_inode_touch_time_cmp(void *priv, struct list_head *a,
 				     struct list_head *b)
 {
 	struct ext4_inode_info *eia, *eib;
-	unsigned long diff;
+	long diff;
 
 	eia = list_entry(a, struct ext4_inode_info, i_es_lru);
 	eib = list_entry(b, struct ext4_inode_info, i_es_lru);
maintainer
#1 lore raw
Quoted 6 lines · Dan Carpenter

"diff" is unsigned so this doesn't sort the LRU list correctly.

---
This was introduced in 6480bad916be "ext4: improve extent cache shrink mechanism to avoid to burn CPU time"

Thanks for pointing this out! The following patch is better I think because it uses the time_after() abstraction. I will be folding the following into Zheng's "ext4: improve extent cache shrink > mechanism to avoid to burn CPU time".

I've desk checked this but we may want to do some explicit testing to make sure we are in fact ejecting the appropriate inode from the list.

- Ted

 fs/ext4/extents_status.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
fs/ext4/extents_status.c +5 -7
index 80dcc59..ee018d5 100644
@@ -880,17 +880,15 @@ static int ext4_inode_touch_time_cmp(void *priv, struct list_head *a,
 				     struct list_head *b)
 {
 	struct ext4_inode_info *eia, *eib;
-	unsigned long diff;
-
 	eia = list_entry(a, struct ext4_inode_info, i_es_lru);
 	eib = list_entry(b, struct ext4_inode_info, i_es_lru);
 
-	diff = eia->i_touch_when - eib->i_touch_when;
-	if (diff < 0)
-		return -1;
-	if (diff > 0)
+	if (eia->i_touch_when = eib->i_touch_when)
+		return 0;
+	if (time_after(eia->i_touch_when, eib->i_touch_when))
 		return 1;
-	return 0;
+	else
+		return -1;
 }
 
 static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
Reviewed-by
#2 lore raw
Quoted 8 lines · Theodore Ts'o
Quoted 6 lines · Dan Carpenter

"diff" is unsigned so this doesn't sort the LRU list correctly.

---
This was introduced in 6480bad916be "ext4: improve extent cache shrink mechanism to avoid to burn CPU time"

Quoted 4 lines

Thanks for pointing this out! The following patch is better I think because it uses the time_after() abstraction. I will be folding the following into Zheng's "ext4: improve extent cache shrink > mechanism to avoid to burn CPU time".

Thanks for fixing it. The patch looks good to me.

Quoted 3 lines

I've desk checked this but we may want to do some explicit testing to make sure we are in fact ejecting the appropriate inode from the list.

I will check it tomorrow. If there still has a problem, I will try to fix it.

- Zheng

Quoted 37 lines

- Ted

 fs/ext4/extents_status.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
fs/ext4/extents_status.c +5 -8
index 80dcc59..ee018d5 100644
@@ -880,17 +880,15 @@ static int ext4_inode_touch_time_cmp(void *priv, struct list_head *a,
 				     struct list_head *b)
 {
 	struct ext4_inode_info *eia, *eib;
-	unsigned long diff;
-
 	eia = list_entry(a, struct ext4_inode_info, i_es_lru);
 	eib = list_entry(b, struct ext4_inode_info, i_es_lru);
 
-	diff = eia->i_touch_when - eib->i_touch_when;
-	if (diff < 0)
-		return -1;
-	if (diff > 0)
+	if (eia->i_touch_when = eib->i_touch_when)
+		return 0;
+	if (time_after(eia->i_touch_when, eib->i_touch_when))
 		return 1;
-	return 0;
+	else
+		return -1;
 }
 
 static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
--

To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Dan Carpenter
Quoted 3 lines · Dan Carpenter

"diff" is unsigned so this doesn't sort the LRU list correctly.

Thanks for fixing it.

Regards,
- Zheng

Quoted 21 lines

---
This was introduced in 6480bad916be "ext4: improve extent cache shrink mechanism to avoid to burn CPU time"

fs/ext4/extents_status.c +1 -2
index e0190f6..79e097d 100644
@@ -880,7 +880,7 @@ static int ext4_inode_touch_time_cmp(void *priv, struct list_head *a,
 				     struct list_head *b)
 {
 	struct ext4_inode_info *eia, *eib;
-	unsigned long diff;
+	long diff;
 
 	eia = list_entry(a, struct ext4_inode_info, i_es_lru);
 	eib = list_entry(b, struct ext4_inode_info, i_es_lru);
--

To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html