From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, christian.koenig@amd.com
Subject: Re: [PATCH 4/4] dma-buf: nuke reservation_object seq number
Date: Wed, 14 Aug 2019 19:48:28 +0200 [thread overview]
Message-ID: <20190814174828.GS7444@phenom.ffwll.local> (raw)
In-Reply-To: <156580322834.2301.14370001730544642496@skylake-alporthouse-com>
On Wed, Aug 14, 2019 at 06:20:28PM +0100, Chris Wilson wrote:
> Quoting Daniel Vetter (2019-08-14 18:06:26)
> > On Wed, Aug 14, 2019 at 05:42:48PM +0100, Chris Wilson wrote:
> > > Quoting Daniel Vetter (2019-08-14 16:39:08)
> [snip]
> > > > > > > if (old)
> > > > > > > - old->shared_count = 0;
> > > > > > > - write_seqcount_end(&obj->seq);
> > > > > > > + smp_store_mb(old->shared_count, 0);
> > > >
> > > > So your comment and the kerneldoc don't match up. Quoting
> > > > Documentation/memory-barriers.txt:
> > > >
> > > > This assigns the value to the variable and then inserts a full memory
> > > > barrier after it. It isn't guaranteed to insert anything more than a
> > > > compiler barrier in a UP compilation.
> > > >
> > > > So order is 1. store 2. fence, but your comment suggests you want it the
> > > > other way round.
> > >
> > > What's more weird is that it is a fully serialising instruction that is
> > > used to fence first as part of the update. If that's way PeterZ uses
> > > it...
> >
> > I haven't looked at the implementations tbh, just going with the text. Or
> > do you mean in the write_seqlock that we're replacing?
>
> Nah, I misremembered set_current_state(), all that implies is the fence
> is before the following instructions. I have some recollection that it
> can be used as a RELEASE operation (if only because it is a locked xchg).
> If all else fails, make it an xchg_release(). Or normal assignment +
> smp_wmb().
Yeah that one is called smp_store_release, not smp_store_mb. I think
smp_store_release is the right one here.
> > > It's an exclusive fence. If it is replaced, it must be later than all
> > > the shared fences (and dependent on them directly or indirectly), and
> > > so still a consistent snapshot.
> >
> > I'm not worried about the fence, that part is fine. But we're defacto
> > using the fence as a fancy seqlock-of-sorts. And if the fence gets reused
> > and the pointers match, then our seqlock-of-sorts breaks. But I haven't
> > looked around whether there's more in the code that makes this an
> > irrelevant issue.
>
> No, it should not break if we replace the fence with the same pointer.
> If the fence pointer expires, reused and assigned back as the excl_fence
> -- it is still the excl_fence and by the properties of that
> excl_fence construction, it is later than the shared_fences.
So I thought the rules are that if we have an exclusive fence and shared
fences both present, then the shared fences are after the exclusive one.
But if we race here, then I think we could accidentally sample shared
fences from _before_ the exclusive fences. Rough timeline:
exlusive fence 1 -> shared fence 2 -> exclusive fence, but reuses memory
of fence 1
Then we sample fence 1, capture the shared fence 2, and notice that the
exclusive fence pointer is the same (but not the fence on the timeline)
and conclude that we got a consistent sample.
But the only consistent sample with the new fence state would be only the
exclusive fence.
Reminds me I forgot to look for the usual kref_get_unless_zero trickery we
also need to do here to make sure we have the right fence.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-08-14 17:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-07 13:53 [PATCH 1/4] dma-buf: add reservation_object_fences helper Christian König
2019-08-07 13:53 ` [PATCH 2/4] drm/i915: use new " Christian König
2019-08-07 16:08 ` Chris Wilson
2019-08-07 13:53 ` [PATCH 3/4] dma-buf: further relax reservation_object_add_shared_fence Christian König
2019-08-07 16:10 ` Chris Wilson
2019-08-07 13:53 ` [PATCH 4/4] dma-buf: nuke reservation_object seq number Christian König
2019-08-07 14:17 ` Chris Wilson
2019-08-10 10:51 ` Christian König
2019-08-14 15:39 ` Daniel Vetter
2019-08-14 16:42 ` Chris Wilson
2019-08-14 17:06 ` Chris Wilson
2019-08-14 17:22 ` Chris Wilson
2019-08-14 17:38 ` Chris Wilson
2019-08-14 17:48 ` Chris Wilson
2019-08-14 17:58 ` Koenig, Christian
2019-08-14 18:52 ` Chris Wilson
2019-08-14 17:06 ` Daniel Vetter
2019-08-14 17:20 ` Chris Wilson
2019-08-14 17:48 ` Daniel Vetter [this message]
2019-08-07 16:07 ` [PATCH 1/4] dma-buf: add reservation_object_fences helper Chris Wilson
2019-08-09 13:07 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/4] " Patchwork
2019-08-09 13:31 ` ✓ Fi.CI.BAT: success " Patchwork
2019-08-10 6:31 ` ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190814174828.GS7444@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=chris@chris-wilson.co.uk \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox