Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Aug 2019 10:23:01 +0300
From:      Andriy Gapon <avg@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   confused/concerned about ZFS / 64-bit atomics / 32-bit platforms
Message-ID:  <8bbee981-4f95-22eb-d9ec-00267c8e111d@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

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?

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8bbee981-4f95-22eb-d9ec-00267c8e111d>