Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4939212pxb; Mon, 15 Feb 2021 05:31:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBk8V2hVp5q4UL3wcuZVgvrDKSGLBzIyXVG9+DBUZsIahjWF9LWiU05R6f15lXGPSZACrj X-Received: by 2002:a17:906:86d4:: with SMTP id j20mr2134846ejy.401.1613395903426; Mon, 15 Feb 2021 05:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613395903; cv=none; d=google.com; s=arc-20160816; b=tvp99YYm7mWUm3ZaRY64ofhJRaFLt9aUFVZQOb0lIKvjulX48I+pFrw55qYtZRpG/F Ms1YS76EuNldggM0ffn241QzE55X3/1KvbFMVmoQ5MqqKgsGyt5UPqLoqIVfMcSqPf5Y r8dhdh+vACRZQQbWuPAv8J73X5mr+skfHYmc1YAX0Tdzv60a0gAyBQcbN1pBdZb/1iDl HZ0V9/gHRgmEPgJQCTiIylHnnjg6nz6vyJ4cqGVhF2Li4FMVf8RV6/QJc78CZOXwf39B Ha3Ck6vG1WHdT++qPVgy9e2AtsBonZDFZj8BYC4ekIizeWuSXS6VJY1MjwqO2caP8VNK kqUQ== 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=iF1BRjXQMTisniUtNADTMpFVGQna/LODXZPKPHQVe4M=; b=ReqXGvt0oldQzSW3j+WyWvWa1o/woZUt3Lwwks42hMlFDuijIjoHtbYZpiw2r2EepX M7EQP5BuMw2uhf7cbNILMVtfvb4rskb3vcd0VAPmG6Rk2T411FTZ3pJVoKVkPDVg8UjG NarfoM8CX8CyEDc7y/zwfVKWehVwPzBL2PrahQRYKsTuTKWlHow/bBITXBqaaW6zgjwU igL2hOvgzRsU29FbfJzgO7Mohkzba0Z1YyiA/lgisfEfnRTY8z1h2+/U9duxSVoXJiGn IcCj2ThYx5LK2GDX8Ct/QtD6xqwqLsS39fo39toog8IZW0jpmCNkYR9PGbMsuR4n+vho Cnmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=o88tO8yO; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si14853695edd.509.2021.02.15.05.31.19; Mon, 15 Feb 2021 05:31:43 -0800 (PST) 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=@suse.com header.s=susede1 header.b=o88tO8yO; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbhBONai (ORCPT + 99 others); Mon, 15 Feb 2021 08:30:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:35868 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbhBON3H (ORCPT ); Mon, 15 Feb 2021 08:29:07 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613395699; h=from:from:reply-to: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=iF1BRjXQMTisniUtNADTMpFVGQna/LODXZPKPHQVe4M=; b=o88tO8yO6q1u06QX8QKb1J8knO2KxhW/C+tXVzOehbr5VwK4IPD+vkAMC+5mEXH3nOGhln dxvxYdtuYrTnfdzkmG4mqttXFjfvoOQJ/zAWyraXxuAfPtuXs1U5bP5vTi83Tvyva5YPt8 3oEB/QeU47jsMB3vCwZmA/hQxWsISJE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BD7C6ADF0; Mon, 15 Feb 2021 13:28:19 +0000 (UTC) Date: Mon, 15 Feb 2021 14:28:19 +0100 From: Petr Mladek To: Yiwei Zhang Cc: Andrew Morton , Felix Kuehling , Jens Axboe , "J. Bruce Fields" , Peter Zijlstra , Frederic Weisbecker , Marcelo Tosatti , Ilias Stamatis , Rob Clark , Mathieu Desnoyers , Liang Chen , linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH] kthread: add kthread_mod_pending_delayed_work api Message-ID: References: <20210214000611.2169820-1-zzyiwei@android.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210214000611.2169820-1-zzyiwei@android.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 2021-02-14 00:06:11, Yiwei Zhang wrote: > The existing kthread_mod_delayed_work api will queue a new work if > failing to cancel the current work due to no longer being pending. > However, there's a case that the same work can be enqueued from both > an async request and a delayed work, and a racing could happen if the > async request comes right after the timeout delayed work gets > scheduled, By other words, you want to modify the delayed work only when it is still waiting in the queue. You do not want to queue new work when it has not been already queued. Do I get it correctly? Could you please provide a patch where the new API is used? > because the clean up work may not be safe to run twice. This looks like a bad design of the code. There is likely another race that might break it. You should ask the following questions: Why anyone tries to modify the clean up work when it has been already queued? There should be only one location/caller that triggers the clean up. Could anyone queue any work to the workqueue after the clean up work was queued? The cleanup work should be the last queued one. The workqueue user must inform all other users that the queue is being destroyed and nobody is allowed to queue any work any longer. Best Regards, Petr