Skip to contentSkip to conversation

Modular qemu?

Qemu-devel Joop Boonen 13 participants 23 messages Dec 5, 2008 – Dec 17, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

Hello All,

I'm wondering if a modular qemu would be an option (loadable modules)? Currently a lot different patched versions of qemu are around. qemu as provided from the qemu project
qemu for openmoko wiki.openmoko.org
qemu for coreboot.org
and probably others.

If it would be possible t load modules like the (linux)kernel it would be possible to use one qemu version for all the projects.
I don't know if this is possible?

Regards,

Joop.

#1 lore raw
Quoted 6 lines · Joop Boonen

I'm wondering if a modular qemu would be an option (loadable modules)? Currently a lot different patched versions of qemu are around. qemu as provided from the qemu project
qemu for openmoko wiki.openmoko.org
qemu for coreboot.org

The coreboot project tries to get their patches merged. Hopefully that will reduce the amounts of coreboot/qemu patches to zero.

Quoted 2 lines

and probably others.

Regards,
Carl-Daniel

Signature · 1 line
http://www.hailfinger.org/
#2 lore raw
In reply to Joop Boonen
Quoted 9 lines · Joop Boonen

Hello All,

I'm wondering if a modular qemu would be an option (loadable modules)? Currently a lot different patched versions of qemu are around. qemu as provided from the qemu project
qemu for openmoko wiki.openmoko.org
qemu for coreboot.org
and probably others.

Quoted 4 lines

If it would be possible t load modules like the (linux)kernel it would be possible to use one qemu version for all the projects.
I don't know if this is possible?

This has been discussed before and I believe the overall consensus was that plugins are not desirable.

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU. This is not just a matter of getting patches accepted, but also getting the appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Regards,

Anthony Liguori

Quoted 7 lines

Regards,

Joop.

#3 lore raw
Quoted 10 lines · Anthony Liguori

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU.
This is not just a matter of getting patches accepted, but also getting the
appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Sorry to say, but many forks are linux-user ones and qemu has no maintainer for that. This might become even worse in the future with, for instance, Nokia using qemu linux-user for the SDK of their upcoming OMAP3 based tablet.

Laurent

#4 lore raw
Quoted 8 lines · Laurent Desnogues
Quoted 7 lines · Anthony Liguori

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU.
This is not just a matter of getting patches accepted, but also getting the
appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

Quoted 8 lines
Quoted 3 lines

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Sorry to say, but many forks are linux-user ones and qemu has no maintainer for that. This might become even worse in the future with, for instance, Nokia using qemu linux-user for the SDK of their upcoming OMAP3 based tablet.

We have no maintainer here, and there's a lot of people maintaining the forks all over. What's stoping those people from becoming maintainers of the linux-user architectures
in upstream qemu?

I believe this is part of what anthony is saying. The situation about how do we welcome
new people improved by a large leap.

#5 lore raw
Quoted 5 lines · Glauber Costa

We have no maintainer here, and there's a lot of people maintaining the forks all over. What's stoping those people from becoming maintainers of the linux-user architectures
in upstream qemu?

git can be really helpful here. As I said, anyone who wants to start maintaining a git tree for a particular subsystem they're interested in, I'm more than happy to do git pulls and then push to svn via git-svn. Of course, all commits should be posted as patches and they should be well separated and bisectable, etc. All discussions should happen on qemu-devel too.

I know part of the problem for maintainership is chicken-and-the-egg. If you don't have commit access, it's hard to prove that you would be a good maintainer. git really helps this though because anyone can setup a git tree.

Regards,

Anthony Liguori

Quoted 4 lines

I believe this is part of what anthony is saying. The situation about how do we welcome
new people improved by a large leap.

#6 lore raw
In reply to Laurent Desnogues
Quoted 14 lines · Laurent Desnogues
Quoted 11 lines · Anthony Liguori

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU.
This is not just a matter of getting patches accepted, but also getting the
appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Quoted 5 lines

Sorry to say, but many forks are linux-user ones and qemu has no maintainer for that. This might become even worse in the future with, for instance, Nokia using qemu linux-user for the SDK of their upcoming OMAP3 based tablet.

Yeah, I understand that the linux-user stuff is currently unmaintained. Just appointing someone is really the right approach either. With the kernel.org git mirror, it would be relatively easy for someone to maintain a linux-user tree.

If someone were to do that, they could post pull requests. I think it's then natural to promote the maintainer of such a tree to an official maintainer.

It just requires someone willing to put in the time. git is not the only option, just maintaining a patch queue for linux-user would be a good start too.

Regards,

Anthony Liguori

Quoted 4 lines

Laurent

#7 lore raw
In reply to Anthony Liguori
Quoted 1 line · Anthony Liguori

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl support.

I'm thinking of something similar to linux kernel modules: no backward compatible ABI, simply load-on-demand functionality that can be packaged separately to reduce dependencies. With kvm integrated, we could even make the cpu emulator an optional loadable module.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#8 lore raw
Quoted 9 lines · Avi Kivity
Quoted 1 line · Anthony Liguori

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl support.

Quoted 4 lines

I'm thinking of something similar to linux kernel modules: no backward compatible ABI, simply load-on-demand functionality that can be packaged separately to reduce dependencies. With kvm integrated, we could even make the cpu emulator an optional loadable module.

What problem would this solve?

Thiemo

#9 lore raw
Quoted 10 lines · Thiemo Seufer
Quoted 6 lines

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl
support.

I'm thinking of something similar to linux kernel modules: no backward compatible ABI, simply load-on-demand functionality that can be packaged separately to reduce dependencies. With kvm integrated, we could even make the cpu emulator an optional loadable module.

What problem would this solve?

You build qemu once, but with separate sub-packages:

qemu
qemu-sdl
qemu-vnc
qemu-tcg
qemu-kvm

On a desktop deployment, you install qemu, qemu-kvm, qemu-tcg, and qemu-sdl (which pulls a bunch of dependencies). On a server deployment, you install qemu, qemu-vnc, and qemu-kvm (which avoids dependencies and the tcg code which is not useful on a server). This allows a distribution to only maintain and support one qemu binary for different deployment scenarios.

We might even make the various targets loadable modules, so you have a single binary which supports a bunch of targets. This is more difficult due to the large numbers of #defines, but is doable.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#10 lore raw
Quoted 8 lines · Avi Kivity

You build qemu once, but with separate sub-packages:

qemu
qemu-sdl
qemu-vnc
qemu-tcg
qemu-kvm

Fair enough, but we're getting the cart before the horse. We need to have clean internal separations between these components before a shared library interface really matters. Note, this is really just dividing QEMU into shared libraries, it's not really a plugin mechanism.

I'm less interested in the shared library bits (although I understand it's usefulness from a distro perspective) and more interested in being able to build out a lot of these things.

Regards,

Anthony Liguori

#11 lore raw
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Avi Kivity

You build qemu once, but with separate sub-packages:

qemu
qemu-sdl
qemu-vnc
qemu-tcg
qemu-kvm

Fair enough, but we're getting the cart before the horse. We need to have clean internal separations between these components before a shared library interface really matters. Note, this is really just dividing QEMU into shared libraries, it's not really a plugin mechanism.

Right, I even introduced it as such. I don't think the separation will be difficult (not does it need to be perfect, given that we're not committing to an ABI).

Quoted 2 lines

I'm less interested in the shared library bits (although I understand it's usefulness from a distro perspective) and more interested in being able to build out a lot of these things.

Parse failure. What does building out mean? ./configure --disable-blah?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#12 lore raw
Quoted 6 lines · Avi Kivity
Quoted 2 lines · Anthony Liguori

I'm less interested in the shared library bits (although I understand it's usefulness from a distro perspective) and more interested in being able to build out a lot of these things.

Parse failure. What does building out mean? ./configure --disable-blah?

In the least, yes. I'd like a kernel style .config though so that each hardware device can be conditionally built or not built. Adding a ='m' option is pretty obvious addition to this.

Regards,

Anthony Liguori

#13 lore raw
In reply to Avi Kivity
Quoted 9 lines · Avi Kivity
Quoted 1 line · Anthony Liguori

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl support.

Quoted 4 lines

I'm thinking of something similar to linux kernel modules: no backward compatible ABI, simply load-on-demand functionality that can be packaged separately to reduce dependencies. With kvm integrated, we could even make the cpu emulator an optional loadable module.

At work, we are currently using this model to separate a very special machine emulation from the latest and greatest qemu (or kvm-userspace) core. We only patch the core with support to load "machine libraries" that provide additional QEMUMachine definitions. The idea is definitely _not_ to distribute a binary-only machine library with the product one day, but to ease the build process. We also face the unavoidable API breakages from time to time, and the whole things is not really clean due to callbacks into the core all over the place, but otherwise it does its job.

As it is not clean and we are still busy with more important stuff, I haven't posted any RFC yet. The biggest issue, besides finding a consensus if such pluging concepts are desired at all, is working out clean (but not necessarily stable) APIs for calling from the plugins into the core. Right now we simply export everything.

Jan

#14 lore raw
In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 1 line · Anthony Liguori

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with
opengl support.

Practically speaking, how helpful is this? You still need to have the libraries present at build time and it's arguable about how much text savings you get because there's some cruft added from loading the libraries themselves.

If we had cleaner, self-registering interfaces, doing the dlopen() is real easy. I definitely think we should move to that model. The dlopen() part is somewhat orthogonal.

Regards,

Anthony Liguori

Quoted 1 line

I'm thinking of something similar to linux kernel modules: no backward compatible ABI, simply load-on-demand functionality that can be packaged separately to reduce dependencies. With kvm integrated, we could even make the cpu emulator an optional loadable module.

#15 lore raw
Quoted 5 lines · Anthony Liguori
Quoted 3 lines
Quoted 1 line

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl support.

Practically speaking, how helpful is this? You still need to have the libraries present at build time

Build time is not an issue; distros usually build with all possible options enabled.

Quoted 1 line

and it's arguable about how much text savings you get because there's some cruft added from loading the libraries themselves.

The goal is not to save text (though that's an added benefit), but to drop an infinite chain of dependencies. Right now, to have both desktop and server deployments, there are two options:

- build two different binaries with different build-time options. Distro maintainers will hug and kiss you whenever you mention this option.
- install SDL, X11 client libraries, and their dependencies on the server. In the future, this gets worse, with opengl libraries, DRI drivers, and maybe even gtk2 and qt for a sane UI. Sysadmins will propose on the spot if you suggest this to them.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#16 lore raw
Quoted 22 lines · Avi Kivity
Quoted 10 lines · Anthony Liguori
Quoted 7 lines
Quoted 2 lines

Plugins are not the solution though.

What about non-plugin dlopen()? Right now building qemu (with all options enabled) requires a large amount of libraries, hence a lot of dependencies. For example, a server setup that will only be used with -vnc needs to have SDL installed. This will only get worse with opengl support.

Practically speaking, how helpful is this? You still need to have the libraries present at build time

Build time is not an issue; distros usually build with all possible options enabled.

Quoted 2 lines

and it's arguable about how much text savings you get because there's some cruft added from loading the libraries themselves.

The goal is not to save text (though that's an added benefit), but to drop an infinite chain of dependencies. Right now, to have both desktop and server deployments, there are two options:

Quoted 5 lines

- build two different binaries with different build-time options. Distro maintainers will hug and kiss you whenever you mention this option.
- install SDL, X11 client libraries, and their dependencies on the server. In the future, this gets worse, with opengl libraries, DRI drivers, and
maybe even gtk2 and qt for a sane UI.

Interesting! Are you aware of any project currently doing on DRI drivers?? Anh OpenGL drivers?

I suppose that you want to say "DRI device model" and "OpenGL device model" for QEMU?

Thanks,
Jun

#17 lore raw
Quoted 3 lines · Jun Koi

Interesting! Are you aware of any project currently doing on DRI drivers?? Anh OpenGL drivers?

I posted a patch to implement OpenGL rendering few months ago but was not applied.
If I have the time I'll try to clean it up and repost it in the future.

#18 lore raw
In reply to Jun Koi
Quoted 11 lines · Jun Koi
Quoted 4 lines

- install SDL, X11 client libraries, and their dependencies on the server. In the future, this gets worse, with opengl libraries, DRI drivers, and
maybe even gtk2 and qt for a sane UI.

Interesting! Are you aware of any project currently doing on DRI drivers?? Anh OpenGL drivers?

I suppose that you want to say "DRI device model" and "OpenGL device model" for QEMU?

No, I'm talking about using opengl to accelerate rendering of the normal 2D emulated cards. The Xen people have posted patches to do this.

Signature · 1 line
error compiling committee.c: too many arguments to function
#19 lore raw
In reply to Anthony Liguori
Quoted 18 lines · Anthony Liguori
Quoted 9 lines · Joop Boonen

Hello All,

I'm wondering if a modular qemu would be an option (loadable modules)? Currently a lot different patched versions of qemu are around. qemu as provided from the qemu project
qemu for openmoko wiki.openmoko.org
qemu for coreboot.org
and probably others.

Quoted 4 lines

If it would be possible t load modules like the (linux)kernel it would be possible to use one qemu version for all the projects.
I don't know if this is possible?

This has been discussed before and I believe the overall consensus was that plugins are not desirable.

Quoted 8 lines

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU. This is not just a matter of getting patches accepted, but also getting the appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

I hope this situation is improving. If people have feedback in how things

In general I think the situation has improved alot. Personally I think the work that in particular Anthony (others too) is doing with reviewing and applying patches is just fantastic.

Quoted 2 lines

could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Personnaly I would welcome some kind of plugin interface for some parts of QEMU but only if someone comes up wiht a an interface that does not hurt performace. I'd definitely have a use to plugin callbacks for every memory accesse in system-mode and I've noticed a reocurring request for hooks to trap syscalls while user-mode emulating.

Best regards
Edgar

#20 lore raw
Quoted 5 lines · Edgar E. Iglesias
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Joop Boonen

Hello All,

Quoted 10 lines

Personnaly I would welcome some kind of plugin interface for some parts of QEMU but only if someone comes up wiht a an interface that does not hurt performace. I'd definitely have a use to plugin callbacks for every memory accesse in system-mode and I've noticed a reocurring request for hooks to trap syscalls while user-mode emulating.

Best regards
Edgar

Hello everyone,

Edgar,

that's exactly what I implemented the past week. I needed to simulate a proprietary driver from a syscall point of view.

I added hooks for syscalls with basic priorities.

Here a few patch (it's a work in progress).

I'm also interrested in splitting the big sys.call.c (~6k lines) using theses hooks.

Regards,

Signature · 3 lines
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris
Quoted 1 line

From eac6fc3bc1adbfeb95da16e82df4851a9ef6c468 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Tue, 2 Dec 2008 07:40:03 +0100
Subject: [PATCH] Added syscall hooks

---
 linux-user/syscall_hook.c |  178 +++++++++++++++++++++++++++++++++++++++++++++
 linux-user/syscall_hook.h |   43 +++++++++++
 2 files changed, 221 insertions(+), 0 deletions(-)
 create mode 100644 linux-user/syscall_hook.c
 create mode 100644 linux-user/syscall_hook.h
linux-user/syscall_hook.c new file +178 -0
new file mode 100644
index 0000000..06fbff3
@@ -0,0 +1,178 @@
+/*
+ *  Syscall hooks
+ *
+ *  Copyright (c) 2008 Lionel Landwerlin
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include <stdlib.h>
+
+#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
+
+typedef struct _qemu_syscall_hook_t {
+    struct _qemu_syscall_hook_t prev;
+    struct _qemu_syscall_hook_t next;
+
+    unsigned int priority;
+
+    syscall_hook_cb_t callback;
+} qemu_syscall_hook_t;
+
+static qemu_syscall_hook_t *syscall_hooks[MAX_SYSCALL];
+
+static qemu_syscall_hook_t *
+_hook_new (syscall_hook_cb_t callback, unsigned int prio)
+{
+    qemu_syscall_hook_t *hook =
+        (qemu_syscall_hook_t *) calloc (1, sizeof (qemu_syscall_hook_t));
+
+    if (hook) {
+        hook->callback = callback;
+        hook->prio = prio;
+    }
+
+    return hook;
+}
+
+static void
+_hook_free (qemu_syscall_hook_t *hook)
+{
+    if (hook)
+        free (hook);
+}
+
+static void
+_hook_insert_after (int num,
+                    qemu_syscall_hook_t *old,
+                    qemu_syscall_hook_t *new)
+{
+    new->prev = old;
+    new->next = old->next;
+    if (old->next)
+        old->next->prev = new;
+}
+
+static void
+_hook_insert_before (int num,
+                     qemu_syscall_hook_t *old,
+                     qemu_syscall_hook_t *new)
+{
+    new->prev = old->prev;
+    new->next = old;
+    if (old->prev)
+        old->prev->next = new;
+}
+
+static void
+_hook_remove (int num,
+              qemu_syscall_hook_t *hook)
+{
+    if (list->prev)
+        list->prev->next = list->next;
+    if (list->next)
+        list->next->prev = list->prev;
+    if (list == syscall_hooks[num])
+        syscall_hooks[num] = list->prev ? list->prev : list->next;
+}
+
+void
+qemu_syscall_hook_init (void)
+{
+    int i;
+
+    for (i = 0 ; i < ARRAY_SIZE (syscall_hooks) ; i++)
+        syscall_hooks[i] = NULL;
+}
+
+int
+qemu_syscall_hook_register (int num, syscall_hook_cb_t callback, unsigned int prio)
+{
+    qemu_syscall_hook_t *new;
+
+    if (num >= ARRAY_SIZE (syscall_hooks))
+        return 0;
+
+    new = _hook_new (callback, prio);
+
+    if (syscall_hooks[num] == NULL) {
+        syscall_hooks[num] = new;
+    } else {
+        qemu_syscall_hook_t *plist, *nlist;
+
+        plist = NULL;
+        nlist = syscall_hooks[num];
+
+        while (nlist &&
+               nlist->prio < prio) {
+            plist = nlist;
+            nlist = nlist->next;
+        }
+
+        if (nlist) {
+            _insert_before (nlist, new);
+            if (nlist == syscall_hooks[num])
+                syscall_hooks[num] = new;
+        } else {
+            _insert_after (plist, new);
+        }
+    }
+
+    return 1;
+}
+
+void
+qemu_syscall_hook_unregister (int num, syscall_hook_cb_t callback)
+{
+    qemu_syscall_hook_t *list;
+
+    if (num >= ARRAY_SIZE (syscall_hooks))
+        return;
+
+    list = syscall_hooks[num];
+
+    while (list &&
+           (list->callback != callback))
+        list = list->next;
+
+    if (list) {
+        _hook_remove (num, list);
+        _hook_free (list);
+    }
+}
+
+int
+qemu_syscall_traverse (void *cpu_env, int num,
+                       abi_long arg1, abi_long arg2,
+                       abi_long arg3, abi_long arg4,
+                       abi_long arg5, abi_long arg6)
+{
+    qemu_syscall_hook_t *list;
+
+    if (num >= ARRAY_SIZE (syscall_hooks))
+        return 0;
+
+    list = syscall_hooks[num];
+
+    while (list) {
+        if (list->callback (cpu_env, num,
+                            arg1, arg2, arg3,
+                            arg4, arg5, arg5))
+            break;
+
+        list = list->next;
+    }
+
+    return (list == NULL);
+}
linux-user/syscall_hook.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
1.5.6.5
Quoted 1 line

From ec887d9e029910f089eff2f6352ae19d8af508f5 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Tue, 2 Dec 2008 10:19:46 +0100
Subject: [PATCH] Rename syscall_hook functions

---
 linux-user/syscall_hook.c |   46 ++++++++++++++++++++++----------------------
 linux-user/syscall_hook.h |   16 +++++++-------
 2 files changed, 31 insertions(+), 31 deletions(-)
linux-user/syscall_hook.c +23 -23

120 lines not on this page · raw message

linux-user/syscall_hook.h +8 -8
index ad6a69b..72c0306 100644
@@ -29,15 +29,15 @@ typedef int (*syscall_hook_cb_t) (void *cpu_env, int num,
                                   abi_long arg3, abi_long arg4,
                                   abi_long arg5, abi_long arg6);
 
-void qemu_syscall_hook_init (void);
+void syscall_hook_init (void);
 
-int qemu_syscall_hook_register (int num, syscall_hook_cb_t callback,
-                                unsigned int prio);
-void qemu_syscall_hook_unregister (int num, syscall_hook_cb_t callback);
+int syscall_hook_register (int num, syscall_hook_cb_t callback,
+                           unsigned int prio);
+void syscall_hook_unregister (int num, syscall_hook_cb_t callback);
 
-int qemu_syscall_traverse (void *cpu_env, int num,
-                           abi_long arg1, abi_long arg2,
-                           abi_long arg3, abi_long arg4,
-                           abi_long arg5, abi_long arg6);
+int syscall_traverse (void *cpu_env, int num,
+                      abi_long arg1, abi_long arg2,
+                      abi_long arg3, abi_long arg4,
+                      abi_long arg5, abi_long arg6);
 
 #endif /* __SYSCALL_HOOK_H__ */
Signature · 1 line
1.5.6.5
Quoted 1 line

From f29bff214a9660e69bad10240e0c08897cacd092 Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Tue, 2 Dec 2008 11:45:42 +0100
Subject: [PATCH] Integration of syscall hooks

---
 Makefile.target           |    6 +++---
 linux-user/main.c         |    2 ++
 linux-user/syscall_hook.c |   26 +++++++++++++-------------
 linux-user/syscall_hook.h |    1 +
 4 files changed, 19 insertions(+), 16 deletions(-)
Makefile.target +3 -3
index 3cdf7db..2b69fb1 100644
@@ -357,7 +357,7 @@ LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
 endif
 
 ifeq ($(ARCH),sparc)
-# -static is used to avoid g1/g3 usage by the dynamic linker	
+# -static is used to avoid g1/g3 usage by the dynamic linker
 LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld -static
 endif
 
@@ -403,8 +403,8 @@ LDFLAGS+=-p
 CFLAGS+=-p
 endif
 
-OBJS= main.o syscall.o strace.o mmap.o signal.o path.o thunk.o \
-      elfload.o linuxload.o uaccess.o
+OBJS= main.o syscall.o syscall_hook.o strace.o mmap.o signal.o path.o\
+      thunk.o elfload.o linuxload.o uaccess.o
 LIBS+= $(AIOLIBS)
 ifdef TARGET_HAS_BFLT
 OBJS+= flatload.o
linux-user/main.c +2 -0
index 0d5115d..5b70e56 100644
@@ -27,6 +27,7 @@
 
 #include "qemu.h"
 #include "qemu-common.h"
+#include "syscall_hook.h"
 /* For tb_lock */
 #include "exec-all.h"
 
@@ -2415,6 +2416,7 @@ int main(int argc, char **argv)
     }
 
     target_set_brk(info->brk);
+    syscall_hook_init();
     syscall_init();
     signal_init();
 
linux-user/syscall_hook.c +13 -13
index b85628f..67d11f7 100644
@@ -19,11 +19,11 @@
  */
 #include <stdlib.h>
 
-#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
+#include "syscall_hook.h"
 
 typedef struct _syscall_hook_t {
-    struct _syscall_hook_t prev;
-    struct _syscall_hook_t next;
+    struct _syscall_hook_t *prev;
+    struct _syscall_hook_t *next;
 
     unsigned int priority;
 
@@ -40,7 +40,7 @@ _hook_new (syscall_hook_cb_t callback, unsigned int prio)
 
     if (hook) {
         hook->callback = callback;
-        hook->prio = prio;
+        hook->priority = prio;
     }
 
     return hook;
@@ -78,12 +78,12 @@ _hook_insert_before (int num,
 static void
 _hook_remove (int num, syscall_hook_t *hook)
 {
-    if (list->prev)
-        list->prev->next = list->next;
-    if (list->next)
-        list->next->prev = list->prev;
-    if (list == syscall_hooks[num])
-        syscall_hooks[num] = list->prev ? list->prev : list->next;
+    if (hook->prev)
+        hook->prev->next = hook->next;
+    if (hook->next)
+        hook->next->prev = hook->prev;
+    if (hook == syscall_hooks[num])
+        syscall_hooks[num] = hook->prev ? hook->prev : hook->next;
 }
 
 void
@@ -115,17 +115,17 @@ syscall_hook_register (int num, syscall_hook_cb_t callback,
         nlist = syscall_hooks[num];
 
         while (nlist &&
-               nlist->prio < prio) {
+               nlist->priority < prio) {
             plist = nlist;
             nlist = nlist->next;
         }
 
         if (nlist) {
-            _insert_before (nlist, new);
+            _hook_insert_before (num, nlist, new);
             if (nlist == syscall_hooks[num])
                 syscall_hooks[num] = new;
         } else {
-            _insert_after (plist, new);
+            _hook_insert_after (num, plist, new);
         }
     }
 
linux-user/syscall_hook.h +1 -0
index 72c0306..8965779 100644
@@ -20,6 +20,7 @@
 #ifndef __SYSCALL_HOOK_H__
 #define __SYSCALL_HOOK_H__
 
+#include "qemu-common.h"
 #include "qemu.h"
 
 #define MAX_SYSCALL (500) // How much ???
Signature · 1 line
1.5.6.5
Quoted 1 line

From 0273c8bc8ce12ec28ab3a29c0f6d253660654d7f Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Tue, 2 Dec 2008 15:00:15 +0100
Subject: [PATCH] hooks integration:

* fixed returned value

---
 linux-user/syscall.c      |    5 +++++
 linux-user/syscall_hook.c |    6 +++---
 linux-user/syscall_hook.h |   10 +++++-----
 3 files changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +5 -0
index c4dd38a..3629439 100644
@@ -3433,6 +3433,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     if(do_strace)
         print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 
+    if (syscall_hook_traverse (&ret, cpu_env, num,
+                               arg1, arg2, arg3,
+                               arg4, arg5, arg6))
+        goto fail;
+
     switch(num) {
     case TARGET_NR_exit:
 #ifdef HAVE_GPROF
linux-user/syscall_hook.c +3 -3
index 67d11f7..ee96e59 100644
@@ -153,7 +153,7 @@ syscall_hook_unregister (int num, syscall_hook_cb_t callback)
 }
 
 int
-syscall_hook_traverse (void *cpu_env, int num,
+syscall_hook_traverse (abi_long *ret, void *cpu_env, int num,
                        abi_long arg1, abi_long arg2,
                        abi_long arg3, abi_long arg4,
                        abi_long arg5, abi_long arg6)
@@ -166,7 +166,7 @@ syscall_hook_traverse (void *cpu_env, int num,
     list = syscall_hooks[num];
 
     while (list) {
-        if (list->callback (cpu_env, num,
+        if (list->callback (ret, cpu_env, num,
                             arg1, arg2, arg3,
                             arg4, arg5, arg5))
             break;
@@ -174,5 +174,5 @@ syscall_hook_traverse (void *cpu_env, int num,
         list = list->next;
     }
 
-    return (list == NULL);
+    return (list != NULL);
 }
linux-user/syscall_hook.h +5 -5
index 8965779..52c2afe 100644
@@ -25,7 +25,7 @@
 
 #define MAX_SYSCALL (500) // How much ???
 
-typedef int (*syscall_hook_cb_t) (void *cpu_env, int num,
+typedef int (*syscall_hook_cb_t) (abi_long *ret, void *cpu_env, int num,
                                   abi_long arg1, abi_long arg2,
                                   abi_long arg3, abi_long arg4,
                                   abi_long arg5, abi_long arg6);
@@ -36,9 +36,9 @@ int syscall_hook_register (int num, syscall_hook_cb_t callback,
                            unsigned int prio);
 void syscall_hook_unregister (int num, syscall_hook_cb_t callback);
 
-int syscall_traverse (void *cpu_env, int num,
-                      abi_long arg1, abi_long arg2,
-                      abi_long arg3, abi_long arg4,
-                      abi_long arg5, abi_long arg6);
+int syscall_hook_traverse (abi_long *ret, void *cpu_env, int num,
+                           abi_long arg1, abi_long arg2,
+                           abi_long arg3, abi_long arg4,
+                           abi_long arg5, abi_long arg6);
 
 #endif /* __SYSCALL_HOOK_H__ */

--
1.5.6.5

Quoted 1 line

From a48e606fe428ee8486ed2000d1077b49da0cf93c Mon Sep 17 00:00:00 2001

From: Lionel Landwerlin <[email protected]>
Date: Wed, 3 Dec 2008 02:27:36 +0100
Subject: [PATCH] Splitted syscalls static arrays.

---
 linux-user/syscall.c      |  269 +++++++++++++++++++++++----------------------
 linux-user/syscall_hook.c |   10 +-
 2 files changed, 293 insertions(+), 136 deletions(-)
linux-user/syscall.c +0 -0
index 3629439..3f48191 100644
@@ -79,2 +79,2 @@
 #include "qemu.h"
 #include "qemu-common.h"

+#include "syscall_hook.h"
+
#if defined(USE_NPTL)
#include <linux/futex.h>
#define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
@@ -3436,4 +3440,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,

     if (syscall_hook_traverse (&ret, cpu_env, num,
                                arg1, arg2, arg3,
                                arg4, arg5, arg6))

- goto fail;
+ {
+ ret = get_errno(ret);
+ goto fail; /* Even if we don't fail... */
+ }

     switch(num) {
     case TARGET_NR_exit:
linux-user/syscall_hook.c +5 -5
index ee96e59..92f2f7e 100644
@@ -166,12 +166,12 @@ syscall_hook_traverse (abi_long *ret, void *cpu_env, int num,
     list = syscall_hooks[num];
 
     while (list) {
-        if (list->callback (ret, cpu_env, num,
-                            arg1, arg2, arg3,
-                            arg4, arg5, arg5))
-            break;
+            if (list->callback (ret, cpu_env, num,
+                                arg1, arg2, arg3,
+                                arg4, arg5, arg5))
+                    break;
 
-        list = list->next;
+            list = list->next;
     }
 
     return (list != NULL);

--
1.5.6.5

#21 lore raw
In reply to Anthony Liguori
Quoted 10 lines · Anthony Liguori

This has been discussed before and I believe the overall consensus was that plugins are not desirable.

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes into QEMU. This is not just a matter of getting patches accepted, but also getting the appropriate guidance about how to refactor things to take into account all of the various architecture combinations that QEMU supports and some of the longer term efforts.

Quoted 4 lines

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

I think that getting patches accepted (or at least reviewed) is far more important than plugins or shared libraries.

Quoted 1 line

From my point of view surely the situation has improved a lot recently

on this aspect.

#22 lore raw
In reply to Anthony Liguori

Anthony Liguori writes ("Re: [Qemu-devel] Modular qemu?"):

Quoted 6 lines

With respect to the various forks of QEMU, I believe the real problem is that historically, people have had a tough time getting changes [in].

I hope this situation is improving. If people have feedback in how things could be improved, I think everyone is eager to here it. Plugins are not the solution though.

Yes, I agree that it has improved an awful lot. (Sorry that I'm a week behind on reading this list.)

It's really good to see such rapid movement even though it means that downstreams like me have a bigger job each time we want to merge up.

Ian.