<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, 5 Apr 2017 at 20:14 Lucas Stach <<a href="mailto:l.stach@pengutronix.de">l.stach@pengutronix.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am Mittwoch, den 05.04.2017, 11:59 +0200 schrieb Daniel Vetter:<br class="gmail_msg">
> On Wed, Apr 05, 2017 at 10:15:44AM +0200, Lucas Stach wrote:<br class="gmail_msg">
> > Am Mittwoch, den 05.04.2017, 00:20 +0000 schrieb Christopher James Halse<br class="gmail_msg">
> > Rogers:<br class="gmail_msg">
> > ><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > On Tue, Apr 4, 2017 at 9:53 PM Daniel Vetter <<a href="mailto:daniel@ffwll.ch" class="gmail_msg" target="_blank">daniel@ffwll.ch</a>> wrote:<br class="gmail_msg">
> > ><br class="gmail_msg">
> > >         On Tue, Apr 4, 2017 at 12:43 PM, Lucas Stach<br class="gmail_msg">
> > >         <<a href="mailto:l.stach@pengutronix.de" class="gmail_msg" target="_blank">l.stach@pengutronix.de</a>> wrote:<br class="gmail_msg">
> > >         >> If I could guarantee that I'd only ever run on<br class="gmail_msg">
> > >         4.13-or-later kernels<br class="gmail_msg">
> > >         >> (I think that's when the previous patches will land?), then<br class="gmail_msg">
> > >         this would<br class="gmail_msg">
> > >         >> indeed be mostly unnecessary. It would save me a bunch of<br class="gmail_msg">
> > >         addfb calls<br class="gmail_msg">
> > >         >> that would predictably fail, but they're cheap.<br class="gmail_msg">
> > >         ><br class="gmail_msg">
> > >         > I don't think we ever had caps for "things are working now,<br class="gmail_msg">
> > >         as they are<br class="gmail_msg">
> > >         > supposed to". i915 wasn't properly synchronizing on foreign<br class="gmail_msg">
> > >         fences for a<br class="gmail_msg">
> > >         > long time, yet we didn't gain a cap for "cross device sync<br class="gmail_msg">
> > >         works now".<br class="gmail_msg">
> > >         ><br class="gmail_msg">
> > >         > If your distro use-case relies on those things working it's<br class="gmail_msg">
> > >         probably<br class="gmail_msg">
> > >         > best to just backport the relevant fixes.<br class="gmail_msg">
> > ><br class="gmail_msg">
> > >         The even better solution for this is to push the backports<br class="gmail_msg">
> > >         through<br class="gmail_msg">
> > >         upstream -stable kernels. This stuff here is simple enough<br class="gmail_msg">
> > >         that we can<br class="gmail_msg">
> > >         do it. Same could have been done for the fairly minimal<br class="gmail_msg">
> > >         fencing fixes<br class="gmail_msg">
> > >         for i915 (at least some of them, the ones in the page-flip).<br class="gmail_msg">
> > ><br class="gmail_msg">
> > >         Otherwise we'll end up with tons IM_NOT_BUGGY and<br class="gmail_msg">
> > >         IM_SLIGHTLY_LESS_BUGGY and<br class="gmail_msg">
> > >         IM_NOT_BUGGY_EXCEPT_THIS_BOTCHED_BACKPORT<br class="gmail_msg">
> > >         flags where no one at all knows what they mean, usage between<br class="gmail_msg">
> > >         different drivers and different userspace is entirely<br class="gmail_msg">
> > >         inconsistent and<br class="gmail_msg">
> > >         they just all add to the confusion. They're just bugs, lets<br class="gmail_msg">
> > >         treat them<br class="gmail_msg">
> > >         like that.<br class="gmail_msg">
> > ><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > It's not *quite* DRM_CAP_PRIME_SCANOUT_NOT_BUGGY - while the relevant<br class="gmail_msg">
> > > hardware allegedly supports it, nouveau/radeon/amdgpu don't do scanout<br class="gmail_msg">
> > > of GTT, so the lack of this cap indicates that there's no point in<br class="gmail_msg">
> > > trying to call addfb2.<br class="gmail_msg">
> > ><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > But calling addfb2 and it failing is not expensive, so this is rather<br class="gmail_msg">
> > > niche.<br class="gmail_msg">
> > ><br class="gmail_msg">
> > ><br class="gmail_msg">
> > > In practice I can just restrict attempting to scanout of imported<br class="gmail_msg">
> > > buffers to i915, as that's the only driver that it'll work on. By the<br class="gmail_msg">
> > > time nouveau/radeon/amdgpu get patches to scanout of GTT the fixes<br class="gmail_msg">
> > > should be old enough that I don't need to care about unfixed kernels.<br class="gmail_msg">
> > ><br class="gmail_msg">
> > So given that most discreet hardware won't ever be able to scanout from<br class="gmail_msg">
> > GTT (latency and iso requirements will be hard to meet), can't we just<br class="gmail_msg">
> > fix the case of the broken prime sharing when migrating to VRAM?<br class="gmail_msg">
> ><br class="gmail_msg">
> > I'm thinking about attaching an exclusive fence to the dma-buf when the<br class="gmail_msg">
> > migration to VRAM happens, then when the GPU is done with the buffer we<br class="gmail_msg">
> > can either write back any changes to GTT, or just drop the fence in case<br class="gmail_msg">
> > the GPU didn't modify the buffer.<br class="gmail_msg">
><br class="gmail_msg">
> We could, but someone needs to type the code for it. There's also the<br class="gmail_msg">
> problem that you need to migrate back, and then doing all that behind<br class="gmail_msg">
> userspaces back might not be the best idea.<br class="gmail_msg">
<br class="gmail_msg">
Drivers with separate VRAM and GTT are already doing a lot of migration<br class="gmail_msg">
behind the userspaces back. The only issue with dma-buf migration to<br class="gmail_msg">
VRAM is that you probably don't want to migrate the pages, but duplicate<br class="gmail_msg">
them in VRAM, doubling memory consumption with possible OOM. But then<br class="gmail_msg">
you could alloc the memory on addfb where you are able to return proper<br class="gmail_msg">
errors.</blockquote><div><br></div><div>Hm. So, on a first inspection, this looks like something I could actually cook up.<br><br></div><div>Looking at amdgpu it seems like the thing to do would be to associate a shadow-bo in VRAM for the imported dma-buf in the addfb call, then pin-and-copy-to the shadow bo in the places where the bo is currently pinned.<br><br></div><div>Is this approach likely to be acceptable?<br></div></div></div>