Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp298700pxj; Thu, 10 Jun 2021 00:37:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0Uo8dOAVrrNbLfRIKZdvYerYKHatdj50H4QTh65h2b6vIOwnrbEAXmyL3xq8rG/0yzEe4 X-Received: by 2002:aa7:dd1a:: with SMTP id i26mr3373833edv.358.1623310663309; Thu, 10 Jun 2021 00:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623310663; cv=none; d=google.com; s=arc-20160816; b=qpzW8rtnV0tTD51GDw1FkgkViTmAYJXYNoocY16aKg8JDzbEdpeZM96ieqO5LzOj+u ngQ/Na1IOxed+gBuRqbdgHMF2hFCoG1NeoM+JQyF/G7o+O4x77lv7EAx3t72xZJs/NSC 7qKQO3fXNxHj1m11/PfBFlZBiKnhbc/vLs3YMmlfog2iU0GKN/en8gjZyc9XH/xv3aD0 FDtu5xtqJ+FG+r0zL/MxFY2z3qToua0/Gqd6xSq63MjxgH/RBL+0OOJcrO7tZlHCv12L Om+z1LUJEFCDzGijpm+pfc1hnWU8xOSNK8TvdTcVZ3cRxjN2PM3AxcskQUUU79j1h4KT tvxA== 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:dkim-signature; bh=cQfQQECCafdNPU0kz3R9QKeUbPWBXKmib+wjJ0WB1so=; b=obJ9OfSqIk7gmBhAburVrpgW4dyMGgWyJnD82IG5HZd6eKawCbE8pb1YkMesdQJVXQ +HPQEmK5TyQ4PfdpAajc2WexdfqAMAuZm5GnCD9FVWE/Pd8VD+CQarKg2DxOARSrrG0+ 0c/m4uLMDkpbZLH8Bq+9EXU+ryRpteXO0N4IyUDAUzhzycxuKq4Bcrgm4ICjSSEVfAbx sZbUOWOsSt3P6BqiywPKBdCPRlTKX0B6d3i+PQeYoRnm5OGJ2bxX2hdHYnQ8JZMTEmnc e8wYeVV35jbXg9IgvSMMy5nRYs9+NEdwxV1Vn0AkaMdaotL8hD6N4kE5Efensft0GsV1 822w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="af8N7k8/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si2048633eja.301.2021.06.10.00.37.19; Thu, 10 Jun 2021 00:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="af8N7k8/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhFJHfd (ORCPT + 99 others); Thu, 10 Jun 2021 03:35:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbhFJHfc (ORCPT ); Thu, 10 Jun 2021 03:35:32 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 651C9C061574 for ; Thu, 10 Jun 2021 00:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cQfQQECCafdNPU0kz3R9QKeUbPWBXKmib+wjJ0WB1so=; b=af8N7k8/Aw6elqRqmi7lnP4xrD uBtBh2e/MO01I3ZwtiG38AM+8iFHgde8eIRrGKY6MMZ9XiCGnPwYt+sZb74ogxktN9BBS61hWjZGq 2W1Mcpo4sJH213K3k4PBRe+/VOxSrGLUWqXc5NGr1rfAPaKsM/FfBaUmPyj85gOsX/wcdyXyhESIm vfhiwSBDzPLpF+9wrfULu8z3fLtO92tT/yj6dpZNJXgu1H+hN1dZIzUuTc97YmoEveiAXVXXPeqOL 2rTMObb1drSSQIlLELv+kHPLwpIrDIscT5FGFDAXRu+0N6y7b1cllNViaLhcppvx+QkGeSsgjCbu/ J2jABj7g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lrFB4-001Ltk-1j; Thu, 10 Jun 2021 07:32:38 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 247D9300258; Thu, 10 Jun 2021 09:32:33 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 136562CCA72F2; Thu, 10 Jun 2021 09:32:33 +0200 (CEST) Date: Thu, 10 Jun 2021 09:32:33 +0200 From: Peter Zijlstra To: Johannes Weiner Cc: Huangzhaoyang , Suren Baghdasaryan , Zhaoyang Huang , Ziwei Dai , Ke Wang , linux-kernel@vger.kernel.org, Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Subject: Re: [PATCH v6] psi: fix race between psi_trigger_create/destroy Message-ID: References: <1621562754-8158-1-git-send-email-huangzhaoyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 10, 2021 at 09:31:33AM +0200, Peter Zijlstra wrote: > On Fri, May 21, 2021 at 10:18:53AM -0400, Johannes Weiner wrote: > > On Fri, May 21, 2021 at 10:05:54AM +0800, Huangzhaoyang wrote: > > > From: Zhaoyang Huang > > > > > > Race detected between psi_trigger_destroy/create as shown below, which > > > cause panic by accessing invalid psi_system->poll_wait->wait_queue_entry > > > and psi_system->poll_timer->entry->next. Under this modification, the > > > race window is removed by initialising poll_wait and poll_timer in > > > group_init which are executed only once at beginning. > > > > > > psi_trigger_destroy psi_trigger_create > > > mutex_lock(trigger_lock); > > > rcu_assign_pointer(poll_task, NULL); > > > mutex_unlock(trigger_lock); > > > mutex_lock(trigger_lock); > > > if (!rcu_access_pointer(group->poll_task)) { > > > > > > timer_setup(poll_timer, poll_timer_fn, 0); > > > > > > rcu_assign_pointer(poll_task, task); > > > } > > > mutex_unlock(trigger_lock); > > > > > > synchronize_rcu(); > > > del_timer_sync(poll_timer); <-- poll_timer has been reinitialized by > > > psi_trigger_create > > > > > > So, trigger_lock/RCU correctly protects destruction of group->poll_task but > > > misses this race affecting poll_timer and poll_wait. > > > > > > Fixes: 461daba06bdc ("psi: eliminate kthread_worker from psi trigger > > > scheduling mechanism") > > > > > > Signed-off-by: ziwei.dai > > > Signed-off-by: ke.wang > > > Signed-off-by: Zhaoyang Huang Argh noticed the SoB chain is invalid. Please fix. > > > > Acked-by: Johannes Weiner > > Thanks!