[PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio management.

2016-04-02 Thread K. Y. Srinivasan
Cleanup and mmio management. Also included is a patch
to fix an issue in KVP.

Jake Oshins (5):
  hv: Make a function to free mmio regions through vmbus
  hv: Lock access to hyperv_mmio resource tree
  hv: Use new vmbus_mmio_free() from client drivers.
  hv: Reverse order of resources in hyperv_mmio
  hv: Track allocations of children of hv_vmbus in private resource
tree

Vitaly Kuznetsov (1):
  Drivers: hv: kvp: fix IP Failover

 drivers/hv/hv_kvp.c |   31 +
 drivers/hv/hyperv_vmbus.h   |5 +++
 drivers/hv/vmbus_drv.c  |   56 ++-
 drivers/pci/host/pci-hyperv.c   |   14 +-
 drivers/video/fbdev/hyperv_fb.c |4 +-
 include/linux/hyperv.h  |2 +-
 6 files changed, 95 insertions(+), 17 deletions(-)

-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/6] hv: Make a function to free mmio regions through vmbus

2016-04-02 Thread K. Y. Srinivasan
From: Jake Oshins 

This patch introduces a function that reverses everything
done by vmbus_allocate_mmio().  Existing code just called
release_mem_region().  Future patches in this series
require a more complex sequence of actions, so this function
is introduced to wrap those actions.

Signed-off-by: Jake Oshins 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/vmbus_drv.c |   15 +++
 include/linux/hyperv.h |2 +-
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 64713ff..44e95a4 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1180,6 +1180,21 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
 EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
 
 /**
+ * vmbus_free_mmio() - Free a memory-mapped I/O range.
+ * @start: Base address of region to release.
+ * @size:  Size of the range to be allocated
+ *
+ * This function releases anything requested by
+ * vmbus_mmio_allocate().
+ */
+void vmbus_free_mmio(resource_size_t start, resource_size_t size)
+{
+   release_mem_region(start, size);
+
+}
+EXPORT_SYMBOL_GPL(vmbus_free_mmio);
+
+/**
  * vmbus_cpu_number_to_vp_number() - Map CPU to VP.
  * @cpu_number: CPU number in Linux terms
  *
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index aa0fadc..ecd81c3 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1091,7 +1091,7 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
resource_size_t min, resource_size_t max,
resource_size_t size, resource_size_t align,
bool fb_overlap_ok);
-
+void vmbus_free_mmio(resource_size_t start, resource_size_t size);
 int vmbus_cpu_number_to_vp_number(int cpu_number);
 u64 hv_do_hypercall(u64 control, void *input, void *output);
 
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/6] hv: Reverse order of resources in hyperv_mmio

2016-04-02 Thread K. Y. Srinivasan
From: Jake Oshins 

A patch later in this series allocates child nodes
in this resource tree.  For that to work, this tree
needs to be sorted in ascending order.

Signed-off-by: Jake Oshins 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/vmbus_drv.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 60553c1..1ce47d0 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1049,7 +1049,6 @@ static acpi_status vmbus_walk_resources(struct 
acpi_resource *res, void *ctx)
new_res->end = end;
 
/*
-* Stick ranges from higher in address space at the front of the list.
 * If two ranges are adjacent, merge them.
 */
do {
@@ -1070,7 +1069,7 @@ static acpi_status vmbus_walk_resources(struct 
acpi_resource *res, void *ctx)
break;
}
 
-   if ((*old_res)->end < new_res->start) {
+   if ((*old_res)->start > new_res->end) {
new_res->sibling = *old_res;
if (prev_res)
(*prev_res)->sibling = new_res;
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/6] hv: Track allocations of children of hv_vmbus in private resource tree

2016-04-02 Thread K. Y. Srinivasan
From: Jake Oshins 

This patch changes vmbus_allocate_mmio() and vmbus_free_mmio() so
that when child paravirtual devices allocate memory-mapped I/O
space, they allocate it privately from a resource tree pointed
at by hyperv_mmio and also by the public resource tree
iomem_resource.  This allows the region to be marked as "busy"
in the private tree, but a "bridge window" in the public tree,
guaranteeing that no two bridge windows will overlap each other
but while also allowing the PCI device children of the bridge
windows to overlap that window.

One might conclude that this belongs in the pnp layer, rather
than in this driver.  Rafael Wysocki, the maintainter of the
pnp layer, has previously asked that we not modify the pnp layer
as it is considered deprecated.  This patch is thus essentially
a workaround.

Signed-off-by: Jake Oshins 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/vmbus_drv.c |   22 +-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 1ce47d0..dfc6149 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1128,7 +1128,7 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
resource_size_t size, resource_size_t align,
bool fb_overlap_ok)
 {
-   struct resource *iter;
+   struct resource *iter, *shadow;
resource_size_t range_min, range_max, start, local_min, local_max;
const char *dev_n = dev_name(&device_obj->device);
u32 fb_end = screen_info.lfb_base + (screen_info.lfb_size << 1);
@@ -1170,12 +1170,22 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
 
start = (local_min + align - 1) & ~(align - 1);
for (; start + size - 1 <= local_max; start += align) {
+   shadow = __request_region(iter, start,
+ size,
+ NULL,
+ IORESOURCE_BUSY);
+   if (!shadow)
+   continue;
+
*new = request_mem_region_exclusive(start, size,
dev_n);
if (*new) {
+   shadow->name = (char *)*new;
retval = 0;
goto exit;
}
+
+   __release_region(iter, start, size);
}
}
}
@@ -1196,7 +1206,17 @@ EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
  */
 void vmbus_free_mmio(resource_size_t start, resource_size_t size)
 {
+   struct resource *iter;
+
+   down(&hyperv_mmio_lock);
+   for (iter = hyperv_mmio; iter; iter = iter->sibling) {
+   if ((iter->start >= start + size) || (iter->end <= start))
+   continue;
+
+   __release_region(iter, start, size);
+   }
release_mem_region(start, size);
+   up(&hyperv_mmio_lock);
 
 }
 EXPORT_SYMBOL_GPL(vmbus_free_mmio);
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/6] hv: Use new vmbus_mmio_free() from client drivers.

2016-04-02 Thread K. Y. Srinivasan
From: Jake Oshins 

This patch modifies all the callers of vmbus_mmio_allocate()
to call vmbus_mmio_free() instead of release_mem_region().

Signed-off-by: Jake Oshins 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/pci/host/pci-hyperv.c   |   14 +++---
 drivers/video/fbdev/hyperv_fb.c |4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index ed651ba..f2559b6 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1795,14 +1795,14 @@ static void hv_pci_free_bridge_windows(struct 
hv_pcibus_device *hbus)
 
if (hbus->low_mmio_space && hbus->low_mmio_res) {
hbus->low_mmio_res->flags |= IORESOURCE_BUSY;
-   release_mem_region(hbus->low_mmio_res->start,
-  resource_size(hbus->low_mmio_res));
+   vmbus_free_mmio(hbus->low_mmio_res->start,
+   resource_size(hbus->low_mmio_res));
}
 
if (hbus->high_mmio_space && hbus->high_mmio_res) {
hbus->high_mmio_res->flags |= IORESOURCE_BUSY;
-   release_mem_region(hbus->high_mmio_res->start,
-  resource_size(hbus->high_mmio_res));
+   vmbus_free_mmio(hbus->high_mmio_res->start,
+   resource_size(hbus->high_mmio_res));
}
 }
 
@@ -1880,8 +1880,8 @@ static int hv_pci_allocate_bridge_windows(struct 
hv_pcibus_device *hbus)
 
 release_low_mmio:
if (hbus->low_mmio_res) {
-   release_mem_region(hbus->low_mmio_res->start,
-  resource_size(hbus->low_mmio_res));
+   vmbus_free_mmio(hbus->low_mmio_res->start,
+   resource_size(hbus->low_mmio_res));
}
 
return ret;
@@ -1924,7 +1924,7 @@ static int hv_allocate_config_window(struct 
hv_pcibus_device *hbus)
 
 static void hv_free_config_window(struct hv_pcibus_device *hbus)
 {
-   release_mem_region(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH);
+   vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH);
 }
 
 /**
diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index e2451bd..2fd49b2 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -743,7 +743,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct 
fb_info *info)
 err3:
iounmap(fb_virt);
 err2:
-   release_mem_region(par->mem->start, screen_fb_size);
+   vmbus_free_mmio(par->mem->start, screen_fb_size);
par->mem = NULL;
 err1:
if (!gen2vm)
@@ -758,7 +758,7 @@ static void hvfb_putmem(struct fb_info *info)
struct hvfb_par *par = info->par;
 
iounmap(info->screen_base);
-   release_mem_region(par->mem->start, screen_fb_size);
+   vmbus_free_mmio(par->mem->start, screen_fb_size);
par->mem = NULL;
 }
 
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/6] Drivers: hv: kvp: fix IP Failover

2016-04-02 Thread K. Y. Srinivasan
From: Vitaly Kuznetsov 

Hyper-V VMs can be replicated to another hosts and there is a feature to
set different IP for replicas, it is called 'Failover TCP/IP'. When
such guest starts Hyper-V host sends it KVP_OP_SET_IP_INFO message as soon
as we finish negotiation procedure. The problem is that it can happen (and
it actually happens) before userspace daemon connects and we reply with
HV_E_FAIL to the message. As there are no repetitions we fail to set the
requested IP.

Solve the issue by postponing our reply to the negotiation message till
userspace daemon is connected. We can't wait too long as there is a
host-side timeout (cca. 75 seconds) and if we fail to reply in this time
frame the whole KVP service will become inactive. The solution is not
ideal - if it takes userspace daemon more than 60 seconds to connect
IP Failover will still fail but I don't see a solution with our current
separation between kernel and userspace parts.

Other two modules (VSS and FCOPY) don't require such delay, leave them
untouched.

Signed-off-by: Vitaly Kuznetsov 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/hv_kvp.c   |   31 +++
 drivers/hv/hyperv_vmbus.h |5 +
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 9b9b370..cb1a916 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -78,9 +78,11 @@ static void kvp_send_key(struct work_struct *dummy);
 
 static void kvp_respond_to_host(struct hv_kvp_msg *msg, int error);
 static void kvp_timeout_func(struct work_struct *dummy);
+static void kvp_host_handshake_func(struct work_struct *dummy);
 static void kvp_register(int);
 
 static DECLARE_DELAYED_WORK(kvp_timeout_work, kvp_timeout_func);
+static DECLARE_DELAYED_WORK(kvp_host_handshake_work, kvp_host_handshake_func);
 static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
 
 static const char kvp_devname[] = "vmbus/hv_kvp";
@@ -130,6 +132,11 @@ static void kvp_timeout_func(struct work_struct *dummy)
hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
 }
 
+static void kvp_host_handshake_func(struct work_struct *dummy)
+{
+   hv_poll_channel(kvp_transaction.recv_channel, hv_kvp_onchannelcallback);
+}
+
 static int kvp_handle_handshake(struct hv_kvp_msg *msg)
 {
switch (msg->kvp_hdr.operation) {
@@ -154,6 +161,12 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg)
pr_debug("KVP: userspace daemon ver. %d registered\n",
 KVP_OP_REGISTER);
kvp_register(dm_reg_value);
+
+   /*
+* If we're still negotiating with the host cancel the timeout
+* work to not poll the channel twice.
+*/
+   cancel_delayed_work_sync(&kvp_host_handshake_work);
hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
 
return 0;
@@ -594,7 +607,22 @@ void hv_kvp_onchannelcallback(void *context)
struct icmsg_negotiate *negop = NULL;
int util_fw_version;
int kvp_srv_version;
+   static enum {NEGO_NOT_STARTED,
+NEGO_IN_PROGRESS,
+NEGO_FINISHED} host_negotiatied = NEGO_NOT_STARTED;
 
+   if (host_negotiatied == NEGO_NOT_STARTED &&
+   kvp_transaction.state < HVUTIL_READY) {
+   /*
+* If userspace daemon is not connected and host is asking
+* us to negotiate we need to delay to not lose messages.
+* This is important for Failover IP setting.
+*/
+   host_negotiatied = NEGO_IN_PROGRESS;
+   schedule_delayed_work(&kvp_host_handshake_work,
+ HV_UTIL_NEGO_TIMEOUT * HZ);
+   return;
+   }
if (kvp_transaction.state > HVUTIL_READY)
return;
 
@@ -672,6 +700,8 @@ void hv_kvp_onchannelcallback(void *context)
vmbus_sendpacket(channel, recv_buffer,
   recvlen, requestid,
   VM_PKT_DATA_INBAND, 0);
+
+   host_negotiatied = NEGO_FINISHED;
}
 
 }
@@ -708,6 +738,7 @@ hv_kvp_init(struct hv_util_service *srv)
 void hv_kvp_deinit(void)
 {
kvp_transaction.state = HVUTIL_DEVICE_DYING;
+   cancel_delayed_work_sync(&kvp_host_handshake_work);
cancel_delayed_work_sync(&kvp_timeout_work);
cancel_work_sync(&kvp_sendkey_work);
hvutil_transport_destroy(hvt);
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 12321b9..8b07f9c 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -36,6 +36,11 @@
 #define HV_UTIL_TIMEOUT 30
 
 /*
+ * Timeout for guest-host handshake for services.
+ */
+#define HV_UTIL_NEGO_TIMEOUT 60
+
+/*
  * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
  * is set by CPUID(HVCPUID_VERSION_FEATURES).
  */
-- 
1.7.4.1

___
devel mailing

[PATCH 3/6] hv: Lock access to hyperv_mmio resource tree

2016-04-02 Thread K. Y. Srinivasan
From: Jake Oshins 

In existing code, this tree of resources is created
in single-threaded code and never modified after it is
created, and thus needs no locking.  This patch introduces
a semaphore for tree access, as other patches in this
series introduce run-time modifications of this resource
tree which can happen on multiple threads.

Signed-off-by: Jake Oshins 
Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/vmbus_drv.c |   16 
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 44e95a4..60553c1 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -102,6 +102,7 @@ static struct notifier_block hyperv_panic_block = {
 };
 
 struct resource *hyperv_mmio;
+DEFINE_SEMAPHORE(hyperv_mmio_lock);
 
 static int vmbus_exists(void)
 {
@@ -1132,7 +1133,10 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
resource_size_t range_min, range_max, start, local_min, local_max;
const char *dev_n = dev_name(&device_obj->device);
u32 fb_end = screen_info.lfb_base + (screen_info.lfb_size << 1);
-   int i;
+   int i, retval;
+
+   retval = -ENXIO;
+   down(&hyperv_mmio_lock);
 
for (iter = hyperv_mmio; iter; iter = iter->sibling) {
if ((iter->start >= max) || (iter->end <= min))
@@ -1169,13 +1173,17 @@ int vmbus_allocate_mmio(struct resource **new, struct 
hv_device *device_obj,
for (; start + size - 1 <= local_max; start += align) {
*new = request_mem_region_exclusive(start, size,
dev_n);
-   if (*new)
-   return 0;
+   if (*new) {
+   retval = 0;
+   goto exit;
+   }
}
}
}
 
-   return -ENXIO;
+exit:
+   up(&hyperv_mmio_lock);
+   return retval;
 }
 EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
 
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Staging: unisys/verisonic: Correct double unlock

2016-04-02 Thread Iban Rodriguez
'priv_lock' is unlocked twice. The first one is removed and
the function 'visornic_serverdown_complete' is now called with
'priv_lock' locked because 'devdata' is modified inside.

Signed-off-by: Iban Rodriguez 
---
 drivers/staging/unisys/visornic/visornic_main.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/unisys/visornic/visornic_main.c 
b/drivers/staging/unisys/visornic/visornic_main.c
index be0d057346c3..af03f2938fe9 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -368,7 +368,6 @@ visornic_serverdown(struct visornic_devdata *devdata,
}
devdata->server_change_state = true;
devdata->server_down_complete_func = complete_func;
-   spin_unlock_irqrestore(&devdata->priv_lock, flags);
visornic_serverdown_complete(devdata);
} else if (devdata->server_change_state) {
dev_dbg(&devdata->dev->device, "%s changing state\n",
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: wlan-ng: memory allocated inside mkimage() is not freed if subsequent calls fails.

2016-04-02 Thread Claudiu Beznea
This patch frees memory allocated inside mkimage() in case mkimage()
or any other subsequent calls inside prism2_fwapply() from prism2fw.c
file fails. To fix this I introduces goto labels where the free
operation is done in case some operations fails. After the introduction
of goto labels has been done, in order to use the same return path,
"return x" instuctions were replaced with "goto" instuctions.

Signed-off-by: Claudiu Beznea 
---
 drivers/staging/wlan-ng/prism2fw.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/wlan-ng/prism2fw.c 
b/drivers/staging/wlan-ng/prism2fw.c
index 8564d9e..56bffd9 100644
--- a/drivers/staging/wlan-ng/prism2fw.c
+++ b/drivers/staging/wlan-ng/prism2fw.c
@@ -278,7 +278,8 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
/* Build the PDA we're going to use. */
if (read_cardpda(&pda, wlandev)) {
netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n");
-   return 1;
+   result = 1;
+   goto out;
}
 
/* read the card's PRI-SUP */
@@ -315,55 +316,58 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
if (result) {
netdev_err(wlandev->netdev,
   "Failed to read the data exiting.\n");
-   return 1;
+   goto out;
}
 
result = validate_identity();
-
if (result) {
netdev_err(wlandev->netdev, "Incompatible firmware image.\n");
-   return 1;
+   goto out;
}
 
if (startaddr == 0x) {
netdev_err(wlandev->netdev,
   "Can't RAM download a Flash image!\n");
-   return 1;
+   result = 1;
+   goto out;
}
 
/* Make the image chunks */
result = mkimage(fchunk, &nfchunks);
if (result) {
netdev_err(wlandev->netdev, "Failed to make image chunk.\n");
-   return 1;
+   goto free_chunks;
}
 
/* Do any plugging */
result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
if (result) {
netdev_err(wlandev->netdev, "Failed to plug data.\n");
-   return 1;
+   goto free_chunks;
}
 
/* Insert any CRCs */
-   if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
+   result = crcimage(fchunk, nfchunks, s3crc, ns3crc);
+   if (result) {
netdev_err(wlandev->netdev, "Failed to insert all CRCs\n");
-   return 1;
+   goto free_chunks;
}
 
/* Write the image */
result = writeimage(wlandev, fchunk, nfchunks);
if (result) {
netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n");
-   return 1;
+   goto free_chunks;
}
 
+   netdev_info(wlandev->netdev, "prism2_usb: firmware loading 
finished.\n");
+
+free_chunks:
/* clear any allocated memory */
free_chunks(fchunk, &nfchunks);
free_srecs();
 
-   netdev_info(wlandev->netdev, "prism2_usb: firmware loading 
finished.\n");
-
+out:
return result;
 }
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/1] Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

2016-04-02 Thread KY Srinivasan


> -Original Message-
> From: K. Y. Srinivasan [mailto:k...@microsoft.com]
> Sent: Friday, March 11, 2016 12:39 PM
> To: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> vkuzn...@redhat.com; jasow...@redhat.com
> Cc: KY Srinivasan ; sta...@vger.kernel.org
> Subject: [PATCH 1/1] Drivers: hv: vmbus: Fix a bug in
> hv_need_to_signal_on_read()
> 
> On the consumer side, we have interrupt driven flow management of the
> producer. It is sufficient to base the signalling decision on the
> amount of space that is available to write after the read is complete.
> The current code samples the previous available space and uses this
> in making the signalling decision. This state can be stale and is
> unnecessary. Since the state can be stale, we end up not signalling
> the host (when we should) and this can result in a hang. Fix this
> problem by removing the unnecessary check.
> 
> I would like to thank Arseney Romanenko 
> for pointing out this bug.

Greg,

Please drop this patch. I am going to update and send the patch.

K. Y
> 
> Signed-off-by: K. Y. Srinivasan 
> Tested-by: Dexuan Cui 
> Cc: 
> ---
>  drivers/hv/ring_buffer.c |7 +++
>  1 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
> index 5613e2b..085003a 100644
> --- a/drivers/hv/ring_buffer.c
> +++ b/drivers/hv/ring_buffer.c
> @@ -103,8 +103,7 @@ static bool hv_need_to_signal(u32 old_write, struct
> hv_ring_buffer_info *rbi)
>   *there is room for the producer to send the pending packet.
>   */
> 
> -static bool hv_need_to_signal_on_read(u32 prev_write_sz,
> -   struct hv_ring_buffer_info *rbi)
> +static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
>  {
>   u32 cur_write_sz;
>   u32 r_size;
> @@ -120,7 +119,7 @@ static bool hv_need_to_signal_on_read(u32
> prev_write_sz,
>   cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc)
> :
>   read_loc - write_loc;
> 
> - if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
> + if (cur_write_sz >= pending_sz)
>   return true;
> 
>   return false;
> @@ -455,7 +454,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info
> *inring_info,
>   /* Update the read index */
>   hv_set_next_read_location(inring_info, next_read_location);
> 
> - *signal = hv_need_to_signal_on_read(bytes_avail_towrite,
> inring_info);
> + *signal = hv_need_to_signal_on_read(inring_info);
> 
>   return ret;
>  }
> --
> 1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/1] Drivers: hv: vmbus: Fix signaling logic in hv_need_to_signal_on_read()

2016-04-02 Thread K. Y. Srinivasan
On the consumer side, we have interrupt driven flow management of the
producer. It is sufficient to base the signaling decision on the
amount of space that is available to write after the read is complete.
The current code samples the previous available space and uses this
in making the signaling decision. This state can be stale and is
unnecessary. Since the state can be stale, we end up not signaling
the host (when we should) and this can result in a hang. Fix this
problem by removing the unnecessary check. I would like to thank
Arseney Romanenko  for pointing out this issue.

Also, issue a full memory barrier before making the signaling descision
to correctly deal with potential reordering of the write (read index)
followed by the read of pending_sz.

Signed-off-by: K. Y. Srinivasan 
Tested-by: Dexuan Cui 
Cc: 
---
 drivers/hv/ring_buffer.c |   20 
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 5613e2b..e00b632 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -103,8 +103,7 @@ static bool hv_need_to_signal(u32 old_write, struct 
hv_ring_buffer_info *rbi)
  *there is room for the producer to send the pending packet.
  */
 
-static bool hv_need_to_signal_on_read(u32 prev_write_sz,
- struct hv_ring_buffer_info *rbi)
+static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
 {
u32 cur_write_sz;
u32 r_size;
@@ -112,6 +111,19 @@ static bool hv_need_to_signal_on_read(u32 prev_write_sz,
u32 read_loc = rbi->ring_buffer->read_index;
u32 pending_sz = rbi->ring_buffer->pending_send_sz;
 
+   /*
+* Issue a full memory barrier before making the signaling decision.
+* Here is the reason for having this barrier:
+* If the reading of the pend_sz (in this function)
+* were to be reordered and read before we commit the new read
+* index (in the calling function)  we could
+* have a problem. If the host were to set the pending_sz after we
+* have sampled pending_sz and go to sleep before we commit the
+* read index, we could miss sending the interrupt. Issue a full
+* memory barrier to address this.
+*/
+   mb();
+
/* If the other end is not blocked on write don't bother. */
if (pending_sz == 0)
return false;
@@ -120,7 +132,7 @@ static bool hv_need_to_signal_on_read(u32 prev_write_sz,
cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) :
read_loc - write_loc;
 
-   if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
+   if (cur_write_sz >= pending_sz)
return true;
 
return false;
@@ -455,7 +467,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info 
*inring_info,
/* Update the read index */
hv_set_next_read_location(inring_info, next_read_location);
 
-   *signal = hv_need_to_signal_on_read(bytes_avail_towrite, inring_info);
+   *signal = hv_need_to_signal_on_read(inring_info);
 
return ret;
 }
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/1] Drivers: hv: vmbus: Fix signaling logic in hv_need_to_signal_on_read()

2016-04-02 Thread KY Srinivasan


> -Original Message-
> From: K. Y. Srinivasan [mailto:k...@microsoft.com]
> Sent: Saturday, April 2, 2016 3:44 PM
> To: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> vkuzn...@redhat.com; jasow...@redhat.com
> Cc: KY Srinivasan ; sta...@vger.kernel.org
> Subject: [PATCH 1/1] Drivers: hv: vmbus: Fix signaling logic in
> hv_need_to_signal_on_read()
> 
> On the consumer side, we have interrupt driven flow management of the
> producer. It is sufficient to base the signaling decision on the
> amount of space that is available to write after the read is complete.
> The current code samples the previous available space and uses this
> in making the signaling decision. This state can be stale and is
> unnecessary. Since the state can be stale, we end up not signaling
> the host (when we should) and this can result in a hang. Fix this
> problem by removing the unnecessary check. I would like to thank
> Arseney Romanenko  for pointing out this issue.
> 
> Also, issue a full memory barrier before making the signaling descision
> to correctly deal with potential reordering of the write (read index)
> followed by the read of pending_sz.

Greg,

Please drop this; I sent the wrong version of the patch. Sorry for
The confusion.

K. Y
> 
> Signed-off-by: K. Y. Srinivasan 
> Tested-by: Dexuan Cui 
> Cc: 
> ---
>  drivers/hv/ring_buffer.c |   20 
>  1 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
> index 5613e2b..e00b632 100644
> --- a/drivers/hv/ring_buffer.c
> +++ b/drivers/hv/ring_buffer.c
> @@ -103,8 +103,7 @@ static bool hv_need_to_signal(u32 old_write, struct
> hv_ring_buffer_info *rbi)
>   *there is room for the producer to send the pending packet.
>   */
> 
> -static bool hv_need_to_signal_on_read(u32 prev_write_sz,
> -   struct hv_ring_buffer_info *rbi)
> +static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
>  {
>   u32 cur_write_sz;
>   u32 r_size;
> @@ -112,6 +111,19 @@ static bool hv_need_to_signal_on_read(u32
> prev_write_sz,
>   u32 read_loc = rbi->ring_buffer->read_index;
>   u32 pending_sz = rbi->ring_buffer->pending_send_sz;
> 
> + /*
> +  * Issue a full memory barrier before making the signaling decision.
> +  * Here is the reason for having this barrier:
> +  * If the reading of the pend_sz (in this function)
> +  * were to be reordered and read before we commit the new read
> +  * index (in the calling function)  we could
> +  * have a problem. If the host were to set the pending_sz after we
> +  * have sampled pending_sz and go to sleep before we commit the
> +  * read index, we could miss sending the interrupt. Issue a full
> +  * memory barrier to address this.
> +  */
> + mb();
> +
>   /* If the other end is not blocked on write don't bother. */
>   if (pending_sz == 0)
>   return false;
> @@ -120,7 +132,7 @@ static bool hv_need_to_signal_on_read(u32
> prev_write_sz,
>   cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc)
> :
>   read_loc - write_loc;
> 
> - if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
> + if (cur_write_sz >= pending_sz)
>   return true;
> 
>   return false;
> @@ -455,7 +467,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info
> *inring_info,
>   /* Update the read index */
>   hv_set_next_read_location(inring_info, next_read_location);
> 
> - *signal = hv_need_to_signal_on_read(bytes_avail_towrite,
> inring_info);
> + *signal = hv_need_to_signal_on_read(inring_info);
> 
>   return ret;
>  }
> --
> 1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: android: align parenthesis in sync.c

2016-04-02 Thread Ben Marsh
Aligns parenthesis in order to silence checkpatch.pl warnings.

Signed-off-by: Ben Marsh 
---
 drivers/staging/android/sync.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 3a8f210..4a64bdd 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -430,7 +430,7 @@ static unsigned int sync_file_poll(struct file *file, 
poll_table *wait)
 }
 
 static long sync_file_ioctl_merge(struct sync_file *sync_file,
-  unsigned long arg)
+ unsigned long arg)
 {
int fd = get_unused_fd_flags(O_CLOEXEC);
int err;
@@ -500,7 +500,7 @@ static int sync_fill_fence_info(struct fence *fence, void 
*data, int size)
 }
 
 static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
-   unsigned long arg)
+  unsigned long arg)
 {
struct sync_file_info *info;
__u32 size;
@@ -552,7 +552,7 @@ out:
 }
 
 static long sync_file_ioctl(struct file *file, unsigned int cmd,
-unsigned long arg)
+   unsigned long arg)
 {
struct sync_file *sync_file = file->private_data;
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: android: change memory allocation style

2016-04-02 Thread Ben Marsh
Changes memory allocation style in order to silence a checkpatch.pl
warning

Signed-off-by: Ben Marsh 
---
 drivers/staging/android/ion/ion_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_test.c 
b/drivers/staging/android/ion/ion_test.c
index b8dcf5a..023568a 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -208,7 +208,7 @@ static int ion_test_open(struct inode *inode, struct file 
*file)
struct ion_test_data *data;
struct miscdevice *miscdev = file->private_data;
 
-   data = kzalloc(sizeof(struct ion_test_data), GFP_KERNEL);
+   data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
 
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH V2 1/1] Drivers: hv: vmbus: Fix signaling logic in hv_need_to_signal_on_read()

2016-04-02 Thread K. Y. Srinivasan
On the consumer side, we have interrupt driven flow management of the
producer. It is sufficient to base the signaling decision on the
amount of space that is available to write after the read is complete.
The current code samples the previous available space and uses this
in making the signaling decision. This state can be stale and is
unnecessary. Since the state can be stale, we end up not signaling
the host (when we should) and this can result in a hang. Fix this
problem by removing the unnecessary check. I would like to thank
Arseney Romanenko  for pointing out this issue.

Also, issue a full memory barrier before making the signaling descision
to correctly deal with potential reordering of the write (read index)
followed by the read of pending_sz.

Signed-off-by: K. Y. Srinivasan 
Tested-by: Dexuan Cui 
Cc: 
---
 drivers/hv/ring_buffer.c |   26 --
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 5613e2b..a40a73a 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -103,15 +103,29 @@ static bool hv_need_to_signal(u32 old_write, struct 
hv_ring_buffer_info *rbi)
  *there is room for the producer to send the pending packet.
  */
 
-static bool hv_need_to_signal_on_read(u32 prev_write_sz,
- struct hv_ring_buffer_info *rbi)
+static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
 {
u32 cur_write_sz;
u32 r_size;
-   u32 write_loc = rbi->ring_buffer->write_index;
+   u32 write_loc;
u32 read_loc = rbi->ring_buffer->read_index;
-   u32 pending_sz = rbi->ring_buffer->pending_send_sz;
+   u32 pending_sz;
 
+   /*
+* Issue a full memory barrier before making the signaling decision.
+* Here is the reason for having this barrier:
+* If the reading of the pend_sz (in this function)
+* were to be reordered and read before we commit the new read
+* index (in the calling function)  we could
+* have a problem. If the host were to set the pending_sz after we
+* have sampled pending_sz and go to sleep before we commit the
+* read index, we could miss sending the interrupt. Issue a full
+* memory barrier to address this.
+*/
+   mb();
+
+   pending_sz = rbi->ring_buffer->pending_send_sz;
+   write_loc = rbi->ring_buffer->write_index;
/* If the other end is not blocked on write don't bother. */
if (pending_sz == 0)
return false;
@@ -120,7 +134,7 @@ static bool hv_need_to_signal_on_read(u32 prev_write_sz,
cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) :
read_loc - write_loc;
 
-   if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
+   if (cur_write_sz >= pending_sz)
return true;
 
return false;
@@ -455,7 +469,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info 
*inring_info,
/* Update the read index */
hv_set_next_read_location(inring_info, next_read_location);
 
-   *signal = hv_need_to_signal_on_read(bytes_avail_towrite, inring_info);
+   *signal = hv_need_to_signal_on_read(inring_info);
 
return ret;
 }
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: android: modify memory allocation style in ion_cma_heap.c

2016-04-02 Thread Ben Marsh
Modifies memory allocation style to silence checkpatch.pl warnings.

Signed-off-by: Ben Marsh 
---
 drivers/staging/android/ion/ion_cma_heap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/ion/ion_cma_heap.c 
b/drivers/staging/android/ion/ion_cma_heap.c
index a3446da..73fae81 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -57,7 +57,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
ion_buffer *buffer,
if (align > PAGE_SIZE)
return -EINVAL;
 
-   info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL);
+   info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return ION_CMA_ALLOCATE_FAILED;
 
@@ -69,7 +69,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
ion_buffer *buffer,
goto err;
}
 
-   info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
+   info->table = kmalloc(sizeof(*info->table), GFP_KERNEL);
if (!info->table)
goto free_mem;
 
@@ -174,7 +174,7 @@ struct ion_heap *ion_cma_heap_create(struct 
ion_platform_heap *data)
 {
struct ion_cma_heap *cma_heap;
 
-   cma_heap = kzalloc(sizeof(struct ion_cma_heap), GFP_KERNEL);
+   cma_heap = kzalloc(sizeof(*cma_heap), GFP_KERNEL);
 
if (!cma_heap)
return ERR_PTR(-ENOMEM);
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Staging: android: remove extra blank line

2016-04-02 Thread Ben Marsh
Remove an extra blank line found by checkpatch.pl

Signed-off-by: Ben Marsh 
---
 drivers/staging/android/ion/ion_dummy_driver.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion_dummy_driver.c 
b/drivers/staging/android/ion/ion_dummy_driver.c
index 5678870..22419d3 100644
--- a/drivers/staging/android/ion/ion_dummy_driver.c
+++ b/drivers/staging/android/ion/ion_dummy_driver.c
@@ -73,7 +73,6 @@ static int __init ion_dummy_init(void)
if (!heaps)
return -ENOMEM;
 
-
/* Allocate a dummy carveout heap */
carveout_ptr = alloc_pages_exact(
dummy_heaps[ION_HEAP_TYPE_CARVEOUT].size,
-- 
1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: android: align parenthesis in sync.c

2016-04-02 Thread Greg KH
On Sat, Apr 02, 2016 at 11:31:37PM +0200, Ben Marsh wrote:
> Aligns parenthesis in order to silence checkpatch.pl warnings.
> 
> Signed-off-by: Ben Marsh 
> ---
>  drivers/staging/android/sync.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

You sent 4 patches, but no hint as to what order they should be applied
in.  Please resend them all as a patch series, properly threaded and
numbered.

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio management.

2016-04-02 Thread Greg KH
On Sat, Apr 02, 2016 at 11:10:38AM -0700, K. Y. Srinivasan wrote:
> Cleanup and mmio management. Also included is a patch
> to fix an issue in KVP.

So these all are for 4.7-rc1?

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] VME: Adding Fake VME driver

2016-04-02 Thread Martyn Welch
This patch introduces a fake VME bridge driver. This driver currently
emulates a subset of the VME bridge functionality. This allows some VME
subsystem development and even some VME device driver development to be
carried out in the absence of a proper VME bus.

Signed-off-by: Martyn Welch 
---
 drivers/vme/bridges/Kconfig|8 +
 drivers/vme/bridges/Makefile   |1 +
 drivers/vme/bridges/vme_fake.c | 1292 
 3 files changed, 1301 insertions(+)
 create mode 100644 drivers/vme/bridges/vme_fake.c

diff --git a/drivers/vme/bridges/Kconfig b/drivers/vme/bridges/Kconfig
index f6d8545..f6ddc37 100644
--- a/drivers/vme/bridges/Kconfig
+++ b/drivers/vme/bridges/Kconfig
@@ -13,3 +13,11 @@ config VME_TSI148
help
 If you say Y here you get support for the Tundra TSI148 VME bridge
 chip.
+
+config VME_FAKE
+   tristate "Fake"
+   help
+If you say Y here you get support for the fake VME bridge. This
+provides a virtualised VME Bus for devices with no VME bridge. This
+is mainly useful for VME development (in the absence of VME
+hardware).
diff --git a/drivers/vme/bridges/Makefile b/drivers/vme/bridges/Makefile
index 59638af..b074542 100644
--- a/drivers/vme/bridges/Makefile
+++ b/drivers/vme/bridges/Makefile
@@ -1,2 +1,3 @@
 obj-$(CONFIG_VME_CA91CX42) += vme_ca91cx42.o
 obj-$(CONFIG_VME_TSI148)   += vme_tsi148.o
+obj-$(CONFIG_VME_FAKE) += vme_fake.o
diff --git a/drivers/vme/bridges/vme_fake.c b/drivers/vme/bridges/vme_fake.c
new file mode 100644
index 000..8789bd6
--- /dev/null
+++ b/drivers/vme/bridges/vme_fake.c
@@ -0,0 +1,1292 @@
+/*
+ * Fake VME bridge support.
+ *
+ * This drive provides a fake VME bridge chip, this enables debugging of the
+ * VME framework in the absence of a VME system.
+ *
+ * This driver has to do a number of things in software that would be driven
+ * by hardware if it was available, it will also result in extra overhead at
+ * times when compared with driving actual hardware.
+ *
+ * Author: Martyn Welch 
+ * Copyright (c) 2014 Martyn Welch
+ *
+ * Based on vme_tsi148.c:
+ *
+ * Author: Martyn Welch 
+ * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
+ *
+ * Based on work by Tom Armistead and Ajit Prem
+ * Copyright 2004 Motorola Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../vme_bridge.h"
+
+/*
+ *  Define the number of each that the fake driver supports.
+ */
+#define FAKE_MAX_MASTER8   /* Max Master Windows */
+#define FAKE_MAX_SLAVE 8   /* Max Slave Windows */
+
+/* Structures to hold information normally held in device registers */
+struct fake_slave_window {
+   int enabled;
+   unsigned long long vme_base;
+   unsigned long long size;
+   dma_addr_t buf_base;
+   u32 aspace;
+   u32 cycle;
+};
+
+struct fake_master_window {
+   int enabled;
+   unsigned long long vme_base;
+   unsigned long long size;
+   u32 aspace;
+   u32 cycle;
+   u32 dwidth;
+};
+
+/* Structure used to hold driver specific information */
+struct fake_driver {
+   struct vme_bridge *parent;
+   struct fake_slave_window slaves[FAKE_MAX_SLAVE];
+   struct fake_master_window masters[FAKE_MAX_MASTER];
+   u32 lm_enabled;
+   unsigned long long lm_base;
+   u32 lm_aspace;
+   u32 lm_cycle;
+   void (*lm_callback[4])(int);
+   struct tasklet_struct int_tasklet;
+   int int_level;
+   int int_statid;
+   void *crcsr_kernel;
+   dma_addr_t crcsr_bus;
+   /* Only one VME interrupt can be generated at a time, provide locking */
+   struct mutex vme_int;
+};
+
+/* Module parameter */
+static int geoid;
+
+static const char driver_name[] = "vme_fake";
+
+static struct vme_bridge *exit_pointer;
+
+static struct device *vme_root;
+
+/*
+ * Calling VME bus interrupt callback if provided.
+ */
+static void fake_VIRQ_tasklet(unsigned long data)
+{
+   struct vme_bridge *fake_bridge;
+   struct fake_driver *bridge;
+
+   fake_bridge = (struct vme_bridge *) data;
+   bridge = fake_bridge->driver_priv;
+
+   vme_irq_handler(fake_bridge, bridge->int_level, bridge->int_statid);
+}
+
+/*
+ * Configure VME interrupt
+ */
+static void fake_irq_set(struct vme_bridge *fake_bridge, int level,
+   int state, int sync)
+{
+   /* Nothing to do */
+}
+
+/*
+ * Generate a VME bus interrupt at the requested level & vector. Wait for
+ * interrupt to be acked.
+ */
+static int fake_irq_generate(struct vme_bridge *fake_bridge, int level,
+   int statid)
+{
+   struct fake_drive

RE: Staging: unisys/verisonic: Correct double unlock

2016-04-02 Thread Sell, Timothy C
> -Original Message-
> From: Iban Rodriguez [mailto:iban.rodrig...@ono.com]
> Sent: Saturday, April 02, 2016 1:47 PM
> To: Kershner, David A; Greg Kroah-Hartman; Benjamin Romer; Sell, Timothy
> C; Neil Horman
> Cc: *S-Par-Maintainer; de...@driverdev.osuosl.org; linux-
> ker...@vger.kernel.org; Iban Rodriguez
> Subject: Staging: unisys/verisonic: Correct double unlock
> 
> 'priv_lock' is unlocked twice. The first one is removed and
> the function 'visornic_serverdown_complete' is now called with
> 'priv_lock' locked because 'devdata' is modified inside.
> 
> Signed-off-by: Iban Rodriguez 
> ---
>  drivers/staging/unisys/visornic/visornic_main.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/staging/unisys/visornic/visornic_main.c
> b/drivers/staging/unisys/visornic/visornic_main.c
> index be0d057346c3..af03f2938fe9 100644
> --- a/drivers/staging/unisys/visornic/visornic_main.c
> +++ b/drivers/staging/unisys/visornic/visornic_main.c
> @@ -368,7 +368,6 @@ visornic_serverdown(struct visornic_devdata
> *devdata,
>   }
>   devdata->server_change_state = true;
>   devdata->server_down_complete_func = complete_func;
> - spin_unlock_irqrestore(&devdata->priv_lock, flags);
>   visornic_serverdown_complete(devdata);
>   } else if (devdata->server_change_state) {
>   dev_dbg(&devdata->dev->device, "%s changing state\n",

I agree there is a bug here involving priv_lock being unlocked
twice, but this patch isn't the appropriate fix.  Reason is, we can NOT
call visornic_serverdown_complete() while holding a spinlock
(which is what this patch would cause to occur) because
visornic_serverdown_complete() might block when it calls
rtnl_lock() in this code sequence (rtnl_lock() grabs a mutex):

rtnl_lock();
dev_close(netdev);
rtnl_unlock();

Blocking with a spinlock held is always a bad idea.  :-(

> --
> 1.9.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/6] Drivers: hv: vmbus: Export the vmbus_set_event() API

2016-04-02 Thread K. Y. Srinivasan
In preparation for moving some ring buffer functionality out of the
vmbus driver, export the API for signaling the host.

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/connection.c   |1 +
 drivers/hv/hyperv_vmbus.h |2 --
 include/linux/hyperv.h|1 +
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index d02f137..fcf8a02 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -495,3 +495,4 @@ void vmbus_set_event(struct vmbus_channel *channel)
 
hv_do_hypercall(HVCALL_SIGNAL_EVENT, channel->sig_event, NULL);
 }
+EXPORT_SYMBOL_GPL(vmbus_set_event);
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 8b07f9c..e5203e4 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -672,8 +672,6 @@ void vmbus_disconnect(void);
 
 int vmbus_post_msg(void *buffer, size_t buflen);
 
-void vmbus_set_event(struct vmbus_channel *channel);
-
 void vmbus_on_event(unsigned long data);
 void vmbus_on_msg_dpc(unsigned long data);
 
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index a6b053c..4adeb6e 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1365,4 +1365,5 @@ extern __u32 vmbus_proto_version;
 
 int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  const uuid_le *shv_host_servie_id);
+void vmbus_set_event(struct vmbus_channel *channel);
 #endif /* _HYPERV_H */
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/6] Drivers: hv: vmbus: Move some ring buffer functions to hyperv.h

2016-04-02 Thread K. Y. Srinivasan
In preparation for implementing APIs for in-place consumption of VMBUS
packets, movve some ring buffer functionality into hyperv.h

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/ring_buffer.c |   55 --
 include/linux/hyperv.h   |   54 +
 2 files changed, 54 insertions(+), 55 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 8f518af..dd255c9 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -84,52 +84,6 @@ static bool hv_need_to_signal(u32 old_write, struct 
hv_ring_buffer_info *rbi)
return false;
 }
 
-/*
- * To optimize the flow management on the send-side,
- * when the sender is blocked because of lack of
- * sufficient space in the ring buffer, potential the
- * consumer of the ring buffer can signal the producer.
- * This is controlled by the following parameters:
- *
- * 1. pending_send_sz: This is the size in bytes that the
- *producer is trying to send.
- * 2. The feature bit feat_pending_send_sz set to indicate if
- *the consumer of the ring will signal when the ring
- *state transitions from being full to a state where
- *there is room for the producer to send the pending packet.
- */
-
-static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
-{
-   u32 cur_write_sz;
-   u32 pending_sz;
-
-   /*
-* Issue a full memory barrier before making the signaling decision.
-* Here is the reason for having this barrier:
-* If the reading of the pend_sz (in this function)
-* were to be reordered and read before we commit the new read
-* index (in the calling function)  we could
-* have a problem. If the host were to set the pending_sz after we
-* have sampled pending_sz and go to sleep before we commit the
-* read index, we could miss sending the interrupt. Issue a full
-* memory barrier to address this.
-*/
-   virt_mb();
-
-   pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
-   /* If the other end is not blocked on write don't bother. */
-   if (pending_sz == 0)
-   return false;
-
-   cur_write_sz = hv_get_bytes_to_write(rbi);
-
-   if (cur_write_sz >= pending_sz)
-   return true;
-
-   return false;
-}
-
 /* Get the next write location for the specified ring buffer. */
 static inline u32
 hv_get_next_write_location(struct hv_ring_buffer_info *ring_info)
@@ -180,15 +134,6 @@ hv_set_next_read_location(struct hv_ring_buffer_info 
*ring_info,
ring_info->ring_buffer->read_index = next_read_location;
 }
 
-
-/* Get the start of the ring buffer. */
-static inline void *
-hv_get_ring_buffer(struct hv_ring_buffer_info *ring_info)
-{
-   return (void *)ring_info->ring_buffer->buffer;
-}
-
-
 /* Get the size of the ring buffer. */
 static inline u32
 hv_get_ring_buffersize(struct hv_ring_buffer_info *ring_info)
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 4adeb6e..6797a30 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -1366,4 +1366,58 @@ extern __u32 vmbus_proto_version;
 int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  const uuid_le *shv_host_servie_id);
 void vmbus_set_event(struct vmbus_channel *channel);
+
+/* Get the start of the ring buffer. */
+static inline void *
+hv_get_ring_buffer(struct hv_ring_buffer_info *ring_info)
+{
+   return (void *)ring_info->ring_buffer->buffer;
+}
+
+/*
+ * To optimize the flow management on the send-side,
+ * when the sender is blocked because of lack of
+ * sufficient space in the ring buffer, potential the
+ * consumer of the ring buffer can signal the producer.
+ * This is controlled by the following parameters:
+ *
+ * 1. pending_send_sz: This is the size in bytes that the
+ *producer is trying to send.
+ * 2. The feature bit feat_pending_send_sz set to indicate if
+ *the consumer of the ring will signal when the ring
+ *state transitions from being full to a state where
+ *there is room for the producer to send the pending packet.
+ */
+
+static inline  bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
+{
+   u32 cur_write_sz;
+   u32 pending_sz;
+
+   /*
+* Issue a full memory barrier before making the signaling decision.
+* Here is the reason for having this barrier:
+* If the reading of the pend_sz (in this function)
+* were to be reordered and read before we commit the new read
+* index (in the calling function)  we could
+* have a problem. If the host were to set the pending_sz after we
+* have sampled pending_sz and go to sleep before we commit the
+* read index, we could miss sending the interrupt. Issue a full
+* memory barrier to address this.
+*/
+   virt_mb();
+
+   pending_sz = READ_ON

[PATCH 0/6] Drivers: hv: vmbus: Cleanup the ring buffer code

2016-04-02 Thread K. Y. Srinivasan
Cleanup and fix a bug in the ring buffer code. Also implement
APIs for in place consumption of received packets.

K. Y. Srinivasan (6):
  Drivers: hv: vmbus: Introduce functions for estimating room in the
ring buffer
  Drivers: hv: vmbus: Use READ_ONCE() to read variables that are
volatile
  Drivers: hv: vmbus: Use the new virt_xx barrier code
  Drivers: hv: vmbus: Export the vmbus_set_event() API
  Drivers: hv: vmbus: Move some ring buffer functions to hyperv.h
  Drivers: hv: vmbus: Implement APIs to support "in place" consumption
of vmbus packets

 drivers/hv/connection.c   |1 +
 drivers/hv/hyperv_vmbus.h |2 -
 drivers/hv/ring_buffer.c  |   95 +++--
 include/linux/hyperv.h|  168 +
 4 files changed, 181 insertions(+), 85 deletions(-)

-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/6] Drivers: hv: vmbus: Use the new virt_xx barrier code

2016-04-02 Thread K. Y. Srinivasan
Use the virt_xx barriers that have been defined for use in virtual machines.

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/ring_buffer.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 6ea1b55..8f518af 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -33,14 +33,14 @@
 void hv_begin_read(struct hv_ring_buffer_info *rbi)
 {
rbi->ring_buffer->interrupt_mask = 1;
-   mb();
+   virt_mb();
 }
 
 u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 {
 
rbi->ring_buffer->interrupt_mask = 0;
-   mb();
+   virt_mb();
 
/*
 * Now check to see if the ring buffer is still empty.
@@ -68,12 +68,12 @@ u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 
 static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
 {
-   mb();
+   virt_mb();
if (READ_ONCE(rbi->ring_buffer->interrupt_mask))
return false;
 
/* check interrupt_mask before read_index */
-   rmb();
+   virt_rmb();
/*
 * This is the only case we need to signal when the
 * ring transitions from being empty to non-empty.
@@ -115,7 +115,7 @@ static bool hv_need_to_signal_on_read(struct 
hv_ring_buffer_info *rbi)
 * read index, we could miss sending the interrupt. Issue a full
 * memory barrier to address this.
 */
-   mb();
+   virt_mb();
 
pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
/* If the other end is not blocked on write don't bother. */
@@ -371,7 +371,7 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info 
*outring_info,
 sizeof(u64));
 
/* Issue a full memory barrier before updating the write index */
-   mb();
+   virt_mb();
 
/* Now, update the write location */
hv_set_next_write_location(outring_info, next_write_location);
@@ -447,7 +447,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info 
*inring_info,
 * the writer may start writing to the read area once the read index
 * is updated.
 */
-   mb();
+   virt_mb();
 
/* Update the read index */
hv_set_next_read_location(inring_info, next_read_location);
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/6] Drivers: hv: vmbus: Implement APIs to support "in place" consumption of vmbus packets

2016-04-02 Thread K. Y. Srinivasan
Implement APIs for in-place consumption of vmbus packets. Currently, each
packet is copied and processed one at a time and as part of processing
each packet we potentially may signal the host (if it is waiting for
room to produce a packet).

These APIs help batched in-place processing of vmbus packets.
We also optimize host signaling by having a separate API to signal
the end of in-place consumption. With netvsc using these APIs,
on an iperf run on average I see about 20X reduction in checks to
signal the host.

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/ring_buffer.c |1 +
 include/linux/hyperv.h   |   86 ++
 2 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index dd255c9..fe586bf 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -132,6 +132,7 @@ hv_set_next_read_location(struct hv_ring_buffer_info 
*ring_info,
u32 next_read_location)
 {
ring_info->ring_buffer->read_index = next_read_location;
+   ring_info->priv_read_index = next_read_location;
 }
 
 /* Get the size of the ring buffer. */
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 6797a30..b10954a 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -126,6 +126,8 @@ struct hv_ring_buffer_info {
 
u32 ring_datasize;  /* < ring_size */
u32 ring_data_startoffset;
+   u32 priv_write_index;
+   u32 priv_read_index;
 };
 
 /*
@@ -1420,4 +1422,88 @@ static inline  bool hv_need_to_signal_on_read(struct 
hv_ring_buffer_info *rbi)
return false;
 }
 
+/*
+ * An API to support in-place processing of incoming VMBUS packets.
+ */
+#define VMBUS_PKT_TRAILER  8
+
+static inline struct vmpacket_descriptor *
+get_next_pkt_raw(struct vmbus_channel *channel)
+{
+   struct hv_ring_buffer_info *ring_info = &channel->inbound;
+   u32 read_loc = ring_info->priv_read_index;
+   void *ring_buffer = hv_get_ring_buffer(ring_info);
+   struct vmpacket_descriptor *cur_desc;
+   u32 packetlen;
+   u32 dsize = ring_info->ring_datasize;
+   u32 delta = read_loc - ring_info->ring_buffer->read_index;
+   u32 bytes_avail_toread = (hv_get_bytes_to_read(ring_info) - delta);
+
+   if (bytes_avail_toread < sizeof(struct vmpacket_descriptor))
+   return NULL;
+
+   if ((read_loc + sizeof(*cur_desc)) > dsize)
+   return NULL;
+
+   cur_desc = ring_buffer + read_loc;
+   packetlen = cur_desc->len8 << 3;
+
+   /*
+* If the packet under consideration is wrapping around,
+* return failure.
+*/
+   if ((read_loc + packetlen + VMBUS_PKT_TRAILER) > (dsize - 1))
+   return NULL;
+
+   return cur_desc;
+}
+
+/*
+ * A helper function to step through packets "in-place"
+ * This API is to be called after each successful call
+ * get_next_pkt_raw().
+ */
+static inline void put_pkt_raw(struct vmbus_channel *channel,
+   struct vmpacket_descriptor *desc)
+{
+   struct hv_ring_buffer_info *ring_info = &channel->inbound;
+   u32 read_loc = ring_info->priv_read_index;
+   u32 packetlen = desc->len8 << 3;
+   u32 dsize = ring_info->ring_datasize;
+
+   if ((read_loc + packetlen + VMBUS_PKT_TRAILER) > dsize)
+   BUG();
+   /*
+* Include the packet trailer.
+*/
+   ring_info->priv_read_index += packetlen + VMBUS_PKT_TRAILER;
+}
+
+/*
+ * This call commits the read index and potentially signals the host.
+ * Here is the pattern for using the "in-place" consumption APIs:
+ *
+ * while (get_next_pkt_raw() {
+ * process the packet "in-place";
+ * put_pkt_raw();
+ * }
+ * if (packets processed in place)
+ * commit_rd_index();
+ */
+static inline void commit_rd_index(struct vmbus_channel *channel)
+{
+   struct hv_ring_buffer_info *ring_info = &channel->inbound;
+   /*
+* Make sure all reads are done before we update the read index since
+* the writer may start writing to the read area once the read index
+* is updated.
+*/
+   virt_rmb();
+   ring_info->ring_buffer->read_index = ring_info->priv_read_index;
+
+   if (hv_need_to_signal_on_read(ring_info))
+   vmbus_set_event(channel);
+}
+
+
 #endif /* _HYPERV_H */
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/6] Drivers: hv: vmbus: Introduce functions for estimating room in the ring buffer

2016-04-02 Thread K. Y. Srinivasan
Introduce separate functions for estimating how much can be read from
and written to the ring buffer.

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/ring_buffer.c |   25 -
 include/linux/hyperv.h   |   27 +++
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index a40a73a..544362c 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -38,8 +38,6 @@ void hv_begin_read(struct hv_ring_buffer_info *rbi)
 
 u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 {
-   u32 read;
-   u32 write;
 
rbi->ring_buffer->interrupt_mask = 0;
mb();
@@ -49,9 +47,7 @@ u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 * If it is not, we raced and we need to process new
 * incoming messages.
 */
-   hv_get_ringbuffer_availbytes(rbi, &read, &write);
-
-   return read;
+   return hv_get_bytes_to_read(rbi);
 }
 
 /*
@@ -106,9 +102,6 @@ static bool hv_need_to_signal(u32 old_write, struct 
hv_ring_buffer_info *rbi)
 static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
 {
u32 cur_write_sz;
-   u32 r_size;
-   u32 write_loc;
-   u32 read_loc = rbi->ring_buffer->read_index;
u32 pending_sz;
 
/*
@@ -125,14 +118,11 @@ static bool hv_need_to_signal_on_read(struct 
hv_ring_buffer_info *rbi)
mb();
 
pending_sz = rbi->ring_buffer->pending_send_sz;
-   write_loc = rbi->ring_buffer->write_index;
/* If the other end is not blocked on write don't bother. */
if (pending_sz == 0)
return false;
 
-   r_size = rbi->ring_datasize;
-   cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) :
-   read_loc - write_loc;
+   cur_write_sz = hv_get_bytes_to_write(rbi);
 
if (cur_write_sz >= pending_sz)
return true;
@@ -332,7 +322,6 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info 
*outring_info,
 {
int i = 0;
u32 bytes_avail_towrite;
-   u32 bytes_avail_toread;
u32 totalbytes_towrite = 0;
 
u32 next_write_location;
@@ -348,9 +337,7 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info 
*outring_info,
if (lock)
spin_lock_irqsave(&outring_info->ring_lock, flags);
 
-   hv_get_ringbuffer_availbytes(outring_info,
-   &bytes_avail_toread,
-   &bytes_avail_towrite);
+   bytes_avail_towrite = hv_get_bytes_to_write(outring_info);
 
/*
 * If there is only room for the packet, assume it is full.
@@ -401,7 +388,6 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info 
*inring_info,
   void *buffer, u32 buflen, u32 *buffer_actual_len,
   u64 *requestid, bool *signal, bool raw)
 {
-   u32 bytes_avail_towrite;
u32 bytes_avail_toread;
u32 next_read_location = 0;
u64 prev_indices = 0;
@@ -417,10 +403,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info 
*inring_info,
*buffer_actual_len = 0;
*requestid = 0;
 
-   hv_get_ringbuffer_availbytes(inring_info,
-   &bytes_avail_toread,
-   &bytes_avail_towrite);
-
+   bytes_avail_toread = hv_get_bytes_to_read(inring_info);
/* Make sure there is something to read */
if (bytes_avail_toread < sizeof(desc)) {
/*
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index ecd81c3..a6b053c 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -151,6 +151,33 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info 
*rbi,
*read = dsize - *write;
 }
 
+static inline u32 hv_get_bytes_to_read(struct hv_ring_buffer_info *rbi)
+{
+   u32 read_loc, write_loc, dsize, read;
+
+   dsize = rbi->ring_datasize;
+   read_loc = rbi->ring_buffer->read_index;
+   write_loc = READ_ONCE(rbi->ring_buffer->write_index);
+
+   read = write_loc >= read_loc ? (write_loc - read_loc) :
+   (dsize - read_loc) + write_loc;
+
+   return read;
+}
+
+static inline u32 hv_get_bytes_to_write(struct hv_ring_buffer_info *rbi)
+{
+   u32 read_loc, write_loc, dsize, write;
+
+   dsize = rbi->ring_datasize;
+   read_loc = READ_ONCE(rbi->ring_buffer->read_index);
+   write_loc = rbi->ring_buffer->write_index;
+
+   write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
+   read_loc - write_loc;
+   return write;
+}
+
 /*
  * VMBUS version is 32 bit entity broken up into
  * two 16 bit quantities: major_number. minor_number.
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/6] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile

2016-04-02 Thread K. Y. Srinivasan
Use the READ_ONCE macro to access variabes that can change asynchronously.
This is the recommended mechanism for dealing with "unsafe" compiler
optimizations.

Signed-off-by: K. Y. Srinivasan 
---
 drivers/hv/ring_buffer.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 544362c..6ea1b55 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -69,7 +69,7 @@ u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
 {
mb();
-   if (rbi->ring_buffer->interrupt_mask)
+   if (READ_ONCE(rbi->ring_buffer->interrupt_mask))
return false;
 
/* check interrupt_mask before read_index */
@@ -78,7 +78,7 @@ static bool hv_need_to_signal(u32 old_write, struct 
hv_ring_buffer_info *rbi)
 * This is the only case we need to signal when the
 * ring transitions from being empty to non-empty.
 */
-   if (old_write == rbi->ring_buffer->read_index)
+   if (old_write == READ_ONCE(rbi->ring_buffer->read_index))
return true;
 
return false;
@@ -117,7 +117,7 @@ static bool hv_need_to_signal_on_read(struct 
hv_ring_buffer_info *rbi)
 */
mb();
 
-   pending_sz = rbi->ring_buffer->pending_send_sz;
+   pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
/* If the other end is not blocked on write don't bother. */
if (pending_sz == 0)
return false;
-- 
1.7.4.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio management.

2016-04-02 Thread KY Srinivasan


> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Saturday, April 2, 2016 3:23 PM
> To: KY Srinivasan 
> Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> jasow...@redhat.com
> Subject: Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio
> management.
> 
> On Sat, Apr 02, 2016 at 11:10:38AM -0700, K. Y. Srinivasan wrote:
> > Cleanup and mmio management. Also included is a patch
> > to fix an issue in KVP.
> 
> So these all are for 4.7-rc1?

Jake's PCI driver made it into 4.6 and some of the patches in this series fix 
issues in the Hyper-V
PCI pass-through driver. Is it possible for this series to go into 4.6. If not, 
4.7-rc1 is fine.

Regards,

K. Y
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] VME: Adding Fake VME driver

2016-04-02 Thread kbuild test robot
Hi Martyn,

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on v4.6-rc1 next-20160401]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Martyn-Welch/VME-Adding-Fake-VME-driver/20160403-071706
config: parisc-allyesconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc 

All warnings (new ones prefixed by >>):

   drivers/vme/bridges/vme_fake.c: In function 'fake_vmeread8':
>> drivers/vme/bridges/vme_fake.c:432:10: warning: cast to pointer from integer 
>> of different size [-Wint-to-pointer-cast]
   loc = (u8 *)(bridge->slaves[i].buf_base + offset);
 ^
   drivers/vme/bridges/vme_fake.c: In function 'fake_vmeread16':
   drivers/vme/bridges/vme_fake.c:464:10: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
   loc = (u16 *)(bridge->slaves[i].buf_base + offset);
 ^
   drivers/vme/bridges/vme_fake.c: In function 'fake_vmeread32':
   drivers/vme/bridges/vme_fake.c:496:10: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
   loc = (u32 *)(bridge->slaves[i].buf_base + offset);
 ^
   drivers/vme/bridges/vme_fake.c: In function 'fake_vmewrite8':
   drivers/vme/bridges/vme_fake.c:626:10: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
   loc = (u8 *)(bridge->slaves[i].buf_base + offset);
 ^
   drivers/vme/bridges/vme_fake.c: In function 'fake_vmewrite16':
   drivers/vme/bridges/vme_fake.c:656:10: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
   loc = (u16 *)(bridge->slaves[i].buf_base + offset);
 ^
   drivers/vme/bridges/vme_fake.c: In function 'fake_vmewrite32':
   drivers/vme/bridges/vme_fake.c:686:10: warning: cast to pointer from integer 
of different size [-Wint-to-pointer-cast]
   loc = (u32 *)(bridge->slaves[i].buf_base + offset);
 ^

vim +432 drivers/vme/bridges/vme_fake.c

   416  int i;
   417  unsigned long long start, end, offset;
   418  u8 *loc;
   419  
   420  for (i = 0; i < FAKE_MAX_SLAVE; i++) {
   421  start = bridge->slaves[i].vme_base;
   422  end = bridge->slaves[i].vme_base + 
bridge->slaves[i].size;
   423  
   424  if (aspace != bridge->slaves[i].aspace)
   425  continue;
   426  
   427  if (cycle != bridge->slaves[i].cycle)
   428  continue;
   429  
   430  if ((addr >= start) && (addr < end)) {
   431  offset = addr - bridge->slaves[i].vme_base;
 > 432  loc = (u8 *)(bridge->slaves[i].buf_base + 
 > offset);
   433  retval = *loc;
   434  
   435  break;
   436  }
   437  }
   438  
   439  fake_lm_check(bridge, addr, aspace, cycle);
   440  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio management.

2016-04-02 Thread Greg KH
On Sat, Apr 02, 2016 at 11:46:21PM +, KY Srinivasan wrote:
> 
> 
> > -Original Message-
> > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > Sent: Saturday, April 2, 2016 3:23 PM
> > To: KY Srinivasan 
> > Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > jasow...@redhat.com
> > Subject: Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio
> > management.
> > 
> > On Sat, Apr 02, 2016 at 11:10:38AM -0700, K. Y. Srinivasan wrote:
> > > Cleanup and mmio management. Also included is a patch
> > > to fix an issue in KVP.
> > 
> > So these all are for 4.7-rc1?
> 
> Jake's PCI driver made it into 4.6 and some of the patches in this series fix 
> issues in the Hyper-V
> PCI pass-through driver. Is it possible for this series to go into 4.6. If 
> not, 4.7-rc1 is fine.

Even patch 1?  Please be specific where you want patches to be merged
to.

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio management.

2016-04-02 Thread KY Srinivasan


> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Saturday, April 2, 2016 6:48 PM
> To: KY Srinivasan 
> Cc: o...@aepfle.de; jasow...@redhat.com; linux-ker...@vger.kernel.org;
> a...@canonical.com; de...@linuxdriverproject.org
> Subject: Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio
> management.
> 
> On Sat, Apr 02, 2016 at 11:46:21PM +, KY Srinivasan wrote:
> >
> >
> > > -Original Message-
> > > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > > Sent: Saturday, April 2, 2016 3:23 PM
> > > To: KY Srinivasan 
> > > Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > > jasow...@redhat.com
> > > Subject: Re: [PATCH 0/6] Drivers: hv: vmbus: Cleanup and mmio
> > > management.
> > >
> > > On Sat, Apr 02, 2016 at 11:10:38AM -0700, K. Y. Srinivasan wrote:
> > > > Cleanup and mmio management. Also included is a patch
> > > > to fix an issue in KVP.
> > >
> > > So these all are for 4.7-rc1?
> >
> > Jake's PCI driver made it into 4.6 and some of the patches in this series 
> > fix
> issues in the Hyper-V
> > PCI pass-through driver. Is it possible for this series to go into 4.6. If 
> > not,
> 4.7-rc1 is fine.
> 
> Even patch 1?  Please be specific where you want patches to be merged
> to.

Patch 1 can go into 4.7. If Jake's patches can go into 4.6, that would be good. 
Do you want me
to resend the patches that clearly indicate where the patches need to be merged.

Thank you for your patience.

K. Y 
> 
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] VME: Adding Fake VME driver

2016-04-02 Thread kbuild test robot
Hi Martyn,

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on v4.6-rc1 next-20160401]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Martyn-Welch/VME-Adding-Fake-VME-driver/20160403-071706
config: sparc64-allmodconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sparc64 

All warnings (new ones prefixed by >>):

   drivers/vme/bridges/vme_fake.c: In function 'fake_alloc_consistent':
>> drivers/vme/bridges/vme_fake.c:996:9: warning: cast from pointer to integer 
>> of different size [-Wpointer-to-int-cast]
 *dma = (dma_addr_t)address;
^
   drivers/vme/bridges/vme_fake.c: In function 'fake_crcsr_init':
   drivers/vme/bridges/vme_fake.c:1027:22: warning: cast from pointer to 
integer of different size [-Wpointer-to-int-cast]
 bridge->crcsr_bus = (dma_addr_t)bridge->crcsr_kernel;
 ^

vim +996 drivers/vme/bridges/vme_fake.c

   980  }
   981  
   982  /*
   983   * Determine Geographical Addressing
   984   */
   985  static int fake_slot_get(struct vme_bridge *fake_bridge)
   986  {
   987  return geoid;
   988  }
   989  
   990  static void *fake_alloc_consistent(struct device *parent, size_t size,
   991  dma_addr_t *dma)
   992  {
   993  void *address;
   994  
   995  address = kzalloc(size, GFP_KERNEL);
 > 996  *dma = (dma_addr_t)address;
   997  
   998  return address;
   999  }
  1000  
  1001  static void fake_free_consistent(struct device *parent, size_t size,
  1002  void *vaddr, dma_addr_t dma)
  1003  {
  1004  kfree(vaddr);

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel