Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* Re: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
       [not found] <20210415054519.12944-1-decui@microsoft.com>
@ 2021-04-15 17:44 ` Jakub Kicinski
  2021-04-15 18:14   ` Dexuan Cui
  2021-04-15 21:07 ` Stephen Hemminger
  2021-04-15 21:15 ` Stephen Hemminger
  2 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2021-04-15 17:44 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: davem, kys, haiyangz, sthemmin, wei.liu, liuwe, netdev, leon,
	andrew, bernd, rdunlap, shacharr, linux-kernel, linux-hyperv

On Wed, 14 Apr 2021 22:45:19 -0700 Dexuan Cui wrote:
> +	buf = dma_alloc_coherent(gmi->dev, length, &dma_handle,
> +				 GFP_KERNEL | __GFP_ZERO);

No need for GFP_ZERO, dma_alloc_coherent() zeroes the memory these days.

> +static int mana_gd_register_irq(struct gdma_queue *queue,
> +				const struct gdma_queue_spec *spec)
> ...
> +	struct gdma_irq_context *gic;
> +
> +	struct gdma_context *gc;

Why the empty line?

> +	queue = kzalloc(sizeof(*queue), GFP_KERNEL);
> +	if (!queue)
> +		return -ENOMEM;
> +
> +	gmi = &queue->mem_info;
> +	err = mana_gd_alloc_memory(gc, spec->queue_size, gmi);
> +	if (err)
> +		return err;

Leaks the memory from 'queue'?

Same code in mana_gd_create_mana_eq(), ...wq_cq(), etc.

> +int mana_do_attach(struct net_device *ndev, enum mana_attach_caller caller)
> +{
> +	struct mana_port_context *apc = netdev_priv(ndev);
> +	struct gdma_dev *gd = apc->ac->gdma_dev;
> +	u32 max_txq, max_rxq, max_queues;
> +	int port_idx = apc->port_idx;
> +	u32 num_indirect_entries;
> +	int err;
> +
> +	if (caller == MANA_OPEN)
> +		goto start_open;
> +
> +	err = mana_init_port_context(apc);
> +	if (err)
> +		return err;
> +
> +	err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
> +				   &num_indirect_entries);
> +	if (err) {
> +		netdev_err(ndev, "Failed to query info for vPort 0\n");
> +		goto reset_apc;
> +	}
> +
> +	max_queues = min_t(u32, max_txq, max_rxq);
> +	if (apc->max_queues > max_queues)
> +		apc->max_queues = max_queues;
> +
> +	if (apc->num_queues > apc->max_queues)
> +		apc->num_queues = apc->max_queues;
> +
> +	memcpy(ndev->dev_addr, apc->mac_addr, ETH_ALEN);
> +
> +	if (caller == MANA_PROBE)
> +		return 0;
> +
> +start_open:

Why keep this as a single function, there is no overlap between what's
done for OPEN and PROBE, it seems.

Similarly detach should probably be split into clearly distinct parts.

> +	err = mana_create_eq(apc);
> +	if (err)
> +		goto reset_apc;
> +
> +	err = mana_create_vport(apc, ndev);
> +	if (err)
> +		goto destroy_eq;
> +
> +	err = netif_set_real_num_tx_queues(ndev, apc->num_queues);
> +	if (err)
> +		goto destroy_vport;
> +
> +	err = mana_add_rx_queues(apc, ndev);
> +	if (err)
> +		goto destroy_vport;
> +
> +	apc->rss_state = apc->num_queues > 1 ? TRI_STATE_TRUE : TRI_STATE_FALSE;
> +
> +	err = netif_set_real_num_rx_queues(ndev, apc->num_queues);
> +	if (err)
> +		goto destroy_vport;
> +
> +	mana_rss_table_init(apc);
> +
> +	err = mana_config_rss(apc, TRI_STATE_TRUE, true, true);
> +	if (err)
> +		goto destroy_vport;
> +
> +	return 0;
> +
> +destroy_vport:
> +	mana_destroy_vport(apc);
> +destroy_eq:
> +	mana_destroy_eq(gd->gdma_context, apc);
> +reset_apc:
> +	if (caller == MANA_OPEN)
> +		return err;
> +	kfree(apc->rxqs);
> +	apc->rxqs = NULL;
> +	return err;
> +}
> +
> +int mana_attach(struct net_device *ndev)
> +{
> +	struct mana_port_context *apc = netdev_priv(ndev);
> +	int err;
> +
> +	ASSERT_RTNL();
> +
> +	err = mana_do_attach(ndev, MANA_ATTACH);
> +	if (err)
> +		return err;
> +
> +	netif_device_attach(ndev);
> +
> +	apc->port_is_up = apc->port_st_save;
> +
> +	/* Ensure port state updated before txq state */
> +	smp_wmb();
> +
> +	if (apc->port_is_up) {
> +		netif_carrier_on(ndev);
> +		netif_tx_wake_all_queues(ndev);
> +	}
> +
> +	return 0;
> +}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
  2021-04-15 17:44 ` [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Jakub Kicinski
@ 2021-04-15 18:14   ` Dexuan Cui
  0 siblings, 0 replies; 6+ messages in thread
From: Dexuan Cui @ 2021-04-15 18:14 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, KY Srinivasan, Haiyang Zhang, Stephen Hemminger, wei.liu,
	Wei Liu, netdev, leon, andrew, bernd, rdunlap, Shachar Raindel,
	linux-kernel, linux-hyperv

> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Thursday, April 15, 2021 10:44 AM
>  ...
> On Wed, 14 Apr 2021 22:45:19 -0700 Dexuan Cui wrote:
> > +	buf = dma_alloc_coherent(gmi->dev, length, &dma_handle,
> > +				 GFP_KERNEL | __GFP_ZERO);
> 
> No need for GFP_ZERO, dma_alloc_coherent() zeroes the memory these days.

Yes, indeed. Will remove __GFP_ZERO.

> 
> > +static int mana_gd_register_irq(struct gdma_queue *queue,
> > +				const struct gdma_queue_spec *spec)
> > ...
> > +	struct gdma_irq_context *gic;
> > +
> > +	struct gdma_context *gc;
> 
> Why the empty line?

No good reason. Will remove this line. I'll check the whole patch
for similar issues.

> 
> > +	queue = kzalloc(sizeof(*queue), GFP_KERNEL);
> > +	if (!queue)
> > +		return -ENOMEM;
> > +
> > +	gmi = &queue->mem_info;
> > +	err = mana_gd_alloc_memory(gc, spec->queue_size, gmi);
> > +	if (err)
> > +		return err;
> 
> Leaks the memory from 'queue'?

Sorry. This should be a bug I introduced when moving arouond some code.

> Same code in mana_gd_create_mana_eq(), ...wq_cq(), etc.

Will fix all of them, and check for the code similar issues.

> > +int mana_do_attach(struct net_device *ndev, enum mana_attach_caller
> caller)
> > +{
> > +	struct mana_port_context *apc = netdev_priv(ndev);
> > +	struct gdma_dev *gd = apc->ac->gdma_dev;
> > +	u32 max_txq, max_rxq, max_queues;
> > +	int port_idx = apc->port_idx;
> > +	u32 num_indirect_entries;
> > +	int err;
> > +
> > +	if (caller == MANA_OPEN)
> > +		goto start_open;
> > +
> > +	err = mana_init_port_context(apc);
> > +	if (err)
> > +		return err;
> > +
> > +	err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
> > +				   &num_indirect_entries);
> > +	if (err) {
> > +		netdev_err(ndev, "Failed to query info for vPort 0\n");
> > +		goto reset_apc;
> > +	}
> > +
> > +	max_queues = min_t(u32, max_txq, max_rxq);
> > +	if (apc->max_queues > max_queues)
> > +		apc->max_queues = max_queues;
> > +
> > +	if (apc->num_queues > apc->max_queues)
> > +		apc->num_queues = apc->max_queues;
> > +
> > +	memcpy(ndev->dev_addr, apc->mac_addr, ETH_ALEN);
> > +
> > +	if (caller == MANA_PROBE)
> > +		return 0;
> > +
> > +start_open:
> 
> Why keep this as a single function, there is no overlap between what's
> done for OPEN and PROBE, it seems.
> 
> Similarly detach should probably be split into clearly distinct parts.

Will improve the code. Thanks for the suggestion!

Thanks,
Dexuan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
       [not found] <20210415054519.12944-1-decui@microsoft.com>
  2021-04-15 17:44 ` [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Jakub Kicinski
@ 2021-04-15 21:07 ` Stephen Hemminger
  2021-04-15 21:08   ` Haiyang Zhang
  2021-04-15 21:15 ` Stephen Hemminger
  2 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2021-04-15 21:07 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: davem, kuba, kys, haiyangz, sthemmin, wei.liu, liuwe, netdev,
	leon, andrew, bernd, rdunlap, shacharr, linux-kernel,
	linux-hyperv

On Wed, 14 Apr 2021 22:45:19 -0700
Dexuan Cui <decui@microsoft.com> wrote:

> +static int mana_query_vport_cfg(struct mana_port_context *apc, u32 vport_index,
> +				u32 *max_sq, u32 *max_rq, u32 *num_indir_entry)
> +{
> +	struct mana_query_vport_cfg_resp resp = {};
> +	struct mana_query_vport_cfg_req req = {};
> +	int err;
> +
> +	mana_gd_init_req_hdr(&req.hdr, MANA_QUERY_VPORT_CONFIG,
> +			     sizeof(req), sizeof(resp));
> +
> +	req.vport_index = vport_index;
> +
> +	err = mana_send_request(apc->ac, &req, sizeof(req), &resp,
> +				sizeof(resp));
> +	if (err)
> +		return err;
> +
> +	err = mana_verify_resp_hdr(&resp.hdr, MANA_QUERY_VPORT_CONFIG,
> +				   sizeof(resp));
> +	if (err)
> +		return err;
> +
> +	if (resp.hdr.status)
> +		return -EPROTO;
> +
> +	*max_sq = resp.max_num_sq;
> +	*max_rq = resp.max_num_rq;
> +	*num_indir_entry = resp.num_indirection_ent;
> +
> +	apc->port_handle = resp.vport;
> +	memcpy(apc->mac_addr, resp.mac_addr, ETH_ALEN);

You could use ether_addr_copy here.


> +int mana_do_attach(struct net_device *ndev, enum mana_attach_caller caller)
> +{
> +	struct mana_port_context *apc = netdev_priv(ndev);
> +	struct gdma_dev *gd = apc->ac->gdma_dev;
> +	u32 max_txq, max_rxq, max_queues;
> +	int port_idx = apc->port_idx;
> +	u32 num_indirect_entries;
> +	int err;
> +
> +	if (caller == MANA_OPEN)
> +		goto start_open;
> +
> +	err = mana_init_port_context(apc);
> +	if (err)
> +		return err;
> +
> +	err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
> +				   &num_indirect_entries);
> +	if (err) {
> +		netdev_err(ndev, "Failed to query info for vPort 0\n");
> +		goto reset_apc;
> +	}
> +
> +	max_queues = min_t(u32, max_txq, max_rxq);
> +	if (apc->max_queues > max_queues)
> +		apc->max_queues = max_queues;
> +
> +	if (apc->num_queues > apc->max_queues)
> +		apc->num_queues = apc->max_queues;
> +
> +	memcpy(ndev->dev_addr, apc->mac_addr, ETH_ALEN);

And here use ether_addr_copy().


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
  2021-04-15 21:07 ` Stephen Hemminger
@ 2021-04-15 21:08   ` Haiyang Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Haiyang Zhang @ 2021-04-15 21:08 UTC (permalink / raw)
  To: Stephen Hemminger, Dexuan Cui
  Cc: davem, kuba, KY Srinivasan, Stephen Hemminger, wei.liu, Wei Liu,
	netdev, leon, andrew, bernd, rdunlap, Shachar Raindel,
	linux-kernel, linux-hyperv



> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, April 15, 2021 5:08 PM
> To: Dexuan Cui <decui@microsoft.com>
> Cc: davem@davemloft.net; kuba@kernel.org; KY Srinivasan
> <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; Stephen
> Hemminger <sthemmin@microsoft.com>; wei.liu@kernel.org; Wei Liu
> <liuwe@microsoft.com>; netdev@vger.kernel.org; leon@kernel.org;
> andrew@lunn.ch; bernd@petrovitsch.priv.at; rdunlap@infradead.org;
> Shachar Raindel <shacharr@microsoft.com>; linux-kernel@vger.kernel.org;
> linux-hyperv@vger.kernel.org
> Subject: Re: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure
> Network Adapter (MANA)
> 
> On Wed, 14 Apr 2021 22:45:19 -0700
> Dexuan Cui <decui@microsoft.com> wrote:
> 
> > +static int mana_query_vport_cfg(struct mana_port_context *apc, u32
> vport_index,
> > +				u32 *max_sq, u32 *max_rq, u32
> *num_indir_entry) {
> > +	struct mana_query_vport_cfg_resp resp = {};
> > +	struct mana_query_vport_cfg_req req = {};
> > +	int err;
> > +
> > +	mana_gd_init_req_hdr(&req.hdr, MANA_QUERY_VPORT_CONFIG,
> > +			     sizeof(req), sizeof(resp));
> > +
> > +	req.vport_index = vport_index;
> > +
> > +	err = mana_send_request(apc->ac, &req, sizeof(req), &resp,
> > +				sizeof(resp));
> > +	if (err)
> > +		return err;
> > +
> > +	err = mana_verify_resp_hdr(&resp.hdr,
> MANA_QUERY_VPORT_CONFIG,
> > +				   sizeof(resp));
> > +	if (err)
> > +		return err;
> > +
> > +	if (resp.hdr.status)
> > +		return -EPROTO;
> > +
> > +	*max_sq = resp.max_num_sq;
> > +	*max_rq = resp.max_num_rq;
> > +	*num_indir_entry = resp.num_indirection_ent;
> > +
> > +	apc->port_handle = resp.vport;
> > +	memcpy(apc->mac_addr, resp.mac_addr, ETH_ALEN);
> 
> You could use ether_addr_copy here.
> 
> 
> > +int mana_do_attach(struct net_device *ndev, enum mana_attach_caller
> > +caller) {
> > +	struct mana_port_context *apc = netdev_priv(ndev);
> > +	struct gdma_dev *gd = apc->ac->gdma_dev;
> > +	u32 max_txq, max_rxq, max_queues;
> > +	int port_idx = apc->port_idx;
> > +	u32 num_indirect_entries;
> > +	int err;
> > +
> > +	if (caller == MANA_OPEN)
> > +		goto start_open;
> > +
> > +	err = mana_init_port_context(apc);
> > +	if (err)
> > +		return err;
> > +
> > +	err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
> > +				   &num_indirect_entries);
> > +	if (err) {
> > +		netdev_err(ndev, "Failed to query info for vPort 0\n");
> > +		goto reset_apc;
> > +	}
> > +
> > +	max_queues = min_t(u32, max_txq, max_rxq);
> > +	if (apc->max_queues > max_queues)
> > +		apc->max_queues = max_queues;
> > +
> > +	if (apc->num_queues > apc->max_queues)
> > +		apc->num_queues = apc->max_queues;
> > +
> > +	memcpy(ndev->dev_addr, apc->mac_addr, ETH_ALEN);
> 
> And here use ether_addr_copy().

Thanks, I will update these.

- Haiyang

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
       [not found] <20210415054519.12944-1-decui@microsoft.com>
  2021-04-15 17:44 ` [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Jakub Kicinski
  2021-04-15 21:07 ` Stephen Hemminger
@ 2021-04-15 21:15 ` Stephen Hemminger
  2021-04-15 21:27   ` Dexuan Cui
  2 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2021-04-15 21:15 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: davem, kuba, kys, haiyangz, sthemmin, wei.liu, liuwe, netdev,
	leon, andrew, bernd, rdunlap, shacharr, linux-kernel,
	linux-hyperv

On Wed, 14 Apr 2021 22:45:19 -0700
Dexuan Cui <decui@microsoft.com> wrote:

> +static int mana_probe_port(struct mana_context *ac, int port_idx,
> +			   struct net_device **ndev_storage)
> +{
> +	struct gdma_context *gc = ac->gdma_dev->gdma_context;
> +	struct mana_port_context *apc;
> +	struct net_device *ndev;
> +	int err;
> +
> +	ndev = alloc_etherdev_mq(sizeof(struct mana_port_context),
> +				 gc->max_num_queues);
> +	if (!ndev)
> +		return -ENOMEM;
> +
> +	*ndev_storage = ndev;
> +
> +	apc = netdev_priv(ndev);
> +	apc->ac = ac;
> +	apc->ndev = ndev;
> +	apc->max_queues = gc->max_num_queues;
> +	apc->num_queues = min_t(uint, gc->max_num_queues, MANA_MAX_NUM_QUEUES);
> +	apc->port_handle = INVALID_MANA_HANDLE;
> +	apc->port_idx = port_idx;
> +
> +	ndev->netdev_ops = &mana_devops;
> +	ndev->ethtool_ops = &mana_ethtool_ops;
> +	ndev->mtu = ETH_DATA_LEN;
> +	ndev->max_mtu = ndev->mtu;
> +	ndev->min_mtu = ndev->mtu;
> +	ndev->needed_headroom = MANA_HEADROOM;
> +	SET_NETDEV_DEV(ndev, gc->dev);
> +
> +	netif_carrier_off(ndev);
> +
> +	get_random_bytes(apc->hashkey, MANA_HASH_KEY_SIZE);

Current practice for network drivers is to use netdev_rss_key_fill() for this.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)
  2021-04-15 21:15 ` Stephen Hemminger
@ 2021-04-15 21:27   ` Dexuan Cui
  0 siblings, 0 replies; 6+ messages in thread
From: Dexuan Cui @ 2021-04-15 21:27 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: davem, kuba, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Wei Liu, netdev, leon, andrew, bernd, rdunlap,
	Shachar Raindel, linux-kernel, linux-hyperv

> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, April 15, 2021 2:15 PM
> > ...
> > +	netif_carrier_off(ndev);
> > +
> > +	get_random_bytes(apc->hashkey, MANA_HASH_KEY_SIZE);
> 
> Current practice for network drivers is to use netdev_rss_key_fill() for this.

Will change to netdev_rss_key_fill(). Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210415054519.12944-1-decui@microsoft.com>
2021-04-15 17:44 ` [PATCH v6 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Jakub Kicinski
2021-04-15 18:14   ` Dexuan Cui
2021-04-15 21:07 ` Stephen Hemminger
2021-04-15 21:08   ` Haiyang Zhang
2021-04-15 21:15 ` Stephen Hemminger
2021-04-15 21:27   ` Dexuan Cui

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hyperv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git