From nobody Sun Jun 14 02:38:16 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F7503E0C4C for ; Mon, 4 May 2026 15:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777909083; cv=none; b=cO9MOnrLukPyVh+KtETA6EEaj+7YdUM4xIi76uWb1mfZ2zFsOuYKZPINfPX85ODSqwU9sxry4lWomsqdom3vPhvoR3NdewbWA5sHOMXaWIBj6D/Ltz/ySa/end2xpaGpdNfM5jWJh4kQgMyMEdoi9Ph5cgFfBLoiFkK4W21R2QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777909083; c=relaxed/simple; bh=jO/ky83hpeaAgon9DQ5I41b1r9GxK7nleXrheD+rud0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NXbiUcXgQcnYg93ahJTYGr0fpzN9VbJPzfn8hofmeKjpUCihEJTI8t1lrtwbX6oYX6+lTC8CoPwkoi26oF3qJlg/i9JhV5M8rrqJVS8RvWFXwuOKsEPPdqfbWnsj4iwKuQoCD5xBo67rZOIG3Q3rQPvqBGKxA6m1+8VmK3kxwag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XJtKrQPi; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XJtKrQPi" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2b2589c26e3so39141085ad.1 for ; Mon, 04 May 2026 08:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777909082; x=1778513882; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jQgLbDmX+j3y6KiTh8+YyN+Fs0cvqV8hTtym1kOKLqc=; b=XJtKrQPiNHd0E8K4CZ0sW5qWsy/V9QkjsQvOXiGFWxDablrHShoso2KZjxugGnV17f Yu+H+iMkknTmWnB+/2i4o1hSZWj6WTCY2C+KE9jrfl3r305BujZumNqncSorND+A1za9 pVzkksz5cSSt734rQH4eoiAqlz4S+PEYwJJ04RSWSgJOua5jNIU3mu5kNOyy3jCErkbA AefwVvypGlnSsCvQqgbN6sdz+LIEOIh+AhZdOONp3tAU33gc0HdluhKg4gcU6UNFXJ3W 03SxIGIHLhjLM7V8DV9b5ASzfenZhguXok/M+Z2gr6X3JBJe3xCgiabhP7/+bMhbVvlj muZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777909082; x=1778513882; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=jQgLbDmX+j3y6KiTh8+YyN+Fs0cvqV8hTtym1kOKLqc=; b=Zw6c9tv197UeCFs4opWMIk8c3yyLwo93lXxJs0bnAGlD3TGjDrmiMprqswxA4QsX0B KCD05nHjJ7qe31qcBlLJYKxa74gR50nX1vLTZZX6gDq88azFoBgfan8wekgVns53IX3G j4U0rXw0kWpD+OY8G75Zyiu60VKz6g6XnTSUgfxnz8FX++CTA/K3CPD3FCvqJoNFWl/X Z2FTfQPLfLCOFQq2bzY/JO2JdZsS1vIqjyEsCp+rFaTYQY3Hb6+HQ2dRvDlPcGsXxkLG 9yqYSXNe8o0P7ZhhFhJjVExMs7ki0iyyoWLJiZi8mGklvhjgow1QsGGtN1kiRBRt3OSQ SlOQ== X-Forwarded-Encrypted: i=1; AFNElJ+S0FjF49ZNEvE/v2oftzJ/hodJ355Iqgy7pNz24TGZpcNQoMRMjX+YvbjcnZ3e5Wvotb8zZnUBRJ8mSAA=@vger.kernel.org X-Gm-Message-State: AOJu0YzAMcqfF6Bro7QuROzYs94crubb2XbzxsPdWvsT0YhJ/t8ZfaUC QeZAx/rLNEIsJVupiGxPAJFmp0980PgoJroU8+wTFUaTtJAQ6OgRvoX63D/t9w== X-Gm-Gg: AeBDievZAG8MdtPssuQUB9VU0OemPlHTLEDsvx3+37PW10SL2Qgn66AX/mpLYBlsY7B HcHuRofxBUVU+u0PTCUHrLp6JEhYeyVQR8wNr0X0Cqnrcrw9rSBZLF832kGRq7yaS1uXe2Dq9Zs lNnkmy6djwzNP0oeVmDpLNq+u2o2rP3R75tkmhH07fULK5mbao5svkylcWt8Q6TtrBGjE5hwdsj zmhgvPxQL5e8IiulE/jwJ4mSeCJM41ZzB8NVVwrbtC20I4D8nCq29t4Hi2/vcCaguoMiJEyizUS eFmWPRwZJL3XvCP1VeO55WpfvnVuG9PeJANz7amv3pdfiXY0tS64yqjGHwP/NYUqWh2TSPRqV6m cleNpUAVFbhDe+smHvyuaM/X0oAP71a7tGi0FCBD9LW7cqNgqitReOJ0KiLAf9x75dZWYaP+bQ8 vddf01/JC2tdv7kQocUcJ3YWPrMSHocX7fshcP/wr+IsLzJ7nktyI4yU5NGrE= X-Received: by 2002:a17:903:13c8:b0:2ba:16be:cb6a with SMTP id d9443c01a7336-2ba16becf42mr55846145ad.9.1777909081476; Mon, 04 May 2026 08:38:01 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9caaaec82sm110364095ad.24.2026.05.04.08.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 08:38:00 -0700 (PDT) From: Maoyi Xie X-Google-Original-From: Maoyi Xie To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] io_uring/timeout: honour caller's time namespace for IORING_TIMEOUT_ABS Date: Mon, 4 May 2026 23:37:54 +0800 Message-Id: <20260504153755.1293932-2-maoyi.xie@ntu.edu.sg> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260504153755.1293932-1-maoyi.xie@ntu.edu.sg> References: <20260504153755.1293932-1-maoyi.xie@ntu.edu.sg> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" io_uring's IORING_OP_TIMEOUT and IORING_OP_LINK_TIMEOUT accept a timespec from the caller via io_parse_user_time(). With IORING_TIMEOUT_ABS, the timestamp is an absolute deadline on the selected clock. The clock is CLOCK_MONOTONIC by default. CLOCK_BOOTTIME and CLOCK_REALTIME are also selectable. A submitter inside a CLONE_NEWTIME time namespace observes CLOCK_MONOTONIC and CLOCK_BOOTTIME shifted by the namespace's offsets relative to the host. Every other ABS timer interface in the kernel converts the caller's absolute time to host view via timens_ktime_to_host() before arming an hrtimer: kernel/time/posix-timers.c -- timer_settime(TIMER_ABSTIME) kernel/time/posix-stubs.c -- clock_nanosleep(TIMER_ABSTIME) kernel/time/alarmtimer.c -- alarm_timer_nsleep(TIMER_ABSTIME) fs/timerfd.c -- timerfd_settime(TFD_TIMER_ABSTIME) io_parse_user_time() does not. As a result, an absolute timeout submitted from within a time namespace is interpreted in host view. That is generally a different point in time. It may already be in the past, causing the timer to fire immediately, or far in the future, causing the timer not to fire when expected. Reproducer: in unshare --user --time, with a -10s monotonic offset, submit IORING_OP_TIMEOUT with IORING_TIMEOUT_ABS and deadline =3D now + 1s. The CQE is delivered after <1ms instead of the expected ~1s. Apply timens_ktime_to_host() to the parsed time when IORING_TIMEOUT_ABS is set. Split the existing clock id resolver in io_timeout_get_clock() into a flags only helper io_flags_to_clock(), so io_parse_user_time() can resolve the clock without a struct io_timeout_data. timens_ktime_to_host() is a no-op for clocks not affected by time namespaces, e.g. CLOCK_REALTIME. It is also a no-op for callers in the initial time namespace. The fast path is unchanged. SQPOLL is also covered. The SQPOLL kernel thread is created via create_io_thread() with CLONE_THREAD and no CLONE_NEW* flag. copy_namespaces() therefore shares the submitter's nsproxy by reference. Inside the SQPOLL kthread, current->nsproxy->time_ns is the submitter's time_ns. timens_ktime_to_host() resolves correctly. Suggested-by: Pavel Begunkov Suggested-by: Jens Axboe Signed-off-by: Maoyi Xie --- io_uring/timeout.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/io_uring/timeout.c b/io_uring/timeout.c index 4cfdfc519..e2595cae2 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -3,6 +3,7 @@ #include #include #include +#include =20 #include =20 @@ -35,6 +36,22 @@ struct io_timeout_rem { bool ltimeout; }; =20 +static clockid_t io_flags_to_clock(unsigned flags) +{ + switch (flags & IORING_TIMEOUT_CLOCK_MASK) { + case IORING_TIMEOUT_BOOTTIME: + return CLOCK_BOOTTIME; + case IORING_TIMEOUT_REALTIME: + return CLOCK_REALTIME; + default: + /* can't happen, vetted at prep time */ + WARN_ON_ONCE(1); + fallthrough; + case 0: + return CLOCK_MONOTONIC; + } +} + static int io_parse_user_time(ktime_t *time, u64 arg, unsigned flags) { struct timespec64 ts; @@ -43,7 +60,7 @@ static int io_parse_user_time(ktime_t *time, u64 arg, uns= igned flags) *time =3D ns_to_ktime(arg); if (*time < 0) return -EINVAL; - return 0; + goto out; } =20 if (get_timespec64(&ts, u64_to_user_ptr(arg))) @@ -51,6 +68,9 @@ static int io_parse_user_time(ktime_t *time, u64 arg, uns= igned flags) if (ts.tv_sec < 0 || ts.tv_nsec < 0) return -EINVAL; *time =3D timespec64_to_ktime(ts); +out: + if (flags & IORING_TIMEOUT_ABS) + *time =3D timens_ktime_to_host(io_flags_to_clock(flags), *time); return 0; } =20 @@ -399,18 +419,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct = hrtimer *timer) =20 static clockid_t io_timeout_get_clock(struct io_timeout_data *data) { - switch (data->flags & IORING_TIMEOUT_CLOCK_MASK) { - case IORING_TIMEOUT_BOOTTIME: - return CLOCK_BOOTTIME; - case IORING_TIMEOUT_REALTIME: - return CLOCK_REALTIME; - default: - /* can't happen, vetted at prep time */ - WARN_ON_ONCE(1); - fallthrough; - case 0: - return CLOCK_MONOTONIC; - } + return io_flags_to_clock(data->flags); } =20 static int io_linked_timeout_update(struct io_ring_ctx *ctx, __u64 user_da= ta, --=20 2.34.1 From nobody Sun Jun 14 02:38:16 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE9233E1203 for ; Mon, 4 May 2026 15:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777909085; cv=none; b=A2QTBfEWrb11ZXyHVvzMqi5Coyp3LZuGaC7ReH/aCzhDOfo0tfcl3xjil05kLvwZt3udmIFTU5Av9+oK7ZhDdo+kuIFUMCSLM50bsSnsb+VKURXSWBJ3T08Oj7gff8yZ4yT87aCrmv2vPPGdWhfFrzFbLpj3ieowC+eckId4Aiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777909085; c=relaxed/simple; bh=DeK8vkDNgVdGtbOfo/XgPm6EantZau9iQInjj3eBNb4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GE34PHlCEE/YUsDcWUd7wzpyTarNimdhNxjkqeryWQMMVIwF4Fmo2CJbnwT5Hj4v2onx5IYzDFSAWfsOsSOrMTywarhhLOlUZzQRrviaXzzOvfpyVtZPwQjXDDIstQiE4HqWJSgnYvDhF/CxAIlaGyAuwwvir/JTiyDipJlxlnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l9ZJVwIe; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l9ZJVwIe" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-36528851d7dso735849a91.1 for ; Mon, 04 May 2026 08:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777909083; x=1778513883; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DRJfHeoNcXWsQi0Hkkxe2yF4lFHCoxvJMvngDFVpA6Y=; b=l9ZJVwIemh4H8Gtyw/Bxt9f1JzhdI73Hz/nEJ9jT5EOR2+QvKqe5G64D7/w6H14h3/ 7h8iRbexigrN/Xrn9L84ZXppDkpbXMqmbgQt+HeOPvlnRjdO0YIbF1rwASFWuDemmi4Q vTL3BPfV5Qmr5A9CCPv3kujb2/Z71D6K4EVQETGs24Q7576VEbAW97QItRcXc1czt4Li 2b19dh25UFAvQj2Wkw9s9PRZcuo8GZ3bugpEIv6Gb79c+wLBj7nCwx2RxCAgUTg+TIdD RDLmM8cDebHvi/eoos+qZWbf92lxw56SlFVeDsnqAj8b4VRZZKkX1BwcPGwmL8C7UI7n 0OCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777909083; x=1778513883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DRJfHeoNcXWsQi0Hkkxe2yF4lFHCoxvJMvngDFVpA6Y=; b=O0nVE7398Z5J7X+3qY2gH6Z3vlm1v1gdK/XHiKkTggy1cfW7sZeZLYQSzbb47YDE0k 7InhFCowBMCH9UUouUswHVyBfMCQcPQLFBqZX/rxXxpUGHZ+0PbOu9az/hbNSIe/0Fqp SGXSTm55eGxPUnTOzAPKDMuqkG+voj4sG507xddDC5loOapzAk9XCvxW8jTKS0BEFQCQ JwbH+0RAsZeAu3IGdxfpgBe2kmC9ju4D9XDi2WTrt2i9lVXM8g6hOkazelTUUA50gME1 MmxTNvKNFTwnbRBReWbflMvVCoM3Mxx5AG0YSZyONaGgE2QvD/kLI1xcye9QnGYpUqsM gr8A== X-Forwarded-Encrypted: i=1; AFNElJ+aY9eNBQx5cfhwlwAHf7/bUAFww/I19622RjjDv5VRpzyxCcjPKhOOW0Hz7Wo5fx9DP72u/nQVZA+ZOdg=@vger.kernel.org X-Gm-Message-State: AOJu0YyKQCRGtBS5FQS19nGw0yA20o6O42tPO7Xml0T1DmkXjJUPDX09 0IgvUCuB2RTd3V30SEgcVs+ApvBL6fp9tq4OdOcxA7BlWvQCptSt7QXYSBjOgw== X-Gm-Gg: AeBDietouqTinMrkk201ULMmw7cd/QC70+r1dPkHWFjJudrp52L/wMX1kcnsgp+smU2 8rPcsSHZMcAQi/WMBrJHlx4QWEzf7niFcgsv9kbBB/+1nHaAGDbzzrJepWXUZn2Da4R830dyPl2 9ftdYh3IzY3uOfy+/EX49jfsMfY6YP93Gr9AMrejap+fO4DQrgJqBCKl2gBMSxsOM3cyD8TOS7a 8mApl49sM8xNmyOyy1KprZi+rK+zaihSrwD8CYGnJTTdmeLRiuDwTIo6FdZegFchYlnka2aOgVW 7DavByCpWl/TZItLGhlVtMoJynNqYjBdvnAx9X56nCCoW3m8NqE2tLg7SkcpBwaxWACL3gw4V3b LsCQCSyNVZhDvCPYB+1Ci1TexvIEFSRypVf+THtluPE/5/SuqXHAbJYTNTz9W/mel/pTYbShOVB 5F+1nL5PfW39Z401Wjr6oRzKw29QSsCqw4NB7REkHnwV6E/U59O4DgIny2aLU= X-Received: by 2002:a17:903:40d1:b0:2b0:ccad:de1a with SMTP id d9443c01a7336-2b9f260b4a7mr110180135ad.30.1777909083288; Mon, 04 May 2026 08:38:03 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9caaaec82sm110364095ad.24.2026.05.04.08.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 08:38:02 -0700 (PDT) From: Maoyi Xie X-Google-Original-From: Maoyi Xie To: Jens Axboe Cc: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] io_uring/wait: honour caller's time namespace for IORING_ENTER_ABS_TIMER Date: Mon, 4 May 2026 23:37:55 +0800 Message-Id: <20260504153755.1293932-3-maoyi.xie@ntu.edu.sg> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260504153755.1293932-1-maoyi.xie@ntu.edu.sg> References: <20260504153755.1293932-1-maoyi.xie@ntu.edu.sg> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" io_uring_enter() with IORING_ENTER_ABS_TIMER takes an absolute timespec from the caller via ext_arg->ts. It arms an ABS mode hrtimer in __io_cqring_wait_schedule(). The conversion path in io_uring/wait.c parses ext_arg->ts inline rather than going through io_parse_user_time(). It therefore does not pick up the time namespace conversion added by the previous patch. Apply timens_ktime_to_host() to the parsed time on the IORING_ENTER_ABS_TIMER branch. This mirrors the IORING_TIMEOUT_ABS fix in io_parse_user_time(). Use ctx->clockid as the clock id. ctx->clockid is set either at ring creation or via IORING_REGISTER_CLOCK. timens_ktime_to_host() is a no-op for clocks not affected by time namespaces. It is also a no-op for callers in the initial time namespace. The fast path is unchanged. Reproducer: in unshare --user --time, with a -10s monotonic offset, call io_uring_enter with min_complete=3D1, IORING_ENTER_ABS_TIMER, and ts =3D now + 1s. The call returns -ETIME after <1ms instead of after the expected ~1s. Suggested-by: Pavel Begunkov Suggested-by: Jens Axboe Signed-off-by: Maoyi Xie --- io_uring/wait.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/io_uring/wait.c b/io_uring/wait.c index 91df86ce0..ec01e78a2 100644 --- a/io_uring/wait.c +++ b/io_uring/wait.c @@ -5,6 +5,7 @@ #include #include #include +#include =20 #include =20 @@ -229,7 +230,10 @@ int io_cqring_wait(struct io_ring_ctx *ctx, int min_ev= ents, u32 flags, =20 if (ext_arg->ts_set) { iowq.timeout =3D timespec64_to_ktime(ext_arg->ts); - if (!(flags & IORING_ENTER_ABS_TIMER)) + if (flags & IORING_ENTER_ABS_TIMER) + iowq.timeout =3D timens_ktime_to_host(ctx->clockid, + iowq.timeout); + else iowq.timeout =3D ktime_add(iowq.timeout, start_time); } =20 --=20 2.34.1