mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Vegard Nossum" <vegard.nossum@gmail.com>
To: "Pekka J Enberg" <penberg@cs.helsinki.fi>
Cc: "Alexey Dobriyan" <adobriyan@gmail.com>,
	"David Miller" <davem@davemloft.net>,
	"Ingo Molnar" <mingo@elte.hu>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] bitfields API
Date: Thu, 28 Aug 2008 21:38:58 +0200	[thread overview]
Message-ID: <19f34abd0808281238w18a53b90wc55591a572c225da@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0808282201190.11146@melkki.cs.Helsinki.FI>

On Thu, Aug 28, 2008 at 9:02 PM, Pekka J Enberg <penberg@cs.helsinki.fi> wrote:
> Why not do something like this (as suggested by Ingo, I think)? Yeah, the
> macro should go into kmemcheck.h but I don't have a tree handy...
>
>                Pekka
>
> Index: linux-2.6/include/linux/bitfield.h
> ===================================================================
> --- /dev/null
> +++ linux-2.6/include/linux/bitfield.h
> @@ -0,0 +1,10 @@
> +#ifndef __LINUX_BITFIELD_H
> +#define __LINUX_BITFIELD_H
> +
> +#ifdef CONFIG_KMEMCHECK
> +#define KMEMCHECK_BIT_FIELD(field) do { field = 0; } while (0)
> +#else
> +#define KMEMCHECK_BIT_FIELD(field) do { } while (0)
> +#endif /* CONFIG_KMEMCHECK */
> +
> +#endif /* __LINUX_BITFIELD_H */
>
> Index: linux-2.6/net/core/skbuff.c
> ===================================================================
> --- linux-2.6.orig/net/core/skbuff.c
> +++ linux-2.6/net/core/skbuff.c
> @@ -55,6 +55,7 @@
>  #include <linux/rtnetlink.h>
>  #include <linux/init.h>
>  #include <linux/scatterlist.h>
> +#include <linux/bitfield.h>
>
>  #include <net/protocol.h>
>  #include <net/dst.h>
> @@ -209,6 +210,11 @@ struct sk_buff *__alloc_skb(unsigned int
>        skb->data = data;
>        skb_reset_tail_pointer(skb);
>        skb->end = skb->tail + size;
> +       KMEMCHECK_BIT_FIELD(skb->local_df);
> +       KMEMCHECK_BIT_FIELD(skb->cloned);
> +       KMEMCHECK_BIT_FIELD(skb->ip_summed);
> +       KMEMCHECK_BIT_FIELD(skb->nohdr);
> +       KMEMCHECK_BIT_FIELD(skb->nfctinfo);
>        /* make sure we initialize shinfo sequentially */
>        shinfo = skb_shinfo(skb);
>        atomic_set(&shinfo->dataref, 1);
>

That looks good to me. If the extra lines are okay with net people, we
can put this in the fixlets branch and make it the norm for dealing
with bitfields in kmemcheck.

One thing to keep in mind that if the members of the bitfield does not
span the entire width of the bitfield, the remaining bits must also be
assigned (as an extra "filler" member), otherwise GCC will not
optimize it to a single store. But that is not an issue in this
particular case since all the bits are used.


Vegard

-- 
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036

  reply	other threads:[~2008-08-28 19:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-28 18:32 Vegard Nossum
2008-08-28 18:40 ` Alexey Dobriyan
2008-08-28 18:40   ` Pekka Enberg
2008-08-28 20:27     ` Adrian Bunk
2008-08-28 20:54       ` Pekka Enberg
2008-08-28 20:59       ` Vegard Nossum
2008-08-28 18:46   ` Vegard Nossum
2008-08-28 19:02     ` Pekka J Enberg
2008-08-28 19:38       ` Vegard Nossum [this message]
2008-08-30  8:28         ` Vegard Nossum
2008-08-28 19:05     ` Alexey Dobriyan
2008-08-28 19:07       ` Pekka Enberg
2008-08-28 19:18       ` Vegard Nossum

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=19f34abd0808281238w18a53b90wc55591a572c225da@mail.gmail.com \
    --to=vegard.nossum@gmail.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penberg@cs.helsinki.fi \
    /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

all inboxes | Powered by JetHome®