From owner-svn-src-head@FreeBSD.ORG Mon Feb 9 10:09:46 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 98A227C6; Mon, 9 Feb 2015 10:09:46 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3BF4A9B5; Mon, 9 Feb 2015 10:09:46 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t19A9fCw033052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 9 Feb 2015 12:09:41 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t19A9fCw033052 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t19A9fSp033051; Mon, 9 Feb 2015 12:09:41 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 9 Feb 2015 12:09:41 +0200 From: Konstantin Belousov To: Bruce Evans Subject: Re: svn commit: r278431 - head/sys/contrib/vchiq/interface/vchiq_arm Message-ID: <20150209100940.GF42409@kib.kiev.ua> References: <201502090231.t192VS6C060751@svn.freebsd.org> <20150209170045.S1037@besplex.bde.org> <20150209090315.GD42409@kib.kiev.ua> <20150209203647.L1800@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150209203647.L1800@besplex.bde.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: svn-src-head@freebsd.org, Oleksandr Tymoshenko , svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Feb 2015 10:09:46 -0000 On Mon, Feb 09, 2015 at 08:51:02PM +1100, Bruce Evans wrote: > On Mon, 9 Feb 2015, Konstantin Belousov wrote: > > > On Mon, Feb 09, 2015 at 05:00:49PM +1100, Bruce Evans wrote: > >> On Mon, 9 Feb 2015, Oleksandr Tymoshenko wrote: > >> ... > >> I think the full bugs only occur when arch has strict alignment > >> requirements and the alignment of the __packed objects is not known. > >> This means that only lesser bugs occur on x86 (unless you enable > >> alignment checking, but this arguably breaks the ABI). The compiler > >> just generates possibly-misaligned full-width accesses if the arch > >> doesn't have strict alignment requirements. Often the acceses turn > >> out to be aligned at runtime. Otherwise, the hardware does them > >> atomically, with a smaller efficiency penalty than split accesses. > > > > On x86 unaligned access is non-atomic. This was very visible on > > Core2 CPUs where DPCPU code mishandled the alignment, resulting in > > the mutexes from the per-cpu areas breaking badly. > > > > Modern CPUs should not lock several cache lines simultaneously either. > > Interesting. I thought that this was relatively easy to handle in > hardware and required for compatibility, so hardware did it. Trying to lock to cache lines easily results in deadlock. FWIW, multi-socket Intel platforms are already deadlock-prone due to the cache, and have some facilities to debug this. > > This gives a reason other than efficiency to enable alignment checking > so as to find all places that do misaligned accesses. I last tried this > more than 20 years ago. Compilers mostly generated aligned accesses. > One exception was for copying small (sub)structs. Inlining of the copy > assumed maximal alignment or no alignment traps. Library functions are > more of a problem. FreeBSD amd64 and i386 memcpy also assume this. > Similarly for the MD mem* in the kernel. Mostly things are suitably > aligned, so it is the correct optimization to not do extra work to align. I also did experiments with preloadable dso which sets EFLAGS.AC bit. Last time I tried, it broke in the very early libc initialization code, due to unaligned access generated by compiler, as you described. This was with in-tree gcc. Tried with the clang-compiled world, I got SIGBUS due to unaligned access in ld-elf.so.1. AC does not work in ring 0, and Intel re-purposed the bit for kernel recently for 'security' theater.