Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1444871ybb; Thu, 2 Apr 2020 00:32:02 -0700 (PDT) X-Google-Smtp-Source: APiQypIPbOTNYPohYbs90QZg5lOz4PfnL6fBhJ34A4Z5/dxmus++spXifHYevuVd1xxFz0LMCyPB X-Received: by 2002:aca:5a56:: with SMTP id o83mr1237373oib.134.1585812721925; Thu, 02 Apr 2020 00:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585812721; cv=none; d=google.com; s=arc-20160816; b=zGIqW80XWvr9sqB/vyd7iUe6FqS7xC/HwuVqRpQ+HIMJAP5smPAmRRktwBwsaqQ1yu +zCITLxOLWvSgGgRMCcsW+OeaQgoxZu7aAURbmGsJnBE4DReDDFVt3a8FAAdLV8fPE85 GkoaNa/1Ct8jVSvz6B7Dpxu1Xbt3/Fq6NT81wU84kT1jil37SbSd/a9/o/Pla9JvujPV DhvI1uBC1lnn6zuJhB7x8fGKZdw8aMcviAggfR9BaLYYCJYMiVY82Bpch8Xtsclea1XT 6UxpGcz+PNnW8YiNJ/M1sR97oL49bAB+iYTGFFadDJ5aO7MZGLQh0PY/a2Did8LjngDH sU1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=vghBWNttBQB030zUU1ffMukH1MrtfgiJBLLL+lGCYA4=; b=Zn2GmkpV1crfuD8R0Yp8LCuRmLtUdvN5yVPXbsjNlYZZdGzju0HigWBK5gCKFlcTbK t7ZLOZmF7izJz6mpzSWjMlCBBBngRu9Uu6nKqnCjmS/Bf1T9MRRKhC+Vnx+ABhZuEY+k 2RBtnrBWgUvl/973crowiu8pVniyFnWT0ahzdrX4rFcAV6HO7hJeyQ/8N0EpLt2dPZGz vl1kkp9O09y6J8eMEzNNZiKnJ1LDEQMmo64KcRrPZfgQiDRysgmaulfY1lh/U7fCg8/A kQQDjF1iGz4Z2cUfvr8qdR93W73RzwhIlEKbC0Yv40lB/Odvqm3m0mNtePDkHJvA1AfM S6ug== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x63si1928240oia.101.2020.04.02.00.31.43; Thu, 02 Apr 2020 00:32:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728833AbgDBHaJ (ORCPT + 99 others); Thu, 2 Apr 2020 03:30:09 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:36253 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbgDBHaJ (ORCPT ); Thu, 2 Apr 2020 03:30:09 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1jJuIX-0006Yi-N0; Thu, 02 Apr 2020 09:29:57 +0200 Date: Thu, 2 Apr 2020 09:29:57 +0200 From: Sebastian Andrzej Siewior To: Lai Jiangshan Cc: kernel test robot , Thomas Gleixner , Ingo Molnar , "Peter Zijlstra (Intel)" , LKML , LKP , Tejun Heo Subject: Re: [PATCH] workqueue: Don't double assign worker->sleeping Message-ID: <20200402072957.fczmj5nbaosfq3hb@linutronix.de> References: <20200327074308.GY11705@shao2-debian> <20200327175350.rw5gex6cwum3ohnu@linutronix.de> <20200401130346.e7cdsqgxppa6ohje@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-04-02 08:07:35 [+0800], Lai Jiangshan wrote: > > > would be *increased* twice > > > > > > I just saw the V2 patch, this issue is not listed, but need to be fixed too. > > > > | void wq_worker_running(struct task_struct *task) > > | { > > | struct worker *worker = kthread_data(task); > > | > > | if (!worker->sleeping) > > | return; > > | if (!(worker->flags & WORKER_NOT_RUNNING)) > > | atomic_inc(&worker->pool->nr_running); > > *0 > > | worker->sleeping = 0; > > *1 > > | } > > > > So an interrupt > > - before *0, the preempting caller drop early in wq_worker_sleeping(), only one > > atomic_inc() > > If it is preempted on *0, the preempting caller drop early in > wq_worker_sleeping() > so there is no atomic decreasing, only one atomic_inc() in the > preempting caller. > The preempted point here, wq_worker_running(), has already just done > atomic_inc(), > the total number of atomic_inc() is two, while the number of atomic decreasing > is one. But in order to look at the same worker->sleeping it has to be same `task'. This can not happen because the `worker' assignment is per-thread. Sebastian