postgresql/src/include
Andres Freund b0779abb3a Fix fallback implementation of pg_atomic_write_u32().
I somehow had assumed that in the spinlock (in turn possibly using
semaphores) based fallback atomics implementation 32 bit writes could be
done without a lock. As far as the write goes that's correct, since
postgres supports only platforms with single-copy atomicity for aligned
32bit writes.  But writing without holding the spinlock breaks
read-modify-write operations like pg_atomic_compare_exchange_u32(),
since they'll potentially "miss" a concurrent write, which can't happen
in actual hardware implementations.

In 9.6+ when using the fallback atomics implementation this could lead
to buffer header locks not being properly marked as released, and
potentially some related state corruption.  I don't see a related danger
in 9.5 (earliest release with the API), because pg_atomic_write_u32()
wasn't used in a concurrent manner there.

The state variable of local buffers, before this change, were
manipulated using pg_atomic_write_u32(), to avoid unnecessary
synchronization overhead. As that'd not be the case anymore, introduce
and use pg_atomic_unlocked_write_u32(), which does not correctly
interact with RMW operations.

This bug only caused issues when postgres is compiled on platforms
without atomics support (i.e. no common new platform), or when compiled
with --disable-atomics, which explains why this wasn't noticed in
testing.

Reported-By: Tom Lane
Discussion: <14947.1475690465@sss.pgh.pa.us>
Backpatch: 9.5-, where the atomic operations API was introduced.
2016-10-07 16:55:15 -07:00
..
access Fix some typos in comment 2016-09-26 12:00:00 -04:00
bootstrap Update copyright for 2016 2016-01-02 13:33:40 -05:00
catalog Replace the built-in GIN array opclasses with a single polymorphic opclass. 2016-09-26 14:52:44 -04:00
commands Turn password_encryption GUC into an enum. 2016-09-28 12:22:44 +03:00
common pg_basebackup pg_receivexlog: Issue fsync more carefully 2016-09-29 12:00:00 -04:00
datatype Be more careful about out-of-range dates and timestamps. 2016-03-16 19:09:28 -04:00
executor Fix worst memory leaks in tqueue.c. 2016-07-29 19:31:06 -04:00
fe_utils Fix assorted places in psql to print version numbers >= 10 in new style. 2016-08-16 15:58:45 -04:00
foreign Remove GetUserMappingId() and GetUserMappingById(). 2016-07-22 11:32:23 -04:00
lib Support multiple iterators in the Red-Black Tree implementation. 2016-09-02 08:39:39 +03:00
libpq C comment: fix file name mention on line 1 2016-09-06 00:03:55 -04:00
mb Update copyright for 2016 2016-01-02 13:33:40 -05:00
nodes Add debugging aid "bmsToString(Bitmapset *bms)". 2016-09-16 09:36:24 -04:00
optimizer Speed up planner's scanning for parallel-query hazards. 2016-08-19 14:03:13 -04:00
parser Improve parser's and planner's handling of set-returning functions. 2016-09-13 13:54:24 -04:00
port Fix fallback implementation of pg_atomic_write_u32(). 2016-10-07 16:55:15 -07:00
portability Update copyright for 2016 2016-01-02 13:33:40 -05:00
postmaster Avoid using PostmasterRandom() for DSM control segment ID. 2016-09-23 09:54:11 -04:00
regex Make locale-dependent regex character classes work for large char codes. 2016-09-05 17:06:29 -04:00
replication Add conninfo to pg_stat_wal_receiver 2016-06-29 16:57:17 -04:00
rewrite Update copyright for 2016 2016-01-02 13:33:40 -05:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Fix fallback implementation of pg_atomic_write_u32(). 2016-10-07 16:55:15 -07:00
tcop Stop the executor if no more tuples can be sent from worker to leader. 2016-06-06 14:52:58 -04:00
tsearch Final pgindent + perltidy run for 9.6. 2016-08-15 13:42:51 -04:00
utils Show a sensible value in pg_settings.unit for GUC_UNIT_XSEGS variables. 2016-10-03 16:40:25 -04:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
Makefile Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
c.h Make init_spin_delay() C89 compliant and change stuck spinlock reporting. 2016-04-13 17:00:53 -07:00
fmgr.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
funcapi.h Widen query numbers-of-tuples-processed counters to uint64. 2016-03-12 16:05:29 -05:00
getaddrinfo.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
getopt_long.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
miscadmin.h Mark PostmasterPid as PGDLLIMPORT. 2016-06-03 14:06:35 -04:00
pg_config.h.in Fix building with LibreSSL. 2016-09-15 22:52:51 +03:00
pg_config.h.win32 Stamp HEAD as 10devel. 2016-08-15 13:49:49 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Add support for more extensive testing of raw_expression_tree_walker(). 2016-05-23 19:08:26 -04:00
pg_getopt.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_trace.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pgstat.h Rename WAIT_* constants to PG_WAIT_*. 2016-10-05 08:04:52 -04:00
pgtar.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pgtime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
port.h Simplify correct use of simple_prompt(). 2016-08-30 17:02:02 -04:00
postgres.h Be pickier about converting between Name and Datum. 2016-09-13 17:17:48 -04:00
postgres_ext.h Add a nonlocalized version of the severity field to client error messages. 2016-08-26 16:20:17 -04:00
postgres_fe.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rusagestub.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
windowapi.h Update copyright for 2016 2016-01-02 13:33:40 -05:00