All of lore.kernel.org
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	kevans@freebsd.org, f4bug@amsat.org,
	"Thomas Huth" <thuth@redhat.com>,
	"Sean Bruno" <sbruno@freebsd.org>,
	"Juergen Lock" <nox@jelal.kn-bremen.de>,
	"Raphael Kubo da Costa" <rakuco@freebsd.org>,
	"Stacey Son" <sson@freebsd.org>
Subject: Re: [PATCH v2 06/12] bsd-user: Helper routines h2t_old_sysctl
Date: Tue, 14 Feb 2023 22:58:07 -0700	[thread overview]
Message-ID: <CANCZdfoxFN46R4hmh3ZadVtiyhrk5vQsOc4LaktQAG-bYRLYgA@mail.gmail.com> (raw)
In-Reply-To: <58c12d92-a371-deca-d320-285871ed6c03@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2996 bytes --]

On Tue, Feb 14, 2023 at 2:16 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 2/13/23 14:27, Warner Losh wrote:
> > +/*
> > + * Convert the old value from host to target.
>
> host vs guest is clearer language; "target" gets overloaded, even though
> still present in
> the code base.
>

OK. Will do. We have that all over the place upstream... I'll start there
too...


>
> > + *
> > + * For LONG and ULONG on ABI32, we need to 'down convert' the 8 byte
> quantities
> > + * to 4 bytes. The caller setup a buffer in host memory to get this
> data from
> > + * the kernel and pass it to us. We do the down conversion and adjust
> the length
> > + * so the caller knows what to write as the returned length into the
> target when
> > + * it copies the down converted values into the target.
> > + *
> > + * For normal integral types, we just need to byte swap. No size
> changes.
> > + *
> > + * For strings and node data, there's no conversion needed.
> > + *
> > + * For opaque data, per sysctl OID converts take care of it.
> > + */
> > +static void G_GNUC_UNUSED h2t_old_sysctl(void *holdp, size_t *holdlen,
> uint32_t kind)
>
> h2g.
>

OK.


> > +    /*
> > +     * hlen == 0 for CTLTYPE_STRING and CTLTYPE_NODE, which need no
> conversion
> > +     * as well as CTLTYPE_OPAQUE, which needs special converters.
> > +     */
> > +    if (hlen == 0) {
> > +        return;
> > +    }
> > +
> > +    while (len < *holdlen) {
> > +        if (hlen == tlen) {
> > +            switch (hlen) {
> > +            case 1:
> > +                /* Nothing needed: no byteswapping and assigning in
> place */
> > +                break;
> > +            case 2:
> > +                *(uint16_t *)tp = tswap16(*(uint16_t *)hp);
> > +                break;
> > +            case 4:
> > +                *(uint32_t *)tp = tswap32(*(uint32_t *)hp);
> > +                break;
> > +            case 8:
> > +                *(uint64_t *)tp = tswap64(*(uint64_t *)hp);
> > +                break;
> > +            }
>
> default: g_assert_not_reached().
>

Ah!  I need that in several places... Thanks.


> > +        }
> > +#ifdef TARGET_ABI32
> > +        else {
> > +            /*
> > +             * Saturating assignment for the only two types that differ
> between
> > +             * 32-bit and 64-bit machines. All other integral types
> have the
> > +             * same, fixed size and will be converted w/o loss of
> precision
> > +             * in the above switch.
> > +             */
> > +            switch (kind & CTLTYPE) {
> > +            case CTLTYPE_LONG:
> > +                *(abi_long *)tp = tswap32(h2t_long_sat(*(long *)hp));
> > +                break;
> > +            case CTLTYPE_ULONG:
> > +                *(abi_ulong *)tp = tswap32(h2t_ulong_sat(*(u_long
> *)hp));
> > +                break;
> > +            }
>
> default: g_assert_not_reached().
>
> > +        }
> > +#endif
>
> #else
>      g_assert_not_reached();
>

Gotcha... Thanks!

Warner


>
> r~
>

[-- Attachment #2: Type: text/html, Size: 4675 bytes --]

  reply	other threads:[~2023-02-15  5:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  0:27 [PATCH v2 00/12] 2023 Q1 bsd-user upstreaming: bugfixes and sysctl Warner Losh
2023-02-14  0:27 ` [PATCH v2 01/12] bsd-user: Don't truncate the return value from freebsd_syscall Warner Losh
2023-02-14  0:27 ` [PATCH v2 02/12] build: Don't specify -no-pie for --static user-mode programs Warner Losh
2023-02-14  0:27 ` [PATCH v2 03/12] bsd-user: Add sysarch syscall Warner Losh
2023-02-14  0:27 ` [PATCH v2 04/12] bsd-user: various helper routines for sysctl Warner Losh
2023-02-14 20:52   ` Richard Henderson
2023-02-14 21:31     ` Warner Losh
2023-02-14 21:39       ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 05/12] bsd-user: Helper routines oidfmt Warner Losh
2023-02-14 20:53   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 06/12] bsd-user: Helper routines h2t_old_sysctl Warner Losh
2023-02-14 21:16   ` Richard Henderson
2023-02-15  5:58     ` Warner Losh [this message]
2023-02-14  0:27 ` [PATCH v2 07/12] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Warner Losh
2023-02-14 21:18   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 08/12] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Warner Losh
2023-02-14 21:21   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 09/12] bsd-user: Start translation of arch-specific sysctls Warner Losh
2023-02-14 21:36   ` Richard Henderson
2023-02-16 22:57     ` Warner Losh
2023-02-14  0:27 ` [PATCH v2 10/12] bsd-user: do_freebsd_sysctl helper for sysctl(2) Warner Losh
2023-02-14 21:45   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 11/12] bsd-user: implement sysctlbyname(2) Warner Losh
2023-02-14 21:48   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 12/12] bsd-user: Add -strict Warner Losh
2023-02-14  6:57   ` Philippe Mathieu-Daudé
2023-02-14 21:49   ` Richard Henderson
2023-02-16 22:37     ` Warner Losh

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=CANCZdfoxFN46R4hmh3ZadVtiyhrk5vQsOc4LaktQAG-bYRLYgA@mail.gmail.com \
    --to=imp@bsdimp.com \
    --cc=alex.bennee@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=kevans@freebsd.org \
    --cc=nox@jelal.kn-bremen.de \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rakuco@freebsd.org \
    --cc=richard.henderson@linaro.org \
    --cc=sbruno@freebsd.org \
    --cc=sson@freebsd.org \
    --cc=thuth@redhat.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.