Re: [PATCH 2/2] mm: prevent gup_fast from racing with COW during fork
From: Linus Torvalds
Date: Mon Oct 26 2020 - 20:20:27 EST
On Mon, Oct 26, 2020 at 4:50 PM Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>
> Right, it isn't a "seqcount" because the read side doesn't spin.
Not all readers spin for seqcount either.
Sure, it's the *common* case, but look at name resolution - it will
basically fail on a seqcount failure in RCU mode, and go to the "slow
and safe" version:
if (unlikely(read_seqcount_retry(&d->d_seq, nd->seq)))
return -ECHILD;
Exactly like gup_fast vs fork, in fact.
So no, you don't need to retry for seqcount failures, doing
seq = seqcount_begin(..);
... optimistic fast case ...
if (!read_seqcount_retry(.., seq))
return 0; // success
.. do slow case ...
is valid and happens.
Linus