2014-07-31 06:24:44

by Chintan Pandya

[permalink] [raw]
Subject: [PATCH v2] 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.

Signed-off-by: Chintan Pandya <[email protected]>
---
Changes:

V1 --> V2

Not touching CONFIG_DEBUG_HIGHMEM.

include/linux/highmem.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 7fb31da..9286a46 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -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;
}
--
Chintan Pandya

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


2014-07-31 07:02:42

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH v2] mm: BUG when __kmap_atomic_idx equals KM_TYPE_NR

On Thu, 31 Jul 2014, Chintan Pandya wrote:

> __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.

> Signed-off-by: Chintan Pandya <[email protected]>
> ---
> Changes:
>
> V1 --> V2
>
> Not touching CONFIG_DEBUG_HIGHMEM.
>
> include/linux/highmem.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 7fb31da..9286a46 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -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;
> }

2014-07-31 09:29:06

by Chintan Pandya

[permalink] [raw]
Subject: Re: [PATCH v2] mm: BUG when __kmap_atomic_idx equals KM_TYPE_NR

On 07/31/2014 12:32 PM, David Rientjes wrote:
> On Thu, 31 Jul 2014, Chintan Pandya wrote:
>
>> __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 agree that this check could have been there even without
CONFIG_DEBUG_HIGHMEM for stability reasons.

>
> 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.

>
>> Signed-off-by: Chintan Pandya<[email protected]>
>> ---
>> Changes:
>>



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

2014-07-31 22:45:43

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH v2] mm: BUG when __kmap_atomic_idx equals KM_TYPE_NR

On Thu, 31 Jul 2014 14:58:58 +0530 Chintan Pandya <[email protected]> wrote:

> >
> > 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.