Page MenuHomeFreeBSD

buf_ring/drbr: Add buf_ring_peek_clear_sc and use it in drbr_peek
ClosedPublic

Authored by sepherosa_gmail.com on Feb 24 2016, 1:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 24, 4:12 AM
Unknown Object (File)
Wed, Apr 24, 1:05 AM
Unknown Object (File)
Mar 23 2024, 1:26 AM
Unknown Object (File)
Mar 11 2024, 11:11 AM
Unknown Object (File)
Feb 16 2024, 6:57 AM
Unknown Object (File)
Feb 16 2024, 5:53 AM
Unknown Object (File)
Dec 24 2023, 11:31 PM
Unknown Object (File)
Dec 20 2023, 12:54 AM
Subscribers

Details

Summary

Unlike buf_ring_peek, it only supports single consumer mode, and it clears the cons_head if DEBUG_BUFRING/INVARIANTS is defined.

The normal use case of drbr_peek for network drivers is:

m = drbr_peek(br);
err = hw_spec_encap(&m); /* could m_defrag/m_collapse */
(*)
if (err) {
    if (m == NULL)
        drbr_advance(br);
    else
        drbr_putback(br, m);
    /* break the loop */
}
drbr_advance(br);

The race is:
If hw_spec_encap() m_defrag or m_collapse the mbuf, i.e. the old mbuf was freed, or like the Hyper-V's network driver, that transmission-done does not even require the TX lock; then on the other CPU at the (*) time, the freed mbuf could be recycled and being drbr_enqueue even before the current CPU had the chance to call drbr_{advance,putback}. This triggers a panic in drbr_enqueue duplicated element check, if DEBUG_BUFRING/INVARIANTS is defined.

Use buf_ring_peek_clear_sc() in drbr_peek() to fix the above race.

This change is a NO-OP, if neither DEBUG_BUFRING nor INVARIANTS are defined.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sepherosa_gmail.com retitled this revision from to buf_ring/drbr: Add buf_ring_peek_clear_sc and use it in drbr_peek.
sepherosa_gmail.com updated this object.
sepherosa_gmail.com edited the test plan for this revision. (Show Details)

It will be committed next Monday if no objection comes.

This revision was automatically updated to reflect the committed changes.