Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp213986imm; Thu, 26 Jul 2018 17:19:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe/WTo6bxXVf7OGLQ2VGzSlubQ/wJcHvzoPhyYiWLxT3pq5NLuMBLgiuesrVKKsKywGzi+y X-Received: by 2002:a62:5290:: with SMTP id g138-v6mr4282626pfb.46.1532650756776; Thu, 26 Jul 2018 17:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532650756; cv=none; d=google.com; s=arc-20160816; b=rVDGU75huw35JeCmu3cK2JcOIRMXBhuyeRBiXpGpZzQ7GtbiXMS+vqLc4ZvULvqiRw 20TS/6IkViNZYcK3ceVZFolP/sg+6bzRCoo5A9FgilLmP0prTUVkns1PLC5ps7+4lIMQ 1YmXX/3OQ1AyAYJsRuujiHIyZiu1Z6/S5knPJprP6Ni7JZbId+Q8wTWH/TLP/2WET+n2 O4eN2b2iVQborbClJkJOKYl1yudnY8J8oJy8vb4R0M4siwcQBWpW6X/aPu5e+kZ+TeXB nNFxgs2IyMxTBBltGXddAMw9zhucKcNZJEKo1xJVwC0auXqn5rzqPA7aNiw7h09RkUiX sKXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=DDQL03F6jDJqg8vmjsAoXWo8ugyjdr2mFrww0D37Icg=; b=nfv6T7dKp1mJzxgP/RAlEK2nppt8BWgRSDsdCP7G9EEkd4zXswI1nlRl80JkKyC2pa 6SUrnE1eeYXjQ4uUUYh0vklrTfPn4vtjrexyiUsyDX2Ff/PzPu55a+Qw2bWFKyjhqMTe rf77jJYA1E+7GpVMOCOBRu3X3RjDwupo1oK1vcawJ1BgdyJeQCMq4+DJNNJsklMQD2rx 5XpuEghLs5TlDUo0+Vg0j2/fgSrnOk+kHlGbkRoFLvetwCFvO1cGEX35pEKqF5BAHvCA cZk6dtBTeogBd97QMpMjxQJ6L6KLf6W4WmDzrlhoRD0+BVIM4Y73DVkjee99WJ667wzC bMWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=frI9N2rO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p185-v6si2542630pga.476.2018.07.26.17.18.59; Thu, 26 Jul 2018 17:19:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=frI9N2rO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732011AbeG0Bgp (ORCPT + 99 others); Thu, 26 Jul 2018 21:36:45 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35140 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732059AbeG0Bgk (ORCPT ); Thu, 26 Jul 2018 21:36:40 -0400 Received: by mail-pf1-f193.google.com with SMTP id q7-v6so1110006pff.2 for ; Thu, 26 Jul 2018 17:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DDQL03F6jDJqg8vmjsAoXWo8ugyjdr2mFrww0D37Icg=; b=frI9N2rOATVJgl3QFPbewz1MednbWezlLzuovtzECxomICpq3aSumq/hfp3sBLFttz 6dYR6MPNNjSbkWrH9cJRGMS/rlYrAloN0ArxCcuwsJKZ0gqmG4TVKqFIfJFNusDjgifD zS5DoAX/KpSytE3ry+T9ox4WtEJuy4FS4b5fpujDUVA031mb3Xb6fktkRAcfXMBY4aps 7ehGh6CmTUIFTQb8a8oDz2aS2OYIqrC76kva8EAdHLylcXlnlQwVc8fGewQeGBpdK7uP jLFBY6UurgTLWClOjnnr3bTwt0XTd+GNxjYsE+NTYF9qfUFxxLkunuCo7oX3h18ivUO7 Ey+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DDQL03F6jDJqg8vmjsAoXWo8ugyjdr2mFrww0D37Icg=; b=NT5JBUqpySD6wIB0YYF1w4Ekn4zNv7wI3WHbq1ZetiAhqIBWY2RoQElEC12AhbR9MC zTFsolgdYqRdKLHdGmJi59EN7+WimA1LDGq1IyEAagXtc3HNOexHz8JpF9L1S9xOyZ75 8g1eh3+4YWCkfn+Kl/Cuc1+s31TP8X5VB7zbna7kcbSyRFHzYzOwSk4uw8dm+cVkFwUO 4N54IvnE7TZ9iXIErD8RgUKBwtevuw6DiVBnsU/VAJTa6Ty9ybeuGtE46aN6gDZ2nYvs GNL+1LIUTKVQCiuDksT2Gg70+80+k7g5xWSQBIupkk7YwtNvlZzmmeDk9MVQRMJICimn 4aXA== X-Gm-Message-State: AOUpUlGdnxNduoFqkEt1JnmMo00PTvkHoTUuM2AZCO5TmAyMLtFtXn/0 g5NIJfsgpwcKhMJoQtx5WpuIC64PydI= X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr3870789pgd.372.1532650648060; Thu, 26 Jul 2018 17:17:28 -0700 (PDT) Received: from sherryy2.mtv.corp.google.com ([2620:0:1000:1611:8e0a:214e:3e7b:4985]) by smtp.gmail.com with ESMTPSA id q65-v6sm5345864pfj.127.2018.07.26.17.17.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 17:17:27 -0700 (PDT) From: Sherry Yang To: linux-kernel@vger.kernel.org Cc: tkjos@google.com, maco@google.com, Sherry Yang , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , devel@driverdev.osuosl.org (open list:ANDROID DRIVERS) Subject: [PATCH 2/2] android: binder: Rate-limit debug and userspace triggered err msgs Date: Thu, 26 Jul 2018 17:17:18 -0700 Message-Id: <20180727001718.242587-3-sherryy@android.com> X-Mailer: git-send-email 2.18.0.345.g5c9ce644c3-goog In-Reply-To: <20180727001718.242587-1-sherryy@android.com> References: <20180727001718.242587-1-sherryy@android.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use rate-limited debug messages where userspace can trigger excessive log spams. Acked-by: Arve Hjønnevåg Signed-off-by: Sherry Yang --- drivers/android/binder.c | 5 +++-- 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 95283f3bb51c..78cc1190282c 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -71,6 +71,7 @@ #include #include #include +#include #include #include "binder_alloc.h" @@ -161,13 +162,13 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error, #define binder_debug(mask, x...) \ do { \ if (binder_debug_mask & mask) \ - pr_info(x); \ + pr_info_ratelimited(x); \ } while (0) #define binder_user_error(x...) \ do { \ if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \ - pr_info(x); \ + pr_info_ratelimited(x); \ if (binder_stop_on_user_error) \ binder_stop_on_user_error = 2; \ } while (0) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 2628806c64a2..e16116e9ad1f 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "binder_alloc.h" #include "binder_trace.h" @@ -36,11 +37,12 @@ struct list_lru binder_alloc_lru; static DEFINE_MUTEX(binder_alloc_mmap_lock); enum { + BINDER_DEBUG_USER_ERROR = 1U << 0, BINDER_DEBUG_OPEN_CLOSE = 1U << 1, BINDER_DEBUG_BUFFER_ALLOC = 1U << 2, BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3, }; -static uint32_t binder_alloc_debug_mask; +static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR; module_param_named(debug_mask, binder_alloc_debug_mask, uint, 0644); @@ -48,7 +50,7 @@ module_param_named(debug_mask, binder_alloc_debug_mask, #define binder_alloc_debug(mask, x...) \ do { \ if (binder_alloc_debug_mask & mask) \ - pr_info(x); \ + pr_info_ratelimited(x); \ } while (0) 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( * free the buffer twice */ if (buffer->free_in_progress) { - pr_err("%d:%d FREE_BUFFER u%016llx user freed buffer twice\n", - alloc->pid, current->pid, (u64)user_ptr); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "%d:%d FREE_BUFFER u%016llx user freed buffer twice\n", + alloc->pid, current->pid, + (u64)user_ptr); return NULL; } buffer->free_in_progress = 1; @@ -224,8 +228,9 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate, } if (!vma && need_mm) { - pr_err("%d: binder_alloc_buf failed to map pages in userspace, no vma\n", - alloc->pid); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "%d: binder_alloc_buf failed to map pages in userspace, no vma\n", + alloc->pid); goto err_no_vma; } @@ -344,8 +349,9 @@ static struct binder_buffer *binder_alloc_new_buf_locked( int ret; if (alloc->vma == NULL) { - pr_err("%d: binder_alloc_buf, no vma\n", - alloc->pid); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "%d: binder_alloc_buf, no vma\n", + alloc->pid); return ERR_PTR(-ESRCH); } @@ -417,11 +423,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked( if (buffer_size > largest_free_size) largest_free_size = buffer_size; } - pr_err("%d: binder_alloc_buf size %zd failed, no address space\n", - alloc->pid, size); - pr_err("allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", - total_alloc_size, allocated_buffers, largest_alloc_size, - total_free_size, free_buffers, largest_free_size); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "%d: binder_alloc_buf size %zd failed, no address space\n", + alloc->pid, size); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n", + total_alloc_size, allocated_buffers, + largest_alloc_size, total_free_size, + free_buffers, largest_free_size); return ERR_PTR(-ENOSPC); } if (n == NULL) { @@ -731,8 +740,10 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc, err_get_vm_area_failed: err_already_mapped: mutex_unlock(&binder_alloc_mmap_lock); - pr_err("%s: %d %lx-%lx %s failed %d\n", __func__, - alloc->pid, vma->vm_start, vma->vm_end, failure_string, ret); + binder_alloc_debug(BINDER_DEBUG_USER_ERROR, + "%s: %d %lx-%lx %s failed %d\n", __func__, + alloc->pid, vma->vm_start, vma->vm_end, + failure_string, ret); return ret; } -- 2.18.0.345.g5c9ce644c3-goog