From patchwork Wed Jan 31 02:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625547dyb; Tue, 30 Jan 2024 18:18:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG75nYvipBe6h+8B0munfTpBB8CpN81SxtK0GG+7X7L1U2kGI/p2ZyG0e0+1o4yMuMKJyCq X-Received: by 2002:a05:6512:3e05:b0:50f:5e2:d50 with SMTP id i5-20020a0565123e0500b0050f05e20d50mr318170lfv.51.1706667482766; Tue, 30 Jan 2024 18:18:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667482; cv=pass; d=google.com; s=arc-20160816; b=ePXibWVXyjkfcHjMqof0MHQ3bdKAyv1KJenxpfuGU1okj6t7v8hzQWtYySgSbqmmfy 1yrIOU89Xs1FBRlWiqQP8nVV+n6FcUkMSmCb08w+hVvbklIuCcX51jF/ovlLuz3IIslM tGnAMLnYr2u5NojqD+I/aXWXqaGjKYDTxs/UJacRmgaswXiFF3F0RHStGTZapzJTOZBM kKK5Y/38tV1MxfPUKBZhHHGmvJyKhdjy5x39kJVYfbYXnHBmRRV9xN6m/9Zli3+50Txg T8niFaLNkALsmBhS4oJwomMroUlObgNTSFED5dgZipsLNyVJvgfuzRl4yKQ44mIK8yRf N3cA== 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=X/IZwfYWP9znQfddabnSoi+xBA9zWsqNxvzC3bQDVaM=; fh=aUQKu1atq2V6oCm/Uj3cXs9I+NsJT8/AIWmtjlLMkjI=; b=o/SOFdNGQJjtC5C78Iv3dtXG1MFwiehsfhRPXpxnbJR4QNHK2m1nix6RvC0aDJK162 k+/7Hg8u3yF9uwySAXz3DHJKOfgbWPXf341ZiwkjJzTDnMzYjlqM5yaRDgy9eU9qUFCV dZe/vlAXOMblqsjWe9NpY7Yg59xM9mG3NmK/NODJ7Stc5tmZsTU+6VaskOBKCxqO2X9c s3+woL633ModYBEKIbaWxFUMokVQaMjN8iSQ3flxD7pCBp83+ZbyoknXVJQL6r1czud/ 6ILWlYR68SLT316ZCVegMu2QGti3tAvab2K8OSHGevvnlnqUGBweXuPYjB40XbXPJ0DK BxhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=cqzL2BqK; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45633-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45633-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVHtGaMO7CBEpdWh9mi6j2jZEYo1rIOgspu55u0i5vv5IQTDD9Qk7Nii/r1lOBHt18qa2cLEOo4butI1QdTkR6vX41eHQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l10-20020a056402124a00b0055f0078ad56si2534546edw.397.2024.01.30.18.18.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:18:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45633-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=cqzL2BqK; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45633-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45633-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 5D5E61F21FD3 for ; Wed, 31 Jan 2024 02:18:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41B4A5240; Wed, 31 Jan 2024 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="cqzL2BqK" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 962C45667; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; cv=none; b=Us8U/eDC+yWj5D1BZFsXAiEmgQ0MvDn8XX/DApZAbDDBg3uEPf8s+XwI//gXhNc/qh3wMryGnTFDCS4jnDPC+fY0LuxRGarECEulJWylmrbuuiNAKQu23HPiHT8gx3sz6CkZp3+y2DkRnRJq+SucZHOgTZ1XekuZKff7jiQEw7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; c=relaxed/simple; bh=I4trA2JfrK9wBwFoc8bTAUMVwA5tJ+kKV0vPGN6dfHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kOyewLxdo/BDuCfFhGd+V7gFjBHFRUN4kBLft/jiTPvSbmZhsVeK+vF1+acGUFMX+XoZjPOz94W7Fz0TA4zDRBp44RlAbJRjehZ4n17+EMe5V/Yp39xa9FI7lv39K8ElAUUK2vUf00UHtNX7qa74f+5vaa2AQGqO6bH3R8rt9OY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=cqzL2BqK; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=X/IZwfYWP9znQfddabnSoi+xBA9zWsqNxvzC3bQDVaM=; b=cqzL2BqKLT0kOzyVTWLpHtAvEn CokxLS83003PLTeKCseYL0B7nzWKw6waJ3UDbNRaafYfrc//BhVcx9Zao0981tSm2EeiA0ClrXoxG UzExgMJCWcy0ZaNjSWr1qAfxZmiDXDgYfv1vc/X8YPSUqgZALKygghsULFRunHTqpIqrINlJCIGXe JvWULanxOUx5Bp0g3zBrhSv640BZBjXxcJcasU4nFf3834DQREf/vub1O67GI9deb+4itk44+5c16 +C+2O4gpet496MFsBKnzh8i/g2R3KR5WLRE7QdGkJNMFu0scFE8vsRUcnKl5TKmNhRWvEqxeMfr4d boR1AvqA==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08m-0038Kv-0L; Tue, 30 Jan 2024 20:15:52 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 01/29] ntsync: Introduce the ntsync driver and character device. Date: Tue, 30 Jan 2024 20:13:28 -0600 Message-ID: <20240131021356.10322-2-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570562793355132 X-GMAIL-MSGID: 1789570562793355132 ntsync uses a misc device as the simplest and least intrusive uAPI interface. Each file description on the device represents an isolated NT instance, intended to correspond to a single NT virtual machine. Signed-off-by: Elizabeth Figura --- drivers/misc/Kconfig | 9 ++++++++ drivers/misc/Makefile | 1 + drivers/misc/ntsync.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 drivers/misc/ntsync.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 4fb291f0bf7c..bdd8a71bd853 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -504,6 +504,15 @@ config OPEN_DICE measured boot flow. Userspace can use CDIs for remote attestation and sealing. +config NTSYNC + tristate "NT synchronization primitive emulation" + help + This module provides kernel support for emulation of Windows NT + synchronization primitives. It is not a hardware driver. + + To compile this driver as a module, choose M here: the + module will be called ntsync. + If unsure, say N. config VCPU_STALL_DETECTOR diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index ea6ea5bbbc9c..153a3f4837e8 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -59,6 +59,7 @@ obj-$(CONFIG_PVPANIC) += pvpanic/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o +obj-$(CONFIG_NTSYNC) += ntsync.o obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c new file mode 100644 index 000000000000..e4969ef90722 --- /dev/null +++ b/drivers/misc/ntsync.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ntsync.c - Kernel driver for NT synchronization primitives + * + * Copyright (C) 2024 Elizabeth Figura + */ + +#include +#include +#include + +#define NTSYNC_NAME "ntsync" + +static int ntsync_char_open(struct inode *inode, struct file *file) +{ + return nonseekable_open(inode, file); +} + +static int ntsync_char_release(struct inode *inode, struct file *file) +{ + return 0; +} + +static long ntsync_char_ioctl(struct file *file, unsigned int cmd, + unsigned long parm) +{ + switch (cmd) { + default: + return -ENOIOCTLCMD; + } +} + +static const struct file_operations ntsync_fops = { + .owner = THIS_MODULE, + .open = ntsync_char_open, + .release = ntsync_char_release, + .unlocked_ioctl = ntsync_char_ioctl, + .compat_ioctl = compat_ptr_ioctl, + .llseek = no_llseek, +}; + +static struct miscdevice ntsync_misc = { + .minor = MISC_DYNAMIC_MINOR, + .name = NTSYNC_NAME, + .fops = &ntsync_fops, +}; + +module_misc_device(ntsync_misc); + +MODULE_AUTHOR("Elizabeth Figura"); +MODULE_DESCRIPTION("Kernel driver for NT synchronization primitives"); +MODULE_LICENSE("GPL"); From patchwork Wed Jan 31 02:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1632973dyb; Tue, 30 Jan 2024 18:41:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmyIw2ISt6dp4KLsqhbkkOryoKM/tONow4tGJq0PuQzwbXRFQZ0VCOV8RgDQL27ZGakpPg X-Received: by 2002:a05:6402:3102:b0:55f:2c58:d831 with SMTP id dc2-20020a056402310200b0055f2c58d831mr109973edb.33.1706668890204; Tue, 30 Jan 2024 18:41:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668890; cv=pass; d=google.com; s=arc-20160816; b=EpE8pJaFHYE9KDZEhgml0PdF7RKBkbFP6gLwccaM5820jL/exojMJrYbTjF4YN40lI xthczaQ6kJ3KjmJojhQXEzyeHY/aOnUd9KqGK+ls7wW6TEKNrYI7lWac5MZ3nNfsgPPO uHxHu+eBb0N5gJNwzdXvpTbLDFCOKRe5ZqZuvWekjj0kyvp9AKksB6bhsAXO0H1+ZKtT dmwxX5PGGPcKkYDGkPwcgrgiU7TPTi3XzPvX9xqUZy2NngIRd9UHoRs+VBNsfKtSuvK2 c8xQN1SuJOO8PAUK1qG4GBEdJ+iQ4PbbGvrKmaaj6m619KiwD+XSVpnlla5kISPfFHi1 qnGA== 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=lHwW4zT2kOoH+YNEOKMeIBkf5DIZZR6wMENN39LT3Xo=; fh=qQ9M/BCW3Ws4D7KaTYLvDscYruAmjiX9f1TKZGxKLPg=; b=VDOdz7eX7ay46zGAdR7twfiliXKatyHoIf6WQuY/IOdufK5jxUJkGWMLwQKLBs1Xyu DL9JabpL5w8fieegpk8oCPgAekHuJzooywQHQT1q5JvTUC3Xztoet67HXAPX5PSOTq+o 28Npt+xwUFAHGRLIxY7FvmoKl0AjHg3tOym4xxRy0zugntOJYnvTi2GI8CLa/WEdgswS tCtwaGbUP6+d3KaNp9eaGAswcfligxC49pkxDB2MOUMxCF9xsJa7RBcV77iX4MsNPwKM SynsG0dAyRGJrZXgHbM54x6U1jD3vxJx1JQ6Wdybc96WlEJejvLdjAJRe07nZami2MnW RtrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="ZAO2TWh/"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45653-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45653-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVSP+tT7ZOCjF2Cq4/XqwbfZeHtMLHtc/nnZTr+y7GyHq5tK/wtn3EC84nuHodPBKYjmBo0CXhR+3H34BFz/n0yxABl1Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g11-20020a50ee0b000000b0055ef9e79403si2633140eds.180.2024.01.30.18.41.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45653-ouuuleilei=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=@codeweavers.com header.s=s1 header.b="ZAO2TWh/"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45653-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45653-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 7F4B31F2A39E for ; Wed, 31 Jan 2024 02:23:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A817F3D984; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="ZAO2TWh/" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 966075673; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; cv=none; b=P/nGY8dhhv7fZ+nU//Z0EII3xaQ81Uv9n5BZPiLCyeI4R2+m2mxwtL31Iy6e9a0LPyZSoyixm+yhRnF4l0CgzT1rKVhD3cUMkWj7n43MwteFDtY8llvbBwRAxTFYNvmkmqVYCLdgRq45iB4Gla8+KYXL93uVuPa4RXbRnC4ytj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; c=relaxed/simple; bh=5/Mn5ps7n4SQKWZX1KTG6D74zm3D8qkkGwwpR0oR9YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jS1kiW7N3Pox4AUQ1tfLPWHHOww2V4KrVXC+leImlDyZLwdsjCo/WnASd8caJLRoVC36hfgs8A9Wa6Ja/yGfJ8sy8V6AZU51ym0r+myY+3P3S4FTOXVz+6W2K339b3WC9GOPxw9DVRYSLKzvKCpjuBZMp1N7suY0elVQp+o/v3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=ZAO2TWh/; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=lHwW4zT2kOoH+YNEOKMeIBkf5DIZZR6wMENN39LT3Xo=; b=ZAO2TWh/Q8+pJvPbbxqwQoM9R9 9ZPW73MChfg6JkEcWsigGdoEj83UJyjWRohSYglif7FrKzlk+wweD/Acvzwg/tbOLlPMjMcu/afos dgDCZyhwoBnaTW/yCumd5FWB/AqBOAs8KqWwjC0bLqgjCBuyDMNygAAziX6Aq6DACWlUB/llU9Vgp qJjuARbo7Kkrjwf2+BW99YtdM/VeBAozb3n0QG7PRimGxFG+J/b2FauOXq1tVu80htaOhtA3154C+ JDAKQUpNkRs2yXtWzX4efUl83ktbEfuVMNtT2+T6I5uyjegLH9f65BiRRD9LgG/jlB2FkxVSZboJB yHd54Ikg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08m-0038Kv-10; Tue, 30 Jan 2024 20:15:52 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 02/29] ntsync: Introduce NTSYNC_IOC_CREATE_SEM. Date: Tue, 30 Jan 2024 20:13:29 -0600 Message-ID: <20240131021356.10322-3-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572038281957058 X-GMAIL-MSGID: 1789572038281957058 This corresponds to the NT syscall NtCreateSemaphore(). Semaphores are one of three types of object to be implemented in this driver, the others being mutexes and events. An NT semaphore contains a 32-bit counter, and is signaled and can be acquired when the counter is nonzero. The counter has a maximum value which is specified at creation time. The initial value of the semaphore is also specified at creation time. There are no restrictions on the maximum and initial value. Each object is exposed as an file, to which any number of fds may be opened. When all fds are closed, the object is deleted. Signed-off-by: Elizabeth Figura --- .../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/misc/ntsync.c | 120 ++++++++++++++++++ include/uapi/linux/ntsync.h | 21 +++ 3 files changed, 143 insertions(+) create mode 100644 include/uapi/linux/ntsync.h diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 457e16f06e04..2f5c6994f042 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -173,6 +173,8 @@ Code Seq# Include File Comments 'M' 00-0F drivers/video/fsl-diu-fb.h conflict! 'N' 00-1F drivers/usb/scanner.h 'N' 40-7F drivers/block/nvme.c +'N' 80-8F uapi/linux/ntsync.h NT synchronization primitives + 'O' 00-06 mtd/ubi-user.h UBI 'P' all linux/soundcard.h conflict! 'P' 60-6F sound/sscape_ioctl.h conflict! diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index e4969ef90722..3ad86d98b82d 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -5,26 +5,146 @@ * Copyright (C) 2024 Elizabeth Figura */ +#include +#include #include #include #include +#include +#include #define NTSYNC_NAME "ntsync" +enum ntsync_type { + NTSYNC_TYPE_SEM, +}; + +struct ntsync_obj { + enum ntsync_type type; + + union { + struct { + __u32 count; + __u32 max; + } sem; + } u; + + struct file *file; + struct ntsync_device *dev; +}; + +struct ntsync_device { + struct file *file; +}; + +static int ntsync_obj_release(struct inode *inode, struct file *file) +{ + struct ntsync_obj *obj = file->private_data; + + fput(obj->dev->file); + kfree(obj); + + return 0; +} + +static const struct file_operations ntsync_obj_fops = { + .owner = THIS_MODULE, + .release = ntsync_obj_release, + .llseek = no_llseek, +}; + +static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, + enum ntsync_type type) +{ + struct ntsync_obj *obj; + + obj = kzalloc(sizeof(*obj), GFP_KERNEL); + if (!obj) + return NULL; + obj->type = type; + obj->dev = dev; + get_file(dev->file); + + return obj; +} + +static int ntsync_obj_get_fd(struct ntsync_obj *obj) +{ + struct file *file; + int fd; + + fd = get_unused_fd_flags(O_CLOEXEC); + if (fd < 0) + return fd; + file = anon_inode_getfile("ntsync", &ntsync_obj_fops, obj, O_RDWR); + if (IS_ERR(file)) { + put_unused_fd(fd); + return PTR_ERR(file); + } + obj->file = file; + fd_install(fd, file); + + return fd; +} + +static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) +{ + struct ntsync_sem_args __user *user_args = argp; + struct ntsync_sem_args args; + struct ntsync_obj *sem; + int fd; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + if (args.count > args.max) + return -EINVAL; + + sem = ntsync_alloc_obj(dev, NTSYNC_TYPE_SEM); + if (!sem) + return -ENOMEM; + sem->u.sem.count = args.count; + sem->u.sem.max = args.max; + fd = ntsync_obj_get_fd(sem); + if (fd < 0) { + kfree(sem); + return fd; + } + + return put_user(fd, &user_args->sem); +} + static int ntsync_char_open(struct inode *inode, struct file *file) { + struct ntsync_device *dev; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + file->private_data = dev; + dev->file = file; return nonseekable_open(inode, file); } static int ntsync_char_release(struct inode *inode, struct file *file) { + struct ntsync_device *dev = file->private_data; + + kfree(dev); + return 0; } static long ntsync_char_ioctl(struct file *file, unsigned int cmd, unsigned long parm) { + struct ntsync_device *dev = file->private_data; + void __user *argp = (void __user *)parm; + switch (cmd) { + case NTSYNC_IOC_CREATE_SEM: + return ntsync_create_sem(dev, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h new file mode 100644 index 000000000000..f38818e7759d --- /dev/null +++ b/include/uapi/linux/ntsync.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Kernel support for NT synchronization primitive emulation + * + * Copyright (C) 2021-2022 Elizabeth Figura + */ + +#ifndef __LINUX_NTSYNC_H +#define __LINUX_NTSYNC_H + +#include + +struct ntsync_sem_args { + __u32 sem; + __u32 count; + __u32 max; +}; + +#define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args) + +#endif From patchwork Wed Jan 31 02:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626091dyb; Tue, 30 Jan 2024 18:19:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEchdN1/tx+cT+n0JHjTu5kdJ2zMcdjIK42Mk1slzksQwcsW+EDoX+IMIpyE1pz9tFO/2hK X-Received: by 2002:aa7:c2d3:0:b0:55f:3cb:9c33 with SMTP id m19-20020aa7c2d3000000b0055f03cb9c33mr91945edp.31.1706667586495; Tue, 30 Jan 2024 18:19:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667586; cv=pass; d=google.com; s=arc-20160816; b=EIZuG2Dlv/jHBU52WtnH2cNYWFM7zcX9OBGufvoW45BdtidoFZxdGKADzawC2xddRU MGySofKoDkET0XgvT8179ZphpJYpmvOjZnjUDpMHmrlz+NMeoBYcAXM3QaFo82JFcVFA jDfwcCH8/ocuwpzhUUQ0dil1YlUhTaiVqVeyYQcF48PTtOOCPgn2lyGFmtTuXy6UVdX/ GPKU34+Th2TJfo5uVjHAob8qACUnbv9I82XRO9ecL2gWuL3rU/7becmtEbcYNqe86vNQ Dd3S5uvHWl5zhcVwCxICWRXmsSW3kktMrc4/wADik4IuapiMexuJkL8+BPbL8FTPFFr7 6PRg== 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=SMlzEM56sFeNJJQFrjOO36bPFoUHb9ev3VvNS+3GYKc=; fh=N5EUaZGF1SDq6Cqq5Y5ddxkhiWnKQpgEPzx5yF7O2ao=; b=y+pD1Zzgh80KdzkXUjR08caAvND25s2s4SIAZIXv0VhxRvseYfRB7LDArEe7ZXDlto DBDzjJtE5MuIGiiWcdFZ5TYEpEW8hgAEiLDIs6MB9/935CJRXQ7MtilogTlOx//p2HFc VaqPRBIhmjDlh9iLufOpfZ44KKUC4THPnOgPtnnEbs1TXPOoIw+yybhMC52m9qKSYgbi cUMSD4owEJ+U1MG/GNTAmAehUTkoTY0FQbpSA/7rfxGdCNhbGSIRX2Qr49a7cxQGueOW RJ/VEUTu/WX+5QuoX3LyLaSmb41ZwzH9Mdj1Lt8LXT5DyvasX4gAwuKYeOp+6Q6I6ZN4 sFJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=XokxqTmI; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45636-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45636-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUJ2U36QJfjXNIPeGqQuIgI5eXbOyH6plZpbYS68OGivp05HGNQIvgL8s7Pp9twqLnmad7W9U451ZsGX+uRfWYbJHoLeA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p32-20020a056402502000b0055671290b71si5197937eda.249.2024.01.30.18.19.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:19:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45636-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=XokxqTmI; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45636-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45636-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 21F841F27DEC for ; Wed, 31 Jan 2024 02:19:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E11863A1B2; Wed, 31 Jan 2024 02:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="XokxqTmI" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 962FD566B; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=K6XAcVIz3UOzeZ9MfEzoPhjn/Nf3zJFHnHmpJMGvBJO8K4bccLwRY2EuTAHgtrx4WqZAYGQ+Go+rM5tg46P/+Ihe50PjENhUD5FJNoaHeuA8bvD7NrGeIDj2ZlSQ1IuDtyr5twmFN5SNxuuqQwtgFnedZo11dPLQcp9BMuUumlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=O5K1LmGQcFzW45Q6iMNwCezjStTLj4HXs8KymesmOXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MjHk2nAEkt+JW4BqJEmjWIwAxlV8Wh8oJkDAqHd86305mDZWb9hiswNbJB9sbWqxKZRdIBe8vAoz97YCNVQe3REXclL1M3OJ1fPhzHUJA0sadXoBFUdqeWiD3SXmn1Nrj0gTkLOPdxywK1SPtJwYeXFehCWqWSZfU1CFQFYvCRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=XokxqTmI; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=SMlzEM56sFeNJJQFrjOO36bPFoUHb9ev3VvNS+3GYKc=; b=XokxqTmIGX0Rw4fNgYQ2FcjfID ilNGxziyyFthA6wx5lM/7tMmvNh3YhBw1dxjrnBJB5pgN0TlWYUc1LBHyF1V55kZxRVGlwif8/t7X xIVOZf6MuVylg3ifStFeA19GP3AVMHDZcOMmO0srK+dYLyF2naM5L5Ca1ObwsiJp+muNHJ684dWWA ouOP3i4PlsRg1tDpusvYKZyFwaT9wXbaDVrNNzyEwJ86O+jE2BTOEIK5rvao17A79tYyeP6ozysbE XLEWfNdQySU3lUA7LMCN+y0E8a1O7DwV6zSTuB6CBiMG8h0rvMcoc9VXSyeVujN6ARCMX1W87l2FD o7FtKjzA==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08m-0038Kv-1s; Tue, 30 Jan 2024 20:15:52 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 03/29] ntsync: Introduce NTSYNC_IOC_SEM_POST. Date: Tue, 30 Jan 2024 20:13:30 -0600 Message-ID: <20240131021356.10322-4-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570671095371372 X-GMAIL-MSGID: 1789570671095371372 This corresponds to the NT syscall NtReleaseSemaphore(). This increases the semaphore's internal counter by the given value, and returns the previous value. If the counter would overflow the defined maximum, the function instead fails and returns -EOVERFLOW. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 68 +++++++++++++++++++++++++++++++++++-- include/uapi/linux/ntsync.h | 2 ++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 3ad86d98b82d..1af38969f9a2 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -20,23 +20,68 @@ enum ntsync_type { }; struct ntsync_obj { + spinlock_t lock; + enum ntsync_type type; + struct file *file; + struct ntsync_device *dev; + + /* The following fields are protected by the object lock. */ union { struct { __u32 count; __u32 max; } sem; } u; - - struct file *file; - struct ntsync_device *dev; }; struct ntsync_device { struct file *file; }; +/* + * Actually change the semaphore state, returning -EOVERFLOW if it is made + * invalid. + */ +static int post_sem_state(struct ntsync_obj *sem, __u32 count) +{ + lockdep_assert_held(&sem->lock); + + if (sem->u.sem.count + count < sem->u.sem.count || + sem->u.sem.count + count > sem->u.sem.max) + return -EOVERFLOW; + + sem->u.sem.count += count; + return 0; +} + +static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) +{ + __u32 __user *user_args = argp; + __u32 prev_count; + __u32 args; + int ret; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + if (sem->type != NTSYNC_TYPE_SEM) + return -EINVAL; + + spin_lock(&sem->lock); + + prev_count = sem->u.sem.count; + ret = post_sem_state(sem, args); + + spin_unlock(&sem->lock); + + if (!ret && put_user(prev_count, user_args)) + ret = -EFAULT; + + return ret; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -47,9 +92,25 @@ static int ntsync_obj_release(struct inode *inode, struct file *file) return 0; } +static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, + unsigned long parm) +{ + struct ntsync_obj *obj = file->private_data; + void __user *argp = (void __user *)parm; + + switch (cmd) { + case NTSYNC_IOC_SEM_POST: + return ntsync_sem_post(obj, argp); + default: + return -ENOIOCTLCMD; + } +} + static const struct file_operations ntsync_obj_fops = { .owner = THIS_MODULE, .release = ntsync_obj_release, + .unlocked_ioctl = ntsync_obj_ioctl, + .compat_ioctl = compat_ptr_ioctl, .llseek = no_llseek, }; @@ -64,6 +125,7 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, obj->type = type; obj->dev = dev; get_file(dev->file); + spin_lock_init(&obj->lock); return obj; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index f38818e7759d..878ec4f0f2e8 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -18,4 +18,6 @@ struct ntsync_sem_args { #define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args) +#define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) + #endif From patchwork Wed Jan 31 02:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1641272dyb; Tue, 30 Jan 2024 19:07:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZwQQ7pCS12pGIE2KY4vYB3wbCCNi4EOXKhohTpVy+SKIrZMytZ4hBKdplquXtG3jmLISQ X-Received: by 2002:a17:902:7408:b0:1d5:8bf4:c79b with SMTP id g8-20020a170902740800b001d58bf4c79bmr534289pll.39.1706670478903; Tue, 30 Jan 2024 19:07:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706670478; cv=pass; d=google.com; s=arc-20160816; b=j+BiXhk4Er4mdhmpDbeiclzOm2DdGpqF/9/+mc8Zox8pcifWsQjRdRT0rTYgDUfWiQ OOK2eNJ5eT/2kJ2ryBOpwBPx/wBkW3fDb2FuDscS73pQzTer4XJD/n+HBbEZQFlywsnH x8hxESUuNElo1YzgQ/ZpcvzH8BrKDME2PBKxEboN9ymbVElUigm0snp1BkLDFsJL3OMN sA8v5Jv3gwQ3bDWUf/J/Ta9WYXGS5tiGjU9Pi69Kln+MCh+9Wm3ruCnEWIv5zv0vddSs TnFaztwNNBE7iyQ20tAJCPqsLg6Wpfv3inI6HYpqmyZQLlyRaa8fvMb8VVmxjoVxul9B Mvyw== 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=dBqQoWEccHAFufDAEgUe6Vd0qbJ3tQL100kMCYoxJh0=; fh=8pc+3q7VJQGnAQ3QEgKStypEW/8z72QglvOaUbyD/2o=; b=VG2KkCQ2qWNXR4kLqtiKST4BmuuOLHo8pwlM3s0Wou89oPvfN6DRUjBUBeS5synlaM o0SQA7rBtXZWf6uFjsvAEsuYg1ry+c5pjqr6iGTY592cL4Ys8+7CILXGEVmv2WExcAD4 aLTeEVbRD7Tb6goYxkmp6qqeubDMu1y/LBGk+cXjf9R3sdmLPtKqa7P9JCjTFjAGGFts ck5YQZ//oZ488IZAnWb47Fn7p3PTRHCzExO7BlT3JG1RvFS32SpQuO8dsQio7D3ad6LW tQzfOnXUkKO98mthLHnXP4PTmQapwtuLdzhPgqEbNNK6zmz6T1SRWhC3X/mzH6DTe9c2 YCEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CxRMRmK8; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45639-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45639-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVzzNRZZjsNRcNo9n1JNFXbZgkPouY8+R93yfAjPvxRJGEY+Ffe+743Gnuo1IptMBjQJDCd0EEssEGhYakyhIxQgPAbJQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n4-20020a1709026a8400b001d8d052e9a1si5234160plk.586.2024.01.30.19.07.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 19:07:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45639-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CxRMRmK8; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45639-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45639-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CB7E228AC6F for ; Wed, 31 Jan 2024 02:20:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AF083A8F2; Wed, 31 Jan 2024 02:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="CxRMRmK8" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 961A2538A; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=hvXsB86mjevxkQ4Kc2Vr8Xqkp+QuExkJCbC/bbpxEvN7F7BfC3Pk3gJeLb8d5MUVJYyYSP99T03npkDQrveOqMOU1MPk35cetKDEx1PJLcnduBlNHkZztDQ3bOAvTEtONqGojLaHSq8g0XacYU7V1XpzrmN+ryxtSRcwdhwtv3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=blvWdmAlT8N2pI4NeUMKOVsakHhLte/Ud+yLGi+AMhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uRdxcXwMtEmA5ibkNDPaQhbALqpFNymS+L84AmorWlFYPvdPvtewSLdldIdWI+RLWJ+VlthMxEplUjgK7hSpCKUv8eaEOVuOcP9zT2UIZ+5DP35Tv6sqZlmqTdCE9TphQSE8hjxh8DYLP79//1/0XGfq9PwxRkDK6bLCvgR7dc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=CxRMRmK8; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=dBqQoWEccHAFufDAEgUe6Vd0qbJ3tQL100kMCYoxJh0=; b=CxRMRmK8l3r4pC2PM/mTZLAsWW VoLkYLIYcBcbRA1oPBu1FMhm4kW7Bm3IaakaJMYUPDNmmnQB/3fx+vmze4diV6CdM504owE1BL3eX OZGuZXfNInLbiulypZ3IJku6m2p3mbCOFtd4lv8DUR14GKnZIS98QkA/W439TUy+W8M0AGLGaQFgZ GyKIfmFUCp7b0/azvcp6NArQZyu81SQbzH4NVbmlPcWd4Bz8YnhdMEHWsO+exAJ9EnA4nFp6/Ns0k XgBrTPfYbAQYToyBqIs7Gv7kdgrbwxnp6asSZrcC4PqU9mltlf47v/2gwUAAav4DzxRyN8+g3czLT rpAwAsOw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08m-0038Kv-2R; Tue, 30 Jan 2024 20:15:52 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 04/29] ntsync: Introduce NTSYNC_IOC_WAIT_ANY. Date: Tue, 30 Jan 2024 20:13:31 -0600 Message-ID: <20240131021356.10322-5-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789573704087718012 X-GMAIL-MSGID: 1789573704087718012 This corresponds to part of the functionality of the NT syscall NtWaitForMultipleObjects(). Specifically, it implements the behaviour where the third argument (wait_any) is TRUE, and it does not handle alertable waits. Those features have been split out into separate patches to ease review. NTSYNC_IOC_WAIT_ANY is a vectored wait function similar to poll(). Unlike poll(), it "consumes" objects when they are signaled. For semaphores, this means decreasing one from the internal counter. At most one object can be consumed by this function. Up to 64 objects can be waited on at once. As soon as one is signaled, the object with the lowest index is consumed, and that index is returned via the "index" field. A timeout is supported. The timeout is passed as a u64 nanosecond value, which represents absolute time measured against the MONOTONIC clock. If U64_MAX is passed, the ioctl waits indefinitely. This ioctl validates that all objects belong to the relevant device. This is not necessary for any technical reason related to NTSYNC_IOC_WAIT_ANY, but will be necessary for NTSYNC_IOC_WAIT_ALL introduced in the following patch. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 232 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 12 ++ 2 files changed, 244 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 1af38969f9a2..0a0ab755d57f 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -34,12 +34,55 @@ struct ntsync_obj { __u32 max; } sem; } u; + + struct list_head any_waiters; +}; + +struct ntsync_q_entry { + struct list_head node; + struct ntsync_q *q; + struct ntsync_obj *obj; + __u32 index; +}; + +struct ntsync_q { + struct task_struct *task; + __u32 owner; + + /* + * Protected via atomic_cmpxchg(). Only the thread that wins the + * compare-and-swap may actually change object states and wake this + * task. + */ + atomic_t signaled; + + __u32 count; + struct ntsync_q_entry entries[]; }; struct ntsync_device { struct file *file; }; +static void try_wake_any_sem(struct ntsync_obj *sem) +{ + struct ntsync_q_entry *entry; + + lockdep_assert_held(&sem->lock); + + list_for_each_entry(entry, &sem->any_waiters, node) { + struct ntsync_q *q = entry->q; + + if (!sem->u.sem.count) + break; + + if (atomic_cmpxchg(&q->signaled, -1, entry->index) == -1) { + sem->u.sem.count--; + wake_up_process(q->task); + } + } +} + /* * Actually change the semaphore state, returning -EOVERFLOW if it is made * invalid. @@ -73,6 +116,8 @@ static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) prev_count = sem->u.sem.count; ret = post_sem_state(sem, args); + if (!ret) + try_wake_any_sem(sem); spin_unlock(&sem->lock); @@ -126,6 +171,7 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, obj->dev = dev; get_file(dev->file); spin_lock_init(&obj->lock); + INIT_LIST_HEAD(&obj->any_waiters); return obj; } @@ -176,6 +222,190 @@ static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) return put_user(fd, &user_args->sem); } +static struct ntsync_obj *get_obj(struct ntsync_device *dev, int fd) +{ + struct file *file = fget(fd); + struct ntsync_obj *obj; + + if (file->f_op != &ntsync_obj_fops) + { + fput(file); + return NULL; + } + + obj = file->private_data; + if (obj->dev != dev) + { + fput(file); + return NULL; + } + + return obj; +} + +static void put_obj(struct ntsync_obj *obj) +{ + fput(obj->file); +} + +static int ntsync_schedule(const struct ntsync_q *q, ktime_t *timeout) +{ + int ret = 0; + + do { + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } + + set_current_state(TASK_INTERRUPTIBLE); + if (atomic_read(&q->signaled) != -1) { + ret = 0; + break; + } + ret = schedule_hrtimeout(timeout, HRTIMER_MODE_ABS); + } while (ret < 0); + __set_current_state(TASK_RUNNING); + + return ret; +} + +/* + * Allocate and initialize the ntsync_q structure, but do not queue us yet. + */ +static int setup_wait(struct ntsync_device *dev, + const struct ntsync_wait_args *args, + struct ntsync_q **ret_q) +{ + const __u32 count = args->count; + int fds[NTSYNC_MAX_WAIT_COUNT]; + struct ntsync_q *q; + __u32 i, j; + + if (!args->owner || args->pad) + return -EINVAL; + + if (args->count > NTSYNC_MAX_WAIT_COUNT) + return -EINVAL; + + if (copy_from_user(fds, u64_to_user_ptr(args->objs), + array_size(count, sizeof(*fds)))) + return -EFAULT; + + q = kmalloc(struct_size(q, entries, count), GFP_KERNEL); + if (!q) + return -ENOMEM; + q->task = current; + q->owner = args->owner; + atomic_set(&q->signaled, -1); + q->count = count; + + for (i = 0; i < count; i++) { + struct ntsync_q_entry *entry = &q->entries[i]; + struct ntsync_obj *obj = get_obj(dev, fds[i]); + + if (!obj) + goto err; + + entry->obj = obj; + entry->q = q; + entry->index = i; + } + + *ret_q = q; + return 0; + +err: + for (j = 0; j < i; j++) + put_obj(q->entries[j].obj); + kfree(q); + return -EINVAL; +} + +static void try_wake_any_obj(struct ntsync_obj *obj) +{ + switch (obj->type) { + case NTSYNC_TYPE_SEM: + try_wake_any_sem(obj); + break; + } +} + +static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) +{ + struct ntsync_wait_args args; + struct ntsync_q *q; + ktime_t timeout; + int signaled; + __u32 i; + int ret; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + ret = setup_wait(dev, &args, &q); + if (ret < 0) + return ret; + + /* queue ourselves */ + + for (i = 0; i < args.count; i++) { + struct ntsync_q_entry *entry = &q->entries[i]; + struct ntsync_obj *obj = entry->obj; + + spin_lock(&obj->lock); + list_add_tail(&entry->node, &obj->any_waiters); + spin_unlock(&obj->lock); + } + + /* check if we are already signaled */ + + for (i = 0; i < args.count; i++) { + struct ntsync_obj *obj = q->entries[i].obj; + + if (atomic_read(&q->signaled) != -1) + break; + + spin_lock(&obj->lock); + try_wake_any_obj(obj); + spin_unlock(&obj->lock); + } + + /* sleep */ + + timeout = ns_to_ktime(args.timeout); + ret = ntsync_schedule(q, args.timeout == U64_MAX ? NULL : &timeout); + + /* and finally, unqueue */ + + for (i = 0; i < args.count; i++) { + struct ntsync_q_entry *entry = &q->entries[i]; + struct ntsync_obj *obj = entry->obj; + + spin_lock(&obj->lock); + list_del(&entry->node); + spin_unlock(&obj->lock); + + put_obj(obj); + } + + signaled = atomic_read(&q->signaled); + if (signaled != -1) { + struct ntsync_wait_args __user *user_args = argp; + + /* even if we caught a signal, we need to communicate success */ + ret = 0; + + if (put_user(signaled, &user_args->index)) + ret = -EFAULT; + } else if (!ret) { + ret = -ETIMEDOUT; + } + + kfree(q); + return ret; +} + static int ntsync_char_open(struct inode *inode, struct file *file) { struct ntsync_device *dev; @@ -207,6 +437,8 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case NTSYNC_IOC_CREATE_SEM: return ntsync_create_sem(dev, argp); + case NTSYNC_IOC_WAIT_ANY: + return ntsync_wait_any(dev, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 878ec4f0f2e8..9cd1dd05d971 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -16,7 +16,19 @@ struct ntsync_sem_args { __u32 max; }; +struct ntsync_wait_args { + __u64 timeout; + __u64 objs; + __u32 count; + __u32 owner; + __u32 index; + __u32 pad; +}; + +#define NTSYNC_MAX_WAIT_COUNT 64 + #define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args) +#define NTSYNC_IOC_WAIT_ANY _IOWR('N', 0x82, struct ntsync_wait_args) #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) From patchwork Wed Jan 31 02:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628186dyb; Tue, 30 Jan 2024 18:26:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKTNtBtEVibXaAUQSD7czQgLt+Z/T/oURv4mmf55wR8EDS/a/8OK+8Tl7vDy7psbNpCvaI X-Received: by 2002:a05:651c:22b:b0:2cf:321:6589 with SMTP id z11-20020a05651c022b00b002cf03216589mr177137ljn.7.1706667992575; Tue, 30 Jan 2024 18:26:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667992; cv=pass; d=google.com; s=arc-20160816; b=fimpC/yHS73xt5u85IqlnxYwdsX2Iio/ZUk9EnT/9iTQHSytaqf9moUKFRNv9nPE99 lQ01LbpuN390+ZXQ5QUBhLBRYIZUkqZ00/TNpDztZG8fL1JrstmKrZXTAxqkLUhMB0Q5 xzr85am3YHeDMHeR40LgHl+UPGh6Zle9wIcwxPvBYcTpvULRtJ+RXL7vksZ/DcDg/4KC nodloyVr5tVeAZfcvRhHkC4buT26av2FqqYrfgSbeTK1XpLbMraMggSH0pAt0GFvM16R uvZ54/c8R4/qdJIALSK1tymoXPt6fZubNzLnKShsndRDdkbgvnyBgVwtj9okaw9T48KK ByiQ== 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=1nZfxA6F+f1Z0QNAff3Atu7Bjojb83j3C3DRMMsyh9k=; fh=043RwhyTei34vk6T0Yo6x4qbjZu9icsWcNL1HAhzE2c=; b=i0U0MpwPJxursLhYE/9Pp27gulYLmObF/cjBmk33IKdD+4C9IlkC5q4TP3lNOyhdX6 lGZ67P8MYqcMO6OCQd9u7ytz5yhVMPiJJ/7kgEl1pcKNMiBsVnDoL4LdkSQ0+y3nQoSx Nm/XO1WuG9++m5MFGIloyBU+hQTBDzyKGrPDQx3uCWIin/rWHcXutTW8pZkDMoA/0PM6 /7ERvfyvwFr6ZW/gq2p7beJqCCmQLWg+IOtqtJFhkNhHcS3N0EhOe+a7fOpnH1v7a1ik HVr5LsUs583ijYuBO7IKHAxpJfyi4IVjnNZhqIPxNgeXLZgEHxER2r5wGLv90PzWozqB A8ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=GheGKtzS; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45640-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45640-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVKAcL4CWhv2MN6M+8bII0wdawZKdADK7JKCJT4WYgbSEqBU0tqNU8vSB8m27TUzv0pSLjWo4CNHciYm/DIa7Ubmw+YjQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t11-20020a508d4b000000b0055c2dd404d3si5232066edt.195.2024.01.30.18.26.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:26:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45640-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=GheGKtzS; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45640-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45640-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 2323A1F2897C for ; Wed, 31 Jan 2024 02:21:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 318793B783; Wed, 31 Jan 2024 02:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="GheGKtzS" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9626253B8; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=J4RXm0vK6hq1RL5lfIOnN+YL07ioyIaPY/7xs5z/FsF1OdUOsPl2bvlNs7aIFii+TXVIRWCabmzefpY+8IheqDoYckAK9WX1omYuStNGyyc1JpafwNDRd7qncfRLFhRMdklH65RKj7YDwlAp3oPylxs8sjjyhl9FQVNUkZYgsug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=E0RabA4ujEItZ2gxO012NoEcQriEtTBQqQAiA6bd+ag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6D+6q5b3HQNjDOrZSYYz0xLJ/v4HIcv44UxjpzCRZRyeOCLhREjqwZEkCemGEUUgBvono2Fv8SfSde3b8shmWIhPsK9W2oLziOmHa5Q30kDNWsuAJrNBmmAJ190LkTCiE8yeTngDWmwrTZOPtGDpiyJzZCgOg8eNVqaC15e12M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=GheGKtzS; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=1nZfxA6F+f1Z0QNAff3Atu7Bjojb83j3C3DRMMsyh9k=; b=GheGKtzSGNluDb60CI1sgKyo7T DO3cCHO7gFrEYlqWOuwZJ2VsCG3vBABvQX7CvPbC+B2XAEopsAcUv+OGqgflV4fTPV5DJVhusaBwK anB1CnAYvJtVgXEnWNLQgKDZ7lD/lrC644bfDPpf3LdnTma/OMLVOBg5qrr4vDQT7+WUFqfs8bbP0 fmtly5U9gFK6zUbhjukRi089lX3pl9yWKJ7wMPj2/UXaz2ZbWztMqMYVFXbJ1VlwuyrpZxCQK8HXq EpVOrov85j1/gvVua7bUQt3Zbq9HqIW4kuEdv0hnqEfATReeSrcp1DPA6nY3KV4Lgj/Z8SiIAW9+2 1waQKOyQ==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08m-0038Kv-2x; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 05/29] ntsync: Introduce NTSYNC_IOC_WAIT_ALL. Date: Tue, 30 Jan 2024 20:13:32 -0600 Message-ID: <20240131021356.10322-6-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571096467326575 X-GMAIL-MSGID: 1789571096467326575 This is similar to NTSYNC_IOC_WAIT_ANY, but waits until all of the objects are simultaneously signaled, and then acquires all of them as a single atomic operation. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 244 ++++++++++++++++++++++++++++++++++-- include/uapi/linux/ntsync.h | 1 + 2 files changed, 237 insertions(+), 8 deletions(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 0a0ab755d57f..b86d62094344 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -35,7 +35,34 @@ struct ntsync_obj { } sem; } u; + /* + * any_waiters is protected by the object lock, but all_waiters is + * protected by the device wait_all_lock. + */ struct list_head any_waiters; + struct list_head all_waiters; + + /* + * Hint describing how many tasks are queued on this object in a + * wait-all operation. + * + * Any time we do a wake, we may need to wake "all" waiters as well as + * "any" waiters. In order to atomically wake "all" waiters, we must + * lock all of the objects, and that means grabbing the wait_all_lock + * below (and, due to lock ordering rules, before locking this object). + * However, wait-all is a rare operation, and grabbing the wait-all + * lock for every wake would create unnecessary contention. + * Therefore we first check whether all_hint is zero, and, if it is, + * we skip trying to wake "all" waiters. + * + * This hint isn't protected by any lock. It might change during the + * course of a wake, but there's no meaningful race there; it's only a + * hint. + * + * Since wait requests must originate from user-space threads, we're + * limited here by PID_MAX_LIMIT, so there's no risk of overflow. + */ + atomic_t all_hint; }; struct ntsync_q_entry { @@ -56,14 +83,99 @@ struct ntsync_q { */ atomic_t signaled; + bool all; __u32 count; struct ntsync_q_entry entries[]; }; struct ntsync_device { + /* + * Wait-all operations must atomically grab all objects, and be totally + * ordered with respect to each other and wait-any operations. + * If one thread is trying to acquire several objects, another thread + * cannot touch the object at the same time. + * + * We achieve this by grabbing multiple object locks at the same time. + * However, this creates a lock ordering problem. To solve that problem, + * wait_all_lock is taken first whenever multiple objects must be locked + * at the same time. + */ + spinlock_t wait_all_lock; + struct file *file; }; +static bool is_signaled(struct ntsync_obj *obj, __u32 owner) +{ + lockdep_assert_held(&obj->lock); + + switch (obj->type) { + case NTSYNC_TYPE_SEM: + return !!obj->u.sem.count; + } + + WARN(1, "bad object type %#x\n", obj->type); + return false; +} + +/* + * "locked_obj" is an optional pointer to an object which is already locked and + * should not be locked again. This is necessary so that changing an object's + * state and waking it can be a single atomic operation. + */ +static void try_wake_all(struct ntsync_device *dev, struct ntsync_q *q, + struct ntsync_obj *locked_obj) +{ + __u32 count = q->count; + bool can_wake = true; + __u32 i; + + lockdep_assert_held(&dev->wait_all_lock); + if (locked_obj) + lockdep_assert_held(&locked_obj->lock); + + for (i = 0; i < count; i++) { + if (q->entries[i].obj != locked_obj) + spin_lock_nest_lock(&q->entries[i].obj->lock, &dev->wait_all_lock); + } + + for (i = 0; i < count; i++) { + if (!is_signaled(q->entries[i].obj, q->owner)) { + can_wake = false; + break; + } + } + + if (can_wake && atomic_cmpxchg(&q->signaled, -1, 0) == -1) { + for (i = 0; i < count; i++) { + struct ntsync_obj *obj = q->entries[i].obj; + + switch (obj->type) { + case NTSYNC_TYPE_SEM: + obj->u.sem.count--; + break; + } + } + wake_up_process(q->task); + } + + for (i = 0; i < count; i++) { + if (q->entries[i].obj != locked_obj) + spin_unlock(&q->entries[i].obj->lock); + } +} + +static void try_wake_all_obj(struct ntsync_device *dev, struct ntsync_obj *obj) +{ + struct ntsync_q_entry *entry; + + lockdep_assert_held(&dev->wait_all_lock); + lockdep_assert_held(&obj->lock); + + list_for_each_entry(entry, &obj->all_waiters, node) + try_wake_all(dev, entry->q, obj); +} + static void try_wake_any_sem(struct ntsync_obj *sem) { struct ntsync_q_entry *entry; @@ -101,6 +213,7 @@ static int post_sem_state(struct ntsync_obj *sem, __u32 count) static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) { + struct ntsync_device *dev = sem->dev; __u32 __user *user_args = argp; __u32 prev_count; __u32 args; @@ -112,14 +225,29 @@ static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) if (sem->type != NTSYNC_TYPE_SEM) return -EINVAL; - spin_lock(&sem->lock); + if (atomic_read(&sem->all_hint) > 0) { + spin_lock(&dev->wait_all_lock); + spin_lock_nest_lock(&sem->lock, &dev->wait_all_lock); - prev_count = sem->u.sem.count; - ret = post_sem_state(sem, args); - if (!ret) - try_wake_any_sem(sem); + prev_count = sem->u.sem.count; + ret = post_sem_state(sem, args); + if (!ret) { + try_wake_all_obj(dev, sem); + try_wake_any_sem(sem); + } - spin_unlock(&sem->lock); + spin_unlock(&sem->lock); + spin_unlock(&dev->wait_all_lock); + } else { + spin_lock(&sem->lock); + + prev_count = sem->u.sem.count; + ret = post_sem_state(sem, args); + if (!ret) + try_wake_any_sem(sem); + + spin_unlock(&sem->lock); + } if (!ret && put_user(prev_count, user_args)) ret = -EFAULT; @@ -172,6 +300,8 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, get_file(dev->file); spin_lock_init(&obj->lock); INIT_LIST_HEAD(&obj->any_waiters); + INIT_LIST_HEAD(&obj->all_waiters); + atomic_set(&obj->all_hint, 0); return obj; } @@ -274,7 +404,7 @@ static int ntsync_schedule(const struct ntsync_q *q, ktime_t *timeout) * Allocate and initialize the ntsync_q structure, but do not queue us yet. */ static int setup_wait(struct ntsync_device *dev, - const struct ntsync_wait_args *args, + const struct ntsync_wait_args *args, bool all, struct ntsync_q **ret_q) { const __u32 count = args->count; @@ -298,6 +428,7 @@ static int setup_wait(struct ntsync_device *dev, q->task = current; q->owner = args->owner; atomic_set(&q->signaled, -1); + q->all = all; q->count = count; for (i = 0; i < count; i++) { @@ -307,6 +438,16 @@ static int setup_wait(struct ntsync_device *dev, if (!obj) goto err; + if (all) { + /* Check that the objects are all distinct. */ + for (j = 0; j < i; j++) { + if (obj == q->entries[j].obj) { + put_obj(obj); + goto err; + } + } + } + entry->obj = obj; entry->q = q; entry->index = i; @@ -343,7 +484,7 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) if (copy_from_user(&args, argp, sizeof(args))) return -EFAULT; - ret = setup_wait(dev, &args, &q); + ret = setup_wait(dev, &args, false, &q); if (ret < 0) return ret; @@ -406,6 +547,89 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) return ret; } +static int ntsync_wait_all(struct ntsync_device *dev, void __user *argp) +{ + struct ntsync_wait_args args; + struct ntsync_q *q; + ktime_t timeout; + int signaled; + __u32 i; + int ret; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + ret = setup_wait(dev, &args, true, &q); + if (ret < 0) + return ret; + + /* queue ourselves */ + + spin_lock(&dev->wait_all_lock); + + for (i = 0; i < args.count; i++) { + struct ntsync_q_entry *entry = &q->entries[i]; + struct ntsync_obj *obj = entry->obj; + + atomic_inc(&obj->all_hint); + + /* + * obj->all_waiters is protected by dev->wait_all_lock rather + * than obj->lock, so there is no need to acquire obj->lock + * here. + */ + list_add_tail(&entry->node, &obj->all_waiters); + } + + /* check if we are already signaled */ + + try_wake_all(dev, q, NULL); + + spin_unlock(&dev->wait_all_lock); + + /* sleep */ + + timeout = ns_to_ktime(args.timeout); + ret = ntsync_schedule(q, args.timeout == U64_MAX ? NULL : &timeout); + + /* and finally, unqueue */ + + spin_lock(&dev->wait_all_lock); + + for (i = 0; i < args.count; i++) { + struct ntsync_q_entry *entry = &q->entries[i]; + struct ntsync_obj *obj = entry->obj; + + /* + * obj->all_waiters is protected by dev->wait_all_lock rather + * than obj->lock, so there is no need to acquire it here. + */ + list_del(&entry->node); + + atomic_dec(&obj->all_hint); + + put_obj(obj); + } + + spin_unlock(&dev->wait_all_lock); + + signaled = atomic_read(&q->signaled); + if (signaled != -1) { + struct ntsync_wait_args __user *user_args = argp; + + /* even if we caught a signal, we need to communicate success */ + ret = 0; + + if (put_user(signaled, &user_args->index)) + ret = -EFAULT; + } else if (!ret) { + ret = -ETIMEDOUT; + } + + kfree(q); + return ret; +} + static int ntsync_char_open(struct inode *inode, struct file *file) { struct ntsync_device *dev; @@ -414,6 +638,8 @@ static int ntsync_char_open(struct inode *inode, struct file *file) if (!dev) return -ENOMEM; + spin_lock_init(&dev->wait_all_lock); + file->private_data = dev; dev->file = file; return nonseekable_open(inode, file); @@ -437,6 +663,8 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case NTSYNC_IOC_CREATE_SEM: return ntsync_create_sem(dev, argp); + case NTSYNC_IOC_WAIT_ALL: + return ntsync_wait_all(dev, argp); case NTSYNC_IOC_WAIT_ANY: return ntsync_wait_any(dev, argp); default: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 9cd1dd05d971..524404f6aceb 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -29,6 +29,7 @@ struct ntsync_wait_args { #define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args) #define NTSYNC_IOC_WAIT_ANY _IOWR('N', 0x82, struct ntsync_wait_args) +#define NTSYNC_IOC_WAIT_ALL _IOWR('N', 0x83, struct ntsync_wait_args) #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) From patchwork Wed Jan 31 02:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1630057dyb; Tue, 30 Jan 2024 18:32:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3UOGsAM+TjGDAsrS7TdxRE96hg0RzXwRL/hDoAH+ey4SsmN41lvOIToJA6X15gR9jMrae X-Received: by 2002:ac8:57d0:0:b0:42a:a9dd:3f36 with SMTP id w16-20020ac857d0000000b0042aa9dd3f36mr543302qta.3.1706668331367; Tue, 30 Jan 2024 18:32:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668331; cv=pass; d=google.com; s=arc-20160816; b=X5LxWH+lJHl6MxCdaRo3L9hUJva/zO/NHZ+ypxIJnGe5EXa1a/UWV+Ig9kuL7B4HY7 KI1Gmr0KBhwC3suRFv5G6vyV6A+OBLYGdwNmV5BcNIcA36xjkG+OsHTvYPhwkJY89CrL iGolQoP1+Kc9hGR34Jjc1tsziBHohYTiyozva0sXB8Uf1ra1k4uzIuzTZbz3YvjTo8f5 f0ZLz2F8glGLipDcVWMEmQOMwViVGW41d8G5pZySP3D/oAJMWcO2QTC8miF2QVQNvTl5 CAQGpX91CRC4n0tXxmCDOF+em68WsfUcyYZo8CoMjgmiyU7YjRlJvXPUi4kar4oac8Rb FXXQ== 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=Of6XvOdno9uHHT4oAURNTaZ9M/wg5z+Nwm47YS4aRDY=; fh=TKcTsE/bC2RrE7HNpSHSRj5eqYeYEd6BSCUTFgCntdI=; b=Jgf5n+/d09LPcMfn3MSaSb6grvY11CvefJgJKsqEQNztU+kk1NdHGqmkOjQVSl+Ijb vtwMDh5jKlDYEKCFMF7NWLXcJLPNJ8yLaNLh3d9SecIatVm+sbIz6fBR7euuEwnnMy7Z vpOrfJXuQk20LKlumXmR+JXVcnGWQjzoLS5neSmQmwqRFtyD5SvYb0QRskXleeoDMB6L GDkMXRNP+Di6l6xamsiGMpeDFLJreKDLr2mP+NHWBBezO5MWAsyrtNblPRPstpst48Ff 20dkC4f2eDAiOJIj5P6BaxdQR98yzD9SazTdv7LR3j3n8cLCOCwguLKZ+NlcJFw66Fw3 uhFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Y1oQjZkp; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45655-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45655-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXWfkOePTy2zYmvBQvRpsXDd7k1NfCxrxO4d0SI6528lFWZXnLL03b+RJmpt3ux1Wqz5gucY4A0hVfSBr6AeyOjesn6MQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v21-20020a05622a145500b0042a3d352f58si7678848qtx.522.2024.01.30.18.32.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:32:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45655-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Y1oQjZkp; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45655-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45655-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 334AB1C279CF for ; Wed, 31 Jan 2024 02:23:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B04B63D992; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Y1oQjZkp" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 966E95681; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; cv=none; b=Te4PXsuGnkzvTPspI3fWBf82d1Mt17auMFkTMKPPl7c2Fmyx9QdAFelyhHISUHXsuQLkt5y3vU3u5VmGEzj59xvaGBnyYI42muNVUyH2FcgRew3hd3gEb3TxdbwRZn+orqo7Gjrc2JJ0oEPiB5faLdFz4Q1QwFaqVFLWADvpL6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; c=relaxed/simple; bh=7AY2HZYGR310aOiJlG/Cr8lCYxSCjMuzd+bM62Jk8lg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ta96n6eI5y86yx6NPLsGapnLPuUja4L8rm44c1E/6XFQD1RAyFYKP9mL694xssshJKWEQgfRKs9UUcV94fddgzqbH52UazinxwAE70mpJ3PDE/y7+qoqfVwtmIXzKmgEazBI7xUSDGsG96zaiyInVBDpKt1blzcenLnGGNNHLEE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=Y1oQjZkp; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=Of6XvOdno9uHHT4oAURNTaZ9M/wg5z+Nwm47YS4aRDY=; b=Y1oQjZkpIVyB0olo8Cvjg7obnV /40XsM0b4bsZUxHER+nJBgp49OCRJiXwpmARuvbfcGXVpdq3y1aO4YAig+DXJ16fDu+cSa6E4CkzM lWuRxu5exTEhOzDgg4dJXwqKuKuksPqxMaTs8QxT8frZHw9E8rMBg7O0XgpdCgb3GoyxkoiRDN9GY aKLGv3JjKsihBgJeWaqR9kywP7omVbyycadb+gl+4D8k4fagPbLlPkwKjeul8qVLy/nQ8HLUgQtPf YlEEAsDlm5vHAX8Ab4whTn/4s+75aE1J0+KLj4FeN+GJdPVxM3fBpVYDNjMfvRxQZyvBLGMJsJXkb iV8IbpBw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-0W; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 06/29] ntsync: Introduce NTSYNC_IOC_CREATE_MUTEX. Date: Tue, 30 Jan 2024 20:13:33 -0600 Message-ID: <20240131021356.10322-7-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571452330132272 X-GMAIL-MSGID: 1789571452330132272 This corresponds to the NT syscall NtCreateMutant(). An NT mutex is recursive, with a 32-bit recursion counter. When acquired via NtWaitForMultipleObjects(), the recursion counter is incremented by one. The OS records the thread which acquired it. However, in order to keep this driver self-contained, the owning thread ID is managed by user-space, and passed as a parameter to all relevant ioctls. The initial owner and recursion count, if any, are specified when the mutex is created. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 67 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 7 ++++ 2 files changed, 74 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index b86d62094344..484219a266ae 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -17,6 +17,7 @@ enum ntsync_type { NTSYNC_TYPE_SEM, + NTSYNC_TYPE_MUTEX, }; struct ntsync_obj { @@ -33,6 +34,10 @@ struct ntsync_obj { __u32 count; __u32 max; } sem; + struct { + __u32 count; + __u32 owner; + } mutex; } u; /* @@ -112,6 +117,10 @@ static bool is_signaled(struct ntsync_obj *obj, __u32 owner) switch (obj->type) { case NTSYNC_TYPE_SEM: return !!obj->u.sem.count; + case NTSYNC_TYPE_MUTEX: + if (obj->u.mutex.owner && obj->u.mutex.owner != owner) + return false; + return obj->u.mutex.count < UINT_MAX; } WARN(1, "bad object type %#x\n", obj->type); @@ -154,6 +163,10 @@ static void try_wake_all(struct ntsync_device *dev, struct ntsync_q *q, case NTSYNC_TYPE_SEM: obj->u.sem.count--; break; + case NTSYNC_TYPE_MUTEX: + obj->u.mutex.count++; + obj->u.mutex.owner = q->owner; + break; } } wake_up_process(q->task); @@ -195,6 +208,28 @@ static void try_wake_any_sem(struct ntsync_obj *sem) } } +static void try_wake_any_mutex(struct ntsync_obj *mutex) +{ + struct ntsync_q_entry *entry; + + lockdep_assert_held(&mutex->lock); + + list_for_each_entry(entry, &mutex->any_waiters, node) { + struct ntsync_q *q = entry->q; + + if (mutex->u.mutex.count == UINT_MAX) + break; + if (mutex->u.mutex.owner && mutex->u.mutex.owner != q->owner) + continue; + + if (atomic_cmpxchg(&q->signaled, -1, entry->index) == -1) { + mutex->u.mutex.count++; + mutex->u.mutex.owner = q->owner; + wake_up_process(q->task); + } + } +} + /* * Actually change the semaphore state, returning -EOVERFLOW if it is made * invalid. @@ -352,6 +387,33 @@ static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) return put_user(fd, &user_args->sem); } +static int ntsync_create_mutex(struct ntsync_device *dev, void __user *argp) +{ + struct ntsync_mutex_args __user *user_args = argp; + struct ntsync_mutex_args args; + struct ntsync_obj *mutex; + int fd; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + if (!args.owner != !args.count) + return -EINVAL; + + mutex = ntsync_alloc_obj(dev, NTSYNC_TYPE_MUTEX); + if (!mutex) + return -ENOMEM; + mutex->u.mutex.count = args.count; + mutex->u.mutex.owner = args.owner; + fd = ntsync_obj_get_fd(mutex); + if (fd < 0) { + kfree(mutex); + return fd; + } + + return put_user(fd, &user_args->mutex); +} + static struct ntsync_obj *get_obj(struct ntsync_device *dev, int fd) { struct file *file = fget(fd); @@ -469,6 +531,9 @@ static void try_wake_any_obj(struct ntsync_obj *obj) case NTSYNC_TYPE_SEM: try_wake_any_sem(obj); break; + case NTSYNC_TYPE_MUTEX: + try_wake_any_mutex(obj); + break; } } @@ -661,6 +726,8 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, void __user *argp = (void __user *)parm; switch (cmd) { + case NTSYNC_IOC_CREATE_MUTEX: + return ntsync_create_mutex(dev, argp); case NTSYNC_IOC_CREATE_SEM: return ntsync_create_sem(dev, argp); case NTSYNC_IOC_WAIT_ALL: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 524404f6aceb..d68f24fd75a2 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -16,6 +16,12 @@ struct ntsync_sem_args { __u32 max; }; +struct ntsync_mutex_args { + __u32 mutex; + __u32 owner; + __u32 count; +}; + struct ntsync_wait_args { __u64 timeout; __u64 objs; @@ -30,6 +36,7 @@ struct ntsync_wait_args { #define NTSYNC_IOC_CREATE_SEM _IOWR('N', 0x80, struct ntsync_sem_args) #define NTSYNC_IOC_WAIT_ANY _IOWR('N', 0x82, struct ntsync_wait_args) #define NTSYNC_IOC_WAIT_ALL _IOWR('N', 0x83, struct ntsync_wait_args) +#define NTSYNC_IOC_CREATE_MUTEX _IOWR('N', 0x84, struct ntsync_sem_args) #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) From patchwork Wed Jan 31 02:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628515dyb; Tue, 30 Jan 2024 18:27:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGF6slzGoamh6C83CzkRmiItKamOFXVghq9aeiJ/tr4fx5CLPiLvOp9Ru5HG37aigWjVMLy X-Received: by 2002:a05:6a00:b52:b0:6da:ca92:3e2e with SMTP id p18-20020a056a000b5200b006daca923e2emr3259297pfo.7.1706668060481; Tue, 30 Jan 2024 18:27:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668060; cv=pass; d=google.com; s=arc-20160816; b=kf5m5F5JRkFDnfEOlAHCimwuHld9uWjGV4Sry3ydoqoTPZRtxpsElMemar0EUGe4cq ECtxnfFnMethyttwNcbxtKkDjHAp1JYCOI5HUGeZZMJuTG83cx3q8ExMBlNo4hrSoSXy 3J2bVYGgCiSoknPHHObypbCmsEE13CatC/Aiu5Ataa3GvXWRDK8e8mZEDRx8/JfRpbON MOqs2tMNrkxpYPE2ESuiwX5SwSlbiPIoaAnaiA5Ip+OSeaOZLBdhUBJdhD4Sg4Kndm4h bEGI8CzqHwOhaI8AGBLPMfAClNz21dwwr/deMaIDr72qN26h9NOjWXOO1RL4r8C7GJ07 sJYA== 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=P3QYzBA4EV4T10nQsEVxMllwkWrG/Pg5gVd9g6PO8jQ=; fh=oGabdciB6lQeUlf1KJ8Y+cH+jh3zzRzN+PDIwi+paus=; b=ycGYPmtwp/pasB5wrdRzt2iho68JNmax0S4S0RN54xpznXIrFJoxqA7jqozcgEnvxn Z/fgIc6ihSvmiwfSI07XyKdyCgs046dEdb0lkRrmzf7BwycEZWBB0+KypyZUISZjNZbo fplMNeG/HmDMbXM8zk5P9U6jChUilv1I5vbLFOU1bqjQujGUJ1+Uq5KVRx5tnZWpHWEp BRlYriKmUOWV24kSQ6X/jZ38n9Udfp1CQPO+BMDQYHXSTLobREV2A1xE1IIOSzCJK7eF bqWD8ctgq72IBKXhvWHhUJz9Eh66aN8p64W0eXSD+i6WNErFeY7sAzr3q9VO4T9u36Qo nrGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=PPni3DAK; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45646-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45646-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVuzQs+mNln+9rrAZAZlSg0kmfjFfg+ViwxkLX3prcTpOQ6qlw3RCqrCEM9MgLK6sOn3JrIu6gaBTEf8DCUZR89OJ9vQg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a16-20020aa78e90000000b006dda276d969si8430930pfr.37.2024.01.30.18.27.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:27:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45646-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=PPni3DAK; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45646-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45646-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EF39AB26978 for ; Wed, 31 Jan 2024 02:22:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 658EE3D396; Wed, 31 Jan 2024 02:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="PPni3DAK" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 965CB5672; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=qbornavIPhx1ljnVfDBXoq5iSEpe80mO+JrqZoS0YvWN9Zlez40X8fUaZtmFp05doUw96A8srxi8MW3VEkT37Ropj4qIMZ4mpnA9qTrddxY2+Idqnj9Bc1RfQnJrxAvQFycp+wSQ5ZA6JBwQjXWZ8TqiWTI9b49rWbcVxWuBKu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=9wT+B7+F1Vv/UHIWNs5HiJCid1GsqOvXjQ+iDzWwuzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K83Hu/NphHFJn0r/wGcD1LZBSAdahGrAVHg9b4x4KUmmN9+by3o5WSof1yIuqOBeUaHOIIsfFS8t58eIsZrUyDl0DtTp4KZpsKsXqW9LteXHjB5rTcQEAE+oyE6iQ2tDHIwL/a89a6Dn9eSgRVS43crJT3NZXr1RHiaqvahFsGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=PPni3DAK; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=P3QYzBA4EV4T10nQsEVxMllwkWrG/Pg5gVd9g6PO8jQ=; b=PPni3DAKGSUoK7BXRjdWNHpeBL 54ckrLRisbmRDYFHO/ZczaH9HL2BMd+yCcG7TCPzdE1vSys0KSDbB+B3xTikGyATyLH6C7QH1R7ie HcJ81uHAOre+bjwvAbfzg2XYiGyo9NEH9MqaJxD1+nyGa/oVDMkc1H6DI2lEtl4ModNOQE2yb9plf jbHpRCYAGcL+3GcUihUpnjrRBOUj4SOSz0d7BDXpy9COvSvorfLA2yHQVpYeUleZ/FzziTd79Ymub 6f61LhVacFnD2GPTn/e8/N2qUoTZ5HeV/gTucyOw6SikwPnK9QuGtE8rA1wsHXb72t6GjGkoNUb2h A0LIUyvw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-1L; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 07/29] ntsync: Introduce NTSYNC_IOC_MUTEX_UNLOCK. Date: Tue, 30 Jan 2024 20:13:34 -0600 Message-ID: <20240131021356.10322-8-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571168092873883 X-GMAIL-MSGID: 1789571168092873883 This corresponds to the NT syscall NtReleaseMutant(). This syscall decrements the mutex's recursion count by one, and returns the previous value. If the mutex is not owned by the given owner ID, the function instead fails and returns -EPERM. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 64 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 65 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 484219a266ae..1770ec4008af 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -290,6 +290,68 @@ static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) return ret; } +/* + * Actually change the mutex state, returning -EPERM if not the owner. + */ +static int unlock_mutex_state(struct ntsync_obj *mutex, + const struct ntsync_mutex_args *args) +{ + lockdep_assert_held(&mutex->lock); + + if (mutex->u.mutex.owner != args->owner) + return -EPERM; + + if (!--mutex->u.mutex.count) + mutex->u.mutex.owner = 0; + return 0; +} + +static int ntsync_mutex_unlock(struct ntsync_obj *mutex, void __user *argp) +{ + struct ntsync_mutex_args __user *user_args = argp; + struct ntsync_device *dev = mutex->dev; + struct ntsync_mutex_args args; + __u32 prev_count; + int ret; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + if (!args.owner) + return -EINVAL; + + if (mutex->type != NTSYNC_TYPE_MUTEX) + return -EINVAL; + + if (atomic_read(&mutex->all_hint) > 0) { + spin_lock(&dev->wait_all_lock); + spin_lock_nest_lock(&mutex->lock, &dev->wait_all_lock); + + prev_count = mutex->u.mutex.count; + ret = unlock_mutex_state(mutex, &args); + if (!ret) { + try_wake_all_obj(dev, mutex); + try_wake_any_mutex(mutex); + } + + spin_unlock(&mutex->lock); + spin_unlock(&dev->wait_all_lock); + } else { + spin_lock(&mutex->lock); + + prev_count = mutex->u.mutex.count; + ret = unlock_mutex_state(mutex, &args); + if (!ret) + try_wake_any_mutex(mutex); + + spin_unlock(&mutex->lock); + } + + if (!ret && put_user(prev_count, &user_args->count)) + ret = -EFAULT; + + return ret; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -309,6 +371,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case NTSYNC_IOC_SEM_POST: return ntsync_sem_post(obj, argp); + case NTSYNC_IOC_MUTEX_UNLOCK: + return ntsync_mutex_unlock(obj, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index d68f24fd75a2..a3f5f4f13798 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -39,5 +39,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_CREATE_MUTEX _IOWR('N', 0x84, struct ntsync_sem_args) #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) +#define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args) #endif From patchwork Wed Jan 31 02:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1629719dyb; Tue, 30 Jan 2024 18:31:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpHjqwXktFSyqvd3G1zJLzPIPkGvfG7o25HyOthFCHRpiv3ut9VdoE0L3n0ccDJeOSlXYM X-Received: by 2002:a05:6402:34d:b0:55e:ee59:be4a with SMTP id r13-20020a056402034d00b0055eee59be4amr96488edw.18.1706668276557; Tue, 30 Jan 2024 18:31:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668276; cv=pass; d=google.com; s=arc-20160816; b=rDxu28IWSnBHhjLAIAhGLnr32eDSV6nF9MICB8bdKyHCcFKjD+NYHLuF0np8Tnnb3N XiOcje6U8q57tAS1eSIXLhJKzEyeRr1ep0euCAqOr8wP7M2v4OI9z42E3rfILPjx12Cd 5k53xk6igT9j3uEGNjFQ7A1ci3Wc38hoC7lMGKz86S7PJvopi5YsQ5xwLKQc5tWUjwRm nmrqbaQNBI7YBffraMsSj9lx1IrO3dJodXS+yWTJZ4zfu9lpV7oz3ERvrkquJQxdW+Dk 9/t1J9gBRp53MvNtYRnbnoCrmvA512M1e2HKdTARqnGA+jibM0qdLFh6UpHHxQUWvfZ2 uo/w== 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=6gxggCDnUPNsYQmKqHXn0seDFBP3d7yi9LkljNs6G+o=; fh=F/L8u//ZtTQDlMhY7j8ziCoq9sgFXbUGsYTOI1rvvqs=; b=whV7iC/OJ5tT0CbLM4KKRg70IRsiZGVAi5s9/cD2VFbb4B4P1H/8CX7PIRDgN2DtRw md24Vpr3FZKSqx+84bbPld6rpeSWKAJWOm7GaBblV5jFM3qjnF5R+rlFJV86maNGKuhX k1FBu5o9+hnUjBSKYBSTOtC8ZYqs86zy4Nx3psmowkkXtJKYKKbH3+qd7hiBr0gGmh4S 2zy53X5pskVSAvzc4mFPAOdNRjzJFxZRQlx95MZlSG7RrDjY1JgpRZ+36EsitJKg8MVF RH/BeU4Jjny7pYq560Cmj/5S5wkhwxdFowpLAhQrjVmb7VGDrILB5Pnx7lrnIsP7eAnj B+xg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=pPhHWQr6; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45644-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45644-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWtOHz7OLSuMmH+Sx94de+itJtqSmR5WhqpUesXQzXKLgQQkTuBlhXwVNzmc0wbsbvnAR2N35GzuRO7DWj17KHkTJ2cRA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x19-20020a50d613000000b0055f69a2af34si353241edi.54.2024.01.30.18.31.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:31:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45644-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=pPhHWQr6; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45644-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45644-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 AC5241F28B9F for ; Wed, 31 Jan 2024 02:21:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B85AA3BB37; Wed, 31 Jan 2024 02:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="pPhHWQr6" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 AAC3A610D; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=Iv5+XUh59Oj2JjfN/CigIDAmamfS0yavyPyDwAoUMY1Ybr4mR2DLVgX8fuhJxTgT9GQCNShrtCY28YUIecZNZarhh1M6GU0hMHlKloqy3DwTJacrLUt70cTgV0WVwG7o2t1pXl9Vjk27wneGrNdYG0Hha8sf80oxE5uvUeVJUrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=M4cpkX4quEVwwnmq0C8x/sMtuoEkGghGC1T9Fuo8irY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VMA14XNSKmplreOiiPHE4qm8sO/6RcDT8W7TVELQOR1fjkjNfJUY926QhYwoOyAP8j+tbUggru4Ftx59PMXtiAuag58o+GfxwlNsx+onyTdDwBwg1BdXXJDbuMACxYXuy3jrL+czAIbpfSZmOP4QvvAgoVIPGPiZ9RecdKLteps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=pPhHWQr6; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=6gxggCDnUPNsYQmKqHXn0seDFBP3d7yi9LkljNs6G+o=; b=pPhHWQr6/nAT2mwDb4SZvuet/3 hd+qBirlgfz5YvLXMeEKflk6Z3WP2jwFvbyMwQm6J/XqTWwpiCV2GArlBRjDLOrqB2aqOUd/YDHcP E1yevq72CJgzByYq+yBiOcbK6iWjXuRWQ9UPSTOR3dAMB8WS/GKYFBUYUSCYro6EcinXGpOwSJ7kK HfpT+bH9kaO+D2FakuYy/KoJT2zwDkDcXsjFEVzfzx1Hu0ZPAdhcMx6+5r4iu8xcHtqZkDJn9xLXj eXz0X+r/f/Rd8FtRX5T4Yaj+8fpaaRggQBXBu/FcrTXMAHBwspNLeSEF4i+tcka4u2yF06QQFGpsE /njMNLzQ==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-1p; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 08/29] ntsync: Introduce NTSYNC_IOC_MUTEX_KILL. Date: Tue, 30 Jan 2024 20:13:35 -0600 Message-ID: <20240131021356.10322-9-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571394618186956 X-GMAIL-MSGID: 1789571394618186956 This does not correspond to any NT syscall. Rather, when a thread dies, it should be called by the NT emulator for each mutex. NT mutexes are robust (in the pthread sense). When an NT thread dies, any mutexes it owned are immediately released. Acquisition of those mutexes by other threads will return a special value indicating that the mutex was abandoned, like EOWNERDEAD returned from pthread_mutex_lock(), and EOWNERDEAD is indeed used here for that purpose. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 71 +++++++++++++++++++++++++++++++++++-- include/uapi/linux/ntsync.h | 1 + 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 1770ec4008af..aadf01c65ca0 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -37,6 +37,7 @@ struct ntsync_obj { struct { __u32 count; __u32 owner; + bool ownerdead; } mutex; } u; @@ -89,6 +90,7 @@ struct ntsync_q { atomic_t signaled; bool all; + bool ownerdead; __u32 count; struct ntsync_q_entry entries[]; }; @@ -164,6 +166,9 @@ static void try_wake_all(struct ntsync_device *dev, struct ntsync_q *q, obj->u.sem.count--; break; case NTSYNC_TYPE_MUTEX: + if (obj->u.mutex.ownerdead) + q->ownerdead = true; + obj->u.mutex.ownerdead = false; obj->u.mutex.count++; obj->u.mutex.owner = q->owner; break; @@ -223,6 +228,9 @@ static void try_wake_any_mutex(struct ntsync_obj *mutex) continue; if (atomic_cmpxchg(&q->signaled, -1, entry->index) == -1) { + if (mutex->u.mutex.ownerdead) + q->ownerdead = true; + mutex->u.mutex.ownerdead = false; mutex->u.mutex.count++; mutex->u.mutex.owner = q->owner; wake_up_process(q->task); @@ -352,6 +360,62 @@ static int ntsync_mutex_unlock(struct ntsync_obj *mutex, void __user *argp) return ret; } +/* + * Actually change the mutex state to mark its owner as dead, + * returning -EPERM if not the owner. + */ +static int kill_mutex_state(struct ntsync_obj *mutex, __u32 owner) +{ + lockdep_assert_held(&mutex->lock); + + if (mutex->u.mutex.owner != owner) + return -EPERM; + + mutex->u.mutex.ownerdead = true; + mutex->u.mutex.owner = 0; + mutex->u.mutex.count = 0; + return 0; +} + +static int ntsync_mutex_kill(struct ntsync_obj *mutex, void __user *argp) +{ + struct ntsync_device *dev = mutex->dev; + __u32 owner; + int ret; + + if (get_user(owner, (__u32 __user *)argp)) + return -EFAULT; + if (!owner) + return -EINVAL; + + if (mutex->type != NTSYNC_TYPE_MUTEX) + return -EINVAL; + + if (atomic_read(&mutex->all_hint) > 0) { + spin_lock(&dev->wait_all_lock); + spin_lock_nest_lock(&mutex->lock, &dev->wait_all_lock); + + ret = kill_mutex_state(mutex, owner); + if (!ret) { + try_wake_all_obj(dev, mutex); + try_wake_any_mutex(mutex); + } + + spin_unlock(&mutex->lock); + spin_unlock(&dev->wait_all_lock); + } else { + spin_lock(&mutex->lock); + + ret = kill_mutex_state(mutex, owner); + if (!ret) + try_wake_any_mutex(mutex); + + spin_unlock(&mutex->lock); + } + + return ret; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -373,6 +437,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, return ntsync_sem_post(obj, argp); case NTSYNC_IOC_MUTEX_UNLOCK: return ntsync_mutex_unlock(obj, argp); + case NTSYNC_IOC_MUTEX_KILL: + return ntsync_mutex_kill(obj, argp); default: return -ENOIOCTLCMD; } @@ -555,6 +621,7 @@ static int setup_wait(struct ntsync_device *dev, q->owner = args->owner; atomic_set(&q->signaled, -1); q->all = all; + q->ownerdead = false; q->count = count; for (i = 0; i < count; i++) { @@ -664,7 +731,7 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) struct ntsync_wait_args __user *user_args = argp; /* even if we caught a signal, we need to communicate success */ - ret = 0; + ret = q->ownerdead ? -EOWNERDEAD : 0; if (put_user(signaled, &user_args->index)) ret = -EFAULT; @@ -747,7 +814,7 @@ static int ntsync_wait_all(struct ntsync_device *dev, void __user *argp) struct ntsync_wait_args __user *user_args = argp; /* even if we caught a signal, we need to communicate success */ - ret = 0; + ret = q->ownerdead ? -EOWNERDEAD : 0; if (put_user(signaled, &user_args->index)) ret = -EFAULT; diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index a3f5f4f13798..3861397c6c2f 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -40,5 +40,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) #define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args) +#define NTSYNC_IOC_MUTEX_KILL _IOW ('N', 0x86, __u32) #endif From patchwork Wed Jan 31 02:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1634496dyb; Tue, 30 Jan 2024 18:46:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVkWkAJ8Fcd40jbeHl7ziKkQgmo/hfp4pWTAyZoXLzYMRaVv9kG9fIomjpyxd55qgSwMfI X-Received: by 2002:a17:906:52d0:b0:a35:9d66:1edc with SMTP id w16-20020a17090652d000b00a359d661edcmr146552ejn.16.1706669207080; Tue, 30 Jan 2024 18:46:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706669207; cv=pass; d=google.com; s=arc-20160816; b=WM+KDDjqpvXsSY+fihq0VnovccdfmiKnz5iW7X58QfT2ViZRTpPjROMz0RjvFkba49 8TI43PQsfU211k3zGweTUALZlvVydBHWg4GbmBc6KOFuH648vxBA2Zi+uHo9a7f7LiWv /p0rpKzJA9wAmLAv6PbsA62c+JnMkb54fsZM+mFz+/t5ZHIIbVgNWRXq0EcTjQNEtQbh kuXZsaoZgETpueHROg5xDIaJSeW+8lBEAeJsGtE9m2tQ/DgC5aj4n5s4igjkrXgi/qpp M5+EJQ4fbi1UuYNVqbxw2SNOnklWS75K+IxQba3j28KZH/SCtzrdr6UXltCRAs5VPHMN Ij4w== 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=HS6PtwBEYnMbEyDHfMfm+haurykzLQrGztmH0knaKOk=; fh=np3JW8phJTiFuuv6P7xHsuvWcP/mXBVoIXC5HPxnmLc=; b=Zvser5+Yghp10uhwNyPpCV7tBUaW+BeGPQgCTCkjwSr4flk1BNQ7HY4MkXi3gdNTOF 9Kzc/Ku0wycXBzy9FLJVB522n+AdgPuee8YdjFXiwGOnA40MCR5O8CWYB1qa14NOLU5u 3KCXnh6+7812NDIHKbo7uvP65psagsPXpqCKz8tiHrqV3etwC1Fk5w3VtL8nqmg9xEcF eP3M1w8fZ1SDIYa0/Nx2yAKirQNmyRdDFcUgrKFUlwD82DVD6fMVNx6FXoRxrm06iGo1 wx8oOJ1ZxSiIlsTEHBTIxdU+tHNkYpVvGC/Wgk0T114JoEs1YYmRWDB2bhoidRVa1nX1 0Ztg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=gEa9sXxl; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVy4jeOjdGTjp1kgisS8DCBJnkyy86PGjAVcT4QnuuFWxUk3mgtx4lRZJ/vAj3VZZUSljnWSX0AW1b3men5VdmpVTRmDQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id zn6-20020a170906ff0600b00a349982a383si5366799ejb.751.2024.01.30.18.46.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:46:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45651-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=gEa9sXxl; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 2AAC01F2A35F for ; Wed, 31 Jan 2024 02:23:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAA973D986; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="gEa9sXxl" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 E6134611E; Wed, 31 Jan 2024 02:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=UFkv/XmuqldLcTG+m6jCceAv0VBnDDdq+DsA/tHKrGuuDh8a2d5dXfwwDPQpjPdFg0O8vSuYSY+kcKHkehFhns/Nk27+tywd9ayyC2A6yppd8O9YvyR/xyntPZN9i8DAaEy4mAaph4u1TFApBvdyT+ZyHkc4NT+P7+498IzyXVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=feJuxpVrTwo1GvHucwKxw2fqfjt5D1lZlxuvTgsLJjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V8GKbYaS0ldFRSnQqdtHew5dHFHvFo3nBHdx76EECwhPRO5eICAtLBnzKDCRshqJW0sdzoTdHsiEubGPq1xNPbNPtXd5183XfM6TGtWr0K2/lFV03IWWR/H+Rvfpf2uyo4sYKl7SXaqDE1rpBnpnPQdfJ2BI8F/QJfoHwhelk34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=gEa9sXxl; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=HS6PtwBEYnMbEyDHfMfm+haurykzLQrGztmH0knaKOk=; b=gEa9sXxleRrt2Az8HkSJ5nrhoH HBWRy76hH5pSS8rzaX+986qDARhLdT4BZNGj80EFXtw/EsyLCjgNThmRmZ27aunkulnaqkGyQul5Y ZvV0jXVPG7fq/ROfupXxOG0YVx1xhnnamzFc5wy/QhUP2Tiv6QaA/SrZgb/b+aZOR3iybPcrtFGpd 6qKE5ZMLRfBkBc98QBuX/g4Yv8lBNBvB4NKGuENQNTSNOVTeO8n17IPnpwBpVVt5nBySFjkCYRdCw Z9yXlsl88fRGspIR98ahUw4yAJCL45OWwgxPnbn3DAjOLAzyGhox7aFH8b0nglhuGtxB0qtjD5zXC 7jgo6pXw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-2K; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 09/29] ntsync: Introduce NTSYNC_IOC_CREATE_EVENT. Date: Tue, 30 Jan 2024 20:13:36 -0600 Message-ID: <20240131021356.10322-10-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572370977514789 X-GMAIL-MSGID: 1789572370977514789 This correspond to the NT syscall NtCreateEvent(). An NT event holds a single bit of state denoting whether it is signaled or unsignaled. There are two types of events: manual-reset and automatic-reset. When an automatic-reset event is acquired via a wait function, its state is reset to unsignaled. Manual-reset events are not affected by wait functions. Whether the event is manual-reset, and its initial state, are specified at creation time. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 60 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 7 +++++ 2 files changed, 67 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index aadf01c65ca0..c719ddd9f6d7 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -18,6 +18,7 @@ enum ntsync_type { NTSYNC_TYPE_SEM, NTSYNC_TYPE_MUTEX, + NTSYNC_TYPE_EVENT, }; struct ntsync_obj { @@ -39,6 +40,10 @@ struct ntsync_obj { __u32 owner; bool ownerdead; } mutex; + struct { + bool manual; + bool signaled; + } event; } u; /* @@ -123,6 +128,8 @@ static bool is_signaled(struct ntsync_obj *obj, __u32 owner) if (obj->u.mutex.owner && obj->u.mutex.owner != owner) return false; return obj->u.mutex.count < UINT_MAX; + case NTSYNC_TYPE_EVENT: + return obj->u.event.signaled; } WARN(1, "bad object type %#x\n", obj->type); @@ -172,6 +179,10 @@ static void try_wake_all(struct ntsync_device *dev, struct ntsync_q *q, obj->u.mutex.count++; obj->u.mutex.owner = q->owner; break; + case NTSYNC_TYPE_EVENT: + if (!obj->u.event.manual) + obj->u.event.signaled = false; + break; } } wake_up_process(q->task); @@ -238,6 +249,26 @@ static void try_wake_any_mutex(struct ntsync_obj *mutex) } } +static void try_wake_any_event(struct ntsync_obj *event) +{ + struct ntsync_q_entry *entry; + + lockdep_assert_held(&event->lock); + + list_for_each_entry(entry, &event->any_waiters, node) { + struct ntsync_q *q = entry->q; + + if (!event->u.event.signaled) + break; + + if (atomic_cmpxchg(&q->signaled, -1, entry->index) == -1) { + if (!event->u.event.manual) + event->u.event.signaled = false; + wake_up_process(q->task); + } + } +} + /* * Actually change the semaphore state, returning -EOVERFLOW if it is made * invalid. @@ -544,6 +575,30 @@ static int ntsync_create_mutex(struct ntsync_device *dev, void __user *argp) return put_user(fd, &user_args->mutex); } +static int ntsync_create_event(struct ntsync_device *dev, void __user *argp) +{ + struct ntsync_event_args __user *user_args = argp; + struct ntsync_event_args args; + struct ntsync_obj *event; + int fd; + + if (copy_from_user(&args, argp, sizeof(args))) + return -EFAULT; + + event = ntsync_alloc_obj(dev, NTSYNC_TYPE_EVENT); + if (!event) + return -ENOMEM; + event->u.event.manual = args.manual; + event->u.event.signaled = args.signaled; + fd = ntsync_obj_get_fd(event); + if (fd < 0) { + kfree(event); + return fd; + } + + return put_user(fd, &user_args->event); +} + static struct ntsync_obj *get_obj(struct ntsync_device *dev, int fd) { struct file *file = fget(fd); @@ -665,6 +720,9 @@ static void try_wake_any_obj(struct ntsync_obj *obj) case NTSYNC_TYPE_MUTEX: try_wake_any_mutex(obj); break; + case NTSYNC_TYPE_EVENT: + try_wake_any_event(obj); + break; } } @@ -857,6 +915,8 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, void __user *argp = (void __user *)parm; switch (cmd) { + case NTSYNC_IOC_CREATE_EVENT: + return ntsync_create_event(dev, argp); case NTSYNC_IOC_CREATE_MUTEX: return ntsync_create_mutex(dev, argp); case NTSYNC_IOC_CREATE_SEM: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 3861397c6c2f..b8cf503365ef 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -22,6 +22,12 @@ struct ntsync_mutex_args { __u32 count; }; +struct ntsync_event_args { + __u32 event; + __u32 manual; + __u32 signaled; +}; + struct ntsync_wait_args { __u64 timeout; __u64 objs; @@ -37,6 +43,7 @@ struct ntsync_wait_args { #define NTSYNC_IOC_WAIT_ANY _IOWR('N', 0x82, struct ntsync_wait_args) #define NTSYNC_IOC_WAIT_ALL _IOWR('N', 0x83, struct ntsync_wait_args) #define NTSYNC_IOC_CREATE_MUTEX _IOWR('N', 0x84, struct ntsync_sem_args) +#define NTSYNC_IOC_CREATE_EVENT _IOWR('N', 0x87, struct ntsync_event_args) #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) #define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args) From patchwork Wed Jan 31 02:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626162dyb; Tue, 30 Jan 2024 18:20:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo37798b0jQilXOkgYGnrLaL8R/cQ4RhQJ2geuLSGr84cfrj9+sXNdMe9tYXnfymjYCg+8 X-Received: by 2002:a05:6808:3085:b0:3be:bcd3:b007 with SMTP id bl5-20020a056808308500b003bebcd3b007mr403999oib.0.1706667600204; Tue, 30 Jan 2024 18:20:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667600; cv=pass; d=google.com; s=arc-20160816; b=qJs0CTlQrOHC9mbaMbYomcSKv1mdb7ETprB2l4PM+V6J10PPMM6mh/wGrHdUtNLZer 8tt8wVn0dRRYoSQBdsMpEjoe9LLcIuJC94Q1v3diNEYDV5AsKoCwQ/w6Bn8CJYJji7FY YlL2QG/oz0NbJl1DVE3LHyJAvjdqUGQB7AWh1hli+3GFKoIYXH1plP6cVlXJT4govwt+ ORiWqw3Vgl587hK8HcEh+K63uDNSxa7xP/6c1wfDpgh01HggEtfEl3vJN5l07/fDAf1u mCpuyg9TUJ2AofjtFydzPhOcheq8QSSRrXGnGjYk3oNPdj28IQMpS5YpZizC+ld8Lu6A mTtw== 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=Sv1UBqSdU6l/6/nEOSf6bUGNGonnKGWUzciaQ82gPQo=; fh=IXrq/9Cwx92x6aFeFciOgYABVt9hQq4+bYvjlFY+Ex4=; b=PS4oPUmZ7RLwJY2XIer0wtht0GrRmJ8IZh44rachVxp3fU1b2DN2NZ2e7VFPTZMF6K YpSnFFHRnGDGtCrwvoFtjvhEzq2AyMeiWhZWLC6EDehG4ALkGVro+MZ7gXgdcQZas6od PhvE1lCMnsJPVf6gXESpSb2/aUG890i0jXWT5rIz6wnk/xpF2CpuuMy9ZM98t5pKJ4Al nygF9eBbhi2iBswEr343yDy+85nRs6NAnKJwKalvyPwb9fe57gm8Qd8bbhHxJDmbCBqA Yv/CNWP8KPb0n+HtqhNedB8l9f7ZWmWNlW4CU5+mEOTS4IZpG6xzI9ZM7CaEvbinAcTt 5wIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=aFCpal0D; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUUs5nMTvDXWNTcO6Y8BmN/jC7O4uEqpaqWjQBpIxBlsbQFuP/qiygi+W/4dfMj7xOw/j6SyzcbKnyFaKPlWD2ntwSESg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z5-20020a6552c5000000b005d8e36d9e11si2267168pgp.149.2024.01.30.18.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:20:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=aFCpal0D; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7B78828367E for ; Wed, 31 Jan 2024 02:19:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E58239FFF; Wed, 31 Jan 2024 02:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="aFCpal0D" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 962A05663; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=Dtu6w1oNlkoXj5GeoeDbf9fyI7/4a8s71xNH8SOKgmptVm57vNyRRcgiGzBQS7P4lopekNSE8z9j6hHZR4IEAlBt3YmFoI5K1AjZqgoudcAXE9i3/iAHiQYNzLHwJ9NlEwWZcPAlFANizP+QuYvQWzZwWu6AF1OOaP9wpjZ8Scs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=H5jdJoivK98burrP8xFN4UKk2ngubL7t2Klv7uTHt/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCInXXZre0KNBwz+5Y8x9QcTILPDUCshcAQ3zbNX6RfgK+vFZmRbOnMIcbfjA3GDNg72jiFqWFXuozQHnFJWJTn0z/pgcqJNRFEKKqxZedNCkvl1rgqV2fKgH4EpUPpkdY3jYkbYRZOIDeEHcqgYSYBbWhAC/j1vWk3sfG/IEI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=aFCpal0D; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=Sv1UBqSdU6l/6/nEOSf6bUGNGonnKGWUzciaQ82gPQo=; b=aFCpal0DxG3QwuWB7FE2qo+bBU VgYKfDLIIoB2SPWPAwTgvMa5xG04P2vtU203k0XbJ+mr48iKZpuFGuEsyPb9Bc8b0qaEbVCeM9dO2 e7EF1v3hu1z2K5XYQL8Gc/zrh3k79yNRhbZsJZfCDUoVmJemaeiSi07cSx2BCxdjoD3C5xe1YqkHl Wldb/7uO9D/91/2e4gxwPbz/UoLt3jb2baXibB7Hk9WYsHwK9TkObELGaGCK1V/Nq53BUJK5n2vZJ GYZrsWxvsTYZrGtanAX7ASyt7M8MqRhj5lUiMSpReqs2eJbV9bd59nlI6dQ8XvCgHFL2xDICddmwu lfC+vPtA==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-2f; Tue, 30 Jan 2024 20:15:53 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 10/29] ntsync: Introduce NTSYNC_IOC_EVENT_SET. Date: Tue, 30 Jan 2024 20:13:37 -0600 Message-ID: <20240131021356.10322-11-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570685266554170 X-GMAIL-MSGID: 1789570685266554170 This corresponds to the NT syscall NtSetEvent(). This sets the event to the signaled state, and returns its previous state. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 37 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index c719ddd9f6d7..b2da50989953 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -447,6 +447,41 @@ static int ntsync_mutex_kill(struct ntsync_obj *mutex, void __user *argp) return ret; } +static int ntsync_event_set(struct ntsync_obj *event, void __user *argp) +{ + struct ntsync_device *dev = event->dev; + __u32 prev_state; + + if (event->type != NTSYNC_TYPE_EVENT) + return -EINVAL; + + if (atomic_read(&event->all_hint) > 0) { + spin_lock(&dev->wait_all_lock); + spin_lock_nest_lock(&event->lock, &dev->wait_all_lock); + + prev_state = event->u.event.signaled; + event->u.event.signaled = true; + try_wake_all_obj(dev, event); + try_wake_any_event(event); + + spin_unlock(&event->lock); + spin_unlock(&dev->wait_all_lock); + } else { + spin_lock(&event->lock); + + prev_state = event->u.event.signaled; + event->u.event.signaled = true; + try_wake_any_event(event); + + spin_unlock(&event->lock); + } + + if (put_user(prev_state, (__u32 __user *)argp)) + return -EFAULT; + + return 0; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -470,6 +505,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, return ntsync_mutex_unlock(obj, argp); case NTSYNC_IOC_MUTEX_KILL: return ntsync_mutex_kill(obj, argp); + case NTSYNC_IOC_EVENT_SET: + return ntsync_event_set(obj, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index b8cf503365ef..782057552483 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -48,5 +48,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_SEM_POST _IOWR('N', 0x81, __u32) #define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args) #define NTSYNC_IOC_MUTEX_KILL _IOW ('N', 0x86, __u32) +#define NTSYNC_IOC_EVENT_SET _IOR ('N', 0x88, __u32) #endif From patchwork Wed Jan 31 02:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625510dyb; Tue, 30 Jan 2024 18:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IE97Q+vDd57XvfO9rJ8m/LjFgbDxZLwrCOknqp5RiulKMD5viCw5IciH7vyPdrYYutDP8Ag X-Received: by 2002:aa7:d716:0:b0:55e:eaee:ddb4 with SMTP id t22-20020aa7d716000000b0055eeaeeddb4mr97121edq.9.1706667474628; Tue, 30 Jan 2024 18:17:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667474; cv=pass; d=google.com; s=arc-20160816; b=Tvf+BOPK0XMdlv8njNZ4104DAxnGXnK7QjqKYIcf7MarRVIJxfQ3P2a9wvcq9UDnhP YXNIUGtVY7crdx1NKlB++7NtVjwIWfu2+WuqrQjSmceXm6GODq5A1BV9beGFLtZQJmbT JiQjhDyhUDOLaVGT0nG4DuoY8E5KwPypBfUibBTyp626mlKcxCgGKikkz2G1k/zPKcbp 62g6oiCZQrPasw2721OQJrvqdCWux/T5eM1WgM4bEhYL3IzUrGBCadh0kF8Z+G4NzeFi /yqQfnAiguJ5FnqLsbB5y/bHHvGiinKrtDzdcz/BaP5i1/ZMBMYIM/FnUp2TfK8yoENs f+cg== 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=Bu0ZiIo7Hs1vPWly90g3amII2kYFsaEWUlUodmN8Ds0=; fh=9bPTZk6dueRuPO3ksh12t3MPKbw4iLDb40E3msRsBHM=; b=r7ZJHd+WQedIFpBzexR97VoHryhsXpOpaPfoYI7eUyXfnjK2zOkg+/vLGkDAAN39l9 RPvpBGBW4W/fmh9IgIFb1cRCwgV6C291fgiMYckEHdefgAE9SVvCDH0lluozpkr3lCHA +qgHoWj0bftJestjJ5VqPJXWY1icLl0x8z+GJkO9FiIDThGEiA4tNjNm9//HVHSsPo+c YVrP+t5sG4+FR9wn2B05ucJDAmj+5uDp/Cj3X83+sbxMwrGh/JHHHH+WP0Wgk1IMvbh3 GiR8XeQsQo0/aTEXYpxE5EgrPNTcLoVlyKgNqF/rKyoIGw+iUszWxZFPI5KvPX3A8t9s 9o0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=j46SZs9h; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWKl7VnlUeJ2PdfrXcfbs4F7xhLF0ka/NZi1pyX9/EQutbu4NahLikS8iU9xuFXB4vKK9xtlsk+QCXago3txTBi/2AX+w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l10-20020a056402124a00b0055f0078ad56si2534546edw.397.2024.01.30.18.17.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:17:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45631-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=j46SZs9h; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 40A351F23789 for ; Wed, 31 Jan 2024 02:17:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E866936AEF; Wed, 31 Jan 2024 02:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="j46SZs9h" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9600E5258; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667365; cv=none; b=Zj/VAjrdX4lh3kZSQxc8PgRNJ65dXyvrYgCSeLDzvCvMHyq2osjDznZHTLa4xc2ljrLy/kP/ztYANdwAiY8dC5FKDZg7d8WFpPiAppp3x78Hns6T8e8XbkYy7E4QsP+EQN/6zy/DZJgcF0hB3crc77c0+ycMN17WMglJBf+hKRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667365; c=relaxed/simple; bh=2odIObPUB+D6zv4g+F9ZVLeovm0W2e6pr8HGw+xbkuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GN6tJ3E+t7HheCsjRy9qYkiVuHJb2Xq5mqjy9cPP4jEap/sClO0U5YcAFqI8MDQdzJ1lHSnIkZnkiItjEgdBTfyVdV0MJt7HXIeOFpkOv9BzzvfQYTWEGiBAvxw+XpQmaGz78zCTs3BFd4xoFc9fy2ia3K6rCy9fipOKataxQRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=j46SZs9h; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=Bu0ZiIo7Hs1vPWly90g3amII2kYFsaEWUlUodmN8Ds0=; b=j46SZs9homq/UDMpGZ5FPOXWd7 BWj7ilgWch/meWOIb77O4Gt9ic5h2vh0oAYO0RKKw3YJr6s4xcXbNBhmPt3kvZX2g1j+iptDH5vfh mRkDNln26e240cmIgJOlOBvI3ezuFczhN9VBqcGRh9W95FCtQmHtlbK9Pio+/FrhUkxbXUnrQIbFL S0dZz2anXZsGa/utyQAV7UulNUJ1OAxUqH+VruNsFoflwz3u6okQUk0ts1rbRAXgjA+GnOpFdMRdo 5pxBGKPz52A7n95KOw7l9tmySRjdGq/WC3pBvED5FtSbZjZyO8ah1tt7AVf7tceMIZSVXE45VIgF7 7AoRwgvw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08n-0038Kv-38; Tue, 30 Jan 2024 20:15:54 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 11/29] ntsync: Introduce NTSYNC_IOC_EVENT_RESET. Date: Tue, 30 Jan 2024 20:13:38 -0600 Message-ID: <20240131021356.10322-12-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570553866108710 X-GMAIL-MSGID: 1789570553866108710 This corresponds to the NT syscall NtResetEvent(). This sets the event to the unsignaled state, and returns its previous state. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 22 ++++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index b2da50989953..009d927739b8 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -482,6 +482,26 @@ static int ntsync_event_set(struct ntsync_obj *event, void __user *argp) return 0; } +static int ntsync_event_reset(struct ntsync_obj *event, void __user *argp) +{ + __u32 prev_state; + + if (event->type != NTSYNC_TYPE_EVENT) + return -EINVAL; + + spin_lock(&event->lock); + + prev_state = event->u.event.signaled; + event->u.event.signaled = false; + + spin_unlock(&event->lock); + + if (put_user(prev_state, (__u32 __user *)argp)) + return -EFAULT; + + return 0; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -507,6 +527,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, return ntsync_mutex_kill(obj, argp); case NTSYNC_IOC_EVENT_SET: return ntsync_event_set(obj, argp); + case NTSYNC_IOC_EVENT_RESET: + return ntsync_event_reset(obj, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 782057552483..f2d7507d8438 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -49,5 +49,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_MUTEX_UNLOCK _IOWR('N', 0x85, struct ntsync_mutex_args) #define NTSYNC_IOC_MUTEX_KILL _IOW ('N', 0x86, __u32) #define NTSYNC_IOC_EVENT_SET _IOR ('N', 0x88, __u32) +#define NTSYNC_IOC_EVENT_RESET _IOR ('N', 0x89, __u32) #endif From patchwork Wed Jan 31 02:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194456 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628920dyb; Tue, 30 Jan 2024 18:28:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOKx8Fq8IsI90Cb7FhIml2ea3AovEQcT7+zrmb4n9/kjxGYin6Lhb55vijZke70BzerwZA X-Received: by 2002:a17:903:2302:b0:1d8:e771:c40a with SMTP id d2-20020a170903230200b001d8e771c40amr481225plh.14.1706668136801; Tue, 30 Jan 2024 18:28:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668136; cv=pass; d=google.com; s=arc-20160816; b=CkOMh1mrZhmMIGp9a44L4XpGlGJyE7jePnJd+SYUj4KlwX+6TKL/Z/OqotGM8Fzo0P hf2vT4UJHwOs86gPWlQ6oKamr5jVn0r/NKidgd/1kZ4HWY8GDtR1giFfGIsm//+9r2qA /GneMDfpAfGaZHy2VfZj56ey7N+RUz8VVg5WeoiawJAfZ4tM1IHdXeC9CDqT7sobLtYo mdgehsJkE9C9HF81wyEHGvpyMLZQI/0vTeWZ/YrihFukNCi3MdwxFMNuLMHPuGEaYct4 ZGYI8cHPZhIdkuUDPkFFERyVuXYxgF2X8Fnarqxdk9MCOXQ90q7J9fexSgTxk1EXJvdw P7cQ== 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=WRk28nnebpEDG8oEow/kRhN8Lt9f1MHcVAwX3iEhD18=; fh=KMGYaisZbbuGkU8PiFXHZLiwtSR16nbny0wD3HRg9DA=; b=CHaukQ0DuK1EoMnRn2fMUg6xOZpAW2q9Hj6ejwBz0RKytdjNsDUr1u+6QfkCJg3HZZ m/+p5VcQEsUyGoA3zO6xkhG9AFs8isU1LuTCoGLb42A/WaITxLq1j5dIICPqLh6EEK1F wDWNqho960f1YYhk26Df3TAx/iMDKT32MxxuSZtQlxRz2xk1XS5rZtUVmBHzHViit/iy +3C4t4tVJuh6YXKJ3KEUN6ucLvxv/Yk+/JIS1A8MRn9kfeKffgyJKhPo+dJgvEaAi1Lw Gc4YBZ6GiEF2ZYoY2eA2HZ6nIwtX5o8//usv7TXE1GRcNpAZ41oPNKfblXk1qudfQAnD 6+Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=cGd8qBhZ; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45659-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVTNw3GpLQGjSD/CpwXIjPWi4cgA38/pNuf0j3UcB05VJd+KZBJNKBLn6GUAyvOqWXUMUzm7Xy2JA07NE+2iczhwOA2Sw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f2-20020a170902ce8200b001d75d88f9a0si8554422plg.466.2024.01.30.18.28.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=cGd8qBhZ; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45659-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45659-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C52CFB26F62 for ; Wed, 31 Jan 2024 02:23:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D43F3E470; Wed, 31 Jan 2024 02:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="cGd8qBhZ" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9673B5684; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; cv=none; b=dNSWOSW9+NSGAG0lHvJTbBGTyuLbQWCmY48BWRnwQQLw6CnL/JmJRQQ1s8yM12+xsX5JfesgBQP/xkJ37eGBMnRzMgQHUBCwzAWKSsPoy7rQg+Hb/iJQ0rSHtXt0fIExpA+CUN1GMQXDmRxKro+JtatNmjd0l/DnxGLVqfwxOl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; c=relaxed/simple; bh=hMJdmUKFkzno0ji8YpHS/pTDnN+SSVTCS/COoDL60fA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0DQoUu4ONfr246CUyFXllTJt55e4jHG+a8Iv8p38D9NlZTEJlVEuRrjacjOyj/J04xW3e47bszp9TO3GbpK6y1/g8Si4Ooj9xzZeBNNhAPVhFqOgtVmCmCTsRyrYmtNZGuCnl7Eivq6ZnbzFKdxBItTCj7Bs4aW9JuydjdPODU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=cGd8qBhZ; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=WRk28nnebpEDG8oEow/kRhN8Lt9f1MHcVAwX3iEhD18=; b=cGd8qBhZDagdmZQ+X2glRs5nfU Q5ih2Dm2wM0UtHrDeoXrMVb7Xwsv941ueKGPsMxFzgLUTFBnQHqALtbJDFZJJZAS8dikbRTQIvNj+ zHgd68xeIF8AF9Fke5W8wjGsVf84dCqgFTmRA5k3pm/pJWqeONOi+yQp1vHZheaKDcPTa5WOwCYrb 7FCOFONgURxnnIVkgmHPiTTZR7Xp5/qON9z19WrFdYp6u7K4kM/3zS+sTBt0/8jujstRe/8K37lci EkjToTagxoqBiq0xkJd5vc3iJj5E3IM47k0x0lJE1wZm1VMlPKs3dRbbtrjcT4eb/gwo1dGhQIxME jdiLKuHw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08o-0038Kv-0N; Tue, 30 Jan 2024 20:15:54 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 12/29] ntsync: Introduce NTSYNC_IOC_EVENT_PULSE. Date: Tue, 30 Jan 2024 20:13:39 -0600 Message-ID: <20240131021356.10322-13-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571248120283317 X-GMAIL-MSGID: 1789571248120283317 This corresponds to the NT syscall NtPulseEvent(). This wakes up any waiters as if the event had been set, but does not set the event, instead resetting it if it had been signalled. Thus, for a manual-reset event, all waiters are woken, whereas for an auto-reset event, at most one waiter is woken. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 10 ++++++++-- include/uapi/linux/ntsync.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 009d927739b8..240ae858fa96 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -447,7 +447,7 @@ static int ntsync_mutex_kill(struct ntsync_obj *mutex, void __user *argp) return ret; } -static int ntsync_event_set(struct ntsync_obj *event, void __user *argp) +static int ntsync_event_set(struct ntsync_obj *event, void __user *argp, bool pulse) { struct ntsync_device *dev = event->dev; __u32 prev_state; @@ -463,6 +463,8 @@ static int ntsync_event_set(struct ntsync_obj *event, void __user *argp) event->u.event.signaled = true; try_wake_all_obj(dev, event); try_wake_any_event(event); + if (pulse) + event->u.event.signaled = false; spin_unlock(&event->lock); spin_unlock(&dev->wait_all_lock); @@ -472,6 +474,8 @@ static int ntsync_event_set(struct ntsync_obj *event, void __user *argp) prev_state = event->u.event.signaled; event->u.event.signaled = true; try_wake_any_event(event); + if (pulse) + event->u.event.signaled = false; spin_unlock(&event->lock); } @@ -526,9 +530,11 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, case NTSYNC_IOC_MUTEX_KILL: return ntsync_mutex_kill(obj, argp); case NTSYNC_IOC_EVENT_SET: - return ntsync_event_set(obj, argp); + return ntsync_event_set(obj, argp, false); case NTSYNC_IOC_EVENT_RESET: return ntsync_event_reset(obj, argp); + case NTSYNC_IOC_EVENT_PULSE: + return ntsync_event_set(obj, argp, true); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index f2d7507d8438..598f894f868d 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -50,5 +50,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_MUTEX_KILL _IOW ('N', 0x86, __u32) #define NTSYNC_IOC_EVENT_SET _IOR ('N', 0x88, __u32) #define NTSYNC_IOC_EVENT_RESET _IOR ('N', 0x89, __u32) +#define NTSYNC_IOC_EVENT_PULSE _IOR ('N', 0x8a, __u32) #endif From patchwork Wed Jan 31 02:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1633314dyb; Tue, 30 Jan 2024 18:42:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGCZWcGtos8f4ZC1j6l5CjAIzR1p1/UIf4/uf+zsl1vfvbGryYlOPBfzTyOSaXbc1g8TOK X-Received: by 2002:a9d:5a10:0:b0:6e1:1437:8a45 with SMTP id v16-20020a9d5a10000000b006e114378a45mr248321oth.16.1706668954566; Tue, 30 Jan 2024 18:42:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668954; cv=pass; d=google.com; s=arc-20160816; b=zmjeMdbkOJakd+mb6XFTXdRsbKYh1n5jswxC4Uy1Hl8xvP3gQnp02ucFB8MsZ2G611 aJUQCQSRaKHPgN/ZdlXJPpRcBkvE+S/Vr2GGTY/ag9jN2P5DBGHJALhFdrLD0nW7UgPL n3Mm7sUkfpyEVocqRVKzNcmMqwyfqTuIdkZ0AvdYM2riUOjey5pkNQAXIK09/X6/Uq+X v5Sj96Pa+ttvlj/+9zv+l0epnxeDDal9Ck8FK2Puj4lwn44S85xq8Z54pUPzOJnolUay fP/m8vRls3zTBbDkCa6mYrjtdpHSezuZCYKspWqy5JWsWlF7WeRtZHPK8Grt6MVYYg/O pMsQ== 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=R39lGOqTNBMRXbRmwXOtAWXBwOD9NggROFCJWXViCO4=; fh=cY3Nfsrebs1N4FR0DlyBcN9JkrW7iKKwgXjcfVfirQM=; b=EyoBpb5ORFhng+i2E6j/pGf8daP5N0OFEPMMwUZ9RGYxUZl/7O0Kcp1lf9U4FIurtq n0Jw7vzi9NFfeyHs2oWTducNxbJVuGawXyKyO/CSqJpyoyfBydY6Fk3PyE2+Tj1hph8c 24pVZkFkBmUwmuUE5+m2Bp9U2EiTKrjakWc3dRtA6E29Qv2BK6VV0mQTmfoEsU7ohlRe tbyG9t5UXbK4WngwqklmdxSnOtCt4ZmI3zJsp3jY7t3IIxR28Va0QFF8nI4kpOG9nNwv oS+CHUnrWzdpsht5qXaOmypDr0WftwxK39vM7790e5cfkdjKq+LQl6gdiCBwd82i+NeU Zc1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="b/wDzQH6"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45648-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45648-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWph/i3FwXpXX7mwuIwMXTYbadalyiWk/nLoqXw/rTQ54cFKh+jJInZfp139djQaJf0LlRx0kYrLRfPDGtQ8hFVRCtAlQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j186-20020a638bc3000000b005b96af23fe6si8533031pge.284.2024.01.30.18.42.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:42:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45648-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="b/wDzQH6"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45648-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45648-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B44A428C774 for ; Wed, 31 Jan 2024 02:22:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 867843D3A5; Wed, 31 Jan 2024 02:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="b/wDzQH6" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 961D05394; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=SKS+kiLgsNDXrMECF40owruN6ivU3pJIOnYkR4Ii0Mv36xnEjtOLBA5Yw49nfW1SWVIP89lwAmmIC3IPCGMydUIqKPO2M7UcRH3e8fVUSoukRzIVR503HMZsiMs4FThBrLGJQo8Rl89Ek8jwhykn4sa0Ws1tRnN5YEoIjFufWG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=HCJDXrbbClLe54itl4O3me4eGm27hgSAHGhToE6sjJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TMSkGJpPyqfaY/LD//lwg5hjR3/Fey7Y5sXE18a171cBns6MNjzJbAXONZ+7LEmtf8TXQn9QNpNsPInEa7TRbD4MX/sbixe1AViKA9fg6Q5YNvfA51/639O5hAl4bzlb9q59FDAiOuEe3o5OdIFV8Y4LUAB92VPWnXmfljOUN0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=b/wDzQH6; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=R39lGOqTNBMRXbRmwXOtAWXBwOD9NggROFCJWXViCO4=; b=b/wDzQH6Mzut/tAITEPLUTaKVE k9IamG8XOeeE3ntHS0bXtYmBvDn97GUEB/LVGXkFeCg0/6Rzb2j+YrUrg1+RUD2pskQOLaGMKA775 hjqKMmHp/Z15IzDSmXc9Hd16oW8zqJxgwF3fS7cVoeppiyvFvclwsfBUo2IykJkzjoxmVchrLxyaM Ds3s6WMIULYiGME82YQS/MHw/rqV236Z/EhhefrGN63zbwnhhtN+kllp/K1EZh8RXU+5Fo19E+W7+ jXAbN2VLiPjFRxpwvHjMccMdMbO/iVZrsND7y3hWzSDk+iP9Wiz2bXQRhyRheboNYWLmI2SRMdJfp yRew08zw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08o-0038Kv-0p; Tue, 30 Jan 2024 20:15:54 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 13/29] ntsync: Introduce NTSYNC_IOC_SEM_READ. Date: Tue, 30 Jan 2024 20:13:40 -0600 Message-ID: <20240131021356.10322-14-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572105311063863 X-GMAIL-MSGID: 1789572105311063863 This corresponds to the NT syscall NtQuerySemaphore(). This returns the current count and maximum count of the semaphore. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 21 +++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 240ae858fa96..6dccfbfb2512 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -506,6 +506,25 @@ static int ntsync_event_reset(struct ntsync_obj *event, void __user *argp) return 0; } +static int ntsync_sem_read(struct ntsync_obj *sem, void __user *argp) +{ + struct ntsync_sem_args __user *user_args = argp; + struct ntsync_sem_args args; + + if (sem->type != NTSYNC_TYPE_SEM) + return -EINVAL; + + args.sem = 0; + spin_lock(&sem->lock); + args.count = sem->u.sem.count; + args.max = sem->u.sem.max; + spin_unlock(&sem->lock); + + if (copy_to_user(user_args, &args, sizeof(args))) + return -EFAULT; + return 0; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -525,6 +544,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case NTSYNC_IOC_SEM_POST: return ntsync_sem_post(obj, argp); + case NTSYNC_IOC_SEM_READ: + return ntsync_sem_read(obj, argp); case NTSYNC_IOC_MUTEX_UNLOCK: return ntsync_mutex_unlock(obj, argp); case NTSYNC_IOC_MUTEX_KILL: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 598f894f868d..6017f621687e 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -51,5 +51,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_EVENT_SET _IOR ('N', 0x88, __u32) #define NTSYNC_IOC_EVENT_RESET _IOR ('N', 0x89, __u32) #define NTSYNC_IOC_EVENT_PULSE _IOR ('N', 0x8a, __u32) +#define NTSYNC_IOC_SEM_READ _IOR ('N', 0x8b, struct ntsync_sem_args) #endif From patchwork Wed Jan 31 02:13:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1633284dyb; Tue, 30 Jan 2024 18:42:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE97vnet3A4aNM33FKwpySzMO/l7Cj3ZJs+VXPxlgK/oLTAjoBuow1hIRnVqg3qW6yOiv7d X-Received: by 2002:a05:6830:410b:b0:6dc:455:e923 with SMTP id w11-20020a056830410b00b006dc0455e923mr329797ott.11.1706668946781; Tue, 30 Jan 2024 18:42:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668946; cv=pass; d=google.com; s=arc-20160816; b=nMpVqafzmm/OCE7TTBe8lg4HU+WYJMbD0xrmvuv45UfdpXYnyvbj6EUgScS5WZTgRi hoUUpE0Tgh0/kOewM95iJlKx1fp3bFCJM8FvTW95SqXoXwyiVZyinAzVptZPipQXkVOb dmUYk2XVIZ0hAjwljRT8U1CcgIJ/Wv5KDlOfs88AsCzeucwChwQo0h6OW55hY79ucKc+ POdFecV9yLoxMM7mHg1Ria4IQyEoFD1cgS35dPxqBZNB2nFrobKtR4s0z6ahSAmegutE NcBO7OZseSqPFAC3Rd0QfZMVCrii6PJg5tPKnP0J4Ts04YYWjf9YpKc/ufMaF5YP8XuA 80wg== 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=1xZgCEZhzxRQI2+IlVlEkSHYGEMNkBdz9sAcroCJGdM=; fh=0Ix+ooFxNwgDpjVaY5bIObqYgpgJQJpsIMVG2lMcvoc=; b=z7OS8d+NM/gBdZl+dHIyd/hP71kPHMwWCxTmjxw+mHdwU4NbiD8vSYXsphxCmTpyjt GuBDu1n5NhesWAPOlrQCjCGGEXafCgLqFow2Y11IjV2sjJWfCaBXV58sRnR+Z7HrOu9D 1fex0aMkgMuaCsSU/qprTTeB8nRLmy4quHYh44Dk8tQ4DSDfKgtTP9K3xcBtQGs4mKsL nGxI668EpWCMLNZlYPL+yUbOMvhFSgYUbrAKQOJMMRnGJqZM1haAnwHwX4ulrXCE4Bp7 krszopiL9F5vov1XNWqpHZWmkO4kt7opxg1wgHa9rJ95PLuVkLYuFLTeVm/y+JjLkGdB ktEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=lpcSbMyS; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45647-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45647-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXXyuA9PVjjffJZw6kuVb7T/eBnoAGXleZfRrfjTU2hjANitCIyxOjiW0sdEQamFxFfqdaJINbMR6B23WmSN/tQ62I4gw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l64-20020a639143000000b005cda184c288si5588648pge.212.2024.01.30.18.42.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:42:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45647-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=lpcSbMyS; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45647-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45647-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C45428643B for ; Wed, 31 Jan 2024 02:22:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DC073D0C2; Wed, 31 Jan 2024 02:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="lpcSbMyS" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9683F5695; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=hK578cHLBN6EfK5rHZoKdGCnJc4768hXHMSnqBUSW1F9XzYD5KoUgj+IZRV1dJYljK25jQA/BDs6L0SHGXr1QnxsJJmDhigxJPIhL0SagRQxGjZPFKcmid/5sr1B6sLVP2uVlCHOc9z/pZBYp/RlkFWr3skOfxYMij6CTmGLp5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=45PqITAzyzIslRj+cjwBpNV+ix/PAFx0emApGk3uvpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sah1QeBdl0myQ3L+AFrMOjlxrvTjC4IsC6Pvel0ej6Rhf/VqNxy2vc0sS6y4B4CNadhlAZ2Xs2jeYYQz3AELPEEM5HpGYphEGvDtNfwN8d0R72pbND92oIPiYkgqy3pOMb43v6VdNZ48Ro906fPKDCt7bAQt9F3598AILKP9+9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=lpcSbMyS; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=1xZgCEZhzxRQI2+IlVlEkSHYGEMNkBdz9sAcroCJGdM=; b=lpcSbMyScOJWYO4kppnSqPKmGr EaO+lS+KIQOmdcVEYpJhRwlbzFSwRvmRefH9Fu4PkQYiSvGYk8YjCnGnZY7Lv17eErv12Cfv90WWd hvjuvXbNYFBL/4iwGEDOyzmXQr9J8ueETNyZlebBoNEsjDHbqc6NPYMSh4Gv33j90DxtKMvyq5AvQ nodXk6X8k/+5YuU4/eSvBlWEYM7NXP4M3sge2THw9EusP0qE4qWiGdApUAXGvmAQHb1ym++iSfZtC CPzeuixY0bvojhKqwahga9gz42e2VJNF9LMAOu5+O13s96SF+CfQlQQ0pLtPsFJXa1z+m57sDXV6F 0hUjftJg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08o-0038Kv-1J; Tue, 30 Jan 2024 20:15:54 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 14/29] ntsync: Introduce NTSYNC_IOC_MUTEX_READ. Date: Tue, 30 Jan 2024 20:13:41 -0600 Message-ID: <20240131021356.10322-15-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572097599267579 X-GMAIL-MSGID: 1789572097599267579 This corresponds to the NT syscall NtQueryMutant(). This returns the recursion count, owner, and abandoned state of the mutex. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 23 +++++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 6dccfbfb2512..7f5f96ec7c69 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -525,6 +525,27 @@ static int ntsync_sem_read(struct ntsync_obj *sem, void __user *argp) return 0; } +static int ntsync_mutex_read(struct ntsync_obj *mutex, void __user *argp) +{ + struct ntsync_mutex_args __user *user_args = argp; + struct ntsync_mutex_args args; + int ret; + + if (mutex->type != NTSYNC_TYPE_MUTEX) + return -EINVAL; + + args.mutex = 0; + spin_lock(&mutex->lock); + args.count = mutex->u.mutex.count; + args.owner = mutex->u.mutex.owner; + ret = mutex->u.mutex.ownerdead ? -EOWNERDEAD : 0; + spin_unlock(&mutex->lock); + + if (copy_to_user(user_args, &args, sizeof(args))) + return -EFAULT; + return ret; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -550,6 +571,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, return ntsync_mutex_unlock(obj, argp); case NTSYNC_IOC_MUTEX_KILL: return ntsync_mutex_kill(obj, argp); + case NTSYNC_IOC_MUTEX_READ: + return ntsync_mutex_read(obj, argp); case NTSYNC_IOC_EVENT_SET: return ntsync_event_set(obj, argp, false); case NTSYNC_IOC_EVENT_RESET: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 6017f621687e..a1d0ef581212 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -52,5 +52,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_EVENT_RESET _IOR ('N', 0x89, __u32) #define NTSYNC_IOC_EVENT_PULSE _IOR ('N', 0x8a, __u32) #define NTSYNC_IOC_SEM_READ _IOR ('N', 0x8b, struct ntsync_sem_args) +#define NTSYNC_IOC_MUTEX_READ _IOR ('N', 0x8c, struct ntsync_mutex_args) #endif From patchwork Wed Jan 31 02:13:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1632858dyb; Tue, 30 Jan 2024 18:41:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGp5AG800MIllT9oenkpuYGTx+/AfI+t+vB75HIUVpkmjbu0EDViDv1vR0rOhjvfKA0me0s X-Received: by 2002:a17:906:1691:b0:a36:5dc3:ca2b with SMTP id s17-20020a170906169100b00a365dc3ca2bmr118133ejd.29.1706668873407; Tue, 30 Jan 2024 18:41:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668873; cv=pass; d=google.com; s=arc-20160816; b=MCSNYH9NOUupEm3OT7S0FzG6KY4N6sNHjsMgfsMBvwE27LOptrGhFIMP6WbKuh23vP 4dp9HpaZX4BNqtG5LLMjCNK2OKgaQGMUbdjNPAk65yBB3T0w1dQHK9njPk318+7t/XH6 XydYysSZTIFhh55r4MU0e6Y4G/nyJlWCZXgqwxZfLiNBm2zR1VSd5XJT3qgzV3SuWM4V Inspf3U0Ljm/1AG1MFdzvcR0BvnihLByJ8zbD7N2e3blBZwY5X15JbgTNhcST2YHnlks 1viUzXx4FATTjtw9grvif0t2w0xQ8Z7Tw5/zbfmWZRSjGFOGVL5bRroK8ajZNYXKA8wU 2TCw== 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=3BWgowJmtieQMddj1G2RVM2nAQyW8FCsxXFT7QNUe/k=; fh=zcXf/R86H7gRcNuU7Jg2SXr0F3e3mYjKjP2pbQdTKfw=; b=RjBBB/+iFS32BIIu2YTVmts7rb8Z/ld9l/dI7jYdEB7lM3yksOPpDLJ+tHgx6YGG1/ cIrMnu8Ju4p7C0D6URIvO7nKjNc+GBqcMrSiDWysBaIgcQC42ztpBcy5qnHvTdQknFEJ lPog29yJRUxawJpNdwXPrtNNl2MTx2fa01DyHMOjyDcijB9bWnUOPcZjZySCnt0B0/TR jyYWVq/nHxJk0TJFvyY1sKbAxeO1Cr6ClNMp06TSYoVEtBg4JuRkGLD/Ifq4wSoY8O+P 8b6DquCUw0+XCId1l23BwY2Ea7mUfxNzCcPFenmcidJX/a/7l0bYMPdv4ZPe0xXuQETo oncQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=XWTVmhZd; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45654-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXHiekWQcPNYRnaP2rds3AHk/wJ5bDJmLVaMmCLx2H8wmoKJ0RDPPiZC7PNZQowJpv99KsGMbSLBjkuLGcJDr76ypysXg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dx22-20020a170906a85600b00a3554a6b921si3582383ejb.107.2024.01.30.18.41.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:41:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45654-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=XWTVmhZd; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45654-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45654-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 D024D1F2A0B1 for ; Wed, 31 Jan 2024 02:23:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ED0E3D57C; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="XWTVmhZd" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 A85A75C99; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; cv=none; b=vGaTMFwfqFGM7U6X/oOXTJIhxs2Jnj6e9e9HGwq5b6uxdU5g1NNoaSCLLEOLTOgTs2n9/fa7o5BX03RxNwmQJiQyH5xRN6y1tPiDQD2EMd364UIaWgnmJh5JNpsDL90+Y4aNt6+Y+9aWMFT37v8xmwQSsAMi61q3a/fGxquZ9qI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; c=relaxed/simple; bh=LDrNxlhtoCwJ7k+stDb9MlrDauz5jYqNXZ6Ztjqd6Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jORs4zSx4g7j5X2qX2iJ3n6avJCAyn0VWzp8bTIyE6e2p9sRmoY92tnjiPJF1COxR9CDkHGigeur0ypGTqx2lGxw3DMLPGbs25/Uab23hEyK3pwE4mYyd4Uk9iSFsyB5rZjbKHU4BQJPYnFMgBzcYPqp62xCIY21PleadUxOkLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=XWTVmhZd; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=3BWgowJmtieQMddj1G2RVM2nAQyW8FCsxXFT7QNUe/k=; b=XWTVmhZds9SBkupWGR2zjPEjm6 W/lB98xH7Yzw76o1iyii7Bj75H1drp0bxTBD6AUoMIFHhf6TWFckjaUa695+xcaacvBkMxNIW5xfh Wp0R71zR1JuOrNBt1PgNAcyYtcytCR6zzIElZTaCrMmtCOPE+R6EkpvMQhD1tC/JenRkTe+kZmCM+ 3lcJ4OfJflbcjihV4gz5TSF66HcqMxKppf5jxQMwyMHJtA4G6Nd0hL3GG1xLG1eT0GqfG1aAW5nUG 4a4d/BoJQTy8sqZbxMaXIa69zHjktHldBE4YknXHVeCSmBnNalHdIz3iA56aA3PEAeqFg0J8V4wAA meAeF57w==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08o-0038Kv-34; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 15/29] ntsync: Introduce NTSYNC_IOC_EVENT_READ. Date: Tue, 30 Jan 2024 20:13:42 -0600 Message-ID: <20240131021356.10322-16-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572020907138670 X-GMAIL-MSGID: 1789572020907138670 This corresponds to the NT syscall NtQueryEvent(). This returns the signaled state of the event and whether it is manual-reset. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 21 +++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 7f5f96ec7c69..5439c1c9e90f 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -546,6 +546,25 @@ static int ntsync_mutex_read(struct ntsync_obj *mutex, void __user *argp) return ret; } +static int ntsync_event_read(struct ntsync_obj *event, void __user *argp) +{ + struct ntsync_event_args __user *user_args = argp; + struct ntsync_event_args args; + + if (event->type != NTSYNC_TYPE_EVENT) + return -EINVAL; + + args.event = 0; + spin_lock(&event->lock); + args.manual = event->u.event.manual; + args.signaled = event->u.event.signaled; + spin_unlock(&event->lock); + + if (copy_to_user(user_args, &args, sizeof(args))) + return -EFAULT; + return 0; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -579,6 +598,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, return ntsync_event_reset(obj, argp); case NTSYNC_IOC_EVENT_PULSE: return ntsync_event_set(obj, argp, true); + case NTSYNC_IOC_EVENT_READ: + return ntsync_event_read(obj, argp); default: return -ENOIOCTLCMD; } diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index a1d0ef581212..582d33b0dcac 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -53,5 +53,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_EVENT_PULSE _IOR ('N', 0x8a, __u32) #define NTSYNC_IOC_SEM_READ _IOR ('N', 0x8b, struct ntsync_sem_args) #define NTSYNC_IOC_MUTEX_READ _IOR ('N', 0x8c, struct ntsync_mutex_args) +#define NTSYNC_IOC_EVENT_READ _IOR ('N', 0x8d, struct ntsync_event_args) #endif From patchwork Wed Jan 31 02:13:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628884dyb; Tue, 30 Jan 2024 18:28:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4E2nubFazmYaU3wq6FIy9RNc2XGQ7BZbgX86WGgjRsskAV9ubg4lhnez9cPT52Lb8sA1Z X-Received: by 2002:a25:ef45:0:b0:dc6:9c4f:9e79 with SMTP id w5-20020a25ef45000000b00dc69c4f9e79mr425435ybm.38.1706668130117; Tue, 30 Jan 2024 18:28:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668130; cv=pass; d=google.com; s=arc-20160816; b=fz50+j6sYQOQmK/QV2HbW5+RzkFP4Is21Xf3NFdYXGPtVdH9c7fy0HcV5nJxTQxdGU o5J94oGEQAGh8E2VEDnR4cvWBePULKBqDyHY1ZT6ur1/gUgV0FwBY92ND+wTu90vC4f0 0oV9/+4ggPiIm3+KaIPHUe24Jo6cp1oRt9F2SyRLO+DJS7rjsSVt78yX96bsVf031OFn PkDu8sMlZmBD5bkWbQb7Ug+Da/fnX7X6yxMqzNwcPi/KVEq60VQ5BX2MZzRjHYDDgxZ6 K/LhJ1vU3pYy/dOtsN6buP2a5KBQb/9/s311MH9Nt3qZd7dlX/pEU3P7p4nklUCoxboY h8OQ== 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=64qfv1/cxBxKplo8j/wLrSClMN20SVON1cvxHlo6Xq0=; fh=uqXMSk9ovOFG7iKjSpuFhjxY2QwwLRU/tX61bulX/CU=; b=svTlG9UvQQQAcbpKWBRPd+v30ZSXrXDES1m8BPtv3yYcoAQ5/Dgcmg8Expje9eL67c sGlFGHJE8PIW2MUcWftF4ELm4JbQzYa8Tl0YjzBxSevOHObBaTgDpFHvTLOYXnrMvAIZ Q1YnhXcF55lH/FjYRVFz86jjbx8pOSNc21ED1wljdJ/N6oE3nnRT/tHTsu26Aw7gVOT2 3j7rbamYXzqznhCjoarUz/+mblFZUAVfJ8+oIs8ysZncV98s08JrdwnWLbo1OtxNFKrd K4Opk1O0i3FOoi7gDWv3oBps6fIG3BMZUMt3jyL0OYcGMfGS+1SpymxKNhGSM8oa8I+8 M4pw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="FPlQAZx/"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45657-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXuwIrd22kOZiA/6yzSsjtHi70mkmFpgiSdYfxIpXYcIw79ro/W/DObvNPgeq0gsrliVxjYM/AxMuUDYhBVcNpDADKmPQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b185-20020a6334c2000000b005d3a532f031si8504022pga.257.2024.01.30.18.28.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="FPlQAZx/"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45657-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C643CB26F06 for ; Wed, 31 Jan 2024 02:23:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 146233DBB3; Wed, 31 Jan 2024 02:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="FPlQAZx/" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 96120525D; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; cv=none; b=suahCm8j92zsH8crRtb8n+dsH7+jPbfUpYTTpAAloYcmBK1gJzNsUKnU7FiQh7Nat2GFELZhFbuUtQnkJit7zkjs1BpujqxK+XDFh/BbPB1UKOz8aGLQUaQXRgwkk2a1W6CU8iTiBfOviq18knKHm+kfBlM+uSVcQqpiPa0nKD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; c=relaxed/simple; bh=Az1dcn+diz6i5pAEU1GrHGwsdplurkEQ20tIVBYPOAQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=stKIxa34YzZY6yLbaJWkCRMJAcwl3W9Twi/VRJz+eM7z8s66z+PIDP2aR0mqWKYyfrO8v8f4Inq7iIva90vhTR4pIO0X2+kZ2dOikgwes4RMBJQDdwDzTvBRWLqXccg7myT4lwOcIJ1WGqCUazLwkCfRL6AxyO9bInzmmMP9O9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=FPlQAZx/; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=64qfv1/cxBxKplo8j/wLrSClMN20SVON1cvxHlo6Xq0=; b=FPlQAZx/WSwQH+Zw4WBTfgvqq6 4jneOXFEH1FliME/wNLgu/dEDzZ4Z6rhGaZpRJrtmYWdfW53GJofQlwpXc477irjYFcEk3LE8/sfO CwDVmS8VOh+870WkARUE7gdaP2VYW6KHnfoGvzt0uXKh6bdT1hFPAZ9Jrhq0RREsvITHcDBFPoRk0 mcSVskKEPkmXnix1iRkSnB7LhDIDoCMZ0qrh4Aan8PYH9inNBND3fUaoW629i8jjAxCOtFs094YW2 oIyz2ba4RosAcGB37HYDujY2WJMSpictYmZjUBMrzM2Toj+H/DYqiKq53S06wxhsXuUGP2B0PzZSk dxiTbGSw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-0Y; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 16/29] ntsync: Introduce alertable waits. Date: Tue, 30 Jan 2024 20:13:43 -0600 Message-ID: <20240131021356.10322-17-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571241133585715 X-GMAIL-MSGID: 1789571241133585715 NT waits can optionally be made "alertable". This is a special channel for thread wakeup that is mildly similar to SIGIO. A thread has an internal single bit of "alerted" state, and if a thread is made alerted while an alertable wait, the wait will return a special value, consume the "alerted" state, and will not consume any of its objects. Alerts are implemented using events; the user-space NT emulator is expected to create an internal ntsync event for each thread and pass that event to wait functions. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 68 ++++++++++++++++++++++++++++++++----- include/uapi/linux/ntsync.h | 2 +- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 5439c1c9e90f..1e619e1ce6a6 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -784,22 +784,29 @@ static int setup_wait(struct ntsync_device *dev, const struct ntsync_wait_args *args, bool all, struct ntsync_q **ret_q) { + int fds[NTSYNC_MAX_WAIT_COUNT + 1]; const __u32 count = args->count; - int fds[NTSYNC_MAX_WAIT_COUNT]; struct ntsync_q *q; + __u32 total_count; __u32 i, j; - if (!args->owner || args->pad) + if (!args->owner) return -EINVAL; if (args->count > NTSYNC_MAX_WAIT_COUNT) return -EINVAL; + total_count = count; + if (args->alert) + total_count++; + if (copy_from_user(fds, u64_to_user_ptr(args->objs), array_size(count, sizeof(*fds)))) return -EFAULT; + if (args->alert) + fds[count] = args->alert; - q = kmalloc(struct_size(q, entries, count), GFP_KERNEL); + q = kmalloc(struct_size(q, entries, total_count), GFP_KERNEL); if (!q) return -ENOMEM; q->task = current; @@ -809,7 +816,7 @@ static int setup_wait(struct ntsync_device *dev, q->ownerdead = false; q->count = count; - for (i = 0; i < count; i++) { + for (i = 0; i < total_count; i++) { struct ntsync_q_entry *entry = &q->entries[i]; struct ntsync_obj *obj = get_obj(dev, fds[i]); @@ -860,9 +867,9 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) { struct ntsync_wait_args args; struct ntsync_q *q; + __u32 i, total_count; ktime_t timeout; int signaled; - __u32 i; int ret; if (copy_from_user(&args, argp, sizeof(args))) @@ -872,9 +879,13 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) if (ret < 0) return ret; + total_count = args.count; + if (args.alert) + total_count++; + /* queue ourselves */ - for (i = 0; i < args.count; i++) { + for (i = 0; i < total_count; i++) { struct ntsync_q_entry *entry = &q->entries[i]; struct ntsync_obj *obj = entry->obj; @@ -883,9 +894,15 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) spin_unlock(&obj->lock); } - /* check if we are already signaled */ + /* + * Check if we are already signaled. + * + * Note that the API requires that normal objects are checked before + * the alert event. Hence we queue the alert event last, and check + * objects in order. + */ - for (i = 0; i < args.count; i++) { + for (i = 0; i < total_count; i++) { struct ntsync_obj *obj = q->entries[i].obj; if (atomic_read(&q->signaled) != -1) @@ -903,7 +920,7 @@ static int ntsync_wait_any(struct ntsync_device *dev, void __user *argp) /* and finally, unqueue */ - for (i = 0; i < args.count; i++) { + for (i = 0; i < total_count; i++) { struct ntsync_q_entry *entry = &q->entries[i]; struct ntsync_obj *obj = entry->obj; @@ -964,6 +981,14 @@ static int ntsync_wait_all(struct ntsync_device *dev, void __user *argp) */ list_add_tail(&entry->node, &obj->all_waiters); } + if (args.alert) { + struct ntsync_q_entry *entry = &q->entries[args.count]; + struct ntsync_obj *obj = entry->obj; + + spin_lock_nest_lock(&obj->lock, &dev->wait_all_lock); + list_add_tail(&entry->node, &obj->any_waiters); + spin_unlock(&obj->lock); + } /* check if we are already signaled */ @@ -971,6 +996,21 @@ static int ntsync_wait_all(struct ntsync_device *dev, void __user *argp) spin_unlock(&dev->wait_all_lock); + /* + * Check if the alert event is signaled, making sure to do so only + * after checking if the other objects are signaled. + */ + + if (args.alert) { + struct ntsync_obj *obj = q->entries[args.count].obj; + + if (atomic_read(&q->signaled) == -1) { + spin_lock(&obj->lock); + try_wake_any_obj(obj); + spin_unlock(&obj->lock); + } + } + /* sleep */ timeout = ns_to_ktime(args.timeout); @@ -994,6 +1034,16 @@ static int ntsync_wait_all(struct ntsync_device *dev, void __user *argp) put_obj(obj); } + if (args.alert) { + struct ntsync_q_entry *entry = &q->entries[args.count]; + struct ntsync_obj *obj = entry->obj; + + spin_lock_nest_lock(&obj->lock, &dev->wait_all_lock); + list_del(&entry->node); + spin_unlock(&obj->lock); + + put_obj(obj); + } spin_unlock(&dev->wait_all_lock); diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 582d33b0dcac..7c91af7011e4 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -34,7 +34,7 @@ struct ntsync_wait_args { __u32 count; __u32 owner; __u32 index; - __u32 pad; + __u32 alert; }; #define NTSYNC_MAX_WAIT_COUNT 64 From patchwork Wed Jan 31 02:13:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628176dyb; Tue, 30 Jan 2024 18:26:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4he5jz6efimXw3t8zvMG5AC4HYGdoJ0h6LK2GkclRooGFlxwWXTFZ0h1ZTTGG3TuLd6fR X-Received: by 2002:a17:902:da8c:b0:1d8:94b6:65e with SMTP id j12-20020a170902da8c00b001d894b6065emr455803plx.2.1706667991290; Tue, 30 Jan 2024 18:26:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667991; cv=pass; d=google.com; s=arc-20160816; b=GDwROnisLAzQ4erBrtTFYRt1z1vn74r/wfLN1IpYRjeqB//kVQoQiBZFVmbQcWYP+0 HymSrTSs6Sw/ZD947u9wU2G9Xtvqz5ybm1ihn23FUNRrEfW8r0a49MtC9GFdaogkYxPJ Gtfk4AA9J8B4vrIJDX+Tw9TzaXgsediiJErkTvNzovpN9EnFDQpDiPSUPxtjMiBqO8B1 qTP3skWKz/DFz5k4oYqdHYCkuoqpwlqnuAeuYT65fwLgKMY5boo7+vDRhPvD3jcnFjMs lwrSWh6GbRYMxf+yT/we5DYeIthmldsDEkyosKKGfNuLOhhlB9TJGPIpbpePXB3lmiYd n/cw== 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=5o9tJ5/jj2QUQQx8KRN1JHGF5/IwL+6r904/5t+pbI8=; fh=SWfTVPMWFIz08afsZs0DEP52QUhKsXl11PeY6En7NrA=; b=dCyfyZLKuvDWl7T83T9nHf9waj0ebYR6W7shlp2T48OjSYBqE5jdKCbE9nslR6Q7Tu 1uobUiWxlZIa4SHHCSinv6hj9YoiGNwdsmZzKmYYN4qn/T/mmzQqX4HBG5UTkuYXLxNY VyzcO/oedL/U9oM8bMCyp5XURI+9TO8ZYbL5ZLYLr2fUz23s/NLmSKEu3lU8DkiNMN2N 48TSqJFb1UoCMkCx+qDWGC88ls4nJ5ak2uAW+MFkd5CJDzZqLnAttB7NLzLOCQLm21a7 LAWTT3Pq5VRkupGqA2AfplBqHEfvD7YiXhUwlROXTcsQHxYf0mpt8G6jYS7yX5x/aR6v 3xmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Zby1bPFI; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45652-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45652-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUFcAQ8X9QOb5/KuJqhsFW9glLi9aGnyWVoupa42mYc9akJWi1XLCZxTv2G1Sv+0/lvUZ5qLd6meWXORpvjes85LRp2IQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jf2-20020a170903268200b001d8f7d2a3fbsi3217606plb.635.2024.01.30.18.26.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:26:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45652-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Zby1bPFI; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45652-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45652-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AE14D28D32E for ; Wed, 31 Jan 2024 02:23:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DED7E3DB91; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Zby1bPFI" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9620653A7; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=lXY0H2Dh2n7wOLlZ6idZakR24xG4TqoEx5vXUR1wMuVvU4x+7mJZdjI76ep+Fp/iMfMcJVsW8nbbHEdZcJNlpQ4htCL0UvSWrdDoY43Gg7rbrb3/ZeVeygfoiuHA1xBYNGySUzVpOpEehLfO0jO7eeJEBmyEP1wv9p3LYGKDA2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=RGMuntwtrCTAGoAA4ViONAa7l35a7ozaio/tGKmS42g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UmfinxHqnLGO1hQ1rH4fp5ynWSmSGOxWr0fCUlHDZw6xlXM9ikoBh3iC7hWFNOFq1T5vORjNBS9osP1A72FDQMBJZrR+1/jmKk4WQqrgVQp+AtgvX00+ihVUD9CkxBj/sUCq3O9cQZBv743AG2MBrNvSoTwK4iDSxb7K2lULQ3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=Zby1bPFI; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=5o9tJ5/jj2QUQQx8KRN1JHGF5/IwL+6r904/5t+pbI8=; b=Zby1bPFIpWN2Ca8cCs6fuB5ps5 K2qvdQ7UrI7Ms2gWK/b29hMI2p4UXiBfmFqRHLb7nVybeqqaOLLHCDGscG67/aCBO7ITMedao19mL Agn3uH7ODiykecBKPHmLvbP/TPwbm2a59x/QdjtGLYmd/KKfotbPOPvyxLw4UohkCQzl1wnIwPp+H CArU/ZnV/9xw6WNyGlOzqifK7NDeuQTCh7HLTlJbLWt8OGqdO8daW2/h32Fpyy/fmd60WLfZDGmi/ xvdOHuct6eb7Xoo0xyRKPNKO5ZETXRoQ3y6Jzcz9hr/C07lxJVqOjnQsO8K/IqznEAnNtxBRfbPvF z/kaOi0g==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-14; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 17/29] selftests: ntsync: Add some tests for semaphore state. Date: Tue, 30 Jan 2024 20:13:44 -0600 Message-ID: <20240131021356.10322-18-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571095471237308 X-GMAIL-MSGID: 1789571095471237308 Wine has tests for its synchronization primitives, but these are more accessible to kernel developers, and also allow us to test some edge cases that Wine does not care about. This patch adds tests for semaphore-specific ioctls NTSYNC_IOC_SEM_POST and NTSYNC_IOC_SEM_READ, and waiting on semaphores. Signed-off-by: Elizabeth Figura --- tools/testing/selftests/Makefile | 1 + .../testing/selftests/drivers/ntsync/Makefile | 8 + tools/testing/selftests/drivers/ntsync/config | 1 + .../testing/selftests/drivers/ntsync/ntsync.c | 143 ++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 tools/testing/selftests/drivers/ntsync/Makefile create mode 100644 tools/testing/selftests/drivers/ntsync/config create mode 100644 tools/testing/selftests/drivers/ntsync/ntsync.c diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 15b6a111c3be..6c714a4e6478 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -15,6 +15,7 @@ TARGETS += cpu-hotplug TARGETS += damon TARGETS += dmabuf-heaps TARGETS += drivers/dma-buf +TARGETS += drivers/ntsync TARGETS += drivers/s390x/uvdevice TARGETS += drivers/net/bonding TARGETS += drivers/net/team diff --git a/tools/testing/selftests/drivers/ntsync/Makefile b/tools/testing/selftests/drivers/ntsync/Makefile new file mode 100644 index 000000000000..a34da5ccacf0 --- /dev/null +++ b/tools/testing/selftests/drivers/ntsync/Makefile @@ -0,0 +1,8 @@ +# SPDX-LICENSE-IDENTIFIER: GPL-2.0-only +TEST_GEN_PROGS := ntsync + +top_srcdir =../../../../.. +CFLAGS += -I$(top_srcdir)/usr/include +LDLIBS += -lpthread + +include ../../lib.mk diff --git a/tools/testing/selftests/drivers/ntsync/config b/tools/testing/selftests/drivers/ntsync/config new file mode 100644 index 000000000000..60539c826d06 --- /dev/null +++ b/tools/testing/selftests/drivers/ntsync/config @@ -0,0 +1 @@ +CONFIG_WINESYNC=y diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c new file mode 100644 index 000000000000..6ceb48fb42e3 --- /dev/null +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Various unit tests for the "ntsync" synchronization primitive driver. + * + * Copyright (C) 2021-2022 Elizabeth Figura + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include "../../kselftest_harness.h" + +static int read_sem_state(int sem, __u32 *count, __u32 *max) +{ + struct ntsync_sem_args args; + int ret; + + memset(&args, 0xcc, sizeof(args)); + ret = ioctl(sem, NTSYNC_IOC_SEM_READ, &args); + *count = args.count; + *max = args.max; + return ret; +} + +#define check_sem_state(sem, count, max) \ + ({ \ + __u32 __count, __max; \ + int ret = read_sem_state((sem), &__count, &__max); \ + EXPECT_EQ(0, ret); \ + EXPECT_EQ((count), __count); \ + EXPECT_EQ((max), __max); \ + }) + +static int post_sem(int sem, __u32 *count) +{ + return ioctl(sem, NTSYNC_IOC_SEM_POST, count); +} + +static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + struct ntsync_wait_args args = {0}; + struct timespec timeout; + int ret; + + clock_gettime(CLOCK_MONOTONIC, &timeout); + + args.timeout = timeout.tv_sec * 1000000000 + timeout.tv_nsec; + args.count = count; + args.objs = (uintptr_t)objs; + args.owner = owner; + args.index = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_WAIT_ANY, &args); + *index = args.index; + return ret; +} + +TEST(semaphore_state) +{ + struct ntsync_sem_args sem_args; + struct timespec timeout; + __u32 count, index; + int fd, ret, sem; + + clock_gettime(CLOCK_MONOTONIC, &timeout); + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 3; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + sem_args.count = 2; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + sem = sem_args.sem; + check_sem_state(sem, 2, 2); + + count = 0; + ret = post_sem(sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, count); + check_sem_state(sem, 2, 2); + + count = 1; + ret = post_sem(sem, &count); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOVERFLOW, errno); + check_sem_state(sem, 2, 2); + + ret = wait_any(fd, 1, &sem, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem, 1, 2); + + ret = wait_any(fd, 1, &sem, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem, 0, 2); + + ret = wait_any(fd, 1, &sem, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + count = 3; + ret = post_sem(sem, &count); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOVERFLOW, errno); + check_sem_state(sem, 0, 2); + + count = 2; + ret = post_sem(sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem, 2, 2); + + ret = wait_any(fd, 1, &sem, 123, &index); + EXPECT_EQ(0, ret); + ret = wait_any(fd, 1, &sem, 123, &index); + EXPECT_EQ(0, ret); + + count = 1; + ret = post_sem(sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem, 1, 2); + + close(sem); + + close(fd); +} + +TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1634413dyb; Tue, 30 Jan 2024 18:46:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEk03TCS0Rc3v3I16w9+AYn/EWySQhZdw1pXSVi4vr7cIsTZbzgtSnVdUNcawyhEhePfIu0 X-Received: by 2002:a17:906:365b:b0:a35:dd68:659b with SMTP id r27-20020a170906365b00b00a35dd68659bmr143751ejb.49.1706669188297; Tue, 30 Jan 2024 18:46:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706669188; cv=pass; d=google.com; s=arc-20160816; b=AXcg1Kef4tYCX8eWPfmcQQCxAqnwIJIbs6uUSWMpSXQIy864jKZNzqie2HMqBFx9KL 3xxVsieFkNP6X2TNLVFR2oLyr30AR77w5kFiLfdG2FJzFMTk/NcRyq4QkmAVHx9mQOJF dZy3DtsBoQsBSoe1pv4YexeP4cXVZ3iSQxCbuu2Rj2OQUyZEgm1+XC3rKztYpcfll9Qu y0NvGhptrl84DXf83os0wA6Ey+iZXxwT3pP25nPyJyTvplNzl2TcBU6/aPz968flvXay A2V59ol2ajPlZ/LBOMVA4dRq9JleoEk5Z1m13GwCEm/bO+qSnjBHxB/I/fpGz9IjbgWU T/7g== 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=BRPNzXs5Mdd2genFVUVY/qOr199TAcld7wPlr9jkEuU=; fh=1JPrqv1wQqZQZmq5wzVgVWXWVIHQT8Pfcz7DdfRkNn4=; b=M6eKvKtpDBZmdfA/CrOpZwofnse0MDg2PmiuNwFkbgQrod9Yp7vMaMts1mMa82YApQ J1Qt+Rf878DLwXQhoWo5/5utdXtewnCjkL1zQGLecPE+nSqh9+rtPWOKSlnUxcSUgMUQ GyBYiOVlTO8/3BYHVIRXwxiAgAxx1lTzgFq2kw+hQr3Uw2k+T0oGdW5WKFh7YkLmFiHo 7gjrxtujYxQpOQjMURad4STjSZ0BsUALEw5W9QMp/9qQIkLtADsRNaTTcgCAVq8BWequ 6Q6Psb10sZQf0vshmE4oB9rd+cUfs86u8uN1ECkxBzAY6WM6JSlkRSBkUbRJg12emV/0 hnCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=H5OgV01a; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45645-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45645-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUmXExqrwTMPVpzTg76VBAjL+qNN6A3ZGuivgpPOOG6aXg54lZAEQxioQl83uOwBht8a2ETYOmMiVEaXezcLXgX2D0Mnw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x24-20020a170906299800b00a34950bf5d9si4982022eje.23.2024.01.30.18.46.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:46:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45645-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=H5OgV01a; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45645-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45645-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 73A291F28D6A for ; Wed, 31 Jan 2024 02:21:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0C263BB3F; Wed, 31 Jan 2024 02:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="H5OgV01a" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9623253A9; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=QsLv8sojQYbvfOflqOI7jVl6rLVY9uSWv5A3IJc86EunyG7zT/FqAnKabQDjIeO3G3tpZgGvz5KimyEaVtQ8iekfkWrfTjT/juntAdWd2GtSzGcVhbhRoyCU+CS8JZmUgU+avTLB1rAYDdO0RBbZCJiSbVkHuMpSZVDOxeFCw50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=bwVTho5WVjvrl0d69Y21acki6MmSdBetK4c5oytB6kc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KEYbkl2u89jy3jCo4Yo0R1ejX02SXDJdQ1LrTLVMaVfIVgCYbQD2NKbuIyIkGwWRooD3QcnmeT8+3cW7pmGY53L5q/f7sghiRCLj44Dtun0BdCwf3P8icOLeEv06N6lzE/4Ha7G2hh3A8uPA5GsUjVOVlKFdBiPGQlOWCbb1JFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=H5OgV01a; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=BRPNzXs5Mdd2genFVUVY/qOr199TAcld7wPlr9jkEuU=; b=H5OgV01aczaNPHL2z82TZhFcNW EhQtAY4usOfJBXo4OAeGUEG8PAGSgeRcTKo94paXx6GtC3nH3mJfRm+92WLJxea8EI1dfjJwVbSwM mKFcK/AIphBqE5NRu13kmE3o2FihGj3d8o2IrO4+YT17kMT0u8uVFCVR8xcyYvhNCpirjiY/AkIaK 2apXM9QlPr8fxAqYTi6cjBc8YdPFIFQLfr00mgAU1sRtTt1S4Ivt4gEwGk2wTd3jJrQaIQPJoTcKe sQkSWpIeEz2Y7PdRZlAmcVt/jq0xRNnDhDjJ7QjXxIdgwedHxacrPxKkJh5Crpt9iq1d7zL09/5TU xFTQfqaA==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-1j; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 18/29] selftests: ntsync: Add some tests for mutex state. Date: Tue, 30 Jan 2024 20:13:45 -0600 Message-ID: <20240131021356.10322-19-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572350591241868 X-GMAIL-MSGID: 1789572350591241868 Test mutex-specific ioctls NTSYNC_IOC_MUTEX_UNLOCK and NTSYNC_IOC_MUTEX_READ, and waiting on mutexes. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 6ceb48fb42e3..80c8bd409d68 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -40,6 +40,39 @@ static int post_sem(int sem, __u32 *count) return ioctl(sem, NTSYNC_IOC_SEM_POST, count); } +static int read_mutex_state(int mutex, __u32 *count, __u32 *owner) +{ + struct ntsync_mutex_args args; + int ret; + + memset(&args, 0xcc, sizeof(args)); + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_READ, &args); + *count = args.count; + *owner = args.owner; + return ret; +} + +#define check_mutex_state(mutex, count, owner) \ + ({ \ + __u32 __count, __owner; \ + int ret = read_mutex_state((mutex), &__count, &__owner); \ + EXPECT_EQ(0, ret); \ + EXPECT_EQ((count), __count); \ + EXPECT_EQ((owner), __owner); \ + }) + +static int unlock_mutex(int mutex, __u32 owner, __u32 *count) +{ + struct ntsync_mutex_args args; + int ret; + + args.owner = owner; + args.count = 0xdeadbeef; + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_UNLOCK, &args); + *count = args.count; + return ret; +} + static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) { struct ntsync_wait_args args = {0}; @@ -140,4 +173,152 @@ TEST(semaphore_state) close(fd); } +TEST(mutex_state) +{ + struct ntsync_mutex_args mutex_args; + __u32 owner, count, index; + struct timespec timeout; + int fd, ret, mutex; + + clock_gettime(CLOCK_MONOTONIC, &timeout); + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + mutex_args.owner = 123; + mutex_args.count = 0; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + mutex_args.owner = 0; + mutex_args.count = 2; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + mutex_args.owner = 123; + mutex_args.count = 2; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + mutex = mutex_args.mutex; + check_mutex_state(mutex, 2, 123); + + ret = unlock_mutex(mutex, 0, &count); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + ret = unlock_mutex(mutex, 456, &count); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EPERM, errno); + check_mutex_state(mutex, 2, 123); + + ret = unlock_mutex(mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, count); + check_mutex_state(mutex, 1, 123); + + ret = unlock_mutex(mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, count); + check_mutex_state(mutex, 0, 0); + + ret = unlock_mutex(mutex, 123, &count); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EPERM, errno); + + ret = wait_any(fd, 1, &mutex, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_mutex_state(mutex, 1, 456); + + ret = wait_any(fd, 1, &mutex, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_mutex_state(mutex, 2, 456); + + ret = unlock_mutex(mutex, 456, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, count); + check_mutex_state(mutex, 1, 456); + + ret = wait_any(fd, 1, &mutex, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + owner = 0; + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + owner = 123; + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EPERM, errno); + check_mutex_state(mutex, 1, 456); + + owner = 456; + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + memset(&mutex_args, 0xcc, sizeof(mutex_args)); + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_READ, &mutex_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(0, mutex_args.count); + EXPECT_EQ(0, mutex_args.owner); + + memset(&mutex_args, 0xcc, sizeof(mutex_args)); + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_READ, &mutex_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(0, mutex_args.count); + EXPECT_EQ(0, mutex_args.owner); + + ret = wait_any(fd, 1, &mutex, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(0, index); + check_mutex_state(mutex, 1, 123); + + owner = 123; + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + memset(&mutex_args, 0xcc, sizeof(mutex_args)); + ret = ioctl(mutex, NTSYNC_IOC_MUTEX_READ, &mutex_args); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(0, mutex_args.count); + EXPECT_EQ(0, mutex_args.owner); + + ret = wait_any(fd, 1, &mutex, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(0, index); + check_mutex_state(mutex, 1, 123); + + close(mutex); + + mutex_args.owner = 0; + mutex_args.count = 0; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + mutex = mutex_args.mutex; + check_mutex_state(mutex, 0, 0); + + ret = wait_any(fd, 1, &mutex, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_mutex_state(mutex, 1, 123); + + close(mutex); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625802dyb; Tue, 30 Jan 2024 18:18:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEe/A+RAN4S2eTbPoN2eYevk3TV8JEYq26SfM/Pd964ztGtfOTpY9T0LAyTaQhsa4wFdrUJ X-Received: by 2002:a17:903:2444:b0:1d9:1e9d:475b with SMTP id l4-20020a170903244400b001d91e9d475bmr403255pls.29.1706667526406; Tue, 30 Jan 2024 18:18:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667526; cv=pass; d=google.com; s=arc-20160816; b=B9mmZA7HKNzTLMpB4o6QVZfC+5qlu2zUccRr9iX+/f3EyTtvvmsdtXg4kiRajA0d+u HG2L/xXsiK9StvQoiIn7K60rGdZIJGV68nv4pJAoBoeUHmxQ/4oW+5ysS2uW+JWhHCP9 eWf3v7nnGeiYUJnwr190gnEazc41IfvXoI2sPTeX41BdHnCSoK9/BS3xwgoQ0pRAubMm yGfnFbT/cJEVd+oADSNdaOsMNEpwyMktrnjP1WIPjN/mJzvBHURdiqGdtgO07T1wqeE8 /EJEBesFdoCB5Gy87wC9TbBxOGl8iy/MCafOzLQXlIGwQ3TzsYxZSFzf3d5t4tZlAF7R nJjg== 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=sQXEg3DfXuCk/ElwByxgMxoggv1uEylDwgBCMnuymGs=; fh=chKNPeTEniZEV3beQsdttoKWsVa1vulqorznAtyiiEs=; b=cU1g1TMGhkM4eabdoHI5revcvC2bWNL8zwBSAdBl7LHhWti2IXMX+JMW2ihCCHCaAa EU2BR/EPxez1yIBzNdLL3zfCjPAgtsLjtaEQdqm7nrpgjin25YE6vPSVGP0QTjzeS0TM /VO8O+Ph9plcRP+lHpIjIQ5AmB2SpDFSJqKsTUx3iQa8FfXp97fNDHE8oB0h2E9Gdacm /3aDpXadPPI3paomPoWsfTs/9XyQQRNDASnzV5NlqtumS/TD4iJ2yV8GgY3LyWu9TJjQ gbNbkCCrhZanGyGWkVRC2to/jeZS17ajlf69YvcWGcZZDgauu9ZIEaDywbWCN5xIrvqu vIPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=QjUiZI3G; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXQiXMslaWkmMsLJkVmxVqYerp/EBuRCIGRHTCPrOvWlRToK568real6YzYiJX1jEMA7eM4WekJrJsV55Qlo9+HW5zzIg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q11-20020a170902c74b00b001d903a572edsi2409645plq.606.2024.01.30.18.18.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:18:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=QjUiZI3G; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 11C1F28A996 for ; Wed, 31 Jan 2024 02:18:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A793383BC; Wed, 31 Jan 2024 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="QjUiZI3G" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 96166525E; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; cv=none; b=i4ADqNv9Bc8Aa9rAh6Ewj5V1fMeRCEBxU+qpqjburWSmOkssfs0U4odFuyZd9isqjRZuHv7oLj7y0y8nRIaBp8oflgxPA0dX+ZeT379BsD+e3vy2KQbnEdJJGagRwKPXLpi8ZF8DiYB85tYKocuEyukxNyKgkpHRBooQK8yvkGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; c=relaxed/simple; bh=VwCLdmCiIAKcgrkmlaOeFhsqBt6LmACQWA252aGh+/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cj1EUyEu1yeJnoFMW6E1jmdzPBc4NO52aRiDLBUeSJ4FJ8fdAQMv+YOAigS9JiUHNWfXcbKGvNWoWt69gZ7m1ZoE7dfHqsAdgDlzDYJdb0qsecjbnVIbzJugArn62rJ7vI5ywdJxJD4cgbQsOylBZSv2cNu1cXi2Q/vdjz3Ycdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=QjUiZI3G; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=sQXEg3DfXuCk/ElwByxgMxoggv1uEylDwgBCMnuymGs=; b=QjUiZI3GGisZZs3nkZEFrWfAqV td1GHtwvnZjumHcecpgEfcIFsGYHm7+5QekNC30z3mOOuNrSAijZSknQD9MRopFXl+L7sBaSggcRH KqT4odVJSTQnWRhQYIFdNpPdVED6kuI6IdQDCpE2YTwjHlNz4BKJYSutfHhvrXr31yNrPhfhRDN4K kwBmdB4ltjlUiXpipGtT/MosREgg1Vf8uSvzAjseUD2bT3gBp58ph7f/67FWrQCfbUPgOlzDmEALF D960gJBQcpvVyyBvnmri4gwdQzb/dmbT44k1kQYaG6TkH7QLTsNZR5IHucN3qc6miyKiR3ByuyS0N b37jVAJQ==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-2E; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 19/29] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY. Date: Tue, 30 Jan 2024 20:13:46 -0600 Message-ID: <20240131021356.10322-20-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570607956593192 X-GMAIL-MSGID: 1789570607956593192 Test basic synchronous functionality of NTSYNC_IOC_WAIT_ANY, when objects are considered signaled or not signaled, and how they are affected by a successful wait. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 80c8bd409d68..13e7c9d7441e 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -321,4 +321,109 @@ TEST(mutex_state) close(fd); } +TEST(test_wait_any) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count; + struct timespec timeout; + int objs[2], fd, ret; + + clock_gettime(CLOCK_MONOTONIC, &timeout); + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 2; + sem_args.max = 3; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + + mutex_args.owner = 0; + mutex_args.count = 0; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + + objs[0] = sem_args.sem; + objs[1] = mutex_args.mutex; + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 0, 0); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 0, 0); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + owner = 123; + ret = ioctl(mutex_args.mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(1, index); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + + /* test waiting on the same object twice */ + count = 2; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + objs[0] = objs[1] = sem_args.sem; + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, wait_args.index); + check_sem_state(sem_args.sem, 1, 3); + + ret = wait_any(fd, 0, NULL, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626189dyb; Tue, 30 Jan 2024 18:20:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4WzHygVcZ0IefSXpwBMiJld+VRRW/LNPwT9qRfupgED+rCo0UqLzNiPkDcCiNS6bZ1xQx X-Received: by 2002:a17:906:5053:b0:a35:32ae:e0c0 with SMTP id e19-20020a170906505300b00a3532aee0c0mr132002ejk.3.1706667603709; Tue, 30 Jan 2024 18:20:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667603; cv=pass; d=google.com; s=arc-20160816; b=xSYK1v8x7+rViNPaXUldjq8XegdF9W0eqBbh5TAfn6ZkRD04txE6gvkh33Rw88NDJ1 WLsXLBHABa1XUp4SRQ+XXBO/jYcHqfPQhfPbeAeixDShCiVgfN7NX1d0Wo55zoDItHLb uIi1MR9oFxNvbTFISZR3Oq6+6wAkBrMygsGUnx4LzogSoTqOuhSUJ6dc5ffbbrpN9v/N gXfhJuua+oUiRprXvCQuK41Fe1SpwiofseN55fesC3x5phDxAfczqxRunxYVoHpIdkI/ jXzSXLyFFeElgiof2agSVdftd48LLixKlcUV9jE6Ua7plhxyh9bzqsfpF7PXZ/Ap8W8H B+9g== 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=sOzqgnLGIgtRKny4Ao2xmWC9bt9j+bFRdf4xOt6jSBg=; fh=gYdumsO9MQReQQWUn7obxuaqjrvRnE+NeXEH/iEc55Y=; b=UQ6Lhj469TniGMuxKQaUGs0kDpzejPVrt4+gnpHuRh1HX+xcoXZk8diCYz5XobeHLj t/wDJjb2p0hRT3Af9Nu3tChs1wWt99ZUYI12XGO8iq29wUdM0pdh6i4w1Qfy7upXCjFc PR5yvZyQpsBB+JBUukz4Aql3/bBaV8+aK1FRA0OWZ6pMzQOwBitSn7msu/ZzWPYK+gHM WmO4ZpBL+kGtOctTFV7lNWvqbMONAcyikqm0658OqDowb/LmdV/usnK/RrxykJ8eWr4H EfSAK7nSg3xW5MPysQZMo6NfQc7FQVwysSeATueC38iy11lJfcyROSkj6mBwp6qWRZqR gWug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=RBVsFPvj; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCU2OGifF7UKKc3N3NAZ3spSBtETzMRhNt7Jg3b/Zucllvqg4obNIDbNj0b/fyNGTk6yH8qAd91DUAV9rbC9lEegq+tPUw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f6-20020a1709067f8600b00a3588053674si3199002ejr.815.2024.01.30.18.20.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:20:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45638-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=RBVsFPvj; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 2525C1F27DF0 for ; Wed, 31 Jan 2024 02:20:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 607F03A1DC; Wed, 31 Jan 2024 02:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="RBVsFPvj" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 969415C89; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=KjcYQH/ORyjEf4N1NGzA4nWd75oydARYyi98Cw66k81h6JrKJZHJu68XPfwb8B8jJlAU1pirenkvcm+rmZs3JzcArGDFe9XIQgmB0iucU05++1y1d8lvQNq7mtQaRBW66upVruzN88HMUiKuT90dd8s8xuSaDA5uDtd4t16JmOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=Kxq4U91L+cNlWSbgSblxx75X7Ad/unW7tV8FCOgmvDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tLpDhv/AEzszk0ESzQRWfXmUBynmRZKKXd26ITLT6Oeao39GyWpjrhiOXJ4VFy4FQsjlXQd6k1fwlQVWiKUW527Sw7zHc35mmXmgZ+S7Q7ImK7tfYS6GqG4CN/LQNZb1T2pEcHe4xOC6V0QRGbSTqKZscmPiVSuC5PtPkjeKJ2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=RBVsFPvj; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=sOzqgnLGIgtRKny4Ao2xmWC9bt9j+bFRdf4xOt6jSBg=; b=RBVsFPvjaFUGQWiZ5fE3H2QHuK QNMwZ+In0cCqZ8//4V7v/9dSRYePTgH2Cdy/H2H4f7rdQiCnUjqSkdXYfUX1cRpWcY2oIcP1tXGHh e8liJK0QCXtXjDYL0oTWWnt4ldy5y6XPFfCyAky9RfEU8ms/TK924zqAMzZVAW2tw4d3qeKGl5UwH j4eRKwNgHKipTPLusD9c8ME4WpxMjjecaJzSnoKvcSYzkPBdnlASvN5WwDIZxwPRWnGObqbUr1+rj M0lIYOiWAFGWh3tQlrGtFTH0FIFQlAtY3KDUFbZA31Lgby0AosPS0Xr30a0thzUnlgl4RdvxAOWLB E4tdhVVg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-2k; Tue, 30 Jan 2024 20:15:55 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 20/29] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL. Date: Tue, 30 Jan 2024 20:13:47 -0600 Message-ID: <20240131021356.10322-21-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570689046815479 X-GMAIL-MSGID: 1789570689046815479 Test basic synchronous functionality of NTSYNC_IOC_WAIT_ALL, and when objects are considered simultaneously signaled. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 99 ++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 13e7c9d7441e..77f1b7e42d76 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -73,7 +73,8 @@ static int unlock_mutex(int mutex, __u32 owner, __u32 *count) return ret; } -static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +static int wait_objs(int fd, unsigned long request, __u32 count, + const int *objs, __u32 owner, __u32 *index) { struct ntsync_wait_args args = {0}; struct timespec timeout; @@ -86,11 +87,21 @@ static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *in args.objs = (uintptr_t)objs; args.owner = owner; args.index = 0xdeadbeef; - ret = ioctl(fd, NTSYNC_IOC_WAIT_ANY, &args); + ret = ioctl(fd, request, &args); *index = args.index; return ret; } +static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); +} + +static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); +} + TEST(semaphore_state) { struct ntsync_sem_args sem_args; @@ -426,4 +437,88 @@ TEST(test_wait_any) close(fd); } +TEST(test_wait_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 2; + sem_args.max = 3; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + + mutex_args.owner = 0; + mutex_args.count = 0; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + + objs[0] = sem_args.sem; + objs[1] = mutex_args.mutex; + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_all(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + count = 3; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 2, 3); + check_mutex_state(mutex_args.mutex, 3, 123); + + owner = 123; + ret = ioctl(mutex_args.mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + /* test waiting on the same object twice */ + objs[0] = objs[1] = sem_args.sem; + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626446dyb; Tue, 30 Jan 2024 18:20:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAiWasXD0VfSoDRRtQwaaOZZYJymMwEaBh8iP0ywyMnjuZtHA0TEAgotWPGTuftIuieJvf X-Received: by 2002:a05:6358:5d87:b0:175:f9b8:89bf with SMTP id s7-20020a0563585d8700b00175f9b889bfmr131785rwm.22.1706667654052; Tue, 30 Jan 2024 18:20:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667654; cv=pass; d=google.com; s=arc-20160816; b=rQwslc5BFZG8Vt0pTTI/rYRmKgmyawUSrHhGlwF8V1rogm8qYMD0hW8VfqPoc7W8AC P5Ap8EgXJ133ZtW0hLI6xYUjvkUxoISTWITeaJB2pV+6DxoUKLqwLfSURw/6lTRYKsQp rAXUdizYfmjVfk7Qp+zAas7dQWrg2+SygZH7Jp341wP6PYcO6mlZu7nfnuZfe2EFrjR8 LXP/rYP0dmXDYxSbsUKGaWI3ryW7Cgi1Y9Z6ml5FPozhp8NeAphzGqZGNgINEvGfbRwF wxAdv7xiTDvKjto9qmFZs2vJ7HiHWDdGyExruQfGiQ3gdBOx+Cw6v5lBWFQ9sGWx+XWf vSGQ== 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=hP8Bz/7TLAf/d75xqJERzPNlxl/Lxor2EgGxfs602cE=; fh=/YqlKDjwZSggOLNtRB2WGBfyy1fjDC4aThAnNi3jbZE=; b=I6AZtLp0/kMyG8R0SWKdmOcVhGNiqW3bbcYK+nVXSeUjh4mCG4VCPyVf5Xghv21bws i4JICcNrWRxD6F2uSPGxPSmXoBz16J8V+4FfHGnJt00rW0kefwEz+PaciCEj+a8v4ofn 8UqVgL/7p4DMclKJzcQY39wNqeNE7UccHjm0Er4a3pBGU4zZEKVZ+4jLQeL30aSf87WH tNxW6I1ACRYuO+K8ZLBbIyWMVmUW4008yTs0AEqPSfoAN34qDoOTxLe82HMcnzndROU2 aCBG0SLDuUZoWB7Rtxdg8U3msOUV7xFn9AmO0Y6iq+vqjKrf2wxd0Ato1p06rTsG2/Hy tAVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=k8hElhhe; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45643-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45643-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXu+puYqba9rETrZ4VQbnJBRuXp1bKaD90Zzl9pxXjAT1a6/bMdQrfYvXdsAHA2IPzdcWDLQPGH5PgFyQk9BAI6Z8qU+w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a24-20020a63e418000000b005d8c1b5a3bdsi5544703pgi.216.2024.01.30.18.20.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:20:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45643-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=k8hElhhe; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45643-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45643-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BE92828A697 for ; Wed, 31 Jan 2024 02:20:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4BFA3A8C0; Wed, 31 Jan 2024 02:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="k8hElhhe" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9666F5677; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=WYe9JCEtADSlcQyM4+6igryAhwHe4z1RgAzsY4WPvGdszAgXi0neK2f4wAT+acPKdRsWQGu62vxnacNY5PDskb4Iv1CR7ep1IeH90nByBaE0B8t2d5E7LKS8whHh4TZpho3P+rIiYKL9FufzT8d/1ALqNrw3HYm2rxv7R4Au76I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=oGzttK4t0knChdTtyUyMOTbKygxUXc7pM2yjHNoCLmQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/YEoNzCb6kxHMO/P1dylrf0FXdfkfTgV9JcqgQYWNQDrV9sOqt3NZh1GiYjn+hq6ZcY1gDdcdkEeYChH3S/WpUb5stzp1RidFJ363bzQ27EwDsZO4ylmiSQ8kuZz2ubi4QPNrZioL4uUGND7cg8eGgJy7RVNOvlfhjfVm8hW7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=k8hElhhe; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=hP8Bz/7TLAf/d75xqJERzPNlxl/Lxor2EgGxfs602cE=; b=k8hElhheWnkvX0v1/DvZauysNO AekF6tSv/6tQ5zF03mAlKgQwy4r2CkYyViT5B2DbnjDCSidQzDXBCQJVVor/Nn8FLKP6BxXjuV1pi I/7G5/yBJv3KGYWkAqdutwkDUOqkqOkp0/AsvjOhZNieey+AKJGnimd5bSEYHriMNjJQzWVXc8++t +7Phzllr4f4NOdjnbZJ85F9lEh7oXaIFWnl7tdbKv/BlNNLTd/xla7I3q662w1HQFaXt8h0sfI1Xv z01BnDpFMu22ymA1hifEin9oecRi34qsGb3c48EX+PlIdv2uKM7zmRt5DQJ4el6lVjM/+L9qvK9El Dq8gQYPg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08p-0038Kv-38; Tue, 30 Jan 2024 20:15:56 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 21/29] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ANY. Date: Tue, 30 Jan 2024 20:13:48 -0600 Message-ID: <20240131021356.10322-22-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570741868485769 X-GMAIL-MSGID: 1789570741868485769 Test contended "wait-for-any" waits, to make sure that scheduling and wakeup logic works correctly. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 77f1b7e42d76..96a866ef235f 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -521,4 +521,156 @@ TEST(test_wait_all) close(fd); } +struct wake_args +{ + int fd; + int obj; +}; + +struct wait_args +{ + int fd; + unsigned long request; + struct ntsync_wait_args *args; + int ret; + int err; +}; + +static void *wait_thread(void *arg) +{ + struct wait_args *args = arg; + + args->ret = ioctl(args->fd, args->request, args->args); + args->err = errno; + return NULL; +} + +static __u64 get_abs_timeout(unsigned int ms) +{ + struct timespec timeout; + clock_gettime(CLOCK_MONOTONIC, &timeout); + return (timeout.tv_sec * 1000000000) + timeout.tv_nsec + (ms * 1000000); +} + +static int wait_for_thread(pthread_t thread, unsigned int ms) +{ + struct timespec timeout; + + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_nsec += ms * 1000000; + timeout.tv_sec += (timeout.tv_nsec / 1000000000); + timeout.tv_nsec %= 1000000000; + return pthread_timedjoin_np(thread, NULL, &timeout); +} + +TEST(wake_any) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + struct wait_args thread_args; + int objs[2], fd, ret; + __u32 count, index; + pthread_t thread; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + sem_args.max = 3; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + + mutex_args.owner = 123; + mutex_args.count = 1; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + + objs[0] = sem_args.sem; + objs[1] = mutex_args.mutex; + + /* test waking the semaphore */ + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 456; + wait_args.index = 0xdeadbeef; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ANY; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem_args.sem, 0, 3); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(0, wait_args.index); + + /* test waking the mutex */ + + /* first grab it again for owner 123 */ + ret = wait_any(fd, 1, &mutex_args.mutex, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + wait_args.timeout = get_abs_timeout(1000); + wait_args.owner = 456; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = unlock_mutex(mutex_args.mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + ret = unlock_mutex(mutex_args.mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, mutex_args.count); + check_mutex_state(mutex_args.mutex, 1, 456); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(1, wait_args.index); + + /* delete an object while it's being waited on */ + + wait_args.timeout = get_abs_timeout(200); + wait_args.owner = 123; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + close(sem_args.sem); + close(mutex_args.mutex); + + ret = wait_for_thread(thread, 200); + EXPECT_EQ(0, ret); + EXPECT_EQ(-1, thread_args.ret); + EXPECT_EQ(ETIMEDOUT, thread_args.err); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625819dyb; Tue, 30 Jan 2024 18:18:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVfap1T4GUqua2RBBMOJzOCz0MWLAhvH8uWKrL8CZNUV8d2yY2IPW7EE1o51p3lw+N8+q3 X-Received: by 2002:a17:90b:3592:b0:290:8bbf:e4c0 with SMTP id mm18-20020a17090b359200b002908bbfe4c0mr454197pjb.39.1706667527610; Tue, 30 Jan 2024 18:18:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667527; cv=pass; d=google.com; s=arc-20160816; b=m8QMk1TuoGdGPJ5/jAN8OSjbqJ/suokSF7dNUlu8fjv3rDxyiR0bUFUo0zGUHgs9Vj M1bWFGAvF/s62Cg4O7ZQeSlvj+/2p5M1mX8hCJhbFqtRwPU6hVKTOnMcTDTwSDN/P6uK TvA7aJO1x0AicOv4JN8lkweb+6pR9ddwJBvHelZ7STl7lwfGv9kJerKfd27j8ckr6RdD LOH25ZadUgGW1v83Tu0MqJHyjH1DjO1uLSOQqFpwJwgf5/hMgamiHBut+F55xAsMjSaC r0No/a3/uqzA3m2TwECq1b7sD6Lw9ke1At90dkbCK5eU7vA2NZ0hC2dUyE2TXFaNQZT6 okRQ== 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=h/1vAQRnjB63mlOEaG3p0S99D4AXtVBKAiVYE66GsDk=; fh=RE5eoUY+nHABu41+F02SXe+o1DxneUTJCtgCxnJ4vLo=; b=h4AxHdk7GIK0SBB3B2Vew1VM5d8O23A3VPr0Y8ZWNfEUDIbikbh5oU76QAia0Ewxiz diVYC0Cqkhx79rho64WSIKO3O4vi6xMEeWfBK3QYPf2y+nKGOD+1CHAKrgAvKA7K2i20 /5Si9hIo2nLQR2WbC4TvpIZQdoG0/wRNENr5B8+yygBut4fl9roF5H9+AKt609vrDXA5 5uf5cEsEe/fx8Qax8Nm1tq9KGELH4W1/an+E/kmcKUxvBpCnf8y2XIOi4KAPXA9n8gap Xr1ZYK6Po5ahi3ukPyoj2nGD7eNpZ553BsC7JWbRIZJZM/x1Y6OuiCU4Gcw5qb6HYsy/ /m3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Nh0D1p1x; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWhWIIJ4rlRX8K/bHNriTepbYsNkfKF3NqQ/LOkvkDK9BRyNRjitT/fUsZyl7wJcfpUGEQGXkTfKKRDiYdPm+sxdST8yA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r31-20020a17090a43a200b00290260542c3si143106pjg.184.2024.01.30.18.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:18:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Nh0D1p1x; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0DA74281DC3 for ; Wed, 31 Jan 2024 02:18:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 838FB38DD2; Wed, 31 Jan 2024 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Nh0D1p1x" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 967F65692; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; cv=none; b=fc0faE1PpktPXd5pTrvPeNySIHr0XujVuKC2He1sZJb7y8vfXrw/xAkvoG22jhSN8RLvclrwDdxyVhgZ+vwRnN9khmDWZMsZf23EHXVDv6ViN2BU4hn4Ess5MBJKhtFW+7f7qDBGD+oux7mHMT/S13RQGGmGCxby/DE6QWWYeW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; c=relaxed/simple; bh=YuG2+eVgb+GAeOar9WYoIv+9X1Xk48CH588RfHzbJNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qlahzXkjX5jPgbP+j1Uvl1iq8NkefiolIGxZPCL9J1QZ9ODa/DAc4BdhXJTX3hJK8k/dSxyhZV8e1qI0+5AVwLxWO4pKGP8RL1wYN8GQpTOYl4RGFEbACkQjE16WS+Eplt1CWYhf3jChOZSlo/xDldV0g+PU6IR0uf19QO+dc+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=Nh0D1p1x; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=h/1vAQRnjB63mlOEaG3p0S99D4AXtVBKAiVYE66GsDk=; b=Nh0D1p1xOizeeLJ7Gb1yhfmm7x /vcGYZN01VBqonIUtCpaFC7LJ0h/nbyS/+2TATgH+AuDSZ+81gWwICo/ALAv76bm6BsJ1s9jw6Yzu 1DCsfHlToQlQVIzYGLDv8R3zm9dYOBDfYOWrfOqCWpoGIlm4Ol/OIpb4Q7cv5bf1fB19G8BcJo4D7 yEJ+eCOlafRyIrywVF6/6OtZUIcRVzJnQqjz7XXeEMbGSksmG79/zJAB8LtC9iCGOtVoWNZ9iEIjs 0R6biI85HXUJnOZkejwPszXc9Yz3M8oA4573n1fE8gOQLzVfqu3ygWGNmxhRVo3dD2DkMkfeI5X00 uJ3VsvAg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08q-0038Kv-0M; Tue, 30 Jan 2024 20:15:56 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 22/29] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL. Date: Tue, 30 Jan 2024 20:13:49 -0600 Message-ID: <20240131021356.10322-23-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570609250805774 X-GMAIL-MSGID: 1789570609250805774 Test contended "wait-for-all" waits, to make sure that scheduling and wakeup logic works correctly, and that the wait only exits once objects are all simultaneously signaled. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 96a866ef235f..7776fe71b8ef 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -673,4 +673,102 @@ TEST(wake_any) close(fd); } +TEST(wake_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + struct wait_args thread_args; + int objs[2], fd, ret; + __u32 count, index; + pthread_t thread; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + sem_args.max = 3; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + + mutex_args.owner = 123; + mutex_args.count = 1; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + + objs[0] = sem_args.sem; + objs[1] = mutex_args.mutex; + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 456; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ALL; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_sem_state(sem_args.sem, 1, 3); + + ret = wait_any(fd, 1, &sem_args.sem, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = unlock_mutex(mutex_args.mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_mutex_state(mutex_args.mutex, 0, 0); + + count = 2; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 456); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + + /* delete an object while it's being waited on */ + + wait_args.timeout = get_abs_timeout(200); + wait_args.owner = 123; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + close(sem_args.sem); + close(mutex_args.mutex); + + ret = wait_for_thread(thread, 200); + EXPECT_EQ(0, ret); + EXPECT_EQ(-1, thread_args.ret); + EXPECT_EQ(ETIMEDOUT, thread_args.err); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1629638dyb; Tue, 30 Jan 2024 18:31:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3hYz24xqYYesZrRkxWHjDZ3RFlqTNGY9h0SIHJFYk4+4YEmV8nupTVTNJG1e4qOC88jfs X-Received: by 2002:a05:6214:c44:b0:685:67e0:1e13 with SMTP id r4-20020a0562140c4400b0068567e01e13mr365708qvj.18.1706668265376; Tue, 30 Jan 2024 18:31:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668265; cv=pass; d=google.com; s=arc-20160816; b=i8VcwVGVlpd7LyNbJJRxA6y7Tvrk11wMULKlIhXx/Xd4hDfuDiEGeqyDra48UtIK8G 2k/Ha/+sNAHv28Ubb0+8nBnoplVDnOtegjeS458PjQ9C/gw2H0NVt3xMRXCH0nVMR2Z4 1A7epWuHxdivVobAqMguF2KQxAUkyplIb1IlzKQM5A139hZYR5ot71w88HOq9qSXuHWl 7vrxznLbjj/OLXaJa1rn9X9jIYtPIq5d6lo80uyd0eu+WNy2b88e4iLYlSYY+yHjWUMW FMWop8D48x9nGNUc2r/5sgUsAsGJ+nzkT++MtR7+7DBdcn7nQ4cV3jbs19hxiIe3zvXb sE1w== 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=zBFsoSMdTXq6ZUjgrCY1qmpBczS13zgM2yQLxywo0xI=; fh=9c0jTnVtO/cRfgOIw4vanxTUv5R46FyCwZ7yxmvt5Mk=; b=iIWgyd3j3ul8sTMJkHWJcRj0eUyyCkKHXEx3sKa7Me+WQiSk3NDmDzfRLo6hd4VB5N PAbboOvXz73o+4GPNWsG/YmiJ7sjSLiTEoFhqdzDsIS7nJ4FBKrZ55fN/p8RVDT+VFRX d9ddG8sLs1riGhBq3TY8Xe3OzE829LznZYnxwYCMcu8E0oZCg1EffrWeb/jmMfM7tGwY nBLCSLSxsqA4BUc4PySwuLMd4hXYhuNUYz0dTqA5dgxTIQjchSfOVkoSrJn/X6TqCFpR PScKX8rzCnoUgePBUf1bAND3e8O7rTYoESczRwExEVP2EZcrLUiKqWebYPNaU0mswEOL G8jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CISuoKe3; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXSgwC7mbV2AQGMpaLej8VM9oYzIkDavEcTs9la2JVpthkcB0WOwjwXSWZ+4mBWXTLW7fnWk95bM5FP1voWxIzbq6zkHQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u12-20020a05620a454c00b0078534dc432bsi1881130qkp.369.2024.01.30.18.31.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:31:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CISuoKe3; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DE1A91C20FAE for ; Wed, 31 Jan 2024 02:20:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A2C03A267; Wed, 31 Jan 2024 02:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="CISuoKe3" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 968D75697; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=RdYjpE7eTsthSVnnfwrZIUemPO1+uYrXed461UID2EaAvrMBQA544ABn2h3xsidaylX92XvfhZczYVm12Yxb2kRpOyLEQJKBbZnjBGDgYSDvEOx+UqgP0+kftcpTeipKgXgPSk20owTtcTJmOIqvYYDc01Q/QkME0t0/Yw0hz0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=VlAa0x53Zal9SGTSmO7FlNYompGdzB0uV0PrcJepaC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGRTK3BRH/XQ6/q6nWE7gc2fDyCIrJ6CLNIt4zTc+2I5QAqjW6Cj06H7cF7oMX+HpK92l+3dp9uIpXMCPDvFDq3tci9Hy22kHrnTNu66sSr4rj0YDEg17Eos5ssE/NLnEq3ZZi+KhogSBhpHLBqhxEJ7s8Y1dbcH4iAL8Famktg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=CISuoKe3; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=zBFsoSMdTXq6ZUjgrCY1qmpBczS13zgM2yQLxywo0xI=; b=CISuoKe3oAl92A2fJOaI8g2P9W AsSdfvikPC8ln2q0is0/4rWRnmbXDFiNmxXAfCfIJaxqE4B+uWla1BTuKi4xwCmIl3CP3Fir3EQg4 1D1i2lQbJNH+2fqqNyKaVJ3aVpHnXxBLyCaaJXfriRMUEJFbxgClGb4lWSlvbIzZS/lh1PZPsZ3uR c7XM9c9brHJG4OOdxaR7F4LBLiFaMBFpWdzvea7yVLp9LiDjvT0P0A69jwvJeLN64v4zO4g/Zd/NX rqMqUlDfkaHGUuX1QA3QqXDW7vVIQ0lMRFZiCESbFpqujktHBEox3dMd1UvY4qJSLSda4c8oWwmJ5 JmYYNuTQ==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08q-0038Kv-0s; Tue, 30 Jan 2024 20:15:56 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 23/29] selftests: ntsync: Add some tests for manual-reset event state. Date: Tue, 30 Jan 2024 20:13:50 -0600 Message-ID: <20240131021356.10322-24-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571382685103290 X-GMAIL-MSGID: 1789571382685103290 Test event-specific ioctls NTSYNC_IOC_EVENT_SET, NTSYNC_IOC_EVENT_RESET, NTSYNC_IOC_EVENT_PULSE, NTSYNC_IOC_EVENT_READ for manual-reset events, and waiting on manual-reset events. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 7776fe71b8ef..98fc70a9a58b 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -73,6 +73,27 @@ static int unlock_mutex(int mutex, __u32 owner, __u32 *count) return ret; } +static int read_event_state(int event, __u32 *signaled, __u32 *manual) +{ + struct ntsync_event_args args; + int ret; + + memset(&args, 0xcc, sizeof(args)); + ret = ioctl(event, NTSYNC_IOC_EVENT_READ, &args); + *signaled = args.signaled; + *manual = args.manual; + return ret; +} + +#define check_event_state(event, signaled, manual) \ + ({ \ + __u32 __signaled, __manual; \ + int ret = read_event_state((event), &__signaled, &__manual); \ + EXPECT_EQ(0, ret); \ + EXPECT_EQ((signaled), __signaled); \ + EXPECT_EQ((manual), __manual); \ + }) + static int wait_objs(int fd, unsigned long request, __u32 count, const int *objs, __u32 owner, __u32 *index) { @@ -332,6 +353,74 @@ TEST(mutex_state) close(fd); } +TEST(manual_event_state) +{ + struct ntsync_event_args event_args; + __u32 index, signaled; + int fd, event, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + event_args.manual = 1; + event_args.signaled = 0; + event_args.event = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, event_args.event); + event = event_args.event; + check_event_state(event, 0, 1); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 1, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 1, 1); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_event_state(event, 1, 1); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 0, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 1); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 0, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 1); + + close(event); + + close(fd); +} + TEST(test_wait_any) { struct ntsync_mutex_args mutex_args = {0}; From patchwork Wed Jan 31 02:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1641351dyb; Tue, 30 Jan 2024 19:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHC14Bplw8iO8VlRI7oyl3xBC72iv6QdqUTLMMAAYlgNCHfeu1YlU7r7F/KIItb2y+obnG8 X-Received: by 2002:a17:90a:e286:b0:295:ae22:574 with SMTP id d6-20020a17090ae28600b00295ae220574mr470721pjz.24.1706670494264; Tue, 30 Jan 2024 19:08:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706670494; cv=pass; d=google.com; s=arc-20160816; b=vpmiQUf4WpLeOebFG0GW1S2k+kL7Y6z2ZK8mYxY79gFOUHqErkNCFBuOtCtftpCwSP T78YUhTrFm/3WAJmnRVF4uJupYty27SndixgrR4i3rdcBzacb9NB5kFHEEKGAoY2v8zm wFMWxSuWe5FucYCSulnZgzDJJUb1nG6Dj04160AnYaxTa6fYaZBlujrtkFUIHnGgDl0G suGSjFE2iNnFImf6Tv1EoGnwsOU4VhHrngOc+tCNACp8wFeoQPAM5ec7jn/cFiXaQtVe MLtbyMIf+Qam8S6E5xgHGx8xncX/LI17jKwu4Guia8Zh5s1SqhzaUXvwoGrlXPoNtw7e 5UFQ== 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=CXWwJG7hNntB0Sd76fqEvUM4syQk+zNXqt/EdvXAsPg=; fh=x67p2b5bW6iDLN7Byy1ZN6TT3V7AYMUydcS+zvBfps8=; b=AVHik0V/edSKJn/IhOII9aNoJe0B5MKOuat54p94ywpiI9HBakUAgxv93HmmuSKtON +RgNVViir+SNa13saLAqh3BYx+1/rIOhMrR3G6OYrNlGiPghDG3MHyd9Xb9P6J6d1xLl gWuJi3aHtLX2efXAOpXnACPLTE+MGRhoO/8ahBtVzcb2o3dzKdTuNLivLSAevODqBLiD n3MEOl10BB1ciUHdaN5HVcodiD8C18y13qXgAJ+d4Snrxp4g1t78l9BR36LZU9Profcy GydJRwzQCmNuM2GrMhsJKt6G6a3i0gdH3yDJ/ttClQtEKIDy9qxOM3z8YmSMTZQCTDrI e8mg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CwZyaYJZ; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45642-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXvMXLW6dzpD/lhtPFVW0WgMuqq3RaL/yjYKw6MRpKKP7ScUOswOyOXVap+NfVmMdZJmb6TSTNfwpR8aaLqrsD6HuVWuA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a12-20020a17090ad80c00b00295b65faa82si249788pjv.80.2024.01.30.19.08.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 19:08:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CwZyaYJZ; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45642-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 662AD28A352 for ; Wed, 31 Jan 2024 02:20:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 605DA3A1DB; Wed, 31 Jan 2024 02:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="CwZyaYJZ" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 E809A6122; Wed, 31 Jan 2024 02:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; cv=none; b=L5RmoK+jTaDYlFWPBjaDuRgYSbbCPR7cCqLjy2urVF6VbkAYgnx+t+tvIMMKKG3lmP7Ly560lJ65neXSnI+zSZaOA+TXyQ24fENOv6XOSc+j1CJhlS39VX5H09tGL5ywcHDZF5BTMTHAaltWPKqbEW2J4m04slJLfTn0wTCTLek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=Vgourthv6+qc2f6oyg7IShZk7b3h5Z7yXed29bs8vsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NZnYvSXMSVbdX+/1EdpqgGlY1W1J4p1jiTI7tIl42xftdfDXOBBPB77ShJYiV/kyhh2Qz93BkEQ2NJLlQheur9glWpcZ/PkBCq7UmnpeyAPdOvysS0qt3LvHCWeL9tkHcF6cXBJLmLzk3493VzFOFbgp1KUAm68tjdVN1HsrdDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=CwZyaYJZ; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=CXWwJG7hNntB0Sd76fqEvUM4syQk+zNXqt/EdvXAsPg=; b=CwZyaYJZwv0NBwH/DzysGJa7rA uRt80Zx6X/t7Je1Gxk7iDd1Tp6f4CldiSS8liaCJqDNe7KTGFuk2pyRQBUWx2nAwEpiMCehgs9RRr mSqYT20YIiC8TDVKWZVeUGUWHUAqbvkJXeWNSMhmXf/5i9ctb3DYVMfUR+rc8/vhTYUcKmM9S6g56 W7byiDlWKhekV12BlEg92o/cm6mMVRnbO0hYkOfwg//53ZBpyfEQw7w2Qb3ZIIpe3Fzr16n7cFpzD l+l5krjnkgu8FQiQTc2YYVWg0MUdZE/+Dh+atxcJEuRJAPVZZazcGI576NHRK2FwfGKy6gJWUTJvE 7FbivdWg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08q-0038Kv-1U; Tue, 30 Jan 2024 20:15:56 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 24/29] selftests: ntsync: Add some tests for auto-reset event state. Date: Tue, 30 Jan 2024 20:13:51 -0600 Message-ID: <20240131021356.10322-25-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789573720468161761 X-GMAIL-MSGID: 1789573720468161761 Test event-specific ioctls NTSYNC_IOC_EVENT_SET, NTSYNC_IOC_EVENT_RESET, NTSYNC_IOC_EVENT_PULSE, NTSYNC_IOC_EVENT_READ for auto-reset events, and waiting on auto-reset events. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 98fc70a9a58b..f1fb28949367 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -421,6 +421,65 @@ TEST(manual_event_state) close(fd); } +TEST(auto_event_state) +{ + struct ntsync_event_args event_args; + __u32 index, signaled; + int fd, event, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + event_args.manual = 0; + event_args.signaled = 1; + event_args.event = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, event_args.event); + event = event_args.event; + + check_event_state(event, 1, 0); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 1, 0); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_event_state(event, 0, 0); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 0); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 0, 0); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 0); + + close(event); + + close(fd); +} + TEST(test_wait_any) { struct ntsync_mutex_args mutex_args = {0}; From patchwork Wed Jan 31 02:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1629412dyb; Tue, 30 Jan 2024 18:30:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDtXBbNC73PrwFX/w/crBKaeXxQwLqrktxNF2afU0EYRh3/+wAaPykcHHgc4yYXPncgiAz X-Received: by 2002:a05:620a:84f:b0:785:35d3:405f with SMTP id u15-20020a05620a084f00b0078535d3405fmr226238qku.48.1706668233987; Tue, 30 Jan 2024 18:30:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668233; cv=pass; d=google.com; s=arc-20160816; b=B9z0VNqc1D3vU8BoQsMRTXfFNsMp6gl6NpWV1grEC1KdYeU7IQn30kHQLloDachy0j ptPE0tSVH92pbbLsnAQ7FbQs2SpCNNHY+NXMH54w5ukd8ShniBum3/oAREmMXtvTTaes t0AZZY/590JoEhowem1GiCUN/dWR9C8ughIdJv4JTFQbUWq9Po1bF3ImS4x+CgZVXSkE cN+sJiQw8AjXrA88tAX+a1BEL8WcTMACHNoKNNAHgL+8iXCxlKja7p1pDAnYSRm4CzFU 0qTzEnC/eOeo8O2gs4862PM2XC+RLNUXNtWOgTzY+eIOgPK7C5yYckGUkPh4RNXukaDz bvVQ== 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=C/l8P/T/8q19HrhgPJ8sTJiMaOotRO1aGNL999D3iO0=; fh=ZJME9B6u/tfi/iKha9Wk8vlTvbGAP74gryEdC2KAeVY=; b=Tqttngb+Bcsz8YHqIJLE0SUgCrlsYQgRAAQM5FlXCZjnKRzhZ51bKO8HICHYi/aZq1 ss2Zzgv5RqoN+70jAiC0v749D3FPTrPz4q2mHHp4lb2Rw1Jgw1u37vKqVYyxHsz+vQvh W/mfO6CyK/68ADNpqw12aAKUrGJImyFbpXVgOEK400c5cwWfMJimSdL8kMtVLotPavnZ isZziGkql3tZ3Zxft6be+3RLush6UMlXk1px49s3CzABi7Cn6AH6d7Ve+P9jxCDOW6Nm TNl3YZdK3DzK2OJU8EIpGVk73OLF5UTe78aBxw11oMXlUvBPWZg0hMsbgoR4h0jsCHkq DiKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=NBzI0219; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45656-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVJgAPY4wjKUOQ1jm+r+r7pS97Wc/e2r4Sq1P/3kYw+Auhp2TCzJOKReAhgqBOnYXt64CDWi2K8h8ADk365OBQumn1SoA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h21-20020a05620a245500b00783f5da4fe7si7998849qkn.260.2024.01.30.18.30.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:30:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=NBzI0219; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45656-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AC3F91C27C95 for ; Wed, 31 Jan 2024 02:23:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C8593E48F; Wed, 31 Jan 2024 02:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="NBzI0219" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 EA3FB6125; Wed, 31 Jan 2024 02:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; cv=none; b=fto37CSqEMis5K0WRZXQ1xegDkCI+h897u2n2Tz5ETCP/bG59+Wl6Yeef+mn9/tJo0yWefJq57kjDE+NOi+BwuNqQ5vCsOTzFftaWL3Z1UyZe4qvkPXY1goVO1HLzTsXVRKFnr046/sZp96xhmDZYhlrRdVG1+mHjeRTonepso0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667369; c=relaxed/simple; bh=bvcyWhlZ3Fr42NYnfxtjnii64Zdx/vP2Jd+TtX5muW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OboJ88HfATSG5zggCmT/x+P/VTPKt4CDbFGxiGG4AsPFDzLSwNpajVRFzQ/560uHzIwze558cN5zIXrQTr4JT+G/Qc5pGO8unvffWTgzT5mBmYxbmXbsH6P5a5CsRRHPDuqnrfqcJRG+CE8R4KmUKeMY6VzmsErQSPrr/OrGNNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=NBzI0219; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=C/l8P/T/8q19HrhgPJ8sTJiMaOotRO1aGNL999D3iO0=; b=NBzI02193DEG+3N/AiuMi+pLMV pApovlbR0dAlxkAyBeTFMrYyEaU0Y06QL7zZHcbCRx7BUCuIEPX7HsJdAEjJfggTtAfmyB4wLbn58 Nep6ja/JmZV0atl2hq9lPGIfqWwZjYym4NjWxWpT94BWjs95sLFuu3KY4FuPtKmP9s7qJ1jq1CXgA ScPZVE6h+Z5hcCONrHDvwCjZ4A/lyrhfTM0nmD1v1HqlovqbJS2b9D7c2R2+MTD01LfeMOHPqdqwD L9k2GAZi33N3EUAE1Qf+G0R7hxTxOt4RYufb1ZpA8Exv63ycYVea9xUHzsmZQf4MsByRSAOlK3xcg ynYG7y3w==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08q-0038Kv-3D; Tue, 30 Jan 2024 20:15:57 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 25/29] selftests: ntsync: Add some tests for wakeup signaling with events. Date: Tue, 30 Jan 2024 20:13:52 -0600 Message-ID: <20240131021356.10322-26-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571350088054663 X-GMAIL-MSGID: 1789571350088054663 Expand the contended wait tests, which previously only covered events and semaphores, to cover events as well. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 151 +++++++++++++++++- 1 file changed, 147 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index f1fb28949367..598333df3e6d 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -587,6 +587,7 @@ TEST(test_wait_any) TEST(test_wait_all) { + struct ntsync_event_args event_args = {0}; struct ntsync_mutex_args mutex_args = {0}; struct ntsync_sem_args sem_args = {0}; __u32 owner, index, count; @@ -609,6 +610,11 @@ TEST(test_wait_all) EXPECT_EQ(0, ret); EXPECT_NE(0xdeadbeef, mutex_args.mutex); + event_args.manual = true; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + objs[0] = sem_args.sem; objs[1] = mutex_args.mutex; @@ -657,6 +663,14 @@ TEST(test_wait_all) check_sem_state(sem_args.sem, 1, 3); check_mutex_state(mutex_args.mutex, 1, 123); + objs[0] = sem_args.sem; + objs[1] = event_args.event; + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 0, 3); + check_event_state(event_args.event, 1, 1); + /* test waiting on the same object twice */ objs[0] = objs[1] = sem_args.sem; ret = wait_all(fd, 2, objs, 123, &index); @@ -665,6 +679,7 @@ TEST(test_wait_all) close(sem_args.sem); close(mutex_args.mutex); + close(event_args.event); close(fd); } @@ -713,12 +728,13 @@ static int wait_for_thread(pthread_t thread, unsigned int ms) TEST(wake_any) { + struct ntsync_event_args event_args = {0}; struct ntsync_mutex_args mutex_args = {0}; struct ntsync_wait_args wait_args = {0}; struct ntsync_sem_args sem_args = {0}; struct wait_args thread_args; + __u32 count, index, signaled; int objs[2], fd, ret; - __u32 count, index; pthread_t thread; fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); @@ -800,10 +816,101 @@ TEST(wake_any) EXPECT_EQ(0, thread_args.ret); EXPECT_EQ(1, wait_args.index); + /* test waking events */ + + event_args.manual = false; + event_args.signaled = false; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + objs[1] = event_args.event; + wait_args.timeout = get_abs_timeout(1000); + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event_args.event, 0, 0); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(1, wait_args.index); + + wait_args.timeout = get_abs_timeout(1000); + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event_args.event, 0, 0); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(1, wait_args.index); + + close(event_args.event); + + event_args.manual = true; + event_args.signaled = false; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + objs[1] = event_args.event; + wait_args.timeout = get_abs_timeout(1000); + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event_args.event, 1, 1); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(1, wait_args.index); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + + wait_args.timeout = get_abs_timeout(1000); + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event_args.event, 0, 1); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(1, wait_args.index); + + close(event_args.event); + /* delete an object while it's being waited on */ wait_args.timeout = get_abs_timeout(200); wait_args.owner = 123; + objs[1] = mutex_args.mutex; ret = pthread_create(&thread, NULL, wait_thread, &thread_args); EXPECT_EQ(0, ret); @@ -823,12 +930,14 @@ TEST(wake_any) TEST(wake_all) { + struct ntsync_event_args manual_event_args = {0}; + struct ntsync_event_args auto_event_args = {0}; struct ntsync_mutex_args mutex_args = {0}; struct ntsync_wait_args wait_args = {0}; struct ntsync_sem_args sem_args = {0}; struct wait_args thread_args; - int objs[2], fd, ret; - __u32 count, index; + __u32 count, index, signaled; + int objs[4], fd, ret; pthread_t thread; fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); @@ -848,12 +957,24 @@ TEST(wake_all) EXPECT_EQ(0, ret); EXPECT_NE(0xdeadbeef, mutex_args.mutex); + manual_event_args.manual = true; + manual_event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &manual_event_args); + EXPECT_EQ(0, ret); + + auto_event_args.manual = false; + auto_event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &auto_event_args); + EXPECT_EQ(0, ret); + objs[0] = sem_args.sem; objs[1] = mutex_args.mutex; + objs[2] = manual_event_args.event; + objs[3] = auto_event_args.event; wait_args.timeout = get_abs_timeout(1000); wait_args.objs = (uintptr_t)objs; - wait_args.count = 2; + wait_args.count = 4; wait_args.owner = 456; thread_args.fd = fd; thread_args.args = &wait_args; @@ -887,12 +1008,32 @@ TEST(wake_all) check_mutex_state(mutex_args.mutex, 0, 0); + ret = ioctl(manual_event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + count = 2; ret = post_sem(sem_args.sem, &count); EXPECT_EQ(0, ret); EXPECT_EQ(0, count); + check_sem_state(sem_args.sem, 2, 3); + + ret = ioctl(auto_event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + + ret = ioctl(manual_event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + + ret = ioctl(auto_event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_sem_state(sem_args.sem, 1, 3); check_mutex_state(mutex_args.mutex, 1, 456); + check_event_state(manual_event_args.event, 1, 1); + check_event_state(auto_event_args.event, 0, 0); ret = wait_for_thread(thread, 100); EXPECT_EQ(0, ret); @@ -910,6 +1051,8 @@ TEST(wake_all) close(sem_args.sem); close(mutex_args.mutex); + close(manual_event_args.event); + close(auto_event_args.event); ret = wait_for_thread(thread, 200); EXPECT_EQ(0, ret); From patchwork Wed Jan 31 02:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628752dyb; Tue, 30 Jan 2024 18:28:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1OBgbWZEaVIxlX7F6+I4A1JqRsLhWU0nRlvCzSuMi4hkTpdDS119r4AiU2D3p9dpJq/jP X-Received: by 2002:a54:4092:0:b0:3be:ab0e:733 with SMTP id i18-20020a544092000000b003beab0e0733mr465483oii.13.1706668103656; Tue, 30 Jan 2024 18:28:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668103; cv=pass; d=google.com; s=arc-20160816; b=imHYQtq6oR+2s9sXFv2fWqINU8dpaZBs+17pG26jwNUcxz7sSv4QlVXEJ0wfOgPsSn YkGKqV/a9+Ihwzfy1Cuzoc4eeeCHdmxV6rHLY3k17RFgYtNI2qBNk5BPUdNlGsxQ86WX 7HHxBZxO1ExGA4PXLSdsm9EdCE4juIrHgiMZiPObpCfHA0hkJnRMcBa8DaTxHyyENuJF 7+1LYeWPIN08dox99OYUjROGkv8WerWbiF2htlN+Nz7q8vNlresE8dwpUKpp9AYFWw1q Pix1GJ05uJ161ZYDbHr6Bc3rh2VDOr77SvxKZHMKF3VEpNDJmQ54P6cZy0OlviUMsD42 5lDg== 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=9a/wMnBLv1xoxspXfxOrW3hEE0JYusn2W8rgrXnFegU=; fh=wqgAhUDHbOcaB+z3edFPpGq8PIk2UfjBVfTdTocLxW0=; b=EB0tkuLA8awbx805/vQgrFh6fp3BSAkFVrlH7PyPpNlZH2IqOB48nIsgmtkStFqZce Cljv69XLhHXbOUZcuG1zAzP4npLMfWqDWtZxFfNtXUzR27gVU1eTQnhz6GjtSMiIm2fu kTz8S2pktqGA2YCFhlcMGx93c3vhO3XmJtPrtKOnaL0c5/NbH0vg9VVKA2FzhcICVo20 PESes0+nooKeSaS1T/C2AdpE3apyUCL2I/MAszmm16u/NgsV8tCiMGaa/HaNUHui+LTf ezJagYizp/ijKvTHuK9ZWNAMonYcxpXxQrXu/hLxEzfgr08OJxO+tizzDMfa9J9jEkAD jPtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=gAx8v05d; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUQUq++KNCjETTrFJAjYFyZ52fvjIwKU79CMzeV3QuZ8i8cFnIs4d71WXK9QMIIK/T9mSuNmbCO00f/vvLUqMxRB0e/ew== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cm8-20020a056a020a0800b005cdfbd1d0e1si8689950pgb.129.2024.01.30.18.28.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:28:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=gAx8v05d; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 521BAB26DBB for ; Wed, 31 Jan 2024 02:23:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BFBC3D96D; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="gAx8v05d" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 59F2063C7; Wed, 31 Jan 2024 02:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=tzdUlIZd6k02zwRo1aryb21tLzGNqGgsoyD5RvZ7wn1FLbp3DTpWhhXXzl9J9GVaWgpMAyrL9vq9Mlq4EVVcLUKikOMUBlRRS4oLw//r74xXG+G9oU020uFFTwWaYeZKq0FxvUrOKFKOOgBHnXl2wR0JiI9eSNQ484s+OCFzZsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=31Rr5cIrKWA5Jh3ekx9HXSxmqlSxR8yZglxBVPVOJoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V42ObxV9Cr8kIsV4A7Y8zth0WqxIvs8UGzA8IIrOgNL8JOBW7SJZAY1M6kLjpG9E3Jx0Cp5bmQqToQeeICnltwM8MSO5Fy3lin7BAj2ZIU/yQSKIMtZUBmYfMqp5Q7Vohph2e0Ah3uY5nsImZKu9KN4uFU0uLtWdpcZWMVfXnVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=gAx8v05d; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=9a/wMnBLv1xoxspXfxOrW3hEE0JYusn2W8rgrXnFegU=; b=gAx8v05dK5R5gEbKhG0F9I9T1o xfnYmZ4w1atOmAQdpD9Rc8pwxpgVFZ9r4KpsKRZD8j7RqjlqGKQ+EmwDxV+0/stfgWITBsjVfMpl6 GTC0f22zZhPch9VELfqE8hKJ6ypkRSSBkAdhBsDmKZnlkxSr0bNVjlvwT2Eq0/l2RTWO8YBHvlNAA nnhmVIZ4l1m62Y6Voeh7HJXlw+K5+WpQeNweQ6eQPjR2YCsGRF13EgV+PKssduXKyRJlmvKAYKIwb h350mEFbPZD9U/zfUoX7W+QTv04/v7Z0pUafk1oOfDYsAJerbD8G2SPaP9ljLfbV+8FpWxeef0rbq LOHInviw==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08r-0038Kv-1n; Tue, 30 Jan 2024 20:15:57 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 26/29] selftests: ntsync: Add tests for alertable waits. Date: Tue, 30 Jan 2024 20:13:53 -0600 Message-ID: <20240131021356.10322-27-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571213320592742 X-GMAIL-MSGID: 1789571213320592742 Test the "alert" functionality of NTSYNC_IOC_WAIT_ALL and NTSYNC_IOC_WAIT_ANY, when a wait is woken with an alert and when it is woken by an object. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 179 +++++++++++++++++- 1 file changed, 176 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 598333df3e6d..6c00a55909aa 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -95,7 +95,7 @@ static int read_event_state(int event, __u32 *signaled, __u32 *manual) }) static int wait_objs(int fd, unsigned long request, __u32 count, - const int *objs, __u32 owner, __u32 *index) + const int *objs, __u32 owner, int alert, __u32 *index) { struct ntsync_wait_args args = {0}; struct timespec timeout; @@ -108,6 +108,7 @@ static int wait_objs(int fd, unsigned long request, __u32 count, args.objs = (uintptr_t)objs; args.owner = owner; args.index = 0xdeadbeef; + args.alert = alert; ret = ioctl(fd, request, &args); *index = args.index; return ret; @@ -115,12 +116,26 @@ static int wait_objs(int fd, unsigned long request, __u32 count, static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) { - return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, 0, index); } static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) { - return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, 0, index); +} + +static int wait_any_alert(int fd, __u32 count, const int *objs, + __u32 owner, int alert, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, + count, objs, owner, alert, index); +} + +static int wait_all_alert(int fd, __u32 count, const int *objs, + __u32 owner, int alert, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, + count, objs, owner, alert, index); } TEST(semaphore_state) @@ -1062,4 +1077,162 @@ TEST(wake_all) close(fd); } +TEST(alert_any) +{ + struct ntsync_event_args event_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 index, count, signaled; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[0] = sem_args.sem; + + sem_args.count = 1; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[1] = sem_args.sem; + + event_args.manual = true; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 0, NULL, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 0, NULL, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + close(event_args.event); + + /* test with an auto-reset event */ + + event_args.manual = false; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + count = 1; + ret = post_sem(objs[0], &count); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + close(event_args.event); + + close(objs[0]); + close(objs[1]); + + close(fd); +} + +TEST(alert_all) +{ + struct ntsync_event_args event_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 index, count, signaled; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 2; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[0] = sem_args.sem; + + sem_args.count = 1; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[1] = sem_args.sem; + + event_args.manual = true; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + close(event_args.event); + + /* test with an auto-reset event */ + + event_args.manual = false; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + count = 2; + ret = post_sem(objs[1], &count); + EXPECT_EQ(0, ret); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + close(event_args.event); + + close(objs[0]); + close(objs[1]); + + close(fd); +} + TEST_HARNESS_MAIN From patchwork Wed Jan 31 02:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1629615dyb; Tue, 30 Jan 2024 18:31:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj0CbE5JjyKWptxaxADqc+pcNMjv2gpu0Ic3aZ81hKtUBaAV+8obmpwS86eImJ4qTqcGXv X-Received: by 2002:a05:6214:29cb:b0:68c:5e07:63e9 with SMTP id gh11-20020a05621429cb00b0068c5e0763e9mr372519qvb.24.1706668262900; Tue, 30 Jan 2024 18:31:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668262; cv=pass; d=google.com; s=arc-20160816; b=EZu9S0G3/WbIzl6ERwtOcQz87UY5AyT2+EQLphhB5oTa1W5l12TBScvRJaXa/C+X+E AdAxirsScOPF5B9HWsOuPLvs7v8y6Denfr6kx3BznEFFt11L4S9iLcBaym/F51UnUKcu Zg4q0Wku5J+hviA5JZ8Nfo0mG77ZvIs2RWLexUOAzr+lcwxMTF61QJ6t8jNubIj8iyaL eegDG++qhowOcVqFNPDb2ExAWYtqQJu8qdFlf62MBnzMkP0SkBzAm9MgrVEkzctBrxxn HMPQb0GUR5nXS+YITSqTZReTZRuTV/k6339HaDU0mHI+VLfmmqHDyQO0l+cydd4TBScD DXSw== 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=In2g/SxOslWdr0ggX/uaBmW3P5Of+22LEm91YJWAe0A=; fh=8eXT+0/cH4c0iDmgMKQmo0uo/p2j09jBBwhOJLOe0CM=; b=UF/F+o+m/8IWbPUQhrsYbCjaXHf+hsDR67QUwD/tOfZxrqQvyZ4qQEB/bh7WfF9+i+ JapDyhsYzPj0zToVjBo8uVnOyZE+2oXgR65mn+VQTHMLWVMoJN2jZYh48lOukrOtsc1y Xi07Sd7qjnWKHmkf9rvvFGxHv/MBGjjkrF50d0qxOY/gXBXb1dqeSVBC7QUewG4kqwgO 1SvKgk+MYl8qJnvogQeC2rm4h+1fFpNYv1VHvCuzUgENotshdOU61AE4IDpsFcGa1cQr fSS3KPD2WzNHOkSvrl6xlz+fX2LhKLKtT2KuvbQqvbl3VJss9cBzMnkLXKqkS1DC1xR+ 4row==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=O6rqaQpH; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45650-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCVVdMDlGR6iQyuV+cc6kNa5dV0CVfCAeYpcHkwqFBiKi16fMnyCQU4t97M6ZsMmF3tb+uR6LA6+DwDgLTGkQP1tQphEdw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kc7-20020a056214410700b0068c5deda105si3038914qvb.211.2024.01.30.18.31.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=O6rqaQpH; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45650-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45650-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D55B41C27756 for ; Wed, 31 Jan 2024 02:23:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 313223D576; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="O6rqaQpH" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 947E7746E; Wed, 31 Jan 2024 02:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; cv=none; b=Pa1mYoBVKQv1xasu4BMIfbxpiGzXHy/6E2W3BnQofubMWojDwbNVSzwbkNyJcqslBvIni7xaK0ZULWowJJUiPxsNRfWar8rWHThl4xKwt1/3WnucRZGG05NpjhupryWFQRrTR+s2xmt7m/YnaINlR2eFgwjwAr1cuLhzPkK77UI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=0/+/hcgGDqBe60bUVEVmocVH9t5svTQdQZc0NkVSSpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pT3Cao5OFiX1Jer00CwIDCtQCMmDnzuNaReg7khAI9bf8nLQlzUMMAELY+K2Y8AFNJ0DAS7jeWaEnE2YTJeLuuwFSHsVz7ZkRD1POseVKNKz1LZ2r/5vbtQzgSR3Oa8KnKlinZd4wwquvdDO23uN4iFR2FpcWS2gp99EPI+dGS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=O6rqaQpH; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=In2g/SxOslWdr0ggX/uaBmW3P5Of+22LEm91YJWAe0A=; b=O6rqaQpHDK+OJLCivF6+Qd0XyV wJQMzjsrn5//04CHK55yjO4hL0I64rS7vXKWVcZ+OErnP0JU8IIXsBCT5mt0T8eBEOOjbcP0KkJmG GDhx2EY9uzYeKaxqiwtKkcDbcb+TsIZFHn4vi5VFmgVpSczH3Y2gDgXbpO9ZivyOBwT2iCJHWG0CX UPKaa3a9dfFyY/SOif9ji24x4+aMRpH1niNLV7rYPLfxjsRLeoJzuuwOokNftlDNEiqLP10aODZBP sxZInVET5kfrRxgrMRQJaAFhS98kKLljV0SENNvAucxDDFA8/jaWeFO1aixdmHa8fxwG+cefI04+7 Qu0IqO/w==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08s-0038Kv-0d; Tue, 30 Jan 2024 20:15:58 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 27/29] selftests: ntsync: Add some tests for wakeup signaling via alerts. Date: Tue, 30 Jan 2024 20:13:54 -0600 Message-ID: <20240131021356.10322-28-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789571380113973875 X-GMAIL-MSGID: 1789571380113973875 Expand the alert tests to cover alerting a thread mid-wait, to test that the relevant scheduling logic works correctly. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 6c00a55909aa..09153d0686ac 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -1080,9 +1080,12 @@ TEST(wake_all) TEST(alert_any) { struct ntsync_event_args event_args = {0}; + struct ntsync_wait_args wait_args = {0}; struct ntsync_sem_args sem_args = {0}; __u32 index, count, signaled; + struct wait_args thread_args; int objs[2], fd, ret; + pthread_t thread; fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); ASSERT_LE(0, fd); @@ -1130,6 +1133,34 @@ TEST(alert_any) EXPECT_EQ(0, ret); EXPECT_EQ(2, index); + /* test wakeup via alert */ + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 123; + wait_args.index = 0xdeadbeef; + wait_args.alert = event_args.event; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ANY; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(2, wait_args.index); + close(event_args.event); /* test with an auto-reset event */ @@ -1166,9 +1197,12 @@ TEST(alert_any) TEST(alert_all) { struct ntsync_event_args event_args = {0}; + struct ntsync_wait_args wait_args = {0}; struct ntsync_sem_args sem_args = {0}; + struct wait_args thread_args; __u32 index, count, signaled; int objs[2], fd, ret; + pthread_t thread; fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); ASSERT_LE(0, fd); @@ -1202,6 +1236,34 @@ TEST(alert_all) EXPECT_EQ(0, ret); EXPECT_EQ(2, index); + /* test wakeup via alert */ + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 123; + wait_args.index = 0xdeadbeef; + wait_args.alert = event_args.event; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ALL; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + EXPECT_EQ(2, wait_args.index); + close(event_args.event); /* test with an auto-reset event */ From patchwork Wed Jan 31 02:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1634586dyb; Tue, 30 Jan 2024 18:47:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqTZztKZTt8grp+PtkxTEVW3J8k2InFnx5l3HfEYWrLXxuW5lmX5wGvMEF83eFMPRM1+a1 X-Received: by 2002:a05:651c:204d:b0:2cc:6fe2:4ddc with SMTP id t13-20020a05651c204d00b002cc6fe24ddcmr173312ljo.3.1706669222964; Tue, 30 Jan 2024 18:47:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706669222; cv=pass; d=google.com; s=arc-20160816; b=sst0hArTleTTJ6R7lJ4oa+6TGxDUiFj6n67A0dY+9j2NE2HyQA/5AhpoFQubxQbHH/ l+aBZnjxf286EB3/MPnSFsmUj6x+YuZf/qY/uT/sJmYLNFQmskMQXffEUDTo13BgEwXQ zBeOEgS+0Wjr+ct6wD9U/xr86rHdqj+ikPrK+eizsvA12PA3gtAJxchbsfIar5p0cxF3 Vd6cemDWHJwf5hKoInhdKu4cbDT1lb6QVpj0iW99qGhpae2R9J5DQIoeUmOYlhr0xUvn Uop3gbrmiF4Bu9B8TZfTnZw2iOWjgDS93Sw2AIeqlkmqAxK+VT7YqhH8hfBDSDkt7E9r 0Big== 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=kEY81ThKNufG032Um78kKWhIVAmyunZr7IiiHuV5wWQ=; fh=6hG6EQdUB1KamSHsQy0Eqe0FxPFkxGPPsTd0s0OOje8=; b=l1Bn/FYdGlWvWhI3IOvo0296WkXnzS0wXt5lgVvRUu5B93ki/c2cLDUKtISQT7syf/ beSCGZLSupGWKMLiFVAkoou15SDjx0zzi1s1CHfLbIRcieRu+hWkxG7psvWszif24kGh hIAcf7rMwDYcFBnXsPCGiMYO+ZCs0DQovl1sV+wEUXknNH1TiRWnIQmDaUMPppOEwFLe kWHqcQoJTGFmq6DO72DcPrTsu+APoCeYOWvT16EQOb2SbOdI8SwqfosWl43JRGCafa7y PF/wR2euPTFcYCEfi7DS5MQv0EkLTartB1K/PGGOGHM4kCo66F4Bm0P80T0jpS9UW4Is 6pDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=mDg24hho; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45658-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45658-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWSTYvZ0d2k5uT6nPAi10wv2ikbNbc0XVvWGLhWphyoCu1G3HTyFURBM1x9aX9uYVsfQlfZE1YAUC0eaqVy0xVr3TSMBA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g6-20020a056402428600b00554692561c1si5283170edc.242.2024.01.30.18.47.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:47:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45658-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=mDg24hho; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45658-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45658-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 5B3531F2A4B9 for ; Wed, 31 Jan 2024 02:23:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA6433DB97; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="mDg24hho" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 8ABB718AFA; Wed, 31 Jan 2024 02:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; cv=none; b=nwkflUmP3OBiT66gr+2BopuIOP1P/uvNg+XBAnrXSDxzbJlu4wHtvC8z9bJsbVfOwdtbohUVH2xYkBG2NM32+Wqjo7Y0zZ2Xg7k37LBSPFK48jWHlfWIB98k82MMPHJfFcXVix/LEl/nfWOFMlOrCrj5Usde1PGULGKq2jI99kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; c=relaxed/simple; bh=7B5CV9F4s4vjyjGFgVZxdU1S+iuE0jPD0kJ+jDAFB9A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tOjKXHLQApQBvFFp2Qg/Z7Cks0N+Z6EPnGTdgD63a5EW+YEqCQ+YTcHHJKpR75j6ILhSn9cvqSNkb7icZ2jHoF5l5EV8EMYDJeK4kAVq1eBANpNyLIgu+eQrr8rI9Jkrs8aGqj4YvERjIcEnRy2Ag94vAfFTnFeOi7qIx7SugIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=mDg24hho; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=kEY81ThKNufG032Um78kKWhIVAmyunZr7IiiHuV5wWQ=; b=mDg24hhoYo2z2gy9XUIyagUrTr vPPfaNvERLV7wmD+M29Y57TvqOTOyWR38WIpGW3YXk+aFQ9hEuoBK7+bzVnz0arEtripOxA/6Jjzh BsAd5iP2gMUlDgAYJB/GCCdRQ64Jss7E4Pg+3JGHxXNMCHxynPJnxtS2i7jAkoELWIA/yx0XEqj1n hOMBgjXlivXFw9L99q1dVsR1jlL8QcZYe/zka43g5Qpu+eXMKvbSclWbNGhyo0C/G3LANBjM9T//T pW3f2Z1GKSvsaiIYKTMd9BB6/UzethYwJ/puySGKKScxv6Vmt8WVNETK7Xyq8OlmXRuHdx52h7CjJ +wfC6WtQ==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08s-0038Kv-2C; Tue, 30 Jan 2024 20:15:58 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 28/29] maintainers: Add an entry for ntsync. Date: Tue, 30 Jan 2024 20:13:55 -0600 Message-ID: <20240131021356.10322-29-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572387520425431 X-GMAIL-MSGID: 1789572387520425431 Add myself as maintainer, supported by CodeWeavers. Signed-off-by: Elizabeth Figura --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8d1052fa6a69..7924127d351b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15585,6 +15585,15 @@ T: git https://github.com/Paragon-Software-Group/linux-ntfs3.git F: Documentation/filesystems/ntfs3.rst F: fs/ntfs3/ +NTSYNC SYNCHRONIZATION PRIMITIVE DRIVER +M: Elizabeth Figura +L: wine-devel@winehq.org +S: Supported +F: Documentation/userspace-api/ntsync.rst +F: drivers/misc/ntsync.c +F: include/uapi/linux/ntsync.h +F: tools/testing/selftests/drivers/ntsync/ + NUBUS SUBSYSTEM M: Finn Thain L: linux-m68k@lists.linux-m68k.org From patchwork Wed Jan 31 02:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1632984dyb; Tue, 30 Jan 2024 18:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHPcXIu3YG2RaWR99G775gQVQymKyP+iriW4OAVY4A92HfMrHSTVBfDxBhhw0dGa/ae8kG X-Received: by 2002:a19:6506:0:b0:511:171e:28a with SMTP id z6-20020a196506000000b00511171e028amr202006lfb.30.1706668892568; Tue, 30 Jan 2024 18:41:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668892; cv=pass; d=google.com; s=arc-20160816; b=dkbVntYPvMh9xypQsd8xuvG/dpbWO8Kl4+eJd3c5dHPnSBsHkmVil45ECH7/Ed9eo9 Pd+maTxr+N5A0eSAFXRqW2OsXukoKaWZqUNno9VuMUexsPmLDFt/ir0/QMB+mCMJXUWP ekOoQsIkQYJxfM41khclSeJqb8HoyHQJDmOWWBvbHYIzoiNnqBjc9YmJtd8803EQudhs slFepR9I3JXO9X5X8pg4BdWBUSqA+NxAQ8fG4XFAL/aFYhiPBMDrQc9hcIvlpf2vMzIy E02l7s39XfxHzuUd5mDyzgwlApH78wtZuFX+MRArXQGFz3Ba6hEWqJ4aWn95CSaFSLT3 AhIA== 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=K80ihujOREZkYym2AtMLKgCoT77UvCmld0M4kXW2kiw=; fh=V1okTuDWOJq8nHA8UmB5IXLSqpI3d/BCYHSNqyN1lSs=; b=l0AOGiL/3VNZzX+5p66ipziIl7jjGYTXc54l4sadWxRloUKAruKkyQbRXdPv+VkHt/ iBbNyFru9gihH0hrAzexornUzJ4dufIhEGCcBKuFi3jp5JBBNBvVJMlXQ0gOUinlIt1U WaJPD2GuKTH+yzZmKjVG+5TtKYt8uZ8BcQcgVaI8uPPRyR2PcUUizxCVZoB4sL7ouuAH whhVba7fp7yf85dIJxnTqU7ganRDp5YRBrEt76omAtNieCgbAEudiRT4sfa917XhWe6G Q4kgHNaxOiu9XXyVn1mxMpg5JOrsAHZk1+OC9YcmMrn76XmwJMX049GJMVTvk4xfExnR U6IA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=cefOX4HX; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45660-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45660-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWvra4TgMQodeasscu9KKdqn/i/EftECoc+J7Mk4Oksv+5IC0TqMVBv+B0/kqMXmurSVrSN25Mu5wVXHSKBqix3z7hdUA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j24-20020a170906051800b00a317ce4d313si5213589eja.723.2024.01.30.18.41.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:41:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45660-ouuuleilei=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=@codeweavers.com header.s=s1 header.b=cefOX4HX; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45660-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45660-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com 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 652671F2A9B1 for ; Wed, 31 Jan 2024 02:24:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97EBE3EA89; Wed, 31 Jan 2024 02:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="cefOX4HX" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 8AEC118AFB; Wed, 31 Jan 2024 02:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; cv=none; b=SpySqll+Nz9DBRKJdS8W/U5Bz7oDUe7wLMESK8hg60Il9d5FjdpqGBtpqKgqo/nIuXc0s1kCvAqSMVzsYCdLi1/pQJsy3yG8yNe2TosJnWgmTbhPuzufWTUOZ8zQXQG0Xmjfxh4ioPs7Ll95hWDkiVJESQd7va+OtRPcpN8M3Go= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667370; c=relaxed/simple; bh=2IVyPvDYPyVF69rC7SvAChwUNS5jjHRV3pawNxVTgo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IPJm4hh2Sl7qu0VtLUxmR9OEFZcgMYnVdNeVuoZpC0gpdGVnUvKHpGY7o4U7HMYzE3WTOBmG9CzvV6uUw2JKDQLit5I0kkrrF9v7l+flOZwqz0obbietnyCvvhGOcvaimmGmQ0T1iEjLoMN1Q3vxt9tdywHoQ0tHfljcc8/gj5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=cefOX4HX; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=K80ihujOREZkYym2AtMLKgCoT77UvCmld0M4kXW2kiw=; b=cefOX4HXahFzG8KCR8tlvhcz0C IHpIVfbwBmsLcq+Ljiv7hX1ZL/D2UAQfForRH5yZGia4t+NHjT4OJm3zVoq2r7Re+3v0r70KO4pHW RLKkbuwDkubp9NWiwEdWuMMe8ATd3QZBIOawNP0WNJA9KA7jK58ET6cwpgNy7UUQX7+vE7h5fadOP ZnuCHMxHoZ87kCZ2sUQ+n1TIdk81RvXNCtAlj+ZJUK318cJVO1TqE85JGxjvQ+JpitNqoMtzLS4gx ruG2faguZ08E3bc/6JU9nIS8XGwwg6cPTRqcWx0TLF5ZVKn4EvH/3my4ZaPNy+YBa7m7/6FWrpQBJ lk4qh22g==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08t-0038Kv-04; Tue, 30 Jan 2024 20:15:59 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 29/29] docs: ntsync: Add documentation for the ntsync uAPI. Date: Tue, 30 Jan 2024 20:13:56 -0600 Message-ID: <20240131021356.10322-30-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789572040629967711 X-GMAIL-MSGID: 1789572040629967711 Add an overall explanation of the driver architecture, and complete and precise specification for its intended behaviour. Signed-off-by: Elizabeth Figura --- Documentation/userspace-api/index.rst | 1 + Documentation/userspace-api/ntsync.rst | 390 +++++++++++++++++++++++++ 2 files changed, 391 insertions(+) create mode 100644 Documentation/userspace-api/ntsync.rst diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst index 09f61bd2ac2e..f5a72ed27def 100644 --- a/Documentation/userspace-api/index.rst +++ b/Documentation/userspace-api/index.rst @@ -34,6 +34,7 @@ place where this information is gathered. tee isapnp dcdbas + ntsync .. only:: subproject and html diff --git a/Documentation/userspace-api/ntsync.rst b/Documentation/userspace-api/ntsync.rst new file mode 100644 index 000000000000..bda9401f6747 --- /dev/null +++ b/Documentation/userspace-api/ntsync.rst @@ -0,0 +1,390 @@ +=================================== +NT synchronization primitive driver +=================================== + +This page documents the user-space API for the ntsync driver. + +ntsync is a support driver for emulation of NT synchronization +primitives by user-space NT emulators. It exists because implementation +in user-space, using existing tools, cannot match Windows performance +while offering accurate semantics. It is implemented entirely in +software, and does not drive any hardware device. + +This interface is meant as a compatibility tool only, and should not +be used for general synchronization. Instead use generic, versatile +interfaces such as futex(2) and poll(2). + +Synchronization primitives +========================== + +The ntsync driver exposes three types of synchronization primitives: +semaphores, mutexes, and events. + +A semaphore holds a single volatile 32-bit counter, and a static 32-bit +integer denoting the maximum value. It is considered signaled when the +counter is nonzero. The counter is decremented by one when a wait is +satisfied. Both the initial and maximum count are established when the +semaphore is created. + +A mutex holds a volatile 32-bit recursion count, and a volatile 32-bit +identifier denoting its owner. A mutex is considered signaled when its +owner is zero (indicating that it is not owned). The recursion count is +incremented when a wait is satisfied, and ownership is set to the given +identifier. + +A mutex also holds an internal flag denoting whether its previous owner +has died; such a mutex is said to be abandoned. Owner death is not +tracked automatically based on thread death, but rather must be +communicated using ``NTSYNC_IOC_MUTEX_KILL``. An abandoned mutex is +inherently considered unowned. + +Except for the "unowned" semantics of zero, the actual value of the +owner identifier is not interpreted by the ntsync driver at all. The +intended use is to store a thread identifier; however, the ntsync +driver does not actually validate that a calling thread provides +consistent or unique identifiers. + +An event holds a volatile boolean state denoting whether it is signaled +or not. There are two types of events, auto-reset and manual-reset. An +auto-reset event is designaled when a wait is satisfied; a manual-reset +event is not. The event type is specified when the event is created. + +Unless specified otherwise, all operations on an object are atomic and +totally ordered with respect to other operations on the same object. + +Objects are represented by files. When all file descriptors to an +object are closed, that object is deleted. + +Char device +=========== + +The ntsync driver creates a single char device /dev/ntsync. Each file +description opened on the device represents a unique instance intended +to back an individual NT virtual machine. Objects created by one ntsync +instance may only be used with other objects created by the same +instance. + +ioctl reference +=============== + +All operations on the device are done through ioctls. There are four +structures used in ioctl calls:: + + struct ntsync_sem_args { + __u32 sem; + __u32 count; + __u32 max; + }; + + struct ntsync_mutex_args { + __u32 mutex; + __u32 owner; + __u32 count; + }; + + struct ntsync_event_args { + __u32 event; + __u32 signaled; + __u32 manual; + }; + + struct ntsync_wait_args { + __u64 timeout; + __u64 objs; + __u32 count; + __u32 owner; + __u32 index; + __u32 alert; + }; + +Depending on the ioctl, members of the structure may be used as input, +output, or not at all. All ioctls return 0 on success. + +The ioctls on the device file are as follows: + +.. c:macro:: NTSYNC_IOC_CREATE_SEM + + Create a semaphore object. Takes a pointer to struct + :c:type:`ntsync_sem_args`, which is used as follows: + + .. list-table:: + + * - ``sem`` + - On output, contains a file descriptor to the created semaphore. + * - ``count`` + - Initial count of the semaphore. + * - ``max`` + - Maximum count of the semaphore. + + Fails with ``EINVAL`` if ``count`` is greater than ``max``. + +.. c:macro:: NTSYNC_IOC_CREATE_MUTEX + + Create a mutex object. Takes a pointer to struct + :c:type:`ntsync_mutex_args`, which is used as follows: + + .. list-table:: + + * - ``mutex`` + - On output, contains a file descriptor to the created mutex. + * - ``count`` + - Initial recursion count of the mutex. + * - ``owner`` + - Initial owner of the mutex. + + If ``owner`` is nonzero and ``count`` is zero, or if ``owner`` is + zero and ``count`` is nonzero, the function fails with ``EINVAL``. + +.. c:macro:: NTSYNC_IOC_CREATE_EVENT + + Create an event object. Takes a pointer to struct + :c:type:`ntsync_event_args`, which is used as follows: + + .. list-table:: + + * - ``event`` + - On output, contains a file descriptor to the created event. + * - ``signaled`` + - If nonzero, the event is initially signaled, otherwise + nonsignaled. + * - ``manual`` + - If nonzero, the event is a manual-reset event, otherwise + auto-reset. + +The ioctls on the individual objects are as follows: + +.. c:macro:: NTSYNC_IOC_SEM_POST + + Post to a semaphore object. Takes a pointer to a 32-bit integer, + which on input holds the count to be added to the semaphore, and on + output contains its previous count. + + If adding to the semaphore's current count would raise the latter + past the semaphore's maximum count, the ioctl fails with + ``EOVERFLOW`` and the semaphore is not affected. If raising the + semaphore's count causes it to become signaled, eligible threads + waiting on this semaphore will be woken and the semaphore's count + decremented appropriately. + +.. c:macro:: NTSYNC_IOC_MUTEX_UNLOCK + + Release a mutex object. Takes a pointer to struct + :c:type:`ntsync_mutex_args`, which is used as follows: + + .. list-table:: + + * - ``mutex`` + - Ignored. + * - ``owner`` + - Specifies the owner trying to release this mutex. + * - ``count`` + - On output, contains the previous recursion count. + + If ``owner`` is zero, the ioctl fails with ``EINVAL``. If ``owner`` + is not the current owner of the mutex, the ioctl fails with + ``EPERM``. + + The mutex's count will be decremented by one. If decrementing the + mutex's count causes it to become zero, the mutex is marked as + unowned and signaled, and eligible threads waiting on it will be + woken as appropriate. + +.. c:macro:: NTSYNC_IOC_SET_EVENT + + Signal an event object. Takes a pointer to a 32-bit integer, which on + output contains the previous state of the event. + + Eligible threads will be woken, and auto-reset events will be + designaled appropriately. + +.. c:macro:: NTSYNC_IOC_RESET_EVENT + + Designal an event object. Takes a pointer to a 32-bit integer, which + on output contains the previous state of the event. + +.. c:macro:: NTSYNC_IOC_PULSE_EVENT + + Wake threads waiting on an event object while leaving it in an + unsignaled state. Takes a pointer to a 32-bit integer, which on + output contains the previous state of the event. + + A pulse operation can be thought of as a set followed by a reset, + performed as a single atomic operation. If two threads are waiting on + an auto-reset event which is pulsed, only one will be woken. If two + threads are waiting a manual-reset event which is pulsed, both will + be woken. However, in both cases, the event will be unsignaled + afterwards, and a simultaneous read operation will always report the + event as unsignaled. + +.. c:macro:: NTSYNC_IOC_READ_SEM + + Read the current state of a semaphore object. Takes a pointer to + struct :c:type:`ntsync_sem_args`, which is used as follows: + + .. list-table:: + + * - ``sem`` + - Ignored. + * - ``count`` + - On output, contains the current count of the semaphore. + * - ``max`` + - On output, contains the maximum count of the semaphore. + +.. c:macro:: NTSYNC_IOC_READ_MUTEX + + Read the current state of a mutex object. Takes a pointer to struct + :c:type:`ntsync_mutex_args`, which is used as follows: + + .. list-table:: + + * - ``mutex`` + - Ignored. + * - ``owner`` + - On output, contains the current owner of the mutex, or zero + if the mutex is not currently owned. + * - ``count`` + - On output, contains the current recursion count of the mutex. + + If the mutex is marked as abandoned, the function fails with + ``EOWNERDEAD``. In this case, ``count`` and ``owner`` are set to + zero. + +.. c:macro:: NTSYNC_IOC_READ_EVENT + + Read the current state of an event object. Takes a pointer to struct + :c:type:`ntsync_event_args`, which is used as follows: + + .. list-table:: + + * - ``event`` + - Ignored. + * - ``signaled`` + - On output, contains the current state of the event. + * - ``manual`` + - On output, contains 1 if the event is a manual-reset event, + and 0 otherwise. + +.. c:macro:: NTSYNC_IOC_KILL_OWNER + + Mark a mutex as unowned and abandoned if it is owned by the given + owner. Takes an input-only pointer to a 32-bit integer denoting the + owner. If the owner is zero, the ioctl fails with ``EINVAL``. If the + owner does not own the mutex, the function fails with ``EPERM``. + + Eligible threads waiting on the mutex will be woken as appropriate + (and such waits will fail with ``EOWNERDEAD``, as described below). + +.. c:macro:: NTSYNC_IOC_WAIT_ANY + + Poll on any of a list of objects, atomically acquiring at most one. + Takes a pointer to struct :c:type:`ntsync_wait_args`, which is + used as follows: + + .. list-table:: + + * - ``timeout`` + - Absolute timeout in nanoseconds, measured against the + MONOTONIC clock. If the timeout is equal to or earlier than + the current time, the function returns immediately without + sleeping. If ``timeout`` is U64_MAX, the function will sleep + until an object is signaled, and will not fail with + ``ETIMEDOUT``. + * - ``objs`` + - Pointer to an array of ``count`` file descriptors + (specified as an integer so that the structure has the same + size regardless of architecture). If any object is + invalid, the function fails with ``EINVAL``. + * - ``count`` + - Number of objects specified in the ``objs`` array. + If greater than ``NTSYNC_MAX_WAIT_COUNT``, the function fails + with ``EINVAL``. + * - ``owner`` + - Mutex owner identifier. If any object in ``objs`` is a mutex, + the ioctl will attempt to acquire that mutex on behalf of + ``owner``. If ``owner`` is zero, the ioctl fails with + ``EINVAL``. + * - ``index`` + - On success, contains the index (into ``objs``) of the object + which was signaled. If ``alert`` was signaled instead, + this contains ``count``. + * - ``alert`` + - Optional event object file descriptor. If nonzero, this + specifies an "alert" event object which, if signaled, will + terminate the wait. If nonzero, the identifier must point to a + valid event. + + This function attempts to acquire one of the given objects. If unable + to do so, it sleeps until an object becomes signaled, subsequently + acquiring it, or the timeout expires. In the latter case the ioctl + fails with ``ETIMEDOUT``. The function only acquires one object, even + if multiple objects are signaled. + + A semaphore is considered to be signaled if its count is nonzero, and + is acquired by decrementing its count by one. A mutex is considered + to be signaled if it is unowned or if its owner matches the ``owner`` + argument, and is acquired by incrementing its recursion count by one + and setting its owner to the ``owner`` argument. An auto-reset event + is acquired by designaling it; a manual-reset event is not affected + by acquisition. + + Acquisition is atomic and totally ordered with respect to other + operations on the same object. If two wait operations (with different + ``owner`` identifiers) are queued on the same mutex, only one is + signaled. If two wait operations are queued on the same semaphore, + and a value of one is posted to it, only one is signaled. The order + in which threads are signaled is not specified. + + If an abandoned mutex is acquired, the ioctl fails with + ``EOWNERDEAD``. Although this is a failure return, the function may + otherwise be considered successful. The mutex is marked as owned by + the given owner (with a recursion count of 1) and as no longer + abandoned, and ``index`` is still set to the index of the mutex. + + The ``alert`` argument is an "extra" event which can terminate the + wait, independently of all other objects. If members of ``objs`` and + ``alert`` are both simultaneously signaled, a member of ``objs`` will + always be given priority and acquired first. + + It is valid to pass the same object more than once, including by + passing the same event in the ``objs`` array and in ``alert``. If a + wakeup occurs due to that object being signaled, ``index`` is set to + the lowest index corresponding to that object. + + The function may fail with ``EINTR`` if a signal is received. + +.. c:macro:: NTSYNC_IOC_WAIT_ALL + + Poll on a list of objects, atomically acquiring all of them. Takes a + pointer to struct :c:type:`ntsync_wait_args`, which is used + identically to ``NTSYNC_IOC_WAIT_ANY``, except that ``index`` is + always filled with zero on success if not woken via alert. + + This function attempts to simultaneously acquire all of the given + objects. If unable to do so, it sleeps until all objects become + simultaneously signaled, subsequently acquiring them, or the timeout + expires. In the latter case the ioctl fails with ``ETIMEDOUT`` and no + objects are modified. + + Objects may become signaled and subsequently designaled (through + acquisition by other threads) while this thread is sleeping. Only + once all objects are simultaneously signaled does the ioctl acquire + them and return. The entire acquisition is atomic and totally ordered + with respect to other operations on any of the given objects. + + If an abandoned mutex is acquired, the ioctl fails with + ``EOWNERDEAD``. Similarly to ``NTSYNC_IOC_WAIT_ANY``, all objects are + nevertheless marked as acquired. Note that if multiple mutex objects + are specified, there is no way to know which were marked as + abandoned. + + As with "any" waits, the ``alert`` argument is an "extra" event which + can terminate the wait. Critically, however, an "all" wait will + succeed if all members in ``objs`` are signaled, *or* if ``alert`` is + signaled. In the latter case ``index`` will be set to ``count``. As + with "any" waits, if both conditions are filled, the former takes + priority, and objects in ``objs`` will be acquired. + + Unlike ``NTSYNC_IOC_WAIT_ANY``, it is not valid to pass the same + object more than once, nor is it valid to pass the same object in + ``objs`` and in ``alert``. If this is attempted, the function fails + with ``EINVAL``.