From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A40BC41604 for ; Tue, 6 Oct 2020 20:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A09A2087E for ; Tue, 6 Oct 2020 20:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602017162; bh=b8XtCLp4DoUvkHKpG4hkR/DpJr2F8hcuTBhXEazrmDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pDGncKJdZ0pJB8Mf+ydUHl3G7nLcKN8rjXZlMBa8mOV+82LbrrFwbBmmXbZbqesr0 QAiIERD0vEp3iAErd7SY5EW4KF29ekPEBfgtsk/4FmeZp6fcGRod/eVIiH/CqaKLLa weY3sICSpQYyrwj/1uHj7LoPCugOH31xpDnWsBpU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbgJFUqB (ORCPT ); Tue, 6 Oct 2020 16:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727381AbgJFUp4 (ORCPT ); Tue, 6 Oct 2020 16:45:56 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A632C0613D5 for ; Tue, 6 Oct 2020 13:45:56 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id y13so14549729iow.4 for ; Tue, 06 Oct 2020 13:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UnP5R+4P1qpVdNXyvoq29UD3wog5Z2QkTi0v6WNmers=; b=GPu7wrtCw5buXjRF+2joj5ooo5aQNMOMurI2Q9gsuBv2O+7ShayjuYntc1epHj7ebi pnzIaExQqrXlC9Kut11M9bvMQ6yIqSsDqtRORPWUqjlKQIx7KcZ6AR3+TOkebg0sW2W9 F97+2okXAsxr6HFFHphx/42aQxQoAYqK3BIWw= 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=UnP5R+4P1qpVdNXyvoq29UD3wog5Z2QkTi0v6WNmers=; b=AKHy9sHqECVdUxaWG+xFupM6hNnWlqjf/6zlpOCpNyORu1xguypKoffh45ixsV16/l 4eGs+Pv0GnYBvr9t843o1mb02CFyzVdRTDJuCzBATgc+BUmsoxqKuJKhWfnMIqH6V9ag mtBdAnuQcBQaC6dx5EYS2u8rMkJrPFAEScMVJ08piWdala3HvgO1HR8OGQjZxH4otgai kxd3XzPqnfZZJkYfqQE8b+fErjHl0hLaWQSv+FDKDw6E9vlUS8qwW3HfZDbGfg14W7Tc +Zi1MPWLk90zEWdD4fFsWlvrYx7LdXjMU7WxUS987rhiafTA6yZ0BOpO67/OPQBGsPDK I+Nw== X-Gm-Message-State: AOAM53321Autw077sTEXocvH2Rrq6AG723SE1XtBu/cRE7zh3C4uCP7n foM99zP+ie0chvdUq4+4vBhsDw== X-Google-Smtp-Source: ABdhPJwYLqpKQoASFOtzCruA9t++iiIO4PWpon4Ys4BDnl50lpi0y7VnCkW8xODVXC97U8OciDOZRg== X-Received: by 2002:a05:6602:2f07:: with SMTP id q7mr2656902iow.191.1602017155562; Tue, 06 Oct 2020 13:45:55 -0700 (PDT) Received: from shuah-t480s.internal (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id s69sm1665627ili.54.2020.10.06.13.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2020 13:45:55 -0700 (PDT) From: Shuah Khan To: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, christian@brauner.io, hridya@google.com, surenb@google.com, keescook@chromium.org Cc: Shuah Khan , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/11] drivers/android/binder: convert stats, transaction_log to counter_atomic32 Date: Tue, 6 Oct 2020 14:44:38 -0600 Message-Id: <63482420f221c3483f6526bfc12fc99fe30a567d.1602011710.git.skhan@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org counter_atomic* is introduced to be used when a variable is used as a simple counter and doesn't guard object lifetimes. This clearly differentiates atomic_t usages that guard object lifetimes. counter_atomic* variables will wrap around to 0 when it overflows and should not be used to guard resource lifetimes, device usage and open counts that control state changes, and pm states. stats tracks per-process binder statistics. Unsure if there is a chance of this overflowing, other than stats getting reset to 0. Convert it to use counter_atomic. binder_transaction_log:cur is used to keep track of the current log entry location. Overflow is handled in the code. Since it is used as a counter, convert it to use counter_atomic32. This conversion doesn't change the overflow wrap around behavior. Reviewed-by: Joel Fernandes (Google) Signed-off-by: Shuah Khan --- drivers/android/binder.c | 41 ++++++++++++++++--------------- drivers/android/binder_internal.h | 3 ++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index f936530a19b0..52175cd6a62b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -172,22 +173,22 @@ enum binder_stat_types { }; struct binder_stats { - atomic_t br[_IOC_NR(BR_FAILED_REPLY) + 1]; - atomic_t bc[_IOC_NR(BC_REPLY_SG) + 1]; - atomic_t obj_created[BINDER_STAT_COUNT]; - atomic_t obj_deleted[BINDER_STAT_COUNT]; + struct counter_atomic32 br[_IOC_NR(BR_FAILED_REPLY) + 1]; + struct counter_atomic32 bc[_IOC_NR(BC_REPLY_SG) + 1]; + struct counter_atomic32 obj_created[BINDER_STAT_COUNT]; + struct counter_atomic32 obj_deleted[BINDER_STAT_COUNT]; }; static struct binder_stats binder_stats; static inline void binder_stats_deleted(enum binder_stat_types type) { - atomic_inc(&binder_stats.obj_deleted[type]); + counter_atomic32_inc(&binder_stats.obj_deleted[type]); } static inline void binder_stats_created(enum binder_stat_types type) { - atomic_inc(&binder_stats.obj_created[type]); + counter_atomic32_inc(&binder_stats.obj_created[type]); } struct binder_transaction_log binder_transaction_log; @@ -197,7 +198,7 @@ static struct binder_transaction_log_entry *binder_transaction_log_add( struct binder_transaction_log *log) { struct binder_transaction_log_entry *e; - unsigned int cur = atomic_inc_return(&log->cur); + unsigned int cur = counter_atomic32_inc_return(&log->cur); if (cur >= ARRAY_SIZE(log->entry)) log->full = true; @@ -3615,9 +3616,9 @@ static int binder_thread_write(struct binder_proc *proc, ptr += sizeof(uint32_t); trace_binder_command(cmd); if (_IOC_NR(cmd) < ARRAY_SIZE(binder_stats.bc)) { - atomic_inc(&binder_stats.bc[_IOC_NR(cmd)]); - atomic_inc(&proc->stats.bc[_IOC_NR(cmd)]); - atomic_inc(&thread->stats.bc[_IOC_NR(cmd)]); + counter_atomic32_inc(&binder_stats.bc[_IOC_NR(cmd)]); + counter_atomic32_inc(&proc->stats.bc[_IOC_NR(cmd)]); + counter_atomic32_inc(&thread->stats.bc[_IOC_NR(cmd)]); } switch (cmd) { case BC_INCREFS: @@ -4047,9 +4048,9 @@ static void binder_stat_br(struct binder_proc *proc, { trace_binder_return(cmd); if (_IOC_NR(cmd) < ARRAY_SIZE(binder_stats.br)) { - atomic_inc(&binder_stats.br[_IOC_NR(cmd)]); - atomic_inc(&proc->stats.br[_IOC_NR(cmd)]); - atomic_inc(&thread->stats.br[_IOC_NR(cmd)]); + counter_atomic32_inc(&binder_stats.br[_IOC_NR(cmd)]); + counter_atomic32_inc(&proc->stats.br[_IOC_NR(cmd)]); + counter_atomic32_inc(&thread->stats.br[_IOC_NR(cmd)]); } } @@ -5841,7 +5842,7 @@ static void print_binder_stats(struct seq_file *m, const char *prefix, BUILD_BUG_ON(ARRAY_SIZE(stats->bc) != ARRAY_SIZE(binder_command_strings)); for (i = 0; i < ARRAY_SIZE(stats->bc); i++) { - int temp = atomic_read(&stats->bc[i]); + int temp = counter_atomic32_read(&stats->bc[i]); if (temp) seq_printf(m, "%s%s: %d\n", prefix, @@ -5851,7 +5852,7 @@ static void print_binder_stats(struct seq_file *m, const char *prefix, BUILD_BUG_ON(ARRAY_SIZE(stats->br) != ARRAY_SIZE(binder_return_strings)); for (i = 0; i < ARRAY_SIZE(stats->br); i++) { - int temp = atomic_read(&stats->br[i]); + int temp = counter_atomic32_read(&stats->br[i]); if (temp) seq_printf(m, "%s%s: %d\n", prefix, @@ -5863,8 +5864,8 @@ static void print_binder_stats(struct seq_file *m, const char *prefix, BUILD_BUG_ON(ARRAY_SIZE(stats->obj_created) != ARRAY_SIZE(stats->obj_deleted)); for (i = 0; i < ARRAY_SIZE(stats->obj_created); i++) { - int created = atomic_read(&stats->obj_created[i]); - int deleted = atomic_read(&stats->obj_deleted[i]); + int created = counter_atomic32_read(&stats->obj_created[i]); + int deleted = counter_atomic32_read(&stats->obj_deleted[i]); if (created || deleted) seq_printf(m, "%s%s: active %d total %d\n", @@ -6054,7 +6055,7 @@ static void print_binder_transaction_log_entry(struct seq_file *m, int binder_transaction_log_show(struct seq_file *m, void *unused) { struct binder_transaction_log *log = m->private; - unsigned int log_cur = atomic_read(&log->cur); + unsigned int log_cur = counter_atomic32_read(&log->cur); unsigned int count; unsigned int cur; int i; @@ -6124,8 +6125,8 @@ static int __init binder_init(void) if (ret) return ret; - atomic_set(&binder_transaction_log.cur, ~0U); - atomic_set(&binder_transaction_log_failed.cur, ~0U); + counter_atomic32_set(&binder_transaction_log.cur, ~0U); + counter_atomic32_set(&binder_transaction_log_failed.cur, ~0U); binder_debugfs_dir_entry_root = debugfs_create_dir("binder", NULL); if (binder_debugfs_dir_entry_root) diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h index 283d3cb9c16e..c77960c01430 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -12,6 +12,7 @@ #include #include #include +#include struct binder_context { struct binder_node *binder_context_mgr_node; @@ -136,7 +137,7 @@ struct binder_transaction_log_entry { }; struct binder_transaction_log { - atomic_t cur; + struct counter_atomic32 cur; bool full; struct binder_transaction_log_entry entry[32]; }; -- 2.25.1