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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 9 Jan 2019 10:11:31 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     "Michael S. Tsirkin" <mst@...hat.com>
Cc:     Ingo Molnar <mingo@...nel.org>,
        Clark Williams <williams@...hat.com>,
        linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Luis Cláudio Gonçalves <lclaudio@...hat.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Wang Nan <wangnan0@...wei.com>
Subject: Re: [PATCH 16/16] tools include uapi: Sync linux/vhost.h with the
 kernel sources

Em Tue, Jan 08, 2019 at 11:10:10PM -0500, Michael S. Tsirkin escreveu:
> On Tue, Jan 08, 2019 at 04:59:10PM -0300, Arnaldo Carvalho de Melo wrote:
> > +++ b/tools/include/uapi/linux/vhost.h
> > @@ -11,94 +11,9 @@
> >   * device configuration.
> >   */

> > +#include <linux/vhost_types.h>
 
> Don't you then also need to import vhost_types.h?

If we were using this file as an include in a C source file, yes, but
we're just using it to generate a string table using regular
expressions:

[acme@...co perf]$ tools/perf/trace/beauty/vhost_virtio_ioctl.sh
static const char *vhost_virtio_ioctl_cmds[] = {
	[0x00] = "SET_FEATURES",
	[0x01] = "SET_OWNER",
	[0x02] = "RESET_OWNER",
	[0x03] = "SET_MEM_TABLE",
	[0x04] = "SET_LOG_BASE",
	[0x07] = "SET_LOG_FD",
	[0x10] = "SET_VRING_NUM",
	[0x11] = "SET_VRING_ADDR",
	[0x12] = "SET_VRING_BASE",
	[0x13] = "SET_VRING_ENDIAN",
	[0x14] = "GET_VRING_ENDIAN",
	[0x20] = "SET_VRING_KICK",
	[0x21] = "SET_VRING_CALL",
	[0x22] = "SET_VRING_ERR",
	[0x23] = "SET_VRING_BUSYLOOP_TIMEOUT",
	[0x24] = "GET_VRING_BUSYLOOP_TIMEOUT",
	[0x25] = "SET_BACKEND_FEATURES",
	[0x30] = "NET_SET_BACKEND",
	[0x40] = "SCSI_SET_ENDPOINT",
	[0x41] = "SCSI_CLEAR_ENDPOINT",
	[0x42] = "SCSI_GET_ABI_VERSION",
	[0x43] = "SCSI_SET_EVENTS_MISSED",
	[0x44] = "SCSI_GET_EVENTS_MISSED",
	[0x60] = "VSOCK_SET_GUEST_CID",
	[0x61] = "VSOCK_SET_RUNNING",
};
static const char *vhost_virtio_ioctl_read_cmds[] = {
	[0x00] = "GET_FEATURES",
	[0x12] = "GET_VRING_BASE",
	[0x26] = "GET_BACKEND_FEATURES",
};
[acme@...co perf]$

[acme@...co perf]$ cat tools/perf/trace/beauty/vhost_virtio_ioctl.sh 
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1

[ $# -eq 1 ] && header_dir=$1 || header_dir=tools/include/uapi/linux/

printf "static const char *vhost_virtio_ioctl_cmds[] = {\n"
regex='^#[[:space:]]*define[[:space:]]+VHOST_(\w+)[[:space:]]+_IOW?\([[:space:]]*VHOST_VIRTIO[[:space:]]*,[[:space:]]*(0x[[:xdigit:]]+).*'
egrep $regex ${header_dir}/vhost.h | \
	sed -r "s/$regex/\2 \1/g"	| \
	sort | xargs printf "\t[%s] = \"%s\",\n"
printf "};\n"

printf "static const char *vhost_virtio_ioctl_read_cmds[] = {\n"
regex='^#[[:space:]]*define[[:space:]]+VHOST_(\w+)[[:space:]]+_IOW?R\([[:space:]]*VHOST_VIRTIO[[:space:]]*,[[:space:]]*(0x[[:xdigit:]]+).*'
egrep $regex ${header_dir}/vhost.h | \
	sed -r "s/$regex/\2 \1/g"	| \
	sort | xargs printf "\t[%s] = \"%s\",\n"
printf "};\n"
[acme@...co perf]$

This ends up being used in tools/perf/trace/beauty/ioctl.c, after that
trace/beauty/generated/ioctl/vhost_virtio_ioctl_array.c file (with the
vhost_virtio_ioctl_read_cmds and vhost_virtio_ioctl_cmds arrays) gets
generated by the tools/perf/Makefile.perf build process:

static size_t ioctl__scnprintf_vhost_virtio_cmd(int nr, int dir, char *bf, size_t size)
{
#include "trace/beauty/generated/ioctl/vhost_virtio_ioctl_array.c"
        static DEFINE_STRARRAY(vhost_virtio_ioctl_cmds, "");
        static DEFINE_STRARRAY(vhost_virtio_ioctl_read_cmds, "");
        struct strarray *s = (dir & _IOC_READ) ? &strarray__vhost_virtio_ioctl_read_cmds : &strarray__vhost_virtio_ioctl_cmds;

        if (nr < s->nr_entries && s->entries[nr] != NULL)
                return scnprintf(bf, size, "VHOST_%s", s->entries[nr]);

        return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAF, nr, dir);
}

So, if at some point a tool needs to really #include that file, yeah,
then we will need to import vhost_types.h too.

- Arnaldo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ