Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp59663lqo; Wed, 15 May 2024 07:43:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwQJAHETGFcvhJuNwMTNfY91eOpsaZxSE28P2XHu3XvRhPnu8jCxPAkRkk2NOefbWVzP2zqC1T8Eus9C4J3S0JZcHTZY2ri2HIVabSeg== X-Google-Smtp-Source: AGHT+IGANGG+SQH62dhry/Giv/G5outs4B6eIFuCNhgxa8JXY/Trvg8LoVEnVyu9YRCiA5BUZEt1 X-Received: by 2002:a17:906:c79a:b0:a5a:3a6c:8b57 with SMTP id a640c23a62f3a-a5a3a6c90ecmr916135266b.6.1715784237006; Wed, 15 May 2024 07:43:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715784236; cv=pass; d=google.com; s=arc-20160816; b=K+fM7WqrHLnruL/Lsy37HkHQUvkQYJIJrkEXuGQgwRBupeevOuFCN+WYJgJCHEvH/j SIlvvqtD0AnvIx3e1ouP+WTC4QF7D84dCHTL/K5KPOd7JaTjVZ624+Bt9MqiMFEz6rNf Vw6sxz1XgD0VjduwtmpGdLWO1Ngv8QST/2Ll+2GZUOrf8pWER0gWD5dOW4wpiXRXIM0k cHET/sNiRQQiRwrodY4AmpW1Kum6ofYcmxP5ML//Qycudn7h3IeDYo+KLIwbFz9msHRO 03M9W+/COc80dKZ3hJdwce7Y9yLCj5KJ8UOoaX52E+CrbUa+AtBEWOxwf9zR5uYZcObk +aSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jlLrYPzh1VUHqS/+nRxv15n7IgGCJs/fGBNJU6/OnQo=; fh=2zwCh0TY81QL+m8lKeshJdiobUNV+OjhPy1yNmYchVY=; b=K/yRJf/oQgGTSfnfgWXL7G+BbHYEQaiNLIhwb1v132YO1Ezrkno81a/vEMfLVXGdCO SczpFJChSirYLTpDxRD9s+U/5SEx61eushIqSph8ZVryWmsrsAKqkCygOBQ3axEIHXuj KkgiWH/jc6DhhWgLeqJccXk+CdditFJd20DmVwAbPnYl6+rUnRSAxLpqJuSZo8lGiEuO m+8n5skqREOYLgpgSGpTzIFDFt9papP4KjAHkkIfVtJeNnSgFtYCCspu9zP1hOE2urPt GfsO4h12W6L8Nfq+FXOCp+50KsDr+kfMz1uAf/pR2Lmo/HfOaXMURkVJWFHCDrU9b232 JWIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=diMDHaAT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180022-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17ba3c8asi787979966b.607.2024.05.15.07.43.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=diMDHaAT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180022-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180022-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BA3B91F233A5 for ; Wed, 15 May 2024 14:43:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51F53156237; Wed, 15 May 2024 14:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="diMDHaAT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77BDB155A43 for ; Wed, 15 May 2024 14:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715784204; cv=none; b=Ohm6RnWwtDrBopyFhKkKEBT6rq4qBt6nOgLyML5bFq2iehmdLwjv7eL+GihZWGVniZBOe1MFfFwH7zd02FMplm+6mGFUQhkoWZBWCspiENXtUESbBLSt92ze3hRpC7pATJ8JW0c1Mm9liLjaehK70bAKv7r+0+gYlAPMOEfKyBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715784204; c=relaxed/simple; bh=rEuS7Fi0Lvzvpv1WWBr1sdY3xojQBPz8s/YrwhEEJOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aYp2go7BGG9yhlF3aXO8HoKSYPohKRHzxBdFRGWKB5hJklxH1mLUAfCa32FFnz9mT9r5PIG/t4p8pMvwkj1JJkQ1qA3JIAMs3LvKivzZWInYpF10VkeTZD6y9yVhenkX4x4Y5PA5jxYJX3OB041l57gILFXUG5KiZcbmkpzaDpE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=diMDHaAT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CFB4C4AF0B; Wed, 15 May 2024 14:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715784204; bh=rEuS7Fi0Lvzvpv1WWBr1sdY3xojQBPz8s/YrwhEEJOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=diMDHaATwzi4NBBG/2fL03CZHf/hX/TuU4nURsJgCvFEBa0EN+sthtVmkmTNgAt0T qFDy6S+snkE3FjzUVTFxyCTMLGAjQ9jL3b/W4a4MN2tIFR8Faly8lt1XZ2rrmTWuq+ B5Zf+lY8fmRZkWRuPpvtpBx+sMpNcBBPcjkTc/cJ4xdl3RrJch1/Mia4MCcQ69vuHX AF8igkqQGfny5vgq0upSUvSO/8+lzujyQqXYuWsSKV8REpmLdG0J/HJ6E6Y6GRPhZT FFfEo8ceXKq63qHEn6Fdx0jY9pJMydSgd962SSiY/9+Z9rDntZBpPOWWptnO0PldAe wwgJEWa9AUrdg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Sebastian Andrzej Siewior Subject: [PATCH 2/4] task_work: Introduce task_work_cancel() again Date: Wed, 15 May 2024 16:43:09 +0200 Message-ID: <20240515144311.16038-3-frederic@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240515144311.16038-1-frederic@kernel.org> References: <20240515144311.16038-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Re-introduce task_work_cancel(), this time to cancel an actual callback and not *any* callback pointing to a given function. This is going to be needed for perf events event freeing. Signed-off-by: Frederic Weisbecker --- include/linux/task_work.h | 1 + kernel/task_work.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/task_work.h b/include/linux/task_work.h index 23ab01ae185e..26b8a47f41fc 100644 --- a/include/linux/task_work.h +++ b/include/linux/task_work.h @@ -31,6 +31,7 @@ int task_work_add(struct task_struct *task, struct callback_head *twork, struct callback_head *task_work_cancel_match(struct task_struct *task, bool (*match)(struct callback_head *, void *data), void *data); struct callback_head *task_work_cancel_func(struct task_struct *, task_work_func_t); +bool task_work_cancel(struct task_struct *task, struct callback_head *cb); void task_work_run(void); static inline void exit_task_work(struct task_struct *task) diff --git a/kernel/task_work.c b/kernel/task_work.c index 54ac24059daa..2134ac8057a9 100644 --- a/kernel/task_work.c +++ b/kernel/task_work.c @@ -136,6 +136,30 @@ task_work_cancel_func(struct task_struct *task, task_work_func_t func) return task_work_cancel_match(task, task_work_func_match, func); } +static bool task_work_match(struct callback_head *cb, void *data) +{ + return cb == data; +} + +/** + * task_work_cancel - cancel a pending work added by task_work_add() + * @task: the task which should execute the work + * @cb: the callback to remove if queued + * + * Remove a callback from a task's queue if queued. + * + * RETURNS: + * True if the callback was queued and got cancelled, false otherwise. + */ +bool task_work_cancel(struct task_struct *task, struct callback_head *cb) +{ + struct callback_head *ret; + + ret = task_work_cancel_match(task, task_work_match, cb); + + return ret == cb; +} + /** * task_work_run - execute the works added by task_work_add() * -- 2.44.0