From patchwork Mon Dec 9 18:58: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: 848518 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 95A80199939; Mon, 9 Dec 2024 19:02:51 +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=1733770973; cv=none; b=ElBU+7CrlgL9PabnFj7jPtsq/vGXpv2Av9KYC0aVZVRf2mwpr+iedEmmj6HydaWRYAbunGGnc89eMODXbq8e7g2f8aMmAtuQ78pT706kjJIClPlBsQT0gndZeBiW8Z89HXAziGBfCxdRjk/avJGoiCcOGQ/5OzCnZ3x12dp9GyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733770973; c=relaxed/simple; bh=sp6FSdlHM8fF2HY/TPn0ZTbgpJUAdwmTjQm0HETkswg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kID0A64RROtof+q6TCcHKArzUxgjO6yqAOXVB9KTpHWm/XSiBfHM/BbcSauJm6S91P8H8/YS0bijwi7pexOjXwFRaLEdpIZGMKFYJSFsuaynYUzyEfxEQsVNkvvNWbY8FMPMAzE/cROMUnMIy3wBUyScE+Xb6lobV8Ry11w9I64= 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=ZJJSQIHW; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="ZJJSQIHW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=r14OW/cQ6BfRX3OgHtXVyjlxZmpfc7UvZouqcnu3iHY=; b=ZJJSQIHW7kzl+ISYs72ZrzeYkI K7rnmXyuangva3etXUnFoxrvgL3W1QTVLpZUn69IEOeVeJNZibOpxtbvQbV1Smpofm9+JWJu9uYI4 XGQvyckwirP9eV6m5u9TB1GGpOI4LPpd+QJmHGYMA7s2XJYmGfhv6S/v2d9bLMhqJE0ExaNk3x5ph cUpZ4KxIPIDqTVPDX7z3UxUGGkoCd27EcNV6zkvqDEb4ZU3Lgl2HInY99d3McKYOf7oM1tIExLQxx kAPTMXz2dXoGT6/LDWw69Us1kddpuEzx7WHrTp8rF3kMEJoJKKJsQTNMXwRij4hBFE4ggEu3UOYeI GDxKGNhw==; 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 1tKiyb-001Gd5-09; Mon, 09 Dec 2024 12:59:25 -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, Randy Dunlap , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Elizabeth Figura Subject: [PATCH v6 11/28] ntsync: Introduce NTSYNC_IOC_MUTEX_READ. Date: Mon, 9 Dec 2024 12:58:47 -0600 Message-ID: <20241209185904.507350-12-zfigura@codeweavers.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241209185904.507350-1-zfigura@codeweavers.com> References: <20241209185904.507350-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 28 ++++++++++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index d6e8a4bde1d0..cff2627c1efe 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -607,6 +607,32 @@ 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_device *dev = mutex->dev; + struct ntsync_mutex_args args; + bool all; + int ret; + + if (mutex->type != NTSYNC_TYPE_MUTEX) + return -EINVAL; + + args.mutex = 0; + + all = ntsync_lock_obj(dev, mutex); + + args.count = mutex->u.mutex.count; + args.owner = mutex->u.mutex.owner; + ret = mutex->u.mutex.ownerdead ? -EOWNERDEAD : 0; + + ntsync_unlock_obj(dev, mutex, all); + + 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; @@ -632,6 +658,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 5e922703686f..eced73d08783 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -55,5 +55,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