From owner-svn-src-all@freebsd.org Mon Aug 22 10:05:04 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 19267BBFDEF; Mon, 22 Aug 2016 10:05:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 89D2D1F10; Mon, 22 Aug 2016 10:05:03 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u7MA4wC8032050 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 22 Aug 2016 13:04:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u7MA4wC8032050 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u7MA4u0w032048; Mon, 22 Aug 2016 13:04:56 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 22 Aug 2016 13:04:56 +0300 From: Konstantin Belousov To: Bruce Evans Cc: Slawa Olhovchenkov , Ed Schouten , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r304555 - head/sys/compat/cloudabi Message-ID: <20160822100456.GA83214@kib.kiev.ua> References: <20160821105207.GS22212@zxy.spb.ru> <20160821210751.J2219@besplex.bde.org> <20160821120016.GZ8192@zxy.spb.ru> <20160821223255.K2478@besplex.bde.org> <20160821131447.GA8192@zxy.spb.ru> <20160821232721.G2639@besplex.bde.org> <20160821135826.GB8192@zxy.spb.ru> <20160822022832.Q3214@besplex.bde.org> <20160821170611.GC8192@zxy.spb.ru> <20160822184056.M1897@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160822184056.M1897@besplex.bde.org> User-Agent: Mutt/1.6.1 (2016-04-27) 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.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2016 10:05:04 -0000 On Mon, Aug 22, 2016 at 06:55:58PM +1000, Bruce Evans wrote: > No. PSL_AC is ignored in kernel mode. Not quite. On recent processors there is a feature called SMAP. If enabled, user mode pages accesses from kernel mode require eflags.ac set to 1. If EFLAGS.AC == 0, usermode access causes #PF with protection violation AFAIR. > Not quite that short. i386 has the 1-byte cli instruction for conveniently > setting the interrupt enable flag, but setting PSL_AC seems to take at > least 3 instructions and 6-7 bytes (pushf; orb $N,$M(%[re][bs]p); popf). In ring 0, when SMAP is present, there are two new instructions STAC (set AC) and CLAC (clear AC). From the manual, the instructions are not available in ring 3 for convenient manipulation of EFLAGS.AC. But I think that the original question was about accesses which cause #AC and not about instructions which manipulate EFLAGS.AC. The description of #AC in SDM contains all relevant details. In short, or userspace accesses must be naturally aligned, otherwise #AC is triggered. I used to have trivial LD_PRELOAD-able dso which just set EFLAGS.AC, but it is not much useful exactly because x86 compilers systematically generate unaligned accesses. Typed languages runtimes sometimes use a witty trick with AC to get tag checking for free. If you assign e.g. a tag 0x7 to pointers, i.e. store tag 0x7 in three low bits of the pointer representation, then load instruction would be movq -0x7(%rdx), %rax and you get the #AC fault in case of any other tag. Quite nifty and gives zero runtime cost for basic dynamic type checking.