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