HomeFreeBSD

buf_ring: Ensure correct ordering of loads

Description

buf_ring: Ensure correct ordering of loads

When enqueueing on an architecture with a weak memory model ensure
loading br->br_prod_head and br->br_cons_tail are ordered correctly.

If br_cons_tail is loaded first then other threads may perform a
dequeue and enqueue before br_prod_head is loaded. This will mean the
tail is one less than it should be and the code under the
prod_next == cons_tail check could incorrectly be skipped.

buf_ring_dequeue_mc has the same issue with br->br_prod_tail and
br->br_cons_head so needs the same fix.

Reported by: Ali Saidi <alisaidi@amazon.com>
Co-developed by: Ali Saidi <alisaidi@amazon.com>
Reviewed by: imp, kib, markj
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D46155

(cherry picked from commit fe2445f47d027c73aa7266669e7d94b70d3949a4)

Details

Provenance
andrewAuthored on Aug 19 2024, 9:07 AM
Reviewer
imp
Differential Revision
D46155: buf_ring: Ensure correct ordering of loads
Parents
rGbfd435bfe8e1: buf_ring: Use atomic operations with br_prod_tail
Branches
Unknown
Tags
Unknown