Re: [Qemu-devel] [PATCH v6 4/8] linux-user/syscall: Introduce target_sockaddr_nl
Le 11/09/2019 à 21:34, Philippe Mathieu-Daudé a écrit : > On Mon, Sep 9, 2019 at 4:23 PM Laurent Vivier wrote: >> Le 08/09/2019 à 08:15, Philippe Mathieu-Daudé a écrit : >>> Signed-off-by: Philippe Mathieu-Daudé >>> Tested-By: Guido Günther >>> --- >>> linux-user/syscall.c | 6 -- >>> linux-user/syscall_defs.h | 7 +++ >>> 2 files changed, 11 insertions(+), 2 deletions(-) >>> >>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c >>> index 8b41a03901..5128312db5 100644 >>> --- a/linux-user/syscall.c >>> +++ b/linux-user/syscall.c >>> @@ -1494,8 +1494,10 @@ static inline abi_long >>> host_to_target_sockaddr(abi_ulong target_addr, >>> sizeof(target_saddr->sa_family)) { >>> target_saddr->sa_family = tswap16(addr->sa_family); >>> } >>> -if (addr->sa_family == AF_NETLINK && len >= sizeof(struct >>> sockaddr_nl)) { >>> -struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; >>> +if (addr->sa_family == AF_NETLINK && >>> +len >= sizeof(struct target_sockaddr_nl)) { >>> +struct target_sockaddr_nl *target_nl = >>> + (struct target_sockaddr_nl *)target_saddr; >>> target_nl->nl_pid = tswap32(target_nl->nl_pid); >>> target_nl->nl_groups = tswap32(target_nl->nl_groups); >>> } else if (addr->sa_family == AF_PACKET) { >>> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h >>> index 0662270300..fcedd0d0fb 100644 >>> --- a/linux-user/syscall_defs.h >>> +++ b/linux-user/syscall_defs.h >>> @@ -153,6 +153,13 @@ struct target_sockaddr_un { >>> uint8_t sun_path[108]; >>> }; >>> >>> +struct target_sockaddr_nl { >>> +uint16_t nl_family; /* AF_NETLINK */ >>> +uint16_t __pad; >>> +uint32_t nl_pid; >>> +uint32_t nl_groups; >>> +}; >> >> You should use abi_ushort and abi_uint to keep alignments good (for >> instance m68k aligns on 16bit whereas others on 32bit). > > Are you sure? The other target_sockaddr don't use that... > Is this because netlink is a host-only structure? (while other are > serialized over some interface). I think other target_sockaddr are wrong too. No one takes really care of alignment, and most of the time structures are by construction well aligned. Thanks, Laurent
Re: [Qemu-devel] [PATCH v6 4/8] linux-user/syscall: Introduce target_sockaddr_nl
On Mon, Sep 9, 2019 at 4:23 PM Laurent Vivier wrote: > Le 08/09/2019 à 08:15, Philippe Mathieu-Daudé a écrit : > > Signed-off-by: Philippe Mathieu-Daudé > > Tested-By: Guido Günther > > --- > > linux-user/syscall.c | 6 -- > > linux-user/syscall_defs.h | 7 +++ > > 2 files changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > > index 8b41a03901..5128312db5 100644 > > --- a/linux-user/syscall.c > > +++ b/linux-user/syscall.c > > @@ -1494,8 +1494,10 @@ static inline abi_long > > host_to_target_sockaddr(abi_ulong target_addr, > > sizeof(target_saddr->sa_family)) { > > target_saddr->sa_family = tswap16(addr->sa_family); > > } > > -if (addr->sa_family == AF_NETLINK && len >= sizeof(struct > > sockaddr_nl)) { > > -struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; > > +if (addr->sa_family == AF_NETLINK && > > +len >= sizeof(struct target_sockaddr_nl)) { > > +struct target_sockaddr_nl *target_nl = > > + (struct target_sockaddr_nl *)target_saddr; > > target_nl->nl_pid = tswap32(target_nl->nl_pid); > > target_nl->nl_groups = tswap32(target_nl->nl_groups); > > } else if (addr->sa_family == AF_PACKET) { > > diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h > > index 0662270300..fcedd0d0fb 100644 > > --- a/linux-user/syscall_defs.h > > +++ b/linux-user/syscall_defs.h > > @@ -153,6 +153,13 @@ struct target_sockaddr_un { > > uint8_t sun_path[108]; > > }; > > > > +struct target_sockaddr_nl { > > +uint16_t nl_family; /* AF_NETLINK */ > > +uint16_t __pad; > > +uint32_t nl_pid; > > +uint32_t nl_groups; > > +}; > > You should use abi_ushort and abi_uint to keep alignments good (for > instance m68k aligns on 16bit whereas others on 32bit). Are you sure? The other target_sockaddr don't use that... Is this because netlink is a host-only structure? (while other are serialized over some interface). Thanks, Phil.
Re: [Qemu-devel] [PATCH v6 4/8] linux-user/syscall: Introduce target_sockaddr_nl
Le 08/09/2019 à 08:15, Philippe Mathieu-Daudé a écrit : > Signed-off-by: Philippe Mathieu-Daudé > Tested-By: Guido Günther > --- > linux-user/syscall.c | 6 -- > linux-user/syscall_defs.h | 7 +++ > 2 files changed, 11 insertions(+), 2 deletions(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 8b41a03901..5128312db5 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -1494,8 +1494,10 @@ static inline abi_long > host_to_target_sockaddr(abi_ulong target_addr, > sizeof(target_saddr->sa_family)) { > target_saddr->sa_family = tswap16(addr->sa_family); > } > -if (addr->sa_family == AF_NETLINK && len >= sizeof(struct sockaddr_nl)) { > -struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; > +if (addr->sa_family == AF_NETLINK && > +len >= sizeof(struct target_sockaddr_nl)) { > +struct target_sockaddr_nl *target_nl = > + (struct target_sockaddr_nl *)target_saddr; > target_nl->nl_pid = tswap32(target_nl->nl_pid); > target_nl->nl_groups = tswap32(target_nl->nl_groups); > } else if (addr->sa_family == AF_PACKET) { > diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h > index 0662270300..fcedd0d0fb 100644 > --- a/linux-user/syscall_defs.h > +++ b/linux-user/syscall_defs.h > @@ -153,6 +153,13 @@ struct target_sockaddr_un { > uint8_t sun_path[108]; > }; > > +struct target_sockaddr_nl { > +uint16_t nl_family; /* AF_NETLINK */ > +uint16_t __pad; > +uint32_t nl_pid; > +uint32_t nl_groups; > +}; You should use abi_ushort and abi_uint to keep alignments good (for instance m68k aligns on 16bit whereas others on 32bit). Thanks, Laurent
[Qemu-devel] [PATCH v6 4/8] linux-user/syscall: Introduce target_sockaddr_nl
Signed-off-by: Philippe Mathieu-Daudé Tested-By: Guido Günther --- linux-user/syscall.c | 6 -- linux-user/syscall_defs.h | 7 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8b41a03901..5128312db5 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1494,8 +1494,10 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, sizeof(target_saddr->sa_family)) { target_saddr->sa_family = tswap16(addr->sa_family); } -if (addr->sa_family == AF_NETLINK && len >= sizeof(struct sockaddr_nl)) { -struct sockaddr_nl *target_nl = (struct sockaddr_nl *)target_saddr; +if (addr->sa_family == AF_NETLINK && +len >= sizeof(struct target_sockaddr_nl)) { +struct target_sockaddr_nl *target_nl = + (struct target_sockaddr_nl *)target_saddr; target_nl->nl_pid = tswap32(target_nl->nl_pid); target_nl->nl_groups = tswap32(target_nl->nl_groups); } else if (addr->sa_family == AF_PACKET) { diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 0662270300..fcedd0d0fb 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -153,6 +153,13 @@ struct target_sockaddr_un { uint8_t sun_path[108]; }; +struct target_sockaddr_nl { +uint16_t nl_family; /* AF_NETLINK */ +uint16_t __pad; +uint32_t nl_pid; +uint32_t nl_groups; +}; + struct target_in_addr { uint32_t s_addr; /* big endian */ }; -- 2.20.1