Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2002089imw; Tue, 5 Jul 2022 20:47:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFzj87MfXTl/9l11yQqd96hgzfR+6C/9iBUCnMg66rqVXiUdAbKQaYR4XX+EDQs8tpIQ58 X-Received: by 2002:a05:6402:4446:b0:43a:3f52:4172 with SMTP id o6-20020a056402444600b0043a3f524172mr21210222edb.417.1657079223205; Tue, 05 Jul 2022 20:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657079223; cv=none; d=google.com; s=arc-20160816; b=S8Cy4/MkHpA9fZrOgKNDx7RPYRb8SoTz7xopG30c8qjurJKvWKcLPCgwSqDnQgXBPu P7Gzi/Q2JWeuWSfhYmW7NvOhYNU0XciVPHJxsgwQ+6tk8M14WMCQZBfi/X5f2+jMe5GW Khf1bbUURPrxXdwQvLHk0//GfmWokqCePchAnzdLzoDjMWSsMzohS76GgD+sqLpzokJH /VSJtSbZxrTFwDgLgK1ZsRzErhRWOWCoFLQw0nqgtJMTB8gjZS5FCoCi0MgSr7g+Nr/a nSNFEDyWR9OHHQCiCUkV19UxbfBHZdeeaZeHf8YDzmqQjqBhIvli1BoJ6m1FUmbyKUIy Nvmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=WIiOCgWeODrlGV9dA9OHD0tG8M0ApsD18lwL5IxMong=; b=tpxRF2Mfql80HQ4gF9nd7ffFSiE++8WFLqY0waNBpriMhWbtHBwNwgIPf9kHEnaQ8V 7xstmXQT1vPYYglo658dg4ohJ+7L1exi0EVMkpdp8mrnblKgzn74cmK+RLOe2I34Z1d4 OT16zcguEFdgGryB0AfmlgMXHixjm/e12o330XBUCJi7jlw9CLWoYIfBUvMp0NP9K39i GCdZfZ8wAu+tK+zHATD2dOyxn9JcrGjx4EtqELtFwaQoMCxzU1a2Aifx8x+Z9OJNKKNs aQs4TeindmNw5j62jnjGVnH6CfKuo8DG9S5fmkbNEST7sOvnUuhNZ0J4ljPL70biB87n SZOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=PdGoTXQ+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa13-20020a1709076d0d00b0072a84586c63si18092385ejc.564.2022.07.05.20.46.38; Tue, 05 Jul 2022 20:47:03 -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; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=PdGoTXQ+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbiGFDmf (ORCPT + 99 others); Tue, 5 Jul 2022 23:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbiGFDme (ORCPT ); Tue, 5 Jul 2022 23:42:34 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AC961CFD7 for ; Tue, 5 Jul 2022 20:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1657078951; x=1688614951; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=WIiOCgWeODrlGV9dA9OHD0tG8M0ApsD18lwL5IxMong=; b=PdGoTXQ+YyOlC0tlFhVTwnedOYEmvjCRel+1FlSEDDzJW0KP3G6AhW8F 6CVp+rMJ5HTR+87fycfygjwQ0s5ZylYLqwPM2MfTon9TRqzx4Pnb0zvRe Na9XNpAMk5Dads8VsBhDr6U6YjtWBPlsaJ0VwSgccSXeuIM2OZ4a/GVWO g=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 05 Jul 2022 20:42:31 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 20:42:30 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 5 Jul 2022 20:42:30 -0700 Received: from [10.47.234.156] (10.49.16.6) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 5 Jul 2022 20:42:29 -0700 Subject: Re: [PATCH] sched: fix rq lock recursion issue To: Dietmar Eggemann , Qais Yousef , Peter Zijlstra CC: , , , , , , , , References: <20220624074240.13108-1-quic_satyap@quicinc.com> <20220630215310.wb3kab72tlh5pq2g@airbuntu> <20220701114846.42o2tkm5fqt325df@wubuntu> <24c63730-2d6a-de14-57ca-919870b64323@arm.com> From: Satya Durga Srinivasu Prabhala Message-ID: <7e8ff7f5-6553-6467-c1f4-89aaf667ff5b@quicinc.com> Date: Tue, 5 Jul 2022 20:42:29 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <24c63730-2d6a-de14-57ca-919870b64323@arm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 7/4/22 1:32 AM, Dietmar Eggemann wrote: > On 01/07/2022 13:48, Qais Yousef wrote: >> 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. > Satya, do you still have these lines from your spin_dump() output showing > current, the kernel version and the hardware? Or a way to recreate this? > I couldn't provoke it so far. > > ... > [ 212.196452] BUG: spinlock recursion on CPU#4, bpftrace/1662 > ^^^^^^^^^^^^^ > [ 212.196473] lock: 0xffff00097ef7f500, .magic: dead4ead, .owner: bpftrace/1662, .owner_cpu: 4 > [ 212.196500] CPU: 4 PID: 1662 Comm: bpftrace Not tainted 5.19.0-rc2-00018-gb7ce5b6b4622-dirty #96 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > [ 212.196513] Hardware name: ARM Juno development board (r0) (DT) > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > [ 212.196520] Call trace: > ... Thanks for cross checking. Below are the output lines from spin_dump. I'm on 5.15 GKI Kernel. [ 7447.326924] BUG: spinlock recursion on CPU#6, kworker/6:9/738 [ 7447.333615] lock: 0xffffff89321d8600, .magic: dead4ead, .owner: kworker/6:9/738, .owner_cpu: 6 I'm trying to get the issue reproduced with some additional debug logs, didn't find any easy way so far. Still cross checking.