Skip to contentSkip to conversation

misc trinity patches

PATCH In review Tommi Rantala 3 participants 13 messages Jun 30, 2013 – Jul 1, 2013

lore
Share & tools
lore
#0 lore raw

cover misc trinity patches

Hello, some fairly small trinity patches, please take a look.

Thanks,
Tommi

Tommi Rantala (8):
Use TRINITY_PF_MAX instead of PF_MAX in syscalls/socket.c Fix open() result check in check_tainted()
Avoid needless get_filename() calls in generate_pathname() Fix double rand() in generate_pathname()
move perf_event.h to include/
msgrcv() and msgsnd() IPC_NOWAIT msgflg ioctls/drm: add deprecated nouveau ioctls ioctls/vhost: VHOST_SCSI_* ioctls

 files.c                            |   5 +-
 {syscalls => include}/perf_event.h |   0
 ioctls/drm.c                       | 102 +++++++++++++++++++++++++++++++++++++
 ioctls/vhost.c                     |  15 ++++++
 main.c                             |   2 +-
 syscalls/msgrcv.c                  |   4 +-
 syscalls/msgsnd.c                  |   4 +-
 syscalls/socket.c                  |   2 +-
 8 files changed, 125 insertions(+), 9 deletions(-)
 rename {syscalls => include}/perf_event.h (100%)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/8 Use TRINITY_PF_MAX instead of PF_MAX in syscalls/socket.c

---
 syscalls/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
syscalls/socket.c +1 -1
index 26e3a6e..3601c04 100644
@@ -47,7 +47,7 @@ void sanitise_socket(int childno)
 	if (do_specific_proto == TRUE)
 		family = specific_proto;
 	else
-		family = rand() % PF_MAX;
+		family = rand() % TRINITY_PF_MAX;
 
 	type = rand() % TYPE_MAX;
 	protocol = rand() % PROTO_MAX;
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/8 Fix open() result check in check_tainted()

In reply to Tommi Rantala
---
 main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
main.c +1 -1
index 648e56d..0e58433 100644
@@ -57,7 +57,7 @@ int check_tainted(void)
 	char buffer[4];
 
 	fd = open("/proc/sys/kernel/tainted", O_RDONLY);
-	if (!fd)
+	if (fd < 0)
 		return -1;
 	ret = read(fd, buffer, 3);
 	close(fd);
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/8 Avoid needless get_filename() calls in generate_pathname()

In reply to Tommi Rantala
---
 files.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
files.c +2 -2
index 89a11d4..3319eef 100644
@@ -363,13 +363,13 @@ char * generate_pathname(void)
 	case 0 ... 90:
 		/* 90% chance of returning an unmangled filename */
 		if ((rand() % 100) > 10)
-			return get_filename();
+			return pathname;
 
 	case 91 ... 99:
 		/* Create a bogus filename. */
 		newpath = malloc(page_size);	// FIXME: We leak this.
 		if (newpath == NULL)
-			return get_filename();	// give up.
+			return pathname;	// give up.
 
 		generate_random_page(newpath);
 
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/8 Fix double rand() in generate_pathname()

In reply to Tommi Rantala

We take 90% chance two times in the "unmangled" path in generate_pathname(); looks accidental to me.

---
 files.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
files.c +1 -2
index 3319eef..ef44ee2 100644
@@ -362,8 +362,7 @@ char * generate_pathname(void)
 
 	case 0 ... 90:
 		/* 90% chance of returning an unmangled filename */
-		if ((rand() % 100) > 10)
-			return pathname;
+		return pathname;
 
 	case 91 ... 99:
 		/* Create a bogus filename. */
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/8 move perf_event.h to include/

In reply to Tommi Rantala

The perf header will be used also in a few other places beyond syscalls, so move it to the include/ directory so that it is easily available.

---
 {syscalls => include}/perf_event.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {syscalls => include}/perf_event.h (100%)
include/perf_event.h renamed from syscalls/perf_event.h +0 -0
similarity index 100%
rename from syscalls/perf_event.h
rename to include/perf_event.h
Signature · 1 line
1.8.1.4
#6 lore raw

Re: [PATCH 5/8] move perf_event.h to include/

include/perf_event.h

Quoted 11 lines · Tommi Rantala

The perf header will be used also in a few other places beyond syscalls, so move it to the include/ directory so that it is easily available.

---
 {syscalls => include}/perf_event.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {syscalls => include}/perf_event.h (100%)
include/perf_event.h renamed from syscalls/perf_event.h +0 -0
similarity index 100%
rename from syscalls/perf_event.h
rename to include/perf_event.h

can you elaborate on this one ?

Dave

#7 lore raw

Re: [PATCH 5/8] move perf_event.h to include/

2013/7/1 Dave Jones <[email protected]>:

Quoted 8 lines · Tommi Rantala
Quoted 7 lines

The perf header will be used also in a few other places beyond syscalls, so move it to the include/ directory so that it is easily available.

---
 {syscalls => include}/perf_event.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {syscalls => include}/perf_event.h (100%)
Quoted 6 lines

include/perf_event.h

Quoted 4 lines
include/perf_event.h renamed from syscalls/perf_event.h +0 -0
similarity index 100%
rename from syscalls/perf_event.h
rename to include/perf_event.h

can you elaborate on this one ?

I'm working on some patches (that I hope to finish sometime soon) to open more types of file descriptors at Trinity startup, and this header will be useful for that purpose. (Might also be possible to use something from syscalls/perf_event_open.c, and perhaps avoid requiring the header, but did not look into that.)

I also want the ioctl definitions from the header (in code living in ioctls/).

Tommi

#8 lore raw

Re: [PATCH 5/8] move perf_event.h to include/

Quoted 5 lines · Tommi Rantala

2013/7/1 Dave Jones <[email protected]>:

Quoted 1 line

can you elaborate on this one ?

I'm working on some patches (that I hope to finish sometime soon) to open more types of file descriptors at Trinity startup

Ah, excellent. I was thinking of that after seeing your hack a while back for epoll descriptors. Looking forward to it. (And glad I don't have to do it now ;)

Quoted 5 lines

and this header will be useful for that purpose. (Might also be possible to use something from syscalls/perf_event_open.c, and perhaps avoid requiring the header, but did not look into that.)

I also want the ioctl definitions from the header (in code living in ioctls/).

Sounds good, I'll merge it and the other patches in a while.

Dave

#9 lore raw

Re: [PATCH 5/8] move perf_event.h to include/

Quoted 4 lines · Dave Jones
Quoted 1 line · Tommi Rantala

I also want the ioctl definitions from the header (in code living in ioctls/).

Sounds good, I'll merge it and the other patches in a while.

I looked into adding the perf_event ioctls myself, but got lost a bit in trinity's ioctl code. It seems to expect you are opening a file in /dev to operate on, and perf_event ioctls don't work that way. I could have been misunderstanding what it is doing though.

In any case, feel free to steal code from my perf_fuzzer which exercises all of the perf_event ioctls, although I need to add in code to explicitly fuzz the PERF_IOC_FLAG_GROUP ioctl paramater which I somehow didn't learn about until a few days ago.

Vince

#10 lore raw

PATCH 6/8 msgrcv() and msgsnd() IPC_NOWAIT msgflg

In reply to Tommi Rantala
---
 syscalls/msgrcv.c | 4 ++--
 syscalls/msgsnd.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
syscalls/msgrcv.c +2 -2
index b730ba6..2200472 100644
@@ -17,7 +17,7 @@ struct syscall syscall_msgrcv = {
 	.arg5name = "msgflg",
 	.arg5type = ARG_LIST,
 	.arg5list = {
-		.num = 3,
-		.values = { MSG_NOERROR, MSG_EXCEPT, MSG_COPY },
+		.num = 4,
+		.values = { MSG_NOERROR, MSG_EXCEPT, MSG_COPY, IPC_NOWAIT },
 	},
 };
syscalls/msgsnd.c +2 -2
index 132336b..3e3a91d 100644
@@ -16,7 +16,7 @@ struct syscall syscall_msgsnd = {
 	.arg4name = "msgflg",
 	.arg4type = ARG_LIST,
 	.arg4list = {
-		.num = 3,
-		.values = { MSG_NOERROR, MSG_EXCEPT, MSG_COPY },
+		.num = 4,
+		.values = { MSG_NOERROR, MSG_EXCEPT, MSG_COPY, IPC_NOWAIT },
 	},
 };
Signature · 1 line
1.8.1.4
#11 lore raw

PATCH 7/8 ioctls/drm: add deprecated nouveau ioctls

In reply to Tommi Rantala

nouveau has some deprecated ioctls that the kernel implements, but the ioctl definitions are no longer available in the kernel headers.

---
 ioctls/drm.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
ioctls/drm.c +102 -0
index 736c264..952a356 100644
@@ -45,6 +45,101 @@
 #define DRM_IOCTL_SIS_FLIP_FINAL	DRM_IO(  0x50)
 */
 
+/* deprecated nouveau ioctls */
+/*
+ * Copyright 2005 Stephane Marchesin.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef DRM_IOCTL_NOUVEAU_GETPARAM
+struct drm_nouveau_getparam {
+	uint64_t param;
+	uint64_t value;
+};
+#define DRM_IOCTL_NOUVEAU_GETPARAM           DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GETPARAM, struct drm_nouveau_getparam)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_SETPARAM
+struct drm_nouveau_setparam {
+	uint64_t param;
+	uint64_t value;
+};
+#define DRM_IOCTL_NOUVEAU_SETPARAM           DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_SETPARAM, struct drm_nouveau_setparam)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_CHANNEL_ALLOC
+struct drm_nouveau_channel_alloc {
+	uint32_t     fb_ctxdma_handle;
+	uint32_t     tt_ctxdma_handle;
+
+	int          channel;
+	uint32_t     pushbuf_domains;
+
+	/* Notifier memory */
+	uint32_t     notifier_handle;
+
+	/* DRM-enforced subchannel assignments */
+	struct {
+		uint32_t handle;
+		uint32_t grclass;
+	} subchan[8];
+	uint32_t nr_subchan;
+};
+#define DRM_IOCTL_NOUVEAU_CHANNEL_ALLOC      DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_CHANNEL_ALLOC, struct drm_nouveau_channel_alloc)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_CHANNEL_FREE
+struct drm_nouveau_channel_free {
+	int channel;
+};
+#define DRM_IOCTL_NOUVEAU_CHANNEL_FREE       DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_CHANNEL_FREE, struct drm_nouveau_channel_free)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_GROBJ_ALLOC
+struct drm_nouveau_grobj_alloc {
+	int      channel;
+	uint32_t handle;
+	int      class;
+};
+#define DRM_IOCTL_NOUVEAU_GROBJ_ALLOC        DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GROBJ_ALLOC, struct drm_nouveau_grobj_alloc)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_NOTIFIEROBJ_ALLOC
+struct drm_nouveau_notifierobj_alloc {
+	uint32_t channel;
+	uint32_t handle;
+	uint32_t size;
+	uint32_t offset;
+};
+#define DRM_IOCTL_NOUVEAU_NOTIFIEROBJ_ALLOC  DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_NOTIFIEROBJ_ALLOC, struct drm_nouveau_notifierobj_alloc)
+#endif
+
+#ifndef DRM_IOCTL_NOUVEAU_GPUOBJ_FREE
+struct drm_nouveau_gpuobj_free {
+	int      channel;
+	uint32_t handle;
+};
+#define DRM_IOCTL_NOUVEAU_GPUOBJ_FREE        DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GPUOBJ_FREE, struct drm_nouveau_gpuobj_free)
+#endif
+
 typedef struct {
 	int context;
 	unsigned long offset;
@@ -294,6 +389,13 @@ static const struct ioctl drm_ioctls[] = {
 	IOCTL(DRM_IOCTL_MGA_DMA_BOOTSTRAP),
 
 	/* nouveau_drm.h */
+	IOCTL(DRM_IOCTL_NOUVEAU_GETPARAM),
+	IOCTL(DRM_IOCTL_NOUVEAU_SETPARAM),
+	IOCTL(DRM_IOCTL_NOUVEAU_CHANNEL_ALLOC),
+	IOCTL(DRM_IOCTL_NOUVEAU_CHANNEL_FREE),
+	IOCTL(DRM_IOCTL_NOUVEAU_GROBJ_ALLOC),
+	IOCTL(DRM_IOCTL_NOUVEAU_NOTIFIEROBJ_ALLOC),
+	IOCTL(DRM_IOCTL_NOUVEAU_GPUOBJ_FREE),
 #ifdef DRM_IOCTL_NOUVEAU_GEM_NEW
 	IOCTL(DRM_IOCTL_NOUVEAU_GEM_NEW),
 #endif
Signature · 1 line
1.8.1.4
#12 lore raw

PATCH 8/8 ioctls/vhost: VHOST_SCSI_* ioctls

In reply to Tommi Rantala
---
 ioctls/vhost.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
ioctls/vhost.c +15 -0
index 58a8b09..3842678 100644
@@ -22,6 +22,21 @@ static const struct ioctl vhost_ioctls[] = {
 	IOCTL(VHOST_SET_VRING_CALL),
 	IOCTL(VHOST_SET_VRING_ERR),
 	IOCTL(VHOST_NET_SET_BACKEND),
+#ifdef VHOST_SCSI_SET_ENDPOINT
+	IOCTL(VHOST_SCSI_SET_ENDPOINT),
+#endif
+#ifdef VHOST_SCSI_CLEAR_ENDPOINT
+	IOCTL(VHOST_SCSI_CLEAR_ENDPOINT),
+#endif
+#ifdef VHOST_SCSI_GET_ABI_VERSION
+	IOCTL(VHOST_SCSI_GET_ABI_VERSION),
+#endif
+#ifdef VHOST_SCSI_SET_EVENTS_MISSED
+	IOCTL(VHOST_SCSI_SET_EVENTS_MISSED),
+#endif
+#ifdef VHOST_SCSI_GET_EVENTS_MISSED
+	IOCTL(VHOST_SCSI_GET_EVENTS_MISSED),
+#endif
 };
 
 static const char *const vhost_devs[] = {
Signature · 1 line
1.8.1.4