From: Richard Henderson <richard.henderson@linaro.org>
To: Warner Losh <imp@bsdimp.com>, qemu-devel@nongnu.org
Cc: "Thomas Huth" <thuth@redhat.com>,
"Kyle Evans" <kevans@freebsd.org>,
f4bug@amsat.org, "Alex Bennée" <alex.bennee@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Juergen Lock" <nox@jelal.kn-bremen.de>,
"Stacey Son" <sson@FreeBSD.org>
Subject: Re: [PATCH 6/9] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants
Date: Sat, 11 Feb 2023 12:56:33 -1000 [thread overview]
Message-ID: <b56a7205-0c22-16aa-f73b-267576b9950e@linaro.org> (raw)
In-Reply-To: <20230210231829.39476-7-imp@bsdimp.com>
On 2/10/23 13:18, Warner Losh wrote:
> + /* Handle some arch/emulator dependent sysctl()'s here. */
> + switch (snamep[0]) {
> +#if defined(TARGET_PPC) || defined(TARGET_PPC64)
> + case CTL_MACHDEP:
> + switch (snamep[1]) {
> + case 1: /* CPU_CACHELINE */
> + holdlen = sizeof(uint32_t);
> + (*(uint32_t *)holdp) = tswap32(env->dcache_line_size);
> + ret = 0;
> + goto out;
> + }
> + break;
> +#endif
abi_int instead of uint32_t.
> + case CTL_HW:
> + switch (snamep[1]) {
> + case HW_MACHINE:
> + holdlen = sizeof(TARGET_HW_MACHINE);
> + if (holdp) {
> + strlcpy(holdp, TARGET_HW_MACHINE, oldlen);
> + }
What's the semantics here when oldlen < sizeof(literal)?
I was expecting something like sysctl_old_kernel.
It would probably be good to create a number of small helper functions per type.
> +#ifdef ARM_FEATURE_VFP /* XXX FIXME XXX */
This define has been removed, so this part is dead,
> + if (env->features & ((1ULL << ARM_FEATURE_VFP)|
> + (1ULL << ARM_FEATURE_VFP3)|
> + (1ULL << ARM_FEATURE_VFP4)))
> + *(int32_t *)holdp = 1;
> + else
> + *(int32_t *)holdp = 0;
> +#else
> + *(int32_t *)holdp = 1;
and this is not right.
You're looking for
ARMCPU *cpu = env_archcpu(env);
*(abi_int *)holdp = cpu_isar_feature(aa32_vfp, cpu);
> +#if TARGET_ABI_BITS != HOST_LONG_BITS
> + case HW_PHYSMEM:
> + case HW_USERMEM:
> + case HW_REALMEM:
> + holdlen = sizeof(abi_ulong);
> + ret = 0;
> +
> + if (oldlen) {
> + int mib[2] = {snamep[0], snamep[1]};
> + unsigned long lvalue;
> + size_t len = sizeof(lvalue);
> +
> + if (sysctl(mib, 2, &lvalue, &len, NULL, 0) == -1) {
> + ret = -1;
> + } else {
> + if (((unsigned long)maxmem) < lvalue) {
Where is maxmem defined?
Why are these numbers only special-cased for TARGET_ABI_BITS != HOST_LONG_BITS?
> + static int oid_hw_pagesizes;
> +
> + if (!oid_hw_availpages) {
> + int real_oid[CTL_MAXNAME + 2];
> + size_t len = sizeof(real_oid) / sizeof(int);
> +
> + if (sysctlnametomib("hw.availpages", real_oid, &len) >= 0) {
> + oid_hw_availpages = real_oid[1];
> + }
> + }
> + if (!oid_hw_pagesizes) {
> + int real_oid[CTL_MAXNAME + 2];
> + size_t len = sizeof(real_oid) / sizeof(int);
> +
> + if (sysctlnametomib("hw.pagesizes", real_oid, &len) >= 0) {
> + oid_hw_pagesizes = real_oid[1];
> + }
> + }
Host pagesizes are not relevant to the guest.
> +
> + if (oid_hw_availpages && snamep[1] == oid_hw_availpages) {
> + long lvalue;
> + size_t len = sizeof(lvalue);
> +
> + if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) {
> + ret = -1;
> + } else {
> + if (oldlen) {
> +#if TARGET_ABI_BITS != HOST_LONG_BITS
> + abi_ulong maxpages = maxmem / (abi_ulong)getpagesize();
Again with maxmem...
> + if (((unsigned long)maxpages) < lvalue) {
> + lvalue = maxpages;
> + }
> +#endif
> + (*(abi_ulong *)holdp) = tswapal((abi_ulong)lvalue);
I would expect a 64-bit guest to rescale the result for TARGET_PAGE_SIZE != getpagesize().
> + }
> + holdlen = sizeof(abi_ulong);
> + ret = 0;
> + }
> + goto out;
> + }
> +
> + if (oid_hw_pagesizes && snamep[1] == oid_hw_pagesizes) {
> + if (oldlen) {
> + (*(abi_ulong *)holdp) = tswapal((abi_ulong)getpagesize());
Indeed, this needs TARGET_PAGE_SIZE.
> diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
> index 0ceecfb6dfa..e24a8cfcfb1 100644
> --- a/bsd-user/qemu.h
> +++ b/bsd-user/qemu.h
> @@ -252,6 +252,11 @@ bool is_error(abi_long ret);
> int host_to_target_errno(int err);
>
> /* os-sys.c */
> +abi_long do_freebsd_sysctl(CPUArchState *env, abi_ulong namep, int32_t namelen,
> + abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp, abi_ulong newlen);
> +abi_long do_freebsd_sysctlbyname(CPUArchState *env, abi_ulong namep,
> + int32_t namelen, abi_ulong oldp, abi_ulong oldlenp, abi_ulong newp,
> + abi_ulong newlen);
These belong to different patches.
r~
next prev parent reply other threads:[~2023-02-11 22:57 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 23:18 [PATCH 0/9] 2023 Q1 bsd-user upstreaming: bugfixes and sysctl Warner Losh
2023-02-10 23:18 ` [PATCH 1/9] bsd-user: Don't truncate the return value from freebsd_syscall Warner Losh
2023-02-11 19:12 ` Richard Henderson
2023-02-10 23:18 ` [PATCH 2/9] build: Don't specify -no-pie for --static user-mode programs Warner Losh
2023-02-10 23:18 ` [PATCH 3/9] bsd-user: Add sysarch syscall Warner Losh
2023-02-11 19:27 ` Richard Henderson
2023-02-10 23:18 ` [PATCH 4/9] bsd-user: Two helper routines oidfmt and sysctl_oldcvt Warner Losh
2023-02-11 22:17 ` Richard Henderson
2023-02-12 4:11 ` Warner Losh
2023-02-12 17:01 ` Warner Losh
2023-02-12 17:11 ` Warner Losh
2023-02-10 23:18 ` [PATCH 5/9] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Warner Losh
2023-02-10 23:18 ` [PATCH 6/9] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Warner Losh
2023-02-11 22:56 ` Richard Henderson [this message]
2023-02-11 23:40 ` Warner Losh
2023-02-11 23:59 ` Richard Henderson
2023-02-12 0:40 ` Warner Losh
2023-02-12 1:13 ` Richard Henderson
2023-02-10 23:18 ` [PATCH 7/9] bsd-user: do_freebsd_sysctl helper for sysctl(2) Warner Losh
2023-02-11 23:09 ` Richard Henderson
2023-02-12 17:53 ` Warner Losh
2023-02-10 23:18 ` [PATCH 8/9] bsd-user: implement sysctlbyname(2) Warner Losh
2023-02-11 23:13 ` Richard Henderson
2023-02-12 4:23 ` Kyle Evans
2023-02-12 15:07 ` Richard Henderson
2023-02-10 23:18 ` [PATCH 9/9] bsd-user: Add -strict Warner Losh
2023-02-11 23:19 ` Richard Henderson
2023-02-13 23:55 ` Warner Losh
2023-02-11 19:30 ` [PATCH 0/9] 2023 Q1 bsd-user upstreaming: bugfixes and sysctl Richard Henderson
2023-02-11 22:20 ` 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=b56a7205-0c22-16aa-f73b-267576b9950e@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=f4bug@amsat.org \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=nox@jelal.kn-bremen.de \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).