RE: [PATCH] MAINTAINERS: Add mailing list for Hyper-V CORE AND DRIVERS

2019-02-20 Thread Haiyang Zhang



> -Original Message-
> From: Greg KH 
> Sent: Wednesday, February 20, 2019 2:52 PM
> To: Haiyang Zhang 
> Cc: sas...@kernel.org; linux-hyp...@vger.kernel.org;
> de...@linuxdriverproject.org; Stephen Hemminger
> ; linux-ker...@vger.kernel.org
> Subject: Re: [PATCH] MAINTAINERS: Add mailing list for Hyper-V CORE AND
> DRIVERS
> 
> On Wed, Feb 20, 2019 at 07:48:23PM +, Haiyang Zhang wrote:
> > From: Haiyang Zhang 
> >
> > The new mailing list is: linux-hyp...@vger.kernel.org
> >
> > Signed-off-by: Haiyang Zhang 
> > ---
> >  MAINTAINERS | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS index
> > 86aa227b5782..ef65de3cfe1b 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -7137,6 +7137,7 @@ M:Haiyang Zhang 
> >  M: Stephen Hemminger 
> >  M: Sasha Levin 
> >  T: git git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git
> > +L: linux-hyp...@vger.kernel.org
> >  L: de...@linuxdriverproject.org
> 
> Why not just drop the linuxdriverproject one when you do this?
> 
> I for one will not mind :)

I will. Thanks,
- Haiyang
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] MAINTAINERS: Add mailing list for Hyper-V CORE AND DRIVERS

2019-02-20 Thread Haiyang Zhang
From: Haiyang Zhang 

The new mailing list is: linux-hyp...@vger.kernel.org

Signed-off-by: Haiyang Zhang 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 86aa227b5782..ef65de3cfe1b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7137,6 +7137,7 @@ M:Haiyang Zhang 
 M: Stephen Hemminger 
 M: Sasha Levin 
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git
+L: linux-hyp...@vger.kernel.org
 L: de...@linuxdriverproject.org
 S: Supported
 F: Documentation/networking/device_drivers/microsoft/netvsc.txt
-- 
2.19.1

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


[PATCH hyperv-fixes,3/3] Fix hash key value reset after other ops

2019-01-14 Thread Haiyang Zhang
From: Haiyang Zhang 

Changing mtu, channels, or buffer sizes ops call to netvsc_attach(),
rndis_set_subchannel(), which always reset the hash key to default
value. That will override hash key changed previously. This patch
fixes the problem by save the hash key, then restore it when we re-
add the netvsc device.

Fixes: ff4a44199012 ("netvsc: allow get/set of RSS indirection table")
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   | 10 +++---
 drivers/net/hyperv/netvsc.c   |  2 +-
 drivers/net/hyperv/netvsc_drv.c   |  5 -
 drivers/net/hyperv/rndis_filter.c |  9 +++--
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index ef6f766f6389..e598a684700b 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -144,6 +144,8 @@ struct hv_netvsc_packet {
u32 total_data_buflen;
 };
 
+#define NETVSC_HASH_KEYLEN 40
+
 struct netvsc_device_info {
unsigned char mac_adr[ETH_ALEN];
u32  num_chn;
@@ -151,6 +153,8 @@ struct netvsc_device_info {
u32  recv_sections;
u32  send_section_size;
u32  recv_section_size;
+
+   u8 rss_key[NETVSC_HASH_KEYLEN];
 };
 
 enum rndis_device_state {
@@ -160,8 +164,6 @@ enum rndis_device_state {
RNDIS_DEV_DATAINITIALIZED,
 };
 
-#define NETVSC_HASH_KEYLEN 40
-
 struct rndis_device {
struct net_device *ndev;
 
@@ -209,7 +211,9 @@ int netvsc_recv_callback(struct net_device *net,
 void netvsc_channel_cb(void *context);
 int netvsc_poll(struct napi_struct *napi, int budget);
 
-int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev);
+int rndis_set_subchannel(struct net_device *ndev,
+struct netvsc_device *nvdev,
+struct netvsc_device_info *dev_info);
 int rndis_filter_open(struct netvsc_device *nvdev);
 int rndis_filter_close(struct netvsc_device *nvdev);
 struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 922054c1d544..1910810e55bd 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -84,7 +84,7 @@ static void netvsc_subchan_work(struct work_struct *w)
 
rdev = nvdev->extension;
if (rdev) {
-   ret = rndis_set_subchannel(rdev->ndev, nvdev);
+   ret = rndis_set_subchannel(rdev->ndev, nvdev, NULL);
if (ret == 0) {
netif_device_attach(rdev->ndev);
} else {
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f424327f7206..e281829a04ef 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -877,6 +877,9 @@ static struct netvsc_device_info *netvsc_devinfo_get
dev_info->send_section_size = nvdev->send_section_size;
dev_info->recv_sections = nvdev->recv_section_cnt;
dev_info->recv_section_size = nvdev->recv_section_size;
+
+   memcpy(dev_info->rss_key, nvdev->extension->rss_key,
+  NETVSC_HASH_KEYLEN);
} else {
dev_info->num_chn = VRSS_CHANNEL_DEFAULT;
dev_info->send_sections = NETVSC_DEFAULT_TX;
@@ -939,7 +942,7 @@ static int netvsc_attach(struct net_device *ndev,
return PTR_ERR(nvdev);
 
if (nvdev->num_chn > 1) {
-   ret = rndis_set_subchannel(ndev, nvdev);
+   ret = rndis_set_subchannel(ndev, nvdev, dev_info);
 
/* if unavailable, just proceed with one queue */
if (ret) {
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index a4661d396e3c..db81378e6624 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1134,7 +1134,9 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
  * This breaks overlap of processing the host message for the
  * new primary channel with the initialization of sub-channels.
  */
-int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev)
+int rndis_set_subchannel(struct net_device *ndev,
+struct netvsc_device *nvdev,
+struct netvsc_device_info *dev_info)
 {
struct nvsp_message *init_packet = >channel_init_pkt;
struct net_device_context *ndev_ctx = netdev_priv(ndev);
@@ -1175,7 +1177,10 @@ int rndis_set_subchannel(struct net_device *ndev, struct 
netvsc_device *nvdev)
   atomic_read(>open_chn) == nvdev->num_chn);
 
/* ignore failues from setting rss parameters, still have channels */
-   rndis_filter_set_rss_param(rdev, netvsc_hash_key);
+   if (dev_info)
+   rndis_filter_set_rss_param(rdev, dev_info->rss_key);
+   

[PATCH hyperv-fixes,0/3] fixes for hash key setting issues

2019-01-14 Thread Haiyang Zhang
From: Haiyang Zhang 

Using ethtool to change Hash key failed on Linux VM runnig on
Hyper-V. This patch set fix them.
It targets Hyper-V tree, hyperv-fixes branch managed by 
Sasha Levin .

Haiyang Zhang (3):
  Fix ethtool change hash key error
  Refactor assignments of struct netvsc_device_info
  Fix hash key value reset after other ops

 drivers/net/hyperv/hyperv_net.h   |  10 ++-
 drivers/net/hyperv/netvsc.c   |   2 +-
 drivers/net/hyperv/netvsc_drv.c   | 139 +++---
 drivers/net/hyperv/rndis_filter.c |  34 ++--
 4 files changed, 123 insertions(+), 62 deletions(-)

-- 
2.19.1

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


[PATCH hyperv-fixes,1/3] Fix ethtool change hash key error

2019-01-14 Thread Haiyang Zhang
From: Haiyang Zhang 

Hyper-V hosts require us to disable RSS before changing RSS key,
otherwise the changing request will fail. This patch fixes the
coding error.

Fixes: ff4a44199012 ("netvsc: allow get/set of RSS indirection table")
Reported-by: Wei Hu 
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/rndis_filter.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 8b537a049c1e..a4661d396e3c 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -774,8 +774,8 @@ rndis_filter_set_offload_params(struct net_device *ndev,
return ret;
 }
 
-int rndis_filter_set_rss_param(struct rndis_device *rdev,
-  const u8 *rss_key)
+static int rndis_set_rss_param_msg(struct rndis_device *rdev,
+  const u8 *rss_key, u16 flag)
 {
struct net_device *ndev = rdev->ndev;
struct rndis_request *request;
@@ -804,7 +804,7 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
rssp->hdr.type = NDIS_OBJECT_TYPE_RSS_PARAMETERS;
rssp->hdr.rev = NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2;
rssp->hdr.size = sizeof(struct ndis_recv_scale_param);
-   rssp->flag = 0;
+   rssp->flag = flag;
rssp->hashinfo = NDIS_HASH_FUNC_TOEPLITZ | NDIS_HASH_IPV4 |
 NDIS_HASH_TCP_IPV4 | NDIS_HASH_IPV6 |
 NDIS_HASH_TCP_IPV6;
@@ -829,9 +829,12 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
 
wait_for_completion(>wait_event);
set_complete = >response_msg.msg.set_complete;
-   if (set_complete->status == RNDIS_STATUS_SUCCESS)
-   memcpy(rdev->rss_key, rss_key, NETVSC_HASH_KEYLEN);
-   else {
+   if (set_complete->status == RNDIS_STATUS_SUCCESS) {
+   if (!(flag & NDIS_RSS_PARAM_FLAG_DISABLE_RSS) &&
+   !(flag & NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED))
+   memcpy(rdev->rss_key, rss_key, NETVSC_HASH_KEYLEN);
+
+   } else {
netdev_err(ndev, "Fail to set RSS parameters:0x%x\n",
   set_complete->status);
ret = -EINVAL;
@@ -842,6 +845,16 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
return ret;
 }
 
+int rndis_filter_set_rss_param(struct rndis_device *rdev,
+  const u8 *rss_key)
+{
+   /* Disable RSS before change */
+   rndis_set_rss_param_msg(rdev, rss_key,
+   NDIS_RSS_PARAM_FLAG_DISABLE_RSS);
+
+   return rndis_set_rss_param_msg(rdev, rss_key, 0);
+}
+
 static int rndis_filter_query_device_link_status(struct rndis_device *dev,
 struct netvsc_device 
*net_device)
 {
-- 
2.19.1

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


[PATCH hyperv-fixes, 2/3] Refactor assignments of struct netvsc_device_info

2019-01-14 Thread Haiyang Zhang
From: Haiyang Zhang 

These assignments occur in multiple places. The patch refactor them
to a function for simplicity. It also puts the struct to heap area
for future expension.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc_drv.c | 134 
 1 file changed, 85 insertions(+), 49 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 91ed15ea5883..f424327f7206 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -858,6 +858,36 @@ static void netvsc_get_channels(struct net_device *net,
}
 }
 
+/* Alloc struct netvsc_device_info, and initialize it from either existing
+ * struct netvsc_device, or from default values.
+ */
+static struct netvsc_device_info *netvsc_devinfo_get
+   (struct netvsc_device *nvdev)
+{
+   struct netvsc_device_info *dev_info;
+
+   dev_info = kzalloc(sizeof(*dev_info), GFP_ATOMIC);
+
+   if (!dev_info)
+   return NULL;
+
+   if (nvdev) {
+   dev_info->num_chn = nvdev->num_chn;
+   dev_info->send_sections = nvdev->send_section_cnt;
+   dev_info->send_section_size = nvdev->send_section_size;
+   dev_info->recv_sections = nvdev->recv_section_cnt;
+   dev_info->recv_section_size = nvdev->recv_section_size;
+   } else {
+   dev_info->num_chn = VRSS_CHANNEL_DEFAULT;
+   dev_info->send_sections = NETVSC_DEFAULT_TX;
+   dev_info->send_section_size = NETVSC_SEND_SECTION_SIZE;
+   dev_info->recv_sections = NETVSC_DEFAULT_RX;
+   dev_info->recv_section_size = NETVSC_RECV_SECTION_SIZE;
+   }
+
+   return dev_info;
+}
+
 static int netvsc_detach(struct net_device *ndev,
 struct netvsc_device *nvdev)
 {
@@ -943,7 +973,7 @@ static int netvsc_set_channels(struct net_device *net,
struct net_device_context *net_device_ctx = netdev_priv(net);
struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
unsigned int orig, count = channels->combined_count;
-   struct netvsc_device_info device_info;
+   struct netvsc_device_info *device_info;
int ret;
 
/* We do not support separate count for rx, tx, or other */
@@ -962,24 +992,26 @@ static int netvsc_set_channels(struct net_device *net,
 
orig = nvdev->num_chn;
 
-   memset(_info, 0, sizeof(device_info));
-   device_info.num_chn = count;
-   device_info.send_sections = nvdev->send_section_cnt;
-   device_info.send_section_size = nvdev->send_section_size;
-   device_info.recv_sections = nvdev->recv_section_cnt;
-   device_info.recv_section_size = nvdev->recv_section_size;
+   device_info = netvsc_devinfo_get(nvdev);
+
+   if (!device_info)
+   return -ENOMEM;
+
+   device_info->num_chn = count;
 
ret = netvsc_detach(net, nvdev);
if (ret)
-   return ret;
+   goto out;
 
-   ret = netvsc_attach(net, _info);
+   ret = netvsc_attach(net, device_info);
if (ret) {
-   device_info.num_chn = orig;
-   if (netvsc_attach(net, _info))
+   device_info->num_chn = orig;
+   if (netvsc_attach(net, device_info))
netdev_err(net, "restoring channel setting failed\n");
}
 
+out:
+   kfree(device_info);
return ret;
 }
 
@@ -1048,48 +1080,45 @@ static int netvsc_change_mtu(struct net_device *ndev, 
int mtu)
struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev);
struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
int orig_mtu = ndev->mtu;
-   struct netvsc_device_info device_info;
+   struct netvsc_device_info *device_info;
int ret = 0;
 
if (!nvdev || nvdev->destroy)
return -ENODEV;
 
+   device_info = netvsc_devinfo_get(nvdev);
+
+   if (!device_info)
+   return -ENOMEM;
+
/* Change MTU of underlying VF netdev first. */
if (vf_netdev) {
ret = dev_set_mtu(vf_netdev, mtu);
if (ret)
-   return ret;
+   goto out;
}
 
-   memset(_info, 0, sizeof(device_info));
-   device_info.num_chn = nvdev->num_chn;
-   device_info.send_sections = nvdev->send_section_cnt;
-   device_info.send_section_size = nvdev->send_section_size;
-   device_info.recv_sections = nvdev->recv_section_cnt;
-   device_info.recv_section_size = nvdev->recv_section_size;
-
ret = netvsc_detach(ndev, nvdev);
if (ret)
goto rollback_vf;
 
ndev->mtu = mtu;
 
-   ret = netvsc_attach(ndev, _info);
-   if (ret)
-   goto rollback;
-
-   r

RE: [PATCH net-next 2/4] net/hyperv: use skb_vlan_tag_*() helpers

2018-11-20 Thread Haiyang Zhang


> -Original Message-
> From: Michał Mirosław 
> Sent: Tuesday, November 20, 2018 7:21 AM
> To: net...@vger.kernel.org
> Cc: KY Srinivasan ; Haiyang Zhang
> ; Stephen Hemminger
> ; de...@linuxdriverproject.org; Ajit Khaparde
> ; Leon Romanovsky ;
> linux-r...@vger.kernel.org; Saeed Mahameed ;
> Sathya Perla ; Somnath Kotur
> ; Sriharsha Basavapatna
> 
> Subject: [PATCH net-next 2/4] net/hyperv: use skb_vlan_tag_*() helpers
> 
> Replace open-coded bitfield manipulation with skb_vlan_tag_*() helpers.
> This also enables correctly passing of VLAN.CFI bit.
> 
> Signed-off-by: Michał Mirosław 
> ---

Reviewed-by: Haiyang Zhang 
Thanks.

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


RE: [PATCH V2 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up

2018-11-01 Thread Haiyang Zhang



> -Original Message-
> From: k...@linuxonhyperv.com 
> Sent: Thursday, October 18, 2018 1:10 AM
> To: gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
> jasow...@redhat.com; Stephen Hemminger ;
> Michael Kelley ; vkuznets 
> Cc: Dexuan Cui ; KY Srinivasan ;
> Haiyang Zhang ; sta...@vger.kernel.org
> Subject: [PATCH V2 3/5] Drivers: hv: kvp: Fix the recent regression caused by
> incorrect clean-up
> 
> From: Dexuan Cui 
> 
> In kvp_send_key(), we do need call process_ib_ipinfo() if
> message->kvp_hdr.operation is KVP_OP_GET_IP_INFO, because it turns out
> the userland hv_kvp_daemon needs the info of operation, adapter_id and
> addr_family. With the incorrect fc62c3b1977d, the host can't get the VM's IP
> via KVP.
> 
> And, fc62c3b1977d added a "break;", but actually forgot to initialize the
> key_size/value in the case of KVP_OP_SET, so the default key_size of
> 0 is passed to the kvp daemon, and the pool files
> /var/lib/hyperv/.kvp_pool_* can't be updated.
> 
> This patch effectively rolls back the previous fc62c3b1977d, and correctly 
> fixes
> the "this statement may fall through" warnings.
> 
> This patch is tested on WS 2012 R2 and 2016.
> 
> Fixes: fc62c3b1977d ("Drivers: hv: kvp: Fix two "this statement may fall
> through" warnings")
> Signed-off-by: Dexuan Cui 
> Cc: K. Y. Srinivasan 
> Cc: Haiyang Zhang 
> Cc: Stephen Hemminger 
> Cc: 
> Signed-off-by: K. Y. Srinivasan 

Signed-off-by: Haiyang Zhang 

Thanks!

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


[PATCH net-next, v3] hv_netvsc: fix vf serial matching with pci slot info

2018-10-15 Thread Haiyang Zhang
From: Haiyang Zhang 

The VF device's serial number is saved as a string in PCI slot's
kobj name, not the slot->number. This patch corrects the netvsc
driver, so the VF device can be successfully paired with synthetic
NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Reported-by: Vitaly Kuznetsov 
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 9bcaf204a7d4..cf36e7ff3191 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct *w)
rtnl_unlock();
 }
 
-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 {
struct device *parent = vf_netdev->dev.parent;
struct net_device_context *ndev_ctx;
struct pci_dev *pdev;
+   u32 serial;
 
if (!parent || !dev_is_pci(parent))
return NULL; /* not a PCI device */
@@ -2048,16 +2049,22 @@ static struct net_device *get_netvsc_byslot(const 
struct net_device *vf_netdev)
return NULL;
}
 
+   if (kstrtou32(pci_slot_name(pdev->slot), 10, )) {
+   netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+ pci_slot_name(pdev->slot));
+   return NULL;
+   }
+
list_for_each_entry(ndev_ctx, _dev_list, list) {
if (!ndev_ctx->vf_alloc)
continue;
 
-   if (ndev_ctx->vf_serial == pdev->slot->number)
+   if (ndev_ctx->vf_serial == serial)
return hv_get_drvdata(ndev_ctx->device_ctx);
}
 
netdev_notice(vf_netdev,
- "no netdev found for slot %u\n", pdev->slot->number);
+ "no netdev found for vf serial:%u\n", serial);
return NULL;
 }
 
-- 
2.18.0

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


RE: [PATCH net-next, v2] hv_netvsc: fix vf serial matching with pci slot info

2018-10-12 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Friday, October 12, 2018 6:21 PM
> To: Haiyang Zhang 
> Cc: Haiyang Zhang ; da...@davemloft.net;
> net...@vger.kernel.org; o...@aepfle.de; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuznets 
> Subject: Re: [PATCH net-next, v2] hv_netvsc: fix vf serial matching with pci 
> slot
> info
> 
> On Fri, 12 Oct 2018 20:55:15 +
> Haiyang Zhang  wrote:
> 
> Thanks for fixing this.
> 
> 
> > +   if (kstrtou32(kobject_name(>slot->kobj), 10, )) {
> > +   netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
> > + pdev->slot->kobj.name);
> > +   return NULL;
> > +   }
> 
> Shouldn't this use kobject_name() in the message as well.
> 
> Looking at the pci.h code there is already an API to get name from slot (it 
> uses
> kobject_name()). So please use that one.

Sure, I will look for that api. Thanks.

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


[PATCH net-next, v2] hv_netvsc: fix vf serial matching with pci slot info

2018-10-12 Thread Haiyang Zhang
From: Haiyang Zhang 

The VF device's serial number is saved as a string in PCI slot's
kobj name, not the slot->number. This patch corrects the netvsc
driver, so the VF device can be successfully paired with synthetic
NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Reported-by: Vitaly Kuznetsov 
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 9bcaf204a7d4..ded623862003 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct *w)
rtnl_unlock();
 }
 
-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 {
struct device *parent = vf_netdev->dev.parent;
struct net_device_context *ndev_ctx;
struct pci_dev *pdev;
+   u32 serial;
 
if (!parent || !dev_is_pci(parent))
return NULL; /* not a PCI device */
@@ -2048,16 +2049,22 @@ static struct net_device *get_netvsc_byslot(const 
struct net_device *vf_netdev)
return NULL;
}
 
+   if (kstrtou32(kobject_name(>slot->kobj), 10, )) {
+   netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+ pdev->slot->kobj.name);
+   return NULL;
+   }
+
list_for_each_entry(ndev_ctx, _dev_list, list) {
if (!ndev_ctx->vf_alloc)
continue;
 
-   if (ndev_ctx->vf_serial == pdev->slot->number)
+   if (ndev_ctx->vf_serial == serial)
return hv_get_drvdata(ndev_ctx->device_ctx);
}
 
netdev_notice(vf_netdev,
- "no netdev found for slot %u\n", pdev->slot->number);
+ "no netdev found for vf serial:%u\n", serial);
return NULL;
 }
 
-- 
2.18.0

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


RE: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

2018-10-12 Thread Haiyang Zhang



> -Original Message-
> From: Greg KH 
> Sent: Friday, October 12, 2018 2:36 AM
> To: Haiyang Zhang 
> Cc: da...@davemloft.net; net...@vger.kernel.org; o...@aepfle.de; Stephen
> Hemminger ; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuznets 
> Subject: Re: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot 
> info
> 
> On Thu, Oct 11, 2018 at 08:14:34PM +, Haiyang Zhang wrote:
> > From: Haiyang Zhang 
> >
> > The VF device's serial number is saved as a string in PCI slot's kobj
> > name, not the slot->number. This patch corrects the netvsc driver, so
> > the VF device can be successfully paired with synthetic NIC.
> >
> > Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
> > Signed-off-by: Haiyang Zhang 
> > ---
> >  drivers/net/hyperv/netvsc_drv.c | 15 +++
> >  1 file changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > b/drivers/net/hyperv/netvsc_drv.c index 9bcaf204a7d4..8121ce34a39f
> > 100644
> > --- a/drivers/net/hyperv/netvsc_drv.c
> > +++ b/drivers/net/hyperv/netvsc_drv.c
> > @@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct
> *w)
> > rtnl_unlock();
> >  }
> >
> > -/* Find netvsc by VMBus serial number.
> > - * The PCI hyperv controller records the serial number as the slot.
> > +/* Find netvsc by VF serial number.
> > + * The PCI hyperv controller records the serial number as the slot kobj 
> > name.
> >   */
> >  static struct net_device *get_netvsc_byslot(const struct net_device
> > *vf_netdev)  {
> > struct device *parent = vf_netdev->dev.parent;
> > struct net_device_context *ndev_ctx;
> > struct pci_dev *pdev;
> > +   u32 serial;
> >
> > if (!parent || !dev_is_pci(parent))
> > return NULL; /* not a PCI device */ @@ -2048,16 +2049,22
> @@ static
> > struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
> > return NULL;
> > }
> >
> > +   if (kstrtou32(pdev->slot->kobj.name, 10, )) {
> 
> kobject_name()?
> 
> And that feels _very_ fragile to me.  This is now an api that you are
> guaranteeing will never change?

Thanks for the suggestion -- I will update it to use kobject_name() to 
access the name.

For stability, the VF NIC's serial numbers are always unique according
to the Hyper-V documents. Other devices may have same numbers,
but they are not handled by netvsc driver.

Thanks,
- Haiyang

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


RE: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

2018-10-11 Thread Haiyang Zhang



> -Original Message-
> From: Haiyang Zhang 
> Sent: Thursday, October 11, 2018 4:15 PM
> To: da...@davemloft.net; net...@vger.kernel.org
> Cc: Haiyang Zhang ; KY Srinivasan
> ; Stephen Hemminger ;
> o...@aepfle.de; vkuznets ;
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org
> Subject: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info
> 
> From: Haiyang Zhang 
> 
> The VF device's serial number is saved as a string in PCI slot's kobj name, 
> not
> the slot->number. This patch corrects the netvsc driver, so the VF device can 
> be
> successfully paired with synthetic NIC.
> 
> Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
> Signed-off-by: Haiyang Zhang 

Thanks Stephen for the reminder -- I added the "reported-by" here:

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


[PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

2018-10-11 Thread Haiyang Zhang
From: Haiyang Zhang 

The VF device's serial number is saved as a string in PCI slot's
kobj name, not the slot->number. This patch corrects the netvsc
driver, so the VF device can be successfully paired with synthetic
NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 9bcaf204a7d4..8121ce34a39f 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct *w)
rtnl_unlock();
 }
 
-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 {
struct device *parent = vf_netdev->dev.parent;
struct net_device_context *ndev_ctx;
struct pci_dev *pdev;
+   u32 serial;
 
if (!parent || !dev_is_pci(parent))
return NULL; /* not a PCI device */
@@ -2048,16 +2049,22 @@ static struct net_device *get_netvsc_byslot(const 
struct net_device *vf_netdev)
return NULL;
}
 
+   if (kstrtou32(pdev->slot->kobj.name, 10, )) {
+   netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+ pdev->slot->kobj.name);
+   return NULL;
+   }
+
list_for_each_entry(ndev_ctx, _dev_list, list) {
if (!ndev_ctx->vf_alloc)
continue;
 
-   if (ndev_ctx->vf_serial == pdev->slot->number)
+   if (ndev_ctx->vf_serial == serial)
return hv_get_drvdata(ndev_ctx->device_ctx);
}
 
netdev_notice(vf_netdev,
- "no netdev found for slot %u\n", pdev->slot->number);
+ "no netdev found for vf serial:%u\n", serial);
return NULL;
 }
 
-- 
2.18.0

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


[PATCH net-next] hv_netvsc: Fix rndis_per_packet_info internal field initialization

2018-09-28 Thread Haiyang Zhang
From: Haiyang Zhang 

The RSC feature -- a bit field "internal" was added here with total
size unchanged:
struct rndis_per_packet_info {
u32 size;
u32 type:31;
u32 internal:1;
u32 ppi_offset;
};

On TX path, we put rndis msg into skb head room, which is not zeroed
before passing to us. We do not use the "internal" field in TX path,
but it may impact older hosts which use the entire 32 bits as "type".

To fix the bug, this patch sets the field "internal" to zero.

Fixes: c8e4eff4675f ("hv_netvsc: Add support for LRO/RSC in the vSwitch")
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index ec699741170b..005cbaa2fa3b 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -226,6 +226,7 @@ static inline void *init_ppi_data(struct rndis_message *msg,
 
ppi->size = ppi_size;
ppi->type = pkt_type;
+   ppi->internal = 0;
ppi->ppi_offset = sizeof(struct rndis_per_packet_info);
 
rndis_pkt->per_pkt_info_len += ppi_size;
-- 
2.18.0

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


RE: [PATCH] hv_netvsc: Make sure out channel is fully opened on send

2018-09-26 Thread Haiyang Zhang



> -Original Message-
> From: Mohammed Gamal 
> Sent: Wednesday, September 26, 2018 12:34 PM
> To: Stephen Hemminger ; net...@vger.kernel.org
> Cc: KY Srinivasan ; Haiyang Zhang
> ; vkuznets ;
> ot...@redhat.com; cavery ; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; Mohammed Gamal
> 
> Subject: [PATCH] hv_netvsc: Make sure out channel is fully opened on send
> 
> Dring high network traffic changes to network interface parameters such as
> number of channels or MTU can cause a kernel panic with a NULL pointer
> dereference. This is due to netvsc_device_remove() being called and
> deallocating the channel ring buffers, which can then be accessed by
> netvsc_send_pkt() before they're allocated on calling
> netvsc_device_add()
> 
> The patch fixes this problem by checking the channel state and returning
> ENODEV if not yet opened. We also move the call to hv_ringbuf_avail_percent()
> which may access the uninitialized ring buffer.
> 
> Signed-off-by: Mohammed Gamal 
> ---
>  drivers/net/hyperv/netvsc.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index
> fe01e14..75f1b31 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -825,7 +825,12 @@ static inline int netvsc_send_pkt(
>   struct netdev_queue *txq = netdev_get_tx_queue(ndev, packet->q_idx);
>   u64 req_id;
>   int ret;
> - u32 ring_avail = hv_get_avail_to_write_percent(_channel-
> >outbound);
> + u32 ring_avail;
> +
> + if (out_channel->state != CHANNEL_OPENED_STATE)
> + return -ENODEV;
> +
> + ring_avail = hv_get_avail_to_write_percent(_channel->outbound);

When you reproducing the NULL ptr panic, does your kernel include the following 
patch?
hv_netvsc: common detach logic
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=7b2ee50c0cd513a176a26a71f2989facdd75bfea

We call netif_tx_disable(ndev) and netif_device_detach(ndev) before doing the 
changes 
on MTU or #channels. So there should be no call to start_xmit() when channel is 
not ready.

If you see the check for CHANNEL_OPENED_STATE is still necessary on upstream 
kernel (including 
the patch " common detach logic "), we should debug further on the code and 
find out the 
root cause.

Thanks,
- Haiyang

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


RE: [PATCH net-next, v2, 1/3] hv_netvsc: Add support for LRO/RSC in the vSwitch

2018-09-21 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Friday, September 21, 2018 4:22 PM
> To: Haiyang Zhang 
> Cc: da...@davemloft.net; net...@vger.kernel.org; o...@aepfle.de; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; vkuznets
> 
> Subject: Re: [PATCH net-next, v2, 1/3] hv_netvsc: Add support for LRO/RSC in
> the vSwitch
> 
> On Fri, 21 Sep 2018 18:51:54 +
> Haiyang Zhang  wrote:
> 
> > > -Original Message-
> > > From: Stephen Hemminger 
> > > Sent: Friday, September 21, 2018 2:37 PM
> > > To: Haiyang Zhang 
> > > Cc: Haiyang Zhang ; da...@davemloft.net;
> > > net...@vger.kernel.org; o...@aepfle.de;
> > > linux-ker...@vger.kernel.org; de...@linuxdriverproject.org; vkuznets
> > > 
> > > Subject: Re: [PATCH net-next, v2, 1/3] hv_netvsc: Add support for
> > > LRO/RSC in the vSwitch
> > >
> > > On Fri, 21 Sep 2018 18:20:35 +
> > > Haiyang Zhang  wrote:
> > >
> > > Overall, this looks good. Some minor suggestions.
> > >
> > > > +struct nvsc_rsc {
> > > > +   const struct ndis_pkt_8021q_info *vlan;
> > > > +   const struct ndis_tcp_ip_checksum_info *csum_info;
> > > > +   u8 is_last; /* last RNDIS msg in a vmtransfer_page */
> > > > +   u32 cnt; /* #fragments in an RSC packet */
> > > > +   u32 pktlen; /* Full packet length */
> > > > +   void *data[NVSP_RSC_MAX];
> > > > +   u32 len[NVSP_RSC_MAX];
> > > > +};
> > > > +
> > >
> > > This new state structure is state on a per-channel basis.
> > > Do you really need this to be persistent across packets?
> > >
> > > Could this be on stack or do you need it to handle split packets
> > > arriving in different polls? Or is the stack space a problem?
> > >
> > > Also, maybe data and length could be in one structure since they are
> related.
> >
> > The stack space is a problem. NVSP_RSC_MAX is 562, which is defined by host.
> > It will be too large for limited stack space.
> >
> > struct nvsc_rsc includes the data, len, cnt, chksum, vlan for one RSC
> > packet. They are all related to construction of one SKB and its meta
> > data. So I put them in one structure.
> >
> > Thanks,
> > - Haiyang
> >
> 
> That makes sense. How big is sizeof(struct net_device) + netdev_priv now?
> Need to make sure it doesn't become an order 2 (ie keep it less than 4K).

This patch does not change struct net_device or netdev_priv, so their size
stays the same. Thanks.

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


RE: [PATCH net-next, v2, 1/3] hv_netvsc: Add support for LRO/RSC in the vSwitch

2018-09-21 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Friday, September 21, 2018 2:37 PM
> To: Haiyang Zhang 
> Cc: Haiyang Zhang ; da...@davemloft.net;
> net...@vger.kernel.org; o...@aepfle.de; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuznets 
> Subject: Re: [PATCH net-next, v2, 1/3] hv_netvsc: Add support for LRO/RSC in
> the vSwitch
> 
> On Fri, 21 Sep 2018 18:20:35 +
> Haiyang Zhang  wrote:
> 
> Overall, this looks good. Some minor suggestions.
> 
> > +struct nvsc_rsc {
> > +   const struct ndis_pkt_8021q_info *vlan;
> > +   const struct ndis_tcp_ip_checksum_info *csum_info;
> > +   u8 is_last; /* last RNDIS msg in a vmtransfer_page */
> > +   u32 cnt; /* #fragments in an RSC packet */
> > +   u32 pktlen; /* Full packet length */
> > +   void *data[NVSP_RSC_MAX];
> > +   u32 len[NVSP_RSC_MAX];
> > +};
> > +
> 
> This new state structure is state on a per-channel basis.
> Do you really need this to be persistent across packets?
> 
> Could this be on stack or do you need it to handle split packets arriving in
> different polls? Or is the stack space a problem?
> 
> Also, maybe data and length could be in one structure since they are related.

The stack space is a problem. NVSP_RSC_MAX is 562, which is defined by host.
It will be too large for limited stack space. 

struct nvsc_rsc includes the data, len, cnt, chksum, vlan for one RSC packet. 
They
are all related to construction of one SKB and its meta data. So I put them in
one structure.

Thanks,
- Haiyang

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


[PATCH net-next, v2, 3/3] hv_netvsc: Update document for LRO/RSC support

2018-09-21 Thread Haiyang Zhang
From: Haiyang Zhang 

Update document for LRO/RSC support, and the command line info to
change the setting.

Signed-off-by: Haiyang Zhang 
---
 Documentation/networking/netvsc.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/networking/netvsc.txt 
b/Documentation/networking/netvsc.txt
index 92f5b31392fa..3bfa635bbbd5 100644
--- a/Documentation/networking/netvsc.txt
+++ b/Documentation/networking/netvsc.txt
@@ -45,6 +45,15 @@ Features
   like packets and significantly reduces CPU usage under heavy Rx
   load.
 
+  Large Receive Offload (LRO), or Receive Side Coalescing (RSC)
+  -
+  The driver supports LRO/RSC in the vSwitch feature. It reduces the per packet
+  processing overhead by coalescing multiple TCP segments when possible. The
+  feature is enabled by default on VMs running on Windows Server 2019 and
+  later. It may be changed by ethtool command:
+   ethtool -K eth0 lro on
+   ethtool -K eth0 lro off
+
   SR-IOV support
   --
   Hyper-V supports SR-IOV as a hardware acceleration option. If SR-IOV
-- 
2.18.0

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


[PATCH net-next, v2, 1/3] hv_netvsc: Add support for LRO/RSC in the vSwitch

2018-09-21 Thread Haiyang Zhang
From: Haiyang Zhang 

LRO/RSC in the vSwitch is a feature available in Windows Server 2019
hosts and later. It reduces the per packet processing overhead by
coalescing multiple TCP segments when possible. This patch adds netvsc
driver support for this feature.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   | 47 +---
 drivers/net/hyperv/netvsc.c   | 18 +--
 drivers/net/hyperv/netvsc_drv.c   | 28 +-
 drivers/net/hyperv/rndis_filter.c | 90 ++-
 4 files changed, 145 insertions(+), 38 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index a32ded5b4f41..7f1603dc8128 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -186,6 +186,7 @@ struct rndis_device {
 /* Interface */
 struct rndis_message;
 struct netvsc_device;
+struct netvsc_channel;
 struct net_device_context;
 
 extern u32 netvsc_ring_bytes;
@@ -203,10 +204,7 @@ void netvsc_linkstatus_callback(struct net_device *net,
struct rndis_message *resp);
 int netvsc_recv_callback(struct net_device *net,
 struct netvsc_device *nvdev,
-struct vmbus_channel *channel,
-void  *data, u32 len,
-const struct ndis_tcp_ip_checksum_info *csum_info,
-const struct ndis_pkt_8021q_info *vlan);
+struct netvsc_channel *nvchan);
 void netvsc_channel_cb(void *context);
 int netvsc_poll(struct napi_struct *napi, int budget);
 
@@ -222,7 +220,7 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
   const u8 *key);
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
-struct vmbus_channel *channel,
+struct netvsc_channel *nvchan,
 void *data, u32 buflen);
 
 int rndis_filter_set_device_mac(struct netvsc_device *ndev,
@@ -524,6 +522,8 @@ struct nvsp_2_vsc_capability {
u64 ieee8021q:1;
u64 correlation_id:1;
u64 teaming:1;
+   u64 vsubnetid:1;
+   u64 rsc:1;
};
};
 } __packed;
@@ -826,7 +826,7 @@ struct nvsp_message {
 
 #define NETVSC_SUPPORTED_HW_FEATURES (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | \
  NETIF_F_TSO | NETIF_F_IPV6_CSUM | \
- NETIF_F_TSO6)
+ NETIF_F_TSO6 | NETIF_F_LRO)
 
 #define VRSS_SEND_TAB_SIZE 16  /* must be power of 2 */
 #define VRSS_CHANNEL_MAX 64
@@ -852,6 +852,18 @@ struct multi_recv_comp {
u32 next;   /* next entry for writing */
 };
 
+#define NVSP_RSC_MAX 562 /* Max #RSC frags in a vmbus xfer page pkt */
+
+struct nvsc_rsc {
+   const struct ndis_pkt_8021q_info *vlan;
+   const struct ndis_tcp_ip_checksum_info *csum_info;
+   u8 is_last; /* last RNDIS msg in a vmtransfer_page */
+   u32 cnt; /* #fragments in an RSC packet */
+   u32 pktlen; /* Full packet length */
+   void *data[NVSP_RSC_MAX];
+   u32 len[NVSP_RSC_MAX];
+};
+
 struct netvsc_stats {
u64 packets;
u64 bytes;
@@ -955,6 +967,7 @@ struct netvsc_channel {
struct multi_send_data msd;
struct multi_recv_comp mrc;
atomic_t queue_sends;
+   struct nvsc_rsc rsc;
 
struct netvsc_stats tx_stats;
struct netvsc_stats rx_stats;
@@ -1136,7 +1149,8 @@ struct rndis_oobd {
 /* Packet extension field contents associated with a Data message. */
 struct rndis_per_packet_info {
u32 size;
-   u32 type;
+   u32 type:31;
+   u32 internal:1;
u32 ppi_offset;
 };
 
@@ -1157,6 +1171,25 @@ enum ndis_per_pkt_info_type {
MAX_PER_PKT_INFO
 };
 
+enum rndis_per_pkt_info_interal_type {
+   RNDIS_PKTINFO_ID = 1,
+   /* Add more memebers here */
+
+   RNDIS_PKTINFO_MAX
+};
+
+#define RNDIS_PKTINFO_SUBALLOC BIT(0)
+#define RNDIS_PKTINFO_1ST_FRAG BIT(1)
+#define RNDIS_PKTINFO_LAST_FRAG BIT(2)
+
+#define RNDIS_PKTINFO_ID_V1 1
+
+struct rndis_pktinfo_id {
+   u8 ver;
+   u8 flag;
+   u16 pkt_id;
+};
+
 struct ndis_pkt_8021q_info {
union {
struct {
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index fe01e141c8f8..922054c1d544 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -542,6 +542,9 @@ static int negotiate_nvsp_ver(struct hv_device *device,
init_packet->msg.v2_msg.send_ndis_config.capability.teaming = 1;
}
 
+   if (nvsp_ver >= NVSP_PROTOCOL_VERSION_61)
+   init_packet->msg.v2_msg.send_ndis_config.capability.rsc = 1;
+
trace_nvsp_send(ndev, init_packet);
 
ret = vmbus_sendpacket(device->channel, init_packet,

[PATCH net-next, v2, 2/3] hv_netvsc: Add handler for LRO setting change

2018-09-21 Thread Haiyang Zhang
From: Haiyang Zhang 

This patch adds the handler for LRO setting change, so that a user
can use ethtool command to enable / disable LRO feature.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   |  4 
 drivers/net/hyperv/netvsc_drv.c   | 30 ++
 drivers/net/hyperv/rndis_filter.c | 11 ---
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 7f1603dc8128..ef6f766f6389 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -185,6 +185,7 @@ struct rndis_device {
 
 /* Interface */
 struct rndis_message;
+struct ndis_offload_params;
 struct netvsc_device;
 struct netvsc_channel;
 struct net_device_context;
@@ -218,6 +219,9 @@ void rndis_filter_device_remove(struct hv_device *dev,
struct netvsc_device *nvdev);
 int rndis_filter_set_rss_param(struct rndis_device *rdev,
   const u8 *key);
+int rndis_filter_set_offload_params(struct net_device *ndev,
+   struct netvsc_device *nvdev,
+   struct ndis_offload_params *req_offloads);
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
 struct netvsc_channel *nvchan,
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f8c18370d9d1..ec699741170b 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1006,6 +1006,8 @@ static void netvsc_init_settings(struct net_device *dev)
 
ndc->speed = SPEED_UNKNOWN;
ndc->duplex = DUPLEX_FULL;
+
+   dev->features = NETIF_F_LRO;
 }
 
 static int netvsc_get_link_ksettings(struct net_device *dev,
@@ -1733,6 +1735,33 @@ static int netvsc_set_ringparam(struct net_device *ndev,
return ret;
 }
 
+static int netvsc_set_features(struct net_device *ndev,
+  netdev_features_t features)
+{
+   netdev_features_t change = features ^ ndev->features;
+   struct net_device_context *ndevctx = netdev_priv(ndev);
+   struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
+   struct ndis_offload_params offloads;
+
+   if (!nvdev || nvdev->destroy)
+   return -ENODEV;
+
+   if (!(change & NETIF_F_LRO))
+   return 0;
+
+   memset(, 0, sizeof(struct ndis_offload_params));
+
+   if (features & NETIF_F_LRO) {
+   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   } else {
+   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   }
+
+   return rndis_filter_set_offload_params(ndev, nvdev, );
+}
+
 static u32 netvsc_get_msglevel(struct net_device *ndev)
 {
struct net_device_context *ndev_ctx = netdev_priv(ndev);
@@ -1776,6 +1805,7 @@ static const struct net_device_ops device_ops = {
.ndo_start_xmit =   netvsc_start_xmit,
.ndo_change_rx_flags =  netvsc_change_rx_flags,
.ndo_set_rx_mode =  netvsc_set_rx_mode,
+   .ndo_set_features = netvsc_set_features,
.ndo_change_mtu =   netvsc_change_mtu,
.ndo_validate_addr =eth_validate_addr,
.ndo_set_mac_address =  netvsc_set_mac_addr,
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index f3ac66386297..8b537a049c1e 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -716,7 +716,7 @@ int rndis_filter_set_device_mac(struct netvsc_device *nvdev,
return ret;
 }
 
-static int
+int
 rndis_filter_set_offload_params(struct net_device *ndev,
struct netvsc_device *nvdev,
struct ndis_offload_params *req_offloads)
@@ -1246,8 +1246,13 @@ static int rndis_netdev_set_hwcaps(struct rndis_device 
*rndis_device,
if (hwcaps.rsc.ip4 && hwcaps.rsc.ip6) {
net->hw_features |= NETIF_F_LRO;
 
-   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
-   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   if (net->features & NETIF_F_LRO) {
+   offloads.rsc_ip_v4 = 
NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   offloads.rsc_ip_v6 = 
NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   } else {
+   offloads.rsc_ip_v4 = 
NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   offloads.rsc_ip_v6 = 
NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   }
}
 
/* In case some hw_features disapp

[PATCH net-next,v2,0/3] hv_netvsc: Support LRO/RSC in the vSwitch

2018-09-21 Thread Haiyang Zhang
From: Haiyang Zhang 

The patch adds support for LRO/RSC in the vSwitch feature. It reduces
the per packet processing overhead by coalescing multiple TCP segments
when possible. The feature is enabled by default on VMs running on
Windows Server 2019 and later.

The patch set also adds ethtool command handler and documents.

Haiyang Zhang (3):
  hv_netvsc: Add support for LRO/RSC in the vSwitch
  hv_netvsc: Add handler for LRO setting change
  hv_netvsc: Update document for LRO/RSC support

 Documentation/networking/netvsc.txt |  9 +++
 drivers/net/hyperv/hyperv_net.h | 51 ---
 drivers/net/hyperv/netvsc.c | 18 --
 drivers/net/hyperv/netvsc_drv.c | 58 -
 drivers/net/hyperv/rndis_filter.c   | 97 +
 5 files changed, 194 insertions(+), 39 deletions(-)

-- 
2.18.0

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


RE: [PATCH net-next, 1/3] hv_netvsc: Add support for LRO/RSC in the vSwitch

2018-09-20 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Thursday, September 20, 2018 4:48 PM
> To: Haiyang Zhang 
> Cc: Haiyang Zhang ; da...@davemloft.net;
> net...@vger.kernel.org; o...@aepfle.de; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuznets 
> Subject: Re: [PATCH net-next, 1/3] hv_netvsc: Add support for LRO/RSC in the
> vSwitch
> 
> On Thu, 20 Sep 2018 17:06:59 +
> Haiyang Zhang  wrote:
> 
> > +static inline void rsc_add_data
> > +   (struct netvsc_channel *nvchan,
> > +const struct ndis_pkt_8021q_info *vlan,
> > +const struct ndis_tcp_ip_checksum_info *csum_info,
> > +void *data, u32 len)
> > +{
> 
> Could this be changed to look more like a function and skip the inline.
> The compiler will end up inlining it anyway.
> 
> static void rsc_add_data(struct netvsc_channel *nvchan,

How about this?
static inline
void rsc_add_data(struct netvsc_channel *nvchan,



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


[PATCH net-next,3/3] hv_netvsc: Update document for LRO/RSC support

2018-09-20 Thread Haiyang Zhang
From: Haiyang Zhang 

Update document for LRO/RSC support, and the command line info to
change the setting.

Signed-off-by: Haiyang Zhang 
---
 Documentation/networking/netvsc.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/networking/netvsc.txt 
b/Documentation/networking/netvsc.txt
index 92f5b31392fa..3bfa635bbbd5 100644
--- a/Documentation/networking/netvsc.txt
+++ b/Documentation/networking/netvsc.txt
@@ -45,6 +45,15 @@ Features
   like packets and significantly reduces CPU usage under heavy Rx
   load.
 
+  Large Receive Offload (LRO), or Receive Side Coalescing (RSC)
+  -
+  The driver supports LRO/RSC in the vSwitch feature. It reduces the per packet
+  processing overhead by coalescing multiple TCP segments when possible. The
+  feature is enabled by default on VMs running on Windows Server 2019 and
+  later. It may be changed by ethtool command:
+   ethtool -K eth0 lro on
+   ethtool -K eth0 lro off
+
   SR-IOV support
   --
   Hyper-V supports SR-IOV as a hardware acceleration option. If SR-IOV
-- 
2.18.0

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


[PATCH net-next, 1/3] hv_netvsc: Add support for LRO/RSC in the vSwitch

2018-09-20 Thread Haiyang Zhang
From: Haiyang Zhang 

LRO/RSC in the vSwitch is a feature available in Windows Server 2019
hosts and later. It reduces the per packet processing overhead by
coalescing multiple TCP segments when possible. This patch adds netvsc
driver support for this feature.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   | 47 +---
 drivers/net/hyperv/netvsc.c   | 18 +--
 drivers/net/hyperv/netvsc_drv.c   | 28 +-
 drivers/net/hyperv/rndis_filter.c | 90 ++-
 4 files changed, 145 insertions(+), 38 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index a32ded5b4f41..7f1603dc8128 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -186,6 +186,7 @@ struct rndis_device {
 /* Interface */
 struct rndis_message;
 struct netvsc_device;
+struct netvsc_channel;
 struct net_device_context;
 
 extern u32 netvsc_ring_bytes;
@@ -203,10 +204,7 @@ void netvsc_linkstatus_callback(struct net_device *net,
struct rndis_message *resp);
 int netvsc_recv_callback(struct net_device *net,
 struct netvsc_device *nvdev,
-struct vmbus_channel *channel,
-void  *data, u32 len,
-const struct ndis_tcp_ip_checksum_info *csum_info,
-const struct ndis_pkt_8021q_info *vlan);
+struct netvsc_channel *nvchan);
 void netvsc_channel_cb(void *context);
 int netvsc_poll(struct napi_struct *napi, int budget);
 
@@ -222,7 +220,7 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,
   const u8 *key);
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
-struct vmbus_channel *channel,
+struct netvsc_channel *nvchan,
 void *data, u32 buflen);
 
 int rndis_filter_set_device_mac(struct netvsc_device *ndev,
@@ -524,6 +522,8 @@ struct nvsp_2_vsc_capability {
u64 ieee8021q:1;
u64 correlation_id:1;
u64 teaming:1;
+   u64 vsubnetid:1;
+   u64 rsc:1;
};
};
 } __packed;
@@ -826,7 +826,7 @@ struct nvsp_message {
 
 #define NETVSC_SUPPORTED_HW_FEATURES (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | \
  NETIF_F_TSO | NETIF_F_IPV6_CSUM | \
- NETIF_F_TSO6)
+ NETIF_F_TSO6 | NETIF_F_LRO)
 
 #define VRSS_SEND_TAB_SIZE 16  /* must be power of 2 */
 #define VRSS_CHANNEL_MAX 64
@@ -852,6 +852,18 @@ struct multi_recv_comp {
u32 next;   /* next entry for writing */
 };
 
+#define NVSP_RSC_MAX 562 /* Max #RSC frags in a vmbus xfer page pkt */
+
+struct nvsc_rsc {
+   const struct ndis_pkt_8021q_info *vlan;
+   const struct ndis_tcp_ip_checksum_info *csum_info;
+   u8 is_last; /* last RNDIS msg in a vmtransfer_page */
+   u32 cnt; /* #fragments in an RSC packet */
+   u32 pktlen; /* Full packet length */
+   void *data[NVSP_RSC_MAX];
+   u32 len[NVSP_RSC_MAX];
+};
+
 struct netvsc_stats {
u64 packets;
u64 bytes;
@@ -955,6 +967,7 @@ struct netvsc_channel {
struct multi_send_data msd;
struct multi_recv_comp mrc;
atomic_t queue_sends;
+   struct nvsc_rsc rsc;
 
struct netvsc_stats tx_stats;
struct netvsc_stats rx_stats;
@@ -1136,7 +1149,8 @@ struct rndis_oobd {
 /* Packet extension field contents associated with a Data message. */
 struct rndis_per_packet_info {
u32 size;
-   u32 type;
+   u32 type:31;
+   u32 internal:1;
u32 ppi_offset;
 };
 
@@ -1157,6 +1171,25 @@ enum ndis_per_pkt_info_type {
MAX_PER_PKT_INFO
 };
 
+enum rndis_per_pkt_info_interal_type {
+   RNDIS_PKTINFO_ID = 1,
+   /* Add more memebers here */
+
+   RNDIS_PKTINFO_MAX
+};
+
+#define RNDIS_PKTINFO_SUBALLOC BIT(0)
+#define RNDIS_PKTINFO_1ST_FRAG BIT(1)
+#define RNDIS_PKTINFO_LAST_FRAG BIT(2)
+
+#define RNDIS_PKTINFO_ID_V1 1
+
+struct rndis_pktinfo_id {
+   u8 ver;
+   u8 flag;
+   u16 pkt_id;
+};
+
 struct ndis_pkt_8021q_info {
union {
struct {
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index fe01e141c8f8..922054c1d544 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -542,6 +542,9 @@ static int negotiate_nvsp_ver(struct hv_device *device,
init_packet->msg.v2_msg.send_ndis_config.capability.teaming = 1;
}
 
+   if (nvsp_ver >= NVSP_PROTOCOL_VERSION_61)
+   init_packet->msg.v2_msg.send_ndis_config.capability.rsc = 1;
+
trace_nvsp_send(ndev, init_packet);
 
ret = vmbus_sendpacket(device->channel, init_packet,

[PATCH net-next,2/3] hv_netvsc: Add handler for LRO setting change

2018-09-20 Thread Haiyang Zhang
From: Haiyang Zhang 

This patch adds the handler for LRO setting change, so that a user
can use ethtool command to enable / disable LRO feature.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   |  4 
 drivers/net/hyperv/netvsc_drv.c   | 30 ++
 drivers/net/hyperv/rndis_filter.c | 11 ---
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 7f1603dc8128..ef6f766f6389 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -185,6 +185,7 @@ struct rndis_device {
 
 /* Interface */
 struct rndis_message;
+struct ndis_offload_params;
 struct netvsc_device;
 struct netvsc_channel;
 struct net_device_context;
@@ -218,6 +219,9 @@ void rndis_filter_device_remove(struct hv_device *dev,
struct netvsc_device *nvdev);
 int rndis_filter_set_rss_param(struct rndis_device *rdev,
   const u8 *key);
+int rndis_filter_set_offload_params(struct net_device *ndev,
+   struct netvsc_device *nvdev,
+   struct ndis_offload_params *req_offloads);
 int rndis_filter_receive(struct net_device *ndev,
 struct netvsc_device *net_dev,
 struct netvsc_channel *nvchan,
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f8c18370d9d1..ec699741170b 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1006,6 +1006,8 @@ static void netvsc_init_settings(struct net_device *dev)
 
ndc->speed = SPEED_UNKNOWN;
ndc->duplex = DUPLEX_FULL;
+
+   dev->features = NETIF_F_LRO;
 }
 
 static int netvsc_get_link_ksettings(struct net_device *dev,
@@ -1733,6 +1735,33 @@ static int netvsc_set_ringparam(struct net_device *ndev,
return ret;
 }
 
+static int netvsc_set_features(struct net_device *ndev,
+  netdev_features_t features)
+{
+   netdev_features_t change = features ^ ndev->features;
+   struct net_device_context *ndevctx = netdev_priv(ndev);
+   struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
+   struct ndis_offload_params offloads;
+
+   if (!nvdev || nvdev->destroy)
+   return -ENODEV;
+
+   if (!(change & NETIF_F_LRO))
+   return 0;
+
+   memset(, 0, sizeof(struct ndis_offload_params));
+
+   if (features & NETIF_F_LRO) {
+   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   } else {
+   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   }
+
+   return rndis_filter_set_offload_params(ndev, nvdev, );
+}
+
 static u32 netvsc_get_msglevel(struct net_device *ndev)
 {
struct net_device_context *ndev_ctx = netdev_priv(ndev);
@@ -1776,6 +1805,7 @@ static const struct net_device_ops device_ops = {
.ndo_start_xmit =   netvsc_start_xmit,
.ndo_change_rx_flags =  netvsc_change_rx_flags,
.ndo_set_rx_mode =  netvsc_set_rx_mode,
+   .ndo_set_features = netvsc_set_features,
.ndo_change_mtu =   netvsc_change_mtu,
.ndo_validate_addr =eth_validate_addr,
.ndo_set_mac_address =  netvsc_set_mac_addr,
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 7bc8ade5c2bd..f94892edaa21 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -716,7 +716,7 @@ int rndis_filter_set_device_mac(struct netvsc_device *nvdev,
return ret;
 }
 
-static int
+int
 rndis_filter_set_offload_params(struct net_device *ndev,
struct netvsc_device *nvdev,
struct ndis_offload_params *req_offloads)
@@ -1246,8 +1246,13 @@ static int rndis_netdev_set_hwcaps(struct rndis_device 
*rndis_device,
if (hwcaps.rsc.ip4 && hwcaps.rsc.ip6) {
net->hw_features |= NETIF_F_LRO;
 
-   offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
-   offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   if (net->features & NETIF_F_LRO) {
+   offloads.rsc_ip_v4 = 
NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   offloads.rsc_ip_v6 = 
NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED;
+   } else {
+   offloads.rsc_ip_v4 = 
NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   offloads.rsc_ip_v6 = 
NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED;
+   }
}
 
/* In case some hw_features disapp

[PATCH net-next,0/3] hv_netvsc: Support LRO/RSC in the vSwitch

2018-09-20 Thread Haiyang Zhang
From: Haiyang Zhang 

The patch adds support for LRO/RSC in the vSwitch feature. It reduces
the per packet processing overhead by coalescing multiple TCP segments
when possible. The feature is enabled by default on VMs running on
Windows Server 2019 and later.

The patch set also adds ethtool command handler and documents.

Haiyang Zhang (3):
  hv_netvsc: Add support for LRO/RSC in the vSwitch
  hv_netvsc: Add handler for LRO setting change
  hv_netvsc: Update document for LRO/RSC support

 Documentation/networking/netvsc.txt |  9 +++
 drivers/net/hyperv/hyperv_net.h | 51 ---
 drivers/net/hyperv/netvsc.c | 18 --
 drivers/net/hyperv/netvsc_drv.c | 58 -
 drivers/net/hyperv/rndis_filter.c   | 97 +
 5 files changed, 194 insertions(+), 39 deletions(-)

-- 
2.18.0

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


RE: [PATCH net-next 17/22] hv_netvsc: fix return type of ndo_start_xmit function

2018-09-20 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Thursday, September 20, 2018 10:44 AM
> To: YueHaibing 
> Cc: da...@davemloft.net; dmitry.tarnya...@lockless.no;
> w...@grandegger.com; m...@pengutronix.de; michal.si...@xilinx.com;
> hswee...@visionengravers.com; madalin.bu...@nxp.com;
> pantelis.anton...@gmail.com; claudiu.man...@nxp.com; leoyang...@nxp.com;
> li...@armlinux.org.uk; sa...@sammy.net; r...@linux-mips.org;
> n...@fluxnic.net; steve.glendinn...@shawell.net; f.faine...@gmail.com;
> grygorii.stras...@ti.com; w-kw...@ti.com; m-kariche...@ti.com;
> t.sai...@alumni.ethz.ch; jreu...@yaina.de; KY Srinivasan ;
> Haiyang Zhang ; wei.l...@citrix.com;
> paul.durr...@citrix.com; arvid.bro...@alten.se; pshe...@ovn.org;
> d...@openvswitch.org; linux-m...@linux-mips.org; xen-
> de...@lists.xenproject.org; net...@vger.kernel.org; linux-...@vger.kernel.org;
> linux-ker...@vger.kernel.org; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; linux-h...@vger.kernel.org; linux-
> o...@vger.kernel.org; linuxppc-...@lists.ozlabs.org; linux-arm-
> ker...@lists.infradead.org
> Subject: Re: [PATCH net-next 17/22] hv_netvsc: fix return type of
> ndo_start_xmit function
> 
> On Thu, 20 Sep 2018 20:33:01 +0800
> YueHaibing  wrote:
> > int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
> >  */
> > vf_netdev = rcu_dereference_bh(net_device_ctx->vf_netdev);
> > if (vf_netdev && netif_running(vf_netdev) &&
> > -   !netpoll_tx_running(net))
> > -   return netvsc_vf_xmit(net, vf_netdev, skb);
> > +   !netpoll_tx_running(net)) {
> > +   ret = netvsc_vf_xmit(net, vf_netdev, skb);
> > +   if (ret)
> > +   return NETDEV_TX_BUSY;
> > +   }
> 
> Sorry, the new code is wrong. It will fall through if ret == 0 (NETDEV_TX_OK)
> Please review and test your patches.

Plus consideration of -- For error case, please just return NETDEV_TX_OK. We 
are not sure if the error can go away after retrying, returning NETDEV_TX_BUSY 
may cause infinite retry from the upper layer.

So, let's just always return NETDEV_TX_OK like this:
netvsc_vf_xmit(net, vf_netdev, skb);
return NETDEV_TX_OK;

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


RE: [PATCH net-next 17/22] hv_netvsc: fix return type of ndo_start_xmit function

2018-09-20 Thread Haiyang Zhang



> -Original Message-
> From: YueHaibing 
> Sent: Thursday, September 20, 2018 8:33 AM
> To: da...@davemloft.net; dmitry.tarnya...@lockless.no;
> w...@grandegger.com; m...@pengutronix.de; michal.si...@xilinx.com;
> hswee...@visionengravers.com; madalin.bu...@nxp.com;
> pantelis.anton...@gmail.com; claudiu.man...@nxp.com; leoyang...@nxp.com;
> li...@armlinux.org.uk; sa...@sammy.net; r...@linux-mips.org;
> n...@fluxnic.net; steve.glendinn...@shawell.net; f.faine...@gmail.com;
> grygorii.stras...@ti.com; w-kw...@ti.com; m-kariche...@ti.com;
> t.sai...@alumni.ethz.ch; jreu...@yaina.de; KY Srinivasan ;
> Haiyang Zhang ; wei.l...@citrix.com;
> paul.durr...@citrix.com; arvid.bro...@alten.se; pshe...@ovn.org
> Cc: linux-ker...@vger.kernel.org; net...@vger.kernel.org; linux-
> c...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; linuxppc-
> d...@lists.ozlabs.org; linux-m...@linux-mips.org; linux-o...@vger.kernel.org;
> linux-h...@vger.kernel.org; de...@linuxdriverproject.org; linux-
> u...@vger.kernel.org; xen-de...@lists.xenproject.org; d...@openvswitch.org;
> YueHaibing 
> Subject: [PATCH net-next 17/22] hv_netvsc: fix return type of ndo_start_xmit
> function
> 
> The method ndo_start_xmit() is defined as returning an 'netdev_tx_t', which is
> a typedef for an enum type, so make sure the implementation in this driver has
> returns 'netdev_tx_t' value, and change the function return type to 
> netdev_tx_t.
> 
> Found by coccinelle.
> 
> Signed-off-by: YueHaibing 
> ---
>  drivers/net/hyperv/netvsc_drv.c | 10 +++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 3af6d8d..056c472 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -511,7 +511,8 @@ static int netvsc_vf_xmit(struct net_device *net, struct
> net_device *vf_netdev,
>   return rc;
>  }
> 
> -static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
> +static netdev_tx_t
> +netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
>  {
>   struct net_device_context *net_device_ctx = netdev_priv(net);
>   struct hv_netvsc_packet *packet = NULL; @@ -528,8 +529,11 @@
> static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
>*/
>   vf_netdev = rcu_dereference_bh(net_device_ctx->vf_netdev);
>   if (vf_netdev && netif_running(vf_netdev) &&
> - !netpoll_tx_running(net))
> - return netvsc_vf_xmit(net, vf_netdev, skb);
> + !netpoll_tx_running(net)) {
> + ret = netvsc_vf_xmit(net, vf_netdev, skb);
> + if (ret)
> + return NETDEV_TX_BUSY;

For error case, please just return NETDEV_TX_OK. We are not sure if the 
error can go away after retrying, returning NETDEV_TX_BUSY may cause 
infinite retry from the upper layer.

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


[PATCH net, v2] hv_netvsc: Fix napi reschedule while receive completion is busy

2018-07-17 Thread Haiyang Zhang
From: Haiyang Zhang 

If out ring is full temporarily and receive completion cannot go out,
we may still need to reschedule napi if certain conditions are met.
Otherwise the napi poll might be stopped forever, and cause network
disconnect.

Fixes: 7426b1a51803 ("netvsc: optimize receive completions")
Signed-off-by: Stephen Hemminger 
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 8e9d0ee1572b..31c3d77b4733 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -1274,6 +1274,7 @@ int netvsc_poll(struct napi_struct *napi, int budget)
struct hv_device *device = netvsc_channel_to_device(channel);
struct net_device *ndev = hv_get_drvdata(device);
int work_done = 0;
+   int ret;
 
/* If starting a new interval */
if (!nvchan->desc)
@@ -1285,16 +1286,18 @@ int netvsc_poll(struct napi_struct *napi, int budget)
nvchan->desc = hv_pkt_iter_next(channel, nvchan->desc);
}
 
-   /* If send of pending receive completions suceeded
-*   and did not exhaust NAPI budget this time
-*   and not doing busy poll
+   /* Send any pending receive completions */
+   ret = send_recv_completions(ndev, net_device, nvchan);
+
+   /* If it did not exhaust NAPI budget this time
+*  and not doing busy poll
 * then re-enable host interrupts
-* and reschedule if ring is not empty.
+*  and reschedule if ring is not empty
+*   or sending receive completion failed.
 */
-   if (send_recv_completions(ndev, net_device, nvchan) == 0 &&
-   work_done < budget &&
+   if (work_done < budget &&
napi_complete_done(napi, work_done) &&
-   hv_end_read(>inbound) &&
+   (ret || hv_end_read(>inbound)) &&
napi_schedule_prep(napi)) {
hv_begin_read(>inbound);
__napi_schedule(napi);
-- 
2.17.1

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


RE: [PATCH net] hv_netvsc: Fix napi reschedule while receive completion is busy

2018-07-09 Thread Haiyang Zhang



> -Original Message-
> From: Stephen Hemminger 
> Sent: Monday, July 9, 2018 2:15 PM
> To: Haiyang Zhang 
> Cc: Haiyang Zhang ; da...@davemloft.net;
> net...@vger.kernel.org; o...@aepfle.de; Stephen Hemminger
> ; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuzn...@redhat.com
> Subject: Re: [PATCH net] hv_netvsc: Fix napi reschedule while receive
> completion is busy
> 
> On Mon,  9 Jul 2018 16:43:19 +
> Haiyang Zhang  wrote:
> 
> > From: Haiyang Zhang 
> >
> > If out ring is full temporarily and receive completion cannot go out,
> > we may still need to reschedule napi if other conditions are met.
> > Otherwise the napi poll might be stopped forever, and cause network
> > disconnect.
> >
> > Fixes: 7426b1a51803 ("netvsc: optimize receive completions")
> > Signed-off-by: Haiyang Zhang 
> > ---
> >  drivers/net/hyperv/netvsc.c | 8 
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> > index 8e9d0ee1572b..caaf5054f446 100644
> > --- a/drivers/net/hyperv/netvsc.c
> > +++ b/drivers/net/hyperv/netvsc.c
> > @@ -1285,14 +1285,14 @@ int netvsc_poll(struct napi_struct *napi, int
> budget)
> > nvchan->desc = hv_pkt_iter_next(channel, nvchan->desc);
> > }
> >
> > -   /* If send of pending receive completions suceeded
> > -*   and did not exhaust NAPI budget this time
> > +   send_recv_completions(ndev, net_device, nvchan);
> > +
> > +   /* If it did not exhaust NAPI budget this time
> >  *   and not doing busy poll
> >  * then re-enable host interrupts
> >  * and reschedule if ring is not empty.
> >  */
> > -   if (send_recv_completions(ndev, net_device, nvchan) == 0 &&
> > -   work_done < budget &&
> > +   if (work_done < budget &&
> > napi_complete_done(napi, work_done) &&
> > hv_end_read(>inbound) &&
> > napi_schedule_prep(napi)) {
> 
> This patch doesn't look right. I think the existing code works as written.
> 
> If send_receive_completions is unable to send because ring is full then
> vmbus_sendpacket will return -EBUSY which gets returns from
> send_receive_completions.  Because the return is non-zero, the driver will not
> call napi_complete_done.
> Since napi_complete_done was not called, NAPI will reschedule the napi poll
> routine.

With the existing code, we found in test, the rx_comp_busy counter increased,
one of the in-ring mask is 1, but guest is not reading it... With this patch, 
the 
pending receive completion will stay in the buffer (no loss), and be sent next 
time. 
It solves the disconnection problem when high number of connections.

If not calling napi_complete_done(), upper layer should guarantee napi_schedule,
then seems the upper NAPI code may have a bug -- the auto scheduling did not
happen in this case. I will check it further.

Thanks,
- Haiyang

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


[PATCH net] hv_netvsc: Fix napi reschedule while receive completion is busy

2018-07-09 Thread Haiyang Zhang
From: Haiyang Zhang 

If out ring is full temporarily and receive completion cannot go out,
we may still need to reschedule napi if other conditions are met.
Otherwise the napi poll might be stopped forever, and cause network
disconnect.

Fixes: 7426b1a51803 ("netvsc: optimize receive completions")
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/netvsc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 8e9d0ee1572b..caaf5054f446 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -1285,14 +1285,14 @@ int netvsc_poll(struct napi_struct *napi, int budget)
nvchan->desc = hv_pkt_iter_next(channel, nvchan->desc);
}
 
-   /* If send of pending receive completions suceeded
-*   and did not exhaust NAPI budget this time
+   send_recv_completions(ndev, net_device, nvchan);
+
+   /* If it did not exhaust NAPI budget this time
 *   and not doing busy poll
 * then re-enable host interrupts
 * and reschedule if ring is not empty.
 */
-   if (send_recv_completions(ndev, net_device, nvchan) == 0 &&
-   work_done < budget &&
+   if (work_done < budget &&
napi_complete_done(napi, work_done) &&
hv_end_read(>inbound) &&
napi_schedule_prep(napi)) {
-- 
2.17.1

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


[PATCH net] hv_netvsc: split sub-channel setup into async and sync

2018-06-29 Thread Haiyang Zhang
From: Stephen Hemminger 

When doing device hotplug the sub channel must be async to avoid
deadlock issues because device is discovered in softirq context.

When doing changes to MTU and number of channels, the setup
must be synchronous to avoid races such as when MTU and device
settings are done in a single ip command.

Reported-by: Thomas Walker 
Fixes: 8195b1396ec8 ("hv_netvsc: fix deadlock on hotplug")
Fixes: 732e49850c5e ("netvsc: fix race on sub channel creation")
Signed-off-by: Stephen Hemminger 
Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h   |  2 +-
 drivers/net/hyperv/netvsc.c   | 37 ++-
 drivers/net/hyperv/netvsc_drv.c   | 17 -
 drivers/net/hyperv/rndis_filter.c | 61 ++-
 4 files changed, 65 insertions(+), 52 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 1a924b867b07..4b6e308199d2 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -210,7 +210,7 @@ int netvsc_recv_callback(struct net_device *net,
 void netvsc_channel_cb(void *context);
 int netvsc_poll(struct napi_struct *napi, int budget);
 
-void rndis_set_subchannel(struct work_struct *w);
+int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev);
 int rndis_filter_open(struct netvsc_device *nvdev);
 int rndis_filter_close(struct netvsc_device *nvdev);
 struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 5d5bd513847f..8e9d0ee1572b 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -65,6 +65,41 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf)
   VM_PKT_DATA_INBAND, 0);
 }
 
+/* Worker to setup sub channels on initial setup
+ * Initial hotplug event occurs in softirq context
+ * and can't wait for channels.
+ */
+static void netvsc_subchan_work(struct work_struct *w)
+{
+   struct netvsc_device *nvdev =
+   container_of(w, struct netvsc_device, subchan_work);
+   struct rndis_device *rdev;
+   int i, ret;
+
+   /* Avoid deadlock with device removal already under RTNL */
+   if (!rtnl_trylock()) {
+   schedule_work(w);
+   return;
+   }
+
+   rdev = nvdev->extension;
+   if (rdev) {
+   ret = rndis_set_subchannel(rdev->ndev, nvdev);
+   if (ret == 0) {
+   netif_device_attach(rdev->ndev);
+   } else {
+   /* fallback to only primary channel */
+   for (i = 1; i < nvdev->num_chn; i++)
+   netif_napi_del(>chan_table[i].napi);
+
+   nvdev->max_chn = 1;
+   nvdev->num_chn = 1;
+   }
+   }
+
+   rtnl_unlock();
+}
+
 static struct netvsc_device *alloc_net_device(void)
 {
struct netvsc_device *net_device;
@@ -81,7 +116,7 @@ static struct netvsc_device *alloc_net_device(void)
 
init_completion(_device->channel_init_wait);
init_waitqueue_head(_device->subchan_open);
-   INIT_WORK(_device->subchan_work, rndis_set_subchannel);
+   INIT_WORK(_device->subchan_work, netvsc_subchan_work);
 
return net_device;
 }
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index fe2256bf1d13..dd1d6e115145 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -905,8 +905,20 @@ static int netvsc_attach(struct net_device *ndev,
if (IS_ERR(nvdev))
return PTR_ERR(nvdev);
 
-   /* Note: enable and attach happen when sub-channels setup */
+   if (nvdev->num_chn > 1) {
+   ret = rndis_set_subchannel(ndev, nvdev);
+
+   /* if unavailable, just proceed with one queue */
+   if (ret) {
+   nvdev->max_chn = 1;
+   nvdev->num_chn = 1;
+   }
+   }
+
+   /* In any case device is now ready */
+   netif_device_attach(ndev);
 
+   /* Note: enable and attach happen when sub-channels setup */
netif_carrier_off(ndev);
 
if (netif_running(ndev)) {
@@ -2089,6 +2101,9 @@ static int netvsc_probe(struct hv_device *dev,
 
memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
 
+   if (nvdev->num_chn > 1)
+   schedule_work(>subchan_work);
+
/* hw_features computed in rndis_netdev_set_hwcaps() */
net->features = net->hw_features |
NETIF_F_HIGHDMA | NETIF_F_SG |
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 5428bb261102..9b4e3c3787e5 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1062,29 +1062,15 @@ static void netvsc_sc_ope

RE: [PATCH net-next] hv_netvsc: Fix the variable sizes in ipsecv2 and rsc offload

2018-06-14 Thread Haiyang Zhang



> -Original Message-
> From: David Miller 
> Sent: Thursday, June 14, 2018 8:00 PM
> To: Haiyang Zhang ; haiya...@linuxonhyperv.com
> Cc: net...@vger.kernel.org; KY Srinivasan ; Stephen
> Hemminger ; o...@aepfle.de;
> vkuzn...@redhat.com; de...@linuxdriverproject.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH net-next] hv_netvsc: Fix the variable sizes in ipsecv2 and
> rsc offload
> 
> 
> Bug fixes should be targetted at net, not net-next.  Furthermore, net-next is
> closed.

Thanks for the reminder. I just sent out the patch to "net" tree.

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


[PATCH net] hv_netvsc: Fix the variable sizes in ipsecv2 and rsc offload

2018-06-14 Thread Haiyang Zhang
From: Haiyang Zhang 

These fields in struct ndis_ipsecv2_offload and struct ndis_rsc_offload
are one byte according to the specs. This patch defines them with the
right size. These structs are not in use right now, but will be used soon.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index d31c0cd329a1..1a924b867b07 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -1277,17 +1277,17 @@ struct ndis_lsov2_offload {
 
 struct ndis_ipsecv2_offload {
u32 encap;
-   u16 ip6;
-   u16 ip4opt;
-   u16 ip6ext;
-   u16 ah;
-   u16 esp;
-   u16 ah_esp;
-   u16 xport;
-   u16 tun;
-   u16 xport_tun;
-   u16 lso;
-   u16 extseq;
+   u8  ip6;
+   u8  ip4opt;
+   u8  ip6ext;
+   u8  ah;
+   u8  esp;
+   u8  ah_esp;
+   u8  xport;
+   u8  tun;
+   u8  xport_tun;
+   u8  lso;
+   u8  extseq;
u32 udp_esp;
u32 auth;
u32 crypto;
@@ -1295,8 +1295,8 @@ struct ndis_ipsecv2_offload {
 };
 
 struct ndis_rsc_offload {
-   u16 ip4;
-   u16 ip6;
+   u8  ip4;
+   u8  ip6;
 };
 
 struct ndis_encap_offload {
-- 
2.17.1

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


[PATCH net-next] hv_netvsc: Fix the variable sizes in ipsecv2 and rsc offload

2018-06-14 Thread Haiyang Zhang
From: Haiyang Zhang 

These fields in struct ndis_ipsecv2_offload and struct ndis_rsc_offload
are one byte according to the specs. This patch defines them with the
right size.

Signed-off-by: Haiyang Zhang 
---
 drivers/net/hyperv/hyperv_net.h | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 23304aca25f9..84eaaa6368a2 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -1277,17 +1277,17 @@ struct ndis_lsov2_offload {
 
 struct ndis_ipsecv2_offload {
u32 encap;
-   u16 ip6;
-   u16 ip4opt;
-   u16 ip6ext;
-   u16 ah;
-   u16 esp;
-   u16 ah_esp;
-   u16 xport;
-   u16 tun;
-   u16 xport_tun;
-   u16 lso;
-   u16 extseq;
+   u8  ip6;
+   u8  ip4opt;
+   u8  ip6ext;
+   u8  ah;
+   u8  esp;
+   u8  ah_esp;
+   u8  xport;
+   u8  tun;
+   u8  xport_tun;
+   u8  lso;
+   u8  extseq;
u32 udp_esp;
u32 auth;
u32 crypto;
@@ -1295,8 +1295,8 @@ struct ndis_ipsecv2_offload {
 };
 
 struct ndis_rsc_offload {
-   u16 ip4;
-   u16 ip6;
+   u8  ip4;
+   u8  ip6;
 };
 
 struct ndis_encap_offload {
-- 
2.17.1

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


RE: [PATCH] PCI: hv: Fix a __local_bh_enable_ip warning in hv_compose_msi_msg()

2018-05-25 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, May 22, 2018 8:18 PM
> To: Lorenzo Pieralisi <lorenzo.pieral...@arm.com>; Bjorn Helgaas
> <bhelg...@google.com>; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com
> Subject: [PATCH] PCI: hv: Fix a __local_bh_enable_ip warning in
> hv_compose_msi_msg()
> 
> 
> Commit de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()")
> uses local_bh_disable()/enable(), because hv_pci_onchannelcallback() can also
> run in tasklet context as the channel event callback.
> 
> With CONFIG_PROVE_LOCKING=y in the latest mainline, or old kernels that
> don't have commit f71b74bca637 ("irq/softirqs: Use lockdep to assert IRQs are
> disabled/enabled"), it turns out can we trigger a warning at the beginning of
> __local_bh_enable_ip(), because the upper layer irq code can call
> hv_compose_msi_msg() with local irqs disabled.
> 
> Let's fix the warning by switching to local_irq_save()/restore(). This is not 
> an
> issue because hv_pci_onchannelcallback() is not slow, and it not a hot path.
> 
> Fixes: de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()")
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: <sta...@vger.kernel.org>
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> ---

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

Thanks you.

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


RE: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared

2018-05-25 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Wednesday, May 23, 2018 5:12 PM
> To: 'Lorenzo Pieralisi' <lorenzo.pieral...@arm.com>; 'Bjorn Helgaas'
> <bhelg...@google.com>; 'linux-...@vger.kernel.org'  p...@vger.kernel.org>; KY Srinivasan <k...@microsoft.com>; Stephen
> Hemminger <sthem...@microsoft.com>; 'o...@aepfle.de' <o...@aepfle.de>;
> 'a...@canonical.com' <a...@canonical.com>; 'jasow...@redhat.com'
> <jasow...@redhat.com>
> Cc: 'linux-ker...@vger.kernel.org' <linux-ker...@vger.kernel.org>; 'driverdev-
> de...@linuxdriverproject.org' <driverdev-devel@linuxdriverproject.org>;
> Haiyang Zhang <haiya...@microsoft.com>; 'vkuzn...@redhat.com'
> <vkuzn...@redhat.com>; 'marcelo.ce...@canonical.com'
> <marcelo.ce...@canonical.com>
> Subject: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared
> 
> 
> Before the guest finishes the device initialization, the device can be removed
> anytime by the host, and after that the host won't respond to the guest's
> request, so the guest should be prepared to handle this case.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> ---
>  drivers/pci/host/pci-hyperv.c | 46 ---
> 

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

Thank you!

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


[PATCH net-next] hv_netvsc: Add handlers for ethtool get/set msg level

2018-05-22 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

The handlers for ethtool get/set msg level are missing from netvsc.
This patch adds them.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index da07ccdf84bf..60a5769ef5a1 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1618,8 +1618,24 @@ static int netvsc_set_ringparam(struct net_device *ndev,
return ret;
 }
 
+static u32 netvsc_get_msglevel(struct net_device *ndev)
+{
+   struct net_device_context *ndev_ctx = netdev_priv(ndev);
+
+   return ndev_ctx->msg_enable;
+}
+
+static void netvsc_set_msglevel(struct net_device *ndev, u32 val)
+{
+   struct net_device_context *ndev_ctx = netdev_priv(ndev);
+
+   ndev_ctx->msg_enable = val;
+}
+
 static const struct ethtool_ops ethtool_ops = {
.get_drvinfo= netvsc_get_drvinfo,
+   .get_msglevel   = netvsc_get_msglevel,
+   .set_msglevel   = netvsc_set_msglevel,
.get_link   = ethtool_op_get_link,
.get_ethtool_stats = netvsc_get_ethtool_stats,
.get_sset_count = netvsc_get_sset_count,
-- 
2.17.0

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


[PATCH net-next] hv_netvsc: Add NetVSP v6 and v6.1 into version negotiation

2018-04-17 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

This patch adds the NetVSP v6 and 6.1 message structures, and includes
these versions into NetVSC/NetVSP version negotiation process.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h | 164 
 drivers/net/hyperv/netvsc.c |   3 +-
 2 files changed, 166 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 960f06141472..6ebe39a3dde6 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -237,6 +237,8 @@ void netvsc_switch_datapath(struct net_device *nv_dev, bool 
vf);
 #define NVSP_PROTOCOL_VERSION_20x30002
 #define NVSP_PROTOCOL_VERSION_40x4
 #define NVSP_PROTOCOL_VERSION_50x5
+#define NVSP_PROTOCOL_VERSION_60x6
+#define NVSP_PROTOCOL_VERSION_61   0x60001
 
 enum {
NVSP_MSG_TYPE_NONE = 0,
@@ -308,6 +310,12 @@ enum {
NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
 
NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
+
+   /* Version 6 messages */
+   NVSP_MSG6_TYPE_PD_API,
+   NVSP_MSG6_TYPE_PD_POST_BATCH,
+
+   NVSP_MSG6_MAX = NVSP_MSG6_TYPE_PD_POST_BATCH
 };
 
 enum {
@@ -619,12 +627,168 @@ union nvsp_5_message_uber {
struct nvsp_5_send_indirect_table send_table;
 } __packed;
 
+enum nvsp_6_pd_api_op {
+   PD_API_OP_CONFIG = 1,
+   PD_API_OP_SW_DATAPATH, /* Switch Datapath */
+   PD_API_OP_OPEN_PROVIDER,
+   PD_API_OP_CLOSE_PROVIDER,
+   PD_API_OP_CREATE_QUEUE,
+   PD_API_OP_FLUSH_QUEUE,
+   PD_API_OP_FREE_QUEUE,
+   PD_API_OP_ALLOC_COM_BUF, /* Allocate Common Buffer */
+   PD_API_OP_FREE_COM_BUF, /* Free Common Buffer */
+   PD_API_OP_MAX
+};
+
+struct grp_affinity {
+   u64 mask;
+   u16 grp;
+   u16 reserved[3];
+} __packed;
+
+struct nvsp_6_pd_api_req {
+   u32 op;
+
+   union {
+   /* MMIO information is sent from the VM to VSP */
+   struct __packed {
+   u64 mmio_pa; /* MMIO Physical Address */
+   u32 mmio_len;
+
+   /* Number of PD queues a VM can support */
+   u16 num_subchn;
+   } config;
+
+   /* Switch Datapath */
+   struct __packed {
+   /* Host Datapath Is PacketDirect */
+   u8 host_dpath_is_pd;
+
+   /* Guest PacketDirect Is Enabled */
+   u8 guest_pd_enabled;
+   } sw_dpath;
+
+   /* Open Provider*/
+   struct __packed {
+   u32 prov_id; /* Provider id */
+   u32 flag;
+   } open_prov;
+
+   /* Close Provider */
+   struct __packed {
+   u32 prov_id;
+   } cls_prov;
+
+   /* Create Queue*/
+   struct __packed {
+   u32 prov_id;
+   u16 q_id;
+   u16 q_size;
+   u8 is_recv_q;
+   u8 is_rss_q;
+   u32 recv_data_len;
+   struct grp_affinity affy;
+   } cr_q;
+
+   /* Delete Queue*/
+   struct __packed {
+   u32 prov_id;
+   u16 q_id;
+   } del_q;
+
+   /* Flush Queue */
+   struct __packed {
+   u32 prov_id;
+   u16 q_id;
+   } flush_q;
+
+   /* Allocate Common Buffer */
+   struct __packed {
+   u32 len;
+   u32 pf_node; /* Preferred Node */
+   u16 region_id;
+   } alloc_com_buf;
+
+   /* Free Common Buffer */
+   struct __packed {
+   u32 len;
+   u64 pa; /* Physical Address */
+   u32 pf_node; /* Preferred Node */
+   u16 region_id;
+   u8 cache_type;
+   } free_com_buf;
+   } __packed;
+} __packed;
+
+struct nvsp_6_pd_api_comp {
+   u32 op;
+   u32 status;
+
+   union {
+   struct __packed {
+   /* actual number of PD queues allocated to the VM */
+   u16 num_pd_q;
+
+   /* Num Receive Rss PD Queues */
+   u8 num_rss_q;
+
+   u8 is_supported; /* Is supported by VSP */
+   u8 is_enabled; /* Is enabled by VSP */
+   } config;
+
+   /* Open Provider */
+   struct __packed {
+   u32 prov_id;
+   } open_prov;
+
+   /* Create Queue */
+ 

RE: [PATCH v7] Revert "PCI: hv: Use device serial number as PCI domain"

2018-04-12 Thread Haiyang Zhang


> -Original Message-
> From: Sridhar Pitchai
> Sent: Thursday, April 12, 2018 11:14 AM
> To: Bjorn Helgaas <helg...@kernel.org>; Lorenzo Pieralisi
> <lorenzo.pieral...@arm.com>
> Cc: Haiyang Zhang <haiya...@microsoft.com>; Dexuan Cui
> <de...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> Jake Oshins <ja...@microsoft.com>; KY Srinivasan <k...@microsoft.com>;
> Michael Kelley (EOSG) <michael.h.kel...@microsoft.com>;
> de...@linuxdriverproject.org; linux-...@vger.kernel.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH v7] Revert "PCI: hv: Use device serial number as PCI
> domain"
> 
> >> I am still not happy with this patch.
> >>
> >> -  You do not explain at all the dependency on commit 0c195567a8f6 and
> >>you should because that's fundamental, if that patch is not present
> >>this revert breaks the kernel as per previous discussions[1].
> >> -  You are sending this patch to all stable kernels that contain the
> >>commit you are fixing - some that may not contain the commit above
> >>(that was merged in v4.14), you are breaking those kernels, if not
> >>explain me why please
> 
> >If there's a dependency on 0c195567a8f6, I totally agree that
> >needs to be cleared up.  I was assuming that turned out to be
> >irrelevant.
> That is right. There is no dependency on 0c195567a8f6. We just need to revert
> 4a9b0933bdfc.

This patch should only be applied to later versions after  0c195567a8f6" 
(transparent VF). Otherwise it causes long & random names of VF NICs for 
bonding. That will make bonding config difficult, especially for auto config.

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


[PATCH net-next] hv_netvsc: Add NetVSP v6 into version negotiation

2018-04-05 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

This patch adds the NetVSP v6 message structures, and includes this
version into NetVSC/NetVSP version negotiation process.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h | 33 +
 drivers/net/hyperv/netvsc.c |  3 ++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 960f06141472..036cd55c66fe 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -237,6 +237,7 @@ void netvsc_switch_datapath(struct net_device *nv_dev, bool 
vf);
 #define NVSP_PROTOCOL_VERSION_20x30002
 #define NVSP_PROTOCOL_VERSION_40x4
 #define NVSP_PROTOCOL_VERSION_50x5
+#define NVSP_PROTOCOL_VERSION_60x6
 
 enum {
NVSP_MSG_TYPE_NONE = 0,
@@ -308,6 +309,11 @@ enum {
NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
 
NVSP_MSG5_MAX = NVSP_MSG5_TYPE_SEND_INDIRECTION_TABLE,
+
+   /* Version 6 messages */
+   NVSP_MSG6_TYPE_PD_API,
+
+   NVSP_MSG6_MAX = NVSP_MSG6_TYPE_PD_API
 };
 
 enum {
@@ -619,12 +625,39 @@ union nvsp_5_message_uber {
struct nvsp_5_send_indirect_table send_table;
 } __packed;
 
+enum nvsp6_pd_api_op {
+   PD_API_OP_NOTIFY_VSP = 0,
+   PD_API_OP_CONFIG,
+   PD_API_OP_MAX
+};
+
+struct nvsp_6_pd_api_req {
+   u32 op;
+   u64 mmio_pa; /* MMIO Physical Address */
+   u32 mmio_len;
+   u32 num_subchn; /* Number of PD subchannels */
+} __packed;
+
+struct nvsp_6_pd_api_comp {
+   u32 op;
+   u32 status;
+   u32 num_subchn; /* Number of PD subchannels */
+   u8 is_supported; /* Is supported by VSP */
+   u8 is_enabled; /* Is enabled by VSP */
+} __packed;
+
+union nvsp_6_message_uber {
+   struct nvsp_6_pd_api_req pd_req;
+   struct nvsp_6_pd_api_comp pd_comp;
+} __packed;
+
 union nvsp_all_messages {
union nvsp_message_init_uber init_msg;
union nvsp_1_message_uber v1_msg;
union nvsp_2_message_uber v2_msg;
union nvsp_4_message_uber v4_msg;
union nvsp_5_message_uber v5_msg;
+   union nvsp_6_message_uber v6_msg;
 } __packed;
 
 /* ALL Messages */
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index c9910c33e671..3abe57bd85bb 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -509,7 +509,8 @@ static int netvsc_connect_vsp(struct hv_device *device,
struct net_device *ndev = hv_get_drvdata(device);
static const u32 ver_list[] = {
NVSP_PROTOCOL_VERSION_1, NVSP_PROTOCOL_VERSION_2,
-   NVSP_PROTOCOL_VERSION_4, NVSP_PROTOCOL_VERSION_5
+   NVSP_PROTOCOL_VERSION_4, NVSP_PROTOCOL_VERSION_5,
+   NVSP_PROTOCOL_VERSION_6
};
struct nvsp_message *init_packet;
int ndis_version, i, ret;
-- 
2.15.1

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


[PATCH net-next] hv_netvsc: Clean up extra parameter from rndis_filter_receive_data()

2018-03-30 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

The variables, msg and data, have the same value. This patch removes
the extra one.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/rndis_filter.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 4a4952363e8a..e2b68d9328a7 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -365,14 +365,15 @@ static inline void *rndis_get_ppi(struct rndis_packet 
*rpkt, u32 type)
 
 static int rndis_filter_receive_data(struct net_device *ndev,
 struct netvsc_device *nvdev,
-struct rndis_message *msg,
 struct vmbus_channel *channel,
-void *data, u32 data_buflen)
+struct rndis_message *msg,
+u32 data_buflen)
 {
struct rndis_packet *rndis_pkt = >msg.pkt;
const struct ndis_tcp_ip_checksum_info *csum_info;
const struct ndis_pkt_8021q_info *vlan;
u32 data_offset;
+   void *data;
 
/* Remove the rndis header and pass it back up the stack */
data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
@@ -393,14 +394,15 @@ static int rndis_filter_receive_data(struct net_device 
*ndev,
 
vlan = rndis_get_ppi(rndis_pkt, IEEE_8021Q_INFO);
 
+   csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO);
+
+   data = (void *)msg + data_offset;
+
/*
 * Remove the rndis trailer padding from rndis packet message
 * rndis_pkt->data_len tell us the real data length, we only copy
 * the data packet to the stack, without the rndis trailer padding
 */
-   data = (void *)((unsigned long)data + data_offset);
-   csum_info = rndis_get_ppi(rndis_pkt, TCPIP_CHKSUM_PKTINFO);
-
return netvsc_recv_callback(ndev, nvdev, channel,
data, rndis_pkt->data_len,
csum_info, vlan);
@@ -419,8 +421,8 @@ int rndis_filter_receive(struct net_device *ndev,
 
switch (rndis_msg->ndis_msg_type) {
case RNDIS_MSG_PACKET:
-   return rndis_filter_receive_data(ndev, net_dev, rndis_msg,
-channel, data, buflen);
+   return rndis_filter_receive_data(ndev, net_dev, channel,
+rndis_msg, buflen);
case RNDIS_MSG_INIT_C:
case RNDIS_MSG_QUERY_C:
case RNDIS_MSG_SET_C:
-- 
2.15.1

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


RE: [PATCH net-next, 2/2] hv_netvsc: Add range checking for rx packet offset and length

2018-03-27 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger <step...@networkplumber.org>
> Sent: Tuesday, March 27, 2018 11:23 AM
> To: Haiyang Zhang <haiya...@linuxonhyperv.com>
> Cc: Haiyang Zhang <haiya...@microsoft.com>; da...@davemloft.net;
> net...@vger.kernel.org; o...@aepfle.de; Stephen Hemminger
> <sthem...@microsoft.com>; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuzn...@redhat.com
> Subject: Re: [PATCH net-next, 2/2] hv_netvsc: Add range checking for rx packet
> offset and length
> 
> On Thu, 22 Mar 2018 12:01:14 -0700
> Haiyang Zhang <haiya...@linuxonhyperv.com> wrote:
> 
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > This patch adds range checking for rx packet offset and length.
> > It may only happen if there is a host side bug.
> >
> > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > ---
> >  drivers/net/hyperv/hyperv_net.h |  1 +
> >  drivers/net/hyperv/netvsc.c | 17 +++--
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/hyperv/hyperv_net.h
> > b/drivers/net/hyperv/hyperv_net.h index 0db3bd1ea06f..49c05ac894e5
> > 100644
> > --- a/drivers/net/hyperv/hyperv_net.h
> > +++ b/drivers/net/hyperv/hyperv_net.h
> > @@ -793,6 +793,7 @@ struct netvsc_device {
> >
> > /* Receive buffer allocated by us but manages by NetVSP */
> > void *recv_buf;
> > +   u32 recv_buf_size; /* allocated bytes */
> > u32 recv_buf_gpadl_handle;
> > u32 recv_section_cnt;
> > u32 recv_section_size;
> > diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> > index 1ddb2c39b6e4..a6700d65f206 100644
> > --- a/drivers/net/hyperv/netvsc.c
> > +++ b/drivers/net/hyperv/netvsc.c
> > @@ -289,6 +289,8 @@ static int netvsc_init_buf(struct hv_device *device,
> > goto cleanup;
> > }
> >
> > +   net_device->recv_buf_size = buf_size;
> > +
> > /*
> >  * Establish the gpadl handle for this buffer on this
> >  * channel.  Note: This call uses the vmbus connection rather @@
> > -1095,11 +1097,22 @@ static int netvsc_receive(struct net_device
> > *ndev,
> >
> > /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
> > for (i = 0; i < count; i++) {
> > -   void *data = recv_buf
> > -   + vmxferpage_packet->ranges[i].byte_offset;
> > +   u32 offset = vmxferpage_packet->ranges[i].byte_offset;
> > u32 buflen = vmxferpage_packet->ranges[i].byte_count;
> > +   void *data;
> > int ret;
> >
> > +   if (unlikely(offset + buflen > net_device->recv_buf_size)) {
> > +   status = NVSP_STAT_FAIL;
> > +   netif_err(net_device_ctx, rx_err, ndev,
> > + "Packet offset:%u + len:%u too big\n",
> > + offset, buflen);
> > +
> > +   continue;
> > +   }
> > +
> 
> If one part of the RNDIS packet is wrong then the whole receive buffer is
> damaged. Just return, don't continue.
> 
> It could really just be a statistic and a one shot log message.

I will let the loop terminates and send NVSP status fail to the host.

For statistics, this range check is to catch potential host side issues, just 
like
these checks in the same function earlier:
/* Make sure this is a valid nvsp packet */
if (unlikely(nvsp->hdr.msg_type != NVSP_MSG1_TYPE_SEND_RNDIS_PKT)) {
netif_err(net_device_ctx, rx_err, ndev,
  "Unknown nvsp packet type received %u\n",
  nvsp->hdr.msg_type);
return 0;
}

if (unlikely(vmxferpage_packet->xfer_pageset_id != 
NETVSC_RECEIVE_BUFFER_ID)) {
netif_err(net_device_ctx, rx_err, ndev,
  "Invalid xfer page set id - expecting %x got %x\n",
  NETVSC_RECEIVE_BUFFER_ID,
  vmxferpage_packet->xfer_pageset_id);
return 0;
}

If these kinds of errors need statistics, there will be many stat variables... 
Maybe we 
should just create one stat variable for all of the "invalid format from host"?

Thanks,
- Haiyang

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


RE: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX path

2018-03-24 Thread Haiyang Zhang


> -Original Message-
> From: Michael Kelley (EOSG)
> Sent: Saturday, March 24, 2018 12:48 PM
> To: Haiyang Zhang <haiya...@microsoft.com>; da...@davemloft.net;
> net...@vger.kernel.org
> Cc: KY Srinivasan <k...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; o...@aepfle.de; vkuzn...@redhat.com;
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org
> Subject: RE: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX path
> 
> > -Original Message-
> > From: linux-kernel-ow...@vger.kernel.org
> > <linux-kernel-ow...@vger.kernel.org> On Behalf Of Haiyang Zhang
> > Sent: Thursday, March 22, 2018 12:01 PM
> > To: da...@davemloft.net; net...@vger.kernel.org
> > Cc: Haiyang Zhang <haiya...@microsoft.com>; KY Srinivasan
> > <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> > o...@aepfle.de; vkuzn...@redhat.com; de...@linuxdriverproject.org;
> > linux-ker...@vger.kernel.org
> > Subject: [PATCH net-next,1/2] hv_netvsc: Fix the return status in RX
> > path
> >
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > As defined in hyperv_net.h, the NVSP_STAT_SUCCESS is one not zero.
> > Some functions returns 0 when it actually means NVSP_STAT_SUCCESS.
> > This patch fixes them.
> >
> > In netvsc_receive(), it puts the last RNDIS packet's receive status
> > for all packets in a vmxferpage which may contain multiple RNDIS
> > packets.
> > This patch puts NVSP_STAT_FAIL in the receive completion if one of the
> > packets in a vmxferpage fails.
> 
> This patch changes the status field that is being reported back to the Hyper-V
> host in the receive completion message in
> enq_receive_complete().   The current code reports 0 on success,
> and with the patch, it will report 1 on success.  So does this change affect
> anything on the Hyper-V side?  Or is Hyper-V just ignoring
> the value?   If this change doesn't have any impact on the
> interactions with Hyper-V, perhaps it would be good to explain why in the
> commit message.

Here is the definition of each status code for NetVSP. 
enum {
NVSP_STAT_NONE = 0,
NVSP_STAT_SUCCESS,
NVSP_STAT_FAIL,
NVSP_STAT_PROTOCOL_TOO_NEW,
NVSP_STAT_PROTOCOL_TOO_OLD,
NVSP_STAT_INVALID_RNDIS_PKT,
NVSP_STAT_BUSY,
NVSP_STAT_PROTOCOL_UNSUPPORTED,
NVSP_STAT_MAX,
};

Existing code returns NVSP_STAT_NONE = 0, and with this patch
we return NVSP_STAT_SUCCESS = 1. 
Based on testing, either way works for now. But for correctness
and future stability (e.g. host side becomes more stringent), we
should follow the protocol.

Thanks,
- Haiyang

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


RE: [PATCH net-next, 2/2] hv_netvsc: Add range checking for rx packet offset and length

2018-03-23 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Sent: Friday, March 23, 2018 11:17 AM
> To: Haiyang Zhang <haiya...@linuxonhyperv.com>
> Cc: da...@davemloft.net; net...@vger.kernel.org; Haiyang Zhang
> <haiya...@microsoft.com>; KY Srinivasan <k...@microsoft.com>; Stephen
> Hemminger <sthem...@microsoft.com>; o...@aepfle.de;
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org
> Subject: Re: [PATCH net-next,2/2] hv_netvsc: Add range checking for rx packet
> offset and length
> 
> Haiyang Zhang <haiya...@linuxonhyperv.com> writes:
> 
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > This patch adds range checking for rx packet offset and length.
> > It may only happen if there is a host side bug.
> >
> > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > ---
> >  drivers/net/hyperv/hyperv_net.h |  1 +
> >  drivers/net/hyperv/netvsc.c | 17 +++--
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/hyperv/hyperv_net.h
> > b/drivers/net/hyperv/hyperv_net.h index 0db3bd1ea06f..49c05ac894e5
> > 100644
> > --- a/drivers/net/hyperv/hyperv_net.h
> > +++ b/drivers/net/hyperv/hyperv_net.h
> > @@ -793,6 +793,7 @@ struct netvsc_device {
> >
> > /* Receive buffer allocated by us but manages by NetVSP */
> > void *recv_buf;
> > +   u32 recv_buf_size; /* allocated bytes */
> > u32 recv_buf_gpadl_handle;
> > u32 recv_section_cnt;
> > u32 recv_section_size;
> > diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> > index 1ddb2c39b6e4..a6700d65f206 100644
> > --- a/drivers/net/hyperv/netvsc.c
> > +++ b/drivers/net/hyperv/netvsc.c
> > @@ -289,6 +289,8 @@ static int netvsc_init_buf(struct hv_device *device,
> > goto cleanup;
> > }
> >
> > +   net_device->recv_buf_size = buf_size;
> > +
> > /*
> >  * Establish the gpadl handle for this buffer on this
> >  * channel.  Note: This call uses the vmbus connection rather @@
> > -1095,11 +1097,22 @@ static int netvsc_receive(struct net_device
> > *ndev,
> >
> > /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
> > for (i = 0; i < count; i++) {
> > -   void *data = recv_buf
> > -   + vmxferpage_packet->ranges[i].byte_offset;
> > +   u32 offset = vmxferpage_packet->ranges[i].byte_offset;
> > u32 buflen = vmxferpage_packet->ranges[i].byte_count;
> > +   void *data;
> > int ret;
> >
> > +   if (unlikely(offset + buflen > net_device->recv_buf_size)) {
> > +   status = NVSP_STAT_FAIL;
> > +   netif_err(net_device_ctx, rx_err, ndev,
> > + "Packet offset:%u + len:%u too big\n",
> > + offset, buflen);
> 
> This shouldn't happen, of course, but I'd rather ratelimit this error or even 
> used
> something like netdev_WARN_ONCE().

Actually I thought about ratelimit, but this range check is only to catch host 
side bug. 
It should not happen. 
But if it happens, the VM should not be used anymore. And we need to debug
the host. Similarly, some other this kind of checks in the same function are 
not using
ratelimit:

if (unlikely(nvsp->hdr.msg_type != NVSP_MSG1_TYPE_SEND_RNDIS_PKT)) {
netif_err(net_device_ctx, rx_err, ndev,
  "Unknown nvsp packet type received %u\n",
  nvsp->hdr.msg_type);

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


RE: [PATCH 1/3] Vmbus: Add function to report available ring buffer to write in total ring size percentage

2018-03-23 Thread Haiyang Zhang


> -Original Message-
> From: Long Li <lon...@linuxonhyperv.com>
> Sent: Thursday, March 22, 2018 8:16 PM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> James E . J . Bottomley <jbottom...@odin.com>; Martin K . Petersen
> <martin.peter...@oracle.com>; de...@linuxdriverproject.org; linux-
> s...@vger.kernel.org; linux-ker...@vger.kernel.org
> Cc: Long Li <lon...@microsoft.com>
> Subject: [PATCH 1/3] Vmbus: Add function to report available ring buffer to
> write in total ring size percentage
> 
> From: Long Li <lon...@microsoft.com>
> 
> Netvsc has a similar function to calculate how much ring buffer in percentage
> is available to write. This function is useful for storvsc and other vmbus 
> devices.
> 
> Define a similar function in vmbus to be used by storvsc.
> 
> Signed-off-by: Long Li <lon...@microsoft.com>
> ---

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH 2/3] Netvsc: Use the vmbus functiton to calculate ring buffer percentage

2018-03-23 Thread Haiyang Zhang


> -Original Message-
> From: Long Li <lon...@linuxonhyperv.com>
> Sent: Thursday, March 22, 2018 8:16 PM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> James E . J . Bottomley <jbottom...@odin.com>; Martin K . Petersen
> <martin.peter...@oracle.com>; de...@linuxdriverproject.org; linux-
> s...@vger.kernel.org; linux-ker...@vger.kernel.org
> Cc: Long Li <lon...@microsoft.com>
> Subject: [PATCH 2/3] Netvsc: Use the vmbus functiton to calculate ring buffer
> percentage
> 
> From: Long Li <lon...@microsoft.com>
> 
> In Vmbus, we have defined a function to calculate available ring buffer
> percentage to write.
> 
> Use that function and remove duplicate netvsc code.
> 
> Signed-off-by: Long Li <lon...@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc.c | 17 +++--
>  drivers/net/hyperv/netvsc_drv.c |  3 ---
>  2 files changed, 3 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index
> 0265d703eb03..8af0069e4d8c 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -31,7 +31,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
> 
>  #include 
> 
> @@ -590,17 +589,6 @@ void netvsc_device_remove(struct hv_device *device)
> #define RING_AVAIL_PERCENT_HIWATER 20  #define
> RING_AVAIL_PERCENT_LOWATER 10
> 
> -/*
> - * Get the percentage of available bytes to write in the ring.
> - * The return value is in range from 0 to 100.
> - */
> -static u32 hv_ringbuf_avail_percent(const struct hv_ring_buffer_info
> *ring_info) -{
> - u32 avail_write = hv_get_bytes_to_write(ring_info);
> -
> - return reciprocal_divide(avail_write  * 100, netvsc_ring_reciprocal);
> -}
> -
>  static inline void netvsc_free_send_slot(struct netvsc_device *net_device,
>u32 index)
>  {
> @@ -649,7 +637,8 @@ static void netvsc_send_tx_complete(struct
> netvsc_device *net_device,
>   wake_up(_device->wait_drain);
> 
>   if (netif_tx_queue_stopped(netdev_get_tx_queue(ndev, q_idx)) &&
> - (hv_ringbuf_avail_percent(>outbound) >
> RING_AVAIL_PERCENT_HIWATER ||
> + (hv_get_avail_to_write_percent(>outbound) >
> +  RING_AVAIL_PERCENT_HIWATER ||
>queue_sends < 1)) {
>   netif_tx_wake_queue(netdev_get_tx_queue(ndev, q_idx));
>   ndev_ctx->eth_stats.wake_queue++;
> @@ -757,7 +746,7 @@ static inline int netvsc_send_pkt(
>   struct netdev_queue *txq = netdev_get_tx_queue(ndev, packet->q_idx);
>   u64 req_id;
>   int ret;
> - u32 ring_avail = hv_ringbuf_avail_percent(_channel->outbound);
> + u32 ring_avail =
> +hv_get_avail_to_write_percent(_channel->outbound);
> 
>   nvmsg.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT;
>   if (skb)
> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index faea0be18924..b0b1c2fd2b7b 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -35,7 +35,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
> 
>  #include 
>  #include 
> @@ -55,7 +54,6 @@ static unsigned int ring_size __ro_after_init = 128;
> module_param(ring_size, uint, S_IRUGO);  MODULE_PARM_DESC(ring_size,
> "Ring buffer size (# of pages)");  unsigned int netvsc_ring_bytes 
> __ro_after_init;
> -struct reciprocal_value netvsc_ring_reciprocal __ro_after_init;
> 
>  static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE |
>   NETIF_MSG_LINK | NETIF_MSG_IFUP |
> @@ -2186,7 +2184,6 @@ static int __init netvsc_drv_init(void)
>   ring_size);
>   }
>   netvsc_ring_bytes = ring_size * PAGE_SIZE;
> - netvsc_ring_reciprocal = reciprocal_value(netvsc_ring_bytes);
> 
>   ret = vmbus_driver_register(_drv);
>   if (ret)
> --


Please also remove netvsc_ring_reciprocal from hyperv_net.h
Thanks.

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH net-next, 2/2] hv_netvsc: Add range checking for rx packet offset and length

2018-03-22 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

This patch adds range checking for rx packet offset and length.
It may only happen if there is a host side bug.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h |  1 +
 drivers/net/hyperv/netvsc.c | 17 +++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 0db3bd1ea06f..49c05ac894e5 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -793,6 +793,7 @@ struct netvsc_device {
 
/* Receive buffer allocated by us but manages by NetVSP */
void *recv_buf;
+   u32 recv_buf_size; /* allocated bytes */
u32 recv_buf_gpadl_handle;
u32 recv_section_cnt;
u32 recv_section_size;
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 1ddb2c39b6e4..a6700d65f206 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -289,6 +289,8 @@ static int netvsc_init_buf(struct hv_device *device,
goto cleanup;
}
 
+   net_device->recv_buf_size = buf_size;
+
/*
 * Establish the gpadl handle for this buffer on this
 * channel.  Note: This call uses the vmbus connection rather
@@ -1095,11 +1097,22 @@ static int netvsc_receive(struct net_device *ndev,
 
/* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
for (i = 0; i < count; i++) {
-   void *data = recv_buf
-   + vmxferpage_packet->ranges[i].byte_offset;
+   u32 offset = vmxferpage_packet->ranges[i].byte_offset;
u32 buflen = vmxferpage_packet->ranges[i].byte_count;
+   void *data;
int ret;
 
+   if (unlikely(offset + buflen > net_device->recv_buf_size)) {
+   status = NVSP_STAT_FAIL;
+   netif_err(net_device_ctx, rx_err, ndev,
+ "Packet offset:%u + len:%u too big\n",
+ offset, buflen);
+
+   continue;
+   }
+
+   data = recv_buf + offset;
+
trace_rndis_recv(ndev, q_idx, data);
 
/* Pass it to the upper layer */
-- 
2.15.1

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


[PATCH net-next,1/2] hv_netvsc: Fix the return status in RX path

2018-03-22 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

As defined in hyperv_net.h, the NVSP_STAT_SUCCESS is one not zero.
Some functions returns 0 when it actually means NVSP_STAT_SUCCESS.
This patch fixes them.

In netvsc_receive(), it puts the last RNDIS packet's receive status
for all packets in a vmxferpage which may contain multiple RNDIS
packets.
This patch puts NVSP_STAT_FAIL in the receive completion if one of
the packets in a vmxferpage fails.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/netvsc.c   | 8 ++--
 drivers/net/hyperv/netvsc_drv.c   | 2 +-
 drivers/net/hyperv/rndis_filter.c | 4 ++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index aa95e81af6e5..1ddb2c39b6e4 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -1098,12 +1098,16 @@ static int netvsc_receive(struct net_device *ndev,
void *data = recv_buf
+ vmxferpage_packet->ranges[i].byte_offset;
u32 buflen = vmxferpage_packet->ranges[i].byte_count;
+   int ret;
 
trace_rndis_recv(ndev, q_idx, data);
 
/* Pass it to the upper layer */
-   status = rndis_filter_receive(ndev, net_device,
- channel, data, buflen);
+   ret = rndis_filter_receive(ndev, net_device,
+  channel, data, buflen);
+
+   if (unlikely(ret != NVSP_STAT_SUCCESS))
+   status = NVSP_STAT_FAIL;
}
 
enq_receive_complete(ndev, net_device, q_idx,
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index cdb78eefab67..33607995be62 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -818,7 +818,7 @@ int netvsc_recv_callback(struct net_device *net,
u64_stats_update_end(_stats->syncp);
 
napi_gro_receive(>napi, skb);
-   return 0;
+   return NVSP_STAT_SUCCESS;
 }
 
 static void netvsc_get_drvinfo(struct net_device *net,
diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 2dc00f714482..591fb8080f11 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -443,10 +443,10 @@ int rndis_filter_receive(struct net_device *ndev,
"unhandled rndis message (type %u len %u)\n",
   rndis_msg->ndis_msg_type,
   rndis_msg->msg_len);
-   break;
+   return NVSP_STAT_FAIL;
}
 
-   return 0;
+   return NVSP_STAT_SUCCESS;
 }
 
 static int rndis_filter_query_device(struct rndis_device *dev,
-- 
2.15.1

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


[PATCH net-next,0/2] hv_netvsc: Fix/improve RX path error handling

2018-03-22 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

Fix the status code returned to the host. Also add range
check for rx packet offset and length.

Haiyang Zhang (2):
  hv_netvsc: Fix the return status in RX path
  hv_netvsc: Add range checking for rx packet offset and length

 drivers/net/hyperv/hyperv_net.h   |  1 +
 drivers/net/hyperv/netvsc.c   | 25 +
 drivers/net/hyperv/netvsc_drv.c   |  2 +-
 drivers/net/hyperv/rndis_filter.c |  4 ++--
 4 files changed, 25 insertions(+), 7 deletions(-)

-- 
2.15.1

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


RE: [PATCH v3 1/6] PCI: hv: fix a comment typo in _hv_pcifront_read_config()

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>;
> sta...@vger.kernel.org
> Subject: [PATCH v3 1/6] PCI: hv: fix a comment typo in
> _hv_pcifront_read_config()
> 
> No functional change.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Fixes: bdd74440d9e8 ("PCI: hv: Add explicit barriers to config space access")
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH v3 2/6] PCI: hv: hv_eject_device_work(): remove the bogus test

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>; Jack
> Morgenstein <ja...@mellanox.com>; sta...@vger.kernel.org
> Subject: [PATCH v3 2/6] PCI: hv: hv_eject_device_work(): remove the bogus test
> 
> When we're in the function, hpdev->state must be hv_pcichild_ejecting:
> see hv_pci_eject_device().
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: Jack Morgenstein <ja...@mellanox.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> Cc: Michael Kelley (EOSG) <michael.h.kel...@microsoft.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v3 5/6] PCI: hv: hv_pci_devices_present(): only queue a new work when necessary

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>; Jack
> Morgenstein <ja...@mellanox.com>; sta...@vger.kernel.org
> Subject: [PATCH v3 5/6] PCI: hv: hv_pci_devices_present(): only queue a new
> work when necessary
> 
> If there is a pending work, we just need to add the new dr into the dr_list.
> 
> This is suggested by Michael Kelley.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: Jack Morgenstein <ja...@mellanox.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> Cc: Michael Kelley (EOSG) <michael.h.kel...@microsoft.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v3 3/6] PCI: hv: serialize the present/eject work items

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>; Jack
> Morgenstein <ja...@mellanox.com>; sta...@vger.kernel.org
> Subject: [PATCH v3 3/6] PCI: hv: serialize the present/eject work items
> 
> When we hot-remove the device, we first receive a PCI_EJECT message and
> then receive a PCI_BUS_RELATIONS message with bus_rel->device_count == 0.
> 
> The first message is offloaded to hv_eject_device_work(), and the second is
> offloaded to pci_devices_present_work(). Both the paths can be running
> list_del(>list_entry), causing general protection fault, because
> system_wq can run them concurrently.
> 
> The patch eliminates the race condition.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Tested-by: Adrian Suhov <v-ads...@microsoft.com>
> Tested-by: Chris Valean <v-chv...@microsoft.com>
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: Jack Morgenstein <ja...@mellanox.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v3 4/6] PCI: hv: remove hbus->enum_sem

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>; Jack
> Morgenstein <ja...@mellanox.com>; sta...@vger.kernel.org
> Subject: [PATCH v3 4/6] PCI: hv: remove hbus->enum_sem
> 
> Since we serialize the present/eject work items now, we don't need the
> semaphore any more.
> 
> This is suggested by Michael Kelley.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: Jack Morgenstein <ja...@mellanox.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> Cc: Michael Kelley (EOSG) <michael.h.kel...@microsoft.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v3 6/6] PCI: hv: fix 2 hang issues in hv_compose_msi_msg()

2018-03-09 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, March 6, 2018 1:22 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; a...@canonical.com; jasow...@redhat.com
> Cc: linux-ker...@vger.kernel.org; driverdev-devel@linuxdriverproject.org;
> Haiyang Zhang <haiya...@microsoft.com>; vkuzn...@redhat.com;
> marcelo.ce...@canonical.com; Michael Kelley (EOSG)
> <michael.h.kel...@microsoft.com>; Dexuan Cui <de...@microsoft.com>;
> sta...@vger.kernel.org; Jack Morgenstein <ja...@mellanox.com>
> Subject: [PATCH v3 6/6] PCI: hv: fix 2 hang issues in hv_compose_msi_msg()
> 
> 1. With the patch "x86/vector/msi: Switch to global reservation mode"
> (4900be8360), the recent v4.15 and newer kernels always hang for 1-vCPU
> Hyper-V VM with SR-IOV. This is because when we reach
> hv_compose_msi_msg() by request_irq()  -> request_threaded_irq() ->
> __setup_irq()->irq_startup()  -> __irq_startup() -> irq_domain_activate_irq() 
> -
> > ... ->
> msi_domain_activate() -> ... -> hv_compose_msi_msg(), local irq is disabled in
> __setup_irq().
> 
> Fix this by polling the channel.
> 
> 2. If the host is ejecting the VF device before we reach hv_compose_msi_msg(),
> in a UP VM, we can hang in hv_compose_msi_msg() forever, because at this
> time the host doesn't respond to the CREATE_INTERRUPT request. This issue
> also happens to old kernels like v4.14, v4.13, etc.
> 
> Fix this by polling the channel for the PCI_EJECT message and
> hpdev->state, and by checking the PCI vendor ID.
> 
> Note: actually the above issues also happen to a SMP VM, if "hbus->hdev-
> >channel->target_cpu == smp_processor_id()" is true.
> 
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Tested-by: Adrian Suhov <v-ads...@microsoft.com>
> Tested-by: Chris Valean <v-chv...@microsoft.com>
> Cc: sta...@vger.kernel.org
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> Cc: Vitaly Kuznetsov <vkuzn...@redhat.com>
> Cc: Jack Morgenstein <ja...@mellanox.com>
> ---

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] hv_vmbus: Correct the stale comments regarding cpu affinity

2018-01-26 Thread Haiyang Zhang
The comments doesn't match what the current code does, also have a
typo. This patch corrects them.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/hv/channel_mgmt.c | 6 ++
 include/linux/hyperv.h| 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index c21020b69114..c6d9d19bc04e 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -596,10 +596,8 @@ static int next_numa_node_id;
 /*
  * Starting with Win8, we can statically distribute the incoming
  * channel interrupt load by binding a channel to VCPU.
- * We do this in a hierarchical fashion:
- * First distribute the primary channels across available NUMA nodes
- * and then distribute the subchannels amongst the CPUs in the NUMA
- * node assigned to the primary channel.
+ * We distribute the interrupt loads to one or more NUMA nodes based on
+ * the channel's affinity_policy.
  *
  * For pre-win8 hosts or non-performance critical channels we assign the
  * first CPU in the first NUMA node.
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 93bd6fcd6e62..2048f3c3b68a 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -844,7 +844,7 @@ struct vmbus_channel {
 
/*
 * NUMA distribution policy:
-* We support teo policies:
+* We support two policies:
 * 1) Balanced: Here all performance critical channels are
 *distributed evenly amongst all the NUMA nodes.
 *This policy will be the default policy.
-- 
2.15.1
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [RFC PATCH 0/2] hv_netvsc: Fix shutdown regression on Win2012 hosts

2018-01-23 Thread Haiyang Zhang


> -Original Message-
> From: Mohammed Gamal [mailto:mga...@redhat.com]
> Sent: Tuesday, January 23, 2018 4:34 AM
> To: net...@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org; KY
> Srinivasan <k...@microsoft.com>; Haiyang Zhang <haiya...@microsoft.com>;
> Stephen Hemminger <sthem...@microsoft.com>; vkuzn...@redhat.com;
> cav...@redhat.com; ot...@redhat.com; Mohammed Gamal
> <mga...@redhat.com>
> Subject: [RFC PATCH 0/2] hv_netvsc: Fix shutdown regression on Win2012
> hosts
> 
> Commit 0cf737808ae7 ("hv_netvsc: netvsc_teardown_gpadl() split")
> introduced a regression that caused VMs not to shutdown after
> netvsc_device_remove() is called. This is caused by GPADL teardown
> sequence change, and while that was necessary to fix issues with Win2016
> hosts, it did introduce a regression for earlier versions.
> 
> Prior to commit 0cf737808 the call sequence in netvsc_device_remove() was
> as follows (as implemented in netvsc_destroy_buf()):
> 1- Send NVSP_MSG1_TYPE_REVOKE_RECV_BUF message
> 2- Teardown receive buffer GPADL
> 3- Send NVSP_MSG1_TYPE_REVOKE_SEND_BUF message
> 4- Teardown send buffer GPADL
> 5- Close vmbus
> 
> This didn't work for WS2016 hosts. Commit 0cf737808 split
> netvsc_destroy_buf() into two functions and rearranged the order as follows
> 1- Send NVSP_MSG1_TYPE_REVOKE_RECV_BUF message
> 2- Send NVSP_MSG1_TYPE_REVOKE_SEND_BUF message
> 3- Close vmbus
> 4- Teardown receive buffer GPADL
> 5- Teardown send buffer GPADL
> 
> That worked well for WS2016 hosts, but for WS2012 hosts it prevented VMs
> from shutting down.
> 
> This patch series works around this problem. The first patch splits
> netvsc_revoke_buf() and netvsc_teardown_gpadl() into two finer grained
> functions for tearing down send and receive buffers individally. The second
> patch uses the finer grained functions to implement the teardown sequence
> according to the host's version. We keep the behavior introduced in
> 0cf737808ae7 for Windows
> 2016 hosts, while we re-introduce the old sequence for earlier verions.
> 
> Mohammed Gamal (2):
>   hv_netvsc: Split netvsc_revoke_buf() and netvsc_teardown_gpadl()
>   hv_netvsc: Change GPADL teardown order according to Hyper-V version
> 
>  drivers/net/hyperv/netvsc.c | 50
> +
>  1 file changed, 42 insertions(+), 8 deletions(-)

Thank you for the patches. We are testing them internally.

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


[PATCH net-next] hv_netvsc: Use the num_online_cpus() for channel limit

2018-01-19 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

Since we no longer localize channel/CPU affiliation within one NUMA
node, num_online_cpus() is used as the number of channel cap, instead of
the number of processors in a NUMA node.

This patch allows a bigger range for tuning the number of channels.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/rndis_filter.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 91a67c5297f7..c3ca191fea7f 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1221,7 +1221,6 @@ struct netvsc_device *rndis_filter_device_add(struct 
hv_device *dev,
struct ndis_recv_scale_cap rsscap;
u32 rsscap_size = sizeof(struct ndis_recv_scale_cap);
u32 mtu, size;
-   const struct cpumask *node_cpu_mask;
u32 num_possible_rss_qs;
int i, ret;

@@ -1290,14 +1289,8 @@ struct netvsc_device *rndis_filter_device_add(struct 
hv_device *dev,
if (ret || rsscap.num_recv_que < 2)
goto out;

-   /*
-* We will limit the VRSS channels to the number CPUs in the NUMA node
-* the primary channel is currently bound to.
-*
-* This also guarantees that num_possible_rss_qs <= num_online_cpus
-*/
-   node_cpu_mask = cpumask_of_node(cpu_to_node(dev->channel->target_cpu));
-   num_possible_rss_qs = min_t(u32, cpumask_weight(node_cpu_mask),
+   /* This guarantees that num_possible_rss_qs <= num_online_cpus */
+   num_possible_rss_qs = min_t(u32, num_online_cpus(),
rsscap.num_recv_que);

net_device->max_chn = min_t(u32, VRSS_CHANNEL_MAX, num_possible_rss_qs);
--
2.15.1

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


[PATCH net-next] hv_netvsc: Use the num_online_cpus() for channel limit

2018-01-19 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

Since we no longer localize channel/CPU affiliation within one NUMA
node, num_online_cpus() is used as the number of channel cap, instead of
the number of processors in a NUMA node.

This patch allows a bigger range for tuning the number of channels.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/net/hyperv/rndis_filter.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/net/hyperv/rndis_filter.c 
b/drivers/net/hyperv/rndis_filter.c
index 91a67c5297f7..c3ca191fea7f 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1221,7 +1221,6 @@ struct netvsc_device *rndis_filter_device_add(struct 
hv_device *dev,
struct ndis_recv_scale_cap rsscap;
u32 rsscap_size = sizeof(struct ndis_recv_scale_cap);
u32 mtu, size;
-   const struct cpumask *node_cpu_mask;
u32 num_possible_rss_qs;
int i, ret;
 
@@ -1290,14 +1289,8 @@ struct netvsc_device *rndis_filter_device_add(struct 
hv_device *dev,
if (ret || rsscap.num_recv_que < 2)
goto out;
 
-   /*
-* We will limit the VRSS channels to the number CPUs in the NUMA node
-* the primary channel is currently bound to.
-*
-* This also guarantees that num_possible_rss_qs <= num_online_cpus
-*/
-   node_cpu_mask = cpumask_of_node(cpu_to_node(dev->channel->target_cpu));
-   num_possible_rss_qs = min_t(u32, cpumask_weight(node_cpu_mask),
+   /* This guarantees that num_possible_rss_qs <= num_online_cpus */
+   num_possible_rss_qs = min_t(u32, num_online_cpus(),
rsscap.num_recv_que);
 
net_device->max_chn = min_t(u32, VRSS_CHANNEL_MAX, num_possible_rss_qs);
-- 
2.15.1

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


RE: [PATCH] hyperv/netvsc: Delete two error messages for a failed memory allocation in netvsc_init_buf()

2018-01-08 Thread Haiyang Zhang


> -Original Message-
> From: SF Markus Elfring [mailto:elfr...@users.sourceforge.net]
> Sent: Sunday, January 7, 2018 3:10 PM
> To: de...@linuxdriverproject.org; net...@vger.kernel.org; Haiyang Zhang
> <haiya...@microsoft.com>; KY Srinivasan <k...@microsoft.com>; Stephen
> Hemminger <sthem...@microsoft.com>
> Cc: LKML <linux-ker...@vger.kernel.org>; kernel-janit...@vger.kernel.org
> Subject: [PATCH] hyperv/netvsc: Delete two error messages for a failed
> memory allocation in netvsc_init_buf()
> 
> From: Markus Elfring <elfr...@users.sourceforge.net>
> Date: Sun, 7 Jan 2018 21:03:26 +0100
> 
> Omit extra messages for a memory allocation failure in this function.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>
> ---
>  drivers/net/hyperv/netvsc.c | 5 -
>  1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index
> 17e529af79dc..c1ec02f801f6 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -275,9 +275,6 @@ static int netvsc_init_buf(struct hv_device *device,
> 
>   net_device->recv_buf = vzalloc(buf_size);
>   if (!net_device->recv_buf) {
> - netdev_err(ndev,
> -"unable to allocate receive buffer of size %u\n",
> -buf_size);
>   ret = -ENOMEM;
>   goto cleanup;
>   }
> @@ -357,8 +354,6 @@ static int netvsc_init_buf(struct hv_device *device,
> 
>   net_device->send_buf = vzalloc(buf_size);
>   if (!net_device->send_buf) {
> - netdev_err(ndev, "unable to allocate send buffer of
> size %u\n",
> -buf_size);
>   ret = -ENOMEM;
>   goto cleanup;
>   }

These messages are not displayed anywhere else:
"unable to allocate receive buffer of size %u\n"
"unable to allocate send buffer of size %u\n",

After set ret = -ENOMEM; and cleanup, we won't know which buffer allocation 
failed without the error message.

So please do not remove these messages.

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


RE: [PATCH net 3/3] hv_netvsc: Fix the default receive buffer size

2017-12-08 Thread Haiyang Zhang


> -Original Message-
> From: Dan Carpenter [mailto:dan.carpen...@oracle.com]
> Sent: Friday, December 8, 2017 5:45 AM
> To: Stephen Hemminger <step...@networkplumber.org>
> Cc: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; de...@linuxdriverproject.org;
> net...@vger.kernel.org
> Subject: Re: [PATCH net 3/3] hv_netvsc: Fix the default receive buffer size
> 
> On Thu, Dec 07, 2017 at 04:10:55PM -0800, Stephen Hemminger wrote:
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > The intended size is 16 MB, and the default slot size is 1728.
> > So, NETVSC_DEFAULT_RX should be 16*1024*1024 / 1728 = 9709.
> >
> > Fixes: 5023a6db73196 ("netvsc: increase default receive buffer size")
> > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > Signed-off-by: Stephen Hemminger <sthem...@microsoft.com>
> > ---
> >  drivers/net/hyperv/netvsc_drv.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > b/drivers/net/hyperv/netvsc_drv.c index dc70de674ca9..edfcde5d3621
> > 100644
> > --- a/drivers/net/hyperv/netvsc_drv.c
> > +++ b/drivers/net/hyperv/netvsc_drv.c
> > @@ -50,7 +50,7 @@
> >  #define NETVSC_MIN_TX_SECTIONS 10
> >  #define NETVSC_DEFAULT_TX  192 /* ~1M */
> >  #define NETVSC_MIN_RX_SECTIONS 10  /* ~64K */
> > -#define NETVSC_DEFAULT_RX  10485   /* Max ~16M */
> > +#define NETVSC_DEFAULT_RX  9709/* ~16M */
> 
> How does this bug look like to the user?  Memory corruption?
> 
> It's weird to me reviewing this code that the default sizes are stored in
> netvsc_drv.c and the max sizes are stored in hyperv_net.h.
> Could we move these to hyperv_net.h?  We could write it like:
> #define NETVSC_DEFAULT_RX ((16 * 1024 * 1024) /
> NETVSC_RECV_SECTION_SIZE)
> 
> 16MB is sort of a weird default because it's larger than the 15MB allowed for
> legacy versions, but it's smaller than the 32MB you'd want for the current
> versions.

As a tradeoff between traffic burst and latency, we set the default to be 16MB.
And this default is reduced automatically for legacy hosts based on the NVSP
version in patch 2. 

I will move the change to hyperv_net.h

Thanks,
- Haiyang

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


RE: [PATCH net 1/3] hv_netvsc: Correct the max receive buffer size

2017-12-08 Thread Haiyang Zhang


> -Original Message-
> From: Dan Carpenter [mailto:dan.carpen...@oracle.com]
> Sent: Friday, December 8, 2017 5:33 AM
> To: Stephen Hemminger <step...@networkplumber.org>
> Cc: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; de...@linuxdriverproject.org;
> net...@vger.kernel.org
> Subject: Re: [PATCH net 1/3] hv_netvsc: Correct the max receive buffer size
> 
> On Thu, Dec 07, 2017 at 04:10:53PM -0800, Stephen Hemminger wrote:
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > It should be 31 MB on recent host versions.
> >
> > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > Signed-off-by: Stephen Hemminger <sthem...@microsoft.com>
> 
> This is very vague.  What does "recent" mean in this context?  There are also
> some unrelated white space changes here which make the patch harder to
> read.
> 
> This patch kind of makes the bug fixed by patch 2 even worse because
> before the receive buffer was capped at around 16MB and now we can set
> the receive buffer to 31MB.  It might make sense to fold the two patches
> together.
> 
> Is patch 2 a memory corruption bug?  The changelog doesn't really say what
> the user visible effects of the bug are.  Basically if you make the buffer too
> small then it's a performance issue but if you make it too large what happens?
> It's not clear to me.

For NVSP v2, and earlier host, the limit is 15MB. Later hosts, the limit is 
31MB.
Setting beyond it will be denied by the host, resulting the vNIC doesn't come 
up.

I will merge this one together with the patch 2.

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


RE: [PATCH 0/4] hv_balloon: fixes for num_pages_onlined accounting and misc improvements

2017-11-29 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, November 28, 2017 8:30 AM
> To: Alex Ng <ale...@microsoft.com>; KY Srinivasan <k...@microsoft.com>
> Cc: linux-ker...@vger.kernel.org; Haiyang Zhang <haiya...@microsoft.com>;
> Stephen Hemminger <sthem...@microsoft.com>; Dexuan Cui
> <de...@microsoft.com>; de...@linuxdriverproject.org
> Subject: Re: [PATCH 0/4] hv_balloon: fixes for num_pages_onlined
> accounting and misc improvements
> 
> Vitaly Kuznetsov <vkuzn...@redhat.com> writes:
> 
> > While doing routing code review I noticed that commit 6df8d9aaf3af
> > ("Drivers: hv: balloon: Correctly update onlined page count")
> > introduced an issue with num_pages_onlined accounting on memory
> > offlining. Deeper look showed that the accounting was always buggy. This is
> fixed in PATCH3.
> > PATCHes 1 and 2 are preparatory cleanups, PATCH4 adds a tracepoint to
> > post_status so it's now possible to see what's being sent to the host
> > and where the data comes from.
> >
> 
> K. Y., Alex,
> 
> did you have a chance to take a look?
> 
> Thanks,
> 
> --
>   Vitaly

Dexuan, 

Maybe, you can take a look? Thanks.

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


[PATCH] tools/hv: Fix IP reporting by KVP daemon with SRIOV

2017-11-21 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

On Hyper-V the VF NIC has the same MAC as the related synthetic NIC.
VF NIC can work under the synthetic NIC transparently, without its
own IP address. The existing KVP daemon only gets IP from the first
NIC matching a MAC address, and may not be able to find the IP in
this case.

This patch fixes the problem by searching the NIC matching the MAC,
and having an IP address. So, the IP address will be found and
reported to the host successfully.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 tools/hv/hv_kvp_daemon.c | 138 ++-
 1 file changed, 65 insertions(+), 73 deletions(-)

diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index eaa3bec273c8..16964a7811a9 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -676,64 +676,6 @@ static char *kvp_if_name_to_mac(char *if_name)
return mac_addr;
 }
 
-
-/*
- * Retrieve the interface name given tha MAC address.
- */
-
-static char *kvp_mac_to_if_name(char *mac)
-{
-   DIR *dir;
-   struct dirent *entry;
-   FILE*file;
-   char*p, *x;
-   char*if_name = NULL;
-   charbuf[256];
-   char dev_id[PATH_MAX];
-   unsigned int i;
-
-   dir = opendir(KVP_NET_DIR);
-   if (dir == NULL)
-   return NULL;
-
-   while ((entry = readdir(dir)) != NULL) {
-   /*
-* Set the state for the next pass.
-*/
-   snprintf(dev_id, sizeof(dev_id), "%s%s/address", KVP_NET_DIR,
-entry->d_name);
-
-   file = fopen(dev_id, "r");
-   if (file == NULL)
-   continue;
-
-   p = fgets(buf, sizeof(buf), file);
-   if (p) {
-   x = strchr(p, '\n');
-   if (x)
-   *x = '\0';
-
-   for (i = 0; i < strlen(p); i++)
-   p[i] = toupper(p[i]);
-
-   if (!strcmp(p, mac)) {
-   /*
-* Found the MAC match; return the interface
-* name. The caller will free the memory.
-*/
-   if_name = strdup(entry->d_name);
-   fclose(file);
-   break;
-   }
-   }
-   fclose(file);
-   }
-
-   closedir(dir);
-   return if_name;
-}
-
-
 static void kvp_process_ipconfig_file(char *cmd,
char *config_buf, unsigned int len,
int element_size, int offset)
@@ -1039,6 +981,70 @@ kvp_get_ip_info(int family, char *if_name, int op,
return error;
 }
 
+/*
+ * Retrieve the IP given the MAC address.
+ */
+static int kvp_mac_to_ip(struct hv_kvp_ipaddr_value *kvp_ip_val)
+{
+   char *mac = (char *)kvp_ip_val->adapter_id;
+   DIR *dir;
+   struct dirent *entry;
+   FILE*file;
+   char*p, *x;
+   char*if_name = NULL;
+   charbuf[256];
+   char dev_id[PATH_MAX];
+   unsigned int i;
+   int error = HV_E_FAIL;
+
+   dir = opendir(KVP_NET_DIR);
+   if (dir == NULL)
+   return HV_E_FAIL;
+
+   while ((entry = readdir(dir)) != NULL) {
+   /*
+* Set the state for the next pass.
+*/
+   snprintf(dev_id, sizeof(dev_id), "%s%s/address", KVP_NET_DIR,
+entry->d_name);
+
+   file = fopen(dev_id, "r");
+   if (file == NULL)
+   continue;
+
+   p = fgets(buf, sizeof(buf), file);
+   fclose(file);
+   if (!p)
+   continue;
+
+   x = strchr(p, '\n');
+   if (x)
+   *x = '\0';
+
+   for (i = 0; i < strlen(p); i++)
+   p[i] = toupper(p[i]);
+
+   if (strcmp(p, mac))
+   continue;
+
+   /*
+* Found the MAC match.
+* A NIC (e.g. VF) matching the MAC, but without IP, is skipped.
+*/
+   if_name = entry->d_name;
+   if (!if_name)
+   continue;
+
+   error = kvp_get_ip_info(0, if_name, KVP_OP_GET_IP_INFO,
+   kvp_ip_val, MAX_IP_ADDR_SIZE * 2);
+
+   if (!error && strlen((char *)kvp_ip_val->ip_addr))
+   break;
+   }
+
+   closedir(dir);
+   return error;
+}
 
 static int expand_ipv6(char *addr, int type)
 {
@@ -1514,26 +1520,12 @@ int main(int argc, char *argv[])
switch (op) 

RE: [PATCH net v2] hv_netvsc: preserve hw_features on mtu/channels/ringparam changes

2017-11-15 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Wednesday, November 15, 2017 9:13 AM
> To: net...@vger.kernel.org
> Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org; KY
> Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; Mohammed Gamal <mmo...@redhat.com>
> Subject: [PATCH net v2] hv_netvsc: preserve hw_features on
> mtu/channels/ringparam changes
> 
> rndis_filter_device_add() is called both from netvsc_probe() when we
> initially create the device and from set channels/mtu/ringparam
> routines where we basically remove the device and add it back.
> 
> hw_features is reset in rndis_filter_device_add() and filled with
> host data. However, we lose all additional flags which are set outside
> of the driver, e.g. register_netdevice() adds NETIF_F_SOFT_FEATURES and
> many others.
> 
> Unfortunately, calls to rndis_{query_hwcaps(), _set_offload_params()}
> calls cannot be avoided on every RNDIS reset: host expects us to set
> required features explicitly. Moreover, in theory hardware capabilities
> can change and we need to reflect the change in hw_features.
> 
> Reset net->hw_features bits according to host data in
> rndis_netdev_set_hwcaps(), clear corresponding feature bits
> from net->features in case some features went missing (will never happen
> in real life I guess but let's be consistent).
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH net] hv_netvsc: preserve hw_features on mtu/channels/ringparam changes

2017-11-14 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, November 14, 2017 11:58 AM
> To: Stephen Hemminger <step...@networkplumber.org>
> Cc: net...@vger.kernel.org; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; KY Srinivasan <k...@microsoft.com>; Haiyang
> Zhang <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; Mohammed Gamal <mmo...@redhat.com>
> Subject: Re: [PATCH net] hv_netvsc: preserve hw_features on
> mtu/channels/ringparam changes
> 
> Stephen Hemminger <step...@networkplumber.org> writes:
> 
> > On Tue, 14 Nov 2017 16:22:05 +0100
> > Vitaly Kuznetsov <vkuzn...@redhat.com> wrote:
> >
> > Yes, this looks like a real issue.
> >
> >> +  /* Query hardware capabilities if we're called from netvsc_probe() */
> >> +  if (!net->hw_features) {
> >> +  ret = rndis_netdev_set_hwcaps(net_device, rndis_device);
> >> +  if (ret != 0)
> >> +  goto err_dev_remv;
> >> +  }
> >> +
> >
> > Rather than conditional behavior in rndis_filter_device_add, it would
> > be cleaner to make the call to get hardware capabilities there.
> >
> > Please respin and make the query of host a separate function.
> 
> You mean call rndis_netdev_set_hwcaps() from netvsc_probe()? Will do.
> 
> One question though: in case we'll be avoiding
> rndis_filter_set_offload_params() call on mtu/channels/ringparam changes -
> - can we trust the host to preserve what was there before the RNDIS reset?
> In case not we'll have to untangle what is
> rndis_netdev_set_hwcaps() in my patch splitting it into two: hw_features
> setup and rndis_filter_set_offload_params() and leaving the later in
> rndis_filter_device_add().

After remove/re-add RNDIS dev, you should pass the parameters to the host
again.

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


RE: [Revised PATCH v2] hv: kvp: Avoid reading past allocated blocks from KVP file

2017-11-08 Thread Haiyang Zhang


> -Original Message-
> From: Long Li [mailto:lon...@exchange.microsoft.com]
> Sent: Wednesday, November 1, 2017 2:45 PM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; de...@linuxdriverproject.org; linux-
> ker...@vger.kernel.org
> Cc: Paul Meyer <paul.me...@microsoft.com>; Long Li
> <lon...@microsoft.com>
> Subject: [Revised PATCH v2] hv: kvp: Avoid reading past allocated blocks
> from KVP file
> 
> [This sender failed our fraud detection checks and may not be who they
> appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]
> 
> From: Paul Meyer <paul.me...@microsoft.com>
> 
> While reading in more than one block (50) of KVP records, the allocation
> goes per block, but the reads used the total number of allocated records
> (without resetting the pointer/stream). This causes the records buffer to
> overrun when the refresh reads more than one block over the previous
> capacity (e.g. reading more than 100 KVP records whereas the in-memory
> database was empty before).
> 
> Fix this by reading the correct number of KVP records from file each time.
> 
> Changes since v1:
> 1. Properly wrapped comment texts.
> 2. Added the 2nd Signed-off-by.
> 
> Signed-off-by: Paul Meyer <paul.me...@microsoft.com>
> Signed-off-by: Long Li <lon...@microsoft.com>

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH] hv_netvsc: make const array ver_list static, reduces object code size

2017-09-22 Thread Haiyang Zhang


> -Original Message-
> From: Colin King [mailto:colin.k...@canonical.com]
> Sent: Friday, September 22, 2017 8:50 AM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> de...@linuxdriverproject.org; net...@vger.kernel.org
> Cc: kernel-janit...@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] hv_netvsc: make const array ver_list static, reduces
> object code size
> 
> From: Colin Ian King <colin.k...@canonical.com>
> 
> Don't populate const array ver_list on the stack, instead make it
> static. Makes the object code smaller by over 400 bytes:
> 
> Before:
>text  data bss dec hex filename
>   18444  3168 320   2193255ac
>   drivers/net/hyperv/netvsc.o
> 
> After:
>text  data bss dec hex filename
>   17950  3224 320   2149453f6
>   drivers/net/hyperv/netvsc.o
> 
> (gcc 6.3.0, x86-64)
> 
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>
> ---

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>


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


RE: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug

2017-09-06 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Wednesday, September 6, 2017 11:19 AM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>
> Cc: de...@linuxdriverproject.org; net...@vger.kernel.org
> Subject: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug
> 
> When a virtual device is added dynamically (via host console), then
> the vmbus sends an offer message for the primary channel. The processing
> of this message for networking causes the network device to then
> initialize the sub channels.
> 
> The problem is that setting up the sub channels needs to wait until
> the subsequent subchannel offers have been processed. These offers
> come in on the same ring buffer and work queue as where the primary
> offer is being processed; leading to a deadlock.
> 
> This did not happen in older kernels, because the sub channel waiting
> logic was broken (it wasn't really waiting).
> 
> The solution is to do the sub channel setup in its own work queue
> context that is scheduled by the primary channel setup; and then
> happens later.
> 
> Fixes: 732e49850c5e ("netvsc: fix race on sub channel creation")
> Reported-by: Dexuan Cui <de...@microsoft.com>
> Signed-off-by: Stephen Hemminger <sthem...@microsoft.com>
> ---
> Should also go to stable, but this version does not apply cleanly
> to 4.13. Have another patch for that.
> 
>  drivers/net/hyperv/hyperv_net.h   |   1 +
>  drivers/net/hyperv/netvsc_drv.c   |   8 +--
>  drivers/net/hyperv/rndis_filter.c | 106 ++-
> ---
>  3 files changed, 74 insertions(+), 41 deletions(-)

The patch looks overall. I just have a question:

With this patch, after module load and probe is done, there may still be
subchannels being processed. If rmmod immediately, the subchannel offers 
may hit half-way removed device structures... Do we also need to add 
cancel_work_sync(>subchan_work) to the top of netvsc_remove()?

unregister_netdevice() includes device close, but it's only called later
in the netvsc_remove() when rndis is already removed.

Thanks,
- Haiyang

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


RE: [PATCHv2] hv_set_ifconfig.sh double check before setting ip

2017-08-28 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Monday, August 28, 2017 11:16 AM
> To: Eduardo Otubo <ot...@redhat.com>
> Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org; Haiyang
> Zhang <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; David Miller <da...@davemloft.net>
> Subject: Re: [PATCHv2] hv_set_ifconfig.sh double check before setting ip
> 
> On Mon, 28 Aug 2017 12:01:21 +0200
> Eduardo Otubo <ot...@redhat.com> wrote:
> 
> > v2: The script is now a little bit safer so it doesn't conflicts with
> > network daemon trying to set configurations at the same time.
> >
> > This patch fixes the behavior of the hv_set_ifconfig script when
> setting
> > the interface ip. Sometimes the interface has already been configured
> by
> > network daemon, in this case hv_set_ifconfig causes "RTNETLINK: file
> > exists error"; in order to avoid this error this patch makes sure
> double
> > checks the interface before trying anything.
> >
> > Signed-off-by: Eduardo Otubo <ot...@redhat.com>
> 
> Adding new dependency on systemd is not going to make this script
> even less useful.  I wonder why the script still exists at all? Most of
> the
> Linux distro's can already setup HV networking without it.
> 

This script is used by a host to inject IP into guests. KY knows more 
details about it.


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


RE: [PATCH v1 4/6] vmbus: Switch to use new generic UUID API

2017-07-19 Thread Haiyang Zhang


> -Original Message-
> From: Andy Shevchenko [mailto:andriy.shevche...@linux.intel.com]
> Sent: Wednesday, July 19, 2017 2:29 PM
> To: linux-a...@vger.kernel.org; de...@linuxdriverproject.org;
> sparmaintai...@unisys.com; de...@driverdev.osuosl.org; linux-
> wirel...@vger.kernel.org; linux-watch...@vger.kernel.org; linux-
> e...@vger.kernel.org; Christoph Hellwig <h...@lst.de>; linux-
> ker...@vger.kernel.org; Lukas Wunner <lu...@wunner.de>
> Cc: Andy Shevchenko <andriy.shevche...@linux.intel.com>; KY Srinivasan
> <k...@microsoft.com>; Haiyang Zhang <haiya...@microsoft.com>; Stephen
> Hemminger <sthem...@microsoft.com>
> Subject: [PATCH v1 4/6] vmbus: Switch to use new generic UUID API
> 


> @@ -118,8 +116,8 @@ enum hv_fcopy_op {
> 
>  struct hv_fcopy_hdr {
>   __u32 operation;
> - uuid_le service_id0; /* currently unused */
> - uuid_le service_id1; /* currently unused */
> + __u8 service_id0[16]; /* currently unused */
> + __u8 service_id1[16]; /* currently unused */
>  } __attribute__((packed));

Even user space may not have all guid_t operations, could you still
put guid_t here for consistency? This file is also used by our kernel
mode code.

Thanks,
- Haiyang


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


RE: [PATCH net-next 3/8] netvsc: change order of steps in setting queues

2017-07-19 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Wednesday, July 19, 2017 2:53 PM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>
> Cc: de...@linuxdriverproject.org; net...@vger.kernel.org
> Subject: [PATCH net-next 3/8] netvsc: change order of steps in setting
> queues
> 
> This fixes the error unwind logic for incorrect number of queues.
> If netif_set_real_num_XX_queues failed then rndis_filter_device_add
> would have been called twice. Since input arguments are already
> ranged checked this is a hypothetical only problem, not possible
> in actual code.
> 
> Signed-off-by: Stephen Hemminger <sthem...@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc_drv.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc_drv.c
> b/drivers/net/hyperv/netvsc_drv.c
> index e8e82a6a4b1a..91637336d1fb 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -724,17 +724,15 @@ static int netvsc_set_queues(struct net_device
> *net, struct hv_device *dev,
>   device_info.ring_size = ring_size;
>   device_info.max_num_vrss_chns = num_chn;
> 
> - ret = rndis_filter_device_add(dev, _info);
> - if (ret)
> - return ret;
> -
>   ret = netif_set_real_num_tx_queues(net, num_chn);
>   if (ret)
>   return ret;
> 
>   ret = netif_set_real_num_rx_queues(net, num_chn);
> + if (ret)
> + return ret;
> 
> - return ret;
> + return rndis_filter_device_add(dev, _info);
>  }

The existing code has a bug here. After rndis_filter_device_add(),
the number of queues granted by the host may change:
net_device->num_chn = 1 +
init_packet->msg.v5_msg.subchn_comp.num_subchannels;
So we should call rndis_filter_device_add() first, then
assign net_device->num_chn to "real number tx queues".

Thanks,
- Haiyang

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


RE: [PATCH] netvsc: Remove redundant use of ipv6_hdr()

2017-07-19 Thread Haiyang Zhang


> -Original Message-
> From: Mohammed Gamal [mailto:mga...@redhat.com]
> Sent: Wednesday, July 19, 2017 1:48 PM
> To: Stephen Hemminger <step...@networkplumber.org>
> Cc: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> ot...@redhat.com; linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org; vkuzn...@redhat.com
> Subject: Re: [PATCH] netvsc: Remove redundant use of ipv6_hdr()
> 
> 
> 
> - Original Message -
> > On Wed, 19 Jul 2017 15:19:28 +0200
> > Mohammed Gamal <mga...@redhat.com> wrote:
> >
> > > This condition already uses an object of type ipv6hdr in the line
> above.
> > > Use the object directly instead of calling ipv6_hdr
> > >
> > > Signed-off-by: Mohammed Gamal <mga...@redhat.com>
> > > ---
> > >  drivers/net/hyperv/netvsc_drv.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > > b/drivers/net/hyperv/netvsc_drv.c
> > > index 63c98bb..06d591c 100644
> > > --- a/drivers/net/hyperv/netvsc_drv.c
> > > +++ b/drivers/net/hyperv/netvsc_drv.c
> > > @@ -339,7 +339,7 @@ static u32 net_checksum_info(struct sk_buff *skb)
> > >
> > >   if (ip6->nexthdr == IPPROTO_TCP)
> > >   return TRANSPORT_INFO_IPV6_TCP;
> > > - else if (ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
> > > + else if (ip6->nexthdr == IPPROTO_UDP)
> > >   return TRANSPORT_INFO_IPV6_UDP;
> > >   }
> > >
> >
> > Patch looks fine.
> > Network patches go through net...@vger.kernel.org not linux driver
> mailing
> > list.
> > I will add it to my next patch of patches that are going to netdev for
> > net-next.
> >
> Thanks for the heads up. Will take that into consideration next time.
> 
> It's worth pointing out that MAINTAINERS points that files under
> drivers/net/hyperv are to be sent to de...@linuxdriverproject.org.
> Perhaps that should be updated.

I will update de...@linuxdriverproject.org in MAINTAINERS to the new
mailing list name of the Linux driver project.

Thanks,
- Haiyang

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


RE: [PATCH] netvsc: Remove redundant use of ipv6_hdr()

2017-07-19 Thread Haiyang Zhang


> -Original Message-
> From: Mohammed Gamal [mailto:mga...@redhat.com]
> Sent: Wednesday, July 19, 2017 9:19 AM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org;
> vkuzn...@redhat.com; cav...@redhat.com; ot...@redhat.com; Mohammed Gamal
> <mga...@redhat.com>
> Subject: [PATCH] netvsc: Remove redundant use of ipv6_hdr()
> 
> This condition already uses an object of type ipv6hdr in the line above.
> Use the object directly instead of calling ipv6_hdr
> 
> Signed-off-by: Mohammed Gamal <mga...@redhat.com>

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH] netvsc: don't access netdev->num_rx_queues directly

2017-06-21 Thread Haiyang Zhang


> -Original Message-
> From: Arnd Bergmann [mailto:a...@arndb.de]
> Sent: Wednesday, June 21, 2017 6:17 PM
> To: Stephen Hemminger <sthem...@microsoft.com>
> Cc: Arnd Bergmann <a...@arndb.de>; KY Srinivasan <k...@microsoft.com>;
> Haiyang Zhang <haiya...@microsoft.com>; David S. Miller
> <da...@davemloft.net>; Simon Xiao <six...@microsoft.com>;
> de...@linuxdriverproject.org; net...@vger.kernel.org; linux-
> ker...@vger.kernel.org
> Subject: [PATCH] netvsc: don't access netdev->num_rx_queues directly
> 
> This structure member is hidden behind CONFIG_SYSFS, and we
> get a build error when that is disabled:
> 
> drivers/net/hyperv/netvsc_drv.c: In function 'netvsc_set_channels':
> drivers/net/hyperv/netvsc_drv.c:754:49: error: 'struct net_device' has
> no member named 'num_rx_queues'; did you mean 'num_tx_queues'?
> drivers/net/hyperv/netvsc_drv.c: In function 'netvsc_set_rxfh':
> drivers/net/hyperv/netvsc_drv.c:1181:25: error: 'struct net_device' has
> no member named 'num_rx_queues'; did you mean 'num_tx_queues'?
> 
> As the value is only set once to the argument of alloc_netdev_mq(),
> we can compare against that constant directly.
> 
> Fixes: ff4a44199012 ("netvsc: allow get/set of RSS indirection table")
> Fixes: 2b01888d1b45 ("netvsc: allow more flexible setting of number of
> channels")
> Signed-off-by: Arnd Bergmann <a...@arndb.de>

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH] pci-hyperv: Use only 16 bit integer for PCI domain

2017-05-24 Thread Haiyang Zhang


> -Original Message-
> From: Haiyang Zhang [mailto:haiya...@exchange.microsoft.com]
> Sent: Wednesday, May 24, 2017 4:39 PM
> To: bhelg...@google.com; linux-...@vger.kernel.org
> Cc: Haiyang Zhang <haiya...@microsoft.com>; KY Srinivasan
> <k...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> o...@aepfle.de; vkuzn...@redhat.com; driverdev-
> de...@linuxdriverproject.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] pci-hyperv: Use only 16 bit integer for PCI domain
> 
> [This sender failed our fraud detection checks and may not be who they
> appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]
> 
> From: Haiyang Zhang <haiya...@microsoft.com>
> 
> This patch uses the lower 16 bits of the serial number as PCI
> domain, otherwise some drivers may not be able to handle it.
> 
> Besides Nvidia drivers, we also found X.org, and DPDK handle
> only 16 bit PCI domain.
> 
> Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> ---

According to Stephen Hemminger <sthem...@microsoft.com>, there are
additional programs, like X.org, DPDK, are also using 16-bit only
PCI domain numbers. So, I'm submitting this patch for re-consideration.

Thanks,
- Haiyang

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


[PATCH] pci-hyperv: Use only 16 bit integer for PCI domain

2017-05-24 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

This patch uses the lower 16 bits of the serial number as PCI
domain, otherwise some drivers may not be able to handle it.

Besides Nvidia drivers, we also found X.org, and DPDK handle
only 16 bit PCI domain.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/pci/host/pci-hyperv.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 8493638..51a815d 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1335,9 +1335,11 @@ static void put_pcichild(struct hv_pci_dev *hpdev,
 * can have shorter names than based on the bus instance UUID.
 * Only the first device serial number is used for domain, so the
 * domain number will not change after the first device is added.
+* The lower 16 bits of the serial number is used, otherwise some
+* drivers may not be able to handle it.
 */
if (list_empty(>children))
-   hbus->sysdata.domain = desc->ser;
+   hbus->sysdata.domain = desc->ser & 0x;
list_add_tail(>list_entry, >children);
spin_unlock_irqrestore(>device_list_lock, flags);
return hpdev;
-- 
1.7.1

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


RE: [PATCH] pci-hyperv: Use only 16 bit integer for PCI domain

2017-04-20 Thread Haiyang Zhang
> -Original Message-
> From: Bjorn Helgaas [mailto:bhelg...@google.com]
> Sent: Thursday, April 20, 2017 2:33 PM
> To: Haiyang Zhang <haiya...@microsoft.com>
> Cc: linux-...@vger.kernel.org; KY Srinivasan <k...@microsoft.com>;
> Stephen Hemminger <sthem...@microsoft.com>; o...@aepfle.de;
> vkuzn...@redhat.com; driverdev-devel@linuxdriverproject.org; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH] pci-hyperv: Use only 16 bit integer for PCI domain
> 
> On Thu, Apr 20, 2017 at 11:35 AM, Haiyang Zhang
> <haiya...@exchange.microsoft.com> wrote:
> > From: Haiyang Zhang <haiya...@microsoft.com>
> >
> > This patch uses the lower 16 bits of the serial number as PCI
> > domain, otherwise some drivers may not be able to handle it.
> 
> Can you give any more details about this?  Which drivers, for
> instance?  Why do drivers care about the domain at all?  Can we or
> should we make this more explicit and consistent in the PCI core,
> e.g., pci_domain_nr() is currently defined to return "int"; maybe it
> should be u32?  (Although I think "int" is the same size as "u32" on
> all arches anyway).

It's Nvidia driver.

Piotr, could you explain why the driver expects 16 bit domain number?

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


[PATCH] pci-hyperv: Use only 16 bit integer for PCI domain

2017-04-20 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

This patch uses the lower 16 bits of the serial number as PCI
domain, otherwise some drivers may not be able to handle it.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
---
 drivers/pci/host/pci-hyperv.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index e73880c..b18dff3 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1334,9 +1334,11 @@ static void put_pcichild(struct hv_pci_dev *hpdev,
 * can have shorter names than based on the bus instance UUID.
 * Only the first device serial number is used for domain, so the
 * domain number will not change after the first device is added.
+* The lower 16 bits of the serial number is used, otherwise some
+* drivers may not be able to handle it.
 */
if (list_empty(>children))
-   hbus->sysdata.domain = desc->ser;
+   hbus->sysdata.domain = desc->ser & 0x;
list_add_tail(>list_entry, >children);
spin_unlock_irqrestore(>device_list_lock, flags);
return hpdev;
-- 
1.7.1

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


RE: [PATCH] netvsc: fix dereference before null check errors

2017-03-26 Thread Haiyang Zhang


> -Original Message-
> From: Colin King [mailto:colin.k...@canonical.com]
> Sent: Saturday, March 25, 2017 10:27 AM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> de...@linuxdriverproject.org; net...@vger.kernel.org
> Cc: kernel-janit...@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] netvsc: fix dereference before null check errors
> 
> From: Colin Ian King <colin.k...@canonical.com>
> 
> ndev is being checked to see if it is a null pointer however before
> the null check ndev is being dereferenced; hence there is a potential
> null pointer dereference bug that needs fixing. Fix this by only
> dereferencing ndev after the null check.
> 
> Detected by CoverityScan, CID#1420760, CID#140761 ("Dereference
> before null check")
> 
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCH] netvsc: fix unititialized return value in variable ret

2017-03-26 Thread Haiyang Zhang


> -Original Message-
> From: Colin King [mailto:colin.k...@canonical.com]
> Sent: Saturday, March 25, 2017 10:17 AM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger <sthem...@microsoft.com>;
> de...@linuxdriverproject.org; net...@vger.kernel.org
> Cc: kernel-janit...@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] netvsc: fix unititialized return value in variable ret
> 
> From: Colin Ian King <colin.k...@canonical.com>
> 
> It is possible for an uninitialized value of ret to be returned
> so fix this by initializing ret to zero.
> 
> Detected by CoverityScan, CID#1420762 ("Uninitialized scalar variable")
> 
> Fixes: 163891d7d429 ("netvsc: handle offline mtu and channel change")
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>
> ---
>  drivers/net/hyperv/netvsc_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/hyperv/netvsc_drv.c
> b/drivers/net/hyperv/netvsc_drv.c
> index eb7ae79d47bb..f830bbbd8ad4 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -855,7 +855,7 @@ static int netvsc_change_mtu(struct net_device *ndev,
> int mtu)
>   struct hv_device *hdev = ndevctx->device_ctx;
>   struct netvsc_device_info device_info;
>   bool was_running;
> - int ret;
> + int ret = 0;

This was just fix by commit: 386f57622cc3bbb39b9c00fc8762bc9ab28e0f8d

Thanks.


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


[PATCH] pci-hyperv: Use device serial number as PCI domain

2017-02-13 Thread Haiyang Zhang

This allows PCI domain numbers starts with 1, and also unique
on the same VM. So names, such as VF NIC names, that include
domain number as part of the name, can be shorter than that
based on part of bus UUID previously. The new names will also
stay same for VMs created with copied VHD and same number of
devices.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
Reviewed-by: K. Y. Srinivasan <k...@microsoft.com>

---
 drivers/pci/host/pci-hyperv.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 3efcc7b..b92b565 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -1315,6 +1315,16 @@ static void put_pcichild(struct hv_pci_dev *hpdev,
get_pcichild(hpdev, hv_pcidev_ref_initial);
get_pcichild(hpdev, hv_pcidev_ref_childlist);
spin_lock_irqsave(>device_list_lock, flags);
+   /* When a device is being added into the bus, we set the PCI domain
+* number to be the device serial number, which is non zero and
+* unique on the same VM. The serial numbers start with 1, and
+* increase by 1 for each device. So device names including this
+* can have shorter names than based on the bus instance UUID.
+* Only the first device serial number is used for domain, so the
+* domain number will not change after the first device is added.
+*/
+   if (list_empty(>children))
+   hbus->sysdata.domain = desc->ser;
list_add_tail(>list_entry, >children);
spin_unlock_irqrestore(>device_list_lock, flags);
return hpdev;
-- 
1.7.1

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


RE: [PATCH] PCI: hv: fix wslot_to_devfn()

2017-02-07 Thread Haiyang Zhang


> -Original Message-
> From: Dexuan Cui
> Sent: Tuesday, February 7, 2017 4:00 AM
> To: Bjorn Helgaas <bhelg...@google.com>; linux-...@vger.kernel.org;
> de...@linuxdriverproject.org; Jake Oshins <ja...@microsoft.com>
> Cc: KY Srinivasan <k...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>; Haiyang Zhang <haiya...@microsoft.com>;
> o...@aepfle.de; gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> a...@canonical.com; jasow...@redhat.com; Vitaly Kuznetsov
> <vkuzn...@redhat.com>
> Subject: [PATCH] PCI: hv: fix wslot_to_devfn()
> 
> The devfn of 00:02.0 is 0x10.
> devfn_to_wslot(0x10) == 0x2, and wslot_to_devfn(0x2) should be 0x10,
> while it's 0x2 in the current code.
> 
> Due to this, hv_eject_device_work() -> pci_get_domain_bus_and_slot()
> returns NULL and pci_stop_and_remove_bus_device() is not called.
> 
> Later when the real device driver's .remove() is invoked by
> hv_pci_remove() -> pci_stop_root_bus(), some warnings can be noticed
> because the VM has lost the access to the underlying device at that time.
> 
> Signed-off-by: Jake Oshins <ja...@microsoft.com>
> Signed-off-by: Dexuan Cui <de...@microsoft.com>
> Cc: sta...@vger.kernel.org
> Cc: K. Y. Srinivasan <k...@microsoft.com>
> CC: Haiyang Zhang <haiya...@microsoft.com>
> Cc: Stephen Hemminger <sthem...@microsoft.com>
> ---
>  drivers/pci/host/pci-hyperv.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> The patch is co-made by Jake and me.

I think this line should be put together with other comments.

Thanks.
Acked-by: Haiyang Zhang <haiya...@microsoft.com>

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


RE: [PATCHv1] net-next: treewide use is_vlan_dev() helper function.

2017-02-06 Thread Haiyang Zhang


> -Original Message-
> From: Parav Pandit [mailto:pa...@mellanox.com]
> Sent: Saturday, February 4, 2017 12:01 PM
> To: dledf...@redhat.com; Sean Hefty <sean.he...@intel.com>;
> hal.rosenst...@gmail.com; mo...@mellanox.com; sant...@chelsio.com;
> ganes...@chelsio.com; manish.cho...@cavium.com; rahul.ve...@cavium.com;
> dept-gelinuxnic...@cavium.com; harish.pa...@cavium.com; KY Srinivasan
> <k...@microsoft.com>; Haiyang Zhang <haiya...@microsoft.com>; Stephen
> Hemminger <sthem...@microsoft.com>; qlogic-storage-upstr...@qlogic.com;
> j...@linux.vnet.ibm.com; martin.peter...@oracle.com; j...@kernel.org;
> arvid.bro...@alten.se; da...@davemloft.net; l...@kernel.org;
> s...@grimberg.me; sw...@opengridcomputing.com;
> bart.vanass...@sandisk.com; va...@mellanox.com; a...@arndb.de;
> weiyj...@gmail.com; jmaxwel...@gmail.com; va...@chelsio.com;
> jb...@redhat.com; linux-r...@vger.kernel.org; net...@vger.kernel.org;
> de...@linuxdriverproject.org; linux-s...@vger.kernel.org; fcoe-
> de...@open-fcoe.org
> Cc: Parav Pandit <pa...@mellanox.com>
> Subject: [PATCHv1] net-next: treewide use is_vlan_dev() helper function.
> 
> This patch makes use of is_vlan_dev() function instead of flag
> comparison which is exactly done by is_vlan_dev() helper function.
> 
> Signed-off-by: Parav Pandit <pa...@mellanox.com>
> Reviewed-by: Daniel Jurgens <dani...@mellanox.com>


For drivers/net/hyperv/netvsc_drv.c
Acked-by: Haiyang Zhang <haiya...@microsoft.com>


Thanks.

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


RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-16 Thread Haiyang Zhang


> -Original Message-
> From: KY Srinivasan
> Sent: Thursday, December 15, 2016 8:11 PM
> To: Stephen Hemminger <step...@networkplumber.org>; Greg KH
> <gre...@linuxfoundation.org>
> Cc: o...@aepfle.de; jasow...@redhat.com; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com; Haiyang Zhang <haiya...@microsoft.com>
> Subject: RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> 
> 
> > -Original Message-
> > From: devel [mailto:driverdev-devel-boun...@linuxdriverproject.org] On
> > Behalf Of Stephen Hemminger
> > Sent: Wednesday, December 14, 2016 3:52 PM
> > To: Greg KH <gre...@linuxfoundation.org>
> > Cc: o...@aepfle.de; jasow...@redhat.com; linux-ker...@vger.kernel.org;
> > bjorn.helg...@gmail.com; a...@canonical.com;
> > de...@linuxdriverproject.org; leann.ogasaw...@canonical.com; Haiyang
> > Zhang <haiya...@microsoft.com>
> > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial
> > numbers
> >
> > Normally, that would work but in this case we have one driver (netvsc)
> > which is managing another driver which is unaware of Hyper-V or netvsc
> > drivers existence.  The callback is happening in netvsc driver and it
> > needs to say "hey I know that SR-IOV device, it is associated with my
> > network device". This problem is how to know that N is associated with
> > V? The V device has to be a network device, that is easy. But then it
> > also has to be a PCI device, not to bad. But then the netvsc code
> > is matching based on hyper-V only PCI bus metadata (the serial #).
> >
> > The Microsoft developers made the rational decision not to go
> modifying
> > all the possible SR-IOV network devices from Intel and Mellanox to add
> > the functionality there. That would have been much worse.
> >
> > Maybe, rather than trying to do the management in the kernel it
> > could have been done better in user space. Unfortunately, this would
> > only move the problem.  The PCI-hyperv host driver could expose serial
> > value through sysfs (with some pain). But the problem would be how
> > to make a new API to  join the two V and N device.  Doing a private
> > ioctl is worse than the notifier.
> 
> All this has been discussed earlier in the thread. I think I have a
> solution
> to the problem:
> The only PCI (non-VF) NIC that may be present in the VM is the emulated
> NIC and
> we know exactly the device ID and vendor ID of this NIC. Furthermore,
> as a platform we are not going to be emulating additional NICs. So,
> if the PCI NIC is not the emulated NIC, it must be a VF and we can
> extract the
> serial number.

How about direct pass-through NIC devices. Do they have vPCI serial number?
And, the numbers should be different from VF NIC?

Thanks,
- Haiyang

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


RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-14 Thread Haiyang Zhang


> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Saturday, December 10, 2016 7:21 AM
> To: Stephen Hemminger <step...@networkplumber.org>
> Cc: Haiyang Zhang <haiya...@microsoft.com>; o...@aepfle.de;
> jasow...@redhat.com; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com
> Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> On Fri, Dec 09, 2016 at 04:21:48PM -0800, Stephen Hemminger wrote:
> > On Fri, 9 Dec 2016 22:35:05 +
> > Haiyang Zhang <haiya...@microsoft.com> wrote:
> >
> > > > > >
> > > > > > Emulated NIC is already excluded in start of netvc notifier
> handler.
> > > > > >
> > > > > > static int netvsc_netdev_event(struct notifier_block *this,
> > > > > >unsigned long event, void *ptr)
> > > > > > {
> > > > > > struct net_device *event_dev =
> netdev_notifier_info_to_dev(ptr);
> > > > > >
> > > > > > /* Skip our own events */
> > > > > > if (event_dev->netdev_ops == _ops)
> > > > > > return NOTIFY_DONE;
> > > > > >
> > > > >
> > > > > Emulated device is not based on netvsc. It's the native Linux
> > > > (dec100M?)
> > > > > Driver. So this line doesn't exclude it. And how about other NIC
> type
> > > > > may be added in the future?
> > > >
> > > > Sorry, forgot about that haven't used emulated device in years.
> > > > The emulated device should appear to be on a PCI bus, but the
> serial
> > > > would not match??
> > >
> > > It's not a vmbus device, not a hv_pci device either. Hv_PCI is a
> subset
> > > of vmbus devices. So emulated NIC won't have hv_pci serial number.
> > >
> > > In my patch, the following code ensure, we only try to get serial
> number
> > > after confirming it's vmbus and hv_pci device:
> > >
> > > +   if (!dev_is_vmbus(dev))
> > > +   continue;
> > > +
> > > +   hdev = device_to_hv_device(dev);
> > > +   if (hdev->device_id != HV_PCIE)
> > > +   continue;
> >
> > Ok, the walk back up the device tree is logically ok, but I don't
> > know enough about PCI device tree to be assured that it is safe.
> > Also, you could short circuit away most of the unwanted devices
> > by making sure the vf_netdev->dev.parent is a PCI device.
> 
> Ugh, this seems really really messy.  Can't we just have the
> netdev_event interface pass back a pointer to something that we "know"
> what it is?  This walking the device tree is a mess, and not good.
> 
> I'd even argue that dev_is_pci() needs to be removed from the tree too,
> as it shouldn't be needed either.  We did a lot of work on the driver
> model to prevent the need for having to declare the "type" of 'struct
> device' at all, and by doing this type of thing it goes against the
> basic design of the model.
> 
> Yes, it makes things a bit "tougher" in places, but you don't do crazy
> things like walk device trees to try to find random devices and then
> think it's safe to actually use them :(
> 

We register a notifier_block with:
register_netdevice_notifier(struct notifier_block *nb)

The "struct notifier_block" basically contains a callback function:
struct notifier_block {
notifier_fn_t notifier_call;
struct notifier_block __rcu *next;
int priority;
};

It doesn't specify which device we want, so all net devices can trigger
this event. Seems we can't have this notifier return VF device only.

Thanks,
- Haiyang

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


RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-09 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Friday, December 9, 2016 5:05 PM
> To: Haiyang Zhang <haiya...@microsoft.com>
> Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> <k...@microsoft.com>; o...@aepfle.de; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com; jasow...@redhat.com
> Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> On Fri, 9 Dec 2016 21:53:49 +
> Haiyang Zhang <haiya...@microsoft.com> wrote:
> 
> > > -Original Message-
> > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > Sent: Friday, December 9, 2016 4:45 PM
> > > To: Haiyang Zhang <haiya...@microsoft.com>
> > > Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> > > <k...@microsoft.com>; o...@aepfle.de; linux-ker...@vger.kernel.org;
> > > bjorn.helg...@gmail.com; a...@canonical.com;
> de...@linuxdriverproject.org;
> > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> > > serial numbers
> > >
> > > On Fri, 9 Dec 2016 21:31:25 +
> > > Haiyang Zhang <haiya...@microsoft.com> wrote:
> > >
> > > > > -Original Message-
> > > > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > > > Sent: Friday, December 9, 2016 3:30 PM
> > > > > To: Haiyang Zhang <haiya...@microsoft.com>
> > > > > Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> > > > > <k...@microsoft.com>; o...@aepfle.de; linux-
> ker...@vger.kernel.org;
> > > > > bjorn.helg...@gmail.com; a...@canonical.com;
> > > de...@linuxdriverproject.org;
> > > > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based
> on
> > > > > serial numbers
> > > > >
> > > > > On Fri, 9 Dec 2016 20:09:49 +
> > > > > Haiyang Zhang <haiya...@microsoft.com> wrote:
> > > > >
> > > > > > > -Original Message-
> > > > > > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > > > > > Sent: Friday, December 9, 2016 1:21 PM
> > > > > > > To: Greg KH <gre...@linuxfoundation.org>
> > > > > > > Cc: KY Srinivasan <k...@microsoft.com>; o...@aepfle.de;
> Haiyang
> > > Zhang
> > > > > > > <haiya...@microsoft.com>; linux-ker...@vger.kernel.org;
> > > > > > > bjorn.helg...@gmail.com; a...@canonical.com;
> > > > > de...@linuxdriverproject.org;
> > > > > > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching
> based
> > > on
> > > > > > > serial numbers
> > > > > > >
> > > > > > > On Fri, 9 Dec 2016 08:31:22 +0100
> > > > > > > Greg KH <gre...@linuxfoundation.org> wrote:
> > > > > > >
> > > > > > > > On Fri, Dec 09, 2016 at 12:05:53AM +, KY Srinivasan
> wrote:
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > > -Original Message-
> > > > > > > > > > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > > > > > > > > > Sent: Thursday, December 8, 2016 7:56 AM
> > > > > > > > > > To: KY Srinivasan <k...@microsoft.com>
> > > > > > > > > > Cc: linux-ker...@vger.kernel.org;
> > > de...@linuxdriverproject.org;
> > > > > > > > > > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > > > > > > > > > jasow...@redhat.com; leann.ogasaw...@canonical.com;
> > > > > > > > > > bjorn.helg...@gmail.com; Haiyang Zhang
> > > <haiya...@microsoft.com>
> > > > > > > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF
> matching
> > > > > based on
> > > > > > > serial
> > > > > > > > > > numbers
> > > > > > > > > >
> > > > > &g

RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-09 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Friday, December 9, 2016 4:45 PM
> To: Haiyang Zhang <haiya...@microsoft.com>
> Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> <k...@microsoft.com>; o...@aepfle.de; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com; jasow...@redhat.com
> Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> On Fri, 9 Dec 2016 21:31:25 +
> Haiyang Zhang <haiya...@microsoft.com> wrote:
> 
> > > -Original Message-
> > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > Sent: Friday, December 9, 2016 3:30 PM
> > > To: Haiyang Zhang <haiya...@microsoft.com>
> > > Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> > > <k...@microsoft.com>; o...@aepfle.de; linux-ker...@vger.kernel.org;
> > > bjorn.helg...@gmail.com; a...@canonical.com;
> de...@linuxdriverproject.org;
> > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> > > serial numbers
> > >
> > > On Fri, 9 Dec 2016 20:09:49 +
> > > Haiyang Zhang <haiya...@microsoft.com> wrote:
> > >
> > > > > -Original Message-
> > > > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > > > Sent: Friday, December 9, 2016 1:21 PM
> > > > > To: Greg KH <gre...@linuxfoundation.org>
> > > > > Cc: KY Srinivasan <k...@microsoft.com>; o...@aepfle.de; Haiyang
> Zhang
> > > > > <haiya...@microsoft.com>; linux-ker...@vger.kernel.org;
> > > > > bjorn.helg...@gmail.com; a...@canonical.com;
> > > de...@linuxdriverproject.org;
> > > > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based
> on
> > > > > serial numbers
> > > > >
> > > > > On Fri, 9 Dec 2016 08:31:22 +0100
> > > > > Greg KH <gre...@linuxfoundation.org> wrote:
> > > > >
> > > > > > On Fri, Dec 09, 2016 at 12:05:53AM +, KY Srinivasan wrote:
> > > > > > >
> > > > > > >
> > > > > > > > -Original Message-
> > > > > > > > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > > > > > > > Sent: Thursday, December 8, 2016 7:56 AM
> > > > > > > > To: KY Srinivasan <k...@microsoft.com>
> > > > > > > > Cc: linux-ker...@vger.kernel.org;
> de...@linuxdriverproject.org;
> > > > > > > > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > > > > > > > jasow...@redhat.com; leann.ogasaw...@canonical.com;
> > > > > > > > bjorn.helg...@gmail.com; Haiyang Zhang
> <haiya...@microsoft.com>
> > > > > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching
> > > based on
> > > > > serial
> > > > > > > > numbers
> > > > > > > >
> > > > > > > > On Thu, Dec 08, 2016 at 12:33:43AM -0800,
> > > > > k...@exchange.microsoft.com
> > > > > > > > wrote:
> > > > > > > > > From: Haiyang Zhang <haiya...@microsoft.com>
> > > > > > > > >
> > > > > > > > > We currently use MAC address to match VF and synthetic
> NICs.
> > > > > Hyper-V
> > > > > > > > > provides a serial number to both devices for this
> purpose.
> > > This
> > > > > patch
> > > > > > > > > implements the matching based on VF serial numbers. This
> is
> > > the
> > > > > way
> > > > > > > > > specified by the protocol and more reliable.
> > > > > > > > >
> > > > > > > > > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > > > > > > > > Signed-off-by: K. Y. Srinivasan <k...@microsoft.com>
> > > > > > > > > ---
> > > > > > > > >  drivers/net/hyperv/netvsc_drv.c |   55
> > > > > > > > ---
> > > > > > >

RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-09 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Friday, December 9, 2016 3:30 PM
> To: Haiyang Zhang <haiya...@microsoft.com>
> Cc: Greg KH <gre...@linuxfoundation.org>; KY Srinivasan
> <k...@microsoft.com>; o...@aepfle.de; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com; jasow...@redhat.com
> Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> On Fri, 9 Dec 2016 20:09:49 +
> Haiyang Zhang <haiya...@microsoft.com> wrote:
> 
> > > -Original Message-
> > > From: Stephen Hemminger [mailto:step...@networkplumber.org]
> > > Sent: Friday, December 9, 2016 1:21 PM
> > > To: Greg KH <gre...@linuxfoundation.org>
> > > Cc: KY Srinivasan <k...@microsoft.com>; o...@aepfle.de; Haiyang Zhang
> > > <haiya...@microsoft.com>; linux-ker...@vger.kernel.org;
> > > bjorn.helg...@gmail.com; a...@canonical.com;
> de...@linuxdriverproject.org;
> > > leann.ogasaw...@canonical.com; jasow...@redhat.com
> > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> > > serial numbers
> > >
> > > On Fri, 9 Dec 2016 08:31:22 +0100
> > > Greg KH <gre...@linuxfoundation.org> wrote:
> > >
> > > > On Fri, Dec 09, 2016 at 12:05:53AM +, KY Srinivasan wrote:
> > > > >
> > > > >
> > > > > > -Original Message-
> > > > > > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > > > > > Sent: Thursday, December 8, 2016 7:56 AM
> > > > > > To: KY Srinivasan <k...@microsoft.com>
> > > > > > Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > > > > > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > > > > > jasow...@redhat.com; leann.ogasaw...@canonical.com;
> > > > > > bjorn.helg...@gmail.com; Haiyang Zhang <haiya...@microsoft.com>
> > > > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching
> based on
> > > serial
> > > > > > numbers
> > > > > >
> > > > > > On Thu, Dec 08, 2016 at 12:33:43AM -0800,
> > > k...@exchange.microsoft.com
> > > > > > wrote:
> > > > > > > From: Haiyang Zhang <haiya...@microsoft.com>
> > > > > > >
> > > > > > > We currently use MAC address to match VF and synthetic NICs.
> > > Hyper-V
> > > > > > > provides a serial number to both devices for this purpose.
> This
> > > patch
> > > > > > > implements the matching based on VF serial numbers. This is
> the
> > > way
> > > > > > > specified by the protocol and more reliable.
> > > > > > >
> > > > > > > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > > > > > > Signed-off-by: K. Y. Srinivasan <k...@microsoft.com>
> > > > > > > ---
> > > > > > >  drivers/net/hyperv/netvsc_drv.c |   55
> > > > > > ---
> > > > > > >  1 files changed, 51 insertions(+), 4 deletions(-)
> > > > > > >
> > > > > > > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > > > > > b/drivers/net/hyperv/netvsc_drv.c
> > > > > > > index 9522763..c5778cf 100644
> > > > > > > --- a/drivers/net/hyperv/netvsc_drv.c
> > > > > > > +++ b/drivers/net/hyperv/netvsc_drv.c
> > > > > > > @@ -1165,9 +1165,10 @@ static void netvsc_free_netdev(struct
> > > > > > net_device *netdev)
> > > > > > >   free_netdev(netdev);
> > > > > > >  }
> > > > > > >
> > > > > > > -static struct net_device *get_netvsc_bymac(const u8 *mac)
> > > > > > > +static struct net_device *get_netvsc_byvfser(u32 vfser)
> > > > > > >  {
> > > > > > >   struct net_device *dev;
> > > > > > > + struct net_device_context *ndev_ctx;
> > > > > > >
> > > > > > >   ASSERT_RTNL();
> > > > > > >
> > > > > > > @@ -1175,7 +1176,8 @@ static void netvsc_free_netdev(struct
> > > net_device
> > > > > > *netdev)
&

RE: [PATCH 3/3] hv_netvsc: Implement VF matching based on serial numbers

2016-12-09 Thread Haiyang Zhang


> -Original Message-
> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Friday, December 9, 2016 1:21 PM
> To: Greg KH <gre...@linuxfoundation.org>
> Cc: KY Srinivasan <k...@microsoft.com>; o...@aepfle.de; Haiyang Zhang
> <haiya...@microsoft.com>; linux-ker...@vger.kernel.org;
> bjorn.helg...@gmail.com; a...@canonical.com; de...@linuxdriverproject.org;
> leann.ogasaw...@canonical.com; jasow...@redhat.com
> Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial numbers
> 
> On Fri, 9 Dec 2016 08:31:22 +0100
> Greg KH <gre...@linuxfoundation.org> wrote:
> 
> > On Fri, Dec 09, 2016 at 12:05:53AM +, KY Srinivasan wrote:
> > >
> > >
> > > > -Original Message-
> > > > From: Greg KH [mailto:gre...@linuxfoundation.org]
> > > > Sent: Thursday, December 8, 2016 7:56 AM
> > > > To: KY Srinivasan <k...@microsoft.com>
> > > > Cc: linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > > > o...@aepfle.de; a...@canonical.com; vkuzn...@redhat.com;
> > > > jasow...@redhat.com; leann.ogasaw...@canonical.com;
> > > > bjorn.helg...@gmail.com; Haiyang Zhang <haiya...@microsoft.com>
> > > > Subject: Re: [PATCH 3/3] hv_netvsc: Implement VF matching based on
> serial
> > > > numbers
> > > >
> > > > On Thu, Dec 08, 2016 at 12:33:43AM -0800,
> k...@exchange.microsoft.com
> > > > wrote:
> > > > > From: Haiyang Zhang <haiya...@microsoft.com>
> > > > >
> > > > > We currently use MAC address to match VF and synthetic NICs.
> Hyper-V
> > > > > provides a serial number to both devices for this purpose. This
> patch
> > > > > implements the matching based on VF serial numbers. This is the
> way
> > > > > specified by the protocol and more reliable.
> > > > >
> > > > > Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
> > > > > Signed-off-by: K. Y. Srinivasan <k...@microsoft.com>
> > > > > ---
> > > > >  drivers/net/hyperv/netvsc_drv.c |   55
> > > > ---
> > > > >  1 files changed, 51 insertions(+), 4 deletions(-)
> > > > >
> > > > > diff --git a/drivers/net/hyperv/netvsc_drv.c
> > > > b/drivers/net/hyperv/netvsc_drv.c
> > > > > index 9522763..c5778cf 100644
> > > > > --- a/drivers/net/hyperv/netvsc_drv.c
> > > > > +++ b/drivers/net/hyperv/netvsc_drv.c
> > > > > @@ -1165,9 +1165,10 @@ static void netvsc_free_netdev(struct
> > > > net_device *netdev)
> > > > >   free_netdev(netdev);
> > > > >  }
> > > > >
> > > > > -static struct net_device *get_netvsc_bymac(const u8 *mac)
> > > > > +static struct net_device *get_netvsc_byvfser(u32 vfser)
> > > > >  {
> > > > >   struct net_device *dev;
> > > > > + struct net_device_context *ndev_ctx;
> > > > >
> > > > >   ASSERT_RTNL();
> > > > >
> > > > > @@ -1175,7 +1176,8 @@ static void netvsc_free_netdev(struct
> net_device
> > > > *netdev)
> > > > >   if (dev->netdev_ops != _ops)
> > > > >   continue;   /* not a netvsc device */
> > > > >
> > > > > - if (ether_addr_equal(mac, dev->perm_addr))
> > > > > + ndev_ctx = netdev_priv(dev);
> > > > > + if (ndev_ctx->vf_serial == vfser)
> > > > >   return dev;
> > > > >   }
> > > > >
> > > > > @@ -1205,21 +1207,66 @@ static void netvsc_free_netdev(struct
> > > > net_device *netdev)
> > > > >   return NULL;
> > > > >  }
> > > > >
> > > > > +static u32 netvsc_get_vfser(struct net_device *vf_netdev)
> > > > > +{
> > > > > + struct device *dev;
> > > > > + struct hv_device *hdev;
> > > > > + struct hv_pcibus_device *hbus = NULL;
> > > > > + struct list_head *iter;
> > > > > + struct hv_pci_dev *hpdev;
> > > > > + unsigned long flags;
> > > > > + u32 vfser = 0;
> > > > > + u32 count = 0;
> > > > > +
> > > > > + for (dev = _netdev-&g

[PATCH net-next] tools: hv: Enable network manager for bonding scripts on RHEL

2016-12-02 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

We found network manager is necessary on RHEL to make the synthetic
NIC, VF NIC bonding operations handled automatically. So, enabling
network manager here.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
Reviewed-by: K. Y. Srinivasan <k...@microsoft.com>
---
 tools/hv/bondvf.sh |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/hv/bondvf.sh b/tools/hv/bondvf.sh
index 8e96023..4aa5369 100755
--- a/tools/hv/bondvf.sh
+++ b/tools/hv/bondvf.sh
@@ -74,8 +74,8 @@ function create_eth_cfg_redhat {
echo DEVICE=$1 >>$fn
echo TYPE=Ethernet >>$fn
echo BOOTPROTO=none >>$fn
+   echo UUID=`uuidgen` >>$fn
echo ONBOOT=yes >>$fn
-   echo NM_CONTROLLED=no >>$fn
echo PEERDNS=yes >>$fn
echo IPV6INIT=yes >>$fn
echo MASTER=$2 >>$fn
@@ -93,8 +93,8 @@ function create_bond_cfg_redhat {
echo DEVICE=$1 >>$fn
echo TYPE=Bond >>$fn
echo BOOTPROTO=dhcp >>$fn
+   echo UUID=`uuidgen` >>$fn
echo ONBOOT=yes >>$fn
-   echo NM_CONTROLLED=no >>$fn
echo PEERDNS=yes >>$fn
echo IPV6INIT=yes >>$fn
echo BONDING_MASTER=yes >>$fn
-- 
1.7.4.1

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


RE: [PATCH v2] Drivers: hv: vmbus: Raise retry/wait limits in vmbus_post_msg()

2016-11-01 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Tuesday, November 1, 2016 9:34 AM
> To: de...@linuxdriverproject.org
> Cc: linux-ker...@vger.kernel.org; KY Srinivasan <k...@microsoft.com>;
> Haiyang Zhang <haiya...@microsoft.com>; Van De Ven, Arjan
> <arjan.van.de@intel.com>
> Subject: [PATCH v2] Drivers: hv: vmbus: Raise retry/wait limits in
> vmbus_post_msg()
> 
> DoS protection conditions were altered in WS2016 and now it's easy to
> get
> -EAGAIN returned from vmbus_post_msg() (e.g. when we try changing MTU on
> a
> netvsc device in a loop). All vmbus_post_msg() callers don't retry the
> operation and we usually end up with a non-functional device or crash.
> 
> While host's DoS protection conditions are unknown to me my tests show
> that
> it can take up to 10 seconds before the message is sent so doing udelay()
> is not an option, we really need to sleep. Almost all vmbus_post_msg()
> callers are ready to sleep but there is one special case:
> vmbus_initiate_unload() which can be called from interrupt/NMI context
> and
> we can't sleep there. I'm also not sure about the lonely
> vmbus_send_tl_connect_request() which has no in-tree users but its
> external
> users are most likely waiting for the host to reply so sleeping there is
> also appropriate.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>
> ---
> - Changes since v1: keep microsecods delays and udelay() for first
> attempts
>   [KY Srinivasan, Arjan Van De Ven]
> ---
>  drivers/hv/channel.c  | 17 +
>  drivers/hv/channel_mgmt.c | 10 ++
>  drivers/hv/connection.c   | 17 ++++-
>  drivers/hv/hyperv_vmbus.h |  2 +-
>  4 files changed, 28 insertions(+), 18 deletions(-)
> 

Thank you.

Reviewed-by: Haiyang Zhang <haiya...@microsoft.com>


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


RE: [PATCH] Drivers: hv: vmbus: Raise retry/wait limits in vmbus_post_msg()

2016-10-26 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Wednesday, October 26, 2016 7:12 AM
> To: de...@linuxdriverproject.org
> Cc: linux-ker...@vger.kernel.org; KY Srinivasan <k...@microsoft.com>;
> Haiyang Zhang <haiya...@microsoft.com>
> Subject: [PATCH] Drivers: hv: vmbus: Raise retry/wait limits in
> vmbus_post_msg()
> 
> DoS protection conditions were altered in WS2016 and now it's easy to
> get
> -EAGAIN returned from vmbus_post_msg() (e.g. when we try changing MTU on
> a
> netvsc device in a loop). All vmbus_post_msg() callers don't retry the
> operation and we usually end up with a non-functional device or crash.
> 
> While host's DoS protection conditions are unknown to me my tests show
> that
> it can take up to 46 attempts to send a message after changing udelay()
> to
> mdelay() and caping msec at '256', this means we can wait up to 10
> seconds
> before the message is sent so we need to use msleep() instead. Almost
> all
> vmbus_post_msg() callers are ready to sleep but there is one special
> case:
> vmbus_initiate_unload() which can be called from interrupt/NMI context
> and
> we can't sleep there. I'm also not sure about the lonely
> vmbus_send_tl_connect_request() which has no in-tree users but its
> external
> users are most likely waiting for the host to reply so sleeping there is
> also appropriate.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>
> ---
>  drivers/hv/channel.c  | 17 +
>  drivers/hv/channel_mgmt.c | 10 ++
>  drivers/hv/connection.c   | 19 ---
>  drivers/hv/hyperv_vmbus.h |  2 +-
>  4 files changed, 28 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
> index 16f91c8..28ca66e 100644
> --- a/drivers/hv/channel.c
> +++ b/drivers/hv/channel.c
> @@ -180,7 +180,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32
> send_ringbuffer_size,
>   spin_unlock_irqrestore(_connection.channelmsg_lock, flags);
> 
>   ret = vmbus_post_msg(open_msg,
> -sizeof(struct vmbus_channel_open_channel));
> +  sizeof(struct vmbus_channel_open_channel), true);
> 
>   if (ret != 0) {
>   err = ret;
> @@ -232,7 +232,7 @@ int vmbus_send_tl_connect_request(const uuid_le
> *shv_guest_servie_id,
>   conn_msg.guest_endpoint_id = *shv_guest_servie_id;
>   conn_msg.host_service_id = *shv_host_servie_id;
> 
> - return vmbus_post_msg(_msg, sizeof(conn_msg));
> + return vmbus_post_msg(_msg, sizeof(conn_msg), true);
>  }
>  EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request);
> 
> @@ -418,7 +418,7 @@ int vmbus_establish_gpadl(struct vmbus_channel
> *channel, void *kbuffer,
>   spin_unlock_irqrestore(_connection.channelmsg_lock, flags);
> 
>   ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize -
> -sizeof(*msginfo));
> +  sizeof(*msginfo), true);
>   if (ret != 0)
>   goto cleanup;
> 
> @@ -432,8 +432,8 @@ int vmbus_establish_gpadl(struct vmbus_channel
> *channel, void *kbuffer,
>   gpadl_body->gpadl = next_gpadl_handle;
> 
>   ret = vmbus_post_msg(gpadl_body,
> -  submsginfo->msgsize -
> -  sizeof(*submsginfo));
> +  submsginfo->msgsize - sizeof(*submsginfo),
> +  true);
>   if (ret != 0)
>   goto cleanup;
> 
> @@ -484,8 +484,8 @@ int vmbus_teardown_gpadl(struct vmbus_channel
> *channel, u32 gpadl_handle)
>   list_add_tail(>msglistentry,
> _connection.chn_msg_list);
>   spin_unlock_irqrestore(_connection.channelmsg_lock, flags);
> - ret = vmbus_post_msg(msg,
> -sizeof(struct vmbus_channel_gpadl_teardown));
> + ret = vmbus_post_msg(msg, sizeof(struct
> vmbus_channel_gpadl_teardown),
> +  true);
> 
>   if (ret)
>   goto post_msg_err;
> @@ -556,7 +556,8 @@ static int vmbus_close_internal(struct vmbus_channel
> *channel)
>   msg->header.msgtype = CHANNELMSG_CLOSECHANNEL;
>   msg->child_relid = channel->offermsg.child_relid;
> 
> - ret = vmbus_post_msg(msg, sizeof(struct
> vmbus_channel_close_channel));
> + ret = vmbus_post_msg(msg, sizeof(struct
> vmbus_channel_close_channel),
> +  true);
> 
>   if (ret) {
>   pr_err("Close failed: close post msg return is %d\n", ret);
> diff --git a/drivers/

RE: [PATCH] hv: do not lose pending heartbeat vmbus packets

2016-09-19 Thread Haiyang Zhang
> -Original Message-
> From: Long Li [mailto:lon...@exchange.microsoft.com]
> Sent: Monday, September 12, 2016 11:31 PM
> To: KY Srinivasan <k...@microsoft.com>; Haiyang Zhang
> <haiya...@microsoft.com>
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Long Li
> <lon...@microsoft.com>
> Subject: [PATCH] hv: do not lose pending heartbeat vmbus packets
>
> From: Long Li <lon...@microsoft.com>
> 
> The host keeps sending heartbeat packets independent of guest responding
> to them. In some situations, there might be multiple heartbeat packets
> pending in the ring buffer. Don't lose them, read them all.
> 
> Signed-off-by: Long Li <lon...@microsoft.com>

Please also apply it to "stable".

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>

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


[PATCH net-next] hv_netvsc: Implement batching of receive completions

2016-08-19 Thread Haiyang Zhang
From: Haiyang Zhang <haiya...@microsoft.com>

The existing code uses busy retry when unable to send out receive
completions due to full ring buffer. It also gives up retrying after limit
is reached, and causes receive buffer slots not being recycled.
This patch implements batching of receive completions. It also prevents
dropping receive completions due to full ring buffer.

Signed-off-by: Haiyang Zhang <haiya...@microsoft.com>
Reviewed-by: Stephen Hemminger <sthem...@microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h   |   17 
 drivers/net/hyperv/netvsc.c   |  170 ++---
 drivers/net/hyperv/rndis_filter.c |6 +-
 3 files changed, 160 insertions(+), 33 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index fa7b1e4..ce45d68 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -634,6 +634,20 @@ struct multi_send_data {
u32 count; /* counter of batched packets */
 };
 
+struct recv_comp_data {
+   u64 tid; /* transaction id */
+   u32 status;
+};
+
+/* Netvsc Receive Slots Max */
+#define NETVSC_RECVSLOT_MAX (NETVSC_RECEIVE_BUFFER_SIZE / ETH_DATA_LEN + 1)
+
+struct multi_recv_comp {
+   void *buf; /* queued receive completions */
+   u32 first; /* first data entry */
+   u32 next; /* next entry for writing */
+};
+
 struct netvsc_stats {
u64 packets;
u64 bytes;
@@ -736,6 +750,9 @@ struct netvsc_device {
u32 max_pkt; /* max number of pkt in one send, e.g. 8 */
u32 pkt_align; /* alignment bytes, e.g. 8 */
 
+   struct multi_recv_comp mrc[VRSS_CHANNEL_MAX];
+   atomic_t num_outstanding_recvs;
+
atomic_t open_cnt;
 };
 
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 8078bc2..b15edfc 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -74,6 +74,9 @@ static struct netvsc_device *alloc_net_device(void)
return NULL;
}
 
+   net_device->mrc[0].buf = vzalloc(NETVSC_RECVSLOT_MAX *
+sizeof(struct recv_comp_data));
+
init_waitqueue_head(_device->wait_drain);
net_device->destroy = false;
atomic_set(_device->open_cnt, 0);
@@ -85,6 +88,11 @@ static struct netvsc_device *alloc_net_device(void)
 
 static void free_netvsc_device(struct netvsc_device *nvdev)
 {
+   int i;
+
+   for (i = 0; i < VRSS_CHANNEL_MAX; i++)
+   vfree(nvdev->mrc[i].buf);
+
kfree(nvdev->cb_buffer);
kfree(nvdev);
 }
@@ -107,7 +115,8 @@ static struct netvsc_device *get_inbound_net_device(struct 
hv_device *device)
goto get_in_err;
 
if (net_device->destroy &&
-   atomic_read(_device->num_outstanding_sends) == 0)
+   atomic_read(_device->num_outstanding_sends) == 0 &&
+   atomic_read(_device->num_outstanding_recvs) == 0)
net_device = NULL;
 
 get_in_err:
@@ -972,49 +981,121 @@ send_now:
return ret;
 }
 
-static void netvsc_send_recv_completion(struct hv_device *device,
-   struct vmbus_channel *channel,
-   struct netvsc_device *net_device,
-   u64 transaction_id, u32 status)
+static int netvsc_send_recv_completion(struct vmbus_channel *channel,
+  u64 transaction_id, u32 status)
 {
struct nvsp_message recvcompMessage;
-   int retries = 0;
int ret;
-   struct net_device *ndev = hv_get_drvdata(device);
 
recvcompMessage.hdr.msg_type =
NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE;
 
recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status = status;
 
-retry_send_cmplt:
/* Send the completion */
ret = vmbus_sendpacket(channel, ,
-  sizeof(struct nvsp_message), transaction_id,
-  VM_PKT_COMP, 0);
-   if (ret == 0) {
-   /* success */
-   /* no-op */
-   } else if (ret == -EAGAIN) {
-   /* no more room...wait a bit and attempt to retry 3 times */
-   retries++;
-   netdev_err(ndev, "unable to send receive completion pkt"
-   " (tid %llx)...retrying %d\n", transaction_id, retries);
-
-   if (retries < 4) {
-   udelay(100);
-   goto retry_send_cmplt;
-   } else {
-   netdev_err(ndev, "unable to send receive "
-   "completion pkt (tid %llx)...give up 
retrying\n",
-   transaction_id);
-   }
-   } else {
-   netdev_err(ndev, "unable to send receive "
- 

RE: [PATCH net v2 5/5] hv_netvsc: fix bonding devices check in netvsc_netdev_event()

2016-08-15 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Monday, August 15, 2016 11:49 AM
> To: net...@vger.kernel.org
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
> Zhang <haiya...@microsoft.com>; KY Srinivasan <k...@microsoft.com>;
> Stephen Hemminger <step...@networkplumber.org>
> Subject: [PATCH net v2 5/5] hv_netvsc: fix bonding devices check in
> netvsc_netdev_event()
> 
> Bonding driver sets IFF_BONDING on both master (the bonding device) and
> slave (the real NIC) devices and in netvsc_netdev_event() we want to skip
> master devices only. Currently, there is an uncertainty when a slave
> interface is removed: if bonding module comes first in netdev_chain it
> clears IFF_BONDING flag on the netdev and netvsc_netdev_event()
> correctly
> handles NETDEV_UNREGISTER event, but in case netvsc comes first on the
> chain it sees the device with IFF_BONDING still attached and skips it. As
> we still hold vf_netdev pointer to the device we crash on the next inject.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>

Thanks!

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH net 3/4] hv_netvsc: protect module refcount by checking net_device_ctx->vf_netdev

2016-08-11 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Thursday, August 11, 2016 6:59 AM
> To: net...@vger.kernel.org
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
> Zhang <haiya...@microsoft.com>; KY Srinivasan <k...@microsoft.com>
> Subject: [PATCH net 3/4] hv_netvsc: protect module refcount by checking
> net_device_ctx->vf_netdev
> 
> We're not guaranteed to see NETDEV_REGISTER/NETDEV_UNREGISTER
> notifications
> only once per VF but we increase/decrease module refcount unconditionally.
> Check vf_netdev to make sure we don't take/release it twice. We presume
> that only one VF per netvsc device may exist.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH net 2/4] hv_netvsc: reset vf_inject on VF removal

2016-08-11 Thread Haiyang Zhang


> -Original Message-
> From: Vitaly Kuznetsov [mailto:vkuzn...@redhat.com]
> Sent: Thursday, August 11, 2016 6:59 AM
> To: net...@vger.kernel.org
> Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org; Haiyang
> Zhang <haiya...@microsoft.com>; KY Srinivasan <k...@microsoft.com>
> Subject: [PATCH net 2/4] hv_netvsc: reset vf_inject on VF removal
> 
> We reset vf_inject on VF going down (netvsc_vf_down()) but we don't on
> VF removal (netvsc_unregister_vf()) so vf_inject stays 'true' while
> vf_netdev is already NULL and we're trying to inject packets into NULL
> net device in netvsc_recv_callback() causing kernel to crash.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuzn...@redhat.com>

Acked-by: Haiyang Zhang <haiya...@microsoft.com>
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


  1   2   3   >