Re: lib/klist.c: bit 0 in pointer can't be used as flag

From: Jesper Nilsson
Date: Wed Jan 14 2009 - 05:19:56 EST


On Wed, Jan 14, 2009 at 12:11:32AM +0100, Bastien ROUCARIES wrote:
> On Tue, Jan 13, 2009 at 11:45 PM, David Miller <davem@xxxxxxxxxxxxx> wrote:
> > From: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
> > Date: Wed, 14 Jan 2009 07:40:19 +0900
> >
> >> > It may be that we've worked around the other spots, although I haven't
> >> > seen anything like that, we might just have been lucky until now.
> >> >
> >> > Can you recall another place where this trick is used?
> >>
> >> rmap.
> >> Don't CRIS use mmu?
> >
> > I'm beginning to suspect the issue is only with objects
> > in the kernel image itself. Dynamically allocated memory
> > is properly aligned and therefore the "low bit status bits
> > in pointer" trick works.
> Perhaps using a pointerhackalign trick on this structure where
> #define pointerhackalign(x) __attribute__ ((aligned (x)))
> and declare
> struct klist_node {
> ...
> } pointerhackalign(2);
>
> Because __attribute__ ((aligned (x))) could only increase alignment
> it will safe to do that and serve as documentation purpose :)

That works, but we need to do it not for the struct klist_node,
but for the struct we insert into the void * in klist_node,
which is struct klist.

The following patch works for CRIS, and is less intrusive than
my earlier patch. If this the way to go I can resubmit a proper patch.

diff --git a/include/linux/klist.h b/include/linux/klist.h
index 8ea98db..a21cd7a 100644
--- a/include/linux/klist.h
+++ b/include/linux/klist.h
@@ -23,7 +23,7 @@ struct klist {
struct list_head k_list;
void (*get)(struct klist_node *);
void (*put)(struct klist_node *);
-};
+} __attribute__ ((aligned (4)));

#define KLIST_INIT(_name, _get, _put) \
{ .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \

> Regards
>
> Bastien

/^JN - Jesper Nilsson
--
Jesper Nilsson -- jesper.nilsson@xxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/