Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1359202pxj; Wed, 19 May 2021 04:24:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz94B8w7cdOVU+9q4TFV3i5YARHQupulNPmZCF96zoswqzGTydjM/d3xSfpbfUgqJ2Ksr4v X-Received: by 2002:a92:cccb:: with SMTP id u11mr9778404ilq.36.1621423475838; Wed, 19 May 2021 04:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621423475; cv=none; d=google.com; s=arc-20160816; b=SB+xyMKFpPrfslzvO8fEpL3ioouk2q/xVy7ByvMQSi47cjvxOCwv2syTOG/ph5A0Lm EcGq7hU4TMWY8OwW+tPZrub3UHNmoTE5obZmLhN2g2jKjEDRMF3Qx9SdIN3L8bgfHCEM QT5hY9r26bzFDhnO3OXURZEeasKgG4T1hPywXG5meSvym2SEG0IYoimT3MKpY/xc1ngt bjH+x8xChDovVVWW3tqif2TPdw+9u5hyipdP5Cy28a1oLth0/fooOXygBnvh9LjyXXK+ wjSFkyNNEzmdUQsFdXqqSPJWapfrnktz83ua48xMNQ7x66SH4tScquYi33zFyuxAZbhl xvRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Deqwsl94N1axNtysM4lpZ1EFCtrsyNhFHn1vfFPcipM=; b=tZNeT/LyxndFMBcP5P6Mcj+X23T0/jyjBJ8klapsSfGB+l/l0AmcoGsFoPHOQGQpBv boGztuZYOjEE+ykZI9XwPIFUGpTO6MjeVsN0NuSrGmugQlrqLoRtb5x0ZQ82oTeMibqN 05wMyL6U4WgJoX0H9r07VCd4QB3FP+INkiJNZVwug8xX6Cr6rN/4bKzAxJYfckC5iw6L TyrowrF6aobGmNsEj/9Od/YFllxM+USBCJ8YCd5vy53xQPPZ6x+rHT04t8HKmPNpbPXv ENP292tfmKKCB3600wfEgNTOHHmHrd+QPg8Smshf51Z4gapSHH6FOUCn2pHo/MAdgmL+ qskw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iFHsNgLk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si22035325ilp.57.2021.05.19.04.24.23; Wed, 19 May 2021 04:24:35 -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=@gmail.com header.s=20161025 header.b=iFHsNgLk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241017AbhERCSH (ORCPT + 99 others); Mon, 17 May 2021 22:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237378AbhERCSG (ORCPT ); Mon, 17 May 2021 22:18:06 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2117C061573 for ; Mon, 17 May 2021 19:16:49 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id t7so6427989qtn.3 for ; Mon, 17 May 2021 19:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Deqwsl94N1axNtysM4lpZ1EFCtrsyNhFHn1vfFPcipM=; b=iFHsNgLkoCW/sJxTMJroMcefzjYSsfK6q4TQrG5bkkA4LjPu+B52K1PjWJTJiRx/gA db3F0JNOHjqWItAoc1EBSUKXk1UwWXbBXQqcaaJTKPs0vIXcq6s6xmTVkRhXm6JtU1bb 9BqLKvUSFHD/sh1YkytXht1mECU//mI2gdXImag/jZc2Vifqz+Wg7WmQE2Vy6JayNtqz kCy3E0pH7wyqYnzoQg7b7/FddZaF8VUPQKEJq/CBdl2+3xeRUVVZWxlOXxbO4oTvk5T2 v2Mbg48Nr80r0F/w3HhomaAwISZAMSBjR+LeAeI+O4BAxRCaJ1T88WsumiP8I3VFNwfO rHhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Deqwsl94N1axNtysM4lpZ1EFCtrsyNhFHn1vfFPcipM=; b=NZIg4LaqhgwC62yLmvsQDubx3cy5cCEGG5dSfAeEf9wLzl4w+EFAztBe3kboG4kuni aUOIHTlENLhjmQ25qgeC//5r1mwMBkNjFd5vD3diw7VBx3vdP7dVL2qpjCD0HauAZhzF 0qpvCJCCT7q/M5Nu0z77nblZkBYm01ZBXx28+CkDusc+906AV6xncbUdeQqPxovKjAQ+ pd8+70PimuRGcYJPRYPomUchTcq8K2iS7WQrY8Pp9yQJuszTi7mcr7M5sGNgjQuk2Zow R+NMDedD7OFhyfDqkMiFPNCJKfwPnIzDw4RoCocCGa7LAWXKsFSXcsfgUtkgFXpttkXC 5YqA== X-Gm-Message-State: AOAM531imJG4RntCMcN9ZyL67UQxAQ0OpCbLdD9w7lHULeMSeNr/QcEs DhtnEIca5q6uslgpoZUH5sBu0RF8DSp+K1QWXzc= X-Received: by 2002:a05:622a:486:: with SMTP id p6mr2540788qtx.98.1621304208812; Mon, 17 May 2021 19:16:48 -0700 (PDT) MIME-Version: 1.0 References: <1621303811-5716-1-git-send-email-huangzhaoyang@gmail.com> In-Reply-To: <1621303811-5716-1-git-send-email-huangzhaoyang@gmail.com> From: Zhaoyang Huang Date: Tue, 18 May 2021 10:15:21 +0800 Message-ID: Subject: Re: [PATCH v2] psi: fix race between psi_trigger_create and psimon To: Johannes Weiner , Suren Baghdasaryan , Zhaoyang Huang , Ziwei Dai , Ke Wang , LKML Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org resend for adding other maintainers in cc On Tue, May 18, 2021 at 10:11 AM Huangzhaoyang wrote: > > From: Zhaoyang Huang > > Race detected between psimon_new and psimon_old as shown below, which > cause panic by accessing invalid psi_system->poll_wait->wait_queue_entry > and psi_system->poll_timer->entry->next. It is not necessary to reinit > resource of psi_system when psi_trigger_create. > > psi_trigger_create psimon_new psimon_old > init_waitqueue_head finish_wait > spin_lock(lock_old) > spin_lock_init(lock_new) > wake_up_process(psimon_new) > > finish_wait > spin_lock(lock_new) > list_del list_del > > Signed-off-by: ziwei.dai > Signed-off-by: ke.wang > Signed-off-by: Zhaoyang Huang > +++ > v2: change del_timer_sync to del_timer in psi_trigger_destroy > +++ > --- > kernel/sched/psi.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index cc25a3c..fe29022 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -182,6 +182,8 @@ struct psi_group psi_system = { > > static void psi_avgs_work(struct work_struct *work); > > +static void poll_timer_fn(struct timer_list *t); > + > static void group_init(struct psi_group *group) > { > int cpu; > @@ -201,6 +203,8 @@ static void group_init(struct psi_group *group) > memset(group->polling_total, 0, sizeof(group->polling_total)); > group->polling_next_update = ULLONG_MAX; > group->polling_until = 0; > + init_waitqueue_head(&group->poll_wait); > + timer_setup(&group->poll_timer, poll_timer_fn, 0); > rcu_assign_pointer(group->poll_task, NULL); > } > > @@ -1157,7 +1161,6 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, > return ERR_CAST(task); > } > atomic_set(&group->poll_wakeup, 0); > - init_waitqueue_head(&group->poll_wait); > wake_up_process(task); > timer_setup(&group->poll_timer, poll_timer_fn, 0); > rcu_assign_pointer(group->poll_task, task); > @@ -1233,7 +1236,7 @@ static void psi_trigger_destroy(struct kref *ref) > * But it might have been already scheduled before > * that - deschedule it cleanly before destroying it. > */ > - del_timer_sync(&group->poll_timer); > + del_timer(&group->poll_timer); > kthread_stop(task_to_destroy); > } > kfree(t); > -- > 1.9.1 >