[PATCH 10/24] bsd-user: Add host_to_target_semid_ds for semctl(2)

Warner Losh posted 24 patches 3 days, 16 hours ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Riku Voipio <riku.voipio@iki.fi>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[PATCH 10/24] bsd-user: Add host_to_target_semid_ds for semctl(2)
Posted by Warner Losh 3 days, 16 hours ago
From: Stacey Son <sson@FreeBSD.org>

Add host_to_target_semid_ds() to convert host struct semid_ds to target
format for semctl(2) IPC_STAT operations.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-misc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
index 581eb50355..f35f682aa4 100644
--- a/bsd-user/bsd-misc.c
+++ b/bsd-user/bsd-misc.c
@@ -134,3 +134,23 @@ abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
     unlock_user_struct(target_sd, target_addr, 0);
     return 0;
 }
+
+abi_long host_to_target_semid_ds(abi_ulong target_addr,
+        struct semid_ds *host_sd)
+{
+    struct target_semid_ds *target_sd;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+    host_to_target_ipc_perm__locked(&target_sd->sem_perm,
+                                    &host_sd->sem_perm);
+    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
+    /* target_sd->sem_base = h2g((void *)host_sd->sem_base); */
+    target_sd->sem_nsems = tswap16(host_sd->sem_nsems);
+    target_sd->sem_otime = tswapal(host_sd->sem_otime);
+    target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
+    unlock_user_struct(target_sd, target_addr, 1);
+
+    return 0;
+}

-- 
2.52.0
Re: [PATCH 10/24] bsd-user: Add host_to_target_semid_ds for semctl(2)
Posted by Richard Henderson 3 days, 7 hours ago
On 2/6/26 03:26, Warner Losh wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> Add host_to_target_semid_ds() to convert host struct semid_ds to target
> format for semctl(2) IPC_STAT operations.
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/bsd-misc.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
> index 581eb50355..f35f682aa4 100644
> --- a/bsd-user/bsd-misc.c
> +++ b/bsd-user/bsd-misc.c
> @@ -134,3 +134,23 @@ abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
>       unlock_user_struct(target_sd, target_addr, 0);
>       return 0;
>   }
> +
> +abi_long host_to_target_semid_ds(abi_ulong target_addr,
> +        struct semid_ds *host_sd)
> +{
> +    struct target_semid_ds *target_sd;
> +
> +    if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
> +        return -TARGET_EFAULT;
> +    }
> +    host_to_target_ipc_perm__locked(&target_sd->sem_perm,
> +                                    &host_sd->sem_perm);
> +    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
> +    /* target_sd->sem_base = h2g((void *)host_sd->sem_base); */
> +    target_sd->sem_nsems = tswap16(host_sd->sem_nsems);
> +    target_sd->sem_otime = tswapal(host_sd->sem_otime);
> +    target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
> +    unlock_user_struct(target_sd, target_addr, 1);
> +
> +    return 0;
> +}
> 

Probably should use __put_user instead, but this isn't wrong.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Re: [PATCH 10/24] bsd-user: Add host_to_target_semid_ds for semctl(2)
Posted by Warner Losh 2 days, 16 hours ago
On Thu, Feb 5, 2026 at 7:46 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/6/26 03:26, Warner Losh wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Add host_to_target_semid_ds() to convert host struct semid_ds to target
> > format for semctl(2) IPC_STAT operations.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   bsd-user/bsd-misc.c | 20 ++++++++++++++++++++
> >   1 file changed, 20 insertions(+)
> >
> > diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c
> > index 581eb50355..f35f682aa4 100644
> > --- a/bsd-user/bsd-misc.c
> > +++ b/bsd-user/bsd-misc.c
> > @@ -134,3 +134,23 @@ abi_long target_to_host_semid_ds(struct semid_ds
> *host_sd,
> >       unlock_user_struct(target_sd, target_addr, 0);
> >       return 0;
> >   }
> > +
> > +abi_long host_to_target_semid_ds(abi_ulong target_addr,
> > +        struct semid_ds *host_sd)
> > +{
> > +    struct target_semid_ds *target_sd;
> > +
> > +    if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) {
> > +        return -TARGET_EFAULT;
> > +    }
> > +    host_to_target_ipc_perm__locked(&target_sd->sem_perm,
> > +                                    &host_sd->sem_perm);
> > +    /* sem_base is not used by kernel for IPC_STAT/IPC_SET */
> > +    /* target_sd->sem_base = h2g((void *)host_sd->sem_base); */
> > +    target_sd->sem_nsems = tswap16(host_sd->sem_nsems);
> > +    target_sd->sem_otime = tswapal(host_sd->sem_otime);
> > +    target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
> > +    unlock_user_struct(target_sd, target_addr, 1);
> > +
> > +    return 0;
> > +}
> >
>
> Probably should use __put_user instead, but this isn't wrong.
>

Agreed.


> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> r~
>
>