From owner-freebsd-arch@FreeBSD.ORG Sat Oct 25 20:25:12 2014 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3237BF77 for ; Sat, 25 Oct 2014 20:25:12 +0000 (UTC) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "funkthat.com", Issuer "funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 02DF8634 for ; Sat, 25 Oct 2014 20:25:11 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id s9PKP9R7031825 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 25 Oct 2014 13:25:10 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id s9PKP9bP031824; Sat, 25 Oct 2014 13:25:09 -0700 (PDT) (envelope-from jmg) Date: Sat, 25 Oct 2014 13:25:09 -0700 From: John-Mark Gurney To: Konstantin Belousov Subject: Re: RfC: fueword(9) and casueword(9) Message-ID: <20141025202509.GX82214@funkthat.com> Mail-Followup-To: Konstantin Belousov , arch@freebsd.org References: <20141021094539.GA1877@kib.kiev.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141021094539.GA1877@kib.kiev.ua> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Sat, 25 Oct 2014 13:25:10 -0700 (PDT) Cc: arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Oct 2014 20:25:12 -0000 Konstantin Belousov wrote this message on Tue, Oct 21, 2014 at 12:45 +0300: > FreeBSD provides the fuword(9) family of functions to fetch a word from > the userspace. Functions return the value read, or -1 on failure (i.e. > when faulted on access). This KPI has flaw, which makes it impossible > to distinguish -1 read from usermode vs. the fault. As John Baldwin > pointed out, fuword(9) cannot be replaced by copyin(9), since fuword(9) > is atomic for aligned data, while copyin(9) is typically implemented as > byte copy. We also need to define what a word is in the man page... I assumed that a word (fuword) was a 32bit word, but it's not on 64 bit arches, it's a 64bit word... if words were 32bit words on 64bit arches, fuword would be safe (assuming reading an unsigned word), but that is not the case... Related to this is that it isn't defined if fubyte (returns an int) reads a signed or unsigned byte. If it reads an unsigned byte, then it is safe, and we do not need an fuebyte version... The same goes w/ fuword16 (returns an int)... > I wanted to fix this wart for long time, below is the prototyped patch, > which adds fueword(9) family of functions. They take the address of > variable where to put the value read, and return 0 on success, -1 on > failure. In similar way, casueword(9) fixes casuword(9). > > The tricky part of the patch are the changes to kern_umtx.c, where the > logic of the loops in the lock acquire routines is delicate and care > must be taken to not obliterate possible errors from the suspension > check or signal test on loop retry. > > I only implemented fueword(9) and casueword(9) for x86 and powerpc. > The fuword(9) and casuword(9) are reimplemented as wrappers around > e-variants. > > For arm, mips and sparc, where I do not know or do not remember the > assembler anymore, I made a hack to provide deficient fueword(9), which > calls fuword(9) and thus still mixing -1 from userspace and fault. See > NO_FUEWORD in machine/param.h; hopefully arch maintainers will fix the > remaining places. > > Some users of fuword(9) are still left, in particular in aio and dtrace. > > Patch was only lightly tested on x86 for now. > > Comments and fixes are welcomed. I'll take a closer look at the patch soon... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."