* [PATCH v3] ANDROID: binder: change down_write to down_read
@ 2018-03-29 2:37 Minchan Kim
2018-03-29 2:42 ` Minchan Kim
2018-03-29 23:42 ` kbuild test robot
0 siblings, 2 replies; 6+ messages in thread
From: Minchan Kim @ 2018-03-29 2:37 UTC (permalink / raw)
To: LKML
Cc: Minchan Kim, Todd Kjos, Greg Kroah-Hartman,
Arve Hjønnevåg, Martijn Coenen
binder_update_page_range needs down_write of mmap_sem because
vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless
it is set. However, when I profile binder working, it seems
every binder buffers should be mapped in advance by binder_mmap.
It means we could set VM_MIXEDMAP in bider_mmap time which is
already hold a mmap_sem as down_write so binder_update_page_range
doesn't need to hold a mmap_sem as down_write.
Android suffers from mmap_sem contention so let's reduce mmap_sem
down_write.
Cc: Todd Kjos <tkjos@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arve Hjønnevåg <arve@android.com>
Reviewed-by: Martijn Coenen <maco@android.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
>From v2:
* Fix vma->flag setting - Arve
>From v1:
* remove WARN_ON_ONCE - Greg
* add reviewed-by - Martijn
Martijn, I took your LGTM of v1 as Reviewed-by. If you don't like it
or want to change it to acked-by, please, tell me.
drivers/android/binder.c | 3 ++-
drivers/android/binder_alloc.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 764b63a5aade..875ab21fa2e0 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -4722,7 +4722,8 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
failure_string = "bad vm_flags";
goto err_bad_arg;
}
- vma->vm_flags = (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE;
+ vma->vm_flags = (vma->flags | VM_DONTCOPY | VM_MIXEDMAP) &
+ ~VM_MAYWRITE;
vma->vm_ops = &binder_vm_ops;
vma->vm_private_data = proc;
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 5a426c877dfb..4f382d51def1 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -219,7 +219,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
mm = alloc->vma_vm_mm;
if (mm) {
- down_write(&mm->mmap_sem);
+ down_read(&mm->mmap_sem);
vma = alloc->vma;
}
@@ -288,7 +288,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
/* vm_insert_page does not seem to increment the refcount */
}
if (mm) {
- up_write(&mm->mmap_sem);
+ up_read(&mm->mmap_sem);
mmput(mm);
}
return 0;
@@ -321,7 +321,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
}
err_no_vma:
if (mm) {
- up_write(&mm->mmap_sem);
+ up_read(&mm->mmap_sem);
mmput(mm);
}
return vma ? -ENOMEM : -ESRCH;
--
2.17.0.rc1.321.gba9d0f2565-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ANDROID: binder: change down_write to down_read
2018-03-29 2:37 [PATCH v3] ANDROID: binder: change down_write to down_read Minchan Kim
@ 2018-03-29 2:42 ` Minchan Kim
2018-03-29 4:15 ` Greg Kroah-Hartman
2018-03-29 23:42 ` kbuild test robot
1 sibling, 1 reply; 6+ messages in thread
From: Minchan Kim @ 2018-03-29 2:42 UTC (permalink / raw)
To: LKML
Cc: Todd Kjos, Greg Kroah-Hartman, Arve Hjønnevåg, Martijn Coenen
On Thu, Mar 29, 2018 at 11:37:12AM +0900, Minchan Kim wrote:
> binder_update_page_range needs down_write of mmap_sem because
> vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless
> it is set. However, when I profile binder working, it seems
> every binder buffers should be mapped in advance by binder_mmap.
> It means we could set VM_MIXEDMAP in bider_mmap time which is
> already hold a mmap_sem as down_write so binder_update_page_range
> doesn't need to hold a mmap_sem as down_write.
>
> Android suffers from mmap_sem contention so let's reduce mmap_sem
> down_write.
>
> Cc: Todd Kjos <tkjos@google.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Arve Hjønnevåg <arve@android.com>
> Reviewed-by: Martijn Coenen <maco@android.com>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
Sent wrong version. Sorry for that. Please ignore this and take it.
>From 480e992d4a650fb98e1397114d75dea7af8e6d0c Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@kernel.org>
Date: Wed, 28 Mar 2018 11:32:42 +0900
Subject: [PATCH v3] ANDROID: binder: change down_write to down_read
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
binder_update_page_range needs down_write of mmap_sem because
vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless
it is set. However, when I profile binder working, it seems
every binder buffers should be mapped in advance by binder_mmap.
It means we could set VM_MIXEDMAP in bider_mmap time which is
already hold a mmap_sem as down_write so binder_update_page_range
doesn't need to hold a mmap_sem as down_write.
Android suffers from mmap_sem contention so let's reduce mmap_sem
down_write.
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Todd Kjos <tkjos@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Martijn Coenen <maco@android.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
>From v2:
* Fix vma->flag setting - Arve
>From v1:
* remove WARN_ON_ONCE - Greg
* add reviewed-by - Martijn
Martijn, I took your LGTM of v1 as Reviewed-by. If you don't like it
or want to change it to acked-by, please, tell me.
drivers/android/binder.c | 3 ++-
drivers/android/binder_alloc.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 764b63a5aade..fe62be7d7113 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -4722,7 +4722,8 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
failure_string = "bad vm_flags";
goto err_bad_arg;
}
- vma->vm_flags = (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE;
+ vma->vm_flags = (vma->vm_flags | VM_DONTCOPY | VM_MIXEDMAP) &
+ ~VM_MAYWRITE;
vma->vm_ops = &binder_vm_ops;
vma->vm_private_data = proc;
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 5a426c877dfb..4f382d51def1 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -219,7 +219,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
mm = alloc->vma_vm_mm;
if (mm) {
- down_write(&mm->mmap_sem);
+ down_read(&mm->mmap_sem);
vma = alloc->vma;
}
@@ -288,7 +288,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
/* vm_insert_page does not seem to increment the refcount */
}
if (mm) {
- up_write(&mm->mmap_sem);
+ up_read(&mm->mmap_sem);
mmput(mm);
}
return 0;
@@ -321,7 +321,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
}
err_no_vma:
if (mm) {
- up_write(&mm->mmap_sem);
+ up_read(&mm->mmap_sem);
mmput(mm);
}
return vma ? -ENOMEM : -ESRCH;
--
2.17.0.rc1.321.gba9d0f2565-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ANDROID: binder: change down_write to down_read
2018-03-29 2:42 ` Minchan Kim
@ 2018-03-29 4:15 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2018-03-29 4:15 UTC (permalink / raw)
To: Minchan Kim; +Cc: LKML, Todd Kjos, Arve Hjønnevåg, Martijn Coenen
On Thu, Mar 29, 2018 at 11:42:04AM +0900, Minchan Kim wrote:
>
> On Thu, Mar 29, 2018 at 11:37:12AM +0900, Minchan Kim wrote:
> > binder_update_page_range needs down_write of mmap_sem because
> > vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless
> > it is set. However, when I profile binder working, it seems
> > every binder buffers should be mapped in advance by binder_mmap.
> > It means we could set VM_MIXEDMAP in bider_mmap time which is
> > already hold a mmap_sem as down_write so binder_update_page_range
> > doesn't need to hold a mmap_sem as down_write.
> >
> > Android suffers from mmap_sem contention so let's reduce mmap_sem
> > down_write.
> >
> > Cc: Todd Kjos <tkjos@google.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Arve Hjønnevåg <arve@android.com>
> > Reviewed-by: Martijn Coenen <maco@android.com>
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
>
> Sent wrong version. Sorry for that. Please ignore this and take it.
>
> >From 480e992d4a650fb98e1397114d75dea7af8e6d0c Mon Sep 17 00:00:00 2001
> From: Minchan Kim <minchan@kernel.org>
> Date: Wed, 28 Mar 2018 11:32:42 +0900
> Subject: [PATCH v3] ANDROID: binder: change down_write to down_read
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
<snip>
I really don't want to hand-edit patches, please just send v4.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ANDROID: binder: change down_write to down_read
2018-03-29 2:37 [PATCH v3] ANDROID: binder: change down_write to down_read Minchan Kim
2018-03-29 2:42 ` Minchan Kim
@ 2018-03-29 23:42 ` kbuild test robot
2018-03-30 0:37 ` Minchan Kim
1 sibling, 1 reply; 6+ messages in thread
From: kbuild test robot @ 2018-03-29 23:42 UTC (permalink / raw)
To: Minchan Kim
Cc: kbuild-all, LKML, Minchan Kim, Todd Kjos, Greg Kroah-Hartman,
Arve Hjønnevåg, Martijn Coenen
[-- Attachment #1: Type: text/plain, Size: 2606 bytes --]
Hi Minchan,
I love your patch! Yet something to improve:
[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.16-rc7 next-20180329]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Minchan-Kim/ANDROID-binder-change-down_write-to-down_read/20180330-043057
config: x86_64-randconfig-x014-201812 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers//android/binder.c: In function 'binder_mmap':
>> drivers//android/binder.c:4725:24: error: 'struct vm_area_struct' has no member named 'flags'; did you mean 'vm_flags'?
vma->vm_flags = (vma->flags | VM_DONTCOPY | VM_MIXEDMAP) &
^~~~~
vm_flags
vim +4725 drivers//android/binder.c
4701
4702 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
4703 {
4704 int ret;
4705 struct binder_proc *proc = filp->private_data;
4706 const char *failure_string;
4707
4708 if (proc->tsk != current->group_leader)
4709 return -EINVAL;
4710
4711 if ((vma->vm_end - vma->vm_start) > SZ_4M)
4712 vma->vm_end = vma->vm_start + SZ_4M;
4713
4714 binder_debug(BINDER_DEBUG_OPEN_CLOSE,
4715 "%s: %d %lx-%lx (%ld K) vma %lx pagep %lx\n",
4716 __func__, proc->pid, vma->vm_start, vma->vm_end,
4717 (vma->vm_end - vma->vm_start) / SZ_1K, vma->vm_flags,
4718 (unsigned long)pgprot_val(vma->vm_page_prot));
4719
4720 if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
4721 ret = -EPERM;
4722 failure_string = "bad vm_flags";
4723 goto err_bad_arg;
4724 }
> 4725 vma->vm_flags = (vma->flags | VM_DONTCOPY | VM_MIXEDMAP) &
4726 ~VM_MAYWRITE;
4727 vma->vm_ops = &binder_vm_ops;
4728 vma->vm_private_data = proc;
4729
4730 ret = binder_alloc_mmap_handler(&proc->alloc, vma);
4731 if (ret)
4732 return ret;
4733 mutex_lock(&proc->files_lock);
4734 proc->files = get_files_struct(current);
4735 mutex_unlock(&proc->files_lock);
4736 return 0;
4737
4738 err_bad_arg:
4739 pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
4740 proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
4741 return ret;
4742 }
4743
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30419 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ANDROID: binder: change down_write to down_read
2018-03-29 23:42 ` kbuild test robot
@ 2018-03-30 0:37 ` Minchan Kim
2018-03-30 2:15 ` Fengguang Wu
0 siblings, 1 reply; 6+ messages in thread
From: Minchan Kim @ 2018-03-30 0:37 UTC (permalink / raw)
To: kbuild test robot
Cc: kbuild-all, LKML, Todd Kjos, Greg Kroah-Hartman,
Arve Hjønnevåg, Martijn Coenen
On Fri, Mar 30, 2018 at 07:42:37AM +0800, kbuild test robot wrote:
> Hi Minchan,
>
> I love your patch! Yet something to improve:
Glad to hear.
It's first time someone loves my patch. ;-)
>
> [auto build test ERROR on staging/staging-testing]
> [also build test ERROR on v4.16-rc7 next-20180329]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url: https://github.com/0day-ci/linux/commits/Minchan-Kim/ANDROID-binder-change-down_write-to-down_read/20180330-043057
> config: x86_64-randconfig-x014-201812 (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64
>
> All errors (new ones prefixed by >>):
>
> drivers//android/binder.c: In function 'binder_mmap':
> >> drivers//android/binder.c:4725:24: error: 'struct vm_area_struct' has no member named 'flags'; did you mean 'vm_flags'?
> vma->vm_flags = (vma->flags | VM_DONTCOPY | VM_MIXEDMAP) &
> ^~~~~
> vm_flags
http://lkml.kernel.org/r/<20180329065424.203172-1-minchan@kernel.org>
This time, I was little bit fast. :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ANDROID: binder: change down_write to down_read
2018-03-30 0:37 ` Minchan Kim
@ 2018-03-30 2:15 ` Fengguang Wu
0 siblings, 0 replies; 6+ messages in thread
From: Fengguang Wu @ 2018-03-30 2:15 UTC (permalink / raw)
To: Minchan Kim
Cc: kbuild test robot, kbuild-all, LKML, Todd Kjos,
Greg Kroah-Hartman, Arve Hjønnevåg, Martijn Coenen
On Fri, Mar 30, 2018 at 09:37:36AM +0900, Minchan Kim wrote:
>On Fri, Mar 30, 2018 at 07:42:37AM +0800, kbuild test robot wrote:
>> Hi Minchan,
>>
>> I love your patch! Yet something to improve:
>
>Glad to hear.
>It's first time someone loves my patch. ;-)
FYI, that message originates from Linus. :-)
>> [auto build test ERROR on staging/staging-testing]
>> [also build test ERROR on v4.16-rc7 next-20180329]
>> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>>
>> url: https://github.com/0day-ci/linux/commits/Minchan-Kim/ANDROID-binder-change-down_write-to-down_read/20180330-043057
>> config: x86_64-randconfig-x014-201812 (attached as .config)
>> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
>> reproduce:
>> # save the attached .config to linux build tree
>> make ARCH=x86_64
>>
>> All errors (new ones prefixed by >>):
>>
>> drivers//android/binder.c: In function 'binder_mmap':
>> >> drivers//android/binder.c:4725:24: error: 'struct vm_area_struct' has no member named 'flags'; did you mean 'vm_flags'?
>> vma->vm_flags = (vma->flags | VM_DONTCOPY | VM_MIXEDMAP) &
>> ^~~~~
>> vm_flags
>
>http://lkml.kernel.org/r/<20180329065424.203172-1-minchan@kernel.org>
>
>This time, I was little bit fast. :)
Hurrah, quick hands! :)
Cheers,
Fengguang
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-03-30 2:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 2:37 [PATCH v3] ANDROID: binder: change down_write to down_read Minchan Kim
2018-03-29 2:42 ` Minchan Kim
2018-03-29 4:15 ` Greg Kroah-Hartman
2018-03-29 23:42 ` kbuild test robot
2018-03-30 0:37 ` Minchan Kim
2018-03-30 2:15 ` Fengguang Wu
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).