From patchwork Wed Feb 14 23:52: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: 201189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp62061dyb; Wed, 14 Feb 2024 15:58:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrllcDIic97zcMEvaz0HnvxhpycTusA5RreKTkft05xqI0L5atnGHGIFRFWlIJfCZdQnOGDty0GDpIoyWFLe5328HgwQ== X-Google-Smtp-Source: AGHT+IGw9YWDxxBiooCPxmkjX75Y9/7XGiroE1kTfQAl9V//ctWNYjf+ZcddplmhnmyXuFbD59KA X-Received: by 2002:a2e:8e77:0:b0:2d0:a6d3:56c6 with SMTP id t23-20020a2e8e77000000b002d0a6d356c6mr105533ljk.32.1707955082292; Wed, 14 Feb 2024 15:58:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955082; cv=pass; d=google.com; s=arc-20160816; b=YwAiALG3fPr2Ci4QP93uIrfnNQ0XWPEh+iFd+5itUJNyYG7wj+Y+D1QqdPT1/hwj0Q 9JRdAcMFwwCjOQDk8LYhlE6smbgLqPTjC177PygNDpeRp7t66hMs92Hwg099z0Px84ux +VbXKYA7Cc0RXcbOh8G5B9BPVhc8UZt55xvqYiTqSYTxr7mQPoYnNWIhqNP6HBMyE8Tt ek8mtPoJg2XqV6FEOtD2JbOmrxpKZMy3m0TnCSccvX2jF2p6Yq/4PFauOBxm4YktIST6 bAFTj367cndjJFjgSQ+bi9LsKXODF/9P52gnNDaHAkA2rP30Zn/RI4TKT7Ptn5/7s7AY 6DvQ== 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=38M0BRywykSfrPjqrIMMa7pA+nqCF6Vo5IqJFLs5TlI=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=r35JMcOQ8lcgYAfkIowRaqhip/FoggLHZjwQY8GN6cCVBqMcDku6NoA83FSSe7av2R QDrQiRqQL1BzxCr7DZhi/oj91P+yu8JYqQvQ2uWPx0J2/Yab+1CWXxYEY1akyAEc4GjY HGlhQj1AY46/SG7PDL4mZIvnuApzkNpipOsAQMd/xxtgjlIL0ecrWOht4F0vZfC1C9tC QTfoyMzTyfdVm2HxGmF23VRK+bcpdnZMKhpQxouixs4vT7C9jLgWM+178XEw9SLeZHbZ 39jpQXfkURzAGAEypb3QEkInHD3lHxfdNGO0SX0Fo6LkTa0etMOtKvJLx+Dnz2bV+P2k sBFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=FkwuwuiO; 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-66152-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66152-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r16-20020a056402035000b00560c8889cfcsi37766edw.280.2024.02.14.15.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:58:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66152-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=FkwuwuiO; 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-66152-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66152-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 842011F2252B for ; Wed, 14 Feb 2024 23:57:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63BC014A4CD; Wed, 14 Feb 2024 23:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="FkwuwuiO" 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 22C741487FA; Wed, 14 Feb 2024 23:53:37 +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=1707954819; cv=none; b=igYhffPJgUKXYBbs+v/21JlRZrx4KYkqwRajUEwfdRH4hQ0V0mxIGlN7J9wbkV5XrtjvjNiSIA1D5iVZPK+O6H23QcCfPCGiAoHbE4ZrmZCRF6726TqTRhOErLcoBDiF05WIOZZT4a7My9ro70a+mQDmqcQyZSgxfH6Cm0ihP44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954819; c=relaxed/simple; bh=aBdrEJ9OoB7TRKIOn6djUqNQcuFcE/19mZ3vUSewMWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jyiF7WHzhiHUK1XtFHEAWq8C5Yf0N32gRmViPxIZbebK0pPGVCpVi9PC/PFnIoH0LFzRAaCPTQg0py/EwPyJswWmn5ydaPmFoRBD5rJ+7py7rhp86t+BsC10hGzixD0T7JmZTe2glKIHVyZl8j6N0rN3lYp3Yhj09uLQNKEyugc= 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=FkwuwuiO; 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=38M0BRywykSfrPjqrIMMa7pA+nqCF6Vo5IqJFLs5TlI=; b=FkwuwuiO3cvXXaJgkbKStjEbOa CPxS+dprY1NOaHTBE4HePTIl41Lf2/oSkyR0j33yTzzBAIOm400uc6aR0VYfiCNLha7j9n4+xhvjn ucFQ9SFztf8htvJFg31Wq7MvvikBSvSOwGPNcWYOzrNZxwESKxbvWAkNZR0/nvLPmmcHwLrbFPfyz HEwUza1kfrl6ivN6DkYT8vbXu/2E9bZdZ76LUQX5W7QPCZHhCpdU3UpS1bCADVHlv+sJ/BVOZH397 WOI6kYpdfo9r2PdXKyaEGvwBQTtQkVb1d3kCtQmaSCTe4QwHeqwLxnU4WxSnlsawn2gB1hNoKYJJR 9S69igyg==; 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 1raP4H-00GcSK-2B; Wed, 14 Feb 2024 17:53:33 -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: [PATCH 17/31] ntsync: Allow waits to use the REALTIME clock. Date: Wed, 14 Feb 2024 17:52:52 -0600 Message-ID: <20240214235307.10494-8-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214235307.10494-1-zfigura@codeweavers.com> References: <20240214233645.9273-1-zfigura@codeweavers.com> <20240214235307.10494-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: 1790920708426647538 X-GMAIL-MSGID: 1790920708426647538 NtWaitForMultipleObjects() can receive a timeout in two forms, relative or absolute. Relative timeouts are unaffected by changes to the system time and do not count down while the system suspends; for absolute timeouts the opposite is true. In order to make the interface and implementation simpler, the ntsync driver only deals in absolute timeouts. However, we need to be able to emulate both behaviours apropos suspension and time adjustment, which is achieved by allowing either the MONOTONIC or REALTIME clock to be used. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 9 ++++++++- include/uapi/linux/ntsync.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index 0773602cc86d..496704268603 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -765,11 +765,15 @@ static void put_obj(struct ntsync_obj *obj) static int ntsync_schedule(const struct ntsync_q *q, const struct ntsync_wait_args *args) { ktime_t timeout = ns_to_ktime(args->timeout); + clockid_t clock = CLOCK_MONOTONIC; ktime_t *timeout_ptr; int ret = 0; timeout_ptr = (args->timeout == U64_MAX ? NULL : &timeout); + if (args->flags & NTSYNC_WAIT_REALTIME) + clock = CLOCK_REALTIME; + do { if (signal_pending(current)) { ret = -ERESTARTSYS; @@ -781,7 +785,7 @@ static int ntsync_schedule(const struct ntsync_q *q, const struct ntsync_wait_ar ret = 0; break; } - ret = schedule_hrtimeout(timeout_ptr, HRTIMER_MODE_ABS); + ret = schedule_hrtimeout_range_clock(timeout_ptr, 0, HRTIMER_MODE_ABS, clock); } while (ret < 0); __set_current_state(TASK_RUNNING); @@ -804,6 +808,9 @@ static int setup_wait(struct ntsync_device *dev, if (!args->owner) return -EINVAL; + if (args->pad || (args->flags & ~NTSYNC_WAIT_REALTIME)) + return -EINVAL; + if (args->count > NTSYNC_MAX_WAIT_COUNT) return -EINVAL; diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 7c91af7011e4..074f26423426 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -28,6 +28,8 @@ struct ntsync_event_args { __u32 signaled; }; +#define NTSYNC_WAIT_REALTIME 0x1 + struct ntsync_wait_args { __u64 timeout; __u64 objs; @@ -35,6 +37,8 @@ struct ntsync_wait_args { __u32 owner; __u32 index; __u32 alert; + __u32 flags; + __u32 pad; }; #define NTSYNC_MAX_WAIT_COUNT 64