Binder ABI updates for 64bit systems for staging-next
cover Binder ABI updates for 64bit systems for staging-next
Wanted to re-submit to staging-next two changes from the AOSP common.git android-3.10 branch, which provide ABI fixes and introduce a new ABI and protocol version for binder, along with compatibility support for existing systems.
This new ABI allows for both 32bit and 64bit applications to co-exist, which wasn't previously possible due to word size assumptions in the binder protocol.
Also included is a minor tweak from me to make the Kconfig compatibility entry a bit more clear.
The changes have been updated to improve their commit message since the last time they were submitted. Thanks to Arve for the extra context and Serban for help with the wording.
thanks
-john
Arve Hjønnevåg (1):
staging: binder: Support concurrent 32 bit and 64 bit processes.
John Stultz (1):
staging: binder: Improve Kconfig entry for ANDROID_BINDER_IPC_32BIT
Serban Constantinescu (1):
staging: binder: Fix ABI for 64bit Android
drivers/staging/android/Kconfig | 13 ++ drivers/staging/android/binder.c | 268 ++++++++++++++++++--------------- drivers/staging/android/binder.h | 4 + drivers/staging/android/binder_trace.h | 14 +- drivers/staging/android/uapi/binder.h | 77 ++++++---- 5 files changed, 224 insertions(+), 152 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/3 staging: binder: Fix ABI for 64bit Android
From: Serban Constantinescu <[email protected]>
BC_REQUEST_DEATH_NOTIFICATION and BC_CLEAR_DEATH_NOTIFICATION were defined with the wrong structure that did not match the code. Since a binder pointer and handle are the same size on 32 bit systems, this change does not affect them. The two commands claimed they were using struct binder_ptr_cookie but they are using a 32bit handle and a pointer.
The main purpose of this patch is to add the binder_handle_cookie struct so the service manager does not have to define its own version (libbinder writes one field at a time so it does not use the struct).
On 32bit systems the payload size is the same as the size of struct binder_ptr_cookie. On 64bit systems, the size does differ, and the ioctl number does change. However, there are no known 64bit users of this interface, and any 64bit systems will need the following patch to run 32 bit processes anyway, so it is not expected that anyone will ship a 64bit system without this change, so this change should not affect any existing systems.
[jstultz: Few 80+ col fixes for checkpatch, improved commit message with help from Serban, and included rational from Arve's email]
--- drivers/staging/android/uapi/binder.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/staging/android/uapi/binder.h +11 -4
@@ -152,6 +152,11 @@ struct binder_ptr_cookie {void *cookie; }; +struct binder_handle_cookie { +__u32 handle; +void *cookie; +} __attribute__((packed)); +struct binder_pri_desc {__s32 priority;__u32 desc;
@@ -308,15 +313,17 @@ enum binder_driver_command_protocol {* of looping threads it has available. */ - BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_ptr_cookie), +BC_REQUEST_DEATH_NOTIFICATION =_IOW ('c' ,14 , + struct binder_handle_cookie),/* -* void *: ptr to binder +* int: handle * void *: cookie */ - BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_ptr_cookie), +BC_CLEAR_DEATH_NOTIFICATION =_IOW ('c' ,15 , + struct binder_handle_cookie),/* -* void *: ptr to binder +* int: handle * void *: cookie */
Signature · 1 line
1.8.3.2
PATCH 2/3 staging: binder: Support concurrent 32 bit and 64 bit processes.
In reply to John StultzFrom: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and size_t with binder_uintptr_t and binder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
* __u32 - on legacy 32bit only userspace
* __u64 - on mixed 32/64bit userspace where all processes use the same
interface.
This change also increments the BINDER_CURRENT_PROTOCOL_VERSION to 8 and hooks the compat_ioctl entry for the mixed 32/64bit Android userspace.
This patch also provides a CONFIG_ANDROID_BINDER_IPC_32BIT option for compatability, which if set which enables the old protocol on 32 bit systems.
Please note that all 64bit kernels will use the 64bit Binder ABI.
[jstultz: Merged with upstream type changes. Various whitespace fixes and longer Kconfig description for checkpatch. Included improved commit message from Serban (with a few tweaks).]
--- drivers/staging/android/Kconfig | 12 ++ drivers/staging/android/binder.c | 268 ++++++++++++++++++--------------- drivers/staging/android/binder.h | 4 + drivers/staging/android/binder_trace.h | 14 +- drivers/staging/android/uapi/binder.h | 64 +++++--- 5 files changed, 213 insertions(+), 149 deletions(-)
drivers/staging/android/Kconfig +12 -0
@@ -20,6 +20,18 @@ config ANDROID_BINDER_IPC Android process, using Binder to identify, invoke and pass arguments between said processes. +config ANDROID_BINDER_IPC_32BIT + bool "Use old 32-bit binder api" + depends on !64BIT + ---help--- + The Binder API has been changed to support both 32 and 64bit + applications in a mixed environment. + + Enable this to support an old 32-bit Android user-space (v4.4 and + earlier). + + Note that enabling this will break newer Android user-space. + config ASHMEM bool "Enable the Anonymous Shared Memory Subsystem" default n
drivers/staging/android/binder.c +150 -118
612 lines not on this page · raw message
drivers/staging/android/binder.h +4 -0
@@ -20,6 +20,10 @@#ifndef _LINUX_BINDER_H#define _LINUX_BINDER_H +#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT +#define BINDER_IPC_32BIT 1 +#endif +#include "uapi/binder.h" #endif /* _LINUX_BINDER_H */
drivers/staging/android/binder_trace.h +8 -6
@@ -152,7 +152,7 @@ TRACE_EVENT(binder_transaction_node_to_ref,TP_STRUCT__entry (__field (int ,debug_id )__field (int, node_debug_id) - __field(void __user *, node_ptr) +__field (binder_uintptr_t, node_ptr)__field (int, ref_debug_id)__field (uint32_t, ref_desc) ),
@@ -163,8 +163,9 @@ TRACE_EVENT(binder_transaction_node_to_ref, __entry->ref_debug_id = ref->debug_id; __entry->ref_desc = ref->desc; ), -TP_printk ("transaction=%d node=%d src_ptr=0x%p ==> dest_ref=%d dest_desc=%d" , - __entry->debug_id, __entry->node_debug_id, __entry->node_ptr, +TP_printk ("transaction=%d node=%d src_ptr=0x%016llx ==> dest_ref=%d dest_desc=%d" , + __entry->debug_id, __entry->node_debug_id, + (u64 )__entry->node_ptr, __entry->ref_debug_id, __entry->ref_desc) );
@@ -177,7 +178,7 @@ TRACE_EVENT(binder_transaction_ref_to_node, __field(int, ref_debug_id) __field(uint32_t, ref_desc) __field(int, node_debug_id) - __field(void __user *, node_ptr) +__field (binder_uintptr_t, node_ptr) ),TP_fast_assign ( __entry->debug_id = t->debug_id;
@@ -186,9 +187,10 @@ TRACE_EVENT(binder_transaction_ref_to_node, __entry->node_debug_id = ref->node->debug_id; __entry->node_ptr = ref->node->ptr; ), -TP_printk ("transaction=%d node=%d src_ref=%d src_desc=%d ==> dest_ptr=0x%p" , +TP_printk ("transaction=%d node=%d src_ref=%d src_desc=%d ==> dest_ptr=0x%016llx" , __entry->debug_id, __entry->node_debug_id, - __entry->ref_debug_id, __entry->ref_desc, __entry->node_ptr) + __entry->ref_debug_id, __entry->ref_desc, + (u64 )__entry->node_ptr) ); TRACE_EVENT(binder_transaction_ref_to_ref,
drivers/staging/android/uapi/binder.h +39 -25
149 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.
It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 6 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.Please note that all 64bit kernels will use the 64bit Binder ABI.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.
Quoted 8 lines
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 3 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.
Ok. I thought that point was covered by the detail on CONFIG_ANDROID_BINDER_IPC_32BIT, but maybe its not explicit enough.
Would you be ok with:
This change also increments the BINDER_CURRENT_PROTOCOL_VERSION to 8 and hooks the compat_ioctl entry for the mixed 32/64bit Android userspace.
This patch also provides a CONFIG_ANDROID_BINDER_IPC_32BIT option for compatability, which if set which enables the old protocol, setting BINDER_CURRENT_PROTOCOL_VERSION to 7, on 32 bit systems.
?
thanks
-john
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 30 lines · John Stultz
Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.Quoted 8 lines
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 3 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.Ok. I thought that point was covered by the detail on
CONFIG_ANDROID_BINDER_IPC_32BIT, but maybe its not explicit enough.Would you be ok with:
Quoted 9 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol, settingBINDER_CURRENT_PROTOCOL_VERSIONto 7, on 32 bit systems.?
Yes, but replacing "This change" with "Selecting the 64 bit interface" would also work.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 33 lines · Arve Hjønnevåg
Quoted 32 lines · John Stultz
Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.Quoted 8 lines
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 3 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.Ok. I thought that point was covered by the detail on
CONFIG_ANDROID_BINDER_IPC_32BIT, but maybe its not explicit enough.Would you be ok with:
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.
Quoted 8 lines
Quoted 6 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol, settingBINDER_CURRENT_PROTOCOL_VERSIONto 7, on 32 bit systems.?
Yes, but replacing "This change" with "Selecting the 64 bit interface" would also work.
Ok.. I might stick to my wording above since with this patch, the 64bit interface is now the unconditional case, with the 32bit interface having the config option. So it might be more clear as there is no 64bit interface option to select.
I'll add that bit and resend. Everything else in the patch series ok by you?
thanks
-john
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 43 lines · John Stultz
Quoted 33 lines · Arve Hjønnevåg
Quoted 32 lines · John Stultz
Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.Quoted 8 lines
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 3 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.Ok. I thought that point was covered by the detail on
CONFIG_ANDROID_BINDER_IPC_32BIT, but maybe its not explicit enough.Would you be ok with:
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.Quoted 8 lines
Quoted 6 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol, settingBINDER_CURRENT_PROTOCOL_VERSIONto 7, on 32 bit systems.?
Yes, but replacing "This change" with "Selecting the 64 bit interface" would also work.
Quoted 7 lines
Ok.. I might stick to my wording above since with this patch, the 64bit interface is now the unconditional case, with the 32bit interface having the config option. So it might be more clear as there is no 64bit interface option to select.
I'll add that bit and resend. Everything else in the patch series ok by you?
Assuming you did not change the code, yes.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/3] staging: binder: Support concurrent 32 bit and 64 bit processes.
Quoted 43 lines · Arve Hjønnevåg
Quoted 42 lines · John Stultz
Quoted 41 lines · Arve Hjønnevåg
Quoted 29 lines · John Stultz
Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · John Stultz
From: Arve Hjønnevåg <[email protected]>
For 64bit systems we want to use the same binder interface for 32bit and 64bit processes. Thus the size and the layout of the structures passed between the kernel and the userspace has to be the same for both 32 and 64bit processes.
This change replaces all the uses of void* and
size_twithbinder_uintptr_tandbinder_size_t. These are then typedefed to specific sizes depending on the use of the interface, as follows:
*__u32- on legacy 32bit only userspace
*__u64- on mixed 32/64bit userspace where all processes use the same
interface.Quoted 8 lines
Quoted 3 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.It only increments the version to 8 if the old 32 bit interface is not selected.
Quoted 3 lines
This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol on 32 bit systems.Ok. I thought that point was covered by the detail on
CONFIG_ANDROID_BINDER_IPC_32BIT, but maybe its not explicit enough.Would you be ok with:
Quoted 9 lines
This change also increments the
BINDER_CURRENT_PROTOCOL_VERSIONto 8 and hooks thecompat_ioctlentry for the mixed 32/64bit Android userspace.This patch also provides a
CONFIG_ANDROID_BINDER_IPC_32BIToption for compatability, which if set which enables the old protocol, settingBINDER_CURRENT_PROTOCOL_VERSIONto 7, on 32 bit systems.?
Yes, but replacing "This change" with "Selecting the 64 bit interface" would also work.
Quoted 8 lines
Quoted 7 lines
Ok.. I might stick to my wording above since with this patch, the 64bit interface is now the unconditional case, with the 32bit interface having the config option. So it might be more clear as there is no 64bit interface option to select.
I'll add that bit and resend. Everything else in the patch series ok by you?
Assuming you did not change the code, yes.
Nothing but whitespace formatting for checkpatch as noted in the commit log.
After these three patches, the binder diff from android-3.10 is only whitespace and the SELinux "Add security hooks to binder" patch which makes changes out of the staging directory.
thanks
-john
PATCH 3/3 staging: binder: Improve Kconfig entry for ANDROID_BINDER_IPC_32BIT
In reply to John StultzAdd a more clear explanation of the option in the prompt, and make the config depend on ANDROID_BINDER_IPC being selected.
Also sets the default to y, which matches AOSP.
--- drivers/staging/android/Kconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/android/Kconfig +3 -2
@@ -21,8 +21,9 @@ config ANDROID_BINDER_IPC between said processes. config ANDROID_BINDER_IPC_32BIT - bool "Use old 32-bit binder api" - depends on !64BIT + bool "Use old (Android 4.4 and earlier) 32-bit binder API" + depends on !64BIT && ANDROID_BINDER_IPC + default y ---help--- The Binder API has been changed to support both 32 and 64bit applications in a mixed environment.
Signature · 1 line
1.8.3.2