From owner-freebsd-hackers@freebsd.org Fri Aug 16 08:14:20 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5B77DC43CF for ; Fri, 16 Aug 2019 08:14:20 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 468x1S0FDQz3wbx; Fri, 16 Aug 2019 08:14:19 +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 x7G8E6QQ035762 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 16 Aug 2019 11:14:09 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x7G8E6QQ035762 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x7G8E66b035761; Fri, 16 Aug 2019 11:14:06 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 16 Aug 2019 11:14:06 +0300 From: Konstantin Belousov To: Andriy Gapon Cc: freebsd-hackers@freebsd.org Subject: Re: confused/concerned about ZFS / 64-bit atomics / 32-bit platforms Message-ID: <20190816081406.GM2738@kib.kiev.ua> References: <8bbee981-4f95-22eb-d9ec-00267c8e111d@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8bbee981-4f95-22eb-d9ec-00267c8e111d@FreeBSD.org> User-Agent: Mutt/1.12.1 (2019-06-15) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-Rspamd-Queue-Id: 468x1S0FDQz3wbx X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-6.94 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.94)[-0.939,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Aug 2019 08:14:20 -0000 On Fri, Aug 16, 2019 at 10:23:01AM +0300, Andriy Gapon wrote: > > I somewhat confused with respect to what guarantees C provides with > respect to accessing 64-bit objects on 32-bit platforms, if any. > I am also concerned about the use of 64-bit atomic values in ZFS given > that FreeBSD seems to support ZFS on 32-bit platforms (powerpc, i386, ...). > > My concerns stems from a failed import of a ZFS change from illumos. > That change has this pattern: > > volatile uint64_t *p; > uint64_t x, y; > ... > x = *p; > ... > atomic_foo_64(p, y); > > Specifically, I am concerned that there can be a torn read in x=*p > assignment on 32-bit platforms even if they provide a native > implementation of atomic_foo_64(). I am even more concerned about > platforms where atomic_foo_64() is not available and we need to emulate > it in opensolaris_atomic.c with the help from atomic_mtx. > > In more general terms, I am concerned about plain reads of 64-bit > variables that are manipulated atomically elsewhere, on 32-bit platforms. > Is my concern justified? Yes, your concerns are justified. Plain reads of 64bit variables on 32bit arches are not atomic. Also we do not provide e.g. atomic_load_64(9) on 32bit machines. On some architectures, there might be specific tricks to ensure atomicity of load and store for 64bit vars, e.g. on i386 (actually Pentium and newer) with use of of the CMPXCHG8 instruction, using it in dumb mode. ARM seems to provide LDREXD/STREXD. But AFAIK 32 ppc does not have any means to do it. > > Note that I saw the above access pattern only in the code that is not > imported yet. I only suspect that that pattern might already be present > in the current ZFS/FreeBSD code given that it uses 64-bit variables and > atomics a lot. > I am not sure if there is a quick way to check that. Maybe > devel/coccinelle could be used for that. > > -- > Andriy Gapon > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"