Re: [PATCH 1/1] dma-buf: heaps: Map system heap pages as managed by linux vm

From: Christoph Hellwig
Date: Tue Feb 02 2021 - 03:52:40 EST


On Tue, Feb 02, 2021 at 12:44:44AM -0800, Suren Baghdasaryan wrote:
> On Mon, Feb 1, 2021 at 11:03 PM Christoph Hellwig <hch@xxxxxxxxxxxxx> wrote:
> >
> > IMHO the
> >
> > BUG_ON(vma->vm_flags & VM_PFNMAP);
> >
> > in vm_insert_page should just become a WARN_ON_ONCE with an error
> > return, and then we just need to gradually fix up the callers that
> > trigger it instead of coming up with workarounds like this.
>
> For the existing vm_insert_page users this should be fine since
> BUG_ON() guarantees that none of them sets VM_PFNMAP.

Even for them WARN_ON_ONCE plus an actual error return is a way
better assert that is much developer friendly.

> However, for the
> system_heap_mmap I have one concern. When vm_insert_page returns an
> error due to VM_PFNMAP flag, the whole mmap operation should fail
> (system_heap_mmap returning an error leading to dma_buf_mmap failure).
> Could there be cases when a heap user (DRM driver for example) would
> be expected to work with a heap which requires VM_PFNMAP and at the
> same time with another heap which requires !VM_PFNMAP? IOW, this
> introduces a dependency between the heap and its
> user. The user would have to know expectations of the heap it uses and
> can't work with another heap that has the opposite expectation. This
> usecase is purely theoretical and maybe I should not worry about it
> for now?

If such a case ever arises we can look into it.