pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix fallback implementation of pg_atomic_write_u32(). 3+ messages / 1 participants [nested] [flat]
* pgsql: Fix fallback implementation of pg_atomic_write_u32(). @ 2016-10-08 00:07 Andres Freund <andres@anarazel.de> 0 siblings, 0 replies; 3+ messages in thread From: Andres Freund @ 2016-10-08 00:07 UTC (permalink / raw) To: pgsql-committers 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. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/b0779abb3add11d4dd745779dd81ea8ecdd00a1d Modified Files -------------- src/backend/port/atomics.c | 13 +++++++++++++ src/backend/storage/buffer/bufmgr.c | 6 +++--- src/backend/storage/buffer/localbuf.c | 16 ++++++++-------- src/include/port/atomics.h | 25 +++++++++++++++++++++++-- src/include/port/atomics/fallback.h | 3 +++ src/include/port/atomics/generic.h | 9 +++++++++ src/include/storage/buf_internals.h | 3 ++- 7 files changed, 61 insertions(+), 14 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix fallback implementation of pg_atomic_write_u32(). @ 2016-10-08 00:07 Andres Freund <andres@anarazel.de> 0 siblings, 0 replies; 3+ messages in thread From: Andres Freund @ 2016-10-08 00:07 UTC (permalink / raw) To: pgsql-committers 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. Branch ------ REL9_6_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/a4b25cd9cba99b2bf1363f6b4fb9ced84b46d796 Modified Files -------------- src/backend/port/atomics.c | 13 +++++++++++++ src/backend/storage/buffer/bufmgr.c | 6 +++--- src/backend/storage/buffer/localbuf.c | 16 ++++++++-------- src/include/port/atomics.h | 25 +++++++++++++++++++++++-- src/include/port/atomics/fallback.h | 3 +++ src/include/port/atomics/generic.h | 9 +++++++++ src/include/storage/buf_internals.h | 3 ++- 7 files changed, 61 insertions(+), 14 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix fallback implementation of pg_atomic_write_u32(). @ 2016-10-08 00:07 Andres Freund <andres@anarazel.de> 0 siblings, 0 replies; 3+ messages in thread From: Andres Freund @ 2016-10-08 00:07 UTC (permalink / raw) To: pgsql-committers 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. Branch ------ REL9_5_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/93fd6de14156d8d9c8d47e6cbfd067ab2b02e399 Modified Files -------------- src/backend/port/atomics.c | 13 +++++++++++++ src/include/port/atomics.h | 25 +++++++++++++++++++++++-- src/include/port/atomics/fallback.h | 3 +++ src/include/port/atomics/generic.h | 9 +++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2016-10-08 00:07 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2016-10-08 00:07 pgsql: Fix fallback implementation of pg_atomic_write_u32(). Andres Freund <andres@anarazel.de> 2016-10-08 00:07 pgsql: Fix fallback implementation of pg_atomic_write_u32(). Andres Freund <andres@anarazel.de> 2016-10-08 00:07 pgsql: Fix fallback implementation of pg_atomic_write_u32(). Andres Freund <andres@anarazel.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox