diff options
author | Sherry Yang <sherryy@android.com> | 2018-08-07 15:57:13 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-08-08 05:05:47 -0400 |
commit | 128f38041035001276e964cda1cf951f218d965d (patch) | |
tree | 823e65cc8b07b8217514df1fbf32330cc0afe005 | |
parent | 6d33b3069ed84be9b8430ccc7705d0e747542a4f (diff) |
android: binder: Rate-limit debug and userspace triggered err msgs
Use rate-limited debug messages where userspace can trigger
excessive log spams.
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Sherry Yang <sherryy@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/android/binder.c | 5 | ||||
-rw-r--r-- | drivers/android/binder_alloc.c | 41 |
2 files changed, 29 insertions, 17 deletions
diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 1cc2fa16af8b..d58763b6b009 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c | |||
@@ -70,6 +70,7 @@ | |||
70 | #include <linux/pid_namespace.h> | 70 | #include <linux/pid_namespace.h> |
71 | #include <linux/security.h> | 71 | #include <linux/security.h> |
72 | #include <linux/spinlock.h> | 72 | #include <linux/spinlock.h> |
73 | #include <linux/ratelimit.h> | ||
73 | 74 | ||
74 | #include <uapi/linux/android/binder.h> | 75 | #include <uapi/linux/android/binder.h> |
75 | 76 | ||
@@ -163,13 +164,13 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error, | |||
163 | #define binder_debug(mask, x...) \ | 164 | #define binder_debug(mask, x...) \ |
164 | do { \ | 165 | do { \ |
165 | if (binder_debug_mask & mask) \ | 166 | if (binder_debug_mask & mask) \ |
166 | pr_info(x); \ | 167 | pr_info_ratelimited(x); \ |
167 | } while (0) | 168 | } while (0) |
168 | 169 | ||
169 | #define binder_user_error(x...) \ | 170 | #define binder_user_error(x...) \ |
170 | do { \ | 171 | do { \ |
171 | if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \ | 172 | if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \ |
172 | pr_info(x); \ | 173 | pr_info_ratelimited(x); \ |
173 | if (binder_stop_on_user_error) \ | 174 | if (binder_stop_on_user_error) \ |
174 | binder_stop_on_user_error = 2; \ | 175 | binder_stop_on_user_error = 2; \ |
175 | } while (0) | 176 | } while (0) |
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 2c258dcf9d72..3f3b7b253445 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
29 | #include <linux/list_lru.h> | 29 | #include <linux/list_lru.h> |
30 | #include <linux/ratelimit.h> | ||
30 | #include <asm/cacheflush.h> | 31 | #include <asm/cacheflush.h> |
31 | #include "binder_alloc.h" | 32 | #include "binder_alloc.h" |
32 | #include "binder_trace.h" | 33 | #include "binder_trace.h" |
@@ -36,11 +37,12 @@ struct list_lru binder_alloc_lru; | |||
36 | static DEFINE_MUTEX(binder_alloc_mmap_lock); | 37 | static DEFINE_MUTEX(binder_alloc_mmap_lock); |
37 | 38 | ||
38 | enum { | 39 | enum { |
40 | BINDER_DEBUG_USER_ERROR = 1U << 0, | ||
39 | BINDER_DEBUG_OPEN_CLOSE = 1U << 1, | 41 | BINDER_DEBUG_OPEN_CLOSE = 1U << 1, |
40 | BINDER_DEBUG_BUFFER_ALLOC = 1U << 2, | 42 | BINDER_DEBUG_BUFFER_ALLOC = 1U << 2, |
41 | BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3, | 43 | BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3, |
42 | }; | 44 | }; |
43 | static uint32_t binder_alloc_debug_mask; | 45 | static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR; |
44 | 46 | ||
45 | module_param_named(debug_mask, binder_alloc_debug_mask, | 47 | module_param_named(debug_mask, binder_alloc_debug_mask, |
46 | uint, 0644); | 48 | uint, 0644); |
@@ -48,7 +50,7 @@ module_param_named(debug_mask, binder_alloc_debug_mask, | |||
48 | #define binder_alloc_debug(mask, x...) \ | 50 | #define binder_alloc_debug(mask, x...) \ |
49 | do { \ | 51 | do { \ |
50 | if (binder_alloc_debug_mask & mask) \ | 52 | if (binder_alloc_debug_mask & mask) \ |
51 | pr_info(x); \ | 53 | pr_info_ratelimited(x); \ |
52 | } while (0) | 54 | } while (0) |
53 | 55 | ||
54 | static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer) | 56 | static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer) |
@@ -152,8 +154,10 @@ static struct binder_buffer *binder_alloc_prepare_to_free_locked( | |||
152 | * free the buffer twice | 154 | * free the buffer twice |
153 | */ | 155 | */ |
154 | if (buffer->free_in_progress) { | 156 | if (buffer->free_in_progress) { |
155 | pr_err("%d:%d FREE_BUFFER u%016llx user freed buffer twice\n", | 157 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
156 | alloc->pid, current->pid, (u64)user_ptr); | 158 | "%d:%d FREE_BUFFER u%016llx user freed buffer twice\n", |
159 | alloc->pid, current->pid, | ||
160 | (u64)user_ptr); | ||
157 | return NULL; | 161 | return NULL; |
158 | } | 162 | } |
159 | buffer->free_in_progress = 1; | 163 | buffer->free_in_progress = 1; |
@@ -224,8 +228,9 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, | |||
224 | } | 228 | } |
225 | 229 | ||
226 | if (!vma && need_mm) { | 230 | if (!vma && need_mm) { |
227 | pr_err("%d: binder_alloc_buf failed to map pages in userspace, no vma\n", | 231 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
228 | alloc->pid); | 232 | "%d: binder_alloc_buf failed to map pages in userspace, no vma\n", |
233 | alloc->pid); | ||
229 | goto err_no_vma; | 234 | goto err_no_vma; |
230 | } | 235 | } |
231 | 236 | ||
@@ -344,8 +349,9 @@ static struct binder_buffer *binder_alloc_new_buf_locked( | |||
344 | int ret; | 349 | int ret; |
345 | 350 | ||
346 | if (alloc->vma == NULL) { | 351 | if (alloc->vma == NULL) { |
347 | pr_err("%d: binder_alloc_buf, no vma\n", | 352 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
348 | alloc->pid); | 353 | "%d: binder_alloc_buf, no vma\n", |
354 | alloc->pid); | ||
349 | return ERR_PTR(-ESRCH); | 355 | return ERR_PTR(-ESRCH); |
350 | } | 356 | } |
351 | 357 | ||
@@ -417,11 +423,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked( | |||
417 | if (buffer_size > largest_free_size) | 423 | if (buffer_size > largest_free_size) |
418 | largest_free_size = buffer_size; | 424 | largest_free_size = buffer_size; |
419 | } | 425 | } |
420 | pr_err("%d: binder_alloc_buf size %zd failed, no address space\n", | 426 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
421 | alloc->pid, size); | 427 | "%d: binder_alloc_buf size %zd failed, no address space\n", |
422 | pr_err("allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", | 428 | alloc->pid, size); |
423 | total_alloc_size, allocated_buffers, largest_alloc_size, | 429 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
424 | total_free_size, free_buffers, largest_free_size); | 430 | "allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", |
431 | total_alloc_size, allocated_buffers, | ||
432 | largest_alloc_size, total_free_size, | ||
433 | free_buffers, largest_free_size); | ||
425 | return ERR_PTR(-ENOSPC); | 434 | return ERR_PTR(-ENOSPC); |
426 | } | 435 | } |
427 | if (n == NULL) { | 436 | if (n == NULL) { |
@@ -731,8 +740,10 @@ err_alloc_pages_failed: | |||
731 | err_get_vm_area_failed: | 740 | err_get_vm_area_failed: |
732 | err_already_mapped: | 741 | err_already_mapped: |
733 | mutex_unlock(&binder_alloc_mmap_lock); | 742 | mutex_unlock(&binder_alloc_mmap_lock); |
734 | pr_err("%s: %d %lx-%lx %s failed %d\n", __func__, | 743 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, |
735 | alloc->pid, vma->vm_start, vma->vm_end, failure_string, ret); | 744 | "%s: %d %lx-%lx %s failed %d\n", __func__, |
745 | alloc->pid, vma->vm_start, vma->vm_end, | ||
746 | failure_string, ret); | ||
736 | return ret; | 747 | return ret; |
737 | } | 748 | } |
738 | 749 | ||