Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2694956rwr; Fri, 21 Apr 2023 12:33:33 -0700 (PDT) X-Google-Smtp-Source: AKy350ZsJfi8F3svq7c9wS4CweUQM09ZAzZ6cDy/wLCFcmJAc0eJLtiQQNieJ7fEVOc47Ey3kNP8 X-Received: by 2002:a17:902:c94f:b0:19d:2a3:f019 with SMTP id i15-20020a170902c94f00b0019d02a3f019mr7343395pla.1.1682105612846; Fri, 21 Apr 2023 12:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682105612; cv=none; d=google.com; s=arc-20160816; b=dl1XeA16p1aNIDnlQpKby95ZeadT+8OxOgXldegKetMoajruqOHisrxI9afmRB71jO iE2TaaSN1CdhIZWIZsZwriUsiRDndTF31hhFfcjuQrpYRj6gfu8uKKO/YQ76oybciaUp rL5QmNS7iqknv4vvec7yLr04r1crROnKruJPtPIrqaM9J/2LOHCC9TuevAS4nxhez0iD 2a6aZkcyJdZ1xMTNyJduks2vmX9cSBa/UfUmpPintYH7pIAaQznXnWK7/UDoH5Wgwl7h uPLeZnQkQhLUsx6a1pJvreefJsKrr648koQRwsLx9fwXw4xjeoBm1t967+arz/o0UYnd KB5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=swnu0givVhZgdAlS4m3xSf1Hambxbj5ky2a6KwMVkiE=; b=FTwmqZ9VcmSeOUZJFtL4lshQWiSGBhsRyleAmknBIb8sda/+VotcttWlZwA+BJnpFH S5mNSJl3zb/WFrucWEHcCKBPqj9UT97JPYTyPn6y5RGJPlCoM7+28+xJCphfRQ9L9bQw dQh+mHrzPb7V/dFmCcIzpMNlk0uO+/+hf9+pQo50aV6PgTuPZHKc9h3wBIWpQnUFlcxY rdEJ8sEtLH0/uaIHboJVOwyflPwkQaC3DGXypgK1H/TqGWZX4y5aJJZsaF7LD5F3ef7l 4gaub35CulNO4R3IoFfmsRcPkLbCz6vbZDcTu4kThf1VQ00T3zt1/P3zQistyQoxlLLJ uxzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3gMiwoMV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LqKRd2il; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a170902c94900b001a1b5191202si5463340pla.151.2023.04.21.12.33.18; Fri, 21 Apr 2023 12:33:32 -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=@linutronix.de header.s=2020 header.b=3gMiwoMV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LqKRd2il; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjDUTSQ (ORCPT + 99 others); Fri, 21 Apr 2023 15:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjDUTSP (ORCPT ); Fri, 21 Apr 2023 15:18:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8F71BC3 for ; Fri, 21 Apr 2023 12:18:12 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1682104689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=swnu0givVhZgdAlS4m3xSf1Hambxbj5ky2a6KwMVkiE=; b=3gMiwoMV+DSI75YpktkmPkRQj+C9gBKllwxbaUUnAMW0HQoiS21qIMmgl4mlhmhzg/+31a hKrWtNFQUlOCxTT7xK/8QZXQdjQt2XCqwf9iO+cIza/AfT/s2LzFa1rhH/Mi92Um6YvkDe D+vBqPY9fFg2e5T1li8xGyzQFlv08idzTaAHlEVadXijU0n+MW6oHTZmEMsTIcPOEw0+q9 I/BRAliLDoxv+f+E8nysCj+Yk0SoOVOmLt0SC47qVQTFmWYVtxdU/UyGXfrmFsqEWHvSus z0XXZj/DDAZ6n7M1cKlDnDfAqN5OLdvoXKW6PcnnXXbeOv6a0J3h04uEXQG/Nw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1682104689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=swnu0givVhZgdAlS4m3xSf1Hambxbj5ky2a6KwMVkiE=; b=LqKRd2ilg8fxesj0lQv123tZIHReiPHWm0E4zXr5+MvobRIXia7AO3PD9HCEtLZoUineUX uBVCIz/hvAs4rxBw== To: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org Cc: Crystal Wood , John Keeping , Boqun Feng , Ingo Molnar , Peter Zijlstra , Waiman Long , Will Deacon Subject: Re: [PATCH] locking/rtmutex: Flush the plug before entering the slowpath. In-Reply-To: <20230322162719.wYG1N0hh@linutronix.de> References: <20230322162719.wYG1N0hh@linutronix.de> Date: Fri, 21 Apr 2023 21:18:08 +0200 Message-ID: <87sfct11u7.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, Mar 22 2023 at 17:27, Sebastian Andrzej Siewior wrote: >> This still leaves the problem vs. io_wq_worker_sleeping() and it's >> running() counterpart after schedule(). > > io_wq_worker_sleeping() has a kfree() so it probably should be moved, > too. > io_wq_worker_running() is a OR and INC and is fine. Why is io_wq_worker_sleeping() not cured in the same way? Just because it did not yet result in a splat? Why not just expose sched_submit_work()? > --- a/kernel/locking/rwbase_rt.c > +++ b/kernel/locking/rwbase_rt.c > @@ -143,6 +143,14 @@ static __always_inline int rwbase_read_lock(struct rwbase_rt *rwb, > if (rwbase_read_trylock(rwb)) > return 0; > > + if (state != TASK_RTLOCK_WAIT) { Bah. That code has explicit rwbase_foo() helpers which are filled in by rwsem and rwlock. Making this conditional on state is creative at best. > + /* > + * If we are going to sleep and we have plugged IO queued, > + * make sure to submit it to avoid deadlocks. > + */ > + blk_flush_plug(current->plug, true); > + } > + > return __rwbase_read_lock(rwb, state); > } > > diff --git a/kernel/locking/ww_rt_mutex.c b/kernel/locking/ww_rt_mutex.c > index d1473c624105c..472e3622abf09 100644 > --- a/kernel/locking/ww_rt_mutex.c > +++ b/kernel/locking/ww_rt_mutex.c > @@ -67,6 +67,11 @@ __ww_rt_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx, > ww_mutex_set_context_fastpath(lock, ww_ctx); > return 0; > } > + /* > + * If we are going to sleep and we have plugged IO queued, make sure to > + * submit it to avoid deadlocks. > + */ > + blk_flush_plug(current->plug, true); > > ret = rt_mutex_slowlock(&rtm->rtmutex, ww_ctx, state); This hunk can be avoided by moving the submit work invocation to rt_mutex_slowlock(). Thanks, tglx