Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 454006 - sys-fs/btrfs-progs-0.9.11 causes unaligned accesses
Summary: sys-fs/btrfs-progs-0.9.11 causes unaligned accesses
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: ARM Linux
: Normal normal (vote)
Assignee: Mike Gilbert
Depends on:
Blocks: unaligned-access
  Show dependency tree
Reported: 2013-01-25 14:52 UTC by Ben Peddell
Modified: 2016-09-22 19:55 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Ben Peddell 2013-01-25 14:52:09 UTC
The btrfs programs (and undoubtedly kernel modules) encounter unaligned accesses.

Reproducible: Always

Steps to Reproduce:
1. run mkfs.btrfs {device}
Actual Results:  
[836847.499603] Alignment trap: mkfs.btrfs (21448) PC=0x00025458 Instr=0xe8880018 Address=0xbeba69c5 FSR 0x801
[836847.500438] Alignment trap: mkfs.btrfs (21448) PC=0x00025458 Instr=0xe8880018 Address=0xbeba69c5 FSR 0x801
[836847.501568] Alignment trap: mkfs.btrfs (21448) PC=0x00025458 Instr=0xe8880018 Address=0xbeba697d FSR 0x801
[836847.501868] Alignment trap: mkfs.btrfs (21448) PC=0x00025458 Instr=0xe8880018 Address=0xbeba697d FSR 0x801

Expected Results:  
no alignment traps

Numerous patches have been submitted to linux-btrfs, but they appear to have been ignored by the linux-btrfs maintainer.

I suspect that the reason why we don't see crashes in the kernel from this on ARM is because the kernel fixes up (but does not report) unaligned accesses that occur in kernel mode.

# emerge --info
Portage (default/linux/arm/10.0, gcc-4.5.4, glibc-2.15-r2, 3.4.2-gentoo-r1 armv5tel)
System uname: Linux-3.4.2-gentoo-r1-armv5tel-Feroceon_88FR131_rev_1_-v5l-with-gentoo-2.1
Timestamp of tree: Fri, 25 Jan 2013 12:45:01 +0000
app-shells/bash:          4.2_p37
dev-lang/python:          2.7.3-r2, 3.2.3
dev-util/cmake:           2.8.7-r5
dev-util/pkgconfig:       0.27.1
sys-apps/baselayout:      2.1-r1
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.68
sys-devel/automake:       1.11.6
sys-devel/binutils:       2.22-r1
sys-devel/gcc:            4.2.4-r1, 4.5.4
sys-devel/gcc-config:     1.7.3
sys-devel/libtool:        2.4-r1
sys-devel/make:           3.82-r3
sys-kernel/linux-headers: 3.4-r2 (virtual/os-headers)
sys-libs/glibc:           2.15-r2
Repositories: gentoo x-local
CFLAGS="-O2 -pipe"
CONFIG_PROTECT="/etc /var/bind"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.4/ext-active/ /etc/php/cgi-php5.4/ext-active/ /etc/php/cli-php5.4/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs buildpkg config-protect-if-modified distlocks ebuild-locks fixlafiles news parallel-fetch parse-eapi-ebuild-head protect-owned sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
USE="acl arm berkdb bzip2 cgi cli cracklib crypt cxx exif fortran gdbm iconv modules mudflap mysql ncurses nls nptl openmp pcre php readline session snmp ssl tcpd threads unicode xml zlib" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" PHP_TARGETS="php5-3" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="exynos fbdev omap omapfb dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Comment 1 Mike Gilbert gentoo-dev 2013-01-26 16:13:24 UTC
I don't plan to diverge from upstream in this package -- I'm not knowledgeable enough to know when it is safe to do so.

Please continue to submit patches upstream.
Comment 2 Mike Gilbert gentoo-dev 2013-01-26 16:19:32 UTC
Actually, it looks like one of those patches landed upstream very recently:;a=commit;h=0b0a954e4383d2074c499523e2aa89527e5ac053
Comment 3 Ben Peddell 2013-01-26 19:57:34 UTC

Instead of 4 alignment traps when running mkfs.btrfs, I now get 3234 alignment traps when using the default '-O2 -pipe' CFLAGS.  When using the btrfs-progs default '-g -O1' CFLAGS, no alignment traps are encountered.

It looks like gcc 4.5.4 optimizes out memcpy when it is copying 4 bytes and optimization level 2 is selected.

e.g. one of the functions that got alignment errors is leaf_space_used in ctree.c

It inlines btrfs_item_end_nr(l, start);
That inlines btrfs_item_end();
That inlines btrfs_item_offset() and btrfs_item_size(), both of which use memcpy to try to avoid those alignment traps.

I'll try a newer gcc, and see if this is still the case.
Comment 4 Ben Peddell 2013-01-27 06:47:50 UTC
I have submitted a patch upstream to attempt to resolve this.

Looking at /usr/src/linux/include/linux/unaligned/memmove.h, they've known that memcpy gets optimized out by gcc for word-sized moves.  Unfortunately, it seems that gcc 4.5.4 (and probably 4.6 and 4.7) also optimize out memmove for word-sized moves.

Therefore my proposed patch uses the packed struct method of unaligned access.
Comment 5 Piotr Szymaniak 2016-09-22 19:55:26 UTC
Looking for btrfs-progs related bugs I've found this one. It seems that this version is gone from portage and mentioned patch in last post was queued by David Sterba for integration in 2013. Marking as FIXED.