Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1698592

Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled()

From Dima Zavin <dmitriyz@waymo.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled()
Date 2017-07-28 10:50 +0200
Message-ID <u8985-1mx-1@gated-at.bofh.it> (permalink)
References <u7xYS-37A-13@gated-at.bofh.it> <u7U95-8vc-31@gated-at.bofh.it> <u88c2-N3-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Jul 28, 2017 at 12:45 AM, Vlastimil Babka <vbabka@suse.cz> wrote:
> [+CC PeterZ]
>
> On 07/27/2017 06:46 PM, Dima Zavin wrote:
>> In codepaths that use the begin/retry interface for reading
>> mems_allowed_seq with irqs disabled, there exists a race condition that
>> stalls the patch process after only modifying a subset of the
>> static_branch call sites.
>>
>> This problem manifested itself as a dead lock in the slub
>> allocator, inside get_any_partial. The loop reads
>> mems_allowed_seq value (via read_mems_allowed_begin),
>> performs the defrag operation, and then verifies the consistency
>> of mem_allowed via the read_mems_allowed_retry and the cookie
>> returned by xxx_begin. The issue here is that both begin and retry
>> first check if cpusets are enabled via cpusets_enabled() static branch.
>> This branch can be rewritted dynamically (via cpuset_inc) if a new
>> cpuset is created. The x86 jump label code fully synchronizes across
>> all CPUs for every entry it rewrites. If it rewrites only one of the
>> callsites (specifically the one in read_mems_allowed_retry) and then
>> waits for the smp_call_function(do_sync_core) to complete while a CPU is
>> inside the begin/retry section with IRQs off and the mems_allowed value
>> is changed, we can hang. This is because begin() will always return 0
>> (since it wasn't patched yet) while retry() will test the 0 against
>> the actual value of the seq counter.
>
> Hm I wonder if there are other static branch users potentially having
> similar problem. Then it would be best to fix this at static branch
> level. Any idea, Peter? An inelegant solution would be to have indicate
> static_branch_(un)likely() callsites ordering for the patching. I.e.
> here we would make sure that read_mems_allowed_begin() callsites are
> patched before read_mems_allowed_retry() when enabling the static key,
> and the opposite order when disabling the static key.
>

This was my main worry, that I'm just patching up one incarnation of
this problem
and other clients will eventually trip over this.

>> The fix is to cache the value that's returned by cpusets_enabled() at the
>> top of the loop, and only operate on the seqcount (both begin and retry) if
>> it was true.
>
> Maybe we could just return e.g. -1 in read_mems_allowed_begin() when
> cpusets are disabled, and test it in read_mems_allowed_retry() before
> doing a proper seqcount retry check? Also I think you can still do the
> cpusets_enabled() check in read_mems_allowed_retry() before the
> was_enabled (or cookie == -1) test?

Hmm, good point! If cpusets_enabled() is true, then we can still test against
was_enabled and do the right thing (adds one extra branch in that case). When
it's false, we still benefit from the static_branch fanciness. Thanks!

Re setting the cookie to -1, I didn't really want to overload the
cookie value but
rather just make the state explicit so it's easier to grawk as this is
all already
subtle enough.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH] mm/slub: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-26 19:00 +0200
  Re: [RFC PATCH] mm/slub: fix a deadlock due to incomplete patching  of cpusets_enabled() Christopher Lameter <cl@linux.com> - 2017-07-26 19:10 +0200
    Re: [RFC PATCH] mm/slub: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-26 22:00 +0200
    [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-27 18:50 +0200
      Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Andrew Morton <akpm@linux-foundation.org> - 2017-07-27 21:50 +0200
        Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-27 23:50 +0200
      Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Andrew Morton <akpm@linux-foundation.org> - 2017-07-27 22:00 +0200
        Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-27 23:50 +0200
      Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Vlastimil Babka <vbabka@suse.cz> - 2017-07-28 09:50 +0200
        Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-28 10:50 +0200
        Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Peter Zijlstra <peterz@infradead.org> - 2017-07-28 11:40 +0200
          Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Vlastimil Babka <vbabka@suse.cz> - 2017-07-28 16:10 +0200
            Re: [PATCH v2] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-28 19:00 +0200
            [PATCH v3] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-31 06:10 +0200
              Re: [PATCH v3] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-31 06:10 +0200
              Re: [PATCH v3] cpuset: fix a deadlock due to incomplete patching of  cpusets_enabled() Vlastimil Babka <vbabka@suse.cz> - 2017-07-31 10:10 +0200
                Re: [PATCH v3] cpuset: fix a deadlock due to incomplete patching of cpusets_enabled() Dima Zavin <dmitriyz@waymo.com> - 2017-07-31 11:10 +0200

csiph-web