Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1213461imi; Fri, 1 Jul 2022 05:32:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vyoeOJo2Jvp494vrdDMxc9P0rkQ8KIjTOPOkmhjgr9W97fkuZ4C5tDtLWPTr6exkYDIVf5 X-Received: by 2002:a05:6402:2816:b0:434:ed38:16f3 with SMTP id h22-20020a056402281600b00434ed3816f3mr18911414ede.116.1656678749079; Fri, 01 Jul 2022 05:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656678749; cv=none; d=google.com; s=arc-20160816; b=y6h4vuVrcl2CbbDjzBOCRbbO20Iq9bglgtdh6zUdaLSfa9frXlOLbANx6LvvcCzmkL 6RVRPXco/d8ZAIQz9/2m7eUMBplsUFmdqeB9dRqvS4GYqpAymwR3EygVBIBFHMb8fYh+ 8rZir6v19YnD9yMCBCmWBig2YnsVwm04rm85poCUlhglrkIO3YDXYcAjjHh1CrB71wh4 /nXPp5PKxhdfole7VqSSC9bQgJa71tjyDy8fUDP7G1m5Gr+JxVU9fRPGSMHLaN2yWrma FcoCC15kcpltE+OjWQlSltgyBPtTEeYZi2N5/rSoWG0Fnjc2B63blkeVgzQ5jUdDuvFh 8QGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=gS4xcf6KYRWMsaoM6FLEDNTOV/idR6A4CHdIdX7xzV0=; b=Y7Y8b8PqqTTBZhHQrl3gqqykdrdDxJH8+UqoVqL7tWYB8LVpfv5WXLAhtlrmn2S/9D NO9yS4Q1CfoTiSvmY/YJNGbCwOrl7+KbjB69oK3ZgnKLzswoR1Z33fIDcwKVvF/ekmxl xmPhYJS5CL8CpV4oIS4HGqeU1cTIxqdbZ4N8BwGvmlEjZxLPnfJsDrnClFMQwE9H7uk7 6Ps7Ct7/POpinPKKeWVpGjS5CDBZ6wscMrbuqIgSG8pm5boXSa3U3BoToveMJQy+UN8O at4fOM5Wp8HUR3Bfg15Yo3ca/y1vC2E9E7l4/VD6xeKeNcOyCBQyAgNfdCeSWXBfO9bD z35w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fk8-20020a056402398800b0043591428d2bsi15847942edb.421.2022.07.01.05.32.04; Fri, 01 Jul 2022 05:32:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235336AbiGALsz (ORCPT + 99 others); Fri, 1 Jul 2022 07:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233057AbiGALsx (ORCPT ); Fri, 1 Jul 2022 07:48:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EEB5479719 for ; Fri, 1 Jul 2022 04:48:51 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 083A0113E; Fri, 1 Jul 2022 04:48:52 -0700 (PDT) Received: from wubuntu (unknown [10.57.84.222]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 54BA13F66F; Fri, 1 Jul 2022 04:48:49 -0700 (PDT) Date: Fri, 1 Jul 2022 12:48:46 +0100 From: Qais Yousef To: Peter Zijlstra Cc: Satya Durga Srinivasu Prabhala , mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: fix rq lock recursion issue Message-ID: <20220701114846.42o2tkm5fqt325df@wubuntu> References: <20220624074240.13108-1-quic_satyap@quicinc.com> <20220630215310.wb3kab72tlh5pq2g@airbuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/01/22 10:33, Peter Zijlstra wrote: > On Thu, Jun 30, 2022 at 10:53:10PM +0100, Qais Yousef wrote: > > Hi Satya > > > > On 06/24/22 00:42, Satya Durga Srinivasu Prabhala wrote: > > > Below recursion is observed in a rare scenario where __schedule() > > > takes rq lock, at around same time task's affinity is being changed, > > > bpf function for tracing sched_switch calls migrate_enabled(), > > > checks for affinity change (cpus_ptr != cpus_mask) lands into > > > __set_cpus_allowed_ptr which tries acquire rq lock and causing the > > > recursion bug. > > > > > > Fix the issue by switching to preempt_enable/disable() for non-RT > > > Kernels. > > > > Interesting bug. Thanks for the report. Unfortunately I can't see this being > > a fix as it just limits the bug visibility to PREEMPT_RT kernels, but won't fix > > anything, no? ie: Kernels compiled with PREEMPT_RT will still hit this failure. > > Worse, there's !RT stuff that grew to rely on the preemptible migrate > disable stuff, so this actively breaks things. > > > I'm curious how the race with set affinity is happening. I would have thought > > user space would get blocked as __schedule() will hold the rq lock. > > > > Do you have more details on that? > > Yeah, I'm not seeing how this works either, in order for > migrate_enable() to actually call __set_cpus_allowed_ptr(), it needs to > have done migrate_disable() *before* schedule, schedule() will then have > to call migrate_disable_swich(), and *then* migrate_enable() does this. > > However, if things are nicely balanced (as they should be), then > trace_call_bpf() using migrate_disable()/migrate_enable() should never > hit this path. > > If, OTOH, migrate_disable() was called prior to schedule() and we did do > migrate_disable_switch(), then it should be impossible for the > tracepoint/bpf stuff to reach p->migration_disabled == 0. I think it's worth to confirm which kernel Satya is on too. If it's GKI, then worth checking first this is actually reproducible on/applicable to mainline. Cheers -- Qais Yousef