Page MenuHomeFreeBSD

Fix "vrefact: wrong use count 0" with DRM
AcceptedPublic

Authored by trasz on Fri, Nov 1, 3:12 PM.

Details

Reviewers
kib
Summary

Bump the vnode use count, not just its hold count. This fixes a panic
triggered by fstatat(..., AT_EMPTY_PATH) on DRM device nodes, which happens
to be what glxinfo(1) from Ubuntu Jammy is doing.

PR: kern/274538

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 60335
Build 57219: arc lint + arc unit

Event Timeline

trasz requested review of this revision.Fri, Nov 1, 3:12 PM

This follows a somewhat similar fix in https://reviews.freebsd.org/D29323?id=86801. I can't say I have a proper understanding of what's going on here though.

Here's the test case from Alex S:

#define _GNU_SOURCE

#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

int main() {
  int fd = open("/dev/dri/card0", O_RDWR);
  assert(fd != -1);

  struct stat st;
  fstatat(fd, "", &st, AT_EMPTY_PATH);

  return 0;
}

This cannot be right.

If the file references vnode, vnode must be active and have the use count at least 1, because file vref-ed the vnode on open.

In D47391#1080971, @kib wrote:

This cannot be right.

If the file references vnode, vnode must be active and have the use count at least 1, because file vref-ed the vnode on open.

Good point. Okay, so here's another attempt; this time in code specific to linuxkpi.

If going that way, then you can remove the adjacent vhold() and vdrop() as they are redundant.

It should be fine modulo the note about vhold() no longer needed.

This revision is now accepted and ready to land.Mon, Nov 4, 10:24 PM