structs with bitfields and spinlocks/atomics

Damian Lukowski damian at tvk.rwth-aachen.de
Tue Dec 11 05:48:19 CST 2012


Hello,

I would like to point out that xfs-code may need a review, whether it is 
affected by compiler issues as described in [1]. There has been a patch 
[2] for btrfs this year summarizing the problem as follows:

On ia64, powerpc64 and sparc64 the bitfield is modified through a RMW 
cycle and current gcc rewrites the adjacent 4B word, which in case of a 
spinlock or atomic has disaterous effect.

In xfs_aops.h we have
> typedef struct xfs_ioend {
>         struct xfs_ioend        *io_list;
>         unsigned int            io_type;
>         int                     io_error;
>         atomic_t                io_remaining;
>         unsigned int            io_isasync : 1;
>         unsigned int            io_isdirect : 1;
> [...]

where atomic_t, io_isasync and io_isdirect presumably share a common 8B 
word. I only found this occurrence so far.

Thanks to Dave Chinner for pointing out the correct mailing list.

Best regards
  Damian Lukowski

[1] https://lkml.org/lkml/2012/2/1/220
[2] btrfs: fix structs where bitfields and spinlock/atomic share 8B word 
(commit c08782dacd7a098f2b8bca7f4a57a5b402e9e1e5)



More information about the xfs mailing list