Closed Bug 1743632 Opened 3 years ago Closed 3 years ago

Strange FD management in DMABufSurface

Categories

(Core :: Graphics: Layers, defect)

Desktop
Linux
defect

Tracking

()

RESOLVED FIXED
97 Branch
Tracking Status
firefox96 --- unaffected
firefox97 --- fixed

People

(Reporter: heftig, Assigned: stransky)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 1 obsolete file)

While looking at DMABufSurface.cpp, I noticed the following code:

  const EGLint attribs[] = {LOCAL_EGL_SYNC_NATIVE_FENCE_FD_ANDROID, mSyncFd,
                            LOCAL_EGL_NONE};
  mSync = egl->fCreateSync(LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
  close(mSyncFd);
  mSyncFd = -1;

It closes the mSyncFd after handing it to fCreateSync, whether the latter succeeds or not.

However, the spec says that the FD is owned by EGL afterwards.
So EGL is responsible for closing it, not the application, and the FD should not be closed.

The other uses of fCreateSync with an FD (e.g. SharedSurfaceAndroidHardwareBuffer) do avoid the close:

  auto rawFD = fenceFd.TakePlatformHandle();
  const EGLint attribs[] = {LOCAL_EGL_SYNC_NATIVE_FENCE_FD_ANDROID, rawFD.get(),
                            LOCAL_EGL_NONE};

  EGLSync sync = egl->fCreateSync(LOCAL_EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
  if (!sync) {
    gfxCriticalNote << "Failed to create EGLSync from fd";
    return;
  }
  // Release fd here, since it is owned by EGLSync
  Unused << rawFD.release();

The code of DMABufSurface should also be ported to use UniqueFileHandle to manage FDs more safely, not raw ints and close.

See Also: → 1742533, 1721617
See Also: → 1743638
Severity: -- → S3
Flags: needinfo?(robert.mader)

Interesting find! This is Martins field of expertise though.
Martin, does this sound reasonable to you?

Flags: needinfo?(robert.mader) → needinfo?(stransky)

Yes, the UniqueFileHandle transition would be great.

Looks like DMABufSurface::FenceWait() is not longer used which is strange.

Flags: needinfo?(stransky)
Assignee: nobody → stransky
Status: NEW → ASSIGNED
  • Remove FenceImportFromFd() and import fence in DMABufSurface::FenceWait().
  • Don't close Fence FD when fence import was sucessfull.
  • Don't save EGLSync to DMABufSurface after eglClientWaitSync().
  • Implement SharedSurface_DMABUF::WaitForBufferOwnership() by DMABufSurface::FenceWait().

Depends on D133901

Attachment #9255507 - Attachment is obsolete: true
Pushed by stransky@redhat.com: https://hg.mozilla.org/integration/autoland/rev/175b3cfd1fd3 [Linux] Polish GLFence management of DMABufSurface, r=emilio https://hg.mozilla.org/integration/autoland/rev/1023d9d498f4 [Linux] Use GL Fence in SharedSurfaceDMABUF
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 97 Branch

The patch landed in nightly and beta is affected.
:stransky, is this bug important enough to require an uplift?
If not please set status_beta to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(stransky)

No need to uplift. DMABuf surface was not used before this patch.

Flags: needinfo?(stransky)
Regressions: 1749119
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: