Skip to contentSkip to conversation

mm: BUG when __kmap_atomic_idx equals KM_TYPE_NR

PATCH In review Chintan Pandya 3 participants 5 messages Jul 31, 2014 – Aug 4, 2014

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

PATCH v2 1/1 mm: BUG when __kmap_atomic_idx equals KM_TYPE_NR

__kmap_atomic_idx is per_cpu variable. Each CPU can use KM_TYPE_NR entries from FIXMAP i.e. from 0 to KM_TYPE_NR - 1. Allowing __kmap_atomic_idx to over- shoot to KM_TYPE_NR can mess up with next CPU's 0th entry which is a bug. Hence BUG_ON if __kmap_atomic_idx >= KM_TYPE_NR.

---
Changes:

V1 --> V2

Not touching CONFIG_DEBUG_HIGHMEM.

 include/linux/highmem.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/highmem.h +1 -1
index 7fb31da..9286a46 100644
@@ -93,7 +93,7 @@ static inline int kmap_atomic_idx_push(void)
 
 #ifdef CONFIG_DEBUG_HIGHMEM
 	WARN_ON_ONCE(in_irq() && !irqs_disabled());
-	BUG_ON(idx > KM_TYPE_NR);
+	BUG_ON(idx >= KM_TYPE_NR);
 #endif
 	return idx;
 }
Signature · 4 lines
Chintan Pandya

QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 7 lines · Chintan Pandya

__kmap_atomic_idx is per_cpu variable. Each CPU can use KM_TYPE_NR entries from FIXMAP i.e. from 0 to KM_TYPE_NR - 1. Allowing __kmap_atomic_idx to over- shoot to KM_TYPE_NR can mess up with next CPU's 0th entry which is a bug. Hence BUG_ON if __kmap_atomic_idx >= KM_TYPE_NR.

This appears to be a completely different patch, not a v2. Why is this check only done for CONFIG_DEBUG_HIGHMEM?

I think Andrew's comment earlier was referring to the changelog only and not the patch, which looked correct.

Quoted 16 lines

---
Changes:

V1 --> V2

Not touching CONFIG_DEBUG_HIGHMEM.

 include/linux/highmem.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/highmem.h +0 -0
index 7fb31da..9286a46 100644

include/linux/highmem.h static inline int kmap_atomic_idx_push(void) · line 99

Quoted 8 lines
include/linux/highmem.h +1 -1
@@ -93,7 +93,7 @@ static inline int kmap_atomic_idx_push(void)
 
 #ifdef CONFIG_DEBUG_HIGHMEM
 	WARN_ON_ONCE(in_irq() && !irqs_disabled());
-	BUG_ON(idx > KM_TYPE_NR);
+	BUG_ON(idx >= KM_TYPE_NR);
 #endif
 	return idx;
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 10 lines · David Rientjes
Quoted 7 lines · Chintan Pandya

__kmap_atomic_idx is per_cpu variable. Each CPU can use KM_TYPE_NR entries from FIXMAP i.e. from 0 to KM_TYPE_NR - 1. Allowing __kmap_atomic_idx to over- shoot to KM_TYPE_NR can mess up with next CPU's 0th entry which is a bug. Hence BUG_ON if __kmap_atomic_idx>= KM_TYPE_NR.

Quoted 2 lines

This appears to be a completely different patch, not a v2. Why is this check only done for CONFIG_DEBUG_HIGHMEM?

I agree that this check could have been there even without CONFIG_DEBUG_HIGHMEM for stability reasons.

Quoted 3 lines

I think Andrew's comment earlier was referring to the changelog only and not the patch, which looked correct.

I think Andrew asked for a BUG case details also to justify the overhead. But we have never encountered that BUG case. Present patch is only logical fix to the code. However, in the fast path, if such overhead is allowed, I can move BUG_ON out of any debug configs. Otherwise, as per Andrew's suggestion, I will convert DEBUG_HIGHMEM into DEBUG_VM which is used more frequently.

Quoted 5 lines
Quoted 5 lines

---
Changes:

Signature · 8 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#3 lore raw
Quoted 10 lines · On Thu, 31 Jul 2014 14:58:58 +0530 Chintan Pandya <[email protected]>…
Quoted 3 lines

I think Andrew's comment earlier was referring to the changelog only and not the patch, which looked correct.

I think Andrew asked for a BUG case details also to justify the overhead. But we have never encountered that BUG case. Present patch is only logical fix to the code. However, in the fast path, if such overhead is allowed, I can move BUG_ON out of any debug configs. Otherwise, as per Andrew's suggestion, I will convert DEBUG_HIGHMEM into DEBUG_VM which is used more frequently.

The v1 patch added a small amount of overhead to kmap_atomic() for what is evidently a very small benefit.

Yes, I suggest we remove CONFIG_DEBUG_HIGHMEM from the kernel entirely and switch all CONFIG_DEBUG_HIGHMEM sites to use CONFIG_DEBUG_VM. That way the BUG_ON which you believe is useful will be tested by more people more often.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 13 lines · Andrew Morton
Quoted 10 lines · On Thu, 31 Jul 2014 14:58:58 +0530 Chintan Pandya<[email protected]>…
Quoted 3 lines

I think Andrew's comment earlier was referring to the changelog only and not the patch, which looked correct.

I think Andrew asked for a BUG case details also to justify the overhead. But we have never encountered that BUG case. Present patch is only logical fix to the code. However, in the fast path, if such overhead is allowed, I can move BUG_ON out of any debug configs. Otherwise, as per Andrew's suggestion, I will convert DEBUG_HIGHMEM into DEBUG_VM which is used more frequently.

Quoted 7 lines

The v1 patch added a small amount of overhead to kmap_atomic() for what is evidently a very small benefit.

Yes, I suggest we remove CONFIG_DEBUG_HIGHMEM from the kernel entirely and switch all CONFIG_DEBUG_HIGHMEM sites to use CONFIG_DEBUG_VM. That way the BUG_ON which you believe is useful will be tested by more people more often.

Ping!! Anything open for me to do here ?

Signature · 4 lines
Chintan Pandya

QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation