All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos Llamas <cmllamas@google.com>
To: Yu-Ting Tseng <yutingtseng@google.com>
Cc: Alice Ryhl <aliceryhl@google.com>,
	tkjos@google.com, gregkh@linuxfoundation.org, arve@android.com,
	maco@android.com, joel@joelfernandes.org, brauner@kernel.org,
	surenb@google.com, kernel-team@android.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] binder: frozen notification
Date: Mon, 24 Jun 2024 15:53:18 +0000	[thread overview]
Message-ID: <ZnmWbpPNjQf0UUYB@google.com> (raw)
In-Reply-To: <CAN5Drs0Gw6=xYVi0Naxm+A86mqckG4xjbEuvO9+UbAYHoEqYCw@mail.gmail.com>

On Mon, Jun 24, 2024 at 08:50:43AM -0700, Yu-Ting Tseng wrote:
> On Mon, Jun 24, 2024 at 7:25 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >
> > On Sat, Jun 22, 2024 at 5:22 AM Yu-Ting Tseng <yutingtseng@google.com> wrote:
> > >
> > > Frozen processes present a significant challenge in binder transactions.
> > > When a process is frozen, it cannot, by design, accept and/or respond to
> > > binder transactions. As a result, the sender needs to adjust its
> > > behavior, such as postponing transactions until the peer process
> > > unfreezes. However, there is currently no way to subscribe to these
> > > state change events, making it impossible to implement frozen-aware
> > > behaviors efficiently.
> > >
> > > Introduce a binder API for subscribing to frozen state change events.
> > > This allows programs to react to changes in peer process state,
> > > mitigating issues related to binder transactions sent to frozen
> > > processes.
> > >
> > > Implementation details:
> > > For a given binder_ref, the state of frozen notification can be one of
> > > the followings:
> > > 1. Userspace doesn't want a notification. binder_ref->freeze is null.
> > > 2. Userspace wants a notification but none is in flight.
> > >    list_empty(&binder_ref->freeze->work.entry) = true
> > > 3. A notification is in flight and waiting to be read by userspace.
> > >    binder_ref_freeze.sent is false.
> > > 4. A notification was read by userspace and kernel is waiting for an ack.
> > >    binder_ref_freeze.sent is true.
> > >
> > > When a notification is in flight, new state change events are coalesced into
> > > the existing binder_ref_freeze struct. If userspace hasn't picked up the
> > > notification yet, the driver simply rewrites the state. Otherwise, the
> > > notification is flagged as requiring a resend, which will be performed
> > > once userspace acks the original notification that's inflight.
> > >
> > > See https://android-review.googlesource.com/c/platform/frameworks/native/+/3070045
> > > for how userspace is going to use this feature.
> > >
> > > Signed-off-by: Yu-Ting Tseng <yutingtseng@google.com>
> >
> > [...]
> >
> > > +               /*
> > > +                * There is already a freeze notification. Take it over and rewrite
> > > +                * the work type. If it was already sent, flag it for re-sending;
> > > +                * Otherwise it's pending and will be sent soon.
> > > +                */
> > > +               freeze->work.type = BINDER_WORK_CLEAR_DEATH_NOTIFICATION;
> >
> > I have not done a comprehensive review yet, but this looks wrong.
> [resending as plain text]
> 
> Thanks for looking at the change!
> 
> The code here seems correct to me. Could you please elaborate why this
> looks wrong?
> 
> This part of code gets executed if freeze->work.entry is in a list.
> There are two possibilities:
> 1. The freeze work of type BINDER_WORK_FROZEN_BINDER is in the work
> queue, waiting to be picked up by binder_thread_read. Since it hasn't
> been picked up yet, this code rewrites the work type to
> BINDER_WORK_CLEAR_DEATH_NOTIFICATION, effectively canceling the state
> change notification and instead making binder_thread_read send a
> BR_CLEAR_FREEZE_NOTIFICATION_DONE to userspace. The API contract
> allows coalescing of events. I can explicitly mention this case if it
> helps.
> 2. The freeze work of type BINDER_WORK_FROZEN_BINDER is in the
> proc->delivered_freeze queue. This means a state change notification
> was just sent to userspace and the kernel is waiting for an ack.
> freeze->sent is true. In this case we set freeze->resend to true. Once
> the kernel receives the ack, it would queue up the work again, whose
> type was already set to BINDER_WORK_CLEAR_DEATH_NOTIFICATION.
> 
> Yu-Ting

Alice means you want to use BINDER_WORK_CLEAR_FREEZE_NOTIFICATION and
not BINDER_WORK_CLEAR_DEATH_NOTIFICATION. 

> 
> >
> >
> > Is there any chance that we could have a test in aosp that would have
> > caught this?
> >
> > Alice

  reply	other threads:[~2024-06-24 15:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240618221347.106627-1-yutingtseng@google.com>
2024-06-22  3:16 ` [PATCH v2] binder: frozen notification Yu-Ting Tseng
2024-06-22  3:16 ` Yu-Ting Tseng
2024-06-24 14:24   ` Alice Ryhl
2024-06-24 15:50     ` Yu-Ting Tseng
2024-06-24 15:53       ` Carlos Llamas [this message]
2024-06-24 15:56         ` Yu-Ting Tseng
2024-06-24 17:20           ` [PATCH v3] " Yu-Ting Tseng
2024-06-25  3:01             ` Yu-Ting Tseng
2024-06-24 17:20           ` [PATCH v3 1/1] " Yu-Ting Tseng
2024-06-28 18:42             ` Carlos Llamas
2024-07-01 18:23           ` [PATCH v4] " Yu-Ting Tseng
2024-07-01 18:27           ` Yu-Ting Tseng
2024-07-03  4:18             ` Carlos Llamas
2024-07-03 17:08           ` [PATCH v5] " Yu-Ting Tseng
2024-07-03 17:08           ` Yu-Ting Tseng
2024-07-03 17:58           ` [PATCH v6 0/2] " Yu-Ting Tseng
2024-07-04 13:00             ` Greg KH
2024-07-03 17:58           ` [PATCH v6 1/2] " Yu-Ting Tseng
2024-07-03 17:58           ` [PATCH v6 2/2] binder: frozen notification binder_features flag Yu-Ting Tseng
2024-06-24 15:10   ` [PATCH v2] binder: frozen notification Carlos Llamas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZnmWbpPNjQf0UUYB@google.com \
    --to=cmllamas@google.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joel@joelfernandes.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=surenb@google.com \
    --cc=tkjos@google.com \
    --cc=yutingtseng@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.