Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp313777lqo; Thu, 16 May 2024 07:10:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUto4XhhfDEKScaPWX54GThYRnbok8mt+4mV6r/xOOlOCGCmbqnLDGvm2mLL9pYW4na5ZaabsTCnKCiDodwgUh52J3xsQuS6kLOVxoUtQ== X-Google-Smtp-Source: AGHT+IF0ullQI7jIZVI4PPiEtoTP8fsGdiJvmqrFYJVG5hQAHhouxPVAHFMIzVw1thYfrNqiaYIv X-Received: by 2002:ac2:43d0:0:b0:51e:1bed:13a8 with SMTP id 2adb3069b0e04-5220fc842f4mr11537031e87.29.1715868611128; Thu, 16 May 2024 07:10:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715868611; cv=pass; d=google.com; s=arc-20160816; b=WrWIwOZUyMRot+A63h/+XQ9WIaHXShR1Jf4+XlHLYJgOqTiLeIuoVnEl0wBvr9XNTb epKNFYbNrREAHHTRTuMg29ADv2VNpWJdMB9liZ/7zJcM9efL9XTl72u+1sGXh1PX8OaC hj+jGHO/g94OeMaLIlnqAy5TjCe0HV4GblfAh9E+xQNxTa0Cb0TFBoo4k9fL1h7oKFtS G+f9frSn8A6iyxxcbnYRi+pueU4w+oPEJTrmEIoqtTUESHBDqlayFj+WlhC8Pup4dWVi iIyGlvGa9ngWFKAvDQOfL7ELdo6bwOLLmgChciNfWz9LSGfr8sCvY03ExU/pjHiHfG34 KI/g== 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=CL0P+C3QlxY0NRK4UYID2SVzzzVfaLn3tafO/eYxp1U=; fh=2zwCh0TY81QL+m8lKeshJdiobUNV+OjhPy1yNmYchVY=; b=Jl/c8tKcMXYdYaHlVnKNcymfPWQ5W1vmmnMye9Y/mmnpVikuAMmixEGkTCzIu45Wkd MXTqUsVbTNFKtBHPR4OktM2WunotdNbIsINUJtcGT45FaxIMbNl2P+9T6n5aW/vpLZao Ng+ovwegVlY4EsjA4fkl6KE7GZ6/DatJQDxgugcYXg9WwF4WFfz3GDmzxmZYPJusk0Ij Cqysaa2U29FiXotgTY6viL6RoWsJa5Fbq3swjf62cvHgeprjm7Oj1R4At72SHE6BtsdM YdvEh/d1mNUJvUX0Rkh9cyPduKlmfAuNrhWWdtOsrRU0Tx5vu1Q3oGcuOnG8ImktAD3s hHMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IrvobaTp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181152-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. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2d588si912813466b.1038.2024.05.16.07.10.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 07:10:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IrvobaTp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181152-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181152-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 B38A11F21C60 for ; Thu, 16 May 2024 14:10:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7213414B976; Thu, 16 May 2024 14:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IrvobaTp" 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 9C66A14B969 for ; Thu, 16 May 2024 14:09:47 +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=1715868587; cv=none; b=KNixPW/nHQl5yBnxDFXeOKq7bfunssZnDwxGa8cWH8SVDWsndOhkrJUZxnJS1YL21M9N4DdTjrjesdk29r8nJjBkD2KVKSx4Bm56OQi6Mwjw25gTLsEkPhA5mVJzGf2582hFPKT8uQmRBfEveQUHQgNPrTHMOLcK4BXnv7dRMfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715868587; c=relaxed/simple; bh=8ujq2iQEISU0Ou+VI37VHgm8fH2OCc7fS2VtpmzXXUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m1aXCjqsmsbvSuVDweNYEtWDMiI2sfsHXLyIzhXCcX9hk2F6RrBra0wbgjZDIE34Pm+mssk/9BGnT/PjqnPP9hyQywgcM8Q6Y3az7HgnLuO65FU47Ud12jJB0TwyQrp9JwiKthbgu52mlT3jFIp3ZqOK9mGcnZ1RP2w616bh8BY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IrvobaTp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0185CC32786; Thu, 16 May 2024 14:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715868587; bh=8ujq2iQEISU0Ou+VI37VHgm8fH2OCc7fS2VtpmzXXUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IrvobaTpzSzkaFAgbJfPzWh4QH25Ys49NPrVlxjiT90HomxxrxvF/qEPFaYsDbfrJ euuhho0U9A5h90eoJMphnQhwXDKcfO6bzb11i67H528Lb9By8wBN+yqnbRpKnD1u6O bZFbgnRG8Y2b92WU8WzO99xsIrti7Y9E1Y15U478LvKzg2b5/1TvahFrsItwiL4f8P iZoCYp4EbBzY+IL7S+d+LQa8Ageyx6Q02psdtscG0n2RsQndbKikpDXt+m4vFJZFzL O4g7E54WkTpv4ca4Xj+UwTr2hOYnD0HREYWCCZeGTyWmdiSQ3UivKWV4g6jaZYJ79p deJZpaqQocGvw== 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: Thu, 16 May 2024 16:09:34 +0200 Message-Id: <20240516140936.13694-3-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516140936.13694-1-frederic@kernel.org> References: <20240516140936.13694-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.34.1