I wonder, if "buf_state &= BM_VALID" is a typo here, maybe it supposed to be "buf_state &= ~BM_VALID" as in ExtendBufferedRelShared()...
Yeah, that's true. I analyze this issue again, and I think the root cause is the " buf_state &= BM_VALID" .
Nice catch. I believe the intention is to clear the BM_VALID bit.
By the way, I wonder if it would be worthwhile to define new macros for bit operations such as set_bit, clear_bit, test_bit, and so on, so that we can avoid such typos in the future.