Re: Using Valgrind to detect faulty buffer accesses (no pin or buffer content lock held)
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: Andres Freund <andres@anarazel.de>,
Alvaro Herrera <alvherre@2ndquadrant.com>, Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-04-26T00:17:17Z
Lists: pgsql-hackers
Attachments
- v2-0001-Add-Valgrind-buffer-access-instrumentation.patch (application/octet-stream) patch v2-0001
- v2-0002-Add-nbtree-Valgrind-buffer-lock-checks.patch (application/octet-stream) patch v2-0002
On Fri, Apr 24, 2020 at 6:37 PM Peter Geoghegan <pg@bowt.ie> wrote: > The final two patches fix the two newly discovered bugs -- I don't > have a fix for the first bug yet, since that one is more complicated > (and probably more serious). I pushed both of the two fixes that I posted yesterday -- fixes for the benign "no buffer lock held" issues in nbtree page deletion. We still need a fix for the more serious issue, though. And that will need to be backpatched down to v11. I'll try to get to that next week. Attached is v2 of the patch series. This version has a centralized description of what we require from nbtree code above _bt_getbuf(), alongside existing, similar commentary. Here's the general idea: If we lock a buffer, that has to go through one of the wrapper functions that knows about Valgrind in all cases. It's presented as a stricter version of what happens in bufmgr.c for all buffers from all access methods. I also added something about how the nbtree Valgrind client requests (those added by the second patch in the series) assume that the bufmgr.c client requests (from the first patch) also take place. We need to be able to rely on bufmgr.c to "clean up" in the event of an error, so the second patch has a strict dependency on the first. If the transaction aborts, we can rely on bufmgr.c marking the buffer's page as defined when the backend acquires its first buffer pin on the buffer in the next transaction (doesn't matter whether or not the same block/page is in the same buffer as before). This is why we can't use client requests for local buffers (not that we'd want to; the existing aset.c Valgrind client requests take care of them automatically). -- Peter Geoghegan
Commits
-
Add nbtree Valgrind buffer lock checks.
- 4a70f829d86c 14.0 landed
-
Add Valgrind buffer access instrumentation.
- 1e0dfd166b3f 14.0 landed
-
Fix bug in nbtree VACUUM "skip full scan" feature.
- b0229f26da75 13.0 cited
-
Fix another minor page deletion buffer lock issue.
- 7154aa16a64d 13.0 landed
-
Fix minor nbtree page deletion buffer lock issue.
- fa7ff642c22c 13.0 landed
-
Skip full index scan during cleanup of B-tree indexes when possible
- 857f9c36cda5 11.0 cited