All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: David Miller <davem@davemloft.net>
Cc: gregkh@linuxfoundation.org, andreas.noever@gmail.com,
	michael.jamet@intel.com, yehezkel.bernat@intel.com,
	amir.jer.levy@intel.com, Mario.Limonciello@dell.com,
	lukas@wunner.de, andriy.shevchenko@linux.intel.com,
	andrew@lunn.ch, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH v2 16/16] net: Add support for networking over Thunderbolt cable
Date: Wed, 27 Sep 2017 16:42:38 +0300	[thread overview]
Message-ID: <20170927134238.GC4630@lahna.fi.intel.com> (raw)
In-Reply-To: <20170926.214721.734746621809140934.davem@davemloft.net>

On Tue, Sep 26, 2017 at 09:47:21PM -0700, David Miller wrote:
> From: Mika Westerberg <mika.westerberg@linux.intel.com>
> Date: Mon, 25 Sep 2017 14:07:38 +0300
> 
> > +struct thunderbolt_ip_header {
> > +	u32 route_hi;
> > +	u32 route_lo;
> > +	u32 length_sn;
> > +	uuid_t uuid;
> > +	uuid_t initiator_uuid;
> > +	uuid_t target_uuid;
> > +	u32 type;
> > +	u32 command_id;
> > +} __packed;
> 
> Again, the __packed attribute should not be necessary and needs to be
> removed.

OK, will do.

> > +static void tbnet_pull_tail(struct sk_buff *skb)
> > +{
> > +	skb_frag_t *frag = &skb_shinfo(skb)->frags[0];
> > +	unsigned int pull_len;
> > +	void *hdr;
> > +
> > +	hdr = skb_frag_address(frag);
> > +	pull_len = eth_get_headlen(hdr, TBNET_RX_HDR_SIZE);
> > +
> > +	/* Align pull length to size of long to optimize memcpy performance */
> > +	skb_copy_to_linear_data(skb, hdr, ALIGN(pull_len, sizeof(long)));
> 
> You do not need to copy here, instead you can build SKB's where the
> skb->data points directly at the head of your first frag page memory.
> 
> See build_skb().
> 
> > +		skb = net->skb;
> > +		if (!skb) {
> > +			skb = netdev_alloc_skb_ip_align(net->dev,
> > +							TBNET_RX_HDR_SIZE);
> > +			net->skb = skb;
> > +		}
> > +		if (!skb)
> > +			break;
> > +
> > +		/* Single small buffer we can copy directly to the
> > +		 * header part of the skb.
> > +		 */
> > +		if (hdr->frame_count == 1 && frame_size <= TBNET_RX_HDR_SIZE) {
> 
> Here you would use build_skb() instead of netdev_alloc_skb*() for the first
> frag, and keep the existing code tacking on subsequent frags using
> skb_add_Rx_frag().

I'm reading kernel-doc of build_skb() (or rather __build_skb()) and it
says caller needs to reserve head room of NET_SKB_PAD and then make sure
there is space for SKB_DATA_ALIGN(skb_shared_info).

Now, in case of ThunderboltIP frames, they look like this:

  +---------+
  | hdr     | 12 bytes
  +---------+
  | data    | 4096 - 12 = 4084 bytes
  |         |
  |         |
  +---------+

A packet can consist of multiple frames where each have the 12-byte
header and 4084 bytes of TSO/LRO payload except the last one which can
be smaller than 4084.

Using build_skb() then would require to allocate larger buffer, that
includes NET_SKB_PAD + SKB_DATA_ALIGN(skb_shared_info) and that exceeds
page size. Is this something supported by build_skb()? It was not clear
to me based on the code and other users of build_skb() but I may be
missing something.

> > +	ret = register_netdev(dev);
> > +	if (ret) {
> > +		free_netdev(dev);
> > +		return ret;
> > +	}
> > +
> > +	net->handler.uuid = &tbnet_svc_uuid;
> > +	net->handler.callback = tbnet_handle_packet,
> > +	net->handler.data = net;
> > +	tb_register_protocol_handler(&net->handler);
> > +
> > +	tb_service_set_drvdata(svc, net);
> 
> There could be races here.
> 
> At the exact moment you call register_netdev(), your device can be
> brought UP, packets transmitted, etc.  You entire set of driver code
> paths can be executed.
> 
> The rest of those initializations after register_netdev() probably
> are needed by the rest of the driver to function properly, so may
> need to happen before register_netdev() publishes the device to the
> entire world.

You're right. I'll change the ordering so that register_netdev() happens
last.

Thanks!

  reply	other threads:[~2017-09-27 13:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25 11:07 [PATCH v2 00/16] Thunderbolt networking Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 01/16] byteorder: Move {cpu_to_be32,be32_to_cpu}_array() from Thunderbolt to core Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 02/16] thunderbolt: Add support for XDomain properties Mika Westerberg
2017-09-27  4:33   ` David Miller
2017-09-27 11:32     ` Mika Westerberg
2017-09-27 16:06       ` David Laight
2017-09-27 16:22       ` David Miller
2017-09-25 11:07 ` [PATCH v2 03/16] thunderbolt: Move enum tb_cfg_pkg_type to thunderbolt.h Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 04/16] thunderbolt: Move thunderbolt domain structure " Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 05/16] thunderbolt: Move tb_switch_phy_port_from_link() " Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 06/16] thunderbolt: Add support for XDomain discovery protocol Mika Westerberg
2017-09-27  4:35   ` David Miller
2017-09-25 11:07 ` [PATCH v2 07/16] thunderbolt: Configure interrupt throttling for all interrupts Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 08/16] thunderbolt: Add support for frame mode Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 09/16] thunderbolt: Export ring handling functions to modules Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 10/16] thunderbolt: Move ring descriptor flags to thunderbolt.h Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 11/16] thunderbolt: Use spinlock in ring serialization Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 12/16] thunderbolt: Use spinlock in NHI serialization Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 13/16] thunderbolt: Add polling mode for rings Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 14/16] thunderbolt: Add function to retrieve DMA device for the ring Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 15/16] thunderbolt: Allocate ring HopID automatically if requested Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 16/16] net: Add support for networking over Thunderbolt cable Mika Westerberg
2017-09-27  4:47   ` David Miller
2017-09-27 13:42     ` Mika Westerberg [this message]
2017-09-27 16:27       ` David Miller
2017-09-27 17:27         ` Mika Westerberg
2017-09-27 18:23           ` David Miller
2017-09-26 17:37 ` [PATCH v2 00/16] Thunderbolt networking Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170927134238.GC4630@lahna.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=Mario.Limonciello@dell.com \
    --cc=amir.jer.levy@intel.com \
    --cc=andreas.noever@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=michael.jamet@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=yehezkel.bernat@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.