From nobody Sat Feb 17 21:33:06 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TchqQ6xbMz59lK8; Sat, 17 Feb 2024 21:33:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TchqQ3zwcz4hYk; Sat, 17 Feb 2024 21:33:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SvRn5fck2TfnNwzsXxOSyne0mKcQb8qtGg0N9Ru39vk=; b=fdXOd9U52UXq4X4QlPgYUSmVw14zw/M8Y0LVzazUfOheJW7szCHsO3nLAwqT2dAMpnCeuC CueFTSEia1Zgkj+1uG6RmsByC/ak1mJN4M+9PEjKza+n2hpO2E7QQxclEHsaC7lthYIfZB aHCaAyjXvseE+I8iBZJNK+jxJOmqXAfWXctNMEGjSkkKWMIfVev1BtWtNlntZ8EaFyQWrX 9xBsYRgJQcg9C6/Vm+QSjYNR1FbdKTAhNOcjtIHul3r5qkoaHwFwKsLXLwOjcXJBqzfaS7 imxJdPBMxlqO54VYNcmuL0437L1h5q2A3vovrIQlT4vWpiyRBnGf3gneIJ/rqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SvRn5fck2TfnNwzsXxOSyne0mKcQb8qtGg0N9Ru39vk=; b=MK6mYQrMPMjNzS43FE8bBMgBZEmcHm2nu0jEVNFZYayFt0nSsfjREgx9GDeMDNMeirxFtn 2WAgeHA0Dpae1Ln7I6/8yZNh5Au1SaqTQcCf1HjfzNaBCNYvGTZrbeNETiIVbUO1plDQ2g 5WASAiT8CRaJ14z+D4YSpkObj/I7eJO+onA3J9iPSepDz+F9EGLvF9OLHHzmWU4Udlezwn mkHQndTh8NBbcka9HpGaFWtCM97D7+ikWyFhZpXZN15+HXgSVyKkFjSdcA+tb5nH5QzwOS cxyRbyjRHXHRRgzJ24gZgvIZKJ6BmNScEhfvxNsRlDJMRm7n52IV++8xEeMt4w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205586; a=rsa-sha256; cv=none; b=rnXs9lwbWdop7Bq/9GtfvSPu7k+TCOhFk2nI223ICnFoEC0OKaCou2CHl8jg99L0a1n4wn bmRiiW+qF9NVbVCLNLPPONtcXkMNCl39sEYpdFTXfqgwkc4iVocy16G+RHLULxarGilrpy c3O/hPyOW3jFix2vxJFdtfXx9AweGHP+V4CWW8Pgrue4nYeiYzO2xyOGqzd+wUx9tmr64U +oQgde9QCImNlAEeVg+z0eHdv/RGRxsidf8cMImu4DrgfaYb0kOJKW2RqZJ6iyghwxrDQe ew1MxXmv2Wo2R3Kb7WqND6VDfBshUAek7WFXzijVDSPH4VsnjB59cTLv7fmNPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TchqQ34ZszP89; Sat, 17 Feb 2024 21:33:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLX6aW021050; Sat, 17 Feb 2024 21:33:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLX6xw021047; Sat, 17 Feb 2024 21:33:06 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:33:06 GMT Message-Id: <202402172133.41HLX6xw021047@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: cdceed0413d0 - stable/14 - LinuxKPI: Add cancel_work() function. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: cdceed0413d0b3e8446fa65e480ec89badfa54c5 Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=cdceed0413d0b3e8446fa65e480ec89badfa54c5 commit cdceed0413d0b3e8446fa65e480ec89badfa54c5 Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:59 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:38 +0000 LinuxKPI: Add cancel_work() function. Cancel a work not waiting for it to finish. Sponsored by: Serenity Cyber Security, LLC Reviewed by: manu, kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42811 (cherry picked from commit 1b2f43a7427ebf51561867f6c497833268014512) --- .../linuxkpi/common/include/linux/workqueue.h | 4 +++ sys/compat/linuxkpi/common/src/linux_work.c | 32 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/workqueue.h b/sys/compat/linuxkpi/common/include/linux/workqueue.h index 226c2d1f4f0c..1c9df9fcb74d 100644 --- a/sys/compat/linuxkpi/common/include/linux/workqueue.h +++ b/sys/compat/linuxkpi/common/include/linux/workqueue.h @@ -188,6 +188,9 @@ do { \ #define delayed_work_pending(dwork) \ linux_work_pending(&(dwork)->work) +#define cancel_work(work) \ + linux_cancel_work(work) + #define cancel_delayed_work(dwork) \ linux_cancel_delayed_work(dwork) @@ -243,6 +246,7 @@ extern void linux_destroy_workqueue(struct workqueue_struct *); extern bool linux_queue_work_on(int cpu, struct workqueue_struct *, struct work_struct *); extern bool linux_queue_delayed_work_on(int cpu, struct workqueue_struct *, struct delayed_work *, unsigned delay); +extern bool linux_cancel_work(struct work_struct *); extern bool linux_cancel_delayed_work(struct delayed_work *); extern bool linux_cancel_work_sync(struct work_struct *); extern bool linux_cancel_delayed_work_sync(struct delayed_work *); diff --git a/sys/compat/linuxkpi/common/src/linux_work.c b/sys/compat/linuxkpi/common/src/linux_work.c index c62302ad2346..939bdbbc1434 100644 --- a/sys/compat/linuxkpi/common/src/linux_work.c +++ b/sys/compat/linuxkpi/common/src/linux_work.c @@ -360,6 +360,38 @@ linux_delayed_work_timer_fn(void *arg) } } +/* + * This function cancels the given work structure in a + * non-blocking fashion. It returns non-zero if the work was + * successfully cancelled. Else the work may still be busy or already + * cancelled. + */ +bool +linux_cancel_work(struct work_struct *work) +{ + static const uint8_t states[WORK_ST_MAX] __aligned(8) = { + [WORK_ST_IDLE] = WORK_ST_IDLE, /* NOP */ + [WORK_ST_TIMER] = WORK_ST_TIMER, /* can't happen */ + [WORK_ST_TASK] = WORK_ST_IDLE, /* cancel */ + [WORK_ST_EXEC] = WORK_ST_EXEC, /* NOP */ + [WORK_ST_CANCEL] = WORK_ST_IDLE, /* can't happen */ + }; + struct taskqueue *tq; + + MPASS(atomic_read(&work->state) != WORK_ST_TIMER); + MPASS(atomic_read(&work->state) != WORK_ST_CANCEL); + + switch (linux_update_state(&work->state, states)) { + case WORK_ST_TASK: + tq = work->work_queue->taskqueue; + if (taskqueue_cancel(tq, &work->work_task, NULL) == 0) + return (true); + /* FALLTHROUGH */ + default: + return (false); + } +} + /* * This function cancels the given work structure in a synchronous * fashion. It returns non-zero if the work was successfully