2009-10-28 17:53:53

by Soeren Sandmann

[permalink] [raw]
Subject: [PATCH 0/2] Some fixes to debug_kmap_atomic()

Hi,

Here are two patches that fix an issue with debug_kmap_atomic().

The first one is a pretty straightforward fix for a race that can
cause an underflow, which in turn causes the stream of warnings to
never end.

The second patch extends debug_kmap_atomic() to deal with KM_IRQ_PTE,
KM_NMI, and KM_NMI_PTE.

I was seeing this because the __get_user_pages_fast() in
arch/x86/kernel/cpu/perf_events.c ends up eventually calling
kmap_atomic() with KM_PTE, which, with CONFIG_HIGHPTE enabled, ends up
expanding to:

#define __KM_PTE \
(in_nmi() ? KM_NMI_PTE : \
in_irq() ? KM_IRQ_PTE : \
KM_PTE0)

and those KM_* types are not handled

For the second patch, I am basically pattern matching, so I might be
completely wrong.


Thanks,
Soren


2009-10-28 17:55:33

by Soeren Sandmann

[permalink] [raw]
Subject: [PATCH 1/2] Fix race in debug_kmap_atomic() which could cause warn_count to underflow

debug_kmap_atomic() tries to prevent ever printing more than 10
warnings, but it does so by testing whether an unsigned integer is
equal to 0. However, if the warning is caused by a nested IRQ, then
this counter may underflow and the stream of warnings will never end.

Fix that by using a signed integer instead.

Signed-off-by: Søren Sandmann Pedersen <[email protected]>
---
mm/highmem.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/highmem.c b/mm/highmem.c
index 25878cc..33587de 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -426,9 +426,9 @@ void __init page_address_init(void)

void debug_kmap_atomic(enum km_type type)
{
- static unsigned warn_count = 10;
+ static int warn_count = 10;

- if (unlikely(warn_count == 0))
+ if (unlikely(warn_count < 0))
return;

if (unlikely(in_interrupt())) {
--
1.6.5.1

2009-10-28 17:56:34

by Soeren Sandmann

[permalink] [raw]
Subject: [PATCH 2/2] Fix debug_kmap_atomic() to also handle KM_IRQ_PTE, KM_NMI, and KM_NMI_PTE

Previously calling debug_kmap_atomic() with these types would cause
spurious warnings.

Signed-off-by: Søren Sandmann Pedersen <[email protected]>
---
mm/highmem.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/mm/highmem.c b/mm/highmem.c
index 33587de..9c1e627 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -432,10 +432,15 @@ void debug_kmap_atomic(enum km_type type)
return;

if (unlikely(in_interrupt())) {
- if (in_irq()) {
+ if (in_nmi()) {
+ if (type != KM_NMI && type != KM_NMI_PTE) {
+ WARN_ON(1);
+ warn_count--;
+ }
+ } else if (in_irq()) {
if (type != KM_IRQ0 && type != KM_IRQ1 &&
type != KM_BIO_SRC_IRQ && type != KM_BIO_DST_IRQ &&
- type != KM_BOUNCE_READ) {
+ type != KM_BOUNCE_READ && type != KM_IRQ_PTE) {
WARN_ON(1);
warn_count--;
}
@@ -452,7 +457,9 @@ void debug_kmap_atomic(enum km_type type)
}

if (type == KM_IRQ0 || type == KM_IRQ1 || type == KM_BOUNCE_READ ||
- type == KM_BIO_SRC_IRQ || type == KM_BIO_DST_IRQ) {
+ type == KM_BIO_SRC_IRQ || type == KM_BIO_DST_IRQ ||
+ type == KM_IRQ_PTE || type == KM_NMI ||
+ type == KM_NMI_PTE ) {
if (!irqs_disabled()) {
WARN_ON(1);
warn_count--;
--
1.6.5.1

2009-10-29 09:07:42

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 0/2] Some fixes to debug_kmap_atomic()


* Soeren Sandmann <[email protected]> wrote:

> Hi,
>
> Here are two patches that fix an issue with debug_kmap_atomic().

hm, have you seen this patch from Peter on lkml:

[RFC][PATCH] kmap_atomic_push

which eliminates debug_kmap_atomic().

Ingo

2009-10-29 14:33:37

by Soeren Sandmann

[permalink] [raw]
Subject: Re: [PATCH 0/2] Some fixes to debug_kmap_atomic()

Ingo Molnar <[email protected]> writes:

> hm, have you seen this patch from Peter on lkml:
>
> [RFC][PATCH] kmap_atomic_push
>
> which eliminates debug_kmap_atomic().

I hadn't; that would work as well, though fixing the infinite stream
of warning is maybe embarrassing enough that it should be in 2.6.32?


Soren

2009-11-10 03:19:55

by Soeren Sandmann

[permalink] [raw]
Subject: [tip:core/urgent] highmem: Fix race in debug_kmap_atomic() which could cause warn_count to underflow

Commit-ID: 5ebd4c22897dce65845807a9bd3a31cc4e142b53
Gitweb: http://git.kernel.org/tip/5ebd4c22897dce65845807a9bd3a31cc4e142b53
Author: Soeren Sandmann <[email protected]>
AuthorDate: Wed, 28 Oct 2009 18:55:36 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 04:15:32 +0100

highmem: Fix race in debug_kmap_atomic() which could cause warn_count to underflow

debug_kmap_atomic() tries to prevent ever printing more than 10
warnings, but it does so by testing whether an unsigned integer
is equal to 0. However, if the warning is caused by a nested
IRQ, then this counter may underflow and the stream of warnings
will never end.

Fix that by using a signed integer instead.

Signed-off-by: Soeren Sandmann Pedersen <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: [email protected]
Cc: <[email protected]> # .31.x
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
mm/highmem.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/highmem.c b/mm/highmem.c
index 25878cc..33587de 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -426,9 +426,9 @@ void __init page_address_init(void)

void debug_kmap_atomic(enum km_type type)
{
- static unsigned warn_count = 10;
+ static int warn_count = 10;

- if (unlikely(warn_count == 0))
+ if (unlikely(warn_count < 0))
return;

if (unlikely(in_interrupt())) {

2009-11-10 03:21:30

by Soeren Sandmann

[permalink] [raw]
Subject: [tip:core/urgent] highmem: Fix debug_kmap_atomic() to also handle KM_IRQ_PTE, KM_NMI, and KM_NMI_PTE

Commit-ID: d4515646699b6ad7b1a98ceb871296b957f3ef47
Gitweb: http://git.kernel.org/tip/d4515646699b6ad7b1a98ceb871296b957f3ef47
Author: Soeren Sandmann <[email protected]>
AuthorDate: Wed, 28 Oct 2009 18:56:35 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Nov 2009 04:15:47 +0100

highmem: Fix debug_kmap_atomic() to also handle KM_IRQ_PTE, KM_NMI, and KM_NMI_PTE

Previously calling debug_kmap_atomic() with these types would
cause spurious warnings.

(triggered by SysProf using perf events)

Signed-off-by: Soeren Sandmann Pedersen <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: [email protected]
Cc: <[email protected]> # .31.x
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
mm/highmem.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/mm/highmem.c b/mm/highmem.c
index 33587de..9c1e627 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -432,10 +432,15 @@ void debug_kmap_atomic(enum km_type type)
return;

if (unlikely(in_interrupt())) {
- if (in_irq()) {
+ if (in_nmi()) {
+ if (type != KM_NMI && type != KM_NMI_PTE) {
+ WARN_ON(1);
+ warn_count--;
+ }
+ } else if (in_irq()) {
if (type != KM_IRQ0 && type != KM_IRQ1 &&
type != KM_BIO_SRC_IRQ && type != KM_BIO_DST_IRQ &&
- type != KM_BOUNCE_READ) {
+ type != KM_BOUNCE_READ && type != KM_IRQ_PTE) {
WARN_ON(1);
warn_count--;
}
@@ -452,7 +457,9 @@ void debug_kmap_atomic(enum km_type type)
}

if (type == KM_IRQ0 || type == KM_IRQ1 || type == KM_BOUNCE_READ ||
- type == KM_BIO_SRC_IRQ || type == KM_BIO_DST_IRQ) {
+ type == KM_BIO_SRC_IRQ || type == KM_BIO_DST_IRQ ||
+ type == KM_IRQ_PTE || type == KM_NMI ||
+ type == KM_NMI_PTE ) {
if (!irqs_disabled()) {
WARN_ON(1);
warn_count--;