From: Adam Iwaniuk <adami@cubiware.com>
To: linux-sh@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Adam Iwaniuk <adami@cubiware.com>
Subject: [PATCH] sh: fix mmap_sem deadlock in sys_cacheflush
Date: Mon, 13 Oct 2014 11:59:12 +0000 [thread overview]
Message-ID: <1413201552-2730-1-git-send-email-adami@cubiware.com> (raw)
From: Adam Iwaniuk <adami@cubiware.com>
We can't be holding the mmap_sem while calling __flush_XXX_region/flush_icache_range
because the flush can fault. If we fault on a user address, the page fault handler
will try to take mmap_sem again. Since both places acquire the read lock, most of the
time it succeeds. However, if another thread tries to acquire the write lock on the
mmap_sem (e.g. mmap) in between the call to __flush_XXX_region/flush_icache_range and
the fault, the down_read in do_page_fault will deadlock.
Signed-off-by: Adam Iwaniuk <adami@cubiware.com>
---
arch/sh/kernel/sys_sh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sh/kernel/sys_sh.c b/arch/sh/kernel/sys_sh.c
index 8c6a350..4aa294c 100644
--- a/arch/sh/kernel/sys_sh.c
+++ b/arch/sh/kernel/sys_sh.c
@@ -74,6 +74,7 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
up_read(¤t->mm->mmap_sem);
return -EFAULT;
}
+ up_read(¤t->mm->mmap_sem);
switch (op & CACHEFLUSH_D_PURGE) {
case CACHEFLUSH_D_INVAL:
@@ -90,6 +91,5 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
if (op & CACHEFLUSH_I)
flush_icache_range(addr, addr+len);
- up_read(¤t->mm->mmap_sem);
return 0;
}
--
1.7.9.5
reply other threads:[~2014-10-13 11:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1413201552-2730-1-git-send-email-adami@cubiware.com \
--to=adami@cubiware.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).