Re: [PATCH v11 2/2] binder: report txn errors via generic netlink

From: Li Li
Date: Thu Jan 09 2025 - 14:49:59 EST


Thank you for the suggestion!

Cleaning up in the NETLINK_URELEASE notifier is better since we
register the process with the netlink socket. I'll change the code
accordingly.

On Thu, Jan 9, 2025 at 11:30 AM Carlos Llamas <cmllamas@xxxxxxxxxx> wrote:
>
> On Thu, Jan 09, 2025 at 06:51:59PM +0000, Carlos Llamas wrote:
> > Did you happen to look into netlink_register_notifier()? That seems like
> > an option to keep the device vs netlink socket interface from mixing up.
> > I believe we could check for NETLINK_URELEASE events and do the cleanup
> > then. I'll do a quick try.
>
> Yeah, this quick prototype worked for me. Although I haven't looked at
> the api details closely.
>
> diff --git a/drivers/android/binder.c b/drivers/android/binder.c
> index 536be42c531e..fa2146cf02a7 100644
> --- a/drivers/android/binder.c
> +++ b/drivers/android/binder.c
> +static int binder_netlink_notify(struct notifier_block *nb,
> + + + + unsigned long action,
> + + + + void *data)
> +{
> + struct netlink_notify *n = data;
> + struct binder_device *device;
> +
> + if (action != NETLINK_URELEASE)
> + + return NOTIFY_DONE;
> +
> + hlist_for_each_entry(device, &binder_devices, hlist) {
> + + if (device->context.report_portid == n->portid)
> + + + pr_info("%s: socket released\n", __func__);
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block binder_netlink_notifier = {
> + .notifier_call = binder_netlink_notify,
> +};
> +
> static int __init binder_init(void)
> {
> + int ret;
> @@ -7244,6 +7259,8 @@ static int __init binder_init(void)
> + + goto err_init_binder_device_failed;
> + }
>
> + netlink_register_notifier(&binder_netlink_notifier);
> +
> + return ret;
>
> err_init_binder_device_failed:
>
>
> With that change we get notified when the socket that registered the
> report exits:
>
> root@debian:~# ./binder-netlink
> report setup complete!
> ^C[ 63.682485] binder: binder_netlink_notify: socket released
>
>
> I don't know if this would be the preferred approach to "install" a
> notification callback with a netlink socket but it works. wdyt?
>
> --
> Carlos Llamas