Bug 197592 - can't switch bpf to zero-copy mode
Summary: can't switch bpf to zero-copy mode
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-13 10:41 UTC by aigars
Modified: 2016-01-14 22:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aigars 2015-02-13 10:41:06 UTC
BIOCSETBUFMODE ioctl call on bpf with BPF_BUFMODE_ZBUF argument always returns EBUSY.
Reason: 
bpfopen() in sys/net/bpf.c calls bpf_buffer_ioctl_sblen() on every opened bpf device. 
bpf_buffer_ioctl_sblen() initializes bd_fbuf and bd_sbuf to freshly allocated memory buffers. 
Therefore later in BIOCSETBUFMODE ioctl the following condition is always true:
                if (d->bd_sbuf != NULL || d->bd_hbuf != NULL ||
                    d->bd_fbuf != NULL || d->bd_bif != NULL) {
                        BPFD_UNLOCK(d);
                        CURVNET_RESTORE();
                        return (EBUSY);
                }

Solution: 
Insert this code in BIOCSETBUFMODE ioctl:
                if(*(u_int *)addr == BPF_BUFMODE_ZBUF && d->bd_bufmode == BPF_BUFMODE_BUFFER) {
                         bpf_buffer_free(d);
                        d->bd_sbuf = 0;
                        d->bd_fbuf = 0;
                        d->bd_hbuf = 0;
                }

This works for switching to zerocopy mode. Probably some checking and action is needed if someone tries to switch back to BPF_BUFMODE_BUFFER mode after zerocopy mode.

10.1-RELEASE has the same problem.
Comment 1 Hiren Panchasara freebsd_committer freebsd_triage 2015-02-23 23:37:29 UTC
Moving to -net.
Comment 2 Jung-uk Kim freebsd_committer freebsd_triage 2016-01-14 22:56:17 UTC
This problem was fixed on head (r286139) and it was MFC'ed to stable/10 (r286850).