From nobody Sun Dec 24 08:23:12 2023 X-Original-To: dev-commits-src-main@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 4SyYvN5XB0z54Hd7; Sun, 24 Dec 2023 08:23:12 +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 4SyYvN3j2jz4Y1X; Sun, 24 Dec 2023 08:23:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406192; 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=voljrSDs4tbNTS4nTBL0xbXA7myuebMbj7IJfgSCBLY=; b=fVwh0zE8qJgwOTAlR4m6vmlOfhPn519TWIdBqw7eM9DyrP5KNhBSatorEz+J3NYzKRGNDp oTSsmg6Xj49G4TksJvdkeSOJyf5kOFOHyohQwWy6GCKnNCa8goUIm+azwgFLxBW7588SCY WRwVw52o/t0SqjDZOfotexl+6cfbB2VuWB9wS/BYz0h+aZMBn++Kxz/r07UCphxAHp4EHU OKY8MQbcHtDoeG/CNhpWwpMwuMPHm3UzLE8xBaWjxmr2IrptNkuqtrKiQVJ2qO/kmLctNv K3l92YLpP/5al1mNmfbQLIOeu0J/41ZHfvoW/mYakFjUupMDNXL6NyrjFaDyvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703406192; a=rsa-sha256; cv=none; b=GWsf2zBVRWJgRLLlQ4Pu+wksVGjkaHVIMv2Mhl8y9n+0n4WJSZQqq7kWlkmTCYL9plN7bz zLK9UHPeqe16MVN8IwmsrJtPZemVNM8JMwcu6CxRsI3upNrTXW4PfmbOLeZ1NLzs6zfjZ7 YOGrESu78M+pwuk9MFWAIaeQp8OeLwDmmwpDeJbVlzMMQkc6h0fn75CzVfjvJajD0z5vBN HZiI78CZPv+ASZsydV4ph7ju9Ke+eQWXBmcOI5sQ7Q+kdKj3ckslVXD56f3Yq09S74gXWB pCrbMnGuuAOue94Qw5SKPSFLq4x96iPWnwN56f652KfR7oov99esV9B34fAG/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703406192; 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=voljrSDs4tbNTS4nTBL0xbXA7myuebMbj7IJfgSCBLY=; b=VssMGeAZ41wJytSqRbFTei2UnZ8Nd0rI1SzbHR7JZFGbVSSf8nEGfzKzapwKureWdTaJwB 42dGHyavArsgJCSaHSdmxuvg75h1mGMUDW5tfVLMD2S/0IlX5+BHuYtznhT82AgBrogyab UN+NpRCXoc5RKfqeT+qoV0Z5soetCGL6N3Qfq5M02ExqRwmfRbwVct9jd/6MjEC8eSeCUZ MIShihbDIWcJ752JUuxau/F6TPRatywptHAOaJZe+gFtT5l4mMOUqifMUtw3UMJ3WGEwZA wYlSDpRtV+TyRY88zAyeLBTtK8LJD5fJddrLscvkkOouLZnbvwvGz7hFaWnKJg== 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 4SyYvN2pHBz5tL; Sun, 24 Dec 2023 08:23:12 +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 3BO8NCE4087303; Sun, 24 Dec 2023 08:23:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BO8NCld087300; Sun, 24 Dec 2023 08:23:12 GMT (envelope-from git) Date: Sun, 24 Dec 2023 08:23:12 GMT Message-Id: <202312240823.3BO8NCld087300@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 1b2f43a7427e - main - LinuxKPI: Add cancel_work() function. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 1b2f43a7427ebf51561867f6c497833268014512 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=1b2f43a7427ebf51561867f6c497833268014512 commit 1b2f43a7427ebf51561867f6c497833268014512 Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:59 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-12-24 08:19:59 +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 --- .../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