From: catalin.marinas@arm.com (Catalin Marinas)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: Do not call flush_cache_user_range with mmap_sem held
Date: Thu, 17 Nov 2011 10:22:05 +0000 [thread overview]
Message-ID: <20111117102205.GF4748@arm.com> (raw)
In-Reply-To: <20111116235024.GH9581@n2100.arm.linux.org.uk>
On Wed, Nov 16, 2011 at 11:50:24PM +0000, Russell King - ARM Linux wrote:
> On Wed, Nov 16, 2011 at 01:23:02PM -0800, Olof Johansson wrote:
> > Agreed. Russell, please consider picking this up -- the bug is very
> > real and it sounds like the objection is vague.
>
> No, it isn't. It's creating an unsafe situation. If we're going to do
> this, we might as well give up on architecture correctness because we're
> throwing out locking correctness.
>
> 1. We look up the VMA.
> 2. We pass the VMA to the cache operation.
> 3. The cache operation dereferences the VMA to obtain the VMA flags.
Not anymore - if you look at the patch, flush_cache_user_range() no
longer gets the vma. We just use the vma to adjust the start/end and
that's done with the mmap_sem down. I won't comment on the rest of your
reply since it's based on the assumption that we pass vma to
flush_cache_user_range().
BTW, we could even go a step further an remove the vma checks entirely,
just use access_ok() since __cpuc_coherent_user_range() can handle
unmapped ranges properly (though it may introduce some latency if some
user app passes a 3G range but we can change the fixup code to abort the
operation when it gets a fault that can't be fixed up).
diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
index d5d8d5c..1252a26 100644
--- a/arch/arm/include/asm/cacheflush.h
+++ b/arch/arm/include/asm/cacheflush.h
@@ -249,7 +249,7 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr
* Harvard caches are synchronised for the user space address range.
* This is used for the ARM private sys_cacheflush system call.
*/
-#define flush_cache_user_range(vma,start,end) \
+#define flush_cache_user_range(start,end) \
__cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
/*
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 99a5727..b215e39 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -474,23 +474,12 @@ static int bad_syscall(int n, struct pt_regs *regs)
static inline void
do_cache_op(unsigned long start, unsigned long end, int flags)
{
- struct mm_struct *mm = current->active_mm;
- struct vm_area_struct *vma;
-
if (end < start || flags)
return;
+ if (!access_ok(VERIFY_WRITE, start, end - start))
+ return;
- down_read(&mm->mmap_sem);
- vma = find_vma(mm, start);
- if (vma && vma->vm_start < end) {
- if (start < vma->vm_start)
- start = vma->vm_start;
- if (end > vma->vm_end)
- end = vma->vm_end;
-
- flush_cache_user_range(vma, start, end);
- }
- up_read(&mm->mmap_sem);
+ flush_cache_user_range(start, end);
}
/*
@@ -816,6 +805,6 @@ void __init early_trap_init(void)
memcpy((void *)(vectors + KERN_RESTART_CODE - CONFIG_VECTORS_BASE),
syscall_restart_code, sizeof(syscall_restart_code));
- flush_icache_range(vectors, vectors + PAGE_SIZE);
+ flush_icache_range(CONFIG_VECTORS_BASE, CONFIG_VECTORS_BASE+PAGE_SIZE);
modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
}
--
Catalin
next prev parent reply other threads:[~2011-11-17 10:22 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-07 17:33 [PATCH] ARM: Do not call flush_cache_user_range with mmap_sem held Catalin Marinas
2011-11-16 21:23 ` Olof Johansson
2011-11-16 23:50 ` Russell King - ARM Linux
2011-11-17 0:16 ` Olof Johansson
2011-11-17 0:20 ` Olof Johansson
2011-11-17 10:26 ` Catalin Marinas
2011-11-17 10:49 ` Russell King - ARM Linux
2011-11-17 10:45 ` Russell King - ARM Linux
2011-11-20 17:54 ` Olof Johansson
2011-11-17 10:22 ` Catalin Marinas [this message]
2011-11-17 10:42 ` Russell King - ARM Linux
2011-11-17 10:59 ` Catalin Marinas
2011-11-17 11:03 ` Russell King - ARM Linux
2011-11-17 11:25 ` Catalin Marinas
2012-04-09 5:58 ` Dirk Behme
2012-04-09 14:24 ` Olof Johansson
2012-04-10 17:17 ` Will Deacon
2012-04-18 15:05 ` Will Deacon
2012-04-18 15:27 ` Russell King - ARM Linux
2012-04-18 16:27 ` Will Deacon
2012-04-18 17:15 ` Catalin Marinas
2012-04-18 8:40 ` Catalin Marinas
-- strict thread matches above, loose matches on Subject: below --
2010-04-28 7:32 [PATCH] [ARM] " Dima Zavin
2010-04-28 7:35 ` Dima Zavin
2010-04-29 13:00 ` Russell King - ARM Linux
2010-04-29 18:16 ` Jamie Lokier
2010-04-29 18:24 ` Russell King - ARM Linux
2010-04-29 19:23 ` Dima Zavin
2010-05-04 4:07 ` Dima Zavin
2010-05-04 7:40 ` Russell King - ARM Linux
2010-05-06 15:08 ` Catalin Marinas
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=20111117102205.GF4748@arm.com \
--to=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.