lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <BANLkTikP==HkDSG1oKcfSKAhrWOXRqGF5w@mail.gmail.com>
Date:	Mon, 16 May 2011 17:42:52 +0200
From:	Denys Vlasenko <vda.linux@...glemail.com>
To:	Andi Kleen <andi@...stfloor.org>
Cc:	linux-kernel@...r.kernel.org, libc-alpha@...rceware.org,
	Andi Kleen <ak@...ux.intel.com>
Subject: Re: [PATCH 4/5] Add a sysconf syscall

On Sat, May 14, 2011 at 1:24 AM, Andi Kleen <andi@...stfloor.org> wrote:
> +/*
> + * POSIX sysconf subset. Some programs need this in relatively fast paths
> + * and /proc is too slow for them.
> + *
> + * Note this is only a subset of the values supported by POSIX.
> + * We assume the C library handles the others.
> + */
> +SYSCALL_DEFINE1(sysconf, int, name)
> +{
> +       switch (name) {
> +       case _SC_ARG_MAX:
> +               return rlimit_or(RLIMIT_STACK, ARG_MAX*ARG_MAX_FACTOR) /
> +                               ARG_MAX_FACTOR;
> +
> +       case _SC_CHILD_MAX:
> +               return rlimit_or(RLIMIT_NPROC, max_threads);
> +
> +       case _SC_CLK_TCK:
> +               return HZ;
> +
> +       case _SC_SEM_NSEMS_MAX:
> +               return current->nsproxy->ipc_ns->sem_ctls[1];
> +
> +       case _SC_OPEN_MAX:
> +               return rlimit_or(RLIMIT_NOFILE, sysctl_nr_open);
> +
> +       case _SC_SIGQUEUE_MAX:
> +               /* or fallback based on memory? */
> +               return rlimit_or(RLIMIT_SIGPENDING, INT_MAX);
> +
> +       case _SC_UIO_MAXIOV:
> +               return UIO_MAXIOV;
> +
> +       case _SC_PAGESIZE:
> +               return PAGE_SIZE;
> +
> +       case _SC_SYMLOOP_MAX:
> +               return SYMLOOP_MAX;
> +
> +       case _SC_PHYS_PAGES:
> +               return totalram_pages;
> +
> +       case _SC_AVPHYS_PAGES:
> +               return nr_free_pages();
> +
> +       case _SC_NPROCESSORS_CONF:
> +               return num_possible_cpus();
> +
> +       case _SC_NPROCESSORS_ONLN:
> +               return num_online_cpus();
> +
> +       case _SC_NGROUPS_MAX:
> +               return NGROUPS_MAX;
> +
> +       default:
> +               return -EINVAL;
> +       }
> +}

...and libc will start making many such calls in a row in order to retrieve
a dozen of such values.

It's rather inefficient to return just one word.
Try to return more data per call.

Pass a pointer to the result struct and its length.
Future-proof API, such as using generously wide data types,
passing "version of struct" input parameter to facilitate incompatible
future changes, etc.

Pass a bit flag variable which says what data you want to have:
all-zeros means "give me only the cheap stuff which needs no calculations",
such as NGROUPS_MAX.
If SYSCONF_NPROCESSORS_ONLN bit is set, also return num_online_cpus().
If SYSCONF_AVPHYS_PAGES bit is set, return nr_free_pages().
Etc.

Maybe it makes sense to pass bits in the struct rather than in a parameter,
to not get caught by "we ran out of bits in the word!" problem later.

-- 
vda
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ