Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3557352ybi; Mon, 29 Jul 2019 08:33:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlygCRfDL1LCv6/7nFyP3mt72sonJC1tpt6j1KTR3+pRqwFzSdbE2/siq4x1v73zYtNaOx X-Received: by 2002:a63:520f:: with SMTP id g15mr100588608pgb.28.1564414395819; Mon, 29 Jul 2019 08:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564414395; cv=none; d=google.com; s=arc-20160816; b=TxLccI2pCYZymYwuHahX7S29KYnHwZ5aR8hObv7+LxUr/tiQTuO+Lqhu7bok9xqa+a z/VeWOWYmcrA43S9ygjxLRKcZ0ML2/1o9SoDlfBnLdk5W8xCgLx4+IBMAOe9GZptBlEm p/GPV2O2R3LpPqw43kalYFFLDcHpTfRuzWtVjbElJ8teOlJ4B0v/9jRRSAza/wH23wR0 xJxfssRXfvTZLhupivR0zavqARX5sogN0oYNBkE3TReGkcsJbmHrpEOSznxgXhqTVpsP LehIM7CtRsfPj/RQ3DsjNPCSn7cL8Sdkx3FdHC5K0pCppNe9J/CyLnHRdH+CMWLWotaT UFFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zClkBN3lTS1+Q+JFzp+qXPFY9wwST6ib98450V0l434=; b=KS/cRIO/jsxZe+GoRQCISZDTK4r2YdTVHFZgqbOM2NuBEcnNqo6JESgqx2H+ySY7wt /jM9OYwX3FKOuxxsp5PlfI0bcVPmcYTTa2rGuIifcjeNWaesVkJeA0cbrNRl6W4/c1Iv sQ+0qHacIS/8TjxlrW8Jo4a1wjSeQD2N5UHe73LKrMQH8vrhx1nuBxPY/J87r7/hRGh1 eQvBaPHx3FA6KyFVFM185UXzW4AZT32Hmt55Cw4Y/Yngh5PAZVu41uy4G0oRPO4A8l9K LJkGCp2cg0vcwSvxdWgw3k5l/IPdV/sCua3QK8VykWgq689c7lJyegQjDQNUQRlUHGhx CV4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=uKh2QezE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i71si24920452pge.3.2019.07.29.08.33.00; Mon, 29 Jul 2019 08:33:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=uKh2QezE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388076AbfG2PaB (ORCPT + 99 others); Mon, 29 Jul 2019 11:30:01 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39390 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388019AbfG2PaA (ORCPT ); Mon, 29 Jul 2019 11:30:00 -0400 Received: by mail-pl1-f194.google.com with SMTP id b7so27696446pls.6 for ; Mon, 29 Jul 2019 08:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zClkBN3lTS1+Q+JFzp+qXPFY9wwST6ib98450V0l434=; b=uKh2QezEkGVv+DpYW2qjVlLCa/B7ZJRmRmtB9hDESR/c/qhRIikFGdrPpODIN5vtHo BV7A/U71JXov8ytlkjvJRxAMlFM6FRcE4XQmnVEZAEIhdIuEvLjZ+7J9NTwVY5zzPmqh Mucd+ULNoW/BYk7iod4QAGLCHzJXyv7mwPgYaoWcImUvTX2Fra5PEkLTIQtM0wepLoQC 4nyZZM+7MHjouKUz0Lb1MMXzIdiCmjZSrJbhqU56XtFCuN7JNUkIypXB1E6pFUfBB6XT mRvUk6l/zkQaeGrHn7uBNFGtLWDUrB5FbJLMwPgwmmGL4eJ80gGdhDrL2EHbpkSRzA0g jrVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zClkBN3lTS1+Q+JFzp+qXPFY9wwST6ib98450V0l434=; b=lq16A4djte4dtRHNgsAmi1flAWAd6jWEtQv4zcjrV76smg4vUO7N1yl6zDxP2CdqmO U1GoYTAa98BXgNS4cFxcuZvsQh17VnvYKC7O6zwYVA+kZQxQU4G/buEXFZPtAijoOLhZ rp04fbrnN+a1umRfeeHsXQk4+ySuvkH7Fn2SUydK1q1stM5UIFbRPqUmT9dJAHeUkVAa SHN3j+EBFasdSHhPNucWTXtzVbxWgsSye5ZGWH9eURvloF3+n/4AGU0+ZNwrpoXeoaH7 urJZD9fqOjxmVQAHTSvmbzTeblGNyhSxyomiedkfAGBgoLH5qEBKLIc3ScKkBSLfecIJ phRA== X-Gm-Message-State: APjAAAWwrosyaNY9LmsEJ+5VXLtjFTcIjTTIlWA+3SY5xaiUMxw0llID rZxomEUWISjQWkwROMynFKY= X-Received: by 2002:a17:902:9a85:: with SMTP id w5mr110768476plp.221.1564414200219; Mon, 29 Jul 2019 08:30:00 -0700 (PDT) Received: from localhost ([2620:10d:c090:180::1:1811]) by smtp.gmail.com with ESMTPSA id h13sm28484598pfn.13.2019.07.29.08.29.59 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 08:29:59 -0700 (PDT) Date: Mon, 29 Jul 2019 11:29:57 -0400 From: Johannes Weiner To: Jason Xing Cc: surenb@google.com, mingo@redhat.com, peterz@infradead.org, dennis@kernel.org, axboe@kernel.dk, lizefan@huawei.com, tj@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] psi: get poll_work to run when calling poll syscall next time Message-ID: <20190729152957.GA21958@cmpxchg.org> References: <1563864339-2621-1-git-send-email-kerneljasonxing@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1563864339-2621-1-git-send-email-kerneljasonxing@linux.alibaba.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On Tue, Jul 23, 2019 at 02:45:39PM +0800, Jason Xing wrote: > Only when calling the poll syscall the first time can user > receive POLLPRI correctly. After that, user always fails to > acquire the event signal. > > Reproduce case: > 1. Get the monitor code in Documentation/accounting/psi.txt > 2. Run it, and wait for the event triggered. > 3. Kill and restart the process. > > If the user doesn't kill the monitor process, it seems the > poll_work works fine. After killing and restarting the monitor, > the poll_work in kernel will never run again due to the wrong > value of poll_scheduled. Therefore, we should reset the value > as group_init() does after the last trigger is destroyed. > > Signed-off-by: Jason Xing Good catch, and the fix makes sense to me. However, it was a bit hard to understand how the problem occurs: > --- > kernel/sched/psi.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index 7acc632..66f4385 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -1133,6 +1133,12 @@ static void psi_trigger_destroy(struct kref *ref) > if (kworker_to_destroy) { > kthread_cancel_delayed_work_sync(&group->poll_work); > kthread_destroy_worker(kworker_to_destroy); > + /* > + * The poll_work should have the chance to be put into the > + * kthread queue when calling poll syscall next time. So > + * reset poll_scheduled to zero as group_init() does > + */ > + atomic_set(&group->poll_scheduled, 0); The question is why we can end up with poll_scheduled = 1 but the work not running (which would reset it to 0). And the answer is because the scheduling side sees group->poll_kworker under RCU protection and then schedules it, but here we cancel the work and destroy the worker. The cancel needs to pair with resetting the poll_scheduled flag: if (kworker_to_destroy) { /* * After the RCU grace period has expired, the worker * can no longer be found through group->poll_kworker. * But it might have been already scheduled before * that - deschedule it cleanly before destroying it. */ kthread_cancel_delayed_work_sync(&group->poll_work); atomic_set(&group->poll_scheduled, 0); kthread_destroy_worker(kworker_to_destroy); } With that change, please add: Acked-by: Johannes Weiner Thanks!