netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johann Baudy <johaahn@gmail.com>
To: "Lovich, Vitali" <vlovich@qualcomm.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Evgeniy Polyakov <zbr@ioremap.net>
Subject: Re: [PATCH] Packet socket: mmapped IO: PACKET_TX_RING
Date: Wed, 05 Nov 2008 11:55:07 +0100	[thread overview]
Message-ID: <1225882507.5273.66.camel@localhost> (raw)

Hi Vitali,

> Right, but check out http://www.mjmwired.net/kernel/Documentation/memory-barriers.txt - namely the implicit nature of ULOCK operations, IMPLICIT KERNEL MEMORY BARRIERS, & ATOMIC OPERATIONS.
>
> However, I'm not sure why currently in the code it's a full memory barrier after __packet_set_status - it could be downgraded to a write barrier.

So you assume an implicit read or data dep barrier before packet_current_rx_frame()?

>
> Also, there is a bug in the current code I believe:
>
> Around line 726:
>
> @@ -723,8 +723,9 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
>        else
>                sll->sll_ifindex = dev->ifindex;
>
> +       smp_wmb();
>        __packet_set_status(po, h.raw, status);
> -       smp_mb();
> +       smp_wmb();
>
>        {
>                struct page *p_start, *p_end;
>
> We only really need 1 memory barrier: for architectures where flush_dcache_page is a no-op and writes may be re-ordered, we need the smp_wmb before (if writes may not be re-ordered, ala x86, then a simple barrier() will suffice).  With architectures that actually need the data flushed, we put it after the __packet_set_status (and this can't be a simple barrier).  However, to generically do it, we do both (I couldn't find a pre-processor that gets defined to indicate if flush_dcache_page is no-op or actually does something).  If we don't do it this way it's possible (however unlikely), that the status is set before the data is filled in correctly.  This'll come up if the compiler moves the set status around or the CPU re-orders writes and flush_dcache_page is a no-op.
>
> Should I submit this as a patch, or am I missing something?
>
> "I'm afraid that once a barrier discussion comes up and we insert them, then I become dazedly paranoid and it's very hard to shake me from seeing a need for barriers everywhere, including a barrier before and after every barrier ad infinitum to make sure they're really barriers."
> -- Hugh Dickins
>
> Vitali
>
If my understanding is correct, smp_wmb should ensure that "all the
STORE operations specified before the barrier will appear to happen
before all the STORE operations specified after the barrier with respect
to the other components of the system.". 
I think that those barriers address reordering effects at the hardware
level and depend on architecture. But again, I'm not an expert of this.

Moreover if we look into Kernel code, most of the time, smp_wmb() is
used immediately after shared data update . (not before)
(ex:kernel/marker.c, kernel/trace/ftrace.c, ...).

I would like to integrate this barrier mechanism in __packet_[set|
get]_status() function. Thoughts?

Best regards,
Johann











-- 
Johann Baudy
johaahn@gmail.com




             reply	other threads:[~2008-11-05 10:55 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05 10:55 Johann Baudy [this message]
2008-11-05 11:02 ` [PATCH] Packet socket: mmapped IO: PACKET_TX_RING Patrick McHardy
2008-11-05 17:32 ` Lovich, Vitali
  -- strict thread matches above, loose matches on Subject: below --
2008-11-12 13:19 Johann Baudy
2008-11-05 15:16 Johann Baudy
2008-11-05 17:49 ` Lovich, Vitali
2008-10-31 10:58 Johann Baudy
2008-10-31 17:07 ` Lovich, Vitali
2008-10-31 18:24   ` Lovich, Vitali
2008-11-04 22:45     ` Johann Baudy
2008-11-06  0:47       ` Lovich, Vitali
2008-11-06  8:03         ` Evgeniy Polyakov
2008-11-06 18:49           ` Lovich, Vitali
2008-11-06 19:40             ` Evgeniy Polyakov
2008-11-06 19:53               ` Lovich, Vitali
2008-11-07 16:36                 ` Johann Baudy
2008-11-07 17:19                   ` Lovich, Vitali
2008-11-10 20:29                     ` Lovich, Vitali
2008-11-11  0:29                       ` Lovich, Vitali
     [not found]                         ` <7e0dd21a0811110656yff651afp8ff0f9928b79f545@mail.gmail.com>
2008-11-11 14:59                           ` Johann Baudy
2008-11-11 19:05                             ` Lovich, Vitali
2008-11-11 12:10                       ` Johann Baudy
2008-11-11 17:44                         ` Lovich, Vitali
2008-11-11 18:08                           ` Johann Baudy
2008-11-11 18:19                             ` Lovich, Vitali
2008-11-11 18:59                               ` Johann Baudy
2008-11-11 19:10                                 ` Lovich, Vitali
2008-11-12 12:09                                   ` Johann Baudy
2008-11-12 17:12                                     ` Lovich, Vitali
2008-11-11 11:43                     ` Johann Baudy
2008-11-11 17:38                       ` Lovich, Vitali
2008-11-11 17:50                         ` Johann Baudy
2008-11-11 18:14                           ` Lovich, Vitali
2008-11-11 18:50                             ` Evgeniy Polyakov
2008-11-11 19:19                               ` Johann Baudy
2008-11-11 19:29                                 ` Evgeniy Polyakov
2008-11-12 13:43                                   ` Johann Baudy
2008-11-12 13:58                                     ` Evgeniy Polyakov
2008-11-12 17:07                                       ` Lovich, Vitali
2008-11-12 17:41                                         ` Evgeniy Polyakov
2008-11-12 17:59                                           ` Lovich, Vitali
2008-11-12 18:11                                             ` Evgeniy Polyakov
2008-11-12 19:05                                               ` Lovich, Vitali
2008-11-12 19:14                                                 ` Evgeniy Polyakov
2008-11-12 21:23                                                   ` Lovich, Vitali
2008-11-12 21:46                                                     ` Evgeniy Polyakov
2008-11-12 22:33                                                       ` Lovich, Vitali
2008-11-18 18:49                                                       ` Johann Baudy
2008-11-18 19:10                                                         ` Evgeniy Polyakov
2008-11-18 19:46                                                         ` Lovich, Vitali
2008-11-07 17:28                 ` Evgeniy Polyakov
2008-11-07 20:22                   ` David Miller
2008-10-31 20:28   ` Evgeniy Polyakov
2008-11-04 22:33   ` Johann Baudy
2008-11-05  1:50     ` Lovich, Vitali
2008-10-30 13:00 Johann Baudy
2008-10-30 18:21 ` Lovich, Vitali
2008-10-27  9:33 Johann Baudy
2008-10-28 22:44 ` David Miller

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=1225882507.5273.66.camel@localhost \
    --to=johaahn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vlovich@qualcomm.com \
    --cc=zbr@ioremap.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).