linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	rt-users <linux-rt-users@vger.kernel.org>,
	Nicolas Pitre <nico@marvell.com>,
	MinChan Kim <minchan.kim@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>, Li Zefan <lizf@cn.fujitsu.com>,
	Jens Axboe <jens.axboe@oracle.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH -rt] Fix kmap_high_get()
Date: Fri, 14 Aug 2009 16:02:53 +0200	[thread overview]
Message-ID: <1250258573.5241.1581.camel@twins> (raw)
In-Reply-To: <1250199243-18677-1-git-send-email-u.kleine-koenig@pengutronix.de>

On Thu, 2009-08-13 at 23:34 +0200, Uwe Kleine-KA?nig wrote:
> This fixes the build failure with ARCH_NEEDS_KMAP_HIGH_GET.
> This is only compile tested.
> 
> Signed-off-by: Uwe Kleine-KA?nig <u.kleine-koenig@pengutronix.de>
> Cc: Nicolas Pitre <nico@marvell.com>
> Cc: MinChan Kim <minchan.kim@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Li Zefan <lizf@cn.fujitsu.com>
> Cc: Jens Axboe <jens.axboe@oracle.com>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org
> ---
> Hello
> 
> this bases on the patch "[PATCH RT 9/6] [RFH] Build failure on
> 2.6.31-rc4-rt1 in mm/highmem.c" earlier in this thread.
> 
> I don't know if kmap_high_get() has to call kmap_account().  Anyone?

I think it should, since it uses kunmap_high() to undo whatever
kmap_high_get() did. Now, if there'd been a kmap_high_put()... :-)

As to the patch, its not quite right.

>From what I understand kmap_high_get() is used to pin a page's kmap iff
it has one, whereas the result of your patch seems to be that it'll
actually create one if its not found.

Something like the below ought to do I guess.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 arch/arm/include/asm/highmem.h |    1 +
 arch/arm/mm/dma-mapping.c      |    2 +-
 mm/highmem.c                   |   50 ++++++++++++++++++---------------------
 3 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h
index 7f36d00..4d9573b 100644
--- a/arch/arm/include/asm/highmem.h
+++ b/arch/arm/include/asm/highmem.h
@@ -19,6 +19,7 @@ extern pte_t *pkmap_page_table;
 
 extern void *kmap_high(struct page *page);
 extern void *kmap_high_get(struct page *page);
+extern void *kmap_high_put(struct page *page);
 extern void kunmap_high(struct page *page);
 
 extern void *kmap(struct page *page);
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 1576176..4a166d9 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -551,7 +551,7 @@ static void dma_cache_maint_contiguous(struct page *page, unsigned long offset,
 		if (vaddr) {
 			vaddr += offset;
 			inner_op(vaddr, vaddr + size);
-			kunmap_high(page);
+			kmap_high_put(page);
 		}
 	}
 
diff --git a/mm/highmem.c b/mm/highmem.c
index 66e915a..b2eaefe 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -75,26 +75,6 @@ pte_t * pkmap_page_table;
 
 static DECLARE_WAIT_QUEUE_HEAD(pkmap_wait);
 
-
-/*
- * Most architectures have no use for kmap_high_get(), so let's abstract
- * the disabling of IRQ out of the locking in that case to save on a
- * potential useless overhead.
- */
-#ifdef ARCH_NEEDS_KMAP_HIGH_GET
-#define lock_kmap()             spin_lock_irq(&kmap_lock)
-#define unlock_kmap()           spin_unlock_irq(&kmap_lock)
-#define lock_kmap_any(flags)    spin_lock_irqsave(&kmap_lock, flags)
-#define unlock_kmap_any(flags)  spin_unlock_irqrestore(&kmap_lock, flags)
-#else
-#define lock_kmap()             spin_lock(&kmap_lock)
-#define unlock_kmap()           spin_unlock(&kmap_lock)
-#define lock_kmap_any(flags)    \
-		do { spin_lock(&kmap_lock); (void)(flags); } while (0)
-#define unlock_kmap_any(flags)  \
-		do { spin_unlock(&kmap_lock); (void)(flags); } while (0)
-#endif
-
 /*
  * Try to free a given kmap slot.
  *
@@ -361,22 +341,38 @@ EXPORT_SYMBOL(kmap_high);
  *
  * Returns the page's current virtual memory address, or NULL if no mapping
  * exists.  When and only when a non null address is returned then a
- * matching call to kunmap_high() is necessary.
+ * matching call to kmap_high_put() is necessary.
  *
  * This can be called from any context.
  */
 void *kmap_high_get(struct page *page)
 {
-	unsigned long vaddr, flags;
+	unsigned long vaddr;
 
-	lock_kmap_any(flags);
+again:
 	vaddr = (unsigned long)page_address(page);
 	if (vaddr) {
-		BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 1);
-		pkmap_count[PKMAP_NR(vaddr)]++;
+		atomic_t *counter = &pkmap_count[PKMAP_NR(vaddr)];
+		if (atomic_inc_not_zero(counter)) {
+			unsigned long vaddr2 = (unsigned long)page_address(page);
+
+			if (likely(vaddr == vaddr2))
+				return (void *)vaddr;
+
+			pkmap_put(counter);
+			goto again;
+		}
 	}
-	unlock_kmap_any(flags);
-	return (void*) vaddr;
+
+	return NULL;
+}
+
+void kmap_high_put(struct page *page)
+{
+	unsigned long vaddr = (unsigned long)page_address(page);
+
+	BUG_ON(!vaddr);
+	pkmap_put(&pkmap_count[PKMAP_NR(vaddr)]);
 }
 #endif
 


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

  reply	other threads:[~2009-08-14 14:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090807203939.GA19374@pengutronix.de>
2009-08-09  9:36 ` [PATCH RT 7/6] include linux/interrupt.h in mm/bounce.c Uwe Kleine-König
     [not found]   ` <1249810600-21946-2-git-send-email-u.kleine-koenig@pengutronix.de>
2009-08-09  9:36     ` [PATCH RT 9/6] [RFH] Build failure on 2.6.31-rc4-rt1 in mm/highmem.c Uwe Kleine-König
2009-08-13 21:34       ` [PATCH] [RFC, RT] fix kmap_high_get Uwe Kleine-König
2009-08-14 14:02         ` Peter Zijlstra [this message]
2009-08-14 15:58           ` [PATCH -rt] Fix kmap_high_get() Nicolas Pitre
2009-08-14 20:13             ` Uwe Kleine-König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1250258573.5241.1581.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=minchan.kim@gmail.com \
    --cc=mingo@elte.hu \
    --cc=nico@marvell.com \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox