* [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-21 0:58 [PATCH v2 0/4] android: binder: fixes for memory allocator change Sherry Yang
@ 2017-10-21 0:58 ` Sherry Yang
2017-10-21 8:15 ` Greg Kroah-Hartman
2017-10-21 0:58 ` [PATCH v2 2/4] android: binder: Fix null ptr dereference in debug msg Sherry Yang
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Sherry Yang @ 2017-10-21 0:58 UTC (permalink / raw)
To: linux-kernel
Cc: tkjos, maco, Sherry Yang, Greg Kroah-Hartman,
Arve Hjønnevåg, Riley Andrews,
open list:ANDROID DRIVERS
Use binder_alloc struct's mm_struct rather than getting
a reference to the mm struct through get_task_mm to
avoid a potential deadlock between lru lock, task lock and
dentry lock, since a thread can be holding the task lock
and the dentry lock while trying to acquire the lru lock.
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Sherry Yang <sherryy@android.com>
---
drivers/android/binder_alloc.c | 22 +++++++++-------------
drivers/android/binder_alloc.h | 1 -
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 064f5e31ec55..e12072b1d507 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -215,17 +215,12 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
}
}
- if (!vma && need_mm)
- mm = get_task_mm(alloc->tsk);
+ if (!vma && need_mm && mmget_not_zero(alloc->vma_vm_mm))
+ mm = alloc->vma_vm_mm;
if (mm) {
down_write(&mm->mmap_sem);
vma = alloc->vma;
- if (vma && mm != alloc->vma_vm_mm) {
- pr_err("%d: vma mm and task mm mismatch\n",
- alloc->pid);
- vma = NULL;
- }
}
if (!vma && need_mm) {
@@ -720,6 +715,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
barrier();
alloc->vma = vma;
alloc->vma_vm_mm = vma->vm_mm;
+ mmgrab(alloc->vma_vm_mm);
return 0;
@@ -795,6 +791,8 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
vfree(alloc->buffer);
}
mutex_unlock(&alloc->mutex);
+ if (alloc->vma_vm_mm)
+ mmdrop(alloc->vma_vm_mm);
binder_alloc_debug(BINDER_DEBUG_OPEN_CLOSE,
"%s: %d buffers %d, pages %d\n",
@@ -889,7 +887,6 @@ int binder_alloc_get_allocated_count(struct binder_alloc *alloc)
void binder_alloc_vma_close(struct binder_alloc *alloc)
{
WRITE_ONCE(alloc->vma, NULL);
- WRITE_ONCE(alloc->vma_vm_mm, NULL);
}
/**
@@ -926,9 +923,9 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE;
vma = alloc->vma;
if (vma) {
- mm = get_task_mm(alloc->tsk);
- if (!mm)
- goto err_get_task_mm_failed;
+ if (!mmget_not_zero(alloc->vma_vm_mm))
+ goto err_mmget;
+ mm = alloc->vma_vm_mm;
if (!down_write_trylock(&mm->mmap_sem))
goto err_down_write_mmap_sem_failed;
}
@@ -963,7 +960,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
err_down_write_mmap_sem_failed:
mmput_async(mm);
-err_get_task_mm_failed:
+err_mmget:
err_page_already_freed:
mutex_unlock(&alloc->mutex);
err_get_alloc_mutex_failed:
@@ -1002,7 +999,6 @@ struct shrinker binder_shrinker = {
*/
void binder_alloc_init(struct binder_alloc *alloc)
{
- alloc->tsk = current->group_leader;
alloc->pid = current->group_leader->pid;
mutex_init(&alloc->mutex);
INIT_LIST_HEAD(&alloc->buffers);
diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h
index a3a3602c689c..2dd33b6df104 100644
--- a/drivers/android/binder_alloc.h
+++ b/drivers/android/binder_alloc.h
@@ -100,7 +100,6 @@ struct binder_lru_page {
*/
struct binder_alloc {
struct mutex mutex;
- struct task_struct *tsk;
struct vm_area_struct *vma;
struct mm_struct *vma_vm_mm;
void *buffer;
--
2.11.0 (Apple Git-81)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-21 0:58 ` [PATCH v2 1/4] android: binder: Don't get mm from task Sherry Yang
@ 2017-10-21 8:15 ` Greg Kroah-Hartman
2017-10-23 18:18 ` Arve Hjønnevåg
0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-10-21 8:15 UTC (permalink / raw)
To: Sherry Yang
Cc: linux-kernel, open list:ANDROID DRIVERS,
Arve Hjønnevåg, Riley Andrews, maco, tkjos
On Fri, Oct 20, 2017 at 08:58:58PM -0400, Sherry Yang wrote:
> Use binder_alloc struct's mm_struct rather than getting
> a reference to the mm struct through get_task_mm to
> avoid a potential deadlock between lru lock, task lock and
> dentry lock, since a thread can be holding the task lock
> and the dentry lock while trying to acquire the lru lock.
>
> Acked-by: Arve Hjønnevåg <arve@android.com>
> Signed-off-by: Sherry Yang <sherryy@android.com>
> ---
> drivers/android/binder_alloc.c | 22 +++++++++-------------
> drivers/android/binder_alloc.h | 1 -
> 2 files changed, 9 insertions(+), 14 deletions(-)
I've applied these first 2 patches, but patches 3 and 4 I have already
applied to my char-misc-next tree, right?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-21 8:15 ` Greg Kroah-Hartman
@ 2017-10-23 18:18 ` Arve Hjønnevåg
2017-10-24 7:28 ` Greg Kroah-Hartman
0 siblings, 1 reply; 10+ messages in thread
From: Arve Hjønnevåg @ 2017-10-23 18:18 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Sherry Yang, LKML, open list:ANDROID DRIVERS, Riley Andrews,
Martijn Coenen, Todd Kjos
On Sat, Oct 21, 2017 at 1:15 AM, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Fri, Oct 20, 2017 at 08:58:58PM -0400, Sherry Yang wrote:
>> Use binder_alloc struct's mm_struct rather than getting
>> a reference to the mm struct through get_task_mm to
>> avoid a potential deadlock between lru lock, task lock and
>> dentry lock, since a thread can be holding the task lock
>> and the dentry lock while trying to acquire the lru lock.
>>
>> Acked-by: Arve Hjønnevåg <arve@android.com>
>> Signed-off-by: Sherry Yang <sherryy@android.com>
>> ---
>> drivers/android/binder_alloc.c | 22 +++++++++-------------
>> drivers/android/binder_alloc.h | 1 -
>> 2 files changed, 9 insertions(+), 14 deletions(-)
>
> I've applied these first 2 patches, but patches 3 and 4 I have already
> applied to my char-misc-next tree, right?
>
> thanks,
>
> greg k-h
I would expect you got a merge conflict from one of those. Using patch
3 and 4 in from this patchset should avoid that conflict if your
eventual 4.15 branch is not based on your current char-misc-next
branch.
--
Arve Hjønnevåg
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-23 18:18 ` Arve Hjønnevåg
@ 2017-10-24 7:28 ` Greg Kroah-Hartman
2017-10-24 18:36 ` Arve Hjønnevåg
0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-10-24 7:28 UTC (permalink / raw)
To: Arve Hjønnevåg
Cc: open list:ANDROID DRIVERS, Sherry Yang, LKML, Riley Andrews,
Martijn Coenen, Todd Kjos
On Mon, Oct 23, 2017 at 11:18:52AM -0700, Arve Hjønnevåg wrote:
> On Sat, Oct 21, 2017 at 1:15 AM, Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > On Fri, Oct 20, 2017 at 08:58:58PM -0400, Sherry Yang wrote:
> >> Use binder_alloc struct's mm_struct rather than getting
> >> a reference to the mm struct through get_task_mm to
> >> avoid a potential deadlock between lru lock, task lock and
> >> dentry lock, since a thread can be holding the task lock
> >> and the dentry lock while trying to acquire the lru lock.
> >>
> >> Acked-by: Arve Hjønnevåg <arve@android.com>
> >> Signed-off-by: Sherry Yang <sherryy@android.com>
> >> ---
> >> drivers/android/binder_alloc.c | 22 +++++++++-------------
> >> drivers/android/binder_alloc.h | 1 -
> >> 2 files changed, 9 insertions(+), 14 deletions(-)
> >
> > I've applied these first 2 patches, but patches 3 and 4 I have already
> > applied to my char-misc-next tree, right?
> >
> > thanks,
> >
> > greg k-h
>
> I would expect you got a merge conflict from one of those. Using patch
> 3 and 4 in from this patchset should avoid that conflict if your
> eventual 4.15 branch is not based on your current char-misc-next
> branch.
I've resolved the merge conflict so my char-misc-next branch should be
all caught up now. It would be wonderful if you could verify this.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-24 7:28 ` Greg Kroah-Hartman
@ 2017-10-24 18:36 ` Arve Hjønnevåg
2017-10-25 7:11 ` Greg Kroah-Hartman
0 siblings, 1 reply; 10+ messages in thread
From: Arve Hjønnevåg @ 2017-10-24 18:36 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: open list:ANDROID DRIVERS, Sherry Yang, LKML, Riley Andrews,
Martijn Coenen, Todd Kjos
On Tue, Oct 24, 2017 at 12:28 AM, Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> On Mon, Oct 23, 2017 at 11:18:52AM -0700, Arve Hjønnevåg wrote:
>> On Sat, Oct 21, 2017 at 1:15 AM, Greg Kroah-Hartman
>> <gregkh@linuxfoundation.org> wrote:
>> > On Fri, Oct 20, 2017 at 08:58:58PM -0400, Sherry Yang wrote:
>> >> Use binder_alloc struct's mm_struct rather than getting
>> >> a reference to the mm struct through get_task_mm to
>> >> avoid a potential deadlock between lru lock, task lock and
>> >> dentry lock, since a thread can be holding the task lock
>> >> and the dentry lock while trying to acquire the lru lock.
>> >>
>> >> Acked-by: Arve Hjønnevåg <arve@android.com>
>> >> Signed-off-by: Sherry Yang <sherryy@android.com>
>> >> ---
>> >> drivers/android/binder_alloc.c | 22 +++++++++-------------
>> >> drivers/android/binder_alloc.h | 1 -
>> >> 2 files changed, 9 insertions(+), 14 deletions(-)
>> >
>> > I've applied these first 2 patches, but patches 3 and 4 I have already
>> > applied to my char-misc-next tree, right?
>> >
>> > thanks,
>> >
>> > greg k-h
>>
>> I would expect you got a merge conflict from one of those. Using patch
>> 3 and 4 in from this patchset should avoid that conflict if your
>> eventual 4.15 branch is not based on your current char-misc-next
>> branch.
>
> I've resolved the merge conflict so my char-misc-next branch should be
> all caught up now. It would be wonderful if you could verify this.
>
> thanks,
>
> greg k-h
I have not tested your branch directly, but the relevant code in
char-misc-next is now identical to the code I tested.
--
Arve Hjønnevåg
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] android: binder: Don't get mm from task
2017-10-24 18:36 ` Arve Hjønnevåg
@ 2017-10-25 7:11 ` Greg Kroah-Hartman
0 siblings, 0 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2017-10-25 7:11 UTC (permalink / raw)
To: Arve Hjønnevåg
Cc: open list:ANDROID DRIVERS, Sherry Yang, LKML, Riley Andrews,
Martijn Coenen, Todd Kjos
On Tue, Oct 24, 2017 at 11:36:48AM -0700, Arve Hjønnevåg wrote:
> On Tue, Oct 24, 2017 at 12:28 AM, Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > On Mon, Oct 23, 2017 at 11:18:52AM -0700, Arve Hjønnevåg wrote:
> >> On Sat, Oct 21, 2017 at 1:15 AM, Greg Kroah-Hartman
> >> <gregkh@linuxfoundation.org> wrote:
> >> > On Fri, Oct 20, 2017 at 08:58:58PM -0400, Sherry Yang wrote:
> >> >> Use binder_alloc struct's mm_struct rather than getting
> >> >> a reference to the mm struct through get_task_mm to
> >> >> avoid a potential deadlock between lru lock, task lock and
> >> >> dentry lock, since a thread can be holding the task lock
> >> >> and the dentry lock while trying to acquire the lru lock.
> >> >>
> >> >> Acked-by: Arve Hjønnevåg <arve@android.com>
> >> >> Signed-off-by: Sherry Yang <sherryy@android.com>
> >> >> ---
> >> >> drivers/android/binder_alloc.c | 22 +++++++++-------------
> >> >> drivers/android/binder_alloc.h | 1 -
> >> >> 2 files changed, 9 insertions(+), 14 deletions(-)
> >> >
> >> > I've applied these first 2 patches, but patches 3 and 4 I have already
> >> > applied to my char-misc-next tree, right?
> >> >
> >> > thanks,
> >> >
> >> > greg k-h
> >>
> >> I would expect you got a merge conflict from one of those. Using patch
> >> 3 and 4 in from this patchset should avoid that conflict if your
> >> eventual 4.15 branch is not based on your current char-misc-next
> >> branch.
> >
> > I've resolved the merge conflict so my char-misc-next branch should be
> > all caught up now. It would be wonderful if you could verify this.
> >
> > thanks,
> >
> > greg k-h
>
> I have not tested your branch directly, but the relevant code in
> char-misc-next is now identical to the code I tested.
Wonderful, thanks for verifying.
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/4] android: binder: Fix null ptr dereference in debug msg
2017-10-21 0:58 [PATCH v2 0/4] android: binder: fixes for memory allocator change Sherry Yang
2017-10-21 0:58 ` [PATCH v2 1/4] android: binder: Don't get mm from task Sherry Yang
@ 2017-10-21 0:58 ` Sherry Yang
2017-10-21 0:59 ` [PATCH v2 3/4] android: binder: Remove unused vma argument Sherry Yang
2017-10-21 0:59 ` [PATCH v2 4/4] android: binder: Change binder_shrinker to static Sherry Yang
3 siblings, 0 replies; 10+ messages in thread
From: Sherry Yang @ 2017-10-21 0:58 UTC (permalink / raw)
To: linux-kernel
Cc: tkjos, maco, Sherry Yang, Greg Kroah-Hartman,
Arve Hjønnevåg, Riley Andrews,
open list:ANDROID DRIVERS
Don't access next->data in kernel debug message when the
next buffer is null.
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Sherry Yang <sherryy@android.com>
---
drivers/android/binder_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index e12072b1d507..c2819a3d58a6 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -560,7 +560,7 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc,
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
"%d: merge free, buffer %pK do not share page with %pK or %pK\n",
alloc->pid, buffer->data,
- prev->data, next->data);
+ prev->data, next ? next->data : NULL);
binder_update_page_range(alloc, 0, buffer_start_page(buffer),
buffer_start_page(buffer) + PAGE_SIZE,
NULL);
--
2.11.0 (Apple Git-81)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] android: binder: Remove unused vma argument
2017-10-21 0:58 [PATCH v2 0/4] android: binder: fixes for memory allocator change Sherry Yang
2017-10-21 0:58 ` [PATCH v2 1/4] android: binder: Don't get mm from task Sherry Yang
2017-10-21 0:58 ` [PATCH v2 2/4] android: binder: Fix null ptr dereference in debug msg Sherry Yang
@ 2017-10-21 0:59 ` Sherry Yang
2017-10-21 0:59 ` [PATCH v2 4/4] android: binder: Change binder_shrinker to static Sherry Yang
3 siblings, 0 replies; 10+ messages in thread
From: Sherry Yang @ 2017-10-21 0:59 UTC (permalink / raw)
To: linux-kernel
Cc: tkjos, maco, Sherry Yang, Greg Kroah-Hartman,
Arve Hjønnevåg, Riley Andrews,
open list:ANDROID DRIVERS
The vma argument in update_page_range is no longer
used after 74310e06 ("android: binder: Move buffer
out of area shared with user space"), since mmap_handler
no longer calls update_page_range with a vma.
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Sherry Yang <sherryy@android.com>
---
drivers/android/binder_alloc.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index c2819a3d58a6..36bcea1fc47c 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -186,12 +186,12 @@ struct binder_buffer *binder_alloc_prepare_to_free(struct binder_alloc *alloc,
}
static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
- void *start, void *end,
- struct vm_area_struct *vma)
+ void *start, void *end)
{
void *page_addr;
unsigned long user_page_addr;
struct binder_lru_page *page;
+ struct vm_area_struct *vma = NULL;
struct mm_struct *mm = NULL;
bool need_mm = false;
@@ -215,7 +215,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
}
}
- if (!vma && need_mm && mmget_not_zero(alloc->vma_vm_mm))
+ if (need_mm && mmget_not_zero(alloc->vma_vm_mm))
mm = alloc->vma_vm_mm;
if (mm) {
@@ -437,7 +437,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct binder_alloc *alloc,
if (end_page_addr > has_page_addr)
end_page_addr = has_page_addr;
ret = binder_update_page_range(alloc, 1,
- (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr, NULL);
+ (void *)PAGE_ALIGN((uintptr_t)buffer->data), end_page_addr);
if (ret)
return ERR_PTR(ret);
@@ -478,7 +478,7 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct binder_alloc *alloc,
err_alloc_buf_struct_failed:
binder_update_page_range(alloc, 0,
(void *)PAGE_ALIGN((uintptr_t)buffer->data),
- end_page_addr, NULL);
+ end_page_addr);
return ERR_PTR(-ENOMEM);
}
@@ -562,8 +562,7 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc,
alloc->pid, buffer->data,
prev->data, next ? next->data : NULL);
binder_update_page_range(alloc, 0, buffer_start_page(buffer),
- buffer_start_page(buffer) + PAGE_SIZE,
- NULL);
+ buffer_start_page(buffer) + PAGE_SIZE);
}
list_del(&buffer->entry);
kfree(buffer);
@@ -600,8 +599,7 @@ static void binder_free_buf_locked(struct binder_alloc *alloc,
binder_update_page_range(alloc, 0,
(void *)PAGE_ALIGN((uintptr_t)buffer->data),
- (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK),
- NULL);
+ (void *)(((uintptr_t)buffer->data + buffer_size) & PAGE_MASK));
rb_erase(&buffer->rb_node, &alloc->allocated_buffers);
buffer->free = 1;
--
2.11.0 (Apple Git-81)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/4] android: binder: Change binder_shrinker to static
2017-10-21 0:58 [PATCH v2 0/4] android: binder: fixes for memory allocator change Sherry Yang
` (2 preceding siblings ...)
2017-10-21 0:59 ` [PATCH v2 3/4] android: binder: Remove unused vma argument Sherry Yang
@ 2017-10-21 0:59 ` Sherry Yang
3 siblings, 0 replies; 10+ messages in thread
From: Sherry Yang @ 2017-10-21 0:59 UTC (permalink / raw)
To: linux-kernel
Cc: tkjos, maco, Sherry Yang, Greg Kroah-Hartman,
Arve Hjønnevåg, Riley Andrews,
open list:ANDROID DRIVERS
binder_shrinker struct is not used anywhere outside of
binder_alloc.c and should be static.
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Sherry Yang <sherryy@android.com>
---
drivers/android/binder_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 36bcea1fc47c..6f6f745605af 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -982,7 +982,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
return ret;
}
-struct shrinker binder_shrinker = {
+static struct shrinker binder_shrinker = {
.count_objects = binder_shrink_count,
.scan_objects = binder_shrink_scan,
.seeks = DEFAULT_SEEKS,
--
2.11.0 (Apple Git-81)
^ permalink raw reply related [flat|nested] 10+ messages in thread