Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7910031pxb; Fri, 19 Feb 2021 02:31:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6Ban2rePmI7znHfJqq5NLPQcDnwbVcU3OviIsaPtrrFNRoZ94BPy/eVRIqaMTMyA33BOn X-Received: by 2002:a50:d307:: with SMTP id g7mr8548280edh.204.1613730712388; Fri, 19 Feb 2021 02:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613730712; cv=none; d=google.com; s=arc-20160816; b=WQ/AaH7g8a5i0kWVq8Xn/tqXpvIgzFZoi+KrBu/eKz7z4A7fb6ySEoJirL2HswGuhg M5aw+UhKXvcWWaxzsiJIEFy3tmQqr17fPMrWDlKZNZUC4Dfv9OHuF5GTEhIZnqeu2f9F HURX2VuuWB2Ypbifz1w/kSn7OqiMtcAIrKwu2pPSYR50J4dvSPEBbKTgKtrnSpG7l3YY yx+GQ03uJO9byDeDiwePQEq71pj759RN7jBHvsMiRZ1DcB2mVPqEEcvHU/AzPn6QduQo YlOyn88xWk//DR7Q7LO/5uH1AVJGt7vpzAvG/ERGzV23/uBeTZMKI3PKyGYvsJFePBp1 nmxQ== 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=jrvKD8kfwE175v3SQ4Nc2VhvWT7hv0j+jUvXS3qcGeU=; b=IrD7F8osTNhm7MilsdWbS3mJuG06GGor911K0IdAo1vqRSo3xUh9LuwzSjhtOe7xav RJALz9lKYW+UEozo6oAhyNZ4VZecKZXUShztM49UfU1D22X4jGIypl6mtZGpAiOkuBMU MBSVtxUWztew0knK6sq8uMnWVcjOpmEsYqirUDJ6wV7rhlvUzE5amATga75yR7DsmxOD cnFtE+2Evj/OxujR2bow9hk25dq++Z+zTW11Mn1mNKawgB+0HN3C71wgNrd/50X8lmSD usgBwU71/6e9zNOOuLySZvFgP9UJ2lQb2kX9HVVURPB8d5LfCw5nvDAtYLDxGSb18E78 WFSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=kmLKHU9T; 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 j19si5979538edw.550.2021.02.19.02.31.13; Fri, 19 Feb 2021 02:31:52 -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=kmLKHU9T; 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 S229636AbhBSK2C (ORCPT + 99 others); Fri, 19 Feb 2021 05:28:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:35430 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbhBSK2A (ORCPT ); Fri, 19 Feb 2021 05:28:00 -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=1613730434; 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=jrvKD8kfwE175v3SQ4Nc2VhvWT7hv0j+jUvXS3qcGeU=; b=kmLKHU9TUN5yDXVK/ZhpwePFA+hBeVedIM42xPe1L+1tSyz2E6IlzSycEosa7ygz2NGfcl qu6jLmxup5zIQbXEUANlpSTWZ5Z5s2Ffr6/RaFRhOX/m/jCrWrGXf+RRmzHuhEJDDPEA+T wNhvC9K0B94QL5tVehViZvsfbxkGfg8= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 946F1ACCF; Fri, 19 Feb 2021 10:27:14 +0000 (UTC) Date: Fri, 19 Feb 2021 11:27:13 +0100 From: Petr Mladek To: Yiwei Zhang Cc: Christoph Hellwig , 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 Mailing List , kernel-team Subject: Re: [PATCH] kthread: add kthread_mod_pending_delayed_work api Message-ID: References: <20210214000611.2169820-1-zzyiwei@android.com> <20210216091128.GA3973504@infradead.org> 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 2021-02-18 22:29:24, Yiwei Zhang wrote: > > 2. User triggered clean up races with the clean up triggered by > > timeout. You try to handle this scenario by this patch. > Yes, exactly. > > > 3. User does clean up after the clean up has already been done > > by the timeout. > This case is well handled. So only (2) has a potential race. Just to be sure. Does the user work correctly when the clean up work is done by the timemout before the user wanted to do the clean up? > Let me clarify a bit more here. The "clean up" is not the clean up > when a process tears down, but it's actually a "post-work" to cancel > out an early "pre-work". The "pre-work" enqueues the delayed "post > work" for the timeout purpose. That pair of operations can repeatedly > happen. > > The racing is currently worked around by refcounting the delayed_work > container, and the later "post-work" will take care of the work > deallocation. > > I mainly want to reach out to see if we agree that this is a valid API > to be supported by kthread. Or we extend the existing > kthread_mod_delayed_work api to take another option to not re-queue if > the cancel failed. OK, I could imagine a situation when you want to speed up the delayed work and avoid this race. The kthread_worker API has more or less the same semantic as the workqueue API. It makes it easier to switch between them. The workqueue API has flush_delayed_work(). It does basically the same as your code. We should call the function kthread_worker_flush_delayed_work(). I am personally fine with adding this API. I am going to comment the original code. Well, there might be a push-back from other people because there will be no in-tree user. Best Regards, Petr