Re: [Qemu-devel] [RFC 1/1] qemu-ga: add missing libpcre to MSI build

2018-11-21 Thread Sameeh Jubran
Hi thomas,

Can you please share more info on why libpcre is needed in the first
place? I have tried to build qemu without it and I see no issues of
qemu-ga failing.
On Fri, Jul 7, 2017 at 9:47 AM Thomas Lamprecht  wrote:
>
> Hi,
>
> On 06/02/2017 01:42 PM, Marc-André Lureau wrote:
> > Hi
> >
> > On Thu, Jun 1, 2017 at 5:08 PM Thomas Lamprecht
> > wrote:
> >
> >> glib depends on libpcre which was not shipped with the MSI, thus
> >> starting of the qemu-ga.exe failed with the respective error message.
> >>
> >> Tell WIXL to ship this library with the MSI to avoid this problem.
> >>
> >> Signed-off-by: Thomas Lamprecht
> >> CC: Stefan Weil
> >> CC: Michael Roth
> >>
> > It depends on your glib build, but since Fedora is one of the most
> > maintained cross mingw- distrib, it make sense to fix the build there.
>
> But even if it isn't best to ship an unnecessary library it shouldn't
> harm either. I'd like to make it nicer but after looking at the complexity
> of possibilities to do so I rather want to avoid it, especially with my
> almost non-existing knowledge of windows builds.
>
> > Other solutions would involve either using wixl-specific require
> > preprocessor directive (which comes with a bunch of unused files since
> > those are mostly generated from mingw*- packages), or coming up with some
> > kind of dynamic dependency resolution (approach similar to Richard W.M.
> > Jones nsiswrapper). However this last approach is quite limited, since it
> > doesn't reach to data files etc.
> > In the meantime:
> >   Reviewed-by: Marc-André Lureau
> >
>
> Thank you for the review!Has this any chance to still get into qemu 2.10?
> Would be nice.
>
> cheers,
> Thomas
>
> >> I haven't done much with the qga or WIXL, so I send this as a RFC.
> >> I hope that I guessed the right people to get CC'ed from MAINTAINERS.
> >>
> >> This fixes a current qemu-ga MSI build, I tested it successfully with
> >> Windows 7
> >> and Windows 10 as guest OS.
> >>
> >> I cross built from a Fedora 25 LXC container.
> >>
> >> The Guid for the libpcre was generated byhttps://www.guidgen.com/  as
> >> suggested
> >> by:
> >>
> >> http://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html
> >>
> >>   qga/installer/qemu-ga.wxs | 4 
> >>   1 file changed, 4 insertions(+)
> >>
> >> diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs
> >> index fa2260cafa..5af11627f8 100644
> >> --- a/qga/installer/qemu-ga.wxs
> >> +++ b/qga/installer/qemu-ga.wxs
> >> @@ -125,6 +125,9 @@
> >>  >> Guid="{6C117C78-0F47-4B07-8F34-6BEE11643829}">
> >>>> Source="$(var.Mingw_bin)/libwinpthread-1.dll" KeyPath="yes" DiskId="1"/>
> >> 
> >> +   >> Guid="{7A86B45E-A009-489A-A849-CE3BACF03CD0}">
> >> + >> Source="$(var.Mingw_bin)/libpcre-1.dll" KeyPath="yes" DiskId="1"/>
> >> +  
> >>  >> Guid="{D075D109-51CA-11E3-9F8B-000C29858960}">
> >>>>
> >> Key="Software\$(env.QEMU_GA_MANUFACTURER)\$(env.QEMU_GA_DISTRO)\Tools\QemuGA">
> >> @@ -173,6 +176,7 @@
> >> 
> >> 
> >> 
> >> +  
> >>   
> >>
> >>   
> >> --
> >> 2.11.0
> >>
> >>
> >>
> >> --
> > Marc-André Lureau
> >
>
>
>
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



[Qemu-devel] qga-win: Build errors when building with vss support

2018-11-13 Thread Sameeh Jubran
Hi all,

The following errors show up when attempting to compile qemu-ga for windows
which is done using mingw:

qga/vss-win32/requester.o: In function `requester_freeze':
/home/bishara/git_qemu/qga/vss-win32/requester.cpp:283: undefined
reference to `g_assertion_message_expr'
qga/vss-win32/requester.o: In function `requester_thaw':
/home/bishara/git_qemu/qga/vss-win32/requester.cpp:468: undefined
reference to `g_assertion_message_expr'
/home/bishara/git_qemu/qga/vss-win32/requester.cpp:469: undefined
reference to `g_assertion_message_expr'

I believe that the error was caused by the following commit:
https://github.com/qemu/qemu/commit/3ebee3b191e755d3f7311a6a62eea5c9628b221b

What do you think is the best approach to resolve this?

-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.


Re: [Qemu-devel] [RFC 0/2] Attempt to implement the standby feature for assigned network devices

2018-10-25 Thread Sameeh Jubran
On Thu, Oct 25, 2018 at 5:06 PM Sameeh Jubran  wrote:
>
> From: Sameeh Jubran 
>
> Hi all,
>
> Background:
>
> There has been a few attempts to implement the standby feature for vfio
> assigned devices which aims to enable the migration of such devices. This
> is another attempt.
>
> The series implements an infrastructure for hiding devices from the bus
> upon boot. What it does is the following:
>
> * In the first patch the infrastructure for hiding the device is added
>   for the qbus and qdev APIs. A "hidden" boolean is added to the device
>   state and it is set based on a callback to the standby device which
>   registers itself for handling the assessment: "should the primary device
>   be hidden?" by cross validating the ids of the devices.
>
> * In the second patch the virtio-net uses the API to hide the vfio
>   device and unhides it when the feature is acked.
>
> Disclaimers:
>
> * I have only scratch tested this and from qemu side, it seems to be
>   working.
> * This is an RFC so it lacks some proper error handling in few cases
>   and proper resource freeing. I wanted to get some feedback first
>   before it is finalized.
>
> Command line example:
>
> /home/sameeh/Builds/failover/qemu/x86_64-softmmu/qemu-system-x86_64 \
> -netdev 
> tap,id=hostnet0,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_71 
> \
> -netdev 
> tap,vhost=on,id=hostnet1,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_72,queues=4
>  \
> -device 
> virtio-net,host_mtu=1500,netdev=hostnet1,id=cc1_72,vectors=10,mq=on,primary=cc1_71
>  \
> -device e1000,netdev=hostnet0,id=cc1_71,standby=cc1_72 \
>
> Migration support:
>
> Pre migration or during setup phase of the migration we should send an
> unplug request to the guest to unplug the primary device. I haven't had
> the chance to implement that part yet but should do soon. Do you know
> what's the best approach to do so? I wanted to have a callback to the
> virtio-net device which tries to send an unplug request to the guest and
> if succeeds then the migration continues. It needs to handle the case where
> the migration fails and then it has to replug the primary device back.
I think that the "add_migration_state_change_notifier" API call can be used
from within the virtio-net device to achieve this, what do you think?
>
> The following terms are used as interchangeable:
> standby - virtio-net
> primary - vfio-device - physical device - assigned device
>
> Please share your thoughts and suggestions,
> Thanks!
>
> Sameeh Jubran (2):
>   qdev/qbus: Add hidden device support
>   virtio-net: Implement VIRTIO_NET_F_STANDBY feature
>
>  hw/core/qdev.c | 48 +---
>  hw/net/virtio-net.c| 25 +++
>  hw/pci/pci.c   |  1 +
>  include/hw/pci/pci.h   |  2 ++
>  include/hw/qdev-core.h | 11 ++-
>  include/hw/virtio/virtio-net.h |  5 +++
>  qdev-monitor.c | 58 --
>  7 files changed, 142 insertions(+), 8 deletions(-)
>
> --
> 2.17.0
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



[Qemu-devel] [RFC 1/2] qdev/qbus: Add hidden device support

2018-10-25 Thread Sameeh Jubran
From: Sameeh Jubran 

Signed-off-by: Sameeh Jubran 
---
 hw/core/qdev.c | 48 +++---
 hw/pci/pci.c   |  1 +
 include/hw/pci/pci.h   |  2 ++
 include/hw/qdev-core.h | 11 +++-
 qdev-monitor.c | 58 +++---
 5 files changed, 112 insertions(+), 8 deletions(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 529b82de18..a7c063f6ae 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -77,16 +77,23 @@ static void bus_add_child(BusState *bus, DeviceState *child)
 kid->child = child;
 object_ref(OBJECT(kid->child));
 
-QTAILQ_INSERT_HEAD(>children, kid, sibling);
+if(child->hidden)
+{
+QTAILQ_INSERT_HEAD(>hidden_children, kid, sibling);
+}
+else
+{
+QTAILQ_INSERT_HEAD(>children, kid, sibling);
 
-/* This transfers ownership of kid->child to the property.  */
-snprintf(name, sizeof(name), "child[%d]", kid->index);
-object_property_add_link(OBJECT(bus), name,
+/* This transfers ownership of kid->child to the property.  */
+snprintf(name, sizeof(name), "child[%d]", kid->index);
+object_property_add_link(OBJECT(bus), name,
  object_get_typename(OBJECT(child)),
  (Object **)>child,
  NULL, /* read-only property */
  0, /* return ownership on prop deletion */
  NULL);
+}
 }
 
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
@@ -104,12 +111,38 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 }
 dev->parent_bus = bus;
 object_ref(OBJECT(bus));
+
 bus_add_child(bus, dev);
+
 if (replugging) {
 object_unref(OBJECT(dev));
 }
 }
 
+void qdev_unhide(const char *dev_id, BusState *bus, Error **errp)
+{
+BusChild *kid;
+DeviceState *dev = NULL;
+
+QTAILQ_FOREACH(kid, >hidden_children, sibling) {
+if (!strcmp(kid->child->id,dev_id)) {
+dev = kid->child;
+break;
+}
+}
+
+if (dev && dev->hidden)
+{
+dev->hidden = false;
+QTAILQ_REMOVE(>hidden_children, kid, sibling);
+qdev_set_parent_bus(dev, dev->parent_bus);
+object_property_set_bool(OBJECT(dev), true, "realized", errp);
+if (!errp)
+hotplug_handler_plug(bus->hotplug_handler, dev,
+errp);
+}
+}
+
 /* Create a new device.  This only initializes the device state
structure and allows properties to be set.  The device still needs
to be realized.  See qdev-core.h.  */
@@ -208,6 +241,13 @@ void device_listener_unregister(DeviceListener *listener)
 QTAILQ_REMOVE(_listeners, listener, link);
 }
 
+bool qdev_should_hide_device(const char *dev_id, BusState *bus)
+{
+bool res;
+DEVICE_LISTENER_CALL(should_be_hidden, Forward, dev_id, bus, );
+return res;
+}
+
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
  int required_for_version)
 {
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 80bc45930d..054c22be1e 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -70,6 +70,7 @@ static Property pci_props[] = {
 QEMU_PCIE_LNKSTA_DLLLA_BITNR, true),
 DEFINE_PROP_BIT("x-pcie-extcap-init", PCIDevice, cap_present,
 QEMU_PCIE_EXTCAP_INIT_BITNR, true),
+DEFINE_PROP_STRING("standby", PCIDevice, standby_id_str),
 DEFINE_PROP_END_OF_LIST()
 };
 
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 990d6fcbde..8c0c3e9ef7 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -351,6 +351,8 @@ struct PCIDevice {
 MSIVectorUseNotifier msix_vector_use_notifier;
 MSIVectorReleaseNotifier msix_vector_release_notifier;
 MSIVectorPollNotifier msix_vector_poll_notifier;
+
+char *standby_id_str;
 };
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index f1fd0f8736..dedb84e539 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -143,6 +143,7 @@ struct DeviceState {
 char *canonical_path;
 bool realized;
 bool pending_deleted_event;
+bool hidden;
 QemuOpts *opts;
 int hotplugged;
 BusState *parent_bus;
@@ -156,6 +157,11 @@ struct DeviceState {
 struct DeviceListener {
 void (*realize)(DeviceListener *listener, DeviceState *dev);
 void (*unrealize)(DeviceListener *listener, DeviceState *dev);
+/* This callback is called just upon init of the DeviceState
+ * and can be used by a standby device for informing qdev if this
+ * device should be hidden by cross checking the ids
+ */
+void (*should_be_hidden)(DeviceListener *listener, const char *dev_id, 
BusState *bus, bool *res);
 QTAILQ_ENTRY(DeviceListener

[Qemu-devel] [RFC 0/2] Attempt to implement the standby feature for assigned network devices

2018-10-25 Thread Sameeh Jubran
From: Sameeh Jubran 

Hi all,

Background:

There has been a few attempts to implement the standby feature for vfio
assigned devices which aims to enable the migration of such devices. This
is another attempt.

The series implements an infrastructure for hiding devices from the bus
upon boot. What it does is the following:

* In the first patch the infrastructure for hiding the device is added
  for the qbus and qdev APIs. A "hidden" boolean is added to the device
  state and it is set based on a callback to the standby device which
  registers itself for handling the assessment: "should the primary device
  be hidden?" by cross validating the ids of the devices.

* In the second patch the virtio-net uses the API to hide the vfio
  device and unhides it when the feature is acked.

Disclaimers:

* I have only scratch tested this and from qemu side, it seems to be
  working.
* This is an RFC so it lacks some proper error handling in few cases
  and proper resource freeing. I wanted to get some feedback first
  before it is finalized.

Command line example:

/home/sameeh/Builds/failover/qemu/x86_64-softmmu/qemu-system-x86_64 \
-netdev 
tap,id=hostnet0,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_71 \
-netdev 
tap,vhost=on,id=hostnet1,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_72,queues=4
 \
-device 
virtio-net,host_mtu=1500,netdev=hostnet1,id=cc1_72,vectors=10,mq=on,primary=cc1_71
 \
-device e1000,netdev=hostnet0,id=cc1_71,standby=cc1_72 \

Migration support:

Pre migration or during setup phase of the migration we should send an
unplug request to the guest to unplug the primary device. I haven't had
the chance to implement that part yet but should do soon. Do you know
what's the best approach to do so? I wanted to have a callback to the
virtio-net device which tries to send an unplug request to the guest and
if succeeds then the migration continues. It needs to handle the case where
the migration fails and then it has to replug the primary device back.

The following terms are used as interchangeable:
standby - virtio-net
primary - vfio-device - physical device - assigned device

Please share your thoughts and suggestions,
Thanks!

Sameeh Jubran (2):
  qdev/qbus: Add hidden device support
  virtio-net: Implement VIRTIO_NET_F_STANDBY feature

 hw/core/qdev.c | 48 +---
 hw/net/virtio-net.c| 25 +++
 hw/pci/pci.c   |  1 +
 include/hw/pci/pci.h   |  2 ++
 include/hw/qdev-core.h | 11 ++-
 include/hw/virtio/virtio-net.h |  5 +++
 qdev-monitor.c | 58 --
 7 files changed, 142 insertions(+), 8 deletions(-)

-- 
2.17.0




[Qemu-devel] [RFC 2/2] virtio-net: Implement VIRTIO_NET_F_STANDBY feature

2018-10-25 Thread Sameeh Jubran
From: Sameeh Jubran 

Signed-off-by: Sameeh Jubran 
---
 hw/net/virtio-net.c| 25 +
 include/hw/virtio/virtio-net.h |  5 +
 2 files changed, 30 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index f154756e85..f478445cbd 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -686,6 +686,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, 
uint64_t features)
 {
 VirtIONet *n = VIRTIO_NET(vdev);
 int i;
+Error *err;
 
 if (n->mtu_bypass_backend &&
 !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU)) {
@@ -721,6 +722,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, 
uint64_t features)
 } else {
 memset(n->vlans, 0xff, MAX_VLAN >> 3);
 }
+
+if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) {
+qdev_unhide(n->net_conf.primary_id_str, n->primary_parent_bus, );
+}
 }
 
 static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
@@ -1946,6 +1951,20 @@ void virtio_net_set_netclient_name(VirtIONet *n, const 
char *name,
 n->netclient_type = g_strdup(type);
 }
 
+static void virtio_net_primary_should_be_hidden(DeviceListener *listener,const 
char *dev_id, BusState *bus, bool *res)
+{
+   VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
+if (!strcmp(n->net_conf.primary_id_str ,dev_id) && bus)
+{
+printf("net_confnet_confnet_confnet_confnet_conf\n");
+n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY);
+n->primary_parent_bus = bus;
+*res = true;
+return;
+}
+*res = false;
+}
+
 static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 {
 VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1976,6 +1995,11 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
 n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
 }
 
+if (n->net_conf.primary_id_str) {
+n->primary_listener.should_be_hidden = 
virtio_net_primary_should_be_hidden;
+device_listener_register(>primary_listener);
+}
+
 virtio_net_set_config_size(n, n->host_features);
 virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
 
@@ -2198,6 +,7 @@ static Property virtio_net_properties[] = {
  true),
 DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN),
 DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
+DEFINE_PROP_STRING("primary", VirtIONet, net_conf.primary_id_str),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 4d7f3c82ca..6aca93e461 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -42,6 +42,7 @@ typedef struct virtio_net_conf
 int32_t speed;
 char *duplex_str;
 uint8_t duplex;
+char *primary_id_str;
 } virtio_net_conf;
 
 /* Maximum packet size we can receive from tap device: header + 64k */
@@ -103,9 +104,13 @@ typedef struct VirtIONet {
 int announce_counter;
 bool needs_vnet_hdr_swap;
 bool mtu_bypass_backend;
+BusState *primary_parent_bus;
+DeviceListener primary_listener;
 } VirtIONet;
 
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
const char *type);
+void virtio_net_register_primary_device(DeviceState *vdev, DeviceState *pdev);
+
 
 #endif
-- 
2.17.0




Re: [Qemu-devel] Hotplug handler

2018-10-08 Thread Sameeh Jubran
Thanks for your help, turns out that the hotlpug is set by piix4 after
the devices are realized.
On Mon, Oct 8, 2018 at 11:28 AM Igor Mammedov  wrote:
>
> On Sun, 7 Oct 2018 12:52:11 +0300
> Sameeh Jubran  wrote:
>
> > This is the command line. All of the devices are wired to pci.0, there is
> > no pci bridge.
> >
> > According to this,  Integrated Endpoints are not hot-pluggable. However I
> > can still use device_del to delete a device and device_add to add e1000
> > with no issues.
> > https://github.com/qemu/qemu/blob/master/docs/pcie.txt#L37
> Your CLI is using default 'pc' machine so it's conventional PCI (not PCI-E),
> with that CLI for a device plugged into pci.0 bus you should get piix4_pm as
> hotplug handler (ACPI is used on pci.0 as default).
> To troubleshoot your issue, you might look at code that's
> using following symbols:
>
>   use_acpi_pci_hotplug
>   piix4_update_bus_hotplug
>   piix4_device_plug_cb
>   piix4_device_unplug_request_cb
>
> >
> > qemu-system-x86_64 \
> > -device
> > e1000,netdev=hostnet0,mac=56:cc:c1:01:cc:21,id=cc1_71,primary=cc1_72 \
> > -netdev
> > tap,vhost=on,id=hostnet1,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_72,queues=4
> > \
> > -device
> > virtio-net,host_mtu=1500,netdev=hostnet1,mac=56:cc:c1:04:2c:21,id=cc1_72,vectors=10,mq=on,standby=cc1_71
> > \
> > -netdev
> > tap,id=hostnet0,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_71
> > \
> > -enable-kvm \
> > -name netkvm \
> > -m 1000M \
> > -snapshot \
> > -smp 4 \
> > -drive file=windows_10_enterprise_x64_netkvm_dev.qcow2,if=ide,id=drivex \
> > -global PIIX4_PM.disable_s3=0 \
> > -global PIIX4_PM.disable_s4=0 \
> > -usbdevice tablet \
> > -vga qxl \
> > -spice port=6110,disable-ticketing \
> > -device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x7
> > \
> > -chardev spicevmc,name=vdagent,id=vdagent \
> > -device
> > virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0
> > \
> > -chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
> > -device virtio-serial \
> > -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
> > -monitor stdio
> >
> >
> > On Thu, Oct 4, 2018 at 2:20 PM Igor Mammedov  wrote:
> >
> > > On Wed, 3 Oct 2018 19:50:58 +0300
> > > Sameeh Jubran  wrote:
> > >
> > > > Hi all,
> > > >
> > > > I am trying to get the hotplug handler of a pci device in Qemu using
> > > > "qdev_get_hotplug_handler" function. This function simply tries to get
> > > > the hotplug handler from the parent bus. For some reason it's always
> > > > null. Why it is not initialized?
> > > >
> > > > Thanks!
> > > >
> > >
> > > what's used qemu command line?
> > >
> >
> >
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [PATCH v4 09/11] qga-win: handle multi-disk volumes

2018-10-07 Thread Sameeh Jubran
isk_h);
>  return;
>  }
>
> @@ -712,6 +728,10 @@ static GuestDiskAddressList
> *build_guest_disk_info(char *guid, Error **errp)
>  Error *local_err = NULL;
>  GuestDiskAddressList *list = NULL, *cur_item = NULL;
>  GuestDiskAddress *disk = NULL;
> +int i;
> +HANDLE vol_h;
> +DWORD size;
> +PVOLUME_DISK_EXTENTS extents = NULL;
>
>  /* strip final backslash */
>  char *name = g_strdup(guid);
> @@ -719,19 +739,89 @@ static GuestDiskAddressList
> *build_guest_disk_info(char *guid, Error **errp)
>  name[strlen(name) - 1] = 0;
>  }
>
> -disk = g_malloc0(sizeof(GuestDiskAddress));
> -get_single_disk_info(name, disk, _err);
> -if (local_err) {
> -error_propagate(errp, local_err);
> +g_debug("opening %s", name);
> +vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
> +   0, NULL);
> +if (vol_h == INVALID_HANDLE_VALUE) {
> +error_setg_win32(errp, GetLastError(), "failed to open volume");
>  goto out;
>  }
>
> -cur_item = g_malloc0(sizeof(*list));
> -cur_item->value = disk;
> -disk = NULL;
> -list = cur_item;
> +/* Get list of extents */
> +g_debug("getting disk extents");
> +size = sizeof(VOLUME_DISK_EXTENTS);
> +extents = g_malloc0(size);
> +if (!DeviceIoControl(vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
> NULL,
> + 0, extents, size, NULL, NULL)) {
> +DWORD last_err = GetLastError();
> +if (last_err == ERROR_MORE_DATA) {
> +/* Try once more with big enough buffer */
> +size = sizeof(VOLUME_DISK_EXTENTS)
> ++ extents->NumberOfDiskExtents*sizeof(DISK_EXTENT);
> +g_free(extents);
> +extents = g_malloc0(size);
> +if (!DeviceIoControl(
> +vol_h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL,
> +0, extents, size, NULL, NULL)) {
> +error_setg_win32(errp, GetLastError(),
> +"failed to get disk extents");
> +return NULL;
> +}
> +} else if (last_err == ERROR_INVALID_FUNCTION) {
> +/* Possibly CD-ROM or a shared drive. Try to pass the volume
> */
> +g_debug("volume not on disk");
> +disk = g_malloc0(sizeof(GuestDiskAddress));
> +get_single_disk_info(name, disk, _err);
> +if (local_err) {
> +g_debug("failed to get disk info, ignoring error: %s",
> +error_get_pretty(local_err));
> +error_free(local_err);
> +goto out;
> +}
> +list = g_malloc0(sizeof(*list));
> +list->value = disk;
> +disk = NULL;
> +list->next = NULL;
> +goto out;
> +} else {
> +error_setg_win32(errp, GetLastError(),
> +"failed to get disk extents");
> +goto out;
> +}
> +}
> +g_debug("Number of extents: %lu", extents->NumberOfDiskExtents);
> +
> +/* Go through each extent */
> +for (i = 0; i < extents->NumberOfDiskExtents; i++) {
> +char *disk_name = NULL;
> +disk = g_malloc0(sizeof(GuestDiskAddress));
> +
> +/* Disk numbers directly correspond to numbers used in UNCs
> + *
> + * See documentation for DISK_EXTENT:
> + *
> https://docs.microsoft.com/en-us/windows/desktop/api/winioctl/ns-winioctl-_disk_extent
> +     *
> + * See also Naming Files, Paths and Namespaces:
> + *
> https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#win32-device-namespaces
> + */
> +disk_name = g_strdup_printf(".\\PhysicalDrive%lu",
> +extents->Extents[i].DiskNumber);
> +get_single_disk_info(disk_name, disk, _err);
> +g_free(disk_name);
> +if (local_err) {
> +error_propagate(errp, local_err);
> +goto out;
> +}
> +cur_item = g_malloc0(sizeof(*list));
> +cur_item->value = disk;
> +disk = NULL;
> +cur_item->next = list;
> +list = cur_item;
> +}
> +
>
>  out:
> +g_free(extents);
>  g_free(disk);
>  g_free(name);
>
> --
> 2.19.0
>
>
>

-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v4 11/11] qga-win: demystify namespace striping

2018-10-07 Thread Sameeh Jubran
+1, this is much clearer.
On Thu, Oct 4, 2018 at 4:34 PM Marc-André Lureau
 wrote:
>
> Hi
>
> On Thu, Oct 4, 2018 at 3:22 PM Tomáš Golembiovský  wrote:
> >
> > It was not obvious what exactly the cryptic string copying does to the
> > GUID. This change makes the intent clearer.
> >
> > Signed-off-by: Tomáš Golembiovský 
>
> Reviewed-by: Marc-André Lureau 
>
> > ---
> >  qga/commands-win32.c | 9 -
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> > index d0d969d0ce..82881aa749 100644
> > --- a/qga/commands-win32.c
> > +++ b/qga/commands-win32.c
> > @@ -507,7 +507,14 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
> > **errp)
> >  char dev_name[MAX_PATH];
> >  char *buffer = NULL;
> >  GuestPCIAddress *pci = NULL;
> > -char *name = g_strdup([4]);
> > +char *name = NULL;
> > +
> > +if ((g_str_has_prefix(guid, ".\\") == TRUE) ||
> > +(g_str_has_prefix(guid, "?\\") == TRUE)) {
> > +name = g_strdup([4]);
>
> I find "guid + 4" easier to read though
>
> > +} else {
> > +name = g_strdup(guid);
> > +}
> >
> >  if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) {
> >  error_setg_win32(errp, GetLastError(), "failed to get dos device 
> > name");
> > --
> > 2.19.0
> >
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] Hotplug handler

2018-10-07 Thread Sameeh Jubran
This is the command line. All of the devices are wired to pci.0, there is
no pci bridge.

According to this,  Integrated Endpoints are not hot-pluggable. However I
can still use device_del to delete a device and device_add to add e1000
with no issues.
https://github.com/qemu/qemu/blob/master/docs/pcie.txt#L37

qemu-system-x86_64 \
-device
e1000,netdev=hostnet0,mac=56:cc:c1:01:cc:21,id=cc1_71,primary=cc1_72 \
-netdev
tap,vhost=on,id=hostnet1,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_72,queues=4
\
-device
virtio-net,host_mtu=1500,netdev=hostnet1,mac=56:cc:c1:04:2c:21,id=cc1_72,vectors=10,mq=on,standby=cc1_71
\
-netdev
tap,id=hostnet0,script=world_bridge_standalone.sh,downscript=no,ifname=cc1_71
\
-enable-kvm \
-name netkvm \
-m 1000M \
-snapshot \
-smp 4 \
-drive file=windows_10_enterprise_x64_netkvm_dev.qcow2,if=ide,id=drivex \
-global PIIX4_PM.disable_s3=0 \
-global PIIX4_PM.disable_s4=0 \
-usbdevice tablet \
-vga qxl \
-spice port=6110,disable-ticketing \
-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x7
\
-chardev spicevmc,name=vdagent,id=vdagent \
-device
virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0
\
-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
-monitor stdio


On Thu, Oct 4, 2018 at 2:20 PM Igor Mammedov  wrote:

> On Wed, 3 Oct 2018 19:50:58 +0300
> Sameeh Jubran  wrote:
>
> > Hi all,
> >
> > I am trying to get the hotplug handler of a pci device in Qemu using
> > "qdev_get_hotplug_handler" function. This function simply tries to get
> > the hotplug handler from the parent bus. For some reason it's always
> > null. Why it is not initialized?
> >
> > Thanks!
> >
>
> what's used qemu command line?
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v4 03/11] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI

2018-10-07 Thread Sameeh Jubran
Reviewed-by: Sameeh Jubran 
On Thu, Oct 4, 2018 at 4:23 PM Marc-André Lureau
 wrote:
>
> Hi
>
> On Thu, Oct 4, 2018 at 3:22 PM Tomáš Golembiovský  wrote:
> >
> > There was inconsistency between commits:
> >
> >   50cbebb9a3 configure: add configure check for ntdddisk.h
> >   a3ef3b2272 qga: added bus type and disk location path
> >
> > The first commit added #define CONFIG_QGA_NTDDDISK but the second commit
> > expected the name to be CONFIG_QGA_NTDDSCSI. As a result the code in
> > second patch was never used.
> >
> > Renaming the option to CONFIG_QGA_NTDDSCSI to match the name of header
> > file that is being checked for.
> >
> > Signed-off-by: Tomáš Golembiovský 
>
> Reviewed-by: Marc-André Lureau 
>
> > ---
> >  configure | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/configure b/configure
> > index 58862d2ae8..0f168607e8 100755
> > --- a/configure
> > +++ b/configure
> > @@ -6201,7 +6201,7 @@ if test "$mingw32" = "yes" ; then
> >  echo "WIN_SDK=\"$win_sdk\"" >> $config_host_mak
> >fi
> >if test "$guest_agent_ntddscsi" = "yes" ; then
> > -echo "CONFIG_QGA_NTDDDISK=y" >> $config_host_mak
> > +echo "CONFIG_QGA_NTDDSCSI=y" >> $config_host_mak
> >fi
> >if test "$guest_agent_msi" = "yes"; then
> >  echo "QEMU_GA_MSI_ENABLED=yes" >> $config_host_mak
> > --
> > 2.19.0
> >
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



[Qemu-devel] Hotplug handler

2018-10-03 Thread Sameeh Jubran
Hi all,

I am trying to get the hotplug handler of a pci device in Qemu using
"qdev_get_hotplug_handler" function. This function simply tries to get
the hotplug handler from the parent bus. For some reason it's always
null. Why it is not initialized?

Thanks!



Re: [Qemu-devel] [PATCH v3 1/5] qga: win32: fix crashes when PCI info cannot be retrived

2018-09-27 Thread Sameeh Jubran
On Thu, Sep 27, 2018 at 12:06 PM Tomáš Golembiovský 
wrote:

> Hi Michael,
>
> thanks for looking into this. My comments are below.
>
> Adding Sameeh...
>
>
> On Wed, 26 Sep 2018 12:15:48 -0500
> Michael Roth  wrote:
>
> > Quoting Tomáš Golembiovský (2018-09-07 06:42:09)
> > > The guest-get-fsinfo command collects also information about PCI
> > > controller where the disk is attached. When this fails for some reasons
> > > it tries to return just the partial information. However in certain
> > > cases the pointer to the structure was not initialized and was set to
> > > NULL. This breaks the serializer and leads to a crash of the guest
> agent.
> > >
> > > Signed-off-by: Tomáš Golembiovský 
> >
> > For a win10 guest started with:
> >
> > qemu-system-x86_64 -m 2G -smp 2,cores=2,sockets=1 -drive
> file=/home/mdroth/vm/win10_pro_n_snap0.qcow2,if=virtio -drive
> file=/home/mdroth/vm/virtio-win-0.1.102.iso,if=ide,media=cdrom -rtc
> base=localtime,driftfix=slew -vga std -boot d -name vm4 -netdev
> tap,script=/etc/qemu-ifup,vhost=on,id=vnet0 -device
> virtio-net-pci,mac=52:54:00:12:34:04,id=vnic0,netdev=vnet0,disable-modern=true
> -vnc :4 -device virtio-serial -balloon virtio -mon chardev=hmp0 -chardev
> socket,path=/tmp/vm4-hmp0.sock,server,nowait,id=hmp0 -mon
> chardev=qmp0,mode=control -chardev
> socket,path=/tmp/vm4-qmp0.sock,server,nowait,id=qmp0 -device
> virtserialport,chardev=vs0,name=vs0,id=vs_vs0 -chardev
> socket,path=/tmp/vm4-vs0.sock,server,nowait,id=vs0 -device
> virtserialport,chardev=vs1,name=vs1,id=vs_vs1 -chardev
> socket,path=/tmp/vm4-vs1.sock,server,nowait,id=vs1 -device
> virtserialport,chardev=qga,name=org.qemu.guest_agent.0,id=vs_qga -chardev
> socket,path=/tmp/vm4-qga.sock,server,nowait,id=qga -device
> isa-serial,chardev=serial0,id=serial_serial0 -chardev
> socket,path=/tmp/vm4-serial0.sock,server,nowait,id=serial0 -L
> /home/mdroth/w/build/qemu-2.11.2-build/pc-bios --enable-kvm
> >
> > this yields the following:
> >
> > {'execute':'guest-get-fsinfo'}
> > {"return": [{"name":
> "?\\Volume{83835b2d-0032-11e6-a84f-806e6f6e6963}\\", "total-bytes":
> 160755712, "mountpoint": "D:\\", "disk": [{"bus-type": "ide", "bus": 0,
> "unit": 0, "pci-controller": {"bus": 0, "slot": 0, "domain": 0, "function":
> 0}, "target": 0}], "used-bytes": 160755712, "type": "CDFS"}, {"name":
> "?\\Volume{2ea839c6----80620c00}\\", "mountpoint":
> "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0, "unit": 0,
> "pci-controller": {"bus": 0, "slot": 0, "domain": 0, "function": 0},
> "target": 0}], "type": "NTFS"}, {"name":
> "?\\Volume{2ea839c6----501f}\\", "total-bytes":
> 52665839616, "mountpoint": "C:\\", "disk": [{"bus-type": "scsi", "bus": 0,
> "unit": 0, "pci-controller": {"bus": 0, "slot": 0, "domain": 0, "function":
> 0}, "target": 0}], "used-bytes": 25265487872, "type": "NTFS"}, {"name":
> "?\\Volume{2ea839c6----1000}\\", "mountpoint":
> "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0, "unit": 0,
> "pci-controller": {"bus": 0, "slot": 0, "domain": 0, "function": 0},
> "target": 0}], "type": "NTFS"}]}
> >
> > domain/bus/slot/function=0 are valid PCI addresses so initializing to 0
> is
> > wrong. Sameeh had a previous series that initializes to -1 that I think
> > is more appropriate (it hasn't gone in yet since we opted not to enable
> > CONFIG_QGA_NTDDSCSI for 3.0 since the PCI stuff seems be generally
> > broken for Windows, also because the 2nd patch needs some fixups:
>
Can you please elaborate? What kind of fixups? I can see no comments of
this in the 2nd patch

> >
> >   https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg07500.html
>
> I wasn't aware of that. I is trying to "fix" the same issue.
>
> I've been also thinking about using -1, but I didn't know what is/isn't
> correct PCI address.
>
> >
> > With that series (and some fixups I have on top at
> > https://github.com/mdroth/qemu/commits/qga-test), we get the following
> > output:
>
> Should I rebase on that and drop my patch?
>
> >
> > {'execute':'guest-get-fsinfo'}
> > {"return": [{"name":
> "?\\Volume{83835b2d-0032-11e6-a84f-806e6f6e6963}\\", "total-bytes":
> 160755712, "mountpoint": "D:\\", "disk": [{"bus-type": "ide", "bus": 0,
> "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": -1,
> "function": -1}, "target": 0}], "used-bytes": 160755712, "type": "CDFS"},
> {"name": "?\\Volume{2ea839c6----80620c00}\\",
> "mountpoint": "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0,
> "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": 0,
> "function": 3}, "target": 0}], "type": "NTFS"}, {"name":
> "?\\Volume{2ea839c6----501f}\\", "total-bytes":
> 52665839616, "mountpoint": "C:\\", "disk": [{"bus-type": "scsi", "bus": 0,
> "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": 0,
> "function": 2}, "target": 0}], "used-bytes": 25267560448, "type": "NTFS"},
> {"name": 

[Qemu-devel] Converting PCIDevice to VirtIODevice

2018-09-26 Thread Sameeh Jubran
Hi All,

I have used the function "pci_qdev_find_device" to find a device using
it's id. This is a virtio device and I'm trying to convert it to
VirtIODevice.

What's the best way to do this? Simply converting it to DeviceState
doesn't work and I think I should access the underlying virtio pci bus
and through it access the virtio-device, but couldn't find any elegant
way of doing so.

Thanks!



Re: [Qemu-devel] [Bug 1791947] Re: isochronous usb device forwarding with windows 10 and xhci freezes

2018-09-25 Thread Sameeh Jubran
How exactly do you use USB redirection: via virt-manager or via spice
client (like remote viewer)?
If via spice-client, on which OS the client runs? In this case running
it with --spice-debug and collecting logs from stdio and stderr could
be helpful.
Can you also provide a usbpcap capture of the usb device's traffic
from within the VM?
On Fri, Sep 21, 2018 at 12:51 PM Florian Kaiser
<1791...@bugs.launchpad.net> wrote:
>
> How to reproduce:
> 1. download windows 10 iso april 2018 from here:
>   
> https://www.microsoft.com/en-us/software-download/windows10ISO?NavToggle=True
> 2. create a VM with virtmanager with q35 chipset and configure two usb 
> redirect devices
> (3. modify xml to use an xhci controller)
> 4. Install windows
> 5. redirect a usb soundcard or a usb headset into the VM
> 5. play some video and observe that it freezes after some time (1-20 mins)
>
> --
> You received this bug notification because you are a member of qemu-
> devel-ml, which is subscribed to QEMU.
> https://bugs.launchpad.net/bugs/1791947
>
> Title:
>   isochronous usb device forwarding with windows 10 and xhci freezes
>
> Status in QEMU:
>   New
>
> Bug description:
>   When I try to forward isochronous usb devices (webcam, HID-Audio) via 
> usbredir into the VM, the devices work for a few minutes then the device 
> stops working and stays that way until a VM reboot or a windows driver reload.
>   It does not matter if I use qemu-xhci or nec-xhci.
>   I can gather more information, if its helpful!
>
>   Windows build:
>   windows 10 pro 1803 jun 2018
>
>   Linux Version:
>   Fedora 28
>   $ uname -a
>   Linux 4.17.19-200.fc28.x86_64 #1 SMP Fri Aug 24 15:47:41 UTC 2018 x86_64 
> x86_64 x86_64 GNU/Linux
>
>   Qemu Version:
>   $ qemu-system-x86_64 -version
>   QEMU emulator version 2.11.2(qemu-2.11.2-2.fc28)
>   Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
>
>   Qemu command line:
>   /usr/bin/qemu-system-x86_64 -machine accel=kvm -name 
> guest=win10,debug-threads=on -S -object 
> secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-win10/master-key.aes
>  -machine pc-q35-2.11,accel=kvm,usb=off,vmport=off,dump-guest-core=off -cpu 
> Skylake-Client-IBRS,ss=on,hypervisor=on,tsc_adjust=on,clflushopt=on,ssbd=on,xsaves=on,pdpe1gb=on,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff
>  -m 8192 -realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid 
> 38b1258e-fea4-41fe-9e21-07c426c5b2b2 -no-user-config -nodefaults -chardev 
> socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-1-win10/monitor.sock,server,nowait
>  -mon chardev=charmonitor,id=monitor,mode=control -rtc 
> base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet 
> -no-shutdown -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 
> -boot strict=on -device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e 
> -device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 -device 
> pcie-root-port,port=0x10,chassis=3,id=pci.3,bus=pcie.0,multifunction=on,addr=0x2
>  -device pcie-root-port,port=0x11,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x1 
> -device pcie-root-port,port=0x12,chassis=5,id=pci.5,bus=pcie.0,addr=0x2.0x2 
> -device pcie-root-port,port=0x13,chassis=6,id=pci.6,bus=pcie.0,addr=0x2.0x3 
> -device qemu-xhci,id=usb,bus=pci.3,addr=0x0 -device 
> virtio-serial-pci,id=virtio-serial0,bus=pci.4,addr=0x0 -drive 
> file=/var/lib/libvirt/images/win10.qcow2,format=qcow2,if=none,id=drive-sata0-0-0
>  -device ide-hd,bus=ide.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1 
> -drive 
> file=/var/lib/libvirt/images/en_windows_10_multiple_editions_version_1803_jun_2018.iso,format=raw,if=none,id=drive-sata0-0-1,media=cdrom,readonly=on
>  -device ide-cd,bus=ide.1,drive=drive-sata0-0-1,id=sata0-0-1 -netdev 
> tap,fd=25,id=hostnet0 -device 
> e1000,netdev=hostnet0,id=net0,mac=52:54:00:ab:33:11,bus=pci.2,addr=0x1 
> -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 
> -chardev spicevmc,id=charchannel0,name=vdagent -device 
> virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0
>  -device usb-tablet,id=input0,bus=usb.0,port=1 -spice 
> port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on
>  -device 
> qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pcie.0,addr=0x1
>  -chardev spicevmc,id=charredir0,name=usbredir -device 
> usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=2 -chardev 
> spicevmc,id=charredir1,name=usbredir -device 
> usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=3 -device 
> virtio-balloon-pci,id=balloon0,bus=pci.5,addr=0x0 -msg timestamp=on
>
>   Cheers,
>   Florian
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qemu/+bug/1791947/+subscriptions
>


-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 6/6] virtio-net: rss: Add bpf filter

2018-09-03 Thread Sameeh Jubran
> I may miss something, but it looks to me the indirection table should be 
> implemented through a map as well? Since it was accessible by guest and qemu 
> need to trap the access and convert it to eBPF map updating?
makes  sense, I'll convert it to map structure.


> This looks tricky as well, should we search the BPF_LD and replace the imm?
Hmm yes this approach is better I guess.

> I believe those bpf helpers should be moved to tap-linux.c.
All of them?  I actually thought about moving them to a standalone
file in the virtio-net.c dir.
Can you explain the motive for this?

> So vhost_net_get_fd() did nothing in fact?
You are correct, I'm dropping it

> STEERING BPF is per device not per queue, so setting this for queue 0 should 
> be ok.
Oh, okay will do.


On Mon, Sep 3, 2018 at 7:12 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>   hw/net/rss_bpf_insns.h   | 3992
>> ++
>>   hw/net/rss_tap_bpf.h |   40 +
>>   hw/net/rss_tap_bpf_program.c |  175 ++
>>   hw/net/virtio-net.c  |   99 +-
>>   4 files changed, 4305 insertions(+), 1 deletion(-)
>>   create mode 100644 hw/net/rss_bpf_insns.h
>>   create mode 100644 hw/net/rss_tap_bpf.h
>>   create mode 100644 hw/net/rss_tap_bpf_program.c
>>
>> diff --git a/hw/net/rss_bpf_insns.h b/hw/net/rss_bpf_insns.h
>> new file mode 100644
>> index 00..1a92110b8d
>> --- /dev/null
>> +++ b/hw/net/rss_bpf_insns.h
>> @@ -0,0 +1,3992 @@
>> +/*
>> + * RSS ebpf instructions for virtio-net
>> + *
>> + * Copyright (c) 2018 RedHat.
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or
>> later.
>> + * See the COPYING file in the top-level directory.
>> + *
>> + */
>> +
>> +#include 
>> +
>> +#ifndef BPF_RSS_INSNS
>> +#define BPF_RSS_INSNS
>> +
>> +/* bpf_insn array matching l3_l4 section. see tap_bpf_program.c file */
>> +struct bpf_insn l3_l4_hash_insns[] = {
>> +{0xbf , 0x6 , 0x1 , 0x , 0x},
>> +{0x28 , 0x0 , 0x0 , 0x , 0x000c},
>> +{0xbf , 0x8 , 0x0 , 0x , 0x},
>> +{0x18 , 0x1 , 0x0 , 0x , 0xdeadbeef},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x},
>> +{0x63 , 0xa , 0x1 , 0xfffc , 0x},
>> +{0xbf , 0x2 , 0xa , 0x , 0x},
>> +{0x07 , 0x2 , 0x0 , 0x , 0xfffc},
>> +{0x18 , 0x1 , 0x1 , 0x , 0xdeadcafe},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x},
>> +{0x85 , 0x0 , 0x0 , 0x , 0x0001},
>> +{0x55 , 0x0 , 0x0 , 0x0017 , 0x},
>> +{0xb7 , 0x1 , 0x0 , 0x , 0x},
>> +{0x73 , 0xa , 0x1 , 0xfffa , 0x},
>> +{0xb7 , 0x1 , 0x0 , 0x , 0x0a64},
>> +{0x6b , 0xa , 0x1 , 0xfff8 , 0x},
>> +{0x18 , 0x1 , 0x0 , 0x , 0x69666e6f},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x65727567},
>> +{0x7b , 0xa , 0x1 , 0xfff0 , 0x},
>> +{0x18 , 0x1 , 0x0 , 0x , 0x6e207369},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x6320746f},
>> +{0x7b , 0xa , 0x1 , 0xffe8 , 0x},
>> +{0x18 , 0x1 , 0x0 , 0x , 0x20737372},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x2079656b},
>> +{0x7b , 0xa , 0x1 , 0xffe0 , 0x},
>> +{0x18 , 0x1 , 0x0 , 0x , 0x68736168},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x203a2928},
>> +{0x7b , 0xa , 0x1 , 0xffd8 , 0x},
>> +{0xbf , 0x1 , 0xa , 0x , 0x},
>> +{0x07 , 0x1 , 0x0 , 0x , 0xffd8},
>> +{0xb7 , 0x2 , 0x0 , 0x , 0x0023},
>> +{0x85 , 0x0 , 0x0 , 0x , 0x0006},
>> +{0x18 , 0x0 , 0x0 , 0x , 0xfffe},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x},
>> +{0x05 , 0x0 , 0x0 , 0x0f60 , 0x},
>> +{0x7b , 0xa , 0x0 , 0xffc8 , 0x},
>> +{0xb7 , 0x7 , 0x0 , 0x , 0x000e},
>> +{0x55 , 0x8 , 0x0 , 0x0003 , 0x88a8},
>> +{0xb7 , 0x7 , 0x0 , 0x , 0x0012},
>> +{0x28 , 0x0 , 0x0 , 0x , 0x0010},
>> +{0xbf , 0x8 , 0x0 , 0x , 0x},
>> +{0x55 , 0x8 , 0x0 , 0x0005 , 0x8100},
>> +{0xbf , 0x8 , 0x7 , 0x , 0x},
>> +{0x07 , 0x8 , 0x0 , 0x , 0x0002},
>> +{0x48 , 0x0 , 0x8 , 0x , 0x},
>> +{0xbf , 0x8 , 0x0 , 0x , 0x},
>> +{0x07 , 0x7 , 0x0 , 0x , 0x0004},
>> +{0x15 , 0x8 , 0x0 , 0x0b48 , 0x0800},
>> +{0x18 , 0x0 , 0x0 , 0x , 0x},
>> +{0x00 , 0x0 , 0x0 , 0x , 0x},
>> +{0x15 , 0x8 , 0x0 , 0x0001 , 0xdd86},
>> +{0x05 , 0x0 , 0x0 , 0x0f4f , 0x},
>> +{0xbf 

Re: [Qemu-devel] [RFC 4/6] virtio-net: implement steering mode feature

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 6:34 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>   hw/net/virtio-net.c | 65
>> +
>>   include/hw/virtio/virtio-net.h  |  3 ++
>>   include/standard-headers/linux/virtio_net.h | 55
>> 
>>   3 files changed, 116 insertions(+), 7 deletions(-)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index 90502fca7c..e7c4ce6f66 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -972,13 +972,53 @@ static int virtio_net_handle_mq(VirtIONet *n,
>> uint8_t cmd,
>>   return VIRTIO_NET_OK;
>>   }
>>   +static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
>> +struct iovec *iov, unsigned int iov_cnt,
>> +struct iovec *iov_in, unsigned int
>> iov_cnt_in,
>> +size_t *size_in)
>> +{
>> +size_t s;
>> +struct virtio_net_steering_mode sm;
>> +
>> +switch (cmd) {
>> +case VIRTIO_NET_CTRL_SM_GET_SUPPORTED_MODES:
>> +if (!size_in) {
>> +return VIRTIO_NET_ERR;
>> +}
>> +  s = iov_from_buf(iov_in, iov_cnt_in, 0,
>> +  >supported_modes, sizeof(n->supported_modes));
>> +if (s != sizeof(n->supported_modes) ||
>> +  !size_in) {
>
>
> size_in has been checked in the above I think?
true
>
>
>> +return VIRTIO_NET_ERR;
>> +}
>> +  *size_in = s;
>> +  break;
>> +case VIRTIO_NET_CTRL_SM_CONTROL:
>> +s = iov_to_buf(iov, iov_cnt, 0, , sizeof(sm) -
>> +sizeof(union command_data));
>> +if (s != sizeof(sm) - sizeof(union command_data)) {
>> +return VIRTIO_NET_ERR;
>> +}
>> +/* switch (cmd)
>> + {
>> +dafault:
>> +return VIRTIO_NET_ERR;
>> + } */
>> +  break;
>> +default:
>> +return VIRTIO_NET_ERR;
>> +}
>> +
>> +return VIRTIO_NET_OK;
>> +}
>> +
>>   static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
>>   {
>>   VirtIONet *n = VIRTIO_NET(vdev);
>>   struct virtio_net_ctrl_hdr ctrl;
>>   virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
>>   VirtQueueElement *elem;
>> -size_t s;
>> +size_t s, elem_in_size = 0;
>>   struct iovec *iov, *iov2;
>>   unsigned int iov_cnt;
>>   @@ -996,7 +1036,8 @@ static void virtio_net_handle_ctrl(VirtIODevice
>> *vdev, VirtQueue *vq)
>>   }
>> iov_cnt = elem->out_num;
>> -iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) *
>> elem->out_num);
>> +iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) *
>> +elem->out_num);
>
>
> Still looks unnecessary.
true
>
>
>>   s = iov_to_buf(iov, iov_cnt, 0, , sizeof(ctrl));
>>   iov_discard_front(, _cnt, sizeof(ctrl));
>>   if (s != sizeof(ctrl)) {
>> @@ -1013,12 +1054,20 @@ static void virtio_net_handle_ctrl(VirtIODevice
>> *vdev, VirtQueue *vq)
>>   status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
>>   } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
>>   status = virtio_net_handle_offloads(n, ctrl.cmd, iov,
>> iov_cnt);
>> +} else if (ctrl.class == VIRTIO_NET_CTRL_STEERING_MODE) {
>> +size_t size_in = 0;
>> +status = virtio_net_ctrl_steering_mode(n, ctrl.cmd, iov,
>> iov_cnt,
>> +   elem->in_sg, elem->in_num, _in);
>> +if (status == VIRTIO_NET_OK  && size_in > 0) {
>> +elem_in_size += size_in;
>> +}
>>   }
>>   -s = iov_from_buf(elem->in_sg, elem->in_num, 0, ,
>> sizeof(status));
>> +s = iov_from_buf(elem->in_sg, elem->in_num, elem_in_size,
>> ,
>> +sizeof(status));
>>   assert(s == sizeof(status));
>> -
>> -virtqueue_push(vq, elem, sizeof(status));
>> +elem_in_size += s;
>> +virtqueue_push(vq, elem, elem_in_size);
>>   virtio_notify(vdev, vq);
>>   g_free(iov2);
>>   g_free

Re: [Qemu-devel] [RFC 6/6] virtio-net: rss: Add bpf filter

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 2:54 PM, Daniel P. Berrangé  wrote:
> On Thu, Aug 30, 2018 at 05:27:08PM +0300, Sameeh Jubran wrote:
>> From: Sameeh Jubran 
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>  hw/net/rss_bpf_insns.h   | 3992 
>> ++
>>  hw/net/rss_tap_bpf.h |   40 +
>>  hw/net/rss_tap_bpf_program.c |  175 ++
>>  hw/net/virtio-net.c  |   99 +-
>>  4 files changed, 4305 insertions(+), 1 deletion(-)
>>  create mode 100644 hw/net/rss_bpf_insns.h
>>  create mode 100644 hw/net/rss_tap_bpf.h
>>  create mode 100644 hw/net/rss_tap_bpf_program.c
>>
>> diff --git a/hw/net/rss_bpf_insns.h b/hw/net/rss_bpf_insns.h
>> new file mode 100644
>> index 00..1a92110b8d
>> --- /dev/null
>> +++ b/hw/net/rss_bpf_insns.h
>> @@ -0,0 +1,3992 @@
>> +/*
>> + * RSS ebpf instructions for virtio-net
>> + *
>> + * Copyright (c) 2018 RedHat.
>
> Why copyright RedHat ?
>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + *
>> + */
>> +
>> +#include 
>> +
>> +#ifndef BPF_RSS_INSNS
>> +#define BPF_RSS_INSNS
>> +
>> +/* bpf_insn array matching l3_l4 section. see tap_bpf_program.c file */
>> +struct bpf_insn l3_l4_hash_insns[] = {
>> +{0xbf , 0x6 , 0x1 , 0x , 0x},
>> +{0x28 , 0x0 , 0x0 , 0x , 0x000c},
>> +{0xbf , 0x8 , 0x0 , 0x , 0x},
>
> [snip]
>
>> +};
>
> This massive array is presumably an auto-generated content.
>
> We shouldn't be storing this in GIT. We need to store the
> original preferred source format, and providing makefile
> rules to generate it.
>
>
>> +
>> +#endif
>> diff --git a/hw/net/rss_tap_bpf.h b/hw/net/rss_tap_bpf.h
>> new file mode 100644
>> index 00..54b88cfb76
>> --- /dev/null
>> +++ b/hw/net/rss_tap_bpf.h
>> @@ -0,0 +1,40 @@
>> +/*
>> + * RSS ebpf header for virtio-net
>> + *
>> + * Copyright (c) 2018 RedHat.
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + *
>> + * This code is heavily based on the following bpf code from dpdk
>> + * https://git.dpdk.org/dpdk/tree/drivers/net/tap/
>
> There are alot of files in this directory, with varying different
> copyright claims on them, while you're claiming Red Hat copyright.
> This looks dubious.
>
>> + *
>> + */
>> +
>> +#ifndef RSS_TAP_BPF_H
>> +#define RSS_TAP_BPF_H
>> +
>> +/* hashed fields for RSS */
>> +enum hash_field {
>> +  HASH_FIELD_IPV4_L3,  /* IPv4 src/dst addr */
>> +  HASH_FIELD_IPV4_L3_L4,  /* IPv4 src/dst addr + L4 src/dst ports */
>> +  HASH_FIELD_IPV6_L3,  /* IPv6 src/dst addr */
>> +  HASH_FIELD_IPV6_L3_L4,  /* IPv6 src/dst addr + L4 src/dst ports */
>> +  HASH_FIELD_L2_SRC,  /* Ethernet src addr */
>> +  HASH_FIELD_L2_DST,  /* Ethernet dst addr */
>> +  HASH_FIELD_L3_SRC,  /* L3 src addr */
>> +  HASH_FIELD_L3_DST,  /* L3 dst addr */
>> +  HASH_FIELD_L4_SRC,  /* TCP/UDP src ports */
>> +  HASH_FIELD_L4_DST,  /* TCP/UDP dst ports */
>> +};
>> +
>> +struct rss_key {
>> +  __u32 hash_fields;
>> +  __u32 nb_queues;
>> +__u32 *indirection_table;
>> +__u32 indirection_table_size;
>> +  __u8 *key;
>> +  __u32 key_size;
>> +} __attribute__((packed));
>> +
>> +#endif
>> diff --git a/hw/net/rss_tap_bpf_program.c b/hw/net/rss_tap_bpf_program.c
>> new file mode 100644
>> index 00..2744436e86
>> --- /dev/null
>> +++ b/hw/net/rss_tap_bpf_program.c
>> @@ -0,0 +1,175 @@
>> +/*
>> + * RSS ebpf code for virtio-net
>> + *
>> + * Copyright (c) 2018 RedHat.
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + *
>> + * This code is heavily based on the following bpf code from dpdk
>> + * https://git.dpdk.org/dpdk/tree/drivers/net/tap/tap_bpf_program.c
>
> That file says
>
>* Copyright 2017 Mellanox Technologies, Ltd
>
> while you are claiming RedHat copyright. That can't be right attribution
> if this is indeed a derived work.
I am not an expert when it comes to licensing, I gave credits Mellanox
for the work but I have introduced some new changes as well to suit my
usage.
Moreover the license for the original code is 3BSD or GPL, I have no
idea how this is possible and which license I should take into
account?
Anyways I'd love some guidance on this topic so I can give the
appropriate credit where it is needed.

Thanks!
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 1/6] Add bpf support to qemu

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 3:24 PM, Peter Maydell  wrote:
> On 3 September 2018 at 12:59, Daniel P. Berrangé  wrote:
>
>>>  ##
>>> +# check for usable bpf system call
>>> +if test "$bpf" = "yes"; then
>>
>> if test "x$bpf" != "xno"; then
>
> We don't use the leading-x thingy elsewhere in configure,
> why is this condition special?
> (We can assume we don't have a broken shell, and we
> know that $bpf won't be a string starting with a hyphen.)
That's what Daniel suggested and I though it should be good for the
reasons above. You have good points as well. Both approaches are okay
with me :)
>
> thanks
> -- PMM



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 1/6] Add bpf support to qemu

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 2:59 PM, Daniel P. Berrangé  wrote:
> On Thu, Aug 30, 2018 at 05:27:03PM +0300, Sameeh Jubran wrote:
>> From: Sameeh Jubran 
>>
>> This commit adds the bpf header provided by Linux to Qemu.
>
> s/Qemu/QEMU/
>
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>  MAINTAINERS |  5 +
>>  configure   | 44 
>> +
>>  scripts/update-linux-headers.sh |  8 ++--
>>  3 files changed, 55 insertions(+), 2 deletions(-)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 0fb5f38f9f..bf2619239c 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -2126,6 +2126,11 @@ F: hw/rdma/*
>>  F: hw/rdma/vmw/*
>>  F: docs/pvrdma.txt
>>
>> +BPF
>> +M: Sameeh Jubran 
>> +S: Maintained
>> +F: linux-headers/linux/bpf.h
>> +
>>  Build and test automation
>>  -
>>  Build and test automation
>> diff --git a/configure b/configure
>> index a8c4094c87..21edaf59aa 100755
>> --- a/configure
>> +++ b/configure
>> @@ -348,6 +348,7 @@ libattr=""
>>  xfs=""
>>  tcg="yes"
>>  membarrier=""
>> +bpf="no"
>
> This should really default to "", with the check below
> automatically doing the right thing to automatically
> enable/disable it.
>
>>  vhost_net="no"
>>  vhost_crypto="no"
>>  vhost_scsi="no"
>> @@ -1173,6 +1174,10 @@ for opt do
>>;;
>>--enable-membarrier) membarrier="yes"
>>;;
>> +  --disable-bpf) bpf="no"
>> +  ;;
>> +  --enable-bpf) bpf="yes"
>> +  ;;
>>--disable-blobs) blobs="no"
>>;;
>>--with-pkgversion=*) pkgversion="$optarg"
>> @@ -1593,6 +1598,7 @@ disabled with --disable-FEATURE, default is enabled if 
>> available:
>>brlapi  BrlAPI (Braile)
>>curlcurl connectivity
>>membarrier  membarrier system call (for Linux 4.14+ or Windows)
>> +  bpf bpf system calls (for Linux 3.18+)
>>fdt fdt device tree
>>bluez   bluez stack connectivity
>>kvm KVM acceleration support
>> @@ -5232,6 +5238,38 @@ else
>>  fi
>>
>>  ##
>> +# check for usable bpf system call
>> +if test "$bpf" = "yes"; then
>
> if test "x$bpf" != "xno"; then
>
>> +have_bpf=no
>> +if test "$linux" = "yes" ; then
>> +cat > $TMPC << EOF
>> +#include 
>> +#include "linux/bpf.h"
>> +#include 
>> +#include 
>> +#include 
>> +int main(void) {
>> +union bpf_attr * attr = NULL;
>> +syscall(__NR_bpf, BPF_PROG_LOAD, attr, sizeof(attr));
>> +exit(0);
>> +}
>> +EOF
>> +bpf_include="-Iinclude/standard-headers/linux"
>> +bpf_cflags=""
>> +bpf_libs=""
>> +if compile_prog "$bpf_include" "$bpf_libs" ; then
>> +have_bpf=yes
>> +fi
>> +fi
>> +if test "$have_bpf" = "no"; then
>> +  feature_not_found "bpf" "libelf libs are not available or else \
>> +the bpf system call is not available"
>
> if test "$have_bpf" = "no"; then
> if test "x$bpf" = "xyes" ;
> then
>feature_not_found 
> else
>bpf=no
> fi
> else
> bpf=yes
> fi
I'll use the x prefix, for anyone wondering why this is necessary ( I
didn't realize this before), checkout the following explanation:
https://stackoverflow.com/questions/174119/why-do-shell-script-comparisons-often-use-xvar-xyes
>
>> +fi
>> +else
>> +bpf=no
>> +fi
>> +
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 3/6] vhost-net: Expose vhost_net_get_fd

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 6:24 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Signed-off-by: Sameeh Jubran 
>
>
> Better explain the motivation in the commit log.
I used to use this function in my initial implementation, but this is
unneeded now and the patch can be dropped
>
> Thanks
>
>
>> ---
>>   hw/net/vhost_net.c | 2 +-
>>   include/hw/virtio/virtio-net.h | 2 ++
>>   2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>> index e037db63a3..c0bff725c9 100644
>> --- a/hw/net/vhost_net.c
>> +++ b/hw/net/vhost_net.c
>> @@ -129,7 +129,7 @@ uint64_t vhost_net_get_acked_features(VHostNetState
>> *net)
>>   return net->dev.acked_features;
>>   }
>>   -static int vhost_net_get_fd(NetClientState *backend)
>> +int vhost_net_get_fd(NetClientState *backend)
>>   {
>>   switch (backend->info->type) {
>>   case NET_CLIENT_DRIVER_TAP:
>> diff --git a/include/hw/virtio/virtio-net.h
>> b/include/hw/virtio/virtio-net.h
>> index 02484dc94c..a7b53edc96 100644
>> --- a/include/hw/virtio/virtio-net.h
>> +++ b/include/hw/virtio/virtio-net.h
>> @@ -107,4 +107,6 @@ typedef struct VirtIONet {
>>   void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
>>  const char *type);
>>   +int vhost_net_get_fd(NetClientState *backend);
>> +
>>   #endif
>
>



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 5/6] virtio-net: steering mode: Implement rss support

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 6:48 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>   hw/net/virtio-net.c | 122
>> 
>>   1 file changed, 105 insertions(+), 17 deletions(-)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index e7c4ce6f66..4a52a6a1d0 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -972,41 +972,129 @@ static int virtio_net_handle_mq(VirtIONet *n,
>> uint8_t cmd,
>>   return VIRTIO_NET_OK;
>>   }
>>   -static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
>> +
>> +static int virtio_net_ctrl_sm_rss(VirtIONet *n, uint32_t cmd,
>>   struct iovec *iov, unsigned int iov_cnt,
>>   struct iovec *iov_in, unsigned int
>> iov_cnt_in,
>> -size_t *size_in)
>> +size_t *size_in)
>> +{
>> +size_t s;
>> +uint32_t supported_hash_function = 0;
>> +
>> +switch (cmd) {
>> +case VIRTIO_NET_SM_CTRL_RSS_GET_SUPPORTED_FUNCTIONS:
>> +supported_hash_function |= RSS_HASH_FUNCTION_TOEPLITZ;
>> +if (!size_in) {
>> +return VIRTIO_NET_ERR;
>> +}
>> +s = iov_from_buf(iov_in, iov_cnt_in, 0,
>> +_hash_function,
>> +supported_hash_function);
>
>
> Indentation looks wrong.
>
>
>> +if (s != sizeof(n->supported_modes) ||
>> +!size_in) {
>> +return VIRTIO_NET_ERR;
>> +}
>> +*size_in = s;
>> +break;
>> +case VIRTIO_NET_SM_CTRL_RSS_SET:
>> +if (!n->rss_conf) {
>> +n->rss_conf = g_malloc0(
>> +sizeof(struct virtio_net_rss_conf));
>> +} else if (iov == NULL || iov_cnt == 0) {
>> +g_free(n->rss_conf->ptrs.hash_key);
>> +g_free(n->rss_conf->ptrs.indirection_table);
>> +g_free(n->rss_conf);
>> +return VIRTIO_NET_OK;
>> +}
>> +s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf,
>> +sizeof(struct virtio_net_rss_conf) -
>> +sizeof(struct virtio_net_rss_conf_ptrs));
>> +
>> +if (s != sizeof(struct virtio_net_rss_conf) -
>> +sizeof(struct virtio_net_rss_conf_ptrs)) {
>> +return VIRTIO_NET_ERR;
>> +}
>> +n->rss_conf->ptrs.hash_key = g_malloc0(sizeof(uint8_t) *
>> +n->rss_conf->hash_key_length);
>
>
> What happens if n->rss_conf != 0 && iov != NULL? Looks like a guest
> trigger-able OOM?
>
> Btw e.g "conf_ptrs" sounds misleading, why not just embed hash key and
> indirection table pointers directly in rss_conf structure itself?
It was neater to do it like this so I can use:
sizeof(struct virtio_net_rss_conf) - sizeof(struct virtio_net_rss_conf_ptrs)
when reading from the iov, but yeah it not a big deal and I can put
the pointers there as well
>
>
>> +s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf->ptrs.hash_key,
>> +sizeof(uint8_t) * n->rss_conf->hash_key_length);
>> +if (s != sizeof(uint8_t) * n->rss_conf->hash_key_length) {
>> +g_free(n->rss_conf->ptrs.hash_key);
>> +return VIRTIO_NET_ERR;
>> +}
>> +n->rss_conf->ptrs.indirection_table
>> += g_malloc0(sizeof(uint32_t) *
>> +n->rss_conf->indirection_table_length);
>> +s = iov_to_buf(iov, iov_cnt, 0,
>> +n->rss_conf->ptrs.indirection_table, sizeof(uint32_t) *
>> +n->rss_conf->indirection_table_length);
>> +if (s != sizeof(uint32_t) *
>> +n->rss_conf->indirection_table_length) {
>> +g_free(n->rss_conf->ptrs.hash_key);
>> +g_free(n->rss_conf->ptrs.indirection_table);
>> +return VIRTIO_NET_ERR;
>> +}
>> +/* do bpf magic */
>> +break;
>> +default:
>> +return VIRTIO_NET_ERR;
>> +}
>> +
>> +return VIRTIO_NET_OK;
>> +}
>> +
>> +static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
>> +struct iovec *iov, unsigned int iov_cnt,
>> +st

Re: [Qemu-devel] [RFC 2/6] tap: Add support for bpf ioctls

2018-09-03 Thread Sameeh Jubran
On Thu, Aug 30, 2018 at 6:21 PM, Eric Blake  wrote:
> On 08/30/2018 09:27 AM, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Starting from kernel v4.16 tun device supports TUNSETSTEERINGEBPF and
>> TUNSETFILTEREBPF.
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>
>
>> +++ b/qapi/net.json
>> @@ -692,3 +692,14 @@
>>   ##
>>   { 'event': 'NIC_RX_FILTER_CHANGED',
>> 'data': { '*name': 'str', 'path': 'str' } }
>> +
>> +##
>> +# @BPFType:
>> +#
>> +# BPF programs types provided as an argument for tap bpf ioctls
>> +#
>> +# Since: 2.12
>
>
> You missed 2.12 by a long shot; this should be 3.1.
Yup, but it seems like I'm dropping this from QAPI,
Thanks
>
>> +#
>> +##
>> +{ 'enum': 'BPFType',
>> +  'data': [ 'filter', 'steering' ] }
>
>
> It might also be wise to document these two values in addition to the
> documentation of the enum as a whole.
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



Re: [Qemu-devel] [RFC 2/6] tap: Add support for bpf ioctls

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 6:24 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> Starting from kernel v4.16 tun device supports TUNSETSTEERINGEBPF and
>> TUNSETFILTEREBPF.
>>
>> Signed-off-by: Sameeh Jubran 
>> ---
>>   include/net/net.h |  3 ++-
>>   net/tap-bsd.c |  5 +
>>   net/tap-linux.c   | 29 -
>>   net/tap-linux.h   |  3 ++-
>>   net/tap-solaris.c |  5 +
>>   net/tap-stub.c|  5 +
>>   net/tap.c |  8 
>>   net/tap_int.h |  1 +
>>   qapi/net.json | 11 +++
>>   9 files changed, 67 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/net/net.h b/include/net/net.h
>> index 1425960f76..e7d1baac10 100644
>> --- a/include/net/net.h
>> +++ b/include/net/net.h
>> @@ -39,7 +39,6 @@ typedef struct NICConf {
>>   DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),
>> \
>>   DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
>>   -
>
>
> Looks unnecessary.
yup
>
>>   /* Net clients */
>> typedef void (NetPoll)(NetClientState *, bool enable);
>> @@ -60,6 +59,7 @@ typedef int (SetVnetLE)(NetClientState *, bool);
>>   typedef int (SetVnetBE)(NetClientState *, bool);
>>   typedef struct SocketReadState SocketReadState;
>>   typedef void (SocketReadStateFinalize)(SocketReadState *rs);
>> +typedef int (SetBPFFilter)(NetClientState *, int, BPFType);
>
>
> Looks like SetBPFProg is better? Anyway steering prog is not a filter.
True
>
>
>> typedef struct NetClientInfo {
>>   NetClientDriver type;
>> @@ -80,6 +80,7 @@ typedef struct NetClientInfo {
>>   SetVnetHdrLen *set_vnet_hdr_len;
>>   SetVnetLE *set_vnet_le;
>>   SetVnetBE *set_vnet_be;
>> +SetBPFFilter *set_bpf_filter;
>>   } NetClientInfo;
>> struct NetClientState {
>> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
>> index 6c9692263d..fccf17bad0 100644
>> --- a/net/tap-bsd.c
>> +++ b/net/tap-bsd.c
>> @@ -259,3 +259,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
>>   {
>>   return -1;
>>   }
>> +
>> +int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
>> +{
>> +return -1;
>> +}
>> diff --git a/net/tap-linux.c b/net/tap-linux.c
>> index 535b1ddb61..e8ee54f3b3 100644
>> --- a/net/tap-linux.c
>> +++ b/net/tap-linux.c
>> @@ -305,7 +305,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
>>   {
>>   struct ifreq ifr;
>>   -if (ioctl(fd, TUNGETIFF, ) != 0) {
>> +if (ioctl(fd, TUNGETIFF, ) != 0)
>> +{
>
>
> This looks unnecessary.
True
>
>
>>   error_report("TUNGETIFF ioctl() failed: %s",
>>strerror(errno));
>>   return -1;
>> @@ -314,3 +315,29 @@ int tap_fd_get_ifname(int fd, char *ifname)
>>   pstrcpy(ifname, sizeof(ifr.ifr_name), ifr.ifr_name);
>>   return 0;
>>   }
>> +
>> +
>> +int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
>> +{
>> +int ioctl_num = 0;
>> +switch (type)
>> +{
>> +case BPF_TYPE_FILTER:
>> +ioctl_num = TUNSETFILTEREBPF;
>> +break;
>> +
>> +case BPF_TYPE_STEERING:
>> +ioctl_num = TUNSETSTEERINGEBPF;
>> +break;
>> +
>> +default:
>> +error_report("Unknown bpf_type");
>> +return -1;
>> +}
>
>
> Indentation looks odd.
Will fix
>
>
>> +
>> +if (ioctl(fd, ioctl_num, _fd) != 0) {
>> +error_report("#%d ioctl() failed: %s", ioctl_num,
>> strerror(errno));
>> +return -1;
>> +}
>> +return 0;
>> +}
>> diff --git a/net/tap-linux.h b/net/tap-linux.h
>> index 2f36d100fc..7348169fc2 100644
>> --- a/net/tap-linux.h
>> +++ b/net/tap-linux.h
>> @@ -31,7 +31,8 @@
>>   #define TUNSETQUEUE  _IOW('T', 217, int)
>>   #define TUNSETVNETLE _IOW('T', 220, int)
>>   #define TUNSETVNETBE _IOW('T', 222, int)
>> -
>> +#define TUNSETSTEERINGEBPF _IOR('T', 224, int)
>> +#define TUNSETFILTEREBPF _IOR('T', 225, int)
>>   #endif
>> /* TUNSETIFF ifr flags */
>> diff --git a/net/tap-solaris.c b/net/tap-solaris.c
>> index a2a92356c1..a5a6248c7d 100644
>> --- a/net/tap-solaris.c
>> +++ b/net/tap-solaris.c
>> @@ -254,3 +254,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
>>   {
>> 

Re: [Qemu-devel] [RFC 0/6] Virtio-net: Support RSS

2018-09-03 Thread Sameeh Jubran
On Mon, Sep 3, 2018 at 7:15 AM, Jason Wang  wrote:
>
>
> On 2018年08月30日 22:27, Sameeh Jubran wrote:
>>
>> From: Sameeh Jubran 
>>
>> This series implements the Steering Mode feature which was introduced on
>> the
>> virtio-dev list a while ago, which can be found here:
>> * https://lists.oasis-open.org/archives/virtio-dev/201805/msg00024.html
>>
>> The first three patches add some infrastructure support that is used in
>> the following three patches.
>>
>> The ebpf filter doesn't fully work yet as I'm having an issue with the
>> verifier which needs to be fixed.
>
>
> What issues did you meet? You can attach a trace buffer and get verbose
> debug information from that. Btw, dpdk use cls bpf and we use socket filter.
I am using the buffer for debugging actually, I keep getting back edge
from two consecutive instructions
in the instruction array which I have no idea how to troubleshoot! The
instructions are generated from the
compiled code which compiles okay.
This didn't happen to me earlier and I have actually succeeded in
inserting the bpf instructions with no issues.
>
>>
>> The patches still need some love as not all of the cases have been handled
>> yet most of the functionality has been implemented.
>
>
> One question is how indirection table is implemented, I thought it should be
> a map but looks not. Please see comment on patch 6.
No it is a hash table.
>
> Thanks
>
>
>>
>> Please share your thoughts and comments so I'll move forward with
>> sending v1 along with a fully functioning ebpf code.
>>
>> Sameeh Jubran (6):
>>Add bpf support to qemu
>>tap: Add support for bpf ioctls
>>vhost-net: Expose vhost_net_get_fd
>>virtio-net: implement steering mode feature
>>virtio-net: steering mode: Implement rss support
>>virtio-net: rss: Add bpf filter
>>
>>   MAINTAINERS |5 +
>>   configure   |   44 +
>>   hw/net/rss_bpf_insns.h  | 3992
>> +++
>>   hw/net/rss_tap_bpf.h|   37 +
>>   hw/net/rss_tap_bpf_program.c|  172 ++
>>   hw/net/vhost_net.c  |2 +-
>>   hw/net/virtio-net.c |  250 +-
>>   include/hw/virtio/virtio-net.h  |5 +
>>   include/net/net.h   |3 +-
>>   include/standard-headers/linux/virtio_net.h |   55 +
>>   net/tap-bsd.c   |5 +
>>   net/tap-linux.c |   29 +-
>>   net/tap-linux.h |3 +-
>>   net/tap-solaris.c   |5 +
>>   net/tap-stub.c  |5 +
>>   net/tap.c   |8 +
>>   net/tap_int.h   |1 +
>>   qapi/net.json       |   11 +
>>   scripts/update-linux-headers.sh |8 +-
>>   19 files changed, 4627 insertions(+), 13 deletions(-)
>>   create mode 100644 hw/net/rss_bpf_insns.h
>>   create mode 100644 hw/net/rss_tap_bpf.h
>>   create mode 100644 hw/net/rss_tap_bpf_program.c
>>
>



-- 
Respectfully,
Sameeh Jubran
Linkedin
Software Engineer @ Daynix.



[Qemu-devel] [RFC 2/6] tap: Add support for bpf ioctls

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

Starting from kernel v4.16 tun device supports TUNSETSTEERINGEBPF and
TUNSETFILTEREBPF.

Signed-off-by: Sameeh Jubran 
---
 include/net/net.h |  3 ++-
 net/tap-bsd.c |  5 +
 net/tap-linux.c   | 29 -
 net/tap-linux.h   |  3 ++-
 net/tap-solaris.c |  5 +
 net/tap-stub.c|  5 +
 net/tap.c |  8 
 net/tap_int.h |  1 +
 qapi/net.json | 11 +++
 9 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index 1425960f76..e7d1baac10 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -39,7 +39,6 @@ typedef struct NICConf {
 DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),\
 DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
 
-
 /* Net clients */
 
 typedef void (NetPoll)(NetClientState *, bool enable);
@@ -60,6 +59,7 @@ typedef int (SetVnetLE)(NetClientState *, bool);
 typedef int (SetVnetBE)(NetClientState *, bool);
 typedef struct SocketReadState SocketReadState;
 typedef void (SocketReadStateFinalize)(SocketReadState *rs);
+typedef int (SetBPFFilter)(NetClientState *, int, BPFType);
 
 typedef struct NetClientInfo {
 NetClientDriver type;
@@ -80,6 +80,7 @@ typedef struct NetClientInfo {
 SetVnetHdrLen *set_vnet_hdr_len;
 SetVnetLE *set_vnet_le;
 SetVnetBE *set_vnet_be;
+SetBPFFilter *set_bpf_filter;
 } NetClientInfo;
 
 struct NetClientState {
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 6c9692263d..fccf17bad0 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -259,3 +259,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
 {
 return -1;
 }
+
+int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
+{
+return -1;
+}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 535b1ddb61..e8ee54f3b3 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -305,7 +305,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
 {
 struct ifreq ifr;
 
-if (ioctl(fd, TUNGETIFF, ) != 0) {
+if (ioctl(fd, TUNGETIFF, ) != 0)
+{
 error_report("TUNGETIFF ioctl() failed: %s",
  strerror(errno));
 return -1;
@@ -314,3 +315,29 @@ int tap_fd_get_ifname(int fd, char *ifname)
 pstrcpy(ifname, sizeof(ifr.ifr_name), ifr.ifr_name);
 return 0;
 }
+
+
+int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
+{
+int ioctl_num = 0;
+switch (type)
+{
+case BPF_TYPE_FILTER:
+ioctl_num = TUNSETFILTEREBPF;
+break;
+
+case BPF_TYPE_STEERING:
+ioctl_num = TUNSETSTEERINGEBPF;
+break;
+
+default:
+error_report("Unknown bpf_type");
+return -1;
+}
+
+if (ioctl(fd, ioctl_num, _fd) != 0) {
+error_report("#%d ioctl() failed: %s", ioctl_num, strerror(errno));
+return -1;
+}
+return 0;
+}
diff --git a/net/tap-linux.h b/net/tap-linux.h
index 2f36d100fc..7348169fc2 100644
--- a/net/tap-linux.h
+++ b/net/tap-linux.h
@@ -31,7 +31,8 @@
 #define TUNSETQUEUE  _IOW('T', 217, int)
 #define TUNSETVNETLE _IOW('T', 220, int)
 #define TUNSETVNETBE _IOW('T', 222, int)
-
+#define TUNSETSTEERINGEBPF _IOR('T', 224, int)
+#define TUNSETFILTEREBPF _IOR('T', 225, int)
 #endif
 
 /* TUNSETIFF ifr flags */
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index a2a92356c1..a5a6248c7d 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -254,3 +254,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
 {
 return -1;
 }
+
+int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
+{
+return -1;
+}
diff --git a/net/tap-stub.c b/net/tap-stub.c
index a9ab8f8293..d059a32435 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -85,3 +85,8 @@ int tap_fd_get_ifname(int fd, char *ifname)
 {
 return -1;
 }
+
+int tap_fd_load_bpf(int fd, int bpf_fd, BPFType type)
+{
+return -1;
+}
diff --git a/net/tap.c b/net/tap.c
index 2126f4882d..ee98fecd40 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -342,6 +342,13 @@ int tap_get_fd(NetClientState *nc)
 return s->fd;
 }
 
+static int tap_set_bpf_filter(NetClientState *nc, int bpf_fd, BPFType type)
+{
+TAPState *s = DO_UPCAST(TAPState, nc, nc);
+assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+return tap_fd_load_bpf(s->fd, bpf_fd, type);
+}
+
 /* fd support */
 
 static NetClientInfo net_tap_info = {
@@ -360,6 +367,7 @@ static NetClientInfo net_tap_info = {
 .set_vnet_hdr_len = tap_set_vnet_hdr_len,
 .set_vnet_le = tap_set_vnet_le,
 .set_vnet_be = tap_set_vnet_be,
+.set_bpf_filter = tap_set_bpf_filter,
 };
 
 static TAPState *net_tap_fd_init(NetClientState *peer,
diff --git a/net/tap_int.h b/net/tap_int.h
index 9f931d52d6..3e1603a88e 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -45,5 +45,6 @@ int tap_fd_set_vnet_be(int fd, int vnet_is_be);
 int tap_fd_enable(int fd);
 int tap_fd_disable(int fd);
 int tap_fd_get_ifname(int fd, char *ifname);
+int tap_fd_load_bpf(int fd, int bpf_fd, 

[Qemu-devel] [RFC 1/6] Add bpf support to qemu

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

This commit adds the bpf header provided by Linux to Qemu.

Signed-off-by: Sameeh Jubran 
---
 MAINTAINERS |  5 +
 configure   | 44 +
 scripts/update-linux-headers.sh |  8 ++--
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb5f38f9f..bf2619239c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2126,6 +2126,11 @@ F: hw/rdma/*
 F: hw/rdma/vmw/*
 F: docs/pvrdma.txt
 
+BPF
+M: Sameeh Jubran 
+S: Maintained
+F: linux-headers/linux/bpf.h
+
 Build and test automation
 -
 Build and test automation
diff --git a/configure b/configure
index a8c4094c87..21edaf59aa 100755
--- a/configure
+++ b/configure
@@ -348,6 +348,7 @@ libattr=""
 xfs=""
 tcg="yes"
 membarrier=""
+bpf="no"
 vhost_net="no"
 vhost_crypto="no"
 vhost_scsi="no"
@@ -1173,6 +1174,10 @@ for opt do
   ;;
   --enable-membarrier) membarrier="yes"
   ;;
+  --disable-bpf) bpf="no"
+  ;;
+  --enable-bpf) bpf="yes"
+  ;;
   --disable-blobs) blobs="no"
   ;;
   --with-pkgversion=*) pkgversion="$optarg"
@@ -1593,6 +1598,7 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   brlapi  BrlAPI (Braile)
   curlcurl connectivity
   membarrier  membarrier system call (for Linux 4.14+ or Windows)
+  bpf bpf system calls (for Linux 3.18+)
   fdt fdt device tree
   bluez   bluez stack connectivity
   kvm KVM acceleration support
@@ -5232,6 +5238,38 @@ else
 fi
 
 ##
+# check for usable bpf system call
+if test "$bpf" = "yes"; then
+have_bpf=no
+if test "$linux" = "yes" ; then
+cat > $TMPC << EOF
+#include 
+#include "linux/bpf.h"
+#include 
+#include 
+#include 
+int main(void) {
+union bpf_attr * attr = NULL;
+syscall(__NR_bpf, BPF_PROG_LOAD, attr, sizeof(attr));
+exit(0);
+}
+EOF
+bpf_include="-Iinclude/standard-headers/linux"
+bpf_cflags=""
+bpf_libs=""
+if compile_prog "$bpf_include" "$bpf_libs" ; then
+have_bpf=yes
+fi
+fi
+if test "$have_bpf" = "no"; then
+  feature_not_found "bpf" "libelf libs are not available or else \
+the bpf system call is not available"
+fi
+else
+bpf=no
+fi
+
+##
 # check if rtnetlink.h exists and is useful
 have_rtnetlink=no
 cat > $TMPC << EOF
@@ -5871,6 +5909,7 @@ echo "malloc trim support $malloc_trim"
 echo "RDMA support  $rdma"
 echo "fdt support   $fdt"
 echo "membarrier$membarrier"
+echo "bpf   $bpf"
 echo "preadv support$preadv"
 echo "fdatasync $fdatasync"
 echo "madvise   $madvise"
@@ -6365,6 +6404,11 @@ fi
 if test "$membarrier" = "yes" ; then
   echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
 fi
+if test "$bpf" = "yes" ; then
+  echo "CONFIG_BPF=y" >> $config_host_mak
+  echo "LIBS_BPF=$bpf_libs" >> $config_host_mak
+  echo "CFLAGS_BPF=$bpf_cflags" >> $config_host_mak
+fi
 if test "$signalfd" = "yes" ; then
   echo "CONFIG_SIGNALFD=y" >> $config_host_mak
 fi
diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index feb75390aa..57df8228af 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -35,6 +35,8 @@ cp_portable() {
 grep '#include' "$f" | grep -v -e 'linux/virtio' \
  -e 'linux/types' \
  -e 'stdint' \
+ -e 'stdio' \
+ -e 'stdbool' \
  -e 'linux/if_ether' \
  -e 'input-event-codes' \
  -e 'sys/' \
@@ -44,6 +46,7 @@ cp_portable() {
  -e 'linux/kernel' \
  -e 'linux/sysinfo' \
  -e 'asm-generic/kvm_para' \
+ -e 'linux/bpf' \
  > /dev/null
 then
 echo "Unexpected #include in input file $f".
@@ -58,7 +61,7 @@ cp_portable() {
 -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
 -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
 -e 's/"\(input-event-codes\.h\)"/&qu

[Qemu-devel] [RFC 4/6] virtio-net: implement steering mode feature

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

Signed-off-by: Sameeh Jubran 
---
 hw/net/virtio-net.c | 65 +
 include/hw/virtio/virtio-net.h  |  3 ++
 include/standard-headers/linux/virtio_net.h | 55 
 3 files changed, 116 insertions(+), 7 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 90502fca7c..e7c4ce6f66 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -972,13 +972,53 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
 return VIRTIO_NET_OK;
 }
 
+static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
+struct iovec *iov, unsigned int iov_cnt,
+struct iovec *iov_in, unsigned int iov_cnt_in,
+size_t *size_in)
+{
+size_t s;
+struct virtio_net_steering_mode sm;
+
+switch (cmd) {
+case VIRTIO_NET_CTRL_SM_GET_SUPPORTED_MODES:
+if (!size_in) {
+return VIRTIO_NET_ERR;
+}
+  s = iov_from_buf(iov_in, iov_cnt_in, 0,
+  >supported_modes, sizeof(n->supported_modes));
+if (s != sizeof(n->supported_modes) ||
+  !size_in) {
+return VIRTIO_NET_ERR;
+}
+  *size_in = s;
+  break;
+case VIRTIO_NET_CTRL_SM_CONTROL:
+s = iov_to_buf(iov, iov_cnt, 0, , sizeof(sm) -
+sizeof(union command_data));
+if (s != sizeof(sm) - sizeof(union command_data)) {
+return VIRTIO_NET_ERR;
+}
+/* switch (cmd)
+ {
+dafault:
+return VIRTIO_NET_ERR;
+ } */
+  break;
+default:
+return VIRTIO_NET_ERR;
+}
+
+return VIRTIO_NET_OK;
+}
+
 static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
 VirtIONet *n = VIRTIO_NET(vdev);
 struct virtio_net_ctrl_hdr ctrl;
 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
 VirtQueueElement *elem;
-size_t s;
+size_t s, elem_in_size = 0;
 struct iovec *iov, *iov2;
 unsigned int iov_cnt;
 
@@ -996,7 +1036,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, 
VirtQueue *vq)
 }
 
 iov_cnt = elem->out_num;
-iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * 
elem->out_num);
+iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) *
+elem->out_num);
 s = iov_to_buf(iov, iov_cnt, 0, , sizeof(ctrl));
 iov_discard_front(, _cnt, sizeof(ctrl));
 if (s != sizeof(ctrl)) {
@@ -1013,12 +1054,20 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, 
VirtQueue *vq)
 status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
 } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
 status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt);
+} else if (ctrl.class == VIRTIO_NET_CTRL_STEERING_MODE) {
+size_t size_in = 0;
+status = virtio_net_ctrl_steering_mode(n, ctrl.cmd, iov, iov_cnt,
+   elem->in_sg, elem->in_num, _in);
+if (status == VIRTIO_NET_OK  && size_in > 0) {
+elem_in_size += size_in;
+}
 }
 
-s = iov_from_buf(elem->in_sg, elem->in_num, 0, , 
sizeof(status));
+s = iov_from_buf(elem->in_sg, elem->in_num, elem_in_size, ,
+sizeof(status));
 assert(s == sizeof(status));
-
-virtqueue_push(vq, elem, sizeof(status));
+elem_in_size += s;
+virtqueue_push(vq, elem, elem_in_size);
 virtio_notify(vdev, vq);
 g_free(iov2);
 g_free(elem);
@@ -1375,10 +1424,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
n->guest_hdr_len, -1);
 if (out_num == VIRTQUEUE_MAX_SIZE) {
 goto drop;
-   }
+}
 out_num += 1;
 out_sg = sg2;
-   }
+  }
 }
 /*
  * If host wants to see the guest header as is, we can
@@ -1957,6 +2006,8 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
 n->host_features |= (1ULL << VIRTIO_NET_F_MTU);
 }
 
+n->host_features |= (1ULL << VIRTIO_NET_F_CTRL_STEERING_MODE);
+
 if (n->net_conf.duplex_str) {
 if (strncmp(n->net_conf.duplex_str, "half", 5) == 0) {
 n->net_conf.duplex = DUPLEX_HALF;
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index a7b53edc96..809e85481c 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -102,6 +102,9 @@ typedef struct VirtIONet {
 int announce_counter;
 bool needs_vnet_hdr_swap;
 bool mtu_bypass_backend;
+struct virtio_net_steering_modes supported_modes;
+struct virtio_net_

[Qemu-devel] [RFC 3/6] vhost-net: Expose vhost_net_get_fd

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

Signed-off-by: Sameeh Jubran 
---
 hw/net/vhost_net.c | 2 +-
 include/hw/virtio/virtio-net.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index e037db63a3..c0bff725c9 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -129,7 +129,7 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net)
 return net->dev.acked_features;
 }
 
-static int vhost_net_get_fd(NetClientState *backend)
+int vhost_net_get_fd(NetClientState *backend)
 {
 switch (backend->info->type) {
 case NET_CLIENT_DRIVER_TAP:
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 02484dc94c..a7b53edc96 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -107,4 +107,6 @@ typedef struct VirtIONet {
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
const char *type);
 
+int vhost_net_get_fd(NetClientState *backend);
+
 #endif
-- 
2.13.6




[Qemu-devel] [RFC 0/6] Virtio-net: Support RSS

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

This series implements the Steering Mode feature which was introduced on the
virtio-dev list a while ago, which can be found here:
* https://lists.oasis-open.org/archives/virtio-dev/201805/msg00024.html

The first three patches add some infrastructure support that is used in
the following three patches.

The ebpf filter doesn't fully work yet as I'm having an issue with the
verifier which needs to be fixed.

The patches still need some love as not all of the cases have been handled
yet most of the functionality has been implemented.

Please share your thoughts and comments so I'll move forward with
sending v1 along with a fully functioning ebpf code.

Sameeh Jubran (6):
  Add bpf support to qemu
  tap: Add support for bpf ioctls
  vhost-net: Expose vhost_net_get_fd
  virtio-net: implement steering mode feature
  virtio-net: steering mode: Implement rss support
  virtio-net: rss: Add bpf filter

 MAINTAINERS |5 +
 configure   |   44 +
 hw/net/rss_bpf_insns.h  | 3992 +++
 hw/net/rss_tap_bpf.h|   37 +
 hw/net/rss_tap_bpf_program.c|  172 ++
 hw/net/vhost_net.c  |2 +-
 hw/net/virtio-net.c |  250 +-
 include/hw/virtio/virtio-net.h  |5 +
 include/net/net.h   |3 +-
 include/standard-headers/linux/virtio_net.h |   55 +
 net/tap-bsd.c   |5 +
 net/tap-linux.c |   29 +-
 net/tap-linux.h |3 +-
 net/tap-solaris.c   |5 +
 net/tap-stub.c  |5 +
 net/tap.c   |8 +
 net/tap_int.h   |1 +
 qapi/net.json   |   11 +
 scripts/update-linux-headers.sh |8 +-
 19 files changed, 4627 insertions(+), 13 deletions(-)
 create mode 100644 hw/net/rss_bpf_insns.h
 create mode 100644 hw/net/rss_tap_bpf.h
 create mode 100644 hw/net/rss_tap_bpf_program.c

-- 
2.13.6




[Qemu-devel] [RFC 5/6] virtio-net: steering mode: Implement rss support

2018-08-30 Thread Sameeh Jubran
From: Sameeh Jubran 

Signed-off-by: Sameeh Jubran 
---
 hw/net/virtio-net.c | 122 
 1 file changed, 105 insertions(+), 17 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index e7c4ce6f66..4a52a6a1d0 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -972,41 +972,129 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t 
cmd,
 return VIRTIO_NET_OK;
 }
 
-static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
+
+static int virtio_net_ctrl_sm_rss(VirtIONet *n, uint32_t cmd,
 struct iovec *iov, unsigned int iov_cnt,
 struct iovec *iov_in, unsigned int iov_cnt_in,
-size_t *size_in)
+size_t *size_in)
+{
+size_t s;
+uint32_t supported_hash_function = 0;
+
+switch (cmd) {
+case VIRTIO_NET_SM_CTRL_RSS_GET_SUPPORTED_FUNCTIONS:
+supported_hash_function |= RSS_HASH_FUNCTION_TOEPLITZ;
+if (!size_in) {
+return VIRTIO_NET_ERR;
+}
+s = iov_from_buf(iov_in, iov_cnt_in, 0,
+_hash_function,
+supported_hash_function);
+if (s != sizeof(n->supported_modes) ||
+!size_in) {
+return VIRTIO_NET_ERR;
+}
+*size_in = s;
+break;
+case VIRTIO_NET_SM_CTRL_RSS_SET:
+if (!n->rss_conf) {
+n->rss_conf = g_malloc0(
+sizeof(struct virtio_net_rss_conf));
+} else if (iov == NULL || iov_cnt == 0) {
+g_free(n->rss_conf->ptrs.hash_key);
+g_free(n->rss_conf->ptrs.indirection_table);
+g_free(n->rss_conf);
+return VIRTIO_NET_OK;
+}
+s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf,
+sizeof(struct virtio_net_rss_conf) -
+sizeof(struct virtio_net_rss_conf_ptrs));
+
+if (s != sizeof(struct virtio_net_rss_conf) -
+sizeof(struct virtio_net_rss_conf_ptrs)) {
+return VIRTIO_NET_ERR;
+}
+n->rss_conf->ptrs.hash_key = g_malloc0(sizeof(uint8_t) *
+n->rss_conf->hash_key_length);
+s = iov_to_buf(iov, iov_cnt, 0, n->rss_conf->ptrs.hash_key,
+sizeof(uint8_t) * n->rss_conf->hash_key_length);
+if (s != sizeof(uint8_t) * n->rss_conf->hash_key_length) {
+g_free(n->rss_conf->ptrs.hash_key);
+return VIRTIO_NET_ERR;
+}
+n->rss_conf->ptrs.indirection_table
+= g_malloc0(sizeof(uint32_t) *
+n->rss_conf->indirection_table_length);
+s = iov_to_buf(iov, iov_cnt, 0,
+n->rss_conf->ptrs.indirection_table, sizeof(uint32_t) *
+n->rss_conf->indirection_table_length);
+if (s != sizeof(uint32_t) *
+n->rss_conf->indirection_table_length) {
+g_free(n->rss_conf->ptrs.hash_key);
+g_free(n->rss_conf->ptrs.indirection_table);
+return VIRTIO_NET_ERR;
+}
+/* do bpf magic */
+break;
+default:
+return VIRTIO_NET_ERR;
+}
+
+return VIRTIO_NET_OK;
+}
+
+static int virtio_net_ctrl_steering_mode(VirtIONet *n, uint8_t cmd,
+struct iovec *iov, unsigned int iov_cnt,
+struct iovec *iov_in, unsigned int iov_in_cnt,
+size_t *size_in)
 {
 size_t s;
 struct virtio_net_steering_mode sm;
+int status = 0;
+size_t size_in_cmd = 0;
 
 switch (cmd) {
 case VIRTIO_NET_CTRL_SM_GET_SUPPORTED_MODES:
 if (!size_in) {
 return VIRTIO_NET_ERR;
 }
-  s = iov_from_buf(iov_in, iov_cnt_in, 0,
-  >supported_modes, sizeof(n->supported_modes));
+n->supported_modes.steering_modes |= STEERING_MODE_RSS |
+STEERING_MODE_AUTO;
+s = iov_from_buf(iov_in, iov_in_cnt, 0,
+>supported_modes,
+sizeof(n->supported_modes));
 if (s != sizeof(n->supported_modes) ||
-  !size_in) {
+!size_in) {
 return VIRTIO_NET_ERR;
 }
-  *size_in = s;
-  break;
+*size_in = s;
+ break;
 case VIRTIO_NET_CTRL_SM_CONTROL:
-s = iov_to_buf(iov, iov_cnt, 0, , sizeof(sm) -
-sizeof(union command_data));
-if (s != sizeof(sm) - sizeof(union command_data)) {
+s = iov_to_buf(iov, iov_cnt, 0, , sizeof(sm));
+if (s != sizeof(sm)) {
+return VIRTIO_NET_ERR;
+}
+iov_discard_front(, _cnt, sizeof(sm));
+/* TODO handle the case where we change mode, call the old */
+/* mode function with null ptrs  should do the trick of */
+/* freeing any resources */
+switch (sm.steering

Re: [Qemu-devel] [PATCH 2/2] qga-win: fsinfo: pci-info: allow partial info

2018-07-17 Thread Sameeh Jubran
On Mon, Jul 16, 2018 at 11:04 PM, Michael Roth 
wrote:

> Quoting Sameeh Jubran (2018-06-26 10:10:38)
> > From: Sameeh Jubran 
> >
> > The call to SetupDiGetDeviceRegistryProperty might fail because the
> > value doesn't exist in the registry, in this case we shouldn't exit from
> > the loop but instead continue to look for other available values in the
> > registry and set this value as unavailable (-1).
> >
> > Signed-off-by: Sameeh Jubran 
>
> The values I'm seeing look off:
>
> win7:
>
> {'execute':'guest-get-fsinfo','arguments':{}}
>
> {"return": [{"name":
> "?\\Volume{2823bc2b-b90f-11e7-9ea5-806e6f6e6963}\\", "total-bytes":
> 316628992, "mountpoint": "E:\\", "disk": [{"bus-type": "ide", "bus": 0,
> "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": -1,
> "function": -1}, "target": 0}], "used-bytes": 316628992, "type":
> "CDFS"}, {"name":
> "?\\Volume{a1ed8064-3f4a-11e1-972d-806e6f6e6963}\\", "total-bytes":
> 21367877632, "mountpoint": "C:\\", "disk": [{"bus-type": "scsi", "bus":
> 0, "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": 0,
> "function": 2}, "target": 0}], "used-bytes": 19656269824, "type":
> "NTFS"}, {"name":
> "?\\Volume{a1ed8063-3f4a-11e1-972d-806e6f6e6963}\\", "mountpoint":
> "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0, "unit": 0,
> "pci-controller": {"bus": -1, "slot": -1, "domain": 0, "function": 1},
> "target": 0}], "type": "NTFS"}]}
>
> win10:
>
> {'execute':'guest-get-fsinfo','arguments':{}}
>
> {"return": [{"name":
> "?\\Volume{83835b2d-0032-11e6-a84f-806e6f6e6963}\\", "total-bytes":
> 160755712, "mountpoint": "D:\\", "disk": [{"bus-type": "ide", "bus": 0,
> "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": -1,
> "function": -1}, "target": 0}], "used-bytes": 160755712, "type":
> "CDFS"}, {"name":
> "?\\Volume{2ea839c6----80620c00}\\", "mountpoint":
> "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0, "unit": 0,
> "pci-controller": {"bus": -1, "slot": -1, "domain": 0, "function": 3},
> "target": 0}], "type": "NTFS"}, {"name":
> "?\\Volume{2ea839c6----501f}\\", "total-bytes":
> 52665839616, "mountpoint": "C:\\", "disk": [{"bus-type": "scsi", "bus":
> 0, "unit": 0, "pci-controller": {"bus": -1, "slot": -1, "domain": 0,
> "function": 2}, "target": 0}], "used-bytes": 29645811712, "type":
> "NTFS"}, {"name":
> "?\\Volume{2ea839c6----1000}\\", "mountpoint":
> "System Reserved", "disk": [{"bus-type": "scsi", "bus": 0, "unit": 0,
> "pci-controller": {"bus": -1, "slot": -1, "domain": 0, "function": 1},
> "target": 0}], "type": "NTFS"}]}
>
> If any one of domain/bus/slot/func fail, we should initialize everything
> to -1 since we can't partially report a PCI address. The fact that we
> get partial success makes me think SPDRP_ADDRESS, SPDRP_UI_NUMBER, etc.
> aren't reporting what we expect they should. The documentation seems
> a bit nebulous. Also I'm not using multifunction to the non-0 function
> values seem off.
>


>
> Do you know of anyone manually setting CONFIG_QGA_NTDDSCSI in practice?
>
Yes, I am using it actually.

> It's been left disabled in configure (left misnamed as CONFIG_QGA_NTDDDISK
> due to some problems that popped up when we tried to enable it that I
> don't quite recall, maybe similar issues to what you're seeing). I'm
> starting to think it's better to leave this for 3.1 since it's not
> technically a supported feature yet

Re: [Qemu-devel] [PATCH] qga-win: Handle fstrim for OSes lower than Win8

2018-07-16 Thread Sameeh Jubran
I'v successfully compiled the previous patch on Fedora 27, but it seems to
be failing on RHEL, You can apply this patch instead which avoids using the
versionhelpers header:
---
 qga/commands-win32.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index fb91f5d..e688e71 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -846,6 +846,17 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,
Error **errp)
 GuestFilesystemTrimResponse *resp;
 HANDLE handle;
 WCHAR guid[MAX_PATH] = L"";
+OSVERSIONINFO osvi;
+BOOL bIsWindows8orLater;
+
+ZeroMemory(, sizeof(OSVERSIONINFO));
+osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+GetVersionEx();
+bIsWindows8orLater = ((osvi.dwMajorVersion == 6) &&
(osvi.dwMinorVersion >= 2));
+if (!bIsWindows8orLater) {
+ error_setg(errp, "fstrim is only supported for Win8+");
+ return NULL;
+}

 handle = FindFirstVolumeW(guid, ARRAYSIZE(guid));
 if (handle == INVALID_HANDLE_VALUE) {
--
2.8.1.185.gdc0db2c


On Mon, Jul 16, 2018 at 11:10 PM, Michael Roth 
wrote:

> Quoting Sameeh Jubran (2018-06-24 07:45:40)
> > From: Sameeh Jubran 
> >
> > The defrag.exe tool which is used for executing the fstrim command
> > on Windows doesn't support retrim for OSes lower than Win8. This
> > commit handles this case and returns a suitable error.
> >
> > Output of fstrim before this commit:
> > {"execute":"guest-fstrim"}
> > {"return": {"paths": [{"path": "C:\\", "error": "An invalid command line
> option
> > was specified. (0x8908)"}, {"path": "F:\\", "error": "An invalid
> command
> > line option was specified. (0x8908)"}, {"path": "S:\\", "error": "An
> > invalid command line option was specified. (0x8908)"}]}}
> >
> > Reported on:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1594113
> >
> > Signed-off-by: Sameeh Jubran 
> > ---
> >  qga/commands-win32.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> > index d79974f212..0bdcd9dd38 100644
> > --- a/qga/commands-win32.c
> > +++ b/qga/commands-win32.c
> > @@ -30,6 +30,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
>
> I have this queued locally but the mingw64 build environment I've been
> using (fc20) doesn't support this header and I'm running into some odd
> null pointer / 0xc005 / access violation issues with the binary
> generated in newer tool chains. I'll send a pull for this next week when
> I can get it tested.
>
> What build envionment are you using?
>
> >
> >  #include "qga/guest-agent-core.h"
> >  #include "qga/vss-win32.h"
> > @@ -852,6 +853,11 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,
> Error **errp)
> >  HANDLE handle;
> >  WCHAR guid[MAX_PATH] = L"";
> >
> > +   if (!IsWindows8OrGreater()) {
> > +error_setg(errp, "fstrim is only supported for Win8+");
> > +return NULL;
> > +   }
> > +
> >  handle = FindFirstVolumeW(guid, ARRAYSIZE(guid));
> >  if (handle == INVALID_HANDLE_VALUE) {
> >  error_setg_win32(errp, GetLastError(), "failed to find any
> volume");
> > --
> > 2.13.6
> >
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH] qga-win: Handle fstrim for OSes lower than Win8

2018-07-16 Thread Sameeh Jubran
ping.

On Sun, Jun 24, 2018 at 3:45 PM, Sameeh Jubran  wrote:

> From: Sameeh Jubran 
>
> The defrag.exe tool which is used for executing the fstrim command
> on Windows doesn't support retrim for OSes lower than Win8. This
> commit handles this case and returns a suitable error.
>
> Output of fstrim before this commit:
> {"execute":"guest-fstrim"}
> {"return": {"paths": [{"path": "C:\\", "error": "An invalid command line
> option
> was specified. (0x8908)"}, {"path": "F:\\", "error": "An invalid
> command
> line option was specified. (0x8908)"}, {"path": "S:\\", "error": "An
> invalid command line option was specified. (0x8908)"}]}}
>
> Reported on:
> https://bugzilla.redhat.com/show_bug.cgi?id=1594113
>
> Signed-off-by: Sameeh Jubran 
> ---
>  qga/commands-win32.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index d79974f212..0bdcd9dd38 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include "qga/guest-agent-core.h"
>  #include "qga/vss-win32.h"
> @@ -852,6 +853,11 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,
> Error **errp)
>  HANDLE handle;
>  WCHAR guid[MAX_PATH] = L"";
>
> +   if (!IsWindows8OrGreater()) {
> +    error_setg(errp, "fstrim is only supported for Win8+");
> +return NULL;
> +   }
> +
>  handle = FindFirstVolumeW(guid, ARRAYSIZE(guid));
>  if (handle == INVALID_HANDLE_VALUE) {
>  error_setg_win32(errp, GetLastError(), "failed to find any
> volume");
> --
> 2.13.6
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH 1/2] qga-win: prevent crash when executing fsinfo command

2018-07-16 Thread Sameeh Jubran
I've found another bug which is related to this one, where pci_controller
might also be null:
in the function "build_guest_disk_info" in "qga/commands-win32.c"

if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID

#if (_WIN32_WINNT >= 0x0600)

/* This bus type is not supported before Windows Server 2003 SP1 */

|| bus == BusTypeSas

#endif

) {

/* We are able to use the same ioctls for different bus types

* according to Microsoft docs

* https://technet.microsoft.com/en-us/library/ee851589(v=ws.10).aspx */

if (DeviceIoControl(vol_h, IOCTL_SCSI_GET_ADDRESS, NULL, 0, scsi_ad,

sizeof(SCSI_ADDRESS), , NULL)) {

disk->unit = addr.Lun;

disk->target = addr.TargetId;

disk->bus = addr.PathId;

disk->pci_controller = get_pci_info(name, errp);

}

/* We do not set error in this case, because we still have enough

* information about volume. */

} else {

disk->pci_controller = NULL;

}

This can be easily prevented by always calling "get_pci_info(name, errp);",
is this a separate patch, or should be combined with this one? what do you
think?

On Tue, Jul 10, 2018 at 1:58 AM, Michael Roth 
wrote:

> Quoting Sameeh Jubran (2018-06-28 18:33:58)
> >
> >
> > On Fri, Jun 29, 2018 at 12:44 AM, Eric Blake  wrote:
> >
> > On 06/26/2018 10:10 AM, Sameeh Jubran wrote:
> >
> > From: Sameeh Jubran 
> >
> > The fsinfo command is currently implemented for Windows only and
> it's
> > disk
> > parameter can be enabled by adding the define
> "CONFIG_QGA_NTDDSCSI" to
> > the qga
> > code. When enabled and executed the qemu-ga crashed with the
> following
> > message:
> >
> > 
> > File qapi/qapi-visit-core.c, Line 49
> >
> > Expression: !(v->type & VISITOR_OUTPUT) || *obj)
> > 
> >
> > After some digging, turns out that the GuestPCIAddress is null
> and the
> > qapi visitor doesn't like that, so we can always allocate it
> instead
> > and
> > initiate all it's members to -1.
> >
> >
> > Adding Markus for a qapi back-compat question.
> >
> > Is faking an invalid address better than making the output optional
> > instead?
> >
> >
> > +++ b/qga/commands-win32.c
> > @@ -485,6 +485,11 @@ static GuestPCIAddress *get_pci_info(char
> *guid,
> > Error **errp)
> >   char *buffer = NULL;
> >   GuestPCIAddress *pci = NULL;
> >   char *name = g_strdup([4]);
> > +pci = g_malloc0(sizeof(*pci));
> > +pci->domain = -1;
> > +pci->slot = -1;
> > +pci->function = -1;
> > +pci->bus = -1;
> >
> >
> > Right now, we have:
> >
> > ##
> > # @GuestDiskAddress:
> > #
> > # @pci-controller: controller's PCI address
> > # @bus-type: bus type
> > # @bus: bus id
> > # @target: target id
> > # @unit: unit id
> > #
> > # Since: 2.2
> > ##
> > { 'struct': 'GuestDiskAddress',
> >   'data': {'pci-controller': 'GuestPCIAddress',
> >'bus-type': 'GuestDiskBusType',
> >'bus': 'int', 'target': 'int', 'unit': 'int'} }
> >
> > and the problem you ran into is that under certain conditions, we
> have no
> > idea what to populate in GuestPCIAddress.  Your patch populates
> garbage
> > instead; but I'm wondering if it would be better to instead mark
> > pci-controller as optional, where code that CAN populate it would set
> > has_pci_controller=true, and the code that crashed will now work by
> leaving
> > the struct NULL (and has_pci_controller=false).  But that removes
> output
> > that the client may expect to be present, hence, this is a
> back-compat
> > question of the best way to approach this.
> >
> > Since all of the fields are ints, I believe that "-1" is very
> informative even
> > though I don't like this approach but it does preserve backward
> compatibility
> > as you've already clarified.
> >
> > I don't want to assume anything but this bug has been laying around for
> quite a
> > while and no one complained, moreover,  the disk option is not enabled by
> > default in upstream code so I don't think that backward compatibility is
> > actually disturbed but then again this

Re: [Qemu-devel] [PATCH 1/2] qga-win: prevent crash when executing fsinfo command

2018-06-28 Thread Sameeh Jubran
On Fri, Jun 29, 2018 at 12:44 AM, Eric Blake  wrote:

> On 06/26/2018 10:10 AM, Sameeh Jubran wrote:
>
>> From: Sameeh Jubran 
>>
>> The fsinfo command is currently implemented for Windows only and it's disk
>> parameter can be enabled by adding the define "CONFIG_QGA_NTDDSCSI" to
>> the qga
>> code. When enabled and executed the qemu-ga crashed with the following
>> message:
>>
>> 
>> File qapi/qapi-visit-core.c, Line 49
>>
>> Expression: !(v->type & VISITOR_OUTPUT) || *obj)
>> 
>>
>> After some digging, turns out that the GuestPCIAddress is null and the
>> qapi visitor doesn't like that, so we can always allocate it instead and
>> initiate all it's members to -1.
>>
>
> Adding Markus for a qapi back-compat question.
>
> Is faking an invalid address better than making the output optional
> instead?
>
> +++ b/qga/commands-win32.c
>> @@ -485,6 +485,11 @@ static GuestPCIAddress *get_pci_info(char *guid,
>> Error **errp)
>>   char *buffer = NULL;
>>   GuestPCIAddress *pci = NULL;
>>   char *name = g_strdup([4]);
>> +pci = g_malloc0(sizeof(*pci));
>> +pci->domain = -1;
>> +pci->slot = -1;
>> +pci->function = -1;
>> +pci->bus = -1;
>>
>
> Right now, we have:
>
> ##
> # @GuestDiskAddress:
> #
> # @pci-controller: controller's PCI address
> # @bus-type: bus type
> # @bus: bus id
> # @target: target id
> # @unit: unit id
> #
> # Since: 2.2
> ##
> { 'struct': 'GuestDiskAddress',
>   'data': {'pci-controller': 'GuestPCIAddress',
>'bus-type': 'GuestDiskBusType',
>'bus': 'int', 'target': 'int', 'unit': 'int'} }
>
> and the problem you ran into is that under certain conditions, we have no
> idea what to populate in GuestPCIAddress.  Your patch populates garbage
> instead; but I'm wondering if it would be better to instead mark
> pci-controller as optional, where code that CAN populate it would set
> has_pci_controller=true, and the code that crashed will now work by leaving
> the struct NULL (and has_pci_controller=false).  But that removes output
> that the client may expect to be present, hence, this is a back-compat
> question of the best way to approach this.

Since all of the fields are ints, I believe that "-1" is very informative
even though I don't like this approach but it does preserve backward
compatibility as you've already clarified.

I don't want to assume anything but this bug has been laying around for
quite a while and no one complained, moreover,  the disk option is not
enabled by default in upstream code so I don't think that backward
compatibility is actually disturbed but then again this is just an
assumption.

One more thing to consider is the second patch of this series which
actually was the root cause of why we didn't allocate the " GuestDiskAddress"
struct which is some registry keys being absent for the specific device
which would leave us with two options:
1. Don not return anything for all of the fields (leave it null)
2. Return partial information
I think that the second option is preferable for obvious reasons.

I am not that familiar with schema files, but it is possible to make int
fields optional too?

I can live with either approaches, maintainers, it's your call :)

Thanks for the review!

>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH 2/2] qga-win: fsinfo: pci-info: allow partial info

2018-06-26 Thread Sameeh Jubran
From: Sameeh Jubran 

The call to SetupDiGetDeviceRegistryProperty might fail because the
value doesn't exist in the registry, in this case we shouldn't exit from
the loop but instead continue to look for other available values in the
registry and set this value as unavailable (-1).

Signed-off-by: Sameeh Jubran 
---
 qga/commands-win32.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index c5f1c884e1..55e460dee3 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -505,7 +505,8 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
**errp)
 
 dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
 for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, _info_data); i++) {
-DWORD addr, bus, slot, func, dev, data, size2;
+DWORD addr, bus, slot, data, size2;
+int func, dev;
 while (!SetupDiGetDeviceRegistryProperty(dev_info, _info_data,
 SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,
 , (PBYTE)buffer, size,
@@ -535,21 +536,21 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
**errp)
  */
 if (!SetupDiGetDeviceRegistryProperty(dev_info, _info_data,
SPDRP_BUSNUMBER, , (PBYTE), size, NULL)) {
-break;
+bus = -1;
 }
 
 /* The function retrieves the device's address. This value will be
  * transformed into device function and number */
 if (!SetupDiGetDeviceRegistryProperty(dev_info, _info_data,
SPDRP_ADDRESS, , (PBYTE), size, NULL)) {
-break;
+addr = -1;
 }
 
 /* This call returns UINumber of DEVICE_CAPABILITIES structure.
  * This number is typically a user-perceived slot number. */
 if (!SetupDiGetDeviceRegistryProperty(dev_info, _info_data,
SPDRP_UI_NUMBER, , (PBYTE), size, NULL)) {
-break;
+slot = -1;
 }
 
 /* SetupApi gives us the same information as driver with
@@ -559,12 +560,12 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
**errp)
  * DeviceNumber = (USHORT)(((propertyAddress) >> 16) & 0x);
  * SPDRP_ADDRESS is propertyAddress, so we do the same.*/
 
-func = addr & 0x;
-dev = (addr >> 16) & 0x;
+func = ((int) addr == -1) ? -1 : addr & 0x;
+dev = ((int) addr == -1) ? -1 : (addr >> 16) & 0x;
 pci->domain = dev;
-pci->slot = slot;
+pci->slot = (int) slot;
 pci->function = func;
-pci->bus = bus;
+pci->bus = (int) bus;
 break;
 }
 
-- 
2.13.6




[Qemu-devel] [PATCH 1/2] qga-win: prevent crash when executing fsinfo command

2018-06-26 Thread Sameeh Jubran
From: Sameeh Jubran 

The fsinfo command is currently implemented for Windows only and it's disk
parameter can be enabled by adding the define "CONFIG_QGA_NTDDSCSI" to the qga
code. When enabled and executed the qemu-ga crashed with the following message:


File qapi/qapi-visit-core.c, Line 49

Expression: !(v->type & VISITOR_OUTPUT) || *obj)


After some digging, turns out that the GuestPCIAddress is null and the
qapi visitor doesn't like that, so we can always allocate it instead and
initiate all it's members to -1.

Signed-off-by: Sameeh Jubran 
---
 qga/commands-win32.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2d48394748..c5f1c884e1 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -485,6 +485,11 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
**errp)
 char *buffer = NULL;
 GuestPCIAddress *pci = NULL;
 char *name = g_strdup([4]);
+pci = g_malloc0(sizeof(*pci));
+pci->domain = -1;
+pci->slot = -1;
+pci->function = -1;
+pci->bus = -1;
 
 if (!QueryDosDevice(name, dev_name, ARRAY_SIZE(dev_name))) {
 error_setg_win32(errp, GetLastError(), "failed to get dos device 
name");
@@ -556,7 +561,6 @@ static GuestPCIAddress *get_pci_info(char *guid, Error 
**errp)
 
 func = addr & 0x;
 dev = (addr >> 16) & 0x;
-pci = g_malloc0(sizeof(*pci));
 pci->domain = dev;
 pci->slot = slot;
 pci->function = func;
-- 
2.13.6




[Qemu-devel] [PATCH 0/2] prevent qga from crashing

2018-06-26 Thread Sameeh Jubran
From: Sameeh Jubran 

The following patch series fixes an issue with fsinfo command of qemu-ga
on Windows which leads to crash of qga when the disk paramter is
enabled.

Sameeh Jubran (2):
  qga-win: prevent crash when executing fsinfo command
  qga-win: fsinfo: pci-info: allow partial info

 qga/commands-win32.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

-- 
2.13.6




Re: [Qemu-devel] [RFC v2 2/2] virtio-net: Example Patch for using BPF

2018-06-25 Thread Sameeh Jubran
On Mon, Jun 25, 2018 at 2:22 PM, Daniel P. Berrangé 
wrote:

> On Mon, Jun 25, 2018 at 02:07:06PM +0300, Sameeh Jubran wrote:
> > From: Sameeh Jubran 
> >
> > This commit is a sample only for using the libbpf in the code and
> > shouldn't be committed.
> >
> > Signed-off-by: Sameeh Jubran 
> > ---
> >  hw/net/Makefile.objs | 4 
> >  hw/net/virtio-net.c  | 4 
> >  2 files changed, 8 insertions(+)
> >
> > diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
> > index fa461d4463..0fb271436d 100644
> > --- a/hw/net/Makefile.objs
> > +++ b/hw/net/Makefile.objs
> > @@ -37,6 +37,10 @@ obj-$(CONFIG_PSERIES) += spapr_llan.o
> >  obj-$(CONFIG_XILINX_ETHLITE) += xilinx_ethlite.o
> >
> >  obj-$(CONFIG_VIRTIO_NET) += virtio-net.o
> > +ifeq ($(CONFIG_BPF),y)
> > + virtio-net.o-cflags := $(CFLAGS_BPF)
> > + virtio-net.o-libs := $(LIBS_BPF)
> > +endif
> >  obj-y += vhost_net.o
> >
> >  obj-$(CONFIG_ETSEC) += fsl_etsec/etsec.o fsl_etsec/registers.o \
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 90502fca7c..b4840838c1 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -27,6 +27,7 @@
> >  #include "hw/virtio/virtio-access.h"
> >  #include "migration/misc.h"
> >  #include "standard-headers/linux/ethtool.h"
> > +#include "standard-headers/linux/libbpf.h"
> >
> >  #define VIRTIO_NET_VM_VERSION11
> >
> > @@ -1329,6 +1330,9 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue
> *q)
> >  VirtQueueElement *elem;
> >  int32_t num_packets = 0;
> >  int queue_index = vq2q(virtio_get_queue_index(q->tx_vq));
> > +
> > +struct bpf_object *obj = NULL;
> > +bpf_object__load(obj);
>
> This really doesn't tell us anything useful about how this will be
> used and integrated in qemu. I'd expect this patch to actually
> be doing a real feature complete impl of RSS for virtio-net.
>
No problem, I'll be sending the full series ASAP,
Thanks :)

>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/
> dberrange :|
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [RFC v2 0/2] Add BPF suuport to Qemu

2018-06-25 Thread Sameeh Jubran
On Mon, Jun 25, 2018 at 2:16 PM, Peter Maydell 
wrote:

> On 25 June 2018 at 12:07, Sameeh Jubran  wrote:
> > From: Sameeh Jubran 
> >
> > The Berkeley Packet Filter has been in the kernel for a while now and I
> > think it is time that it is introduced to Qemu. This patch is an
> > infrastructure for any future usage of the BPF in Qemu.
> >
> > It is important to note that the tun driver had started supporting using
> > BPF programs through ioctls (TUNSETSTEERINGEBPF and TUNSETFILTEREBPF).
> > My plan is to use the bpf support from within virtio-net in order to set
> > a bpf steering program to the tun device which would allow virtio-net to
> > support RSS feature https://lists.oasis-open.org/
> archives/virtio-dev/201805/msg00024.html
> >
> > Difference from v1:
> > * Used libbpf library provided by linux
> > * Added a configure option
> > * Added a sample patch with demonstrates how to use the libbpf library
> >   from within virtio-net. This patch should not be applied! It is for
> >   demonstration purposes only
> >
> > The libbpf can be manually installed from the Linux source tree by
> running make
> > tools/bpf and make tools/bpf_install from the top level directory.
>
> I'm afraid this series still doesn't have a real use case for the
> library, which is what we would need to be able to review whether
> using BPF is a sensible design for whatever the underlying
> feature to be implemented is. That is, what you should be sending
> is "here is a patchset to implement RSS in virtio-net (and it
> happens to be implemented using BPF)", not "here is a patchset
> which links QEMU with libbpf and does nothing else".
>
I don't think the infrastructure should be coupled with the implementation.
These are two separate patch sets, however I can combine them to one.

>
> thanks
> -- PMM
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [RFC v2 1/2] Add bpf support to qemu

2018-06-25 Thread Sameeh Jubran
From: Sameeh Jubran 

This commit adds the libbpf library provided by Linux to Qemu.

Signed-off-by: Sameeh Jubran 
---
 MAINTAINERS |6 +
 configure   |   46 +
 include/standard-headers/linux/libbpf.h |  284 
 linux-headers/linux/bpf.h   | 2669 +++
 scripts/update-linux-headers.sh |   11 +-
 5 files changed, 3013 insertions(+), 3 deletions(-)
 create mode 100644 include/standard-headers/linux/libbpf.h
 create mode 100644 linux-headers/linux/bpf.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb5f38f9f..341dd3e1d9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2126,6 +2126,12 @@ F: hw/rdma/*
 F: hw/rdma/vmw/*
 F: docs/pvrdma.txt
 
+BPF
+M: Sameeh Jubran 
+S: Maintained
+F: linux-headers/linux/bpf.h
+F: include/standard-headers/linux/libbpf.h
+
 Build and test automation
 -
 Build and test automation
diff --git a/configure b/configure
index a8c4094c87..8140f9b6a9 100755
--- a/configure
+++ b/configure
@@ -348,6 +348,7 @@ libattr=""
 xfs=""
 tcg="yes"
 membarrier=""
+bpf="no"
 vhost_net="no"
 vhost_crypto="no"
 vhost_scsi="no"
@@ -1173,6 +1174,10 @@ for opt do
   ;;
   --enable-membarrier) membarrier="yes"
   ;;
+  --disable-bpf) bpf="no"
+  ;;
+  --enable-bpf) bpf="yes"
+  ;;
   --disable-blobs) blobs="no"
   ;;
   --with-pkgversion=*) pkgversion="$optarg"
@@ -1593,6 +1598,7 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   brlapi  BrlAPI (Braile)
   curlcurl connectivity
   membarrier  membarrier system call (for Linux 4.14+ or Windows)
+  bpf bpf system calls (for Linux 3.18+)
   fdt fdt device tree
   bluez   bluez stack connectivity
   kvm KVM acceleration support
@@ -5232,6 +5238,40 @@ else
 fi
 
 ##
+# check for usable bpf system call
+if test "$bpf" = "yes"; then
+have_bpf=no
+if test "$linux" = "yes" ; then
+cat > $TMPC << EOF
+#include 
+#include "libbpf.h"
+#include 
+#include 
+#include 
+int main(void) {
+union bpf_attr * attr = NULL;
+struct bpf_object * obj = NULL;
+syscall(__NR_bpf, BPF_PROG_LOAD, attr, sizeof(attr));
+   bpf_object__load(obj);
+exit(0);
+}
+EOF
+bpf_include="-Iinclude/standard-headers/linux/"
+bpf_cflags=""
+bpf_libs="-lelf -lbpf"
+if compile_prog "$bpf_include" "$bpf_libs" ; then
+have_bpf=yes
+fi
+fi
+if test "$have_bpf" = "no"; then
+  feature_not_found "bpf" "libbpf/libelf libs are not available or else \
+the bpf system call is not available"
+fi
+else
+bpf=no
+fi
+
+##
 # check if rtnetlink.h exists and is useful
 have_rtnetlink=no
 cat > $TMPC << EOF
@@ -5871,6 +5911,7 @@ echo "malloc trim support $malloc_trim"
 echo "RDMA support  $rdma"
 echo "fdt support   $fdt"
 echo "membarrier$membarrier"
+echo "bpf   $bpf"
 echo "preadv support$preadv"
 echo "fdatasync $fdatasync"
 echo "madvise   $madvise"
@@ -6365,6 +6406,11 @@ fi
 if test "$membarrier" = "yes" ; then
   echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
 fi
+if test "$bpf" = "yes" ; then
+  echo "CONFIG_BPF=y" >> $config_host_mak
+  echo "LIBS_BPF=$bpf_libs" >> $config_host_mak
+  echo "CFLAGS_BPF=$bpf_cflags" >> $config_host_mak
+fi
 if test "$signalfd" = "yes" ; then
   echo "CONFIG_SIGNALFD=y" >> $config_host_mak
 fi
diff --git a/include/standard-headers/linux/libbpf.h 
b/include/standard-headers/linux/libbpf.h
new file mode 100644
index 00..1931a07b98
--- /dev/null
+++ b/include/standard-headers/linux/libbpf.h
@@ -0,0 +1,284 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+
+/*
+ * Common eBPF ELF object loading operations.
+ *
+ * Copyright (C) 2013-2015 Alexei Starovoitov 
+ * Copyright (C) 2015 Wang Nan 
+ * Copyright (C) 2015 Huawei Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License (not later!)
+ *
+ * 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 Lesser General Public Licen

[Qemu-devel] [RFC v2 2/2] virtio-net: Example Patch for using BPF

2018-06-25 Thread Sameeh Jubran
From: Sameeh Jubran 

This commit is a sample only for using the libbpf in the code and
shouldn't be committed.

Signed-off-by: Sameeh Jubran 
---
 hw/net/Makefile.objs | 4 
 hw/net/virtio-net.c  | 4 
 2 files changed, 8 insertions(+)

diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
index fa461d4463..0fb271436d 100644
--- a/hw/net/Makefile.objs
+++ b/hw/net/Makefile.objs
@@ -37,6 +37,10 @@ obj-$(CONFIG_PSERIES) += spapr_llan.o
 obj-$(CONFIG_XILINX_ETHLITE) += xilinx_ethlite.o
 
 obj-$(CONFIG_VIRTIO_NET) += virtio-net.o
+ifeq ($(CONFIG_BPF),y)
+   virtio-net.o-cflags := $(CFLAGS_BPF)
+   virtio-net.o-libs := $(LIBS_BPF)
+endif
 obj-y += vhost_net.o
 
 obj-$(CONFIG_ETSEC) += fsl_etsec/etsec.o fsl_etsec/registers.o \
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 90502fca7c..b4840838c1 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -27,6 +27,7 @@
 #include "hw/virtio/virtio-access.h"
 #include "migration/misc.h"
 #include "standard-headers/linux/ethtool.h"
+#include "standard-headers/linux/libbpf.h"
 
 #define VIRTIO_NET_VM_VERSION11
 
@@ -1329,6 +1330,9 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
 VirtQueueElement *elem;
 int32_t num_packets = 0;
 int queue_index = vq2q(virtio_get_queue_index(q->tx_vq));
+
+struct bpf_object *obj = NULL;
+bpf_object__load(obj);
 if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
 return num_packets;
 }
-- 
2.13.6




[Qemu-devel] [RFC v2 0/2] Add BPF suuport to Qemu

2018-06-25 Thread Sameeh Jubran
From: Sameeh Jubran 

The Berkeley Packet Filter has been in the kernel for a while now and I
think it is time that it is introduced to Qemu. This patch is an
infrastructure for any future usage of the BPF in Qemu.

It is important to note that the tun driver had started supporting using
BPF programs through ioctls (TUNSETSTEERINGEBPF and TUNSETFILTEREBPF).
My plan is to use the bpf support from within virtio-net in order to set
a bpf steering program to the tun device which would allow virtio-net to
support RSS feature 
https://lists.oasis-open.org/archives/virtio-dev/201805/msg00024.html

Difference from v1:
* Used libbpf library provided by linux
* Added a configure option
* Added a sample patch with demonstrates how to use the libbpf library
  from within virtio-net. This patch should not be applied! It is for
  demonstration purposes only

The libbpf can be manually installed from the Linux source tree by running make
tools/bpf and make tools/bpf_install from the top level directory.

Please share your thoughts :)

v1 - https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg05307.html

Sameeh Jubran (2):
  Add bpf support to qemu
  virtio-net: Example Patch for using BPF

 MAINTAINERS |6 +
 configure   |   46 +
 hw/net/Makefile.objs|4 +
 hw/net/virtio-net.c |4 +
 include/standard-headers/linux/libbpf.h |  284 
 linux-headers/linux/bpf.h   | 2669 +++
 scripts/update-linux-headers.sh |   11 +-
 7 files changed, 3021 insertions(+), 3 deletions(-)
 create mode 100644 include/standard-headers/linux/libbpf.h
 create mode 100644 linux-headers/linux/bpf.h

-- 
2.13.6




[Qemu-devel] [PATCH] qga-win: Handle fstrim for OSes lower than Win8

2018-06-24 Thread Sameeh Jubran
From: Sameeh Jubran 

The defrag.exe tool which is used for executing the fstrim command
on Windows doesn't support retrim for OSes lower than Win8. This
commit handles this case and returns a suitable error.

Output of fstrim before this commit:
{"execute":"guest-fstrim"}
{"return": {"paths": [{"path": "C:\\", "error": "An invalid command line option
was specified. (0x8908)"}, {"path": "F:\\", "error": "An invalid command
line option was specified. (0x8908)"}, {"path": "S:\\", "error": "An
invalid command line option was specified. (0x8908)"}]}}

Reported on:
https://bugzilla.redhat.com/show_bug.cgi?id=1594113

Signed-off-by: Sameeh Jubran 
---
 qga/commands-win32.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d79974f212..0bdcd9dd38 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "qga/guest-agent-core.h"
 #include "qga/vss-win32.h"
@@ -852,6 +853,11 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error 
**errp)
 HANDLE handle;
 WCHAR guid[MAX_PATH] = L"";
 
+   if (!IsWindows8OrGreater()) {
+error_setg(errp, "fstrim is only supported for Win8+");
+return NULL;
+   }
+
 handle = FindFirstVolumeW(guid, ARRAYSIZE(guid));
 if (handle == INVALID_HANDLE_VALUE) {
 error_setg_win32(errp, GetLastError(), "failed to find any volume");
-- 
2.13.6




Re: [Qemu-devel] [RFC 0/1] Add BPF suuport to Qemu

2018-06-20 Thread Sameeh Jubran
On Wed, Jun 20, 2018 at 11:34 AM, Daniel P. Berrangé 
wrote:

> On Tue, Jun 19, 2018 at 05:37:10PM +0300, Sameeh Jubran wrote:
> > This patch is actually a preparation for an upcoming patch set that I
> want
> > to integrate into virtio-net which implements the RSS feature. (
> > https://lists.oasis-open.org/archives/virtio-dev/201805/msg00024.html)
> > So there is a use case. The rationale behind this is to distinguish the
> > infrastructure preparation needed for the BPF from the actual RSS feature
> > implementation.
>
> Ah, so IIUC, that is not actually doing network filtering, rather it is
> some performance related feature than happens to make of use of BPF.
>
> I think it is be important to submit code changes for the virtio driver
> at the same time, so we can properly understand the interface and usage
> model exposed to the user CLI (if any).
>
I understand, but I thought about adding the bpf support in an elegant way
that might serve others in the future.

>
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/
> dberrange :|
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [RFC 0/1] Add BPF suuport to Qemu

2018-06-20 Thread Sameeh Jubran
On Wed, Jun 20, 2018 at 11:13 AM, Jason Wang  wrote:

>
>
> On 2018年06月19日 21:21, Sameeh Jubran wrote:
>
>> From: Sameeh Jubran 
>>
>> The Berkeley Packet Filter has been in the kernel for a while now and I
>> think it is time that it is introduced to Qemu. This patch is an
>> infrastructure for any future usage of the BPF in Qemu.
>>
>> It is important to note that the tun driver had started supporting using
>> BPF programs through ioctls (TUNSETSTEERINGEBPF and TUNSETFILTEREBPF).
>>
>> At first, instead of adding the syscall wrappers, I wanted to integrate
>> libbpf
>> library which resides in the Linux source tree under tools/lib/bpf. It
>> appears
>> to be that by default it compiles to x64 on x64 arch - which can't be
>> integrated into Qemu  - and my attempts to compile the 32 bit versions
>> have
>> failed. What's more interesting is that the vendors don't provide this
>> library
>> in any package, which makes this library a nasty dependency.
>>
>> Please share your thoughts :)
>>
>
> I wonder, instead of a generic eBPF support, can we have a limited but
> sufficient eBPF suppor for TAP only (see dpdk tap driver)? E.g if we only
> do bytecode loading, there's no need for e.g map update helpers.
>
That can do, I am actually using the map update helpers in the code as I am
using it to pass RSS configuration to the kernel program. The motive behind
adding the code this way is to add it as an infrastructure that others can
use in the future.

BTW I think I made a mistake, as it turns out I can add libbpf and it is
much neater than adding the syscall wrappers this way as the code is taken
straight from the linux kernel and can be updated easily using the
scripts's tool - update-linux-headers.sh. I'll prepare the patches and send
them soon.

>
> Thanks
>
>
>
>> Sameeh Jubran (1):
>>Add BPF support to qemu
>>
>>   MAINTAINERS |   7 +
>>   bpf/Makefile.objs   |   1 +
>>   bpf/bpf_syscall.c   |  98 ++
>>   include/bpf/bpf_syscall.h   |  35 +++
>>   linux-headers/linux/bpf.h   | 673 ++
>> ++
>>   scripts/update-linux-headers.sh |   3 +-
>>   6 files changed, 816 insertions(+), 1 deletion(-)
>>   create mode 100644 bpf/Makefile.objs
>>   create mode 100644 bpf/bpf_syscall.c
>>   create mode 100644 include/bpf/bpf_syscall.h
>>   create mode 100644 linux-headers/linux/bpf.h
>>
>>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [RFC 1/1] Add BPF support to qemu

2018-06-19 Thread Sameeh Jubran
On Tue, Jun 19, 2018 at 5:41 PM, Murilo Opsfelder Araujo <
muri...@linux.ibm.com> wrote:

> On Tue, Jun 19, 2018 at 04:22:00PM +0300, Sameeh Jubran wrote:
> > From: Sameeh Jubran 
> >
> > This commit introduces wrappers around BPF syscalls to qemu. The Berkeley
> > Packet Filter (BPF) can be really usefull for packet filtering, tracing
> and
> > monitoring with very minimal overhead.
> >
> > Signed-off-by: Sameeh Jubran 
> > ---
> >  MAINTAINERS |   7 +
> >  bpf/Makefile.objs   |   1 +
> >  bpf/bpf_syscall.c   |  98 ++
> >  include/bpf/bpf_syscall.h   |  35 +++
> >  linux-headers/linux/bpf.h   | 673 ++
> ++
> >  scripts/update-linux-headers.sh |   3 +-
> >  6 files changed, 816 insertions(+), 1 deletion(-)
> >  create mode 100644 bpf/Makefile.objs
> >  create mode 100644 bpf/bpf_syscall.c
> >  create mode 100644 include/bpf/bpf_syscall.h
> >  create mode 100644 linux-headers/linux/bpf.h
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 0fb5f38f9f..ce3cd39121 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -2126,6 +2126,13 @@ F: hw/rdma/*
> >  F: hw/rdma/vmw/*
> >  F: docs/pvrdma.txt
> >
> > +
> > +BPF
> > +M: Sameeh Jubran 
> > +S: Maintained
> > +F: bpf/*
> > +F: include/bpf*
> > +
> >  Build and test automation
> >  -
> >  Build and test automation
> > diff --git a/bpf/Makefile.objs b/bpf/Makefile.objs
> > new file mode 100644
> > index 00..fc38d9b5c9
> > --- /dev/null
> > +++ b/bpf/Makefile.objs
> > @@ -0,0 +1 @@
> > +common-obj-y += bpf_syscall.o
>
> Why do we need to have this enabled by default?
>
> IMO, this should be configurable.  For example, adding a new --enable-bpf
> to the
> ./configure script and accessing it via $(CONFIG_BPF) variable in
> Makefiles.  Or
> something among these lines.

I agree, I did this as an RFC only. I will change that when I'll send v1 :)
Thanks!

>
> > diff --git a/bpf/bpf_syscall.c b/bpf/bpf_syscall.c
> > new file mode 100644
> > index 00..efdcd57ae8
> > --- /dev/null
> > +++ b/bpf/bpf_syscall.c
> > @@ -0,0 +1,98 @@
> > +/*
> > + * BPF syscalls
> > + *
> > + * Based on bpf-syscall.c from iovisor/ply
> > + *
> > + * Authors:
> > + *  Sameeh Jubran 
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2.  See
> > + * the COPYING file in the top-level directory.
> > + *
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "bpf/bpf_syscall.h"
> > +
> > +static __u64 ptr_to_u64(const void *ptr)
> > +{
> > +return (__u64) (unsigned long) ptr;
> > +}
> > +
> > +int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
> > +int insn_cnt, const char *license, unsigned
> kern_version,
> > +int log_level, char *bpf_log_buf, unsigned log_buf_size)
> > +{
> > +union bpf_attr attr;
> > +
> > +/* required since the kernel checks that unused fields and pad
> > + * bytes are zeroed */
> > +memset(, 0, sizeof(attr));
> > +
> > +attr.kern_version = kern_version;
> > +attr.prog_type= type;
> > +attr.insns= ptr_to_u64(insns);
> > +attr.insn_cnt = insn_cnt;
> > +attr.license  = ptr_to_u64(license);
> > +attr.log_buf  = ptr_to_u64(bpf_log_buf);
> > +attr.log_size = log_buf_size;
> > +attr.log_level= log_level;
> > +
> > +return syscall(__NR_bpf, BPF_PROG_LOAD, , sizeof(attr));
> > +}
> > +
> > +int bpf_map_create(enum bpf_map_type type, int key_size, int val_size,
> > +int entries)
> > +{
> > +union bpf_attr attr;
> > +
> > +/* required since the kernel checks that unused fields and pad
> > + * bytes are zeroed */
> > +memset(, 0, sizeof(attr));
> > +
> > +attr.map_type = type;
> > +attr.key_size = key_size;
> > +attr.value_size = val_size;
> > +attr.max_entries = entries;
> > +
> > +return syscall(__NR_bpf, BPF_MAP_CREATE, , sizeof(attr));
> > +}
> > +
> > +
> > +static int bpf_map_operation(enum bpf_cmd cmd, int fd,
> > +  void *key, void *val_or_next, int flags)
> > +{
> > +union bpf_attr

Re: [Qemu-devel] [RFC 0/1] Add BPF suuport to Qemu

2018-06-19 Thread Sameeh Jubran
This patch is actually a preparation for an upcoming patch set that I want
to integrate into virtio-net which implements the RSS feature. (
https://lists.oasis-open.org/archives/virtio-dev/201805/msg00024.html)
So there is a use case. The rationale behind this is to distinguish the
infrastructure preparation needed for the BPF from the actual RSS feature
implementation.

On Tue, Jun 19, 2018 at 4:49 PM, Daniel P. Berrangé 
wrote:

> On Tue, Jun 19, 2018 at 04:21:59PM +0300, Sameeh Jubran wrote:
> > From: Sameeh Jubran 
> >
> > The Berkeley Packet Filter has been in the kernel for a while now and I
> > think it is time that it is introduced to Qemu. This patch is an
> > infrastructure for any future usage of the BPF in Qemu.
> >
> > It is important to note that the tun driver had started supporting using
> > BPF programs through ioctls (TUNSETSTEERINGEBPF and TUNSETFILTEREBPF).
> >
> > At first, instead of adding the syscall wrappers, I wanted to integrate
> libbpf
> > library which resides in the Linux source tree under tools/lib/bpf. It
> appears
> > to be that by default it compiles to x64 on x64 arch - which can't be
> > integrated into Qemu  - and my attempts to compile the 32 bit versions
> have
> > failed. What's more interesting is that the vendors don't provide this
> library
> > in any package, which makes this library a nasty dependency.
> >
> > Please share your thoughts :)
>
> IMHO there should be example usage illustrated for some part of QEMU
> before we add any general infrastructure, as you can't really do a
> useful design evaluation without understanding its usage.
>
> It isn't clear that QEMU is neccessarily the best place to even do it, if
> the intended usage is to provide network traffic firewalling for guest
> NICs. eg libvirt already provides a firewalling system based on iptables,
> that could have an BPFilter implementation added to it.
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/
> dberrange :|
> |: https://libvirt.org -o-
> https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/
> dberrange :|
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [RFC 1/1] Add BPF support to qemu

2018-06-19 Thread Sameeh Jubran
From: Sameeh Jubran 

This commit introduces wrappers around BPF syscalls to qemu. The Berkeley
Packet Filter (BPF) can be really usefull for packet filtering, tracing and
monitoring with very minimal overhead.

Signed-off-by: Sameeh Jubran 
---
 MAINTAINERS |   7 +
 bpf/Makefile.objs   |   1 +
 bpf/bpf_syscall.c   |  98 ++
 include/bpf/bpf_syscall.h   |  35 +++
 linux-headers/linux/bpf.h   | 673 
 scripts/update-linux-headers.sh |   3 +-
 6 files changed, 816 insertions(+), 1 deletion(-)
 create mode 100644 bpf/Makefile.objs
 create mode 100644 bpf/bpf_syscall.c
 create mode 100644 include/bpf/bpf_syscall.h
 create mode 100644 linux-headers/linux/bpf.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb5f38f9f..ce3cd39121 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2126,6 +2126,13 @@ F: hw/rdma/*
 F: hw/rdma/vmw/*
 F: docs/pvrdma.txt
 
+
+BPF
+M: Sameeh Jubran 
+S: Maintained
+F: bpf/*
+F: include/bpf*
+
 Build and test automation
 -
 Build and test automation
diff --git a/bpf/Makefile.objs b/bpf/Makefile.objs
new file mode 100644
index 00..fc38d9b5c9
--- /dev/null
+++ b/bpf/Makefile.objs
@@ -0,0 +1 @@
+common-obj-y += bpf_syscall.o
diff --git a/bpf/bpf_syscall.c b/bpf/bpf_syscall.c
new file mode 100644
index 00..efdcd57ae8
--- /dev/null
+++ b/bpf/bpf_syscall.c
@@ -0,0 +1,98 @@
+/*
+ * BPF syscalls
+ *
+ * Based on bpf-syscall.c from iovisor/ply
+ *
+ * Authors:
+ *  Sameeh Jubran 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bpf/bpf_syscall.h"
+
+static __u64 ptr_to_u64(const void *ptr)
+{
+return (__u64) (unsigned long) ptr;
+}
+
+int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+int insn_cnt, const char *license, unsigned kern_version,
+int log_level, char *bpf_log_buf, unsigned log_buf_size)
+{
+union bpf_attr attr;
+
+/* required since the kernel checks that unused fields and pad
+ * bytes are zeroed */
+memset(, 0, sizeof(attr));
+
+attr.kern_version = kern_version;
+attr.prog_type= type;
+attr.insns= ptr_to_u64(insns);
+attr.insn_cnt = insn_cnt;
+attr.license  = ptr_to_u64(license);
+attr.log_buf  = ptr_to_u64(bpf_log_buf);
+attr.log_size = log_buf_size;
+attr.log_level= log_level;
+
+return syscall(__NR_bpf, BPF_PROG_LOAD, , sizeof(attr));
+}
+
+int bpf_map_create(enum bpf_map_type type, int key_size, int val_size,
+int entries)
+{
+union bpf_attr attr;
+
+/* required since the kernel checks that unused fields and pad
+ * bytes are zeroed */
+memset(, 0, sizeof(attr));
+
+attr.map_type = type;
+attr.key_size = key_size;
+attr.value_size = val_size;
+attr.max_entries = entries;
+
+return syscall(__NR_bpf, BPF_MAP_CREATE, , sizeof(attr));
+}
+
+
+static int bpf_map_operation(enum bpf_cmd cmd, int fd,
+  void *key, void *val_or_next, int flags)
+{
+union bpf_attr attr =  {
+.map_fd = fd,
+.key = ptr_to_u64(key),
+.value = ptr_to_u64(val_or_next),
+.flags = flags,
+};
+
+return syscall(__NR_bpf, cmd, , sizeof(attr));
+}
+
+int bpf_map_lookup(int fd, void *key, void *val)
+{
+return bpf_map_operation(BPF_MAP_LOOKUP_ELEM, fd, key, val, 0);
+}
+
+int bpf_map_update(int fd, void *key, void *val, int flags)
+{
+return bpf_map_operation(BPF_MAP_UPDATE_ELEM, fd, key, val, flags);
+}
+
+int bpf_map_delete(int fd, void *key)
+{
+return bpf_map_operation(BPF_MAP_DELETE_ELEM, fd, key, NULL, 0);
+}
+
+int bpf_map_next(int fd, void *key, void *next_key)
+{
+return bpf_map_operation(BPF_MAP_GET_NEXT_KEY, fd, key, next_key, 0);
+}
diff --git a/include/bpf/bpf_syscall.h b/include/bpf/bpf_syscall.h
new file mode 100644
index 00..8d1f170343
--- /dev/null
+++ b/include/bpf/bpf_syscall.h
@@ -0,0 +1,35 @@
+/*
+ * BPF syscalls
+ *
+ * Based on bpf-syscall.h from iovisor/ply
+ *
+ * Authors:
+ *  Sameeh Jubran 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef BPF_SYSCALL_H
+#define BPF_SYSCALL_H
+
+#include 
+
+#include 
+#include 
+#include 
+
+int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+int insn_cnt, const char *license, unsigned kern_version,
+int log_level, char *bpf_log_buf, unsigned log_buf_size);
+
+int bpf_map_create(enum bpf_map_type type, int key_size, int val_size,
+int entries);
+
+int bpf_map_lookup(int fd, void *key, void *val);
+int bpf_map_update(int fd, void *key, void *val, int flags);
+int bpf_map_delete(int fd, void *key);
+int bpf_map_next(int fd, void 

[Qemu-devel] [RFC 0/1] Add BPF suuport to Qemu

2018-06-19 Thread Sameeh Jubran
From: Sameeh Jubran 

The Berkeley Packet Filter has been in the kernel for a while now and I
think it is time that it is introduced to Qemu. This patch is an
infrastructure for any future usage of the BPF in Qemu.

It is important to note that the tun driver had started supporting using
BPF programs through ioctls (TUNSETSTEERINGEBPF and TUNSETFILTEREBPF).

At first, instead of adding the syscall wrappers, I wanted to integrate libbpf
library which resides in the Linux source tree under tools/lib/bpf. It appears
to be that by default it compiles to x64 on x64 arch - which can't be
integrated into Qemu  - and my attempts to compile the 32 bit versions have
failed. What's more interesting is that the vendors don't provide this library
in any package, which makes this library a nasty dependency.

Please share your thoughts :)

Sameeh Jubran (1):
  Add BPF support to qemu

 MAINTAINERS |   7 +
 bpf/Makefile.objs   |   1 +
 bpf/bpf_syscall.c   |  98 ++
 include/bpf/bpf_syscall.h   |  35 +++
 linux-headers/linux/bpf.h   | 673 
 scripts/update-linux-headers.sh |   3 +-
 6 files changed, 816 insertions(+), 1 deletion(-)
 create mode 100644 bpf/Makefile.objs
 create mode 100644 bpf/bpf_syscall.c
 create mode 100644 include/bpf/bpf_syscall.h
 create mode 100644 linux-headers/linux/bpf.h

-- 
2.13.6




Re: [Qemu-devel] [PATCH 0/3]

2018-01-22 Thread Sameeh Jubran
Ping.

On Fri, Oct 27, 2017 at 10:08 AM, Sameeh Jubran <sam...@daynix.com> wrote:

>
>
> On Fri, Oct 27, 2017 at 2:51 AM, Michael Roth <mdr...@linux.vnet.ibm.com>
> wrote:
>
>> Quoting Sameeh Jubran (2017-08-13 10:58:46)
>> > From: Sameeh Jubran <sjub...@redhat.com>
>> >
>> > This series fixes qemu-ga's behaviour upon facing a missing
>> serial/serial
>> > driver by listening to the serial device's events.
>> >
>> > For more info on why this series is needed checkout the commit message
>> > of the third patch and the following bugzilla:
>> https://bugzilla.redhat.com/show_bug.cgi?id=990629.
>> >
>> > Sameeh Jubran (3):
>> >   qga: Channel: Add functions for checking serial status
>> >   qga: main: make qga config and socket activation global
>> >   qga: Prevent qemu-ga exit if serial doesn't exist
>>
>> Hi Sameeh,
>>
>> The event handling stuff is spiffy and could be useful for other use-cases
>> (e.g. cpu/mem hotplug events that can be consumed by management), but
>> since
>> the actual bug here is somewhat of an edge case (we *could* just tell
>> people that installing the agent before virtio-serial drivers is a bug,
>> or that unplugging the agent's communication channel is a bad idea),
>> I'm not too comfortable with adding this much complexity unless there's
>> a stronger argument for it.
>>
> I can relate to your concerns, it is somehow an edge case but I think that
> this
> is the elegant way to handle it instead of just polling forever. This
> patch series
> is more related to Windows than Linux as this edge case is much more common
> on Windows since when the virtio-serial driver is installed sometimes
> usually
> it requires a post-installation reboot and when the system is up, qemu-ga
> runs before
> the virtio-serial driver is fully configured and it fails to load and then
> another reboot is needed.
>
>
>>
>> There's also a couple issues I had with this series as it stands, namely
>> the lack of a ./configure check for udev (which could cause build
>> breakage in some environments), and a lot of spillage of GAConfig into
>> qga/channel-*, which I think could be avoided.
>>
> I think we can use the --retry with linux clients and use the device
> notifications
> API provided by Windows as it is supported since xp.
>
>>
>> I've sent an alternative series that I think we should consider as it
>> uses a much simpler mechanism to implement this support (basically
>> just periodically retrying the channel if it doesn't exist, or if it
>> disappears for whatever reason). I've tested it on Windows, but would
>> be good to confirm that it adequately addresses the use-case you were
>> looking at. Thanks!
>>
> I haven't tested it yet, but I think it might solve the issue. Your series
> is much
> simpler and less intrusive to the code but I don't think this is the right
> approach.
>
>>
>> >
>> >  Makefile|   4 +
>> >  qga/channel-posix.c |  54 ++
>> >  qga/channel-win32.c |  60 +++
>> >  qga/channel.h   |   9 ++
>> >  qga/main.c  | 284 ++
>> --
>> >  qga/service-win32.h |   4 +
>> >  6 files changed, 385 insertions(+), 30 deletions(-)
>> >
>> > --
>> > 2.9.4
>> >
>>
>>
>
>
> --
> Respectfully,
> *Sameeh Jubran*
> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
> *Software Engineer @ Daynix <http://www.daynix.com>.*
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH] qga-win: VSS: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error

2017-11-30 Thread Sameeh Jubran
On Wed, Nov 29, 2017 at 1:17 AM, Michael Roth <mdr...@linux.vnet.ibm.com>
wrote:

> Quoting Sameeh Jubran (2017-11-22 05:30:14)
> > From: Sameeh Jubran <sjub...@redhat.com>
> >
> > We can get VSS_E_PROVIDER_ALREADY_REGISTERED error if for some
> > reason the uninstall of qemu-ga didn't complete successfully.
> > In this case we can try to unregister the component service
> > and attempt to register it again.
> >
> > Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
>
> This might be reasonable either way, but I'm concerned with why the
> uninstall of the VSS provider is failing in the first place. Are
> you seeing this issue with uninstall->install of the MSI package?
>
> If so there's 2 cases I've noticed with that:
>
> a) the VSS_E_PROVIDER_ALREADY_REGISTERED issue when you do the install,
>which currently requires you to run qemu-ga -s vss-uninstall separately
>and then retrying. This one would get fixed with this patch
> b) the DllRegisterServer call just hangs indefinitely. This one wouldn't
>get fixed with this patch and it seems to be the one I see more often on
>Windows 7
>
> I don't yet know the root cause, but both issues seem to have gone away for
> me with this patch:
>
> diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs
> index 5af11627f8..c76b7a39c5 100644
> --- a/qga/installer/qemu-ga.wxs
> +++ b/qga/installer/qemu-ga.wxs
> @@ -81,7 +81,7 @@
>Arguments="-d"
>>
>  
> - Remove="uninstall" Name="QEMU-GA" Wait="no" />
> + Remove="uninstall" Name="QEMU-GA" Wait="yes" />
>
>
>
>
> Does this help in your case as well?
>
Yes it does, thanks!

>
> > ---
> >  qga/vss-win32/install.cpp | 9 +
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> > index 51838eeb26..e7bc5e1d9d 100644
> > --- a/qga/vss-win32/install.cpp
> > +++ b/qga/vss-win32/install.cpp
> > @@ -443,6 +443,15 @@ STDAPI DllRegisterServer(void)
> >   VSS_PROV_SOFTWARE,
> >   const_cast<WCHAR*>(QGA_
> PROVIDER_VERSION),
> >   g_gProviderVersion);
> > +if (hr == (long int) VSS_E_PROVIDER_ALREADY_REGISTERED) {
> > +DllUnregisterServer();
> > +hr = pVssAdmin->RegisterProvider(g_gProviderId,
> CLSID_QGAVSSProvider,
> > + const_cast >(QGA_PROVIDER_LNAME),
> > + VSS_PROV_SOFTWARE,
> > + const_cast >(QGA_PROVIDER_VERSION),
> > + g_gProviderVersion);
> > +}
> > +
> >  if (FAILED(hr)) {
> >  errmsg_dialog(hr, "RegisterProvider failed");
> >  }
> > --
> > 2.13.6
> >
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH] qga-win: VSS: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error

2017-11-22 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

We can get VSS_E_PROVIDER_ALREADY_REGISTERED error if for some
reason the uninstall of qemu-ga didn't complete successfully.
In this case we can try to unregister the component service
and attempt to register it again.

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/vss-win32/install.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index 51838eeb26..e7bc5e1d9d 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -443,6 +443,15 @@ STDAPI DllRegisterServer(void)
  VSS_PROV_SOFTWARE,
  const_cast<WCHAR*>(QGA_PROVIDER_VERSION),
  g_gProviderVersion);
+if (hr == (long int) VSS_E_PROVIDER_ALREADY_REGISTERED) {
+DllUnregisterServer();
+hr = pVssAdmin->RegisterProvider(g_gProviderId, CLSID_QGAVSSProvider,
+ const_cast(QGA_PROVIDER_LNAME),
+ VSS_PROV_SOFTWARE,
+ const_cast(QGA_PROVIDER_VERSION),
+ g_gProviderVersion);
+}
+
 if (FAILED(hr)) {
 errmsg_dialog(hr, "RegisterProvider failed");
 }
-- 
2.13.6




Re: [Qemu-devel] [PATCH 0/3]

2017-10-27 Thread Sameeh Jubran
On Fri, Oct 27, 2017 at 2:51 AM, Michael Roth <mdr...@linux.vnet.ibm.com>
wrote:

> Quoting Sameeh Jubran (2017-08-13 10:58:46)
> > From: Sameeh Jubran <sjub...@redhat.com>
> >
> > This series fixes qemu-ga's behaviour upon facing a missing serial/serial
> > driver by listening to the serial device's events.
> >
> > For more info on why this series is needed checkout the commit message
> > of the third patch and the following bugzilla:
> https://bugzilla.redhat.com/show_bug.cgi?id=990629.
> >
> > Sameeh Jubran (3):
> >   qga: Channel: Add functions for checking serial status
> >   qga: main: make qga config and socket activation global
> >   qga: Prevent qemu-ga exit if serial doesn't exist
>
> Hi Sameeh,
>
> The event handling stuff is spiffy and could be useful for other use-cases
> (e.g. cpu/mem hotplug events that can be consumed by management), but since
> the actual bug here is somewhat of an edge case (we *could* just tell
> people that installing the agent before virtio-serial drivers is a bug,
> or that unplugging the agent's communication channel is a bad idea),
> I'm not too comfortable with adding this much complexity unless there's
> a stronger argument for it.
>
I can relate to your concerns, it is somehow an edge case but I think that
this
is the elegant way to handle it instead of just polling forever. This patch
series
is more related to Windows than Linux as this edge case is much more common
on Windows since when the virtio-serial driver is installed sometimes
usually
it requires a post-installation reboot and when the system is up, qemu-ga
runs before
the virtio-serial driver is fully configured and it fails to load and then
another reboot is needed.


>
> There's also a couple issues I had with this series as it stands, namely
> the lack of a ./configure check for udev (which could cause build
> breakage in some environments), and a lot of spillage of GAConfig into
> qga/channel-*, which I think could be avoided.
>
I think we can use the --retry with linux clients and use the device
notifications
API provided by Windows as it is supported since xp.

>
> I've sent an alternative series that I think we should consider as it
> uses a much simpler mechanism to implement this support (basically
> just periodically retrying the channel if it doesn't exist, or if it
> disappears for whatever reason). I've tested it on Windows, but would
> be good to confirm that it adequately addresses the use-case you were
> looking at. Thanks!
>
I haven't tested it yet, but I think it might solve the issue. Your series
is much
simpler and less intrusive to the code but I don't think this is the right
approach.

>
> >
> >  Makefile|   4 +
> >  qga/channel-posix.c |  54 ++
> >  qga/channel-win32.c |  60 +++
> >  qga/channel.h   |   9 ++
> >  qga/main.c  | 284 ++
> ++++--
> >  qga/service-win32.h |   4 +
> >  6 files changed, 385 insertions(+), 30 deletions(-)
> >
> > --
> > 2.9.4
> >
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [QGA] Bug of qga?

2017-09-12 Thread Sameeh Jubran
Hi Sam,

Can you share the whole python script you use in order to execute the
commands? This wasn't clear from what you've sent earlier, however we
already tried to reproduce the issue using ncat while manually inserting
the JSON strings for the route -n and the ping commands.

Here is the test run:

{"execute":"guest-exec","arguments":{"path":"/sbin/route","arg":["-n"],"capture-output":
true}}
{"return": {"pid": 2628}}
{"execute":"guest-exec","arguments":{"path":"/bin/ping","capture-output":
true }}
{"return": {"pid": 2629}}
{"execute":"guest-exec-status","arguments":{"pid": 2628}}
{"return": {"exitcode": 0, "out-data":
"S2VybmVsIElQIHJvdXRpbmcgdGFibGUKRGVzdGluYXRpb24gICAgIEdhdGV3YXkgICAgICAgICBHZW5tYXNrICAgICAgICAgRmxhZ3MgTWV0cmljIFJlZiAgICBVc2UgSWZhY2UKMC4wLjAuMCAgICAgICAgIDEwLjAuMC4xNTAgICAgICAwLjAuMC4wICAgICAgICAgVUcgICAgMTAwICAgIDAgICAgICAgIDAgZW5zNAoxMC4wLjAuMCAgICAgICAgMC4wLjAuMCAgICAgICAgIDI1NS4yNTUuMC4wICAgICBVICAgICAxMDAgICAgMCAgICAgICAgMCBlbnM0Cg==",
"exited": true}}
{"execute":"guest-exec-status","arguments":{"pid": 2629}}
{"return": {"exitcode": 2, "err-data":
"VXNhZ2U6IHBpbmcgWy1hQWJCZERmaExuT3FyUlV2VjY0XSBbLWMgY291bnRdIFstaSBpbnRlcnZhbF0gWy1JIGludGVyZmFjZV0KICAgICAgICAgICAgWy1tIG1hcmtdIFstTSBwbXR1ZGlzY19vcHRpb25dIFstbCBwcmVsb2FkXSBbLXAgcGF0dGVybl0gWy1RIHRvc10KICAgICAgICAgICAgWy1zIHBhY2tldHNpemVdIFstUyBzbmRidWZdIFstdCB0dGxdIFstVCB0aW1lc3RhbXBfb3B0aW9uXQogICAgICAgICAgICBbLXcgZGVhZGxpbmVdIFstVyB0aW1lb3V0XSBbaG9wMSAuLi5dIGRlc3RpbmF0aW9uClVzYWdlOiBwaW5nIC02IFstYUFiQmREZmhMbk9xclJVdlZdIFstYyBjb3VudF0gWy1pIGludGVydmFsXSBbLUkgaW50ZXJmYWNlXQogICAgICAgICAgICAgWy1sIHByZWxvYWRdIFstbSBtYXJrXSBbLU0gcG10dWRpc2Nfb3B0aW9uXQogICAgICAgICAgICAgWy1OIG5vZGVpbmZvX29wdGlvbl0gWy1wIHBhdHRlcm5dIFstUSB0Y2xhc3NdIFstcyBwYWNrZXRzaXplXQogICAgICAgICAgICAgWy1TIHNuZGJ1Zl0gWy10IHR0bF0gWy1UIHRpbWVzdGFtcF9vcHRpb25dIFstdyBkZWFkbGluZV0KICAgICAgICAgICAgIFstVyB0aW1lb3V0XSBkZXN0aW5hdGlvbgo=",
"exited": true}}

On Wed, Aug 30, 2017 at 9:22 AM, Sam <batmanu...@gmail.com> wrote:

> Qemu-2.6.0
>
> 2017-08-30 14:20 GMT+08:00 Sam <batmanu...@gmail.com>:
>
>> Hi all,
>>
>> I could repeat it, host os and guest os is Centos-7, qemu-ga is alive in
>> guest. the step to repeat it is:
>>
>> 1. run python script just like the first email.
>> 2. send qmp command1(cmd in the python script, like `route -n` command or
>> something, of course it's qmp format), and interrupt it immediately(use
>> `ctrl+c`).
>> 3. then use that script to send command2(do not send command1) again,
>> then you could get the result of command1.
>>
>>
>> 2017-08-29 17:04 GMT+08:00 Sameeh Jubran <sam...@daynix.com>:
>>
>>> Hi Sam,
>>>
>>> Thanks for reporting this, in order to debug this efficiently I need you
>>> to provide me with more info, if you can provide it that would be great.
>>> Can you reproduce the issue with ncat? You can use ncat to connect to
>>> the socket by running the following command:
>>>
>>> nc -U /tmp/qga.sock
>>>
>>> Which OS are you running? Which qemu-ga version are you running? can you
>>> reproduce with upstream qemu-ga?
>>>
>>> On Tue, Aug 29, 2017 at 9:19 AM, Sam <batmanu...@gmail.com> wrote:
>>>
>>>> So how to fix this bug? And where should I to report bug?
>>>>
>>>> 2017-08-29 13:52 GMT+08:00 Sam <batmanu...@gmail.com>:
>>>>
>>>> > I could repeat this several times, I think it's mis-order of qmp in
>>>> qga
>>>> > socket.
>>>> >
>>>> > 2017-08-25 11:09 GMT+08:00 Sam <batmanu...@gmail.com>:
>>>> >
>>>> >> Also I found:
>>>> >>
>>>> >> when I use `socat` to take a qga socket, then I use `socat` to
>>>> >> communicate it will got error.
>>>> >> But also SOMETIMES, I will not got error and will communicate OK.
>>>> >>
>>>> >> If one user take qga socket, another user should got error, is it?
>>>> But
>>>> >> why sometimes, the communicate is OK?
>>>> >>
>>>> >> 2017-08-25 10:11 GMT+08:00 Sam <batmanu...@gmail.com>:
>>>> >>
>>>> >>> Hi all,
>>>> >>>
>>>> >>> I'm using qga to send `route -n` and `ping` comma

Re: [Qemu-devel] [PATCH 0/3]

2017-09-04 Thread Sameeh Jubran
Ping.

On Tue, Aug 22, 2017 at 2:18 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Ping.
>
> On Sun, Aug 13, 2017 at 6:58 PM, Sameeh Jubran <sam...@daynix.com> wrote:
>
>> From: Sameeh Jubran <sjub...@redhat.com>
>>
>> This series fixes qemu-ga's behaviour upon facing a missing serial/serial
>> driver by listening to the serial device's events.
>>
>> For more info on why this series is needed checkout the commit message
>> of the third patch and the following bugzilla:
>> https://bugzilla.redhat.com/show_bug.cgi?id=990629.
>>
>> Sameeh Jubran (3):
>>   qga: Channel: Add functions for checking serial status
>>   qga: main: make qga config and socket activation global
>>   qga: Prevent qemu-ga exit if serial doesn't exist
>>
>>  Makefile|   4 +
>>  qga/channel-posix.c |  54 ++
>>  qga/channel-win32.c |  60 +++
>>  qga/channel.h   |   9 ++
>>  qga/main.c  | 284 ++
>> ++++------
>>  qga/service-win32.h |   4 +
>>  6 files changed, 385 insertions(+), 30 deletions(-)
>>
>> --
>> 2.9.4
>>
>>
>
>
> --
> Respectfully,
> *Sameeh Jubran*
> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
> *Software Engineer @ Daynix <http://www.daynix.com>.*
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [QGA] Bug of qga?

2017-08-29 Thread Sameeh Jubran
Hi Sam,

Thanks for reporting this, in order to debug this efficiently I need you to
provide me with more info, if you can provide it that would be great.
Can you reproduce the issue with ncat? You can use ncat to connect to the
socket by running the following command:

nc -U /tmp/qga.sock

Which OS are you running? Which qemu-ga version are you running? can you
reproduce with upstream qemu-ga?

On Tue, Aug 29, 2017 at 9:19 AM, Sam <batmanu...@gmail.com> wrote:

> So how to fix this bug? And where should I to report bug?
>
> 2017-08-29 13:52 GMT+08:00 Sam <batmanu...@gmail.com>:
>
> > I could repeat this several times, I think it's mis-order of qmp in qga
> > socket.
> >
> > 2017-08-25 11:09 GMT+08:00 Sam <batmanu...@gmail.com>:
> >
> >> Also I found:
> >>
> >> when I use `socat` to take a qga socket, then I use `socat` to
> >> communicate it will got error.
> >> But also SOMETIMES, I will not got error and will communicate OK.
> >>
> >> If one user take qga socket, another user should got error, is it? But
> >> why sometimes, the communicate is OK?
> >>
> >> 2017-08-25 10:11 GMT+08:00 Sam <batmanu...@gmail.com>:
> >>
> >>> Hi all,
> >>>
> >>> I'm using qga to send `route -n` and `ping` command to guest. But I
> >>> found SOMETIMES, the second `ping` command's result is the same as
> `route
> >>> -n` command.
> >>>
> >>> So I guess is there some cache mechanism of qga command result? So when
> >>> I send the second command, and receive from qga socket, I receive the
> >>> result of first command.
> >>>
> >>> Or is this bug happened because of I use async mechanism of python code
> >>> to operate qga socket?
> >>>
> >>> This is the python code I use to operate on this qga socket:
> >>>
> >>> try:
> >>>> sock=socket(AF_UNIX, SOCK_STREAM)
> >>>> sock.settimeout(20)
> >>>> sock.connect(vm_qga_sockpath)
> >>>> sock.send(cmd)
> >>>> while True:
> >>>> res = sock.recv(1024)
> >>>> if len(res):
> >>>> break
> >>>> except Exception as e:
> >>>> res = -1
> >>>> finally:
> >>>> sock.settimeout(None)
> >>>> sock.close()
> >>>
> >>>
> >>
> >
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] Why I got "timeout" while using qga socket to connect VM?

2017-08-23 Thread Sameeh Jubran
Hi Sam,

>From the command line I assume that you are running CentOS-7-x86_64, did
you install the guest agent on the VM? Can you see that it is running?

What do you mean by blocked?

On Wed, Aug 23, 2017 at 5:34 AM, Sam <batmanu...@gmail.com> wrote:

> Hi all,
>
> I start VM using command like this:
>
> -chardev socket,path=/home/gangyewei-3/kvm/qga.sock,server,nowait,id=qga0
> > -device virtio-serial -device virtserialport,chardev=qga0,
> > name=org.qemu.guest_agent.0
>
>
> But When I use socat to send command (https://wiki.qemu.org/
> Features/GuestAgent), it blocked. Why and how to fix this? Thank you~
>
> whole command is :
>
> /usr/local/kvm/bin/qemu-system-x86_64 -smp 4 -m 4096 -enable-kvm
> > /home/gangyewei-3/kvm/centos6.6_2.img -cdrom
> /home/gangyewei-3/kvm/CentOS-7-x86_64-DVD-1503-01.iso
> > -daemonize -vnc 0.0.0.0:2520 -chardev socket,id=char-client-07-1,
> > path=/usr/local/var/run/openvswitch/client-07-1,server=on -netdev
> > type=vhost-user,id=client-07-1,chardev=char-client-07-1 -device
> > virtio-net-pci,mac=00:00:af:07:03:02,netdev=client-07-1 -object
> > memory-backend-file,id=mem,size=4096M,mem-path=/mnt/huge/,share=on -numa
> > node,memdev=mem -mem-prealloc -chardev socket,path=/home/gangyewei-3/
> > kvm/qga.sock,server,nowait,id=qga0 -device virtio-serial -device
> > virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -incoming
> > tcp:0:
>
>
>
> 2017-08-22 18:00 GMT+08:00 Sam <batmanu...@gmail.com>:
>
> > whole command is :
> >
> > /usr/local/kvm/bin/qemu-system-x86_64 -smp 4 -m 4096 -enable-kvm
> >> /home/gangyewei-3/kvm/centos6.6_2.img -cdrom
> >> /home/gangyewei-3/kvm/CentOS-7-x86_64-DVD-1503-01.iso -daemonize -vnc
> >> 0.0.0.0:2520 -chardev socket,id=char-client-07-1,
> path=/usr/local/var/run/
> >> openvswitch/client-07-1,server=on -netdev type=vhost-user,id=client-07-
> 1,chardev=char-client-07-1
> >> -device virtio-net-pci,mac=00:00:af:07:03:02,netdev=client-07-1 -object
> >> memory-backend-file,id=mem,size=4096M,mem-path=/mnt/huge/,share=on
> -numa
> >> node,memdev=mem -mem-prealloc -chardev socket,path=/home/gangyewei-3/
> >> kvm/qga.sock,server,nowait,id=qga0 -device virtio-serial -device
> >> virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -incoming
> >> tcp:0:
> >
> >
> > 2017-08-22 17:54 GMT+08:00 Sam <batmanu...@gmail.com>:
> >
> >> Hi all,
> >>
> >> I start VM using command like this:
> >>
> >> -chardev socket,path=/home/gangyewei-3/kvm/qga.sock,server,nowait,id=
> qga0
> >>> -device virtio-serial -device virtserialport,chardev=qga0,na
> >>> me=org.qemu.guest_agent.0
> >>
> >>
> >> But When I use socat to send command (https://wiki.qemu.org/Feature
> >> s/GuestAgent), it blocked. Why and how to fix this? Thank you~
> >>
> >
> >
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v2] qga-win: Updating guest_set_time action

2017-08-22 Thread Sameeh Jubran
Reviewed-by: Sameeh Jubran <sam...@daynix.com>

On Tue, Aug 22, 2017 at 4:55 PM, Bishara AbuHattoum <bish...@daynix.com>
wrote:

>   At the moment, Windows libraries don't provide a way to access
>   RTC, so, a workaround is to use the Windows w32tm command to
>   resync the time.
>   Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1183874
>
> Signed-off-by: Bishara AbuHattoum <bish...@daynix.com>
> ---
>  configure|  2 +-
>  qga/commands-win32.c | 36 +++-
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index dd73cce62f..2c044ba2ca 100755
> --- a/configure
> +++ b/configure
> @@ -824,7 +824,7 @@ if test "$mingw32" = "yes" ; then
>sysconfdir="\${prefix}"
>local_statedir=
>confsuffix=""
> -  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32
> $libs_qga"
> +  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lwininet -liphlpapi
> -lnetapi32 $libs_qga"
>  fi
>
>  werror=""
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 619dbd2bc2..fbd7eb7bbb 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -29,6 +29,7 @@
>  #endif
>  #include 
>  #include 
> +#include 
>
>  #include "qga/guest-agent-core.h"
>  #include "qga/vss-win32.h"
> @@ -1277,8 +1278,41 @@ void qmp_guest_set_time(bool has_time, int64_t
> time_ns, Error **errp)
>   * RTC yet:
>   *
>   * https://msdn.microsoft.com/en-us/library/aa908981.aspx
> + *
> + * Instead, a workaround is to use the Windows win32tm command to
> + * resync the time using the Windows Time service.
>   */
> -error_setg(errp, "Time argument is required on this platform");
> +LPVOID msg_buffer;
> +DWORD ret_flags;
> +
> +HRESULT hr = system("w32tm /resync /nowait");
> +
> +if (GetLastError() != 0) {
> +strerror_s((LPTSTR) & msg_buffer, 0, errno);
> +error_setg(errp, "system(...) failed: %s",
> (LPCTSTR)msg_buffer);
> +} else if (hr != 0) {
> +if (hr == HRESULT_FROM_WIN32(ERROR_SERVICE_NOT_ACTIVE)) {
> +error_setg(errp, "Windows Time service not running on the
> "
> + "guest");
> +} else {
> +if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
> +   FORMAT_MESSAGE_FROM_SYSTEM |
> +   FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
> +   (DWORD)hr, MAKELANGID(LANG_NEUTRAL,
> +   SUBLANG_DEFAULT), (LPTSTR) &
> msg_buffer, 0,
> +   NULL)) {
> +error_setg(errp, "w32tm failed with error (0x%lx),
> couldn'"
> + "t retrieve error message", hr);
> +} else {
> +error_setg(errp, "w32tm failed with error (0x%lx):
> %s", hr,
> +   (LPCTSTR)msg_buffer);
> +LocalFree(msg_buffer);
> +}
> +}
> +} else if (!InternetGetConnectedState(_flags, 0)) {
> +error_setg(errp, "No internet connection on guest, sync not "
> + "accurate");
> +}
>  return;
>  }
>
> --
> 2.13.5
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH] qga-win: Updating guest_set_time action

2017-08-22 Thread Sameeh Jubran
Reviewed-by: Sameeh Jubran <sam...@daynix.com>

On Tue, Aug 22, 2017 at 3:20 PM, Bishara AbuHattoum <bish...@daynix.com>
wrote:

>   At the moment, Windows libraries don't provide a way to access
>   RTC, so, a workaround is to use the Windows w32tm command to
>   resync the time.
>   Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1183874
>
> Signed-off-by: Bishara AbuHattoum <bish...@daynix.com>
> ---
>  configure|  2 +-
>  qga/commands-win32.c | 36 +++-
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index dd73cce62f..c7d42d8b00 100755
> --- a/configure
> +++ b/configure
> @@ -824,7 +824,7 @@ if test "$mingw32" = "yes" ; then
>sysconfdir="\${prefix}"
>local_statedir=
>confsuffix=""
> -  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32
> $libs_qga"
> +  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -lsensapi -liphlpapi
> -lnetapi32 $libs_qga"
>  fi
>
>  werror=""
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 619dbd2bc2..f93f69baeb 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -29,6 +29,7 @@
>  #endif
>  #include 
>  #include 
> +#include 
>
>  #include "qga/guest-agent-core.h"
>  #include "qga/vss-win32.h"
> @@ -1277,8 +1278,41 @@ void qmp_guest_set_time(bool has_time, int64_t
> time_ns, Error **errp)
>   * RTC yet:
>   *
>   * https://msdn.microsoft.com/en-us/library/aa908981.aspx
> + *
> + * Instead, a workaround is to use the Windows win32tm command to
> + * resync the time using the Windows Time service.
>   */
> -error_setg(errp, "Time argument is required on this platform");
> +LPVOID msg_buffer;
> +DWORD ret_flags;
> +
> +HRESULT hr = system("w32tm /resync /nowait");
> +
> +if (GetLastError() != 0) {
> +strerror_s((LPTSTR) & msg_buffer, 0, errno);
> +error_setg(errp, "system(...) failed: %s",
> (LPCTSTR)msg_buffer);
> +} else if (hr != 0) {
> +if (hr == HRESULT_FROM_WIN32(ERROR_SERVICE_NOT_ACTIVE)) {
> +error_setg(errp, "Windows Time service not running on the
> "
> + "guest");
> +} else {
> +if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
> +   FORMAT_MESSAGE_FROM_SYSTEM |
> +   FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
> +   (DWORD)hr, MAKELANGID(LANG_NEUTRAL,
> +   SUBLANG_DEFAULT), (LPTSTR) &
> msg_buffer, 0,
> +   NULL)) {
> +error_setg(errp, "w32tm failed with error (0x%lx),
> couldn'"
> + "t retrieve error message", hr);
> +} else {
> +error_setg(errp, "w32tm failed with error (0x%lx):
> %s", hr,
> +       (LPCTSTR)msg_buffer);
> +LocalFree(msg_buffer);
> +}
> +}
> +} else if (!IsNetworkAlive(_flags)) {
> +error_setg(errp, "No network connection on guest, sync not"
> + " accurate");
> +}
>  return;
>  }
>
> --
> 2.13.5
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH 0/3]

2017-08-22 Thread Sameeh Jubran
Ping.

On Sun, Aug 13, 2017 at 6:58 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> From: Sameeh Jubran <sjub...@redhat.com>
>
> This series fixes qemu-ga's behaviour upon facing a missing serial/serial
> driver by listening to the serial device's events.
>
> For more info on why this series is needed checkout the commit message
> of the third patch and the following bugzilla:
> https://bugzilla.redhat.com/show_bug.cgi?id=990629.
>
> Sameeh Jubran (3):
>   qga: Channel: Add functions for checking serial status
>   qga: main: make qga config and socket activation global
>   qga: Prevent qemu-ga exit if serial doesn't exist
>
>  Makefile|   4 +
>  qga/channel-posix.c |  54 ++
>  qga/channel-win32.c |  60 +++
>  qga/channel.h   |   9 ++
>  qga/main.c  | 284 ++
> --
>  qga/service-win32.h |   4 +
>  6 files changed, 385 insertions(+), 30 deletions(-)
>
> --
> 2.9.4
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH 3/3] qga: Prevent qemu-ga exit if serial doesn't exist

2017-08-13 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Currently whenever the qemu-ga's service doesn't find the virtio-serial
it terminates. This commit addresses this issue by listening to the serial 
events
by registering for notifications for the chosen serial and it handles channel
initialization accordingily.

A list of possible scenarios of which could lead to this behavour:

* qemu-ga's service is started while the virtio-serial driver hasn't been 
installed yet
* hotplug/ unplug of the virtio-serial device
* upgrading the virtio-serial driver

Note: This problem is much more common on Windows as the virtio-serial
driver should be installed by the user and isn't shipped with the Windows OS.

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 Makefile|   4 +
 qga/main.c  | 240 ++--
 qga/service-win32.h |   4 +
 3 files changed, 239 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index ef72148..82f26d5 100644
--- a/Makefile
+++ b/Makefile
@@ -203,6 +203,10 @@ $(call set-vpath, $(SRC_PATH))
 
 LIBS+=-lz $(LIBS_TOOLS)
 
+ifndef CONFIG_WIN32
+LIBS_QGA+=-ludev
+endif
+
 HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
 ifdef BUILD_DOCS
diff --git a/qga/main.c b/qga/main.c
index cf312b9..d727880 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -16,6 +16,8 @@
 #ifndef _WIN32
 #include 
 #include 
+#include 
+#include 
 #endif
 #include "qapi/qmp/json-streamer.h"
 #include "qapi/qmp/json-parser.h"
@@ -30,6 +32,7 @@
 #include "qemu/sockets.h"
 #include "qemu/systemd.h"
 #ifdef _WIN32
+#include 
 #include "qga/service-win32.h"
 #include "qga/vss-win32.h"
 #endif
@@ -74,6 +77,10 @@ struct GAState {
 GLogLevelFlags log_level;
 FILE *log_file;
 bool logging_enabled;
+bool serial_connected;
+#ifndef _WIN32
+struct udev_monitor *udev_monitor;
+#endif
 #ifdef _WIN32
 GAService service;
 #endif
@@ -130,9 +137,15 @@ static const char *ga_freeze_whitelist[] = {
 #ifdef _WIN32
 DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
   LPVOID ctx);
+DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data);
 VOID WINAPI service_main(DWORD argc, TCHAR *argv[]);
 #endif
 
+static bool get_channel_method(GAChannelMethod *channel_method,
+const gchar *method, GAState *s);
+static gboolean channel_init(GAState *s, const gchar *method, const gchar 
*path,
+int listen_fd, bool *serial_connected);
+
 static void
 init_dfl_pathnames(void)
 {
@@ -186,6 +199,136 @@ static void quit_handler(int sig)
 }
 
 #ifndef _WIN32
+static int get_method_udev_subsystem(const char **serial_subsystem)
+{
+if (strcmp(ga_config->method, "virtio-serial") == 0) {
+*serial_subsystem = SUBSYSTEM_VIRTIO_SERIAL;
+} else if (strcmp(ga_config->method, "isa-serial") == 0) {
+/* try the default path for the serial port - COM1 */
+*serial_subsystem = SUBSYSTEM_ISA_SERIAL;
+} else {
+serial_subsystem = NULL;
+return -1;
+}
+return 0;
+}
+
+static gboolean serial_event_callback(GIOChannel *source,
+GIOCondition condition, gpointer data)
+{
+struct udev_monitor *mon = ga_state->udev_monitor;
+const char *serial_subsystem = NULL;
+struct udev_device *dev;
+
+if (get_method_udev_subsystem(_subsystem) == -1) {
+return false;
+}
+dev = udev_monitor_receive_device(mon);
+
+if (dev && serial_subsystem && strcmp(udev_device_get_subsystem(dev),
+serial_subsystem) ==  0) {
+
+GAChannelMethod channel_method;
+get_channel_method(_method, ga_config->method, ga_state);
+if (ga_channel_was_serial_attached(channel_method,
+ga_config->channel_path, ga_state->serial_connected)) {
+ga_state->serial_connected = true;
+if (!channel_init(ga_state,
+ga_config->method, ga_config->channel_path,
+ga_socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1,
+_state->serial_connected)) {
+g_critical("failed to initialize guest agent channel");
+}
+}
+
+if (ga_channel_was_serial_detached(channel_method,
+ga_config->channel_path, ga_state->serial_connected)) {
+ga_state->serial_connected = false;
+ga_channel_free(ga_state->channel);
+}
+udev_device_unref(dev);
+}
+return true;
+}
+
+static int monitor_serial_events(void)
+{
+int ret = 0;
+const char *serial_subsystem = NULL;
+struct udev *udev = NULL;
+ga_state->udev_monitor = NULL;
+GIOChannel *channel = NULL;
+GSource *watch_source = NULL;
+if (get_method_udev_subsystem(_subsystem) == -1) {
+ret = -1;
+goto out;
+}
+
+udev = udev_new();
+if (!udev

[Qemu-devel] [PATCH 0/3]

2017-08-13 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

This series fixes qemu-ga's behaviour upon facing a missing serial/serial
driver by listening to the serial device's events.

For more info on why this series is needed checkout the commit message
of the third patch and the following bugzilla: 
https://bugzilla.redhat.com/show_bug.cgi?id=990629.

Sameeh Jubran (3):
  qga: Channel: Add functions for checking serial status
  qga: main: make qga config and socket activation global
  qga: Prevent qemu-ga exit if serial doesn't exist

 Makefile|   4 +
 qga/channel-posix.c |  54 ++
 qga/channel-win32.c |  60 +++
 qga/channel.h   |   9 ++
 qga/main.c  | 284 ++--
 qga/service-win32.h |   4 +
 6 files changed, 385 insertions(+), 30 deletions(-)

-- 
2.9.4




[Qemu-devel] [PATCH 2/3] qga: main: make qga config and socket activation global

2017-08-13 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/main.c | 44 +++-
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index 1b381d0..cf312b9 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -92,7 +92,28 @@ struct GAState {
 GAPersistentState pstate;
 };
 
+typedef struct GAConfig {
+char *channel_path;
+char *method;
+char *log_filepath;
+char *pid_filepath;
+#ifdef CONFIG_FSFREEZE
+char *fsfreeze_hook;
+#endif
+char *state_dir;
+#ifdef _WIN32
+const char *service;
+#endif
+gchar *bliststr; /* blacklist may point to this string */
+GList *blacklist;
+int daemonize;
+GLogLevelFlags log_level;
+int dumpconf;
+} GAConfig;
+
 struct GAState *ga_state;
+struct GAConfig *ga_config;
+int ga_socket_activation;
 QmpCommandList ga_commands;
 
 /* commands that are safe to issue while filesystems are frozen */
@@ -942,25 +963,6 @@ static GList *split_list(const gchar *str, const gchar 
*delim)
 return list;
 }
 
-typedef struct GAConfig {
-char *channel_path;
-char *method;
-char *log_filepath;
-char *pid_filepath;
-#ifdef CONFIG_FSFREEZE
-char *fsfreeze_hook;
-#endif
-char *state_dir;
-#ifdef _WIN32
-const char *service;
-#endif
-gchar *bliststr; /* blacklist may point to this string */
-GList *blacklist;
-int daemonize;
-GLogLevelFlags log_level;
-int dumpconf;
-} GAConfig;
-
 static void config_load(GAConfig *config)
 {
 GError *gerr = NULL;
@@ -1353,7 +1355,7 @@ int main(int argc, char **argv)
 {
 int ret = EXIT_SUCCESS;
 GAState *s = g_new0(GAState, 1);
-GAConfig *config = g_new0(GAConfig, 1);
+GAConfig *config = ga_config = g_new0(GAConfig, 1);
 int socket_activation;
 
 config->log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
@@ -1376,7 +1378,7 @@ int main(int argc, char **argv)
 config->method = g_strdup("virtio-serial");
 }
 
-socket_activation = check_socket_activation();
+ga_socket_activation = socket_activation = check_socket_activation();
 if (socket_activation > 1) {
 g_critical("qemu-ga only supports listening on one socket");
 ret = EXIT_FAILURE;
-- 
2.9.4




[Qemu-devel] [PATCH 1/3] qga: Channel: Add functions for checking serial status

2017-08-13 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

This commit adds functions to check if the serial is
connected/disconnected or else if it has been attached or detached.

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/channel-posix.c | 54 +++
 qga/channel-win32.c | 60 +
 qga/channel.h   |  9 
 3 files changed, 123 insertions(+)

diff --git a/qga/channel-posix.c b/qga/channel-posix.c
index 3f34465..d307cf4 100644
--- a/qga/channel-posix.c
+++ b/qga/channel-posix.c
@@ -295,3 +295,57 @@ void ga_channel_free(GAChannel *c)
 }
 g_free(c);
 }
+
+static bool is_serial_present(GAChannelMethod method, const gchar *path,
+int *error_code)
+{
+int fd = -1;
+bool ret = true;
+
+assert(error_code);
+*error_code = 0;
+
+switch (method) {
+case GA_CHANNEL_VIRTIO_SERIAL:
+fd = qemu_open(path, O_RDWR | O_NONBLOCK
+#ifndef CONFIG_SOLARIS
+| O_ASYNC
+#endif
+);
+break;
+case GA_CHANNEL_ISA_SERIAL:
+fd = qemu_open(path, O_RDWR | O_NOCTTY | O_NONBLOCK);
+break;
+default:
+ret = false;
+}
+if (fd < 0) {
+*error_code = errno;
+ret = false;
+} else {
+close(fd);
+}
+return ret;
+}
+
+bool ga_channel_serial_is_present(GAChannelMethod method, const gchar *path)
+{
+int error_code = 0;
+return is_serial_present(method, path, _code) ||
+error_code == EBUSY;
+}
+
+bool ga_channel_was_serial_attached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached)
+{
+int error_code = 0;
+return !is_serial_attached &&
+is_serial_present(method, path, _code);
+}
+bool ga_channel_was_serial_detached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached)
+{
+int error_code = 0;
+return is_serial_attached && !is_serial_present(method, path, _code)
+&& error_code == ENOENT;
+}
diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index 7e6dc4d..2d51bee 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -354,3 +354,63 @@ void ga_channel_free(GAChannel *c)
 g_free(c->rstate.buf);
 g_free(c);
 }
+
+static bool is_serial_present(GAChannelMethod method, const gchar *path,
+DWORD *err)
+{
+gchar newpath[MAXPATHLEN] = { 0 };
+bool ret = false;
+
+assert(err);
+
+if (method != GA_CHANNEL_VIRTIO_SERIAL && method != GA_CHANNEL_ISA_SERIAL) 
{
+g_critical("unsupported communication method");
+return false;
+}
+
+if (method == GA_CHANNEL_ISA_SERIAL) {
+snprintf(newpath, sizeof(newpath), ".\\%s", path);
+} else {
+g_strlcpy(newpath, path, sizeof(newpath));
+}
+
+HANDLE handle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+OPEN_EXISTING,
+FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
+
+if (handle == INVALID_HANDLE_VALUE) {
+*err = GetLastError();
+ret = false;
+} else {
+ret = true;
+}
+
+CloseHandle(handle);
+return ret;
+}
+
+bool ga_channel_serial_is_present(GAChannelMethod method, const gchar *path)
+{
+DWORD err_code;
+return is_serial_present(method, path, _code) ||
+err_code == ERROR_ACCESS_DENIED;
+}
+
+bool ga_channel_was_serial_attached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached)
+{
+DWORD err_code;
+return !is_serial_attached && is_serial_present(method, path, _code);
+}
+
+bool ga_channel_was_serial_detached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached)
+{
+DWORD err_code = NO_ERROR;
+/* In order to make sure the serial that qemu-ga uses is the one that
+ * was detached. We'll get the error ERROR_FILE_NOT_FOUND when
+ * attempting to call CreateFile with the serial path.
+*/
+   return is_serial_attached && !is_serial_present(method, path, _code)
+   && err_code == ERROR_FILE_NOT_FOUND;
+}
diff --git a/qga/channel.h b/qga/channel.h
index 1778416..acb3d73 100644
--- a/qga/channel.h
+++ b/qga/channel.h
@@ -12,6 +12,10 @@
 #ifndef QGA_CHANNEL_H
 #define QGA_CHANNEL_H
 
+#ifndef _WIN32
+#define SUBSYSTEM_VIRTIO_SERIAL "virtio-ports";
+#define SUBSYSTEM_ISA_SERIAL "isa-serial";
+#endif
 
 typedef struct GAChannel GAChannel;
 
@@ -30,5 +34,10 @@ GAChannel *ga_channel_new(GAChannelMethod method, const 
gchar *path,
 void ga_channel_free(GAChannel *c);
 GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *count);
 GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size);
+bool ga_channel_serial_is_present(GAChannelMethod method, const gchar *path);
+bool ga_channel_was_serial_attached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached);
+bool ga_channel_was_serial_detached(GAChannelMethod method, const gchar *path,
+bool is_serial_attached);
 
 #endif
-- 
2.9.4




Re: [Qemu-devel] [PATCH] vfio/pci-quirks: Set non-zero GMS memory size for IGD

2017-07-24 Thread Sameeh Jubran
Just noticed a small typo, other than LGTM +1 :)
On Mon, Jul 24, 2017 at 3:07 PM, Dmitry Fleytman <dmi...@daynix.com> wrote:

> There is a claim that GMS memory is unused however
> Intel Windows 10 drivers starting from V.4534 (10/7/2016)
> allocate extra ~4G memory when GMS size set to 0.
>
> This patch fixes this issue by seting IGD GMS memory
>
* setting

> size to minimum by changing default value of x-igd-gms
> device parameter.
>
> Signed-off-by: Dmitry Fleytman <dmi...@daynix.com>
> ---
>  hw/vfio/pci-quirks.c | 13 +
>  hw/vfio/pci.c|  2 +-
>  2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> index 349085e..197cb90 100644
> --- a/hw/vfio/pci-quirks.c
> +++ b/hw/vfio/pci-quirks.c
> @@ -1527,10 +1527,15 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice
> *vdev, int nr)
>  }
>
>  /*
> - * Assume we have no GMS memory, but allow it to be overrided by
> device
> - * option (experimental).  The spec doesn't actually allow zero GMS
> when
> - * when IVD (IGD VGA Disable) is clear, but the claim is that it's
> unused,
> - * so let's not waste VM memory for it.
> + * There is a claim that GMS memory is unused and we want to waste
> for it
> + * as less VM memory as possible, however Intel Windows 10 drivers
> starting
> + * from V.4534 (10/7/2016) allocate extra ~4G memory when GMS size
> set to 0.
> + * The spec as well doesn't actually allow zero GMS when IVD
> + * (IGD VGA Disable) is clear.
> + *
> + * Therefore we set GMS memory size to minimal by default via device
> + * option x-igd-gms (experimental) and allow further tweaking of this
> + * parameter.
>   */
>  gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8));
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index d4051cb..bda07b7 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2982,7 +2982,7 @@ static Property vfio_pci_dev_properties[] = {
> sub_vendor_id, PCI_ANY_ID),
>  DEFINE_PROP_UINT32("x-pci-sub-device-id", VFIOPCIDevice,
> sub_device_id, PCI_ANY_ID),
> -DEFINE_PROP_UINT32("x-igd-gms", VFIOPCIDevice, igd_gms, 0),
> +DEFINE_PROP_UINT32("x-igd-gms", VFIOPCIDevice, igd_gms, 1),
>  /*
>   * TODO - support passed fds... is this necessary?
>   * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name),
> --
> 2.9.4
>
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH 0/5] Fix qemu-ga's behaviour on Windows

2017-07-23 Thread Sameeh Jubran
Ping.

On Wed, Jul 5, 2017 at 10:54 AM, Sameeh Jubran <sam...@daynix.com> wrote:

> From: Sameeh Jubran <sjub...@redhat.com>
>
> This patch series fixes qemu-ga's main service behaviour on Windows
> by listening to the virtio-serial device's events.
>
> For more info on why this series is needed checkout the commit message
> of the third patch and the following bugzilla:
> https://bugzilla.redhat.com/show_bug.cgi?id=990629.
>
> Sameeh Jubran (5):
>   Makefile: clean: Clean exe files
>   qga-win: service-win32: Add start_service and stop_service functions
>   qga-win: Add serial listener service
>   qga-win: Add qga-serial-listener to msi installer
>   qga-win: service-win32: Use get_service function
>
>  Makefile|  12 ++-
>  Makefile.objs   |   1 +
>  qga/Makefile.objs   |   2 +
>  qga/channel.h   |   9 ++
>  qga/installer/qemu-ga.wxs   |  24 +
>  qga/main.c  |  23 +++--
>  qga/serial-listener-service-win32.c | 181 ++
> ++
>  qga/serial-listener-service-win32.h |  29 ++
>  qga/service-win32.c | 142 +++-
>  qga/service-win32.h |   5 +
>  10 files changed, 395 insertions(+), 33 deletions(-)
>  create mode 100644 qga/serial-listener-service-win32.c
>  create mode 100644 qga/serial-listener-service-win32.h
>
> --
> 2.9.4
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [Qemu-GA-Win PATCH v3] qemu-ga-win localization fix

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

This version doesn't differ from v2 at all, v2 have been waiting too
long for a review, so I'm resending it again.

Daniel Rempel (1):
  qga-win: fix installation on localized windows

 qga/vss-win32/install.cpp | 35 +--
 1 file changed, 33 insertions(+), 2 deletions(-)

-- 
2.9.4




[Qemu-devel] [Qemu-GA-Win PATCH v3] qga-win: fix installation on localized windows

2017-07-05 Thread Sameeh Jubran
From: Daniel Rempel <dan...@daynix.com>

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1357789
Replace hardcoded user and group names ("Administrators", "SYSTEM") with the 
ones acquired from system. Windows uses localized strings for these names and 
it may cause the installation to fail.
Windows has Well-known SIDs for "Administrators" group and "SYSTEM" user so 
they were used to identify required users and groups.
Well-known SIDs: 
https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems

Signed-off-by: Daniel Rempel <dan...@daynix.com>
Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/vss-win32/install.cpp | 35 +--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index f41fcdf..ba7c94e 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -18,6 +18,9 @@
 #include 
 #include 
 #include 
+#include 
+
+#define BUFFER_SIZE 1024
 
 extern HINSTANCE g_hinstDll;
 
@@ -135,6 +138,27 @@ out:
 return hr;
 }
 
+/* Acquire group or user name by SID */
+static HRESULT getNameByStringSID(
+const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
+{
+HRESULT hr = S_OK;
+PSID psid = NULL;
+SID_NAME_USE groupType;
+DWORD domainNameLen = BUFFER_SIZE;
+wchar_t domainName[BUFFER_SIZE];
+
+chk(ConvertStringSidToSidW(sid, ));
+LookupAccountSidW(NULL, psid, buffer, bufferLen,
+domainName, , );
+hr = HRESULT_FROM_WIN32(GetLastError());
+
+LocalFree(psid);
+
+out:
+return hr;
+}
+
 /* Find and iterate QGA VSS provider in COM+ Application Catalog */
 static HRESULT QGAProviderFind(
 HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
@@ -216,6 +240,10 @@ STDAPI COMRegister(void)
 CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
 bool unregisterOnFailure = false;
 int count = 0;
+DWORD bufferLen = BUFFER_SIZE;
+wchar_t buffer[BUFFER_SIZE];
+const wchar_t *administratorsGroupSID = L"S-1-5-32-544";
+const wchar_t *systemUserSID = L"S-1-5-18";
 
 if (!g_hinstDll) {
 errmsg(E_FAIL, "Failed to initialize DLL");
@@ -284,11 +312,12 @@ STDAPI COMRegister(void)
 
 /* Setup roles of the applicaion */
 
+chk(getNameByStringSID(administratorsGroupSID, buffer, ));
 chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
  (IDispatch **)pRoles.replace()));
 chk(pRoles->Populate());
 chk(pRoles->Add((IDispatch **)pObj.replace()));
-chk(put_Value(pObj, L"Name",L"Administrators"));
+chk(put_Value(pObj, L"Name", buffer));
 chk(put_Value(pObj, L"Description", L"Administrators group"));
 chk(pRoles->SaveChanges());
 chk(pObj->get_Key());
@@ -303,8 +332,10 @@ STDAPI COMRegister(void)
 chk(GetAdminName());
 chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
 
+bufferLen = BUFFER_SIZE;
+chk(getNameByStringSID(systemUserSID, buffer, ));
 chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
-chk(put_Value(pObj, L"User", L"SYSTEM"));
+chk(put_Value(pObj, L"User", buffer));
 chk(pUsersInRole->SaveChanges());
 
 out:
-- 
2.9.4




[Qemu-devel] [PATCH 3/5] qga-win: Add serial listener service

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Currently on Windows whenever the qemu-ga's service doesn't find the 
virtio-serial
it terminates. This commit addresses this issue by adding a new listener service
which registers for notifications of the virtio-port-serial device handle the
qemu-ga's service accordingly.

Note that adding a new service to the qga code is much neater and simpler than
changing the behaviour of the qemu-ga's service as a good portion of the code is
shared between Windows and Linux.

A list of possible scenarios of which could lead to this behavour:

* qemu-ga's service is started while the virtio-serial driver hasn't been 
installed yet
* hotplug/ unplug of the virtio-serial device
* upgrading the virtio-serial driver

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 Makefile|  11 ++-
 Makefile.objs   |   1 +
 qga/Makefile.objs   |   2 +
 qga/channel.h   |   9 ++
 qga/main.c  |  23 +++--
 qga/serial-listener-service-win32.c | 181 
 qga/serial-listener-service-win32.h |  29 ++
 qga/service-win32.c |  79 +---
 qga/service-win32.h |   3 +
 9 files changed, 315 insertions(+), 23 deletions(-)
 create mode 100644 qga/serial-listener-service-win32.c
 create mode 100644 qga/serial-listener-service-win32.h

diff --git a/Makefile b/Makefile
index 22d29d6..3583c8d 100644
--- a/Makefile
+++ b/Makefile
@@ -266,6 +266,7 @@ dummy := $(call unnest-vars,, \
 chardev-obj-y \
 util-obj-y \
 qga-obj-y \
+qga-serial-listener-obj-y \
 ivshmem-client-obj-y \
 ivshmem-server-obj-y \
 libvhost-user-obj-y \
@@ -390,6 +391,9 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx 
$(SRC_PATH)/scripts/hxtool
 qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
 qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
 
+qga-serial-listener$(EXESUF): LIBS = $(LIBS_QGA)
+qga-serial-listener$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
+
 gen-out-type = $(subst .,-,$(suffix $@))
 
 qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
@@ -448,6 +452,11 @@ $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
 qemu-ga$(EXESUF): $(qga-obj-y) $(COMMON_LDADDS)
$(call LINK, $^)
 
+$(qga-serial-listener-obj-y) qga-serial-listener.o: $(QGALIB_GEN)
+
+qga-serial-listener$(EXESUF): $(qga-serial-listener-obj-y) $(COMMON_LDADDS)
+   $(call LINK, $^)
+
 ifdef QEMU_GA_MSI_ENABLED
 QEMU_GA_MSI=qemu-ga-$(ARCH).msi
 
@@ -467,7 +476,7 @@ endif
 
 ifneq ($(EXESUF),)
 .PHONY: qemu-ga
-qemu-ga: qemu-ga$(EXESUF) $(QGA_VSS_PROVIDER) $(QEMU_GA_MSI)
+qemu-ga: qga-serial-listener$(EXESUF) qemu-ga$(EXESUF) $(QGA_VSS_PROVIDER) 
$(QEMU_GA_MSI)
 endif
 
 ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) $(COMMON_LDADDS)
diff --git a/Makefile.objs b/Makefile.objs
index b2e6322..b3fc042 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -103,6 +103,7 @@ target-obj-y += trace/
 # FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
 # by libqemuutil.a.  These should be moved to a separate .json schema.
 qga-obj-y = qga/
+qga-serial-listener-obj-y = qga/
 qga-vss-dll-obj-y = qga/
 
 ##
diff --git a/qga/Makefile.objs b/qga/Makefile.objs
index 1c5986c..f9d0170 100644
--- a/qga/Makefile.objs
+++ b/qga/Makefile.objs
@@ -5,4 +5,6 @@ qga-obj-$(CONFIG_WIN32) += vss-win32.o
 qga-obj-y += qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-visit.o
 qga-obj-y += qapi-generated/qga-qmp-marshal.o
 
+qga-serial-listener-obj-$(CONFIG_WIN32) = service-win32.o 
serial-listener-service-win32.o
+
 qga-vss-dll-obj-$(CONFIG_QGA_VSS) += vss-win32/
diff --git a/qga/channel.h b/qga/channel.h
index 1778416..df53ec9 100644
--- a/qga/channel.h
+++ b/qga/channel.h
@@ -12,6 +12,15 @@
 #ifndef QGA_CHANNEL_H
 #define QGA_CHANNEL_H
 
+#ifndef _WIN32
+#define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
+#define QGA_STATE_RELATIVE_DIR  "run"
+#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
+#else
+#define QGA_VIRTIO_PATH_DEFAULT ".\\Global\\org.qemu.guest_agent.0"
+#define QGA_STATE_RELATIVE_DIR  "qemu-ga"
+#define QGA_SERIAL_PATH_DEFAULT "COM1"
+#endif
 
 typedef struct GAChannel GAChannel;
 
diff --git a/qga/main.c b/qga/main.c
index cc58d2b..44b0822 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -41,15 +41,6 @@
 #endif
 #endif
 
-#ifndef _WIN32
-#define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
-#define QGA_STATE_RELATIVE_DIR  "run"
-#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
-#else
-#define QGA_VIRTIO_PATH_DEFAULT ".\\Global\\org.qemu.guest_agent.0"
-#define QGA_STATE_RELATIVE_DIR  "qemu-ga"
-#define QGA_SERIAL_PATH_DEFA

[Qemu-devel] [PATCH 5/5] qga-win: service-win32: Use get_service function

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/service-win32.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/qga/service-win32.c b/qga/service-win32.c
index 861f9fc..c17e0eb 100644
--- a/qga/service-win32.c
+++ b/qga/service-win32.c
@@ -198,20 +198,12 @@ int ga_install_service(const char *path, const char 
*logfile,
 
 static int uninstall_service(LPCTSTR service_name)
 {
-SC_HANDLE manager;
-SC_HANDLE service;
-
-manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-if (manager == NULL) {
-printf_win_error("No handle to service control manager");
-return EXIT_FAILURE;
-}
+int ret = EXIT_FAILURE;
+SC_HANDLE service = NULL;
+ret = get_service(service_name, );
 
-service = OpenService(manager, service_name, DELETE);
-if (service == NULL) {
-printf_win_error("No handle to service");
-CloseServiceHandle(manager);
-return EXIT_FAILURE;
+if (ret != EXIT_SUCCESS) {
+return ret;
 }
 
 if (DeleteService(service) == FALSE) {
@@ -221,7 +213,6 @@ static int uninstall_service(LPCTSTR service_name)
 }
 
 CloseServiceHandle(service);
-CloseServiceHandle(manager);
 
 return EXIT_SUCCESS;
 }
-- 
2.9.4




[Qemu-devel] [PATCH 2/5] qga-win: service-win32: Add start_service and stop_service functions

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

This commits adds two functions which handle service's start and stop
process in Windows.

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/service-win32.c | 52 
 qga/service-win32.h |  2 ++
 2 files changed, 54 insertions(+)

diff --git a/qga/service-win32.c b/qga/service-win32.c
index fd434e3..dc41d63 100644
--- a/qga/service-win32.c
+++ b/qga/service-win32.c
@@ -95,6 +95,26 @@ static const char *win_escape_arg(const char *to_escape, 
GString *buffer)
 return buffer->str;
 }
 
+
+static int get_service(const char *service_name, SC_HANDLE* service)
+{
+SC_HANDLE manager = NULL;
+manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+if (manager == NULL) {
+printf_win_error("No handle to service control manager");
+return EXIT_FAILURE;
+}
+
+*service = OpenService(manager, service_name, SERVICE_ALL_ACCESS);
+if (service == NULL) {
+printf_win_error("Failed to open service");
+return EXIT_FAILURE;
+}
+
+CloseServiceHandle(manager);
+return EXIT_SUCCESS;
+}
+
 int ga_install_service(const char *path, const char *logfile,
const char *state_dir)
 {
@@ -188,3 +208,35 @@ int ga_uninstall_service(void)
 
 return EXIT_SUCCESS;
 }
+
+int start_service(const char *service_name)
+{
+int ret = EXIT_FAILURE;
+SC_HANDLE service = NULL;
+ret = get_service(service_name, );
+if (ret != EXIT_SUCCESS) {
+return ret;
+}
+ret = StartService(service, 0 , NULL) ? EXIT_SUCCESS : GetLastError();
+
+CloseServiceHandle(service);
+return ret;
+}
+
+int stop_service(const char *service_name)
+{
+int ret = EXIT_FAILURE;
+SC_HANDLE service = NULL;
+
+SERVICE_STATUS service_status;
+ret = get_service(service_name, );
+
+if (ret != EXIT_SUCCESS) {
+return ret;
+}
+ret = ControlService(service, SERVICE_CONTROL_STOP, _status) ?
+EXIT_SUCCESS : GetLastError();
+
+CloseServiceHandle(service);
+return ret;
+}
diff --git a/qga/service-win32.h b/qga/service-win32.h
index 89e99df..65248ea 100644
--- a/qga/service-win32.h
+++ b/qga/service-win32.h
@@ -28,5 +28,7 @@ typedef struct GAService {
 int ga_install_service(const char *path, const char *logfile,
const char *state_dir);
 int ga_uninstall_service(void);
+int start_service(const char *service_name);
+int stop_service(const char *service_name);
 
 #endif
-- 
2.9.4




[Qemu-devel] [PATCH 1/5] Makefile: clean: Clean exe files

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Clean exe files such as qemu-ga.exe

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile b/Makefile
index 16a0430..22d29d6 100644
--- a/Makefile
+++ b/Makefile
@@ -487,6 +487,7 @@ clean:
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
rm -f qemu-options.def
rm -f *.msi
+   rm -f *${EXESUF}
find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name 
'*.[oda]' \) -type f -exec rm {} +
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
rm -f fsdev/*.pod
-- 
2.9.4




[Qemu-devel] [PATCH 4/5] qga-win: Add qga-serial-listener to msi installer

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 qga/installer/qemu-ga.wxs | 24 
 1 file changed, 24 insertions(+)

diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs
index fa2260c..40b7a7b 100644
--- a/qga/installer/qemu-ga.wxs
+++ b/qga/installer/qemu-ga.wxs
@@ -83,6 +83,9 @@
 
 
   
+  
+
+  
   
   
 
@@ -139,6 +142,24 @@
 
 
 
+
+
+
+
+
+
 
 
   
+  
   
   
   
@@ -176,6 +198,8 @@
 
 
 
+  Installed
+  NOT 
REMOVE
   
   Installed
   NOT REMOVE
-- 
2.9.4




[Qemu-devel] [PATCH 0/5] Fix qemu-ga's behaviour on Windows

2017-07-05 Thread Sameeh Jubran
From: Sameeh Jubran <sjub...@redhat.com>

This patch series fixes qemu-ga's main service behaviour on Windows
by listening to the virtio-serial device's events.

For more info on why this series is needed checkout the commit message
of the third patch and the following bugzilla: 
https://bugzilla.redhat.com/show_bug.cgi?id=990629.

Sameeh Jubran (5):
  Makefile: clean: Clean exe files
  qga-win: service-win32: Add start_service and stop_service functions
  qga-win: Add serial listener service
  qga-win: Add qga-serial-listener to msi installer
  qga-win: service-win32: Use get_service function

 Makefile|  12 ++-
 Makefile.objs   |   1 +
 qga/Makefile.objs   |   2 +
 qga/channel.h   |   9 ++
 qga/installer/qemu-ga.wxs   |  24 +
 qga/main.c  |  23 +++--
 qga/serial-listener-service-win32.c | 181 
 qga/serial-listener-service-win32.h |  29 ++
 qga/service-win32.c | 142 +++-
 qga/service-win32.h |   5 +
 10 files changed, 395 insertions(+), 33 deletions(-)
 create mode 100644 qga/serial-listener-service-win32.c
 create mode 100644 qga/serial-listener-service-win32.h

-- 
2.9.4




Re: [Qemu-devel] [PATCH v2 1/1] qga-win: fix installation on localized windows

2017-06-21 Thread Sameeh Jubran
This patch have been waiting too long for a review, Can someone please
review it!!

On Thu, Jun 1, 2017 at 3:07 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Can someone review this patch please?
>
> On Thu, May 25, 2017 at 2:06 PM, Sameeh Jubran <sam...@daynix.com> wrote:
>
>> Ping
>>
>> On Sun, May 14, 2017 at 3:53 PM, Sameeh Jubran <sam...@daynix.com> wrote:
>>
>>> Reviewed-by: Sameeh Jubran <sam...@daynix.com>
>>>
>>> On Thu, Apr 27, 2017 at 4:21 PM, Daniel Rempel <dan...@daynix.com>
>>> wrote:
>>>
>>>> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1357789
>>>> Replace hardcoded user and group names ("Administrators", "SYSTEM")
>>>> with the ones acquired from system. Windows uses localized strings for
>>>> these names and it may cause the installation to fail.
>>>> Windows has Well-known SIDs for "Administrators" group and "SYSTEM"
>>>> user so they were used to identify required users and groups.
>>>> Well-known SIDs: https://support.microsoft.com/
>>>> en-us/help/243330/well-known-security-identifiers-in-windows
>>>> -operating-systems
>>>>
>>>> Signed-off-by: Daniel Rempel <dan...@daynix.com>
>>>> ---
>>>>  qga/vss-win32/install.cpp | 35 +--
>>>>  1 file changed, 33 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
>>>> index f4160a3..1be482a 100644
>>>> --- a/qga/vss-win32/install.cpp
>>>> +++ b/qga/vss-win32/install.cpp
>>>> @@ -18,6 +18,9 @@
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> +#include 
>>>> +
>>>> +#define BUFFER_SIZE 1024
>>>>
>>>>  extern HINSTANCE g_hinstDll;
>>>>
>>>> @@ -135,6 +138,27 @@ out:
>>>>  return hr;
>>>>  }
>>>>
>>>> +/* Acquire group or user name by SID */
>>>> +static HRESULT getNameByStringSID(
>>>> +const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
>>>> +{
>>>> +HRESULT hr = S_OK;
>>>> +PSID psid = NULL;
>>>> +SID_NAME_USE groupType;
>>>> +DWORD domainNameLen = BUFFER_SIZE;
>>>> +wchar_t domainName[BUFFER_SIZE];
>>>> +
>>>> +chk(ConvertStringSidToSidW(sid, ));
>>>> +LookupAccountSidW(NULL, psid, buffer, bufferLen,
>>>> +domainName, , );
>>>> +hr = HRESULT_FROM_WIN32(GetLastError());
>>>> +
>>>> +LocalFree(psid);
>>>> +
>>>> +out:
>>>> +return hr;
>>>> +}
>>>> +
>>>>  /* Find and iterate QGA VSS provider in COM+ Application Catalog */
>>>>  static HRESULT QGAProviderFind(
>>>>  HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
>>>> @@ -216,6 +240,10 @@ STDAPI COMRegister(void)
>>>>  CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
>>>>  bool unregisterOnFailure = false;
>>>>  int count = 0;
>>>> +DWORD bufferLen = BUFFER_SIZE;
>>>> +wchar_t buffer[BUFFER_SIZE];
>>>> +const wchar_t *administratorsGroupSID = L"S-1-5-32-544";
>>>> +const wchar_t *systemUserSID = L"S-1-5-18";
>>>>
>>>>  if (!g_hinstDll) {
>>>>  errmsg(E_FAIL, "Failed to initialize DLL");
>>>> @@ -284,11 +312,12 @@ STDAPI COMRegister(void)
>>>>
>>>>  /* Setup roles of the applicaion */
>>>>
>>>> +chk(getNameByStringSID(administratorsGroupSID, buffer,
>>>> ));
>>>>      chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
>>>>   (IDispatch **)pRoles.replace()));
>>>>  chk(pRoles->Populate());
>>>>  chk(pRoles->Add((IDispatch **)pObj.replace()));
>>>> -chk(put_Value(pObj, L"Name",L"Administrators"));
>>>> +chk(put_Value(pObj, L"Name", buffer));
>>>>  chk(put_Value(pObj, L"Description", L"Administrators group"));
>>>>  chk(pRoles->SaveChanges());
>>>>  chk(pObj->get_Key());
>>>> @@ -303,8 +332,10 @@ STDAPI COMRegister(void)
>>>>  chk(GetAdminName());
>>>>  chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
>>>>
>>>> +bufferLen = BUFFER_SIZE;
>>>> +chk(getNameByStringSID(systemUserSID, buffer, ));
>>>>  chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
>>>> -chk(put_Value(pObj, L"User", L"SYSTEM"));
>>>> +chk(put_Value(pObj, L"User", buffer));
>>>>  chk(pUsersInRole->SaveChanges());
>>>>
>>>>  out:
>>>> --
>>>> 2.9.3
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Respectfully,
>>> *Sameeh Jubran*
>>> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
>>> *Software Engineer @ Daynix <http://www.daynix.com>.*
>>>
>>
>>
>>
>> --
>> Respectfully,
>> *Sameeh Jubran*
>> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
>> *Software Engineer @ Daynix <http://www.daynix.com>.*
>>
>
>
>
> --
> Respectfully,
> *Sameeh Jubran*
> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
> *Software Engineer @ Daynix <http://www.daynix.com>.*
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v2 1/1] qga-win: fix installation on localized windows

2017-06-01 Thread Sameeh Jubran
Can someone review this patch please?

On Thu, May 25, 2017 at 2:06 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Ping
>
> On Sun, May 14, 2017 at 3:53 PM, Sameeh Jubran <sam...@daynix.com> wrote:
>
>> Reviewed-by: Sameeh Jubran <sam...@daynix.com>
>>
>> On Thu, Apr 27, 2017 at 4:21 PM, Daniel Rempel <dan...@daynix.com> wrote:
>>
>>> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1357789
>>> Replace hardcoded user and group names ("Administrators", "SYSTEM") with
>>> the ones acquired from system. Windows uses localized strings for these
>>> names and it may cause the installation to fail.
>>> Windows has Well-known SIDs for "Administrators" group and "SYSTEM" user
>>> so they were used to identify required users and groups.
>>> Well-known SIDs: https://support.microsoft.com/
>>> en-us/help/243330/well-known-security-identifiers-in-windows
>>> -operating-systems
>>>
>>> Signed-off-by: Daniel Rempel <dan...@daynix.com>
>>> ---
>>>  qga/vss-win32/install.cpp | 35 +--
>>>  1 file changed, 33 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
>>> index f4160a3..1be482a 100644
>>> --- a/qga/vss-win32/install.cpp
>>> +++ b/qga/vss-win32/install.cpp
>>> @@ -18,6 +18,9 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>> +
>>> +#define BUFFER_SIZE 1024
>>>
>>>  extern HINSTANCE g_hinstDll;
>>>
>>> @@ -135,6 +138,27 @@ out:
>>>  return hr;
>>>  }
>>>
>>> +/* Acquire group or user name by SID */
>>> +static HRESULT getNameByStringSID(
>>> +const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
>>> +{
>>> +HRESULT hr = S_OK;
>>> +PSID psid = NULL;
>>> +SID_NAME_USE groupType;
>>> +DWORD domainNameLen = BUFFER_SIZE;
>>> +wchar_t domainName[BUFFER_SIZE];
>>> +
>>> +chk(ConvertStringSidToSidW(sid, ));
>>> +LookupAccountSidW(NULL, psid, buffer, bufferLen,
>>> +domainName, , );
>>> +hr = HRESULT_FROM_WIN32(GetLastError());
>>> +
>>> +LocalFree(psid);
>>> +
>>> +out:
>>> +return hr;
>>> +}
>>> +
>>>  /* Find and iterate QGA VSS provider in COM+ Application Catalog */
>>>  static HRESULT QGAProviderFind(
>>>  HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
>>> @@ -216,6 +240,10 @@ STDAPI COMRegister(void)
>>>  CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
>>>  bool unregisterOnFailure = false;
>>>  int count = 0;
>>> +DWORD bufferLen = BUFFER_SIZE;
>>> +wchar_t buffer[BUFFER_SIZE];
>>> +const wchar_t *administratorsGroupSID = L"S-1-5-32-544";
>>> +const wchar_t *systemUserSID = L"S-1-5-18";
>>>
>>>  if (!g_hinstDll) {
>>>  errmsg(E_FAIL, "Failed to initialize DLL");
>>> @@ -284,11 +312,12 @@ STDAPI COMRegister(void)
>>>
>>>  /* Setup roles of the applicaion */
>>>
>>> +chk(getNameByStringSID(administratorsGroupSID, buffer,
>>> ));
>>>  chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
>>>   (IDispatch **)pRoles.replace()));
>>>  chk(pRoles->Populate());
>>>  chk(pRoles->Add((IDispatch **)pObj.replace()));
>>> -chk(put_Value(pObj, L"Name",L"Administrators"));
>>> +chk(put_Value(pObj, L"Name", buffer));
>>>  chk(put_Value(pObj, L"Description", L"Administrators group"));
>>>  chk(pRoles->SaveChanges());
>>>  chk(pObj->get_Key());
>>> @@ -303,8 +332,10 @@ STDAPI COMRegister(void)
>>>  chk(GetAdminName());
>>>  chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
>>>
>>> +bufferLen = BUFFER_SIZE;
>>> +chk(getNameByStringSID(systemUserSID, buffer, ));
>>>  chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
>>> -chk(put_Value(pObj, L"User", L"SYSTEM"));
>>> +chk(put_Value(pObj, L"User", buffer));
>>>  chk(pUsersInRole->SaveChanges());
>>>
>>>  out:
>>> --
>>> 2.9.3
>>>
>>>
>>>
>>
>>
>> --
>> Respectfully,
>> *Sameeh Jubran*
>> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
>> *Software Engineer @ Daynix <http://www.daynix.com>.*
>>
>
>
>
> --
> Respectfully,
> *Sameeh Jubran*
> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
> *Software Engineer @ Daynix <http://www.daynix.com>.*
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v2 1/1] qga-win: fix installation on localized windows

2017-05-25 Thread Sameeh Jubran
Ping

On Sun, May 14, 2017 at 3:53 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Reviewed-by: Sameeh Jubran <sam...@daynix.com>
>
> On Thu, Apr 27, 2017 at 4:21 PM, Daniel Rempel <dan...@daynix.com> wrote:
>
>> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1357789
>> Replace hardcoded user and group names ("Administrators", "SYSTEM") with
>> the ones acquired from system. Windows uses localized strings for these
>> names and it may cause the installation to fail.
>> Windows has Well-known SIDs for "Administrators" group and "SYSTEM" user
>> so they were used to identify required users and groups.
>> Well-known SIDs: https://support.microsoft.com/
>> en-us/help/243330/well-known-security-identifiers-in-windows
>> -operating-systems
>>
>> Signed-off-by: Daniel Rempel <dan...@daynix.com>
>> ---
>>  qga/vss-win32/install.cpp | 35 +--
>>  1 file changed, 33 insertions(+), 2 deletions(-)
>>
>> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
>> index f4160a3..1be482a 100644
>> --- a/qga/vss-win32/install.cpp
>> +++ b/qga/vss-win32/install.cpp
>> @@ -18,6 +18,9 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +
>> +#define BUFFER_SIZE 1024
>>
>>  extern HINSTANCE g_hinstDll;
>>
>> @@ -135,6 +138,27 @@ out:
>>  return hr;
>>  }
>>
>> +/* Acquire group or user name by SID */
>> +static HRESULT getNameByStringSID(
>> +const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
>> +{
>> +HRESULT hr = S_OK;
>> +PSID psid = NULL;
>> +SID_NAME_USE groupType;
>> +DWORD domainNameLen = BUFFER_SIZE;
>> +wchar_t domainName[BUFFER_SIZE];
>> +
>> +chk(ConvertStringSidToSidW(sid, ));
>> +LookupAccountSidW(NULL, psid, buffer, bufferLen,
>> +domainName, , );
>> +hr = HRESULT_FROM_WIN32(GetLastError());
>> +
>> +LocalFree(psid);
>> +
>> +out:
>> +return hr;
>> +}
>> +
>>  /* Find and iterate QGA VSS provider in COM+ Application Catalog */
>>  static HRESULT QGAProviderFind(
>>  HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
>> @@ -216,6 +240,10 @@ STDAPI COMRegister(void)
>>  CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
>>  bool unregisterOnFailure = false;
>>  int count = 0;
>> +DWORD bufferLen = BUFFER_SIZE;
>> +wchar_t buffer[BUFFER_SIZE];
>> +const wchar_t *administratorsGroupSID = L"S-1-5-32-544";
>> +const wchar_t *systemUserSID = L"S-1-5-18";
>>
>>  if (!g_hinstDll) {
>>  errmsg(E_FAIL, "Failed to initialize DLL");
>> @@ -284,11 +312,12 @@ STDAPI COMRegister(void)
>>
>>  /* Setup roles of the applicaion */
>>
>> +chk(getNameByStringSID(administratorsGroupSID, buffer, ));
>>  chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
>>   (IDispatch **)pRoles.replace()));
>>  chk(pRoles->Populate());
>>  chk(pRoles->Add((IDispatch **)pObj.replace()));
>> -chk(put_Value(pObj, L"Name",L"Administrators"));
>> +chk(put_Value(pObj, L"Name", buffer));
>>  chk(put_Value(pObj, L"Description", L"Administrators group"));
>>  chk(pRoles->SaveChanges());
>>  chk(pObj->get_Key());
>> @@ -303,8 +332,10 @@ STDAPI COMRegister(void)
>>  chk(GetAdminName());
>>  chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
>>
>> +bufferLen = BUFFER_SIZE;
>> +chk(getNameByStringSID(systemUserSID, buffer, ));
>>  chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
>> -chk(put_Value(pObj, L"User", L"SYSTEM"));
>> +chk(put_Value(pObj, L"User", buffer));
>>  chk(pUsersInRole->SaveChanges());
>>
>>  out:
>> --
>> 2.9.3
>>
>>
>>
>
>
> --
> Respectfully,
> *Sameeh Jubran*
> *Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
> *Software Engineer @ Daynix <http://www.daynix.com>.*
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH v2] e1000e: Fix ICR "Other" causes clear logic

2017-05-22 Thread Sameeh Jubran
This commit fixes a bug which causes the guest to hang. The bug was observed 
upon a
"receive overrun" (bit #6 of the ICR register) interrupt which could be 
triggered post
migration in a heavy traffic environment. Even though the "receive overrun" bit 
(#6)
is masked out by the IMS register (refer to the log below) the driver still 
receives
an interrupt as the "receive overrun" bit (#6) causes the "Other" - bit #24 of 
the
ICR register - bit to be set as documented below. The driver handles the 
interrupt
and clears the "Other" bit (#24) but doesn't clear the "receive overrun" bit 
(#6)
which leads to an infinite loop. Apparently the Windows driver expects that the
"receive overrun" bit and other ones - documented below - to be cleared when the
"Other" bit (#24) is cleared.

So to sum that up:
1. Bit #6 of the ICR register is set by heavy traffic
2. As a results of setting bit #6, bit #24 is set
3. The driver receives an interrupt for bit 24 (it doesn't receieve an 
interrupt for bit #6 as it is masked out by IMS)
4. The driver handles and clears the interrupt of bit #24
5. Bit #6 is still set.
6. 2 happens all over again

The Interrupt Cause Read - ICR register:

The ICR has the "Other" bit - bit #24 - that is set when one or more of the 
following
ICR register's bits are set:

LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit #17, MNG - 
bit #18

This bug can occur with any of these bits depending on the driver's behaviour 
and
the way it configures the device. However, trying to reproduce it with any bit 
other
than RX0 is challenging and came to failure as the drivers don't implement most 
of
these bits, trying to reproduce it with LSC (Link Status Change - bit #2) bit 
didn't
succeed too as it seems that Windows handles this bit differently.

Log sample of the storm:

27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)
27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)

* This bug behaviour wasn't observed with the Linux driver.

This commit solves:
https://bugzilla.redhat.com/show_bug.cgi?id=1447935
https://bugzilla.redhat.com/show_bug.cgi?id=1449490

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 hw/net/e1000e_core.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index 28c5be1..8174b53 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -2454,14 +2454,17 @@ e1000e_set_ics(E1000ECore *core, int index, uint32_t 
val)
 static void
 e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
 {
+uint32_t icr = 0;
 if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
 (core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
 trace_e1000e_irq_icr_process_iame();
 e1000e_clear_ims_bits(core, core->mac[IAM]);
 }
 
-trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR] & ~val);
-core->mac[ICR] &= ~val;
+icr = core->mac[ICR] & ~val;
+icr = (val & E1000_ICR_OTHER) ? (icr & ~E1000_ICR_OTHER_CAUSES) : icr;
+trace_e1000e_irq_icr_write(val, core->mac[ICR], icr);
+core->mac[ICR] = icr;
 e1000e_update_interrupt_state(core);
 }
 
-- 
2.8.1.185.gdc0db2c




Re: [Qemu-devel] [PATCH] e1000e: Fix a bug where guest hangs upon migration

2017-05-22 Thread Sameeh Jubran
On Mon, May 22, 2017 at 5:46 AM, Jason Wang <jasow...@redhat.com> wrote:

>
>
> On 2017年05月19日 22:04, Sameeh Jubran wrote:
>
>> On Fri, May 19, 2017 at 9:25 AM, Jason Wang <jasow...@redhat.com> wrote:
>>
>>
>>> On 2017年05月17日 19:46, Sameeh Jubran wrote:
>>>
>>> The bug was caused by the "receive overrun" (bit #6 of the ICR register)
>>>> interrupt
>>>> which would be triggered post migration in a heavy traffic environment.
>>>> Even though the
>>>> "receive overrun" bit (#6) is masked out by the IMS register (refer to
>>>> the log below)
>>>> the driver still receives an interrupt as the "receive overrun" bit (#6)
>>>> causes the
>>>> "Other" - bit #24 of the ICR register - bit to be set as documented
>>>> below. The driver
>>>> handles the interrupt and clears the "Other" bit (#24) but doesn't clear
>>>> the
>>>> "receive overrun" bit (#6) which leads to an infinite loop. Apparently
>>>> the Windows
>>>> driver expects that the "receive overrun" bit and other ones -
>>>> documented
>>>> below - to be
>>>> cleared when the "Other" bit (#24) is cleared.
>>>>
>>>> So to sum that up:
>>>> 1. Bit #6 of the ICR register is set by heavy traffic
>>>> 2. As a results of setting bit #6, bit #24 is set
>>>> 3. The driver receives an interrupt for bit 24 (it doesn't receieve an
>>>> interrupt for bit #6 as it is masked out by IMS)
>>>> 4. The driver handles and clears the interrupt of bit #24
>>>> 5. Bit #6 is still set.
>>>> 6. 2 happens all over again
>>>>
>>>> The Interrupt Cause Read - ICR register:
>>>>
>>>> The ICR has the "Other" bit - bit #24 - that is set when one or more of
>>>> the following
>>>> ICR register's bits are set:
>>>>
>>>> LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit
>>>> #17,
>>>> MNG - bit #18
>>>>
>>>> Log sample of the storm:
>>>>
>>>> 27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING:
>>>> 0x100 (ICR: 0x815000c2, IMS: 0x1a4)
>>>> 27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>>>> (ICR: 0x815000c2, IMS: 0xa4)
>>>> 27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING:
>>>> 0x100 (ICR: 0x815000c2, IMS: 0x1a4)
>>>>
>>>> This commit solves:
>>>> https://bugzilla.redhat.com/show_bug.cgi?id=1447935
>>>> https://bugzilla.redhat.com/show_bug.cgi?id=1449490
>>>>
>>>> Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
>>>> ---
>>>>hw/net/e1000e_core.c | 7 +--
>>>>1 file changed, 5 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
>>>> index 28c5be1..8174b53 100644
>>>> --- a/hw/net/e1000e_core.c
>>>> +++ b/hw/net/e1000e_core.c
>>>> @@ -2454,14 +2454,17 @@ e1000e_set_ics(E1000ECore *core, int index,
>>>> uint32_t val)
>>>>static void
>>>>e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
>>>>{
>>>> +uint32_t icr = 0;
>>>>if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
>>>>(core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
>>>>trace_e1000e_irq_icr_process_iame();
>>>>e1000e_clear_ims_bits(core, core->mac[IAM]);
>>>>}
>>>>-trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR]
>>>> &
>>>> ~val);
>>>> -core->mac[ICR]

Re: [Qemu-devel] [PATCH] e1000e: Fix a bug where guest hangs upon migration

2017-05-19 Thread Sameeh Jubran
On Fri, May 19, 2017 at 9:25 AM, Jason Wang <jasow...@redhat.com> wrote:

>
>
> On 2017年05月17日 19:46, Sameeh Jubran wrote:
>
>> The bug was caused by the "receive overrun" (bit #6 of the ICR register)
>> interrupt
>> which would be triggered post migration in a heavy traffic environment.
>> Even though the
>> "receive overrun" bit (#6) is masked out by the IMS register (refer to
>> the log below)
>> the driver still receives an interrupt as the "receive overrun" bit (#6)
>> causes the
>> "Other" - bit #24 of the ICR register - bit to be set as documented
>> below. The driver
>> handles the interrupt and clears the "Other" bit (#24) but doesn't clear
>> the
>> "receive overrun" bit (#6) which leads to an infinite loop. Apparently
>> the Windows
>> driver expects that the "receive overrun" bit and other ones - documented
>> below - to be
>> cleared when the "Other" bit (#24) is cleared.
>>
>> So to sum that up:
>> 1. Bit #6 of the ICR register is set by heavy traffic
>> 2. As a results of setting bit #6, bit #24 is set
>> 3. The driver receives an interrupt for bit 24 (it doesn't receieve an
>> interrupt for bit #6 as it is masked out by IMS)
>> 4. The driver handles and clears the interrupt of bit #24
>> 5. Bit #6 is still set.
>> 6. 2 happens all over again
>>
>> The Interrupt Cause Read - ICR register:
>>
>> The ICR has the "Other" bit - bit #24 - that is set when one or more of
>> the following
>> ICR register's bits are set:
>>
>> LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit #17,
>> MNG - bit #18
>>
>> Log sample of the storm:
>>
>> 27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING:
>> 0x100 (ICR: 0x815000c2, IMS: 0x1a4)
>> 27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0
>> (ICR: 0x815000c2, IMS: 0xa4)
>> 27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING:
>> 0x100 (ICR: 0x815000c2, IMS: 0x1a4)
>>
>> This commit solves:
>> https://bugzilla.redhat.com/show_bug.cgi?id=1447935
>> https://bugzilla.redhat.com/show_bug.cgi?id=1449490
>>
>> Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
>> ---
>>   hw/net/e1000e_core.c | 7 +--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
>> index 28c5be1..8174b53 100644
>> --- a/hw/net/e1000e_core.c
>> +++ b/hw/net/e1000e_core.c
>> @@ -2454,14 +2454,17 @@ e1000e_set_ics(E1000ECore *core, int index,
>> uint32_t val)
>>   static void
>>   e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
>>   {
>> +uint32_t icr = 0;
>>   if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
>>   (core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
>>   trace_e1000e_irq_icr_process_iame();
>>   e1000e_clear_ims_bits(core, core->mac[IAM]);
>>   }
>>   -trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR] &
>> ~val);
>> -core->mac[ICR] &= ~val;
>> +icr = core->mac[ICR] & ~val;
>> +icr = (val & E1000_ICR_OTHER) ? (icr & ~E1000_ICR_OTHER_CAUSES) :
>> icr;
>> +trace_e1000e_irq_icr_write(val, core->mac[ICR], icr);
>> +core->mac[ICR] = icr;
>>   e1000e_update_interrupt_state(core);
>>   }
>>
>>
>
> Thanks for the patch.
>
> So this is an undocumented behavior, we must be careful on this. Several
> question below:
>
> - have you verified this on real hardware?
>
No I haven't

> - is MSIX enabled in this case?
>
Yes it is, I have tested the patch with msi disabled too.

> - according to the steps you've summed up above, it's not specific to
> migration?
>
True

>
> Thanks
>



-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH] e1000e: Fix a bug where guest hangs upon migration

2017-05-17 Thread Sameeh Jubran
The bug was caused by the "receive overrun" (bit #6 of the ICR register) 
interrupt
which would be triggered post migration in a heavy traffic environment. Even 
though the
"receive overrun" bit (#6) is masked out by the IMS register (refer to the log 
below)
the driver still receives an interrupt as the "receive overrun" bit (#6) causes 
the
"Other" - bit #24 of the ICR register - bit to be set as documented below. The 
driver
handles the interrupt and clears the "Other" bit (#24) but doesn't clear the
"receive overrun" bit (#6) which leads to an infinite loop. Apparently the 
Windows
driver expects that the "receive overrun" bit and other ones - documented below 
- to be
cleared when the "Other" bit (#24) is cleared.

So to sum that up:
1. Bit #6 of the ICR register is set by heavy traffic
2. As a results of setting bit #6, bit #24 is set
3. The driver receives an interrupt for bit 24 (it doesn't receieve an 
interrupt for bit #6 as it is masked out by IMS)
4. The driver handles and clears the interrupt of bit #24
5. Bit #6 is still set.
6. 2 happens all over again

The Interrupt Cause Read - ICR register:

The ICR has the "Other" bit - bit #24 - that is set when one or more of the 
following
ICR register's bits are set:

LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit #17, MNG - 
bit #18

Log sample of the storm:

27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)
27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 
0x815000c2, IMS: 0xa4)
27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING: 0x100 
(ICR: 0x815000c2, IMS: 0x1a4)

This commit solves:
https://bugzilla.redhat.com/show_bug.cgi?id=1447935
https://bugzilla.redhat.com/show_bug.cgi?id=1449490

Signed-off-by: Sameeh Jubran <sjub...@redhat.com>
---
 hw/net/e1000e_core.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index 28c5be1..8174b53 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -2454,14 +2454,17 @@ e1000e_set_ics(E1000ECore *core, int index, uint32_t 
val)
 static void
 e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
 {
+uint32_t icr = 0;
 if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
 (core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
 trace_e1000e_irq_icr_process_iame();
 e1000e_clear_ims_bits(core, core->mac[IAM]);
 }
 
-trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR] & ~val);
-core->mac[ICR] &= ~val;
+icr = core->mac[ICR] & ~val;
+icr = (val & E1000_ICR_OTHER) ? (icr & ~E1000_ICR_OTHER_CAUSES) : icr;
+trace_e1000e_irq_icr_write(val, core->mac[ICR], icr);
+core->mac[ICR] = icr;
 e1000e_update_interrupt_state(core);
 }
 
-- 
2.8.1.185.gdc0db2c




Re: [Qemu-devel] [PATCH v2 1/1] qga-win: fix installation on localized windows

2017-05-14 Thread Sameeh Jubran
Reviewed-by: Sameeh Jubran <sam...@daynix.com>

On Thu, Apr 27, 2017 at 4:21 PM, Daniel Rempel <dan...@daynix.com> wrote:

> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1357789
> Replace hardcoded user and group names ("Administrators", "SYSTEM") with
> the ones acquired from system. Windows uses localized strings for these
> names and it may cause the installation to fail.
> Windows has Well-known SIDs for "Administrators" group and "SYSTEM" user
> so they were used to identify required users and groups.
> Well-known SIDs: https://support.microsoft.com/
> en-us/help/243330/well-known-security-identifiers-in-
> windows-operating-systems
>
> Signed-off-by: Daniel Rempel <dan...@daynix.com>
> ---
>  qga/vss-win32/install.cpp | 35 +--
>  1 file changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index f4160a3..1be482a 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -18,6 +18,9 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +
> +#define BUFFER_SIZE 1024
>
>  extern HINSTANCE g_hinstDll;
>
> @@ -135,6 +138,27 @@ out:
>  return hr;
>  }
>
> +/* Acquire group or user name by SID */
> +static HRESULT getNameByStringSID(
> +const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
> +{
> +HRESULT hr = S_OK;
> +PSID psid = NULL;
> +SID_NAME_USE groupType;
> +DWORD domainNameLen = BUFFER_SIZE;
> +wchar_t domainName[BUFFER_SIZE];
> +
> +chk(ConvertStringSidToSidW(sid, ));
> +LookupAccountSidW(NULL, psid, buffer, bufferLen,
> +domainName, , );
> +hr = HRESULT_FROM_WIN32(GetLastError());
> +
> +LocalFree(psid);
> +
> +out:
> +return hr;
> +}
> +
>  /* Find and iterate QGA VSS provider in COM+ Application Catalog */
>  static HRESULT QGAProviderFind(
>  HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
> @@ -216,6 +240,10 @@ STDAPI COMRegister(void)
>  CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
>  bool unregisterOnFailure = false;
>  int count = 0;
> +DWORD bufferLen = BUFFER_SIZE;
> +wchar_t buffer[BUFFER_SIZE];
> +const wchar_t *administratorsGroupSID = L"S-1-5-32-544";
> +const wchar_t *systemUserSID = L"S-1-5-18";
>
>  if (!g_hinstDll) {
>  errmsg(E_FAIL, "Failed to initialize DLL");
> @@ -284,11 +312,12 @@ STDAPI COMRegister(void)
>
>  /* Setup roles of the applicaion */
>
> +chk(getNameByStringSID(administratorsGroupSID, buffer, ));
>  chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
>   (IDispatch **)pRoles.replace()));
>  chk(pRoles->Populate());
>  chk(pRoles->Add((IDispatch **)pObj.replace()));
> -chk(put_Value(pObj, L"Name",L"Administrators"));
> +chk(put_Value(pObj, L"Name", buffer));
>  chk(put_Value(pObj, L"Description", L"Administrators group"));
>  chk(pRoles->SaveChanges());
>  chk(pObj->get_Key());
> @@ -303,8 +332,10 @@ STDAPI COMRegister(void)
>  chk(GetAdminName());
>  chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
>
> +bufferLen = BUFFER_SIZE;
> +chk(getNameByStringSID(systemUserSID, buffer, ));
>  chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
> -chk(put_Value(pObj, L"User", L"SYSTEM"));
> +chk(put_Value(pObj, L"User", buffer));
>  chk(pUsersInRole->SaveChanges());
>
>  out:
> --
> 2.9.3
>
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v2 0/1] qga-win: fix installation on localized Windows

2017-05-04 Thread Sameeh Jubran
Acked-by: Sameeh Jubran <sam...@daynix.com>

On Thu, Apr 27, 2017 at 4:21 PM, Daniel Rempel <dan...@daynix.com> wrote:

> Second version of the patch. Cleaned the code a bit.
>
> Daniel Rempel (1):
>   qga-win: fix installation on localized windows
>
>  qga/vss-win32/install.cpp | 35 +--
>  1 file changed, 33 insertions(+), 2 deletions(-)
>
> --
> 2.9.3
>
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH] qga-win: Enable 'can-offline' field in 'guest-get-vcpus' reply

2017-04-11 Thread Sameeh Jubran
The QGA schema states:

@can-offline: Whether offlining the VCPU is possible. This member
   is always filled in by the guest agent when the structure
   is returned, and always ignored on input (hence it can be
   omitted then).

Currently 'can-offline' is missing entirely from the reply. This causes
errors in libvirt which is expecting the reply to be compliant with the
schema docs.

BZ#1438735: https://bugzilla.redhat.com/show_bug.cgi?id=1438735

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 19d72b2..f0d72a0 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1344,7 +1344,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error 
**errp)
 vcpu = g_malloc0(sizeof *vcpu);
 vcpu->logical_id = current++;
 vcpu->online = true;
-vcpu->has_can_offline = false;
+vcpu->has_can_offline = true;
 
 entry = g_malloc0(sizeof *entry);
 entry->value = vcpu;
-- 
2.9.3




[Qemu-devel] Windows 10 IoT Core Raspberry Pi 2 on top of Qemu

2017-04-11 Thread Sameeh Jubran
Hi all,

I am trying to run Windows 10 IoT Core for Raspberry Pi 2 on top of Qemu
with no luck. I am using this repository https://github.com/0xabu/qemu, and
I am using a newer build of Windows IoT core (1607) as earlier versions
aren't available to download from Microsoft.

The first core is stuck in an infinite loop and the other cores are halted!
Anyone else faced this issue? Is there any version of Windows 10 IoT Core
ARM that can run on top of Qemu?


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH v3] qga-win: Fix a bug where qemu-ga service is stuck during stop operation

2017-04-11 Thread Sameeh Jubran
After triggering a freeze command without any following thaw command,
qemu-ga will not respond to stop operation. This behaviour is wanted on Linux
as there is no time limit for a freeze command and we want to prevent
quitting in the middle of freeze, on the other hand on Windows the time
limit for freeze is 10 seconds, so we should wait for the timeout, thaw
the file system and quit.

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
---
 qga/main.c  | 23 +++
 qga/vss-win32.h |  1 +
 qga/vss-win32/vss-common.h  | 11 +--
 qga/vss-win32/vss-handles.h | 14 ++
 4 files changed, 39 insertions(+), 10 deletions(-)
 create mode 100644 qga/vss-win32/vss-handles.h

diff --git a/qga/main.c b/qga/main.c
index 07c2953..8269bf4 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -131,9 +131,32 @@ static void quit_handler(int sig)
  * unless all log/pid files are on unfreezable filesystems. there's
  * also a very likely chance killing the agent before unfreezing
  * the filesystems is a mistake (or will be viewed as one later).
+ * On Windows the freeze interval is limited to 10 seconds, so
+ * we should quit, but first we should wait for the timeout, thaw
+ * the filesystem and quit.
  */
 if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+int i = 0;
+Error *err = NULL;
+HANDLE hEventTimeout;
+
+g_debug("Thawing filesystems before exiting");
+
+hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT);
+if (hEventTimeout) {
+WaitForSingleObject(hEventTimeout, 0);
+CloseHandle(hEventTimeout);
+}
+qga_vss_fsfreeze(, , false);
+if (err) {
+g_debug("Error unfreezing filesystems prior to exiting: %s",
+error_get_pretty(err));
+error_free(err);
+}
+#else
 return;
+#endif
 }
 g_debug("received signal num %d, quitting", sig);
 
diff --git a/qga/vss-win32.h b/qga/vss-win32.h
index 4d1d150..cd9f26e 100644
--- a/qga/vss-win32.h
+++ b/qga/vss-win32.h
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-handles.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
diff --git a/qga/vss-win32/vss-common.h b/qga/vss-win32/vss-common.h
index c81a856..61c170b 100644
--- a/qga/vss-win32/vss-common.h
+++ b/qga/vss-win32/vss-common.h
@@ -51,21 +51,12 @@
  * http://www.microsoft.com/en-us/download/details.aspx?id=23490
  */
 #include 
+#include "vss-handles.h"
 
 /* Macros to convert char definitions to wchar */
 #define _L(a) L##a
 #define L(a) _L(a)
 
-/* Constants for QGA VSS Provider */
-
-#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
-#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
-#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
-
-#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
-#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
-#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
-
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
 {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
diff --git a/qga/vss-win32/vss-handles.h b/qga/vss-win32/vss-handles.h
new file mode 100644
index 000..ff399dd
--- /dev/null
+++ b/qga/vss-win32/vss-handles.h
@@ -0,0 +1,14 @@
+#ifndef VSS_HANDLES
+#define VSS_HANDLES
+
+/* Constants for QGA VSS Provider */
+
+#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
+#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
+#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
+
+#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
+#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
+#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
+
+#endif
-- 
2.9.3




Re: [Qemu-devel] [PATCH qemu-ga] qemu-ga: Don't display errors to the user on thaw command

2017-04-05 Thread Sameeh Jubran
On Wed, Apr 5, 2017 at 1:55 AM, Michael Roth <mdr...@linux.vnet.ibm.com>
wrote:

> Quoting Sameeh Jubran (2017-03-21 09:14:35)
> > Errors that are related to ur inner implementation for the thaw command
> > shouldn't be displayed to the user.
> >
> > Signed-off-by: Sameeh Jubran <sam...@daynix.com>
> > ---
> >  qga/vss-win32/requester.cpp | 8 
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
> > index 0cd2f0e..272e71b 100644
> > --- a/qga/vss-win32/requester.cpp
> > +++ b/qga/vss-win32/requester.cpp
> > @@ -463,7 +463,7 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
> >  hr = WaitForAsync(pAsync);
> >  }
> >  if (FAILED(hr)) {
> > -err_set(errset, hr, "failed to complete backup");
>
> We cannot do this. If the freeze operation didn't successfully maintain
> the frozen state for entire duration we *must* report an error to the
> user, otherwise users have no way to know that their snapshot might be
> completely corrupted. Well, I suppose they can look at
> guest-fsfreeze-thaw's return value and check that it matches the number
> of volumes that were originally frozen, but that aspect is intended as a
> sanity check to identify situations outside of qemu-ga's control, like
> another user/application unfreezing the filesystems before qemu-ga. This
> situation *is* within qemu-ga's control, and should be reported as an
> error. Same for the other failures below.

This patch was introduced to hide the error "{"error": {"class":
"GenericError", "desc": "couldn't hold writes: fsfreeze is limited up to 10
seconds: "}" which shows up whenever we
execute thaw after 10 seconds have passed from freeze event and in order to
align the behaviour Windows with Linux. However I agree with you about
informing the user about possible
corruption during the backup operation.

>


> > +fprintf(stderr, "failed to complete backup");
> >  }
> >  break;
> >
> > @@ -480,18 +480,18 @@ void requester_thaw(int *num_vols, ErrorSet
> *errset)
> >
> >  case VSS_E_UNEXPECTED_PROVIDER_ERROR:
> >  if (WaitForSingleObject(vss_ctx.hEventTimeout, 0) !=
> WAIT_OBJECT_0) {
> > -err_set(errset, hr, "unexpected error in VSS provider");
> > +fprintf(stderr, "unexpected error in VSS provider");
> >  break;
> >  }
> >  /* fall through if hEventTimeout is signaled */
> >
> >  case (HRESULT)VSS_E_HOLD_WRITES_TIMEOUT:
> > -err_set(errset, hr, "couldn't hold writes: "
> > +    fprintf(stderr, "couldn't hold writes: "
> >  "fsfreeze is limited up to 10 seconds");
> >  break;
> >
> >  default:
> > -err_set(errset, hr, "failed to do snapshot set");
> > +fprintf(stderr, "failed to do snapshot set");
> >  }
> >
> >  if (err_is_set(errset)) {
> > --
> > 2.9.3
> >
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH v2] qga-win: Fix Event Viewer errors caused by qemu-ga

2017-04-05 Thread Sameeh Jubran
When the command "guest-fsfreeze-freeze" is executed it causes
the VSS service to log the error below in the Event Viewer. This
error is caused by an issue in the function "CommitSnapshots" in
provider.cpp:

* When VSS_TIMEOUT_MSEC expires the funtion returns E_ABORT. This causes
the error #12293.

|event id|   error   |
* 12293  : Volume Shadow Copy Service error: Error calling a routine on a
   Shadow Copy Provider {----}.
   Routine details CommitSnapshots [hr = 0x80004004, Operation
   aborted.

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
---
 qga/vss-win32/provider.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/qga/vss-win32/provider.cpp b/qga/vss-win32/provider.cpp
index ef94669..72d8b0e 100644
--- a/qga/vss-win32/provider.cpp
+++ b/qga/vss-win32/provider.cpp
@@ -377,7 +377,6 @@ STDMETHODIMP CQGAVssProvider::CommitSnapshots(VSS_ID 
SnapshotSetId)
 if (WaitForSingleObject(hEventThaw, VSS_TIMEOUT_MSEC) != WAIT_OBJECT_0) {
 /* Send event to qemu-ga to notify the provider is timed out */
 SetEvent(hEventTimeout);
-hr = E_ABORT;
 }
 
 CloseHandle(hEventThaw);
-- 
2.9.3




[Qemu-devel] [PATCH v2] qga-win: Fix a bug where qemu-ga service is stuck during stop operation

2017-04-05 Thread Sameeh Jubran
After triggering a freeze command without any following thaw command,
qemu-ga will not respond to stop operation. This behaviour is wanted on Linux
as there is no time limit for a freeze command and we want to prevent
quitting in the middle of freeze, on the other hand on Windows the time
limit for freeze is 10 seconds, so we should wait for the timeout, thaw
the file system and quit.

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
---
 qga/main.c  | 22 ++
 qga/vss-win32.h |  1 +
 qga/vss-win32/vss-common.h  | 11 +--
 qga/vss-win32/vss-handles.h | 14 ++
 4 files changed, 38 insertions(+), 10 deletions(-)
 create mode 100644 qga/vss-win32/vss-handles.h

diff --git a/qga/main.c b/qga/main.c
index 07c2953..96072fb 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -131,9 +131,31 @@ static void quit_handler(int sig)
  * unless all log/pid files are on unfreezable filesystems. there's
  * also a very likely chance killing the agent before unfreezing
  * the filesystems is a mistake (or will be viewed as one later).
+ * On Windows the freeze interval is limited to 10 seconds, so
+ * we should quit, but first we should wait for the timeout, thaw
+ * the filesystem and quit.
  */
 if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+int i = 0;
+Error *err = NULL;
+HANDLE hEventTimeout;
+
+g_debug("Thawing filesystems before exiting");
+
+hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT);
+if (hEventTimeout) {
+WaitForSingleObject(hEventTimeout, 0);
+CloseHandle(hEventTimeout);
+}
+qga_vss_fsfreeze(, , false);
+if (err) {
+g_debug("Error unfreezing filesystems prior to exiting: %s", 
error_get_pretty(err));
+error_free(err);
+}
+#else
 return;
+#endif
 }
 g_debug("received signal num %d, quitting", sig);
 
diff --git a/qga/vss-win32.h b/qga/vss-win32.h
index 4d1d150..cd9f26e 100644
--- a/qga/vss-win32.h
+++ b/qga/vss-win32.h
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-handles.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
diff --git a/qga/vss-win32/vss-common.h b/qga/vss-win32/vss-common.h
index c81a856..61c170b 100644
--- a/qga/vss-win32/vss-common.h
+++ b/qga/vss-win32/vss-common.h
@@ -51,21 +51,12 @@
  * http://www.microsoft.com/en-us/download/details.aspx?id=23490
  */
 #include 
+#include "vss-handles.h"
 
 /* Macros to convert char definitions to wchar */
 #define _L(a) L##a
 #define L(a) _L(a)
 
-/* Constants for QGA VSS Provider */
-
-#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
-#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
-#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
-
-#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
-#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
-#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
-
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
 {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
diff --git a/qga/vss-win32/vss-handles.h b/qga/vss-win32/vss-handles.h
new file mode 100644
index 000..ff399dd
--- /dev/null
+++ b/qga/vss-win32/vss-handles.h
@@ -0,0 +1,14 @@
+#ifndef VSS_HANDLES
+#define VSS_HANDLES
+
+/* Constants for QGA VSS Provider */
+
+#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
+#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
+#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
+
+#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
+#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
+#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
+
+#endif
-- 
2.9.3




Re: [Qemu-devel] [PATCH v5] qga: Add `guest-get-timezone` command

2017-04-04 Thread Sameeh Jubran
I have tested the patch on Windows 2012 R2

Reviewed-by: Sameeh Jubran <sam...@daynix.com>
Tested-by: Sameeh Jubran <sam...@daynix.com>

On Thu, Mar 23, 2017 at 2:39 PM, Vinzenz 'evilissimo' Feenstra <
vfeen...@redhat.com> wrote:

> From: Vinzenz Feenstra <vfeen...@redhat.com>
>
> Adds a new command `guest-get-timezone` reporting the currently
> configured timezone on the system. The information on what timezone is
> currently is configured is useful in case of Windows VMs where the
> offset of the hardware clock is required to have the same offset. This
> can be used for management systems like `oVirt` to detect the timezone
> difference and warn administrators of the misconfiguration.
>
> Signed-off-by: Vinzenz Feenstra <vfeen...@redhat.com>
> ---
>  qga/commands.c   | 29 +
>  qga/qapi-schema.json | 26 ++
>  2 files changed, 55 insertions(+)
>
> diff --git a/qga/commands.c b/qga/commands.c
> index 4d92946..3b5789c 100644
> --- a/qga/commands.c
> +++ b/qga/commands.c
> @@ -499,3 +499,32 @@ int ga_parse_whence(GuestFileWhence *whence, Error
> **errp)
>  error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
>  return -1;
>  }
> +
> +GuestTimezone *qmp_guest_get_timezone(Error **errp)
> +{
> +GuestTimezone *info = g_new0(GuestTimezone, 1);
> +GTimeZone *tz = g_time_zone_new_local();
> +if (tz == NULL) {
> +error_setg(errp, QERR_QGA_COMMAND_FAILED,
> +   "Couldn't retrieve local timezone");
> +goto error;
> +}
> +
> +gint64 now = g_get_real_time() / G_USEC_PER_SEC;
> +gint32 intv = g_time_zone_find_interval(tz, G_TIME_TYPE_UNIVERSAL,
> now);
> +info->offset = g_time_zone_get_offset(tz, intv);
> +gchar const *name = g_time_zone_get_abbreviation(tz, intv);
> +if (name != NULL) {
> +info->has_zone = true;
> +info->zone = g_strdup(name);
> +}
> +g_time_zone_unref(tz);
> +
> +return info;
> +
> +error:
> +g_time_zone_unref(tz);
> +g_free(info);
> +return NULL;
> +}
> +
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index a02dbf2..5183ea2 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -1042,3 +1042,29 @@
>'data':{ 'path': 'str', '*arg': ['str'], '*env': ['str'],
> '*input-data': 'str', '*capture-output': 'bool' },
>'returns': 'GuestExec' }
> +
> +
> +##
> +# @GuestTimezone:
> +#
> +# @zone:Timezone name
> +# @offset:  Offset to UTC in seconds, negative numbers for time zones
> west of
> +#   GMT, positive numbers for east
> +#
> +# Since: 2.10
> +##
> +{ 'struct': 'GuestTimezone',
> +  'data':   { '*zone': 'str', 'offset': 'int' } }
> +
> +
> +##
> +# @guest-get-timezone:
> +#
> +# Retrieves the timezone information from the guest.
> +#
> +# Returns: A GuestTimezone dictionary.
> +#
> +# Since: 2.10
> +##
> +{ 'command': 'guest-get-timezone',
> +  'returns': 'GuestTimezone' }
> --
> 2.9.3
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH qemu-ga] qemu-ga: Don't display errors to the user on thaw command

2017-04-02 Thread Sameeh Jubran
Ping.

On Tue, Mar 21, 2017 at 5:14 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Errors that are related to ur inner implementation for the thaw command
> shouldn't be displayed to the user.
>
> Signed-off-by: Sameeh Jubran <sam...@daynix.com>
> ---
>  qga/vss-win32/requester.cpp | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
> index 0cd2f0e..272e71b 100644
> --- a/qga/vss-win32/requester.cpp
> +++ b/qga/vss-win32/requester.cpp
> @@ -463,7 +463,7 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
>  hr = WaitForAsync(pAsync);
>  }
>  if (FAILED(hr)) {
> -err_set(errset, hr, "failed to complete backup");
> +fprintf(stderr, "failed to complete backup");
>  }
>  break;
>
> @@ -480,18 +480,18 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
>
>  case VSS_E_UNEXPECTED_PROVIDER_ERROR:
>  if (WaitForSingleObject(vss_ctx.hEventTimeout, 0) !=
> WAIT_OBJECT_0) {
> -err_set(errset, hr, "unexpected error in VSS provider");
> +fprintf(stderr, "unexpected error in VSS provider");
>  break;
>  }
>  /* fall through if hEventTimeout is signaled */
>
>  case (HRESULT)VSS_E_HOLD_WRITES_TIMEOUT:
> -err_set(errset, hr, "couldn't hold writes: "
> +fprintf(stderr, "couldn't hold writes: "
>  "fsfreeze is limited up to 10 seconds");
>  break;
>
>  default:
> -    err_set(errset, hr, "failed to do snapshot set");
> +fprintf(stderr, "failed to do snapshot set");
>  }
>
>  if (err_is_set(errset)) {
> --
> 2.9.3
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH qemu-ga] Fix a bug where qemu-ga service is stuck during stop operation

2017-04-02 Thread Sameeh Jubran
Ping.

On Tue, Mar 21, 2017 at 4:59 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> After triggering a freeze command without any following thaw command,
> qemu-ga will not respond to stop operation. This behaviour is wanted on
> Linux
> as there is no time limit for a freeze command and we want to prevent
> quitting in the middle of freeze, on the other hand on Windows the time
> limit for freeze is 10 seconds, so we should wait for the timeout, thaw
> the file system and quit.
>
> Signed-off-by: Sameeh Jubran <sam...@daynix.com>
> ---
>  qga/main.c | 20 
>  qga/vss-win32.h|  1 +
>  qga/vss-win32/vss-common.h |  5 +
>  3 files changed, 26 insertions(+)
>
> diff --git a/qga/main.c b/qga/main.c
> index 92658bc..de37c85 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -130,9 +130,29 @@ static void quit_handler(int sig)
>   * unless all log/pid files are on unfreezable filesystems. there's
>   * also a very likely chance killing the agent before unfreezing
>   * the filesystems is a mistake (or will be viewed as one later).
> + * On Windows the freeze interval is limited to 10 seconds, so
> + * we should quit, but first we should wait for the timeout, thaw
> + * the filesystem and quit.
>   */
>  if (ga_is_frozen(ga_state)) {
> +#ifdef _WIN32
> +int i = 0;
> +Error *err = NULL;
> +HANDLE hEventTimeout;
> +
> +hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE,
> EVENT_NAME_TIMEOUT);
> +if (hEventTimeout) {
> +WaitForSingleObject(hEventTimeout, 0);
> +CloseHandle(hEventTimeout);
> +}
> +qga_vss_fsfreeze(, , false);
> +if (err) {
> +g_debug("Error: %s", error_get_pretty(err));
> +error_free(err);
> +}
> +#else
>  return;
> +#endif
>  }
>  g_debug("received signal num %d, quitting", sig);
>
> diff --git a/qga/vss-win32.h b/qga/vss-win32.h
> index 4d1d150..5f4ea70 100644
> --- a/qga/vss-win32.h
> +++ b/qga/vss-win32.h
> @@ -13,6 +13,7 @@
>  #ifndef VSS_WIN32_H
>  #define VSS_WIN32_H
>
> +#include "qga/vss-win32/vss-common.h"
>
>  bool vss_init(bool init_requester);
>  void vss_deinit(bool deinit_requester);
> diff --git a/qga/vss-win32/vss-common.h b/qga/vss-win32/vss-common.h
> index c81a856..5756d00 100644
> --- a/qga/vss-win32/vss-common.h
> +++ b/qga/vss-win32/vss-common.h
> @@ -12,6 +12,7 @@
>
>  #ifndef VSS_COMMON_H
>  #define VSS_COMMON_H
> +#ifndef VSS_WIN32_H
>
>  #define __MIDL_user_allocate_free_DEFINED__
>  #include 
> @@ -57,6 +58,7 @@
>  #define L(a) _L(a)
>
>  /* Constants for QGA VSS Provider */
> +#endif
>
>  #define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
>  #define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
> @@ -66,6 +68,8 @@
>  #define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
>  #define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
>
> +#ifndef VSS_WIN32_H
> +
>  const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
>  {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
>  const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
> @@ -126,3 +130,4 @@ public:
>  };
>
>  #endif
> +#endif
> --
> 2.9.3
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH] Fix Event Viewer errors caused by qemu-ga

2017-04-02 Thread Sameeh Jubran
Ping.

On Wed, Mar 22, 2017 at 11:14 AM, Sameeh Jubran <sam...@daynix.com> wrote:

>
>
> On Tue, Mar 21, 2017 at 6:09 PM, Michael Roth <mdr...@linux.vnet.ibm.com>
> wrote:
>
>> Quoting Sameeh Jubran (2017-03-21 05:49:52)
>> > When the command "guest-fsfreeze-freeze" is executed it causes
>> > the VSS service to log the errors below in the Event Viewer.
>> >
>> > These errors are caused by two issues in the function "CommitSnapshots"
>> in
>> > provider.cpp:
>> >
>> > 1. When VSS_TIMEOUT_MSEC expires the funtion returns E_ABORT. This
>> causes
>> > the error #12293.
>> >
>> > 2. The VSS_TIMEOUT_MSEC value is too big. According to msdn the
>> > "Flush & Hold" operation has 10 seconds timeout not configurable, The
>> > "CommitSnapshots" is a part of the "Flush & Hold" process and thus any
>> > timeout bigger than 10 seconds would cause the error #12298 and anything
>> > bigger than 40 seconds causes the error #12340. All this info can be
>> found here:
>> > https://msdn.microsoft.com/en-us/library/windows/desktop/aa3
>> 84589(v=vs.85).aspx
>>
>> Not sure how best to deal with this. Technically our CommitSnapshots
>> interface is driven by the backup job being run by QGA/QEMU management
>> side. If that amount of time exceeds the VSS limits then I think it's
>> appropriate for VSS to log the error accordingly. VSS_TIMEOUT_MSEC here
>> doesn't actually have too much correlation with the VSS-set timeout,
>> IIRC it's specifically picked to exceed both the 10 and 40 second
>> timeouts and acts more as a fail-safe timeout.
>
> The timeout was added in #commit: b39297aedfabe9b2c426cd540413be991500da25
> There is no point in setting the TIMEOUT for this long as the actual
> freeze - Fush and Hold Writes -
> is limited to 10 seconds ( not configurable) according to msdn
> https://msdn.microsoft.com/en-us/library/windows/
> desktop/aa384589%28v=vs.85%29.aspx
>
>>
>> Are the event logs causing issues? FWIW, on the posix side we also opt
>> for gratuitous logging to syslog and such, the idea there being that
>> cooperative guests would prefer transparency on how the agent is being
>> used.
>>
> Apparently, these error logs are annoying to some (
> https://bugzilla.redhat.com/show_bug.cgi?id=1387125),
> moreover I don't think that our implementation to the freeze operation -
> which is a workaround in a way -
> should log errors even though we know they are false alarm.
>
>>
>> That said, I do think error 12293 is unecessary, since IIUC it would
>> always be paired with the actual VSS-reported error. So avoiding the
>> E_ABORT seems reasonable either way.
>>
>> >
>> > |event id|   error
>>  |
>> > * 12293  : Volume Shadow Copy Service error: Error calling a routine on
>> a
>> >Shadow Copy Provider {----}.
>> >Routine details CommitSnapshots [hr = 0x80004004, Operation
>> >aborted.
>> >
>> > * 12340  : Volume Shadow Copy Error: VSS waited more than 40 seconds for
>> >all volumes to be flushed.  This caused volume
>> >\\?\Volume{62a171da-32ec-11e4-80b1-806e6f6e6963}\ to timeout
>> >while waiting for the release-writes phase of shadow copy
>> >creation. Trying again when disk activity is lower may solve
>> >this problem.
>> >
>> > * 12298  : Volume Shadow Copy Service error: The I/O writes cannot be
>> held
>> >during the shadow copy creation period on volume
>> >\\?\Volume{62a171d9-32ec-11e4-80b1-806e6f6e6963}\. The
>> volume
>> >index in the shadow copy set is 0. Error details:
>> >Open[0x, The operation completed successfully. ],
>> >Flush[0x, The operation completed successfully.],
>> >Release[0x, The operation completed successfully.],
>> >OnRun[0x80042314, The shadow copy provider timed out while
>> >holding writes to the volume being shadow copied. This is
>> >probably due to excessive activity on the volume by an
>> >application or a system service. Try again later when activity
>> >on the volume is reduced.
>> >
>> > Signed-off-by: Sameeh Jubran <sam...@daynix.com>
>> > ---
>> >  qga/vss-win32/provider.cpp | 3 +--
>> >  1 file changed, 1 insertion(+), 2 deletions(-)
&g

Re: [Qemu-devel] [PATCH qemu-ga v2] qemu-ga: Make QGA VSS provider service run only when needed

2017-04-02 Thread Sameeh Jubran
Ping.

On Thu, Mar 23, 2017 at 7:26 PM, Sameeh Jubran <sam...@daynix.com> wrote:

> Currently the service runs in background on boot even though it is not
> needed and once it is running it never stops. The service needs to be
> running only during freeze operation and it should be stopped after
> executing thaw.
>
> Signed-off-by: Sameeh Jubran <sam...@daynix.com>
> ---
>  qga/vss-win32/install.cpp   | 28 ++--
>  qga/vss-win32/install.h | 20 
>  qga/vss-win32/requester.cpp |  2 ++
>  3 files changed, 48 insertions(+), 2 deletions(-)
>  create mode 100644 qga/vss-win32/install.h
>
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index f4160a3..f41fcdf 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -14,7 +14,7 @@
>
>  #include "vss-common.h"
>  #include 
> -#include 
> +#include "install.h"
>  #include 
>  #include 
>  #include 
> @@ -276,7 +276,7 @@ STDAPI COMRegister(void)
>
>  chk(pCatalog->CreateServiceForApplication(
>  _bstr_t(QGA_PROVIDER_LNAME), _bstr_t(QGA_PROVIDER_LNAME),
> -_bstr_t(L"SERVICE_AUTO_START"), _bstr_t(L"SERVICE_ERROR_
> NORMAL"),
> +_bstr_t(L"SERVICE_DEMAND_START"), _bstr_t(L"SERVICE_ERROR_
> NORMAL"),
>  _bstr_t(L""), _bstr_t(L".\\localsystem"), _bstr_t(L""),
> FALSE));
>  chk(pCatalog->InstallComponent(_bstr_t(QGA_PROVIDER_LNAME),
> _bstr_t(dllPath), _bstr_t(tlbPath),
> @@ -461,3 +461,27 @@ namespace _com_util
>  return bstr;
>  }
>  }
> +
> +/* Stop QGA VSS provider service from COM+ Application Admin Catalog */
> +
> +STDAPI StopService(void)
> +{
> +HRESULT hr;
> +COMInitializer initializer;
> +COMPointer pUnknown;
> +COMPointer pCatalog;
> +
> +int count = 0;
> +
> +chk(QGAProviderFind(QGAProviderCount, (void *)));
> +if (count) {
> +chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL,
> CLSCTX_INPROC_SERVER,
> +IID_IUnknown, (void **)pUnknown.replace()));
> +chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog2,
> +(void **)pCatalog.replace()));
> +chk(pCatalog->ShutdownApplication(_bstr_t(QGA_PROVIDER_LNAME)));
> +}
> +
> +out:
> +return hr;
> +}
> diff --git a/qga/vss-win32/install.h b/qga/vss-win32/install.h
> new file mode 100644
> index 000..35364af
> --- /dev/null
> +++ b/qga/vss-win32/install.h
> @@ -0,0 +1,20 @@
> +/*
> + * QEMU Guest Agent VSS requester declarations
> + *
> + * Copyright Hitachi Data Systems Corp. 2013
> + *
> + * Authors:
> + *  Tomoki Sekiyama   <tomoki.sekiy...@hds.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#ifndef INSTALL_H
> +#define INSTALL_H
> +
> +#include 
> +
> +STDAPI StopService(void);
> +
> +#endif
> diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
> index 272e71b..27308ad 100644
> --- a/qga/vss-win32/requester.cpp
> +++ b/qga/vss-win32/requester.cpp
> @@ -13,6 +13,7 @@
>  #include "qemu/osdep.h"
>  #include "vss-common.h"
>  #include "requester.h"
> +#include "install.h"
>  #include 
>  #include 
>
> @@ -501,4 +502,5 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
>  requester_cleanup();
>
>  CoUninitialize();
> +StopService();
>  }
> --
> 2.9.3
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


Re: [Qemu-devel] [PATCH v1] qga: Add 'guest-get-fqdn' command

2017-03-27 Thread Sameeh Jubran
On Thu, Mar 23, 2017 at 9:51 PM, Vinzenz 'evilissimo' Feenstra <
vfeen...@redhat.com> wrote:

> From: Vinzenz Feenstra <vfeen...@redhat.com>
>
> Retrieving the guest OS fully qualified domain name (FQDN) is a very
> useful feature for virtual management systems. This information can help
> to have more user friendly VM access details, instead of an IP there
> would be the FQDN. Also the FQDN reported can be used to have automated
> checks for valid SSL certificates.
>
> virsh # qemu-agent-command F25 '{ "execute": "guest-get-fqdn" }'
> {"return":{"fqdn":"F25.lab.evilissimo.net"}}
>
> Signed-off-by: Vinzenz Feenstra <vfeen...@redhat.com>
> ---
>  qga/commands.c   | 11 +++
>  qga/qapi-schema.json | 25 +
>  2 files changed, 36 insertions(+)
>
> diff --git a/qga/commands.c b/qga/commands.c
> index 4d92946..61577af 100644
> --- a/qga/commands.c
> +++ b/qga/commands.c
> @@ -499,3 +499,14 @@ int ga_parse_whence(GuestFileWhence *whence, Error
> **errp)
>  error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
>  return -1;
>  }
> +
> +GuestFQDN *qmp_guest_get_fqdn(Error **err)
> +{
> +GuestFQDN *result = NULL;
> +gchar const *hostname = g_get_host_name();
>
According to glib documentation on "g_get_host_name" function:
"The returned name is not necessarily a fully-qualified domain name, or
even present in DNS or some other name service at all. It need not even be
unique on your local network or site, but usually it is."
I think the command name should be changed to something like
"guest_get_machine_name" and not fqdn as this is not always true!

Moreover the documentation states that:
"If no name can be determined, a default fixed string "localhost" is
returned."
I think we should handle this case and return and informative error.

> +if (hostname != NULL) {
> +result = g_new0(GuestFQDN, 1);
> +result->fqdn = g_strdup(hostname);
> +}
> +return result;
> +}
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index a02dbf2..0a2c0a4 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -1042,3 +1042,28 @@
>'data':{ 'path': 'str', '*arg': ['str'], '*env': ['str'],
> '*input-data': 'str', '*capture-output': 'bool' },
>'returns': 'GuestExec' }
> +
> +
> +
> +##
> +# @GuestFQDN:
> +# @fqdn: Fully qualified domain name of the guest OS
> +#
> +# Since: 2.10
> +##
> +{ 'struct': 'GuestFQDN',
> +  'data':   { 'fqdn': 'str' } }
> +
> +
> +##
> +# @guest-get-fqdn:
> +#
> +# Request the FQDN (Fully Qualified Domain Name) of the guest operating
> system
> +#
> +# Returns: FQDN on success
> +#
> +# Since: 2.10
> +##
> +{ 'command': 'guest-get-fqdn',
> +  'returns': 'GuestFQDN' }
> +
> --
> 2.9.3
>
>
>


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH qemu-ga v3] qga: Make qemu-ga compile statically for Windows

2017-03-26 Thread Sameeh Jubran
Attempting to compile qemu-ga statically as follows for Windows causes
the following error:

Compilation:
./configure --disable-docs --target-list=x86_64-softmmu \
--cross-prefix=x86_64-w64-mingw32- --static \
--enable-guest-agent-msi --with-vss-sdk=/path/to/VSSSDK72

make -j8 qemu-ga

Error:
path/to/qemu/stubs/error-printf.c:7: undefined reference to 
`__imp_g_test_config_vars'
collect2: error: ld returned 1 exit status
Makefile:444: recipe for target 'qemu-ga.exe' failed
make: *** [qemu-ga.exe] Error 1

This is caused by a bug in the pkg-config file for glib as it doesn't define
GLIB_STATIC_COMPILATION for pkg-config --static.

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com>
---
 configure | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/configure b/configure
index b9a30cf..8210494 100755
--- a/configure
+++ b/configure
@@ -3041,6 +3041,13 @@ if test "$modules" = yes; then
 glib_modules="$glib_modules gmodule-2.0"
 fi
 
+# This workaround is required due to a bug in pkg-config file for glib as it
+# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
+
+if test "$static" = yes -a "$mingw32" = yes; then
+QEMU_CFLAGS="-DGLIB_STATIC_COMPILATION $QEMU_CFLAGS"
+fi
+
 for i in $glib_modules; do
 if $pkg_config --atleast-version=$glib_req_ver $i; then
 glib_cflags=$($pkg_config --cflags $i)
-- 
2.9.3




Re: [Qemu-devel] [PATCH qemu-ga v2] qga: Make qemu-ga compile statically for Windows

2017-03-26 Thread Sameeh Jubran
On Thu, Mar 23, 2017 at 9:21 PM, Stefan Hajnoczi <stefa...@gmail.com> wrote:

> On Thu, Mar 23, 2017 at 11:22:11AM +0200, Sameeh Jubran wrote:
> > Attempting to compile qemu-ga statically as follows for Windows causes
> > the following error:
> >
> > Compilation:
> > ./configure --disable-docs --target-list=x86_64-softmmu \
> > --cross-prefix=x86_64-w64-mingw32- --static \
> > --enable-guest-agent-msi --with-vss-sdk=/path/to/VSSSDK72
> >
> > make -j8 qemu-ga
> >
> > Error:
> > path/to/qemu/stubs/error-printf.c:7: undefined reference to
> `__imp_g_test_config_vars'
> > collect2: error: ld returned 1 exit status
> > Makefile:444: recipe for target 'qemu-ga.exe' failed
> > make: *** [qemu-ga.exe] Error 1
> >
> > This is caused by a bug in the pkg-config file for glib as it doesn't
> define
> > GLIB_STATIC_COMPILATION for pkg-config --static.
>
> >
> > Signed-off-by: Stefan Hajnoczi <stefa...@gmail.com>
>
> Please remove this.  I didn't post my Signed-off-by.  Only add
> Signed-off-by for someone else if they ask you to do so.
>
> For details on Signed-off-by please read:
> "11) Sign your work - the Developer's Certificate of Origin"
> https://www.kernel.org/doc/Documentation/process/submitting-patches.rst

 I added your signed off to indicate that you were involved in the
development of the patch as you are the one that suggested
this workaround in the first place. No problem I will drop it.

>
>
> > Signed-off-by: Sameeh Jubran <sam...@daynix.com>
> > ---
> >  configure | 7 +++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/configure b/configure
> > index b9a30cf..8210494 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3041,6 +3041,13 @@ if test "$modules" = yes; then
> >  glib_modules="$glib_modules gmodule-2.0"
> >  fi
> >
> > +# This workaround is required due to a bug in pkg-config file for glib
> as it
> > +# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
>
> Please add:
>
> # See https://bugzilla.gnome.org/show_bug.cgi?id=780399 for the glib bug
> # report.


> Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com>
>
I'll add them in v3, thanks for the review.


-- 
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*


[Qemu-devel] [PATCH qemu-ga v2] qemu-ga: Make QGA VSS provider service run only when needed

2017-03-23 Thread Sameeh Jubran
Currently the service runs in background on boot even though it is not
needed and once it is running it never stops. The service needs to be
running only during freeze operation and it should be stopped after
executing thaw.

Signed-off-by: Sameeh Jubran <sam...@daynix.com>
---
 qga/vss-win32/install.cpp   | 28 ++--
 qga/vss-win32/install.h | 20 
 qga/vss-win32/requester.cpp |  2 ++
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 qga/vss-win32/install.h

diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index f4160a3..f41fcdf 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -14,7 +14,7 @@
 
 #include "vss-common.h"
 #include 
-#include 
+#include "install.h"
 #include 
 #include 
 #include 
@@ -276,7 +276,7 @@ STDAPI COMRegister(void)
 
 chk(pCatalog->CreateServiceForApplication(
 _bstr_t(QGA_PROVIDER_LNAME), _bstr_t(QGA_PROVIDER_LNAME),
-_bstr_t(L"SERVICE_AUTO_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"),
+_bstr_t(L"SERVICE_DEMAND_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"),
 _bstr_t(L""), _bstr_t(L".\\localsystem"), _bstr_t(L""), FALSE));
 chk(pCatalog->InstallComponent(_bstr_t(QGA_PROVIDER_LNAME),
_bstr_t(dllPath), _bstr_t(tlbPath),
@@ -461,3 +461,27 @@ namespace _com_util
 return bstr;
 }
 }
+
+/* Stop QGA VSS provider service from COM+ Application Admin Catalog */
+
+STDAPI StopService(void)
+{
+HRESULT hr;
+COMInitializer initializer;
+COMPointer pUnknown;
+COMPointer pCatalog;
+
+int count = 0;
+
+chk(QGAProviderFind(QGAProviderCount, (void *)));
+if (count) {
+chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER,
+IID_IUnknown, (void **)pUnknown.replace()));
+chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog2,
+(void **)pCatalog.replace()));
+chk(pCatalog->ShutdownApplication(_bstr_t(QGA_PROVIDER_LNAME)));
+}
+
+out:
+return hr;
+}
diff --git a/qga/vss-win32/install.h b/qga/vss-win32/install.h
new file mode 100644
index 000..35364af
--- /dev/null
+++ b/qga/vss-win32/install.h
@@ -0,0 +1,20 @@
+/*
+ * QEMU Guest Agent VSS requester declarations
+ *
+ * Copyright Hitachi Data Systems Corp. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   <tomoki.sekiy...@hds.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef INSTALL_H
+#define INSTALL_H
+
+#include 
+
+STDAPI StopService(void);
+
+#endif
diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
index 272e71b..27308ad 100644
--- a/qga/vss-win32/requester.cpp
+++ b/qga/vss-win32/requester.cpp
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 #include "vss-common.h"
 #include "requester.h"
+#include "install.h"
 #include 
 #include 
 
@@ -501,4 +502,5 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
 requester_cleanup();
 
 CoUninitialize();
+StopService();
 }
-- 
2.9.3




  1   2   >