From: Anthony PERARD <anthony.perard@citrix.com>
To: Alexander Graf <agraf@suse.de>
Cc: Xen Devel <xen-devel@lists.xensource.com>,
QEMU-devel <qemu-devel@nongnu.org>,
Anthony Liguori <anthony@codemonkey.ws>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: Re: [Qemu-devel] [PATCH V11 03/15] xen: Support new libxc calls from xen unstable.
Date: Mon, 28 Mar 2011 16:22:09 +0100 [thread overview]
Message-ID: <AANLkTike2Uv5-7YaNr6J44fvEuh8ET0e78gdkyQ=x-By@mail.gmail.com> (raw)
In-Reply-To: <7B2F3BE5-FCE1-49E1-A7CC-18E71D88F83D@suse.de>
On Wed, Mar 23, 2011 at 10:43, Alexander Graf <agraf@suse.de> wrote:
>
> On 01.03.2011, at 19:35, Anthony.Perard@citrix.com wrote:
>
>> From: Anthony PERARD <anthony.perard@citrix.com>
>>
>> This patch updates the libxenctrl calls in Qemu to use the new interface,
>> otherwise Qemu wouldn't be able to build against new versions of the
>> library.
>>
>> We check libxenctrl version in configure, from Xen 3.3.0 to Xen
>> unstable.
>>
>> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>> Acked-by: Alexander Graf <agraf@suse.de>
>> ---
>> configure | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-
>> hw/xen_backend.c | 21 ++++++++-------
>> hw/xen_backend.h | 6 ++--
>> hw/xen_common.h | 64 +++++++++++++++++++++++++++++++++++++----------
>> hw/xen_disk.c | 4 +-
>> hw/xen_domainbuild.c | 3 +-
>> 6 files changed, 133 insertions(+), 32 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 3036faf..a84d974 100755
>> --- a/configure
>> +++ b/configure
>> @@ -126,6 +126,7 @@ vnc_jpeg=""
>> vnc_png=""
>> vnc_thread="no"
>> xen=""
>> +xen_ctrl_version=""
>> linux_aio=""
>> attr=""
>> vhost_net=""
>> @@ -1147,20 +1148,81 @@ fi
>>
>> if test "$xen" != "no" ; then
>> xen_libs="-lxenstore -lxenctrl -lxenguest"
>> +
>> + # Xen unstable
>> cat > $TMPC <<EOF
>> #include <xenctrl.h>
>> #include <xs.h>
>> -int main(void) { xs_daemon_open(); xc_interface_open(); return 0; }
>> +#include <stdint.h>
>> +#include <xen/hvm/hvm_info_table.h>
>> +#if !defined(HVM_MAX_VCPUS)
>> +# error HVM_MAX_VCPUS not defined
>> +#endif
>> +int main(void) {
>> + xc_interface *xc;
>> + xs_daemon_open();
>> + xc = xc_interface_open(0, 0, 0);
>> + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
>> + xc_gnttab_open(NULL, 0);
>> + return 0;
>> +}
>> EOF
>> if compile_prog "" "$xen_libs" ; then
>> + xen_ctrl_version=410
>> xen=yes
>> - libs_softmmu="$xen_libs $libs_softmmu"
>> +
>> + # Xen 4.0.0
>> + elif (
>> + cat > $TMPC <<EOF
>> +#include <xenctrl.h>
>> +#include <xs.h>
>> +#include <stdint.h>
>> +#include <xen/hvm/hvm_info_table.h>
>> +#if !defined(HVM_MAX_VCPUS)
>> +# error HVM_MAX_VCPUS not defined
>> +#endif
>> +int main(void) {
>> + xs_daemon_open();
>> + xc_interface_open();
>> + xc_gnttab_open();
>> + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
>> + return 0;
>> +}
>> +EOF
>> + compile_prog "" "$xen_libs"
>> + ) ; then
>> + xen_ctrl_version=400
>> + xen=yes
>> +
>> + # Xen 3.3.0, 3.4.0
>> + elif (
>> + cat > $TMPC <<EOF
>> +#include <xenctrl.h>
>> +#include <xs.h>
>> +int main(void) {
>> + xs_daemon_open();
>> + xc_interface_open();
>> + xc_gnttab_open();
>> + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
>> + return 0;
>> +}
>> +EOF
>> + compile_prog "" "$xen_libs"
>> + ) ; then
>> + xen_ctrl_version=330
>> + xen=yes
>> +
>> + # Xen not found or unsupported
>> else
>> if test "$xen" = "yes" ; then
>> feature_not_found "xen"
>> fi
>> xen=no
>> fi
>> +
>> + if test "$xen" = yes; then
>> + libs_softmmu="$xen_libs $libs_softmmu"
>> + fi
>> fi
>>
>> ##########################################
>> @@ -2755,6 +2817,7 @@ if test "$bluez" = "yes" ; then
>> fi
>> if test "$xen" = "yes" ; then
>> echo "CONFIG_XEN=y" >> $config_host_mak
>> + echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
>> fi
>> if test "$io_thread" = "yes" ; then
>> echo "CONFIG_IOTHREAD=y" >> $config_host_mak
>> diff --git a/hw/xen_backend.c b/hw/xen_backend.c
>> index 9f4ec4b..3907b83 100644
>> --- a/hw/xen_backend.c
>> +++ b/hw/xen_backend.c
>> @@ -43,7 +43,8 @@
>> /* ------------------------------------------------------------- */
>>
>> /* public */
>> -int xen_xc;
>> +XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
>> +XenGnttab xen_xcg = XC_HANDLER_INITIAL_VALUE;
>> struct xs_handle *xenstore = NULL;
>> const char *xen_protocol;
>>
>> @@ -214,8 +215,8 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
>> xendev->debug = debug;
>> xendev->local_port = -1;
>>
>> - xendev->evtchndev = xc_evtchn_open();
>> - if (xendev->evtchndev < 0) {
>> + xendev->evtchndev = xc_evtchn_open(NULL, 0);
>> + if (xendev->evtchndev == XC_HANDLER_INITIAL_VALUE) {
>> xen_be_printf(NULL, 0, "can't open evtchn device\n");
>> qemu_free(xendev);
>> return NULL;
>> @@ -223,15 +224,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
>> fcntl(xc_evtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
>>
>> if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
>> - xendev->gnttabdev = xc_gnttab_open();
>> - if (xendev->gnttabdev < 0) {
>> + xendev->gnttabdev = xc_gnttab_open(NULL, 0);
>> + if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
>> xen_be_printf(NULL, 0, "can't open gnttab device\n");
>> xc_evtchn_close(xendev->evtchndev);
>> qemu_free(xendev);
>> return NULL;
>> }
>> } else {
>> - xendev->gnttabdev = -1;
>> + xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
>> }
>>
>> QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
>> @@ -277,10 +278,10 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
>> qemu_free(xendev->fe);
>> }
>>
>> - if (xendev->evtchndev >= 0) {
>> + if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {
>> xc_evtchn_close(xendev->evtchndev);
>> }
>> - if (xendev->gnttabdev >= 0) {
>> + if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
>> xc_gnttab_close(xendev->gnttabdev);
>> }
>>
>> @@ -664,8 +665,8 @@ int xen_be_init(void)
>> goto err;
>> }
>>
>> - xen_xc = xc_interface_open();
>> - if (xen_xc == -1) {
>> + xen_xc = xc_interface_open(0, 0, 0);
>> + if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
>> xen_be_printf(NULL, 0, "can't open xen interface\n");
>> goto err;
>> }
>> diff --git a/hw/xen_backend.h b/hw/xen_backend.h
>> index 1b428e3..6401c85 100644
>> --- a/hw/xen_backend.h
>> +++ b/hw/xen_backend.h
>> @@ -45,8 +45,8 @@ struct XenDevice {
>> int remote_port;
>> int local_port;
>>
>> - int evtchndev;
>> - int gnttabdev;
>> + XenEvtchn evtchndev;
>> + XenGnttab gnttabdev;
>>
>> struct XenDevOps *ops;
>> QTAILQ_ENTRY(XenDevice) next;
>> @@ -55,7 +55,7 @@ struct XenDevice {
>> /* ------------------------------------------------------------- */
>>
>> /* variables */
>> -extern int xen_xc;
>> +extern XenXC xen_xc;
>> extern struct xs_handle *xenstore;
>> extern const char *xen_protocol;
>>
>> diff --git a/hw/xen_common.h b/hw/xen_common.h
>> index 8a55b44..7e123ec 100644
>> --- a/hw/xen_common.h
>> +++ b/hw/xen_common.h
>> @@ -1,6 +1,8 @@
>> #ifndef QEMU_HW_XEN_COMMON_H
>> #define QEMU_HW_XEN_COMMON_H 1
>>
>> +#include "config-host.h"
>> +
>> #include <stddef.h>
>> #include <inttypes.h>
>>
>> @@ -13,22 +15,56 @@
>> #include "qemu-queue.h"
>>
>> /*
>> - * tweaks needed to build with different xen versions
>> - * 0x00030205 -> 3.1.0
>> - * 0x00030207 -> 3.2.0
>> - * 0x00030208 -> unstable
>> + * We don't support Xen prior to 3.3.0.
>> */
>> -#include <xen/xen-compat.h>
>> -#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030205
>> -# define evtchn_port_or_error_t int
>> -#endif
>> -#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030207
>> -# define xc_map_foreign_pages xc_map_foreign_batch
>> +
>> +/* Xen before 4.0 */
>> +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
>> +static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
>> + xen_pfn_t *arr, int *err,
>> + unsigned int num)
>> +{
>> + return xc_map_foreign_batch(xc_handle, dom, prot, arr, num);
>> +}
>> #endif
>> -#if __XEN_LATEST_INTERFACE_VERSION__ < 0x00030208
>> -# define xen_mb() mb()
>> -# define xen_rmb() rmb()
>> -# define xen_wmb() wmb()
>> +
>> +
>> +/* Xen before 4.1 */
>> +#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
>> +
>> +typedef int XenXC;
>> +typedef int XenEvtchn;
>> +typedef int XenGnttab;
>> +
>> +# define XC_INTERFACE_FMT "%i"
>> +# define XC_HANDLER_INITIAL_VALUE -1
>> +
>> +# define xc_interface_open(logger, dombuild_logger, open_flags) \
>> + xc_interface_open()
>> +# define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
>> +# define xc_gnttab_open(logger, open_flags) xc_gnttab_open()
>
>
> defines really bite me when abstracting the interface through an indirect calling table. I had to change the code this way to make it work with xenner:
>
>
> diff --git a/hw/xen_common.h b/hw/xen_common.h
> index a5fc74b..0c09b37 100644
> --- a/hw/xen_common.h
> +++ b/hw/xen_common.h
> @@ -39,10 +39,23 @@ typedef int XenGnttab;
> # define XC_INTERFACE_FMT "%i"
> # define XC_HANDLER_INITIAL_VALUE -1
>
> -# define xc_interface_open(logger, dombuild_logger, open_flags) \
> - xc_interface_open()
> -# define xc_evtchn_open(logger, open_flags) xc_evtchn_open()
> -# define xc_gnttab_open(logger, open_flags) xc_gnttab_open()
> +static inline XenEvtchn xen_xc_evtchn_open(void *logger,
> + unsigned int open_flags)
> +{
> + return xc_evtchn_open();
> +}
> +
> +static inline XenGnttab xen_xc_gnttab_open(void *logger,
> + unsigned int open_flags)
> +{
> + return xc_gnttab_open();
> +}
> +
> +static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
> + unsigned int open_flags)
> +{
> + return xc_interface_open();
> +}
>
> static inline int xc_fd(int xen_xc)
> {
> @@ -69,6 +82,24 @@ typedef xc_gnttab *XenGnttab;
> # define XC_INTERFACE_FMT "%p"
> # define XC_HANDLER_INITIAL_VALUE NULL
>
> +static inline XenEvtchn xen_xc_evtchn_open(void *logger,
> + unsigned int open_flags)
> +{
> + return xc_evtchn_open(logger, open_flags);
> +}
> +
> +static inline XenGnttab xen_xc_gnttab_open(void *logger,
> + unsigned int open_flags)
> +{
> + return xc_gnttab_open(logger, open_flags);
> +}
> +
> +static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
> + int open_flags)
> +{
> + return xc_interface_open(logger, dombuild_logger, open_flags);
> +}
> +
> /* FIXME There is now way to have the xen fd */
> static inline int xc_fd(xc_interface *xen_xc)
> {
>
>
> Leave it as is in your patch and I'll change it in my xenner patch set again, but I wanted to make sure that you're aware of the issues going along with #defines.
I understand the issues with the defines. I just trying to address
both comment from Anthony and you. But, I think these static inline
instead of the #defines will be ok. So I will put it in my series.
--
Anthony PERARD
next prev parent reply other threads:[~2011-03-28 15:22 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-01 18:35 [PATCH V11 00/15] Xen device model support anthony.perard
2011-03-01 18:35 ` [PATCH V11 01/15] xen: Replace some tab-indents with spaces (clean-up) anthony.perard
2011-03-01 18:35 ` [PATCH V11 02/15] xen: Make Xen build once anthony.perard
2011-03-23 10:57 ` [Qemu-devel] " Alexander Graf
2011-03-28 14:50 ` Anthony PERARD
2011-03-28 17:29 ` Alexander Graf
2011-03-01 18:35 ` [PATCH V11 03/15] xen: Support new libxc calls from xen unstable anthony.perard
2011-03-23 10:43 ` [Qemu-devel] " Alexander Graf
2011-03-28 15:22 ` Anthony PERARD [this message]
2011-03-01 18:35 ` [PATCH V11 04/15] xen: Add initialisation of Xen anthony.perard
2011-03-01 18:35 ` [PATCH V11 05/15] xen: Add xenfv machine anthony.perard
2011-03-01 18:35 ` [PATCH V11 06/15] xen: Add the Xen platform pci device anthony.perard
2011-03-23 12:08 ` Alexander Graf
2011-03-28 16:08 ` [Qemu-devel] " Anthony PERARD
2011-03-01 18:35 ` [PATCH V11 07/15] piix_pci: Introduces Xen specific call for irq anthony.perard
2011-03-01 18:35 ` [PATCH V11 08/15] xen: Introduce Xen Interrupt Controller anthony.perard
2011-03-01 18:35 ` [PATCH V11 09/15] xen: Introduce the Xen mapcache anthony.perard
2011-03-23 12:33 ` [Qemu-devel] " Alexander Graf
2011-03-28 16:28 ` Anthony PERARD
2011-03-01 18:35 ` [PATCH V11 10/15] configure: Always use 64bits target physical addresses with xen enabled anthony.perard
2011-03-01 18:35 ` [PATCH V11 11/15] Introduce qemu_put_ram_ptr anthony.perard
2011-03-01 18:35 ` [PATCH V11 12/15] vl.c: Introduce getter for shutdown_requested and reset_requested anthony.perard
2011-03-01 18:35 ` [PATCH V11 13/15] xen: Initialize event channels and io rings anthony.perard
2011-03-23 12:36 ` [Qemu-devel] " Alexander Graf
2011-03-28 16:30 ` Anthony PERARD
2011-03-01 18:35 ` [PATCH V11 14/15] xen: Set running state in xenstore anthony.perard
2011-03-01 18:35 ` [PATCH V11 15/15] xen: Add Xen hypercall for sleep state in the cmos_s3 callback anthony.perard
2011-03-11 16:29 ` [Qemu-devel] [PATCH V11 00/15] Xen device model support Anthony Liguori
2011-03-11 20:47 ` Alexander Graf
2011-03-22 14:23 ` Alexander Graf
2011-03-22 14:47 ` Anthony PERARD
2011-03-22 15:13 ` Alexander Graf
2011-03-22 15:40 ` [Xen-devel] " Alexander Graf
2011-03-22 15:52 ` Re: [Qemu-devel] " Alexander Graf
2011-03-22 17:22 ` Anthony PERARD
2011-03-22 17:23 ` [Xen-devel] " Alexander Graf
2011-03-23 12:37 ` [Qemu-devel] " Alexander Graf
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='AANLkTike2Uv5-7YaNr6J44fvEuh8ET0e78gdkyQ=x-By@mail.gmail.com' \
--to=anthony.perard@citrix.com \
--cc=agraf@suse.de \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.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).