Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2058979iob; Fri, 20 May 2022 00:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzInmiHJO8hpmZIxZzorbZTfv1N8Yy26QnFGXwbot62RgTA5lcpmdURAevRJ+UT28Uy1oGz X-Received: by 2002:a17:902:b203:b0:161:de49:10d3 with SMTP id t3-20020a170902b20300b00161de4910d3mr6270346plr.109.1653031530801; Fri, 20 May 2022 00:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653031530; cv=none; d=google.com; s=arc-20160816; b=T0YbT/eiIMSWXTc5qwVFkt9zE0mPfO4PBOvP3I0QP9SxvTyuej+AtfR57x3fyTA+p2 xc54W325LaJIuNmw07cBrXWY4zKievxjBS8NyCzm4dHpuC8/0SiEaf1FMNDr3PQLB3X+ v3R6I8YEIku5/NUwR5FkbLNnJxGr4ywnYHrxi8X+AVL9N/aL1YUAZHb+g6pAHLkS7eVJ qQbnmInecpC0I85r6u3Du81BNqa4QIeY0FH6uQFvxdudOWHpMt7BumeobBBwKVwtbL7f NGMnYiYkx1UBLm+7/eMOoqm3FuOsuExUw4Ix2mNUEy1ONQUB9nVGIezIaj8q85nGAjEj hVDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3mLS4PfQr+FDNI3uFdJ7+BYDJ3LWS+aKjrtyVzRLVpY=; b=YBmk6qlsav15PBtJXSO73rAh+QqSNDIW9fn+Io1xNQp9eM+t25WHsE+un4l6Ex4nXV ruoR/0QCyKQZH8B2zrgdXxIsywQwz3q/w/VCFYArIwBEdzAJbWL1U90j1Y6zKR5DYLBX sgpbr0Ggt6UyG9ASE1zkPT3sMgNes6Z9Y0YvtLTkjvhBL8KTdbY5t3nQ2+emP2IhJRrT g3FlyHFX3knW8zcIq4JL+eeD0TL94w+ovOfhw2A7InffX+/ld/YO493t9KR7gRflXbJ5 H0YN4sTJOwuHW8MMHVMr/2Ky5XZx15hHIFSWgNk5mA//FDk9aVOJydh6toymVQl6iTX0 h27Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WMa5x8l6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a170902cf4200b001570e00e0cesi8811133plg.536.2022.05.20.00.25.18; Fri, 20 May 2022 00:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WMa5x8l6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242507AbiESRVm (ORCPT + 99 others); Thu, 19 May 2022 13:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232931AbiESRVj (ORCPT ); Thu, 19 May 2022 13:21:39 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C6A9E9FF for ; Thu, 19 May 2022 10:21:36 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-2fedd26615cso63643607b3.7 for ; Thu, 19 May 2022 10:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3mLS4PfQr+FDNI3uFdJ7+BYDJ3LWS+aKjrtyVzRLVpY=; b=WMa5x8l6tFoxGelsCird41pK0BBotvFBfvnE5lwAdL/kgrGv6gu86m+TJd0JyCaXE2 SeJisA5KBdLUbqM6JhWR9PKhwqYmnk0OsE019K0ueszy1r3lXgYJHWlhn8lp43uUeppZ 8ds7Pg5NNzov+e4FToqf03y/SseCfayzEqKBQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3mLS4PfQr+FDNI3uFdJ7+BYDJ3LWS+aKjrtyVzRLVpY=; b=SC7VAdoxToK3G9WMeRuyHoUJVlOYa6+QmaKu6sTrPoNBUfkr0b6i2Gmqsq9BsQXdjw JC5EvzfoQyrP4RlqZ3E6holIITNAxTJ9mkS8pErf/lfvI9bApVPakSCjm0jHv7wdJrD6 Hn/IEsXIbYQJBGUPWLaric+CcG7MuCeKjjfgweq78I2M8WA00mCMCUvc+UnoNwrsJyDh zpxgUT+4mZtUUTduC44OtTJydRLW+LNtnGb9j3IJ11qX1xDvunygX1rvEUsGm2KU1+9+ mAI/i8RvilxCYlQXrHyzRxqjKLwuQGpgtGTnxNXQCtBcHwV8kvwG/WfeJZONxI+hjZNN XLMg== X-Gm-Message-State: AOAM531e5nNn6UiDd5U7Gi7Zae0hSrkZHr+7FEEd4H+1zN2TysigOfY/ zJzzqFAWSRMfBUEEwt4NZ+Q004dlsmcIluV+1ojbfQ== X-Received: by 2002:a81:8450:0:b0:2ff:c13:17d1 with SMTP id u77-20020a818450000000b002ff0c1317d1mr6004756ywf.207.1652980895889; Thu, 19 May 2022 10:21:35 -0700 (PDT) MIME-Version: 1.0 References: <20220519000623.1715899-1-dualli@chromium.org> In-Reply-To: From: Li Li Date: Thu, 19 May 2022 10:21:25 -0700 Message-ID: Subject: Re: [PATCH v1] Binder: add TF_UPDATE_TXN To: Greg KH Cc: dualli@google.com, tkjos@google.com, christian@brauner.io, arve@android.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, maco@google.com, hridya@google.com, surenb@google.com, joel@joelfernandes.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 19, 2022 at 8:50 AM Greg KH wrote: > > On Wed, May 18, 2022 at 05:06:23PM -0700, Li Li wrote: > > From: Li Li > > Note, your subject does not say what TF_UPDATE_TXN is, so it's a bit > hard to determine what is happening here. Can you clean that up a bit > and sumarize what this new addition does? Sure, I'll add a brief summary there. > > > > > When the target process is busy, incoming oneway transactions are > > queued in the async_todo list. If the clients continue sending extra > > oneway transactions while the target process is frozen, this queue can > > become too large to accommodate new transactions. That's why binder > > driver introduced ONEWAY_SPAM_DETECTION to detect this situation. It's > > helpful to debug the async binder buffer exhausting issue, but the > > issue itself isn't solved directly. > > > > In real cases applications are designed to send oneway transactions > > repeatedly, delivering updated inforamtion to the target process. > > Typical examples are Wi-Fi signal strength and some real time sensor > > data. Even if the apps might only care about the lastet information, > > all outdated oneway transactions are still accumulated there until the > > frozen process is thawed later. For this kind of situations, there's > > no existing method to skip those outdated transactions and deliver the > > latest one only. > > > > This patch introduces a new transaction flag TF_UPDATE_TXN. To use it, > > use apps can set this new flag along with TF_ONE_WAY. When such an > > oneway transaction is to be queued into the async_todo list of a frozen > > process, binder driver will check if any previous pending transactions > > can be superseded by comparing their code, flags and target node. If > > such an outdated pending transaction is found, the latest transaction > > will supersede that outdated one. This effectively prevents the async > > binder buffer running out and saves unnecessary binder read workloads. > > > > Signed-off-by: Li Li > > --- > > drivers/android/binder.c | 90 ++++++++++++++++++++++++++++- > > drivers/android/binder_trace.h | 4 ++ > > include/uapi/linux/android/binder.h | 1 + > > How was this tested? Old kernel: without this TF_UPDATE_TXN patch New kernel: with this TF_UPDATE_TXN patch Old apps: without setting TF_UPDATE_TXN New apps: if (flags & TF_ONE_WAY) flags |= TF_UPDATE_TXN; 1. Compatibility: New kernel + Old apps, to verify the original behavior doesn't change; 2. Compatibility: Old kernel + New apps, to verify the original behavior doesn't change; 3. Unit test: New kernel + New apps, to verify the outdated oneway binder transaction is actually superseded by the latest one (by enabling BINDER_DEBUG logs); 4. Stress test: New kernel + New apps sending oneway binder transactions repeatedly, to verify the size of the available async binder buffer over time, and if the transactions fail as before (due to async buffer running out). > > > 3 files changed, 92 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > > index f3b639e89dd8..153486a32d69 100644 > > --- a/drivers/android/binder.c > > +++ b/drivers/android/binder.c > > @@ -2594,6 +2594,60 @@ static int binder_fixup_parent(struct list_head *pf_head, > > return binder_add_fixup(pf_head, buffer_offset, bp->buffer, 0); > > } > > > > +/** > > + * binder_can_update_transaction() - Can a txn be superseded by an updated one? > > + * @t1: the pending async txn in the frozen process > > + * @t2: the new async txn to supersede the outdated pending one > > + * > > + * Return: true if t2 can supersede t1 > > + * false if t2 can not supersede t1 > > + */ > > +static bool binder_can_update_transaction(struct binder_transaction *t1, > > + struct binder_transaction *t2) > > +{ > > + if ((t1->flags & t2->flags & (TF_ONE_WAY | TF_UPDATE_TXN)) > > + != (TF_ONE_WAY | TF_UPDATE_TXN) > > + || t1->to_proc == NULL || t2->to_proc == NULL) > > + return false; > > + if (t1->to_proc->tsk == t2->to_proc->tsk && t1->code == t2->code > > + && t1->flags == t2->flags > > + && t1->buffer->pid == t2->buffer->pid > > + && t1->buffer->target_node->ptr > > + == t2->buffer->target_node->ptr > > + && t1->buffer->target_node->cookie > > + == t2->buffer->target_node->cookie) > > Did checkpatch pass this? Please always use --strict and fix up all the > issues that it reports as this is not a normal kernel coding style, > sorry. It passed checkpatch but --strict does suggest I adjust the logical ops. I'll update it in v2. Thanks for reminding me about using --strict. Thanks, Li