From patchwork Mon Feb 19 22:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 203329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp78014dyc; Mon, 19 Feb 2024 14:50:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUdVy43ZT2573vydRiYQTmzwYVJhOE1GRir5oY6KW0rz9yEjgEGZWND3VmkM56oJ6wZUU2gblLCWAAW0zXiI+vcWgdDzg== X-Google-Smtp-Source: AGHT+IEwFgVlOiRSiMZGBs4GX8Kn6dNX4IkG5hXX7VNgm69NPbFjNIybaMYqvvs1T3v5X9vzvJby X-Received: by 2002:a05:6870:a9a5:b0:21e:a40e:7465 with SMTP id ep37-20020a056870a9a500b0021ea40e7465mr7445722oab.24.1708383020244; Mon, 19 Feb 2024 14:50:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708383020; cv=pass; d=google.com; s=arc-20160816; b=wN8wmZsqkbenRIKBStVpU8SULG17sJaH8tryF52nTh9LspLvxzRqEqbcpZtP5NzpoS jJnswagqQft5vF6j7lnPcLBgouE/oCBsTi0NzL7Xz/+kajYkzNotQ5HnG5qslkZf9Sky Rq+9dH6+o1fhI0CG+EwWimpcx7OZ4y5nlJXmFxgrCEpX+c5CmpG6GVCXNspp4wq79eKp rgdfPTqfuIT01NlDwsVv/eoDDBU5U4qnkqCs4kD3bzGPjNJ0MLx6ssy5dq/XWyeUmh5P tL3ytUNfbzwxBgCylLLPHmgdlVqCftgOUwlRR/kkt3AGoMQFbXudU4mOZCgXGSMS0Tw+ v5XQ== 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=318iLk4qhgnvG3UCB4Cli5m+symGF/f8He5a8Oh6z/w=; fh=hR3Xqo6s6FufP5gEw1XgbtLHrluZu7hd5XGp+hLIfiM=; b=I8/rOkBwZmMrxwiudE0yx6hzqKaKGoDvbi4VZxHWWzEZLJEI+ze74TsG3jkbr+lEIQ WJHbPR9fFWP4TiVwhf9+Y1Xyvb6ZsFVdDiqPRC38q6w7z+CIcqwdjqWxjmgicn/6rmGL 9gmBHz9Xyc3TWJLVFBODSM6lhfPh5mpGcZ/cQR6z28OzlIng6RWPrDyQd0bFuEY1qgQ4 RfmVOn1HoBQyLbcUvnCE2eRRuALGhQoEiKbFj5HrTo3SdKejKfZuvT6KvXP2yV5xFaiy 26Bqs6hE7iGrDiz0uUlyuBt5JPlxrULbHQsHqh4XmnZsKDmGda1mz5v2ImrrsqATp5Ue N68g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=YDeIS2RY; 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-72078-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72078-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k185-20020a6324c2000000b005cd7c92f504si4959079pgk.481.2024.02.19.14.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:50:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72078-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=YDeIS2RY; 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-72078-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72078-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 58EC0286475 for ; Mon, 19 Feb 2024 22:41:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F26E5BAFD; Mon, 19 Feb 2024 22:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="YDeIS2RY" 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 E8C5B55E75; Mon, 19 Feb 2024 22:39:35 +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=1708382378; cv=none; b=LOCVBEi8Y66pza72+erwteMDMxpaAahs9cqYwjtPTALiOmGtdKVxE4NRlWuW5YKYHEGsQ6yJy8uqN7j8jY1XBzATW1YclIZWIwNo3xGU/k57gOBAyh9+O/dlgwSLpqHIJIfJ6kxHVrhGNImpBTeom0g1j4RSuVlUojyvPrfmY2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708382378; c=relaxed/simple; bh=8vChgnZcciRVIn4A4k5nT/+5cnSjuxpcKRkohbyTjM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S0QHNMxhAE1iZ6psQG3lPlo7BGPWvi6ppIEjg90qoaeT3Uux1aoRKYJ3u9NJEgRCQlfzyWWwbACc3VqKlbG3x79Uin87ZxNSVikDYgDHJ+5Nz8JNZVIkOzKbcq96/vVJ+taqeyrHUE1NGLnoEzTkPOLjUX76mIy+c2DMdNxWTDs= 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=YDeIS2RY; 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=318iLk4qhgnvG3UCB4Cli5m+symGF/f8He5a8Oh6z/w=; b=YDeIS2RYr+xKUT8prN4JFPKzg3 LGg1VkcbH53dXhRCt65geIPsHQiPqBTE5Od1S+mLwWA7ZcOeZr+iJhGZJPokHeU76xOXrihvhSsN2 mha7HNZrQ+cSNUCecj/asvwPbRFzM6XW2gNldw71TTQtTQa8+P/C8XZLXqvNnzw+5QvmoLtsUdctk k1DydH9qrW6dk6aVS5eB9jvCLzJ5MVgg4eCxdMb7Aao3tN59P4710yg9GC/vjlsz63WhMqZbhj7Bb DSLvAB6VawHLodLS8a6wr/2o2sVEuQToG3I3KrqVcguTt9DHVOOr+jwQnAMGlmoei4T/Fj68gBVp3 dNDqNEJg==; 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 1rcCIN-0037Oz-0P; Mon, 19 Feb 2024 16:39:31 -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 , Elizabeth Figura Subject: [PATCH v2 14/31] ntsync: Introduce NTSYNC_IOC_MUTEX_READ. Date: Mon, 19 Feb 2024 16:38:16 -0600 Message-ID: <20240219223833.95710-15-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219223833.95710-1-zfigura@codeweavers.com> References: <20240219223833.95710-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: 1791369433878514782 X-GMAIL-MSGID: 1791369433878514782 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 0daaeeeba051..b07510035c1f 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -547,6 +547,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; @@ -572,6 +593,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 42f51dc4e57e..25f3296cfabf 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