Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp666491rdb; Thu, 15 Feb 2024 11:22:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUS6t+y8GpxMXBQ4CIFkpTQ3xvo6w/XOqup1OlIbV87sUsoLapSaP/cgEssl6YsU5HkYv54xmaMit9zFRGk2y7JhwDw7xDZKttqPL0Y2A== X-Google-Smtp-Source: AGHT+IFK6EemSKTvaSWBmrLMZtzAoVoE6kHw75YQ0itF4DSFHOgZ2LNa/GdLCPNoacCKSFa3h05a X-Received: by 2002:a17:903:2307:b0:1d9:9e4f:c0c8 with SMTP id d7-20020a170903230700b001d99e4fc0c8mr3667443plh.18.1708024939853; Thu, 15 Feb 2024 11:22:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708024939; cv=pass; d=google.com; s=arc-20160816; b=P6lx34bM2xcoOuMD1vvL8pvB0SYvcsPYZsz5mv3kLWD67eATLe63Sla570vj0T6Zlz q4mH+IUKo/xMknwANAGWlJqylLXKhNDXLqe36xXz0JtA4nBvwSDbrUUR/VZBUVUY5yH7 ujn9RuZd3oRxxSLRi0HfHVoVIusZUJy4cDFjpDtlG2v01CPiqtFkRzVGk84reYQ3Ix4B 0EHGJpwGU0cSKUuO7alQ/L2VLXfykOUVvBBpnBzdO1IY3k5XpEtN47vhB8/Q9bWLk749 kwBK9xanuH6rueKL4giDiOOSFK72uum30xp7lEM9A4e53EYNHCXJLiICIpni3/PCE6GB Z4AA== 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=EswZ6wqtyT9+dG9fdNUkq4Y5N/Agv4gLkmDHefAesOQ=; fh=+QLQnCaKHe3ryQAcb3Bb74FYPehh+OncWnv5LsDqsBI=; b=rw9BWooKKooNK9zJlJW5iMFKB6PP7S4oNrY+2ggJ1hOKHvSeMc1rRgTO7P61rQ4tP/ cA3s08Czz64wdpmoOtwGxJEsjU+ISHov+XzfOWqUFN6ASjU2jMxr+/uFekSMXs/ZCkDp pgluP4MEXbbrrHv4IH+175FjFTDSA8TXS95fBSzJbi0uocxUFQ8jTqNujs8ObZwQKqmc rZ3KbUl6OdYt6Q3qiaIgxfLXxWgdTq3l4A8i9ekZEVDM4HWVKiExcXXszXO6DxosHLA6 EZhJtZV5BJD4vibQoJFpMxkRFF1vIPzs5K0zgEha3onSx92N4x8LyH7SJ4Z7RBqiCZR/ gZ/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=q0+Dxvfm; 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-67568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p19-20020a637413000000b005dc430e6e30si1585649pgc.788.2024.02.15.11.22.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 11:22:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67568-linux.lists.archive=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=q0+Dxvfm; 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-67568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67568-linux.lists.archive=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 6CE8D2869D4 for ; Thu, 15 Feb 2024 19:22:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA0EF13959C; Thu, 15 Feb 2024 19:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="q0+Dxvfm" 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 72B5B136983; Thu, 15 Feb 2024 19:22:05 +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=1708024927; cv=none; b=OXGvTUfhQaMNqF0L+OL0TsSwIz54defgyaTdIMCqWD77olLb+k3NhBhnanK7eOkdvrA4AdrPD5HwaEyyVxchrZYpMBR6uIeQXfduCNCOG1c4lZKyrzRXGuLg/USFZ45d0X0lExmn+bfCYBlbduLxb2aArEpBGY5djbut2waifxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708024927; c=relaxed/simple; bh=CBp2D/DDv0XKJPrPwReIWJc4I2Sf+kTEZIl+XqHMYHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DjRDASE0u6hKCr8WLQNMJhTe20q9VGiDT3W4fXxAQQBzfkQVDQyiygDDml2Ms+I4jn3n+ArGTBQTBHX3aCgzXXYXDtwNU0Nni3z+D96QqSZhusVyzpTuXlLYn4h4oX0bHwIuNRKbdsUkIwEz5GQ4pMWmMwz+A7PQkU/UX+wm4q8= 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=q0+Dxvfm; 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=EswZ6wqtyT9+dG9fdNUkq4Y5N/Agv4gLkmDHefAesOQ=; b=q0+Dxvfmb/LkUUTBEx+LmnSfZl dddyNRKg/YAdOo8KtDqpogC2VAAub11Sl2cVL4bkrzFNrTxTGl9KUI5FBgczT1N+FEphfrECMwNuB zMKY1abXbiveB7kA05ZsApLo8gVfq3e4NV1bdWp0vKvk0LRDmD/cIPpmeaodSt9B7MX2aNyBVlkki CrQxHEySb1e1PAPaP6AC+ZhTxLPlaFU6XebhIuvyrWhYGHJncO92/sMD9p3e+eE96+HWvxzCPgqUf xqKpITGLAv/nT55SjaNTgxVJgIZ7aBWjZm/+k3Du+qB0Zm1orSxXCGEzWbkCo62BueuHIXhwezyUe q0Izqh/Q==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.localnet) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rahJ4-00HKoO-0e; Thu, 15 Feb 2024 13:22:02 -0600 From: Elizabeth Figura To: Greg Kroah-Hartman Cc: Arnd Bergmann , Jonathan Corbet , Shuah Khan , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?ISO-8859-1?Q?Andr=E9?= Almeida , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 02/31] ntsync: Introduce NTSYNC_IOC_CREATE_SEM. Date: Thu, 15 Feb 2024 13:22:01 -0600 Message-ID: <13452408.uLZWGnKmhe@camazotz> In-Reply-To: <2024021533-thicken-handed-7d2d@gregkh> References: <20240214233645.9273-1-zfigura@codeweavers.com> <20240214233645.9273-3-zfigura@codeweavers.com> <2024021533-thicken-handed-7d2d@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Thursday, 15 February 2024 01:28:32 CST Greg Kroah-Hartman wrote: > On Wed, Feb 14, 2024 at 05:36:38PM -0600, Elizabeth Figura wrote: > > 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; > > +}; > > No reference counting is needed for your ntsync_device? Or are you > relying on the reference counting of struct file here? > > You pass around pointers to this structure, and save it off into other > structures, how do you know it is "safe" to do so? Yes, this relies on the reference counting of struct file. The sync objects (semaphore etc.) grab a reference when they're created, via get_file(), and release it when they're destroyed. This reference is taken from within ioctls on the ntsync_device, so the file must be valid when we grab a reference. Maybe I'm missing something, though?