RE: [Qemu-devel] [PATCH v3 1/2] contrib: add ivshmem client and server

2014-08-09 Thread Gonglei
Hi,

> Subject: [Qemu-devel] [PATCH v3 1/2] contrib: add ivshmem client and server
> 
> When using ivshmem devices, notifications between guests can be sent as
> interrupts using a ivshmem-server (typical use described in documentation).
> The client is provided as a debug tool.
> 
> Signed-off-by: Olivier Matz 
> Signed-off-by: David Marchand 
> ---
>  contrib/ivshmem-client/Makefile |   29 +++
>  contrib/ivshmem-client/ivshmem-client.c |  418
> ++
>  contrib/ivshmem-client/ivshmem-client.h |  238 ++
>  contrib/ivshmem-client/main.c   |  246 ++
>  contrib/ivshmem-server/Makefile |   29 +++
>  contrib/ivshmem-server/ivshmem-server.c |  420
> +++
>  contrib/ivshmem-server/ivshmem-server.h |  185 ++
>  contrib/ivshmem-server/main.c   |  296
> ++
>  qemu-doc.texi   |   10 +-
>  9 files changed, 1868 insertions(+), 3 deletions(-)
>  create mode 100644 contrib/ivshmem-client/Makefile
>  create mode 100644 contrib/ivshmem-client/ivshmem-client.c
>  create mode 100644 contrib/ivshmem-client/ivshmem-client.h
>  create mode 100644 contrib/ivshmem-client/main.c
>  create mode 100644 contrib/ivshmem-server/Makefile
>  create mode 100644 contrib/ivshmem-server/ivshmem-server.c
>  create mode 100644 contrib/ivshmem-server/ivshmem-server.h
>  create mode 100644 contrib/ivshmem-server/main.c
> 
> diff --git a/contrib/ivshmem-client/Makefile b/contrib/ivshmem-client/Makefile
> new file mode 100644
> index 000..eee97c6
> --- /dev/null
> +++ b/contrib/ivshmem-client/Makefile
> @@ -0,0 +1,29 @@
> +# Copyright 6WIND S.A., 2014
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# (at your option) any later version.  See the COPYING file in the
> +# top-level directory.
> +
> +S ?= $(CURDIR)
> +O ?= $(CURDIR)
> +
> +CFLAGS += -Wall -Wextra -Werror -g
> +LDFLAGS +=
> +LDLIBS += -lrt
> +
> +VPATH = $(S)
> +PROG = ivshmem-client
> +OBJS := $(O)/ivshmem-client.o
> +OBJS += $(O)/main.o
> +
> +$(O)/%.o: %.c
> + $(CC) $(CFLAGS) -o $@ -c $<
> +
> +$(O)/$(PROG): $(OBJS)
> + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
> +
> +.PHONY: all
> +all: $(O)/$(PROG)
> +
> +clean:
> + rm -f $(OBJS) $(O)/$(PROG)
> diff --git a/contrib/ivshmem-client/ivshmem-client.c
> b/contrib/ivshmem-client/ivshmem-client.c
> new file mode 100644
> index 000..2166b64
> --- /dev/null
> +++ b/contrib/ivshmem-client/ivshmem-client.c
> @@ -0,0 +1,418 @@
> +/*
> + * Copyright 6WIND S.A., 2014
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * (at your option) any later version.  See the COPYING file in the
> + * top-level directory.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#include "ivshmem-client.h"
> +
> +/* log a message on stdout if verbose=1 */
> +#define debug_log(client, fmt, ...) do { \
> +if ((client)->verbose) { \
> +printf(fmt, ## __VA_ARGS__); \
> +}\
> +} while (0)
> +
> +/* read message from the unix socket */
> +static int
> +read_one_msg(struct ivshmem_client *client, long *index, int *fd)
> +{
> +int ret;
> +struct msghdr msg;
> +struct iovec iov[1];
> +union {
> +struct cmsghdr cmsg;
> +char control[CMSG_SPACE(sizeof(int))];
> +} msg_control;
> +struct cmsghdr *cmsg;
> +
> +iov[0].iov_base = index;
> +iov[0].iov_len = sizeof(*index);
> +
> +memset(&msg, 0, sizeof(msg));
> +msg.msg_iov = iov;
> +msg.msg_iovlen = 1;
> +msg.msg_control = &msg_control;
> +msg.msg_controllen = sizeof(msg_control);
> +
> +ret = recvmsg(client->sock_fd, &msg, 0);
> +if (ret < 0) {
> +debug_log(client, "cannot read message: %s\n", strerror(errno));
> +return -1;
> +}
> +if (ret == 0) {
> +debug_log(client, "lost connection to server\n");
> +return -1;
> +}
> +
> +*fd = -1;
> +
> +for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg =
> CMSG_NXTHDR(&msg, cmsg)) {
> +
> +if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
> +cmsg->cmsg_level != SOL_SOCKET ||
> +cmsg->cmsg_type != SCM_RIGHTS) {
> +continue;
> +}
> +
> +memcpy(fd, CMSG_DATA(cmsg), sizeof(*fd));
> +}
> +
> +return 0;
> +}
> +
> +/* free a peer when the server advertise a disconnection or when the
> + * client is freed */
> +static void
> +free_peer(struct ivshmem_client *client, struct ivshmem_client_peer *peer)
> +{
> +unsigned vector;
> +
> +TAILQ_REMOVE(&client->peer_list, peer, next);
> +for (vector = 0; vector < peer->vectors_count; vector++) {
> +close(peer->vectors[vector]);
> +}
> +
> +free(peer);
> +}
> +
> +/* handle message coming from server (n

Re: [PATCH] vfio: Fix build failure seen if vfio is built as module and EEH is enabled

2014-08-09 Thread Guenter Roeck

On 08/09/2014 04:18 PM, Alex Williamson wrote:

On Sat, 2014-08-09 at 15:28 -0700, Guenter Roeck wrote:

On 08/09/2014 12:28 PM, Alex Williamson wrote:

On Sat, 2014-08-09 at 10:04 -0700, Guenter Roeck wrote:

The following build failure is seen with ppc:allmodconfig.

ERROR: ".vfio_spapr_iommu_eeh_ioctl" [drivers/vfio/vfio_iommu_spapr_tce.ko] 
undefined!
ERROR: ".vfio_spapr_pci_eeh_open" [drivers/vfio/pci/vfio-pci.ko] undefined!
ERROR: ".vfio_spapr_pci_eeh_release" [drivers/vfio/pci/vfio-pci.ko] undefined!

Simply exporting the missing symbols is insufficient, since drivers/vfio
can be built as module but drivers/vfio/vfio_spapr_eeh.c depends on
EEH which is boolean. The combination of obj-m for drivers/vfio and obj-y
for drivers/vfio/vfio_spapr_eeh.o results in the symbols being missed even
if exported.

Export missing symbols and introduce new tristate configuration option
VFIO_EEH depending on both EEH and VFIO to fix the problem.

Cc: Gavin Shan 
Cc: Benjamin Herrenschmidt 
Signed-off-by: Guenter Roeck 


Please try:

git://github.com/awilliam/linux-vfio.git next

This will be part of the next linux-next build, should resolve the
problem, and I plan to ask for a pull early this coming week.  Thanks,



That should do for the most part, but it will select VFIO_SPAPR_EEH
even if EEH is not configured. You would need something like
select VFIO_SPAPR_EEH if (PPC_POWERNV || PPC_PSERIES) && EEH
to prevent that.


Feel free to post a patch against this branch.  Thanks,



I'll wait for -next to see if there are any problems in practice.

Guenter

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] vfio: Fix build failure seen if vfio is built as module and EEH is enabled

2014-08-09 Thread Alex Williamson
On Sat, 2014-08-09 at 15:28 -0700, Guenter Roeck wrote:
> On 08/09/2014 12:28 PM, Alex Williamson wrote:
> > On Sat, 2014-08-09 at 10:04 -0700, Guenter Roeck wrote:
> >> The following build failure is seen with ppc:allmodconfig.
> >>
> >> ERROR: ".vfio_spapr_iommu_eeh_ioctl" 
> >> [drivers/vfio/vfio_iommu_spapr_tce.ko] undefined!
> >> ERROR: ".vfio_spapr_pci_eeh_open" [drivers/vfio/pci/vfio-pci.ko] undefined!
> >> ERROR: ".vfio_spapr_pci_eeh_release" [drivers/vfio/pci/vfio-pci.ko] 
> >> undefined!
> >>
> >> Simply exporting the missing symbols is insufficient, since drivers/vfio
> >> can be built as module but drivers/vfio/vfio_spapr_eeh.c depends on
> >> EEH which is boolean. The combination of obj-m for drivers/vfio and obj-y
> >> for drivers/vfio/vfio_spapr_eeh.o results in the symbols being missed even
> >> if exported.
> >>
> >> Export missing symbols and introduce new tristate configuration option
> >> VFIO_EEH depending on both EEH and VFIO to fix the problem.
> >>
> >> Cc: Gavin Shan 
> >> Cc: Benjamin Herrenschmidt 
> >> Signed-off-by: Guenter Roeck 
> >
> > Please try:
> >
> > git://github.com/awilliam/linux-vfio.git next
> >
> > This will be part of the next linux-next build, should resolve the
> > problem, and I plan to ask for a pull early this coming week.  Thanks,
> >
> 
> That should do for the most part, but it will select VFIO_SPAPR_EEH
> even if EEH is not configured. You would need something like
>   select VFIO_SPAPR_EEH if (PPC_POWERNV || PPC_PSERIES) && EEH
> to prevent that.

Feel free to post a patch against this branch.  Thanks,

Alex


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] vfio: Fix build failure seen if vfio is built as module and EEH is enabled

2014-08-09 Thread Guenter Roeck

On 08/09/2014 12:28 PM, Alex Williamson wrote:

On Sat, 2014-08-09 at 10:04 -0700, Guenter Roeck wrote:

The following build failure is seen with ppc:allmodconfig.

ERROR: ".vfio_spapr_iommu_eeh_ioctl" [drivers/vfio/vfio_iommu_spapr_tce.ko] 
undefined!
ERROR: ".vfio_spapr_pci_eeh_open" [drivers/vfio/pci/vfio-pci.ko] undefined!
ERROR: ".vfio_spapr_pci_eeh_release" [drivers/vfio/pci/vfio-pci.ko] undefined!

Simply exporting the missing symbols is insufficient, since drivers/vfio
can be built as module but drivers/vfio/vfio_spapr_eeh.c depends on
EEH which is boolean. The combination of obj-m for drivers/vfio and obj-y
for drivers/vfio/vfio_spapr_eeh.o results in the symbols being missed even
if exported.

Export missing symbols and introduce new tristate configuration option
VFIO_EEH depending on both EEH and VFIO to fix the problem.

Cc: Gavin Shan 
Cc: Benjamin Herrenschmidt 
Signed-off-by: Guenter Roeck 


Please try:

git://github.com/awilliam/linux-vfio.git next

This will be part of the next linux-next build, should resolve the
problem, and I plan to ask for a pull early this coming week.  Thanks,



That should do for the most part, but it will select VFIO_SPAPR_EEH
even if EEH is not configured. You would need something like
select VFIO_SPAPR_EEH if (PPC_POWERNV || PPC_PSERIES) && EEH
to prevent that.

Guenter

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] vfio: Fix build failure seen if vfio is built as module and EEH is enabled

2014-08-09 Thread Alex Williamson
On Sat, 2014-08-09 at 10:04 -0700, Guenter Roeck wrote:
> The following build failure is seen with ppc:allmodconfig.
> 
> ERROR: ".vfio_spapr_iommu_eeh_ioctl" [drivers/vfio/vfio_iommu_spapr_tce.ko] 
> undefined!
> ERROR: ".vfio_spapr_pci_eeh_open" [drivers/vfio/pci/vfio-pci.ko] undefined!
> ERROR: ".vfio_spapr_pci_eeh_release" [drivers/vfio/pci/vfio-pci.ko] undefined!
> 
> Simply exporting the missing symbols is insufficient, since drivers/vfio
> can be built as module but drivers/vfio/vfio_spapr_eeh.c depends on
> EEH which is boolean. The combination of obj-m for drivers/vfio and obj-y
> for drivers/vfio/vfio_spapr_eeh.o results in the symbols being missed even
> if exported.
> 
> Export missing symbols and introduce new tristate configuration option
> VFIO_EEH depending on both EEH and VFIO to fix the problem.
> 
> Cc: Gavin Shan 
> Cc: Benjamin Herrenschmidt 
> Signed-off-by: Guenter Roeck 

Please try:

git://github.com/awilliam/linux-vfio.git next

This will be part of the next linux-next build, should resolve the
problem, and I plan to ask for a pull early this coming week.  Thanks,

Alex

> ---
>  drivers/vfio/Kconfig  | 6 ++
>  drivers/vfio/Makefile | 2 +-
>  drivers/vfio/vfio_spapr_eeh.c | 4 
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
> index af7b204..06adecd 100644
> --- a/drivers/vfio/Kconfig
> +++ b/drivers/vfio/Kconfig
> @@ -8,12 +8,18 @@ config VFIO_IOMMU_SPAPR_TCE
>   depends on VFIO && SPAPR_TCE_IOMMU
>   default n
>  
> +config VFIO_EEH
> + tristate
> + depends on VFIO && EEH
> + default n
> +
>  menuconfig VFIO
>   tristate "VFIO Non-Privileged userspace driver framework"
>   depends on IOMMU_API
>   select VFIO_IOMMU_TYPE1 if X86
>   select VFIO_IOMMU_SPAPR_TCE if (PPC_POWERNV || PPC_PSERIES)
>   select ANON_INODES
> + select VFIO_EEH if EEH
>   help
> VFIO provides a framework for secure userspace device drivers.
> See Documentation/vfio.txt for more details.
> diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
> index 50e30bc..26016cd 100644
> --- a/drivers/vfio/Makefile
> +++ b/drivers/vfio/Makefile
> @@ -1,5 +1,5 @@
>  obj-$(CONFIG_VFIO) += vfio.o
>  obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o
>  obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o
> -obj-$(CONFIG_EEH) += vfio_spapr_eeh.o
> +obj-$(CONFIG_VFIO_EEH) += vfio_spapr_eeh.o
>  obj-$(CONFIG_VFIO_PCI) += pci/
> diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c
> index f834b4c..e827309 100644
> --- a/drivers/vfio/vfio_spapr_eeh.c
> +++ b/drivers/vfio/vfio_spapr_eeh.c
> @@ -9,6 +9,7 @@
>   * published by the Free Software Foundation.
>   */
>  
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -18,11 +19,13 @@ int vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
>  {
>   return eeh_dev_open(pdev);
>  }
> +EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open);
>  
>  void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
>  {
>   eeh_dev_release(pdev);
>  }
> +EXPORT_SYMBOL(vfio_spapr_pci_eeh_release);
>  
>  long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
>   unsigned int cmd, unsigned long arg)
> @@ -85,3 +88,4 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
>  
>   return ret;
>  }
> +EXPORT_SYMBOL(vfio_spapr_iommu_eeh_ioctl);



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] vfio: Fix build failure seen if vfio is built as module and EEH is enabled

2014-08-09 Thread Guenter Roeck
The following build failure is seen with ppc:allmodconfig.

ERROR: ".vfio_spapr_iommu_eeh_ioctl" [drivers/vfio/vfio_iommu_spapr_tce.ko] 
undefined!
ERROR: ".vfio_spapr_pci_eeh_open" [drivers/vfio/pci/vfio-pci.ko] undefined!
ERROR: ".vfio_spapr_pci_eeh_release" [drivers/vfio/pci/vfio-pci.ko] undefined!

Simply exporting the missing symbols is insufficient, since drivers/vfio
can be built as module but drivers/vfio/vfio_spapr_eeh.c depends on
EEH which is boolean. The combination of obj-m for drivers/vfio and obj-y
for drivers/vfio/vfio_spapr_eeh.o results in the symbols being missed even
if exported.

Export missing symbols and introduce new tristate configuration option
VFIO_EEH depending on both EEH and VFIO to fix the problem.

Cc: Gavin Shan 
Cc: Benjamin Herrenschmidt 
Signed-off-by: Guenter Roeck 
---
 drivers/vfio/Kconfig  | 6 ++
 drivers/vfio/Makefile | 2 +-
 drivers/vfio/vfio_spapr_eeh.c | 4 
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/Kconfig b/drivers/vfio/Kconfig
index af7b204..06adecd 100644
--- a/drivers/vfio/Kconfig
+++ b/drivers/vfio/Kconfig
@@ -8,12 +8,18 @@ config VFIO_IOMMU_SPAPR_TCE
depends on VFIO && SPAPR_TCE_IOMMU
default n
 
+config VFIO_EEH
+   tristate
+   depends on VFIO && EEH
+   default n
+
 menuconfig VFIO
tristate "VFIO Non-Privileged userspace driver framework"
depends on IOMMU_API
select VFIO_IOMMU_TYPE1 if X86
select VFIO_IOMMU_SPAPR_TCE if (PPC_POWERNV || PPC_PSERIES)
select ANON_INODES
+   select VFIO_EEH if EEH
help
  VFIO provides a framework for secure userspace device drivers.
  See Documentation/vfio.txt for more details.
diff --git a/drivers/vfio/Makefile b/drivers/vfio/Makefile
index 50e30bc..26016cd 100644
--- a/drivers/vfio/Makefile
+++ b/drivers/vfio/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_VFIO) += vfio.o
 obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o
 obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o
-obj-$(CONFIG_EEH) += vfio_spapr_eeh.o
+obj-$(CONFIG_VFIO_EEH) += vfio_spapr_eeh.o
 obj-$(CONFIG_VFIO_PCI) += pci/
diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c
index f834b4c..e827309 100644
--- a/drivers/vfio/vfio_spapr_eeh.c
+++ b/drivers/vfio/vfio_spapr_eeh.c
@@ -9,6 +9,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -18,11 +19,13 @@ int vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
 {
return eeh_dev_open(pdev);
 }
+EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open);
 
 void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
 {
eeh_dev_release(pdev);
 }
+EXPORT_SYMBOL(vfio_spapr_pci_eeh_release);
 
 long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
unsigned int cmd, unsigned long arg)
@@ -85,3 +88,4 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
 
return ret;
 }
+EXPORT_SYMBOL(vfio_spapr_iommu_eeh_ioctl);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html