<div dir="ltr"><div><div>I also haven't tested it on hardware (all my hardware seems to be supported by amdgpu), but the only times we touch prime_shared_count are:<br></div>1) It's set to 1 in radeon_gem_prime_import_sg_table. This shouldn't be called in the self-import case (and isn't, as far as I can tell), and<br></div>2) It's incremented in radeon_gem_prime_pin, right after the bo is pinned to GTT, so cannot be migrated to VRAM anyway (unless there's an unmatched radeon_bo_unpin call somewhere else?).<br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 4 Apr 2017 at 02:30 Christian König <<a href="mailto:deathsimple@vodafone.de">deathsimple@vodafone.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 03.04.2017 um 17:51 schrieb Alex Deucher:<br class="gmail_msg">
> On Mon, Apr 3, 2017 at 4:24 AM, Christian König <<a href="mailto:deathsimple@vodafone.de" class="gmail_msg" target="_blank">deathsimple@vodafone.de</a>> wrote:<br class="gmail_msg">
>> Am 03.04.2017 um 05:35 schrieb <a href="mailto:raof@ubuntu.com" class="gmail_msg" target="_blank">raof@ubuntu.com</a>:<br class="gmail_msg">
>>> From: Christopher James Halse Rogers<br class="gmail_msg">
>>> <<a href="mailto:christopher.halse.rogers@canonical.com" class="gmail_msg" target="_blank">christopher.halse.rogers@canonical.com</a>><br class="gmail_msg">
>>><br class="gmail_msg">
>>> BOs shared via dma-buf, either imported or exported, cannot sensibly be<br class="gmail_msg">
>>> migrated to VRAM<br class="gmail_msg">
>>> without breaking the dma-buf sharing. Refuse userspace requests to migrate<br class="gmail_msg">
>>> to VRAM,<br class="gmail_msg">
>>> ensure such BOs are not migrated during command submission, and refuse to<br class="gmail_msg">
>>> pin them<br class="gmail_msg">
>>> to VRAM.<br class="gmail_msg">
>>><br class="gmail_msg">
>>> v2: Don't pin BOs in GTT. Instead, refuse to migrate BOs to VRAM.<br class="gmail_msg">
>>><br class="gmail_msg">
>>> Signed-off-by: Christopher James Halse Rogers<br class="gmail_msg">
>>> <<a href="mailto:christopher.halse.rogers@canonical.com" class="gmail_msg" target="_blank">christopher.halse.rogers@canonical.com</a>><br class="gmail_msg">
>><br class="gmail_msg">
>> Patches #4, #6 and this one (#7) are Reviewed-by: Christian König<br class="gmail_msg">
>> <<a href="mailto:christian.koenig@amd.com" class="gmail_msg" target="_blank">christian.koenig@amd.com</a>>.<br class="gmail_msg">
> Will this cause any issues with self sharing?  E.g., the standard use<br class="gmail_msg">
> case with a single GPU and DRI3?<br class="gmail_msg">
<br class="gmail_msg">
No, the code from amdgpu to count the number of times we really shared a<br class="gmail_msg">
BO with somebody was ported over to radeon as far as I can see.<br class="gmail_msg">
<br class="gmail_msg">
So that should work fine, but I haven't double checked or tested it.<br class="gmail_msg">
<br class="gmail_msg">
Christian.<br class="gmail_msg">
<br class="gmail_msg">
><br class="gmail_msg">
> Alex<br class="gmail_msg">
><br class="gmail_msg">
>><br class="gmail_msg">
>>> ---<br class="gmail_msg">
>>>    drivers/gpu/drm/radeon/radeon_cs.c     | 10 ++++++++++<br class="gmail_msg">
>>>    drivers/gpu/drm/radeon/radeon_gem.c    |  4 ++++<br class="gmail_msg">
>>>    drivers/gpu/drm/radeon/radeon_object.c |  5 +++++<br class="gmail_msg">
>>>    3 files changed, 19 insertions(+)<br class="gmail_msg">
>>><br class="gmail_msg">
>>> diff --git a/drivers/gpu/drm/radeon/radeon_cs.c<br class="gmail_msg">
>>> b/drivers/gpu/drm/radeon/radeon_cs.c<br class="gmail_msg">
>>> index a8442f7196d6..df6b58c08544 100644<br class="gmail_msg">
>>> --- a/drivers/gpu/drm/radeon/radeon_cs.c<br class="gmail_msg">
>>> +++ b/drivers/gpu/drm/radeon/radeon_cs.c<br class="gmail_msg">
>>> @@ -164,6 +164,16 @@ static int radeon_cs_parser_relocs(struct<br class="gmail_msg">
>>> radeon_cs_parser *p)<br class="gmail_msg">
>>>                          p->relocs[i].allowed_domains = domain;<br class="gmail_msg">
>>>                  }<br class="gmail_msg">
>>>    +             /* Objects shared as dma-bufs cannot be moved to VRAM */<br class="gmail_msg">
>>> +               if (p->relocs[i].robj->prime_shared_count) {<br class="gmail_msg">
>>> +                       p->relocs[i].allowed_domains &=<br class="gmail_msg">
>>> ~RADEON_GEM_DOMAIN_VRAM;<br class="gmail_msg">
>>> +                       if (!p->relocs[i].allowed_domains) {<br class="gmail_msg">
>>> +                               DRM_ERROR("BO associated with dma-buf<br class="gmail_msg">
>>> cannot "<br class="gmail_msg">
>>> +                                         "be moved to VRAM\n");<br class="gmail_msg">
>>> +                               return -EINVAL;<br class="gmail_msg">
>>> +                       }<br class="gmail_msg">
>>> +               }<br class="gmail_msg">
>>> +<br class="gmail_msg">
>>>                  p->relocs[i].<a href="http://tv.bo" rel="noreferrer" class="gmail_msg" target="_blank">tv.bo</a> = &p->relocs[i].robj->tbo;<br class="gmail_msg">
>>>                  p->relocs[i].tv.shared = !r->write_domain;<br class="gmail_msg">
>>>    diff --git a/drivers/gpu/drm/radeon/radeon_gem.c<br class="gmail_msg">
>>> b/drivers/gpu/drm/radeon/radeon_gem.c<br class="gmail_msg">
>>> index 96683f5b2b1b..067ea7d7658a 100644<br class="gmail_msg">
>>> --- a/drivers/gpu/drm/radeon/radeon_gem.c<br class="gmail_msg">
>>> +++ b/drivers/gpu/drm/radeon/radeon_gem.c<br class="gmail_msg">
>>> @@ -120,6 +120,10 @@ static int radeon_gem_set_domain(struct<br class="gmail_msg">
>>> drm_gem_object *gobj,<br class="gmail_msg">
>>>                          return r;<br class="gmail_msg">
>>>                  }<br class="gmail_msg">
>>>          }<br class="gmail_msg">
>>> +       if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count)<br class="gmail_msg">
>>> {<br class="gmail_msg">
>>> +               /* A BO that is associated with a dma-buf cannot be<br class="gmail_msg">
>>> sensibly migrated to VRAM */<br class="gmail_msg">
>>> +               return -EINVAL;<br class="gmail_msg">
>>> +       }<br class="gmail_msg">
>>>          return 0;<br class="gmail_msg">
>>>    }<br class="gmail_msg">
>>>    diff --git a/drivers/gpu/drm/radeon/radeon_object.c<br class="gmail_msg">
>>> b/drivers/gpu/drm/radeon/radeon_object.c<br class="gmail_msg">
>>> index 74b276060c20..bec2ec056de4 100644<br class="gmail_msg">
>>> --- a/drivers/gpu/drm/radeon/radeon_object.c<br class="gmail_msg">
>>> +++ b/drivers/gpu/drm/radeon/radeon_object.c<br class="gmail_msg">
>>> @@ -352,6 +352,11 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo,<br class="gmail_msg">
>>> u32 domain, u64 max_offset,<br class="gmail_msg">
>>>                  return 0;<br class="gmail_msg">
>>>          }<br class="gmail_msg">
>>> +       if (bo->prime_shared_count && domain == RADEON_GEM_DOMAIN_VRAM) {<br class="gmail_msg">
>>> +               /* A BO shared as a dma-buf cannot be sensibly migrated to<br class="gmail_msg">
>>> VRAM */<br class="gmail_msg">
>>> +               return -EINVAL;<br class="gmail_msg">
>>> +       }<br class="gmail_msg">
>>> +<br class="gmail_msg">
>>>          radeon_ttm_placement_from_domain(bo, domain);<br class="gmail_msg">
>>>          for (i = 0; i < bo->placement.num_placement; i++) {<br class="gmail_msg">
>>>                  /* force to pin into visible video ram */<br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>> _______________________________________________<br class="gmail_msg">
>> amd-gfx mailing list<br class="gmail_msg">
>> <a href="mailto:amd-gfx@lists.freedesktop.org" class="gmail_msg" target="_blank">amd-gfx@lists.freedesktop.org</a><br class="gmail_msg">
>> <a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> amd-gfx mailing list<br class="gmail_msg">
> <a href="mailto:amd-gfx@lists.freedesktop.org" class="gmail_msg" target="_blank">amd-gfx@lists.freedesktop.org</a><br class="gmail_msg">
> <a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div>