From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 5DA6B3C3C0C for ; Sun, 11 Oct 2026 05:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791696001; cv=none; b=fETJU0EN923MwlUv6znUuFFXC6bMS5AyEHVN55DT1BgPn9hhwpA4mj97O0Gj0LGjGABcVC3qYxGbk1pdW4GOHZVACxJ8+/4IOpdBENQM2w/zn9nvlDEECEptANgNFFm9a//U+N+Y15mArcq0JMggNcbNTIwqGfmt1j1FTm+Mbsg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791696001; c=relaxed/simple; bh=IqZOTLrn7eYpXP48OnT1+GGJUhbeoR4Az65ChcnizhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PGPyvr98asGr/Es4LJMo6tFrwc0tdgAPssOmjCGQCunl84DOtcDhhmpnUNlR720rTLHOaBW00bucfwPADS8LhrNlxfdydGLQEBYRvGWv6rRjy6ygE/z34dzvXCjkE+chqE+jRXF89kiMSKf8WCuSOU9P+ohNRObejTJGblMOcJU= 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=iWzmVDud; arc=none smtp.client-ip=74.125.82.176 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="iWzmVDud" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-3535a54bed9so1227476eec.1 for ; Sat, 10 Oct 2026 22:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791695999; x=1792300799; 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:content-type; bh=wlvJfMM29kaHQ8AJYFEoB0KmVZRRhlej3ZxZxNGG49w=; b=iWzmVDudd0dFgi903RuZHBaGZNobq/DIms98l28wFPNW0AbZaJGHcG0ekKibjblWD7 S+TEgRTj01A2VtwQevaj6xJ1tIe5jtzxxxZxJj0VfOhRjYjAhIH4n/wpClaRskFt7diJ QcU/krThHPfPXQwMKmsqLLIRqP2UB/KqypJWJY3ixEHJrmayAq8aCGv7tJDrMno9bZXu RNMoZXJFEA01GeGJd73lfnoukdRhJKxwHKCpQuFZmM2EYEA1bUgm4FfgUapGhtWbgi4Z e91N6Y5vSDBVSyIYT4i6CoLgHSZ7BXUq5S8wUJaYDTOoLWaF2HNqmF6pq3kX/B6XVU5d ArMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791695999; x=1792300799; 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:content-type; bh=wlvJfMM29kaHQ8AJYFEoB0KmVZRRhlej3ZxZxNGG49w=; b=eGZfkHTn2YSsDTYNIgVYlS9s9r04opQj7QELFzIqEZmBIRcof7RBY5cF3D0IbuSPNH 034y3/wLmmIV+rnUoSMntMkVMps67crhA3Pn8mJzUlqpHoDVFUI1xGoXMuqY7/wp175o nPuYLxuODhw0o/DbNdHAnuHwTtUVyAkY03kZR/GvUqYTaioBY9GWVxS5eFnlFFUm3TDe Nf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ubI4kAMX/gFpTja8vkdzAXhjCZbzIlGXOGQWkydhIIvFBzyYR9aS8fBnONJ2A== X-Received: by 2002:a05:701b:4546:20b0:14e:7162:2ab3 with SMTP id a92af1059eb24-16a5e49fd10mr7893438c88.8.1791695999082; Sat, 10 Oct 2026 22:19:59 -0700 (PDT) Received: from FT6N242TWK ([223.181.119.248]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-169a1becf08sm20673698c88.5.2026.10.10.22.19.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 10 Oct 2026 22:19:58 -0700 (PDT) From: Shashank Mohan Jain To: Thomas Gleixner , John Stultz , Anna-Maria Behnsen , Frederic Weisbecker Cc: Stephen Boyd , Miroslav Lichvar , Shuah Khan , Todd Poynor , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 2/3] posix-timers: Report a disarmed SIGEV_NONE timer as disarmed Date: Sun, 11 Oct 2026 10:49:42 +0530 Message-ID: <20261011051943.60520-3-jain.sm@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261011051943.60520-1-jain.sm@gmail.com> References: <20261011051943.60520-1-jain.sm@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A SIGEV_NONE timer on a hrtimer or alarmtimer based clock is never queued. The expiry time stored in the timer is all that common_timer_get() has to compute the remaining time, and common_timer_set() leaves it alone when the timer is disarmed with a zero it_value. timer_gettime() then reports the remaining time of the previous setting until that time has passed: struct sigevent sev = { .sigev_notify = SIGEV_NONE }; struct itimerspec arm = { .it_value.tv_sec = 100 }; struct itimerspec disarm = { }, cur; timer_create(CLOCK_MONOTONIC, &sev, &t); timer_settime(t, 0, &arm, NULL); timer_settime(t, 0, &disarm, NULL); timer_gettime(t, &cur); leaves 99.99... seconds in cur.it_value. POSIX wants a zero it_value for a disarmed timer. Timers which deliver a signal get that from the POSIX_TIMER_DISARMED check in common_timer_get(), and the CPU time clocks set the expiry time to 0 in posix_cpu_timer_set(), so they are not affected. CLOCK_MONOTONIC, CLOCK_BOOTTIME, CLOCK_REALTIME and the two alarm clocks are. When a SIGEV_NONE timer is disarmed, move its expiry time into the past. The timer_arm() callbacks only store the expiry time for such a timer, so call them with an absolute expiry time of 0, which is not after the current time of any of these clocks. common_timer_get() then sees a remaining time which is not positive and reports a zero it_value. This is old behaviour: the sequence above gives the same result on a v6.8 based distribution kernel. The commit which introduced it was not searched for, hence no Fixes tag. Tested in qemu with the sequence above on the five clocks, and with the posix_timers selftest including the test added in the next patch. Assisted-by: LLM Signed-off-by: Shashank Mohan Jain --- Prepared with Claude Code (Anthropic), model Claude Opus 5.5 (claude-opus-5-5). kernel/time/posix-timers.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 436ba794cc..f6dd8d34a8 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -904,15 +904,23 @@ int common_timer_set(struct k_itimer *timr, int flags, timr->it_status = POSIX_TIMER_DISARMED; posix_timer_set_common(timr, new_setting); + sigev_none = timr->it_sigev_notify == SIGEV_NONE; /* Keep timer disarmed when it_value is zero */ - if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) + if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) { + /* + * SIGEV_NONE timers are never queued. The expiry time is + * the only information timer_gettime() has to tell whether + * such a timer is armed, so move it into the past. + */ + if (sigev_none) + kc->timer_arm(timr, 0, true, true); return 0; + } expires = timespec64_to_ktime(new_setting->it_value); if (flags & TIMER_ABSTIME) expires = timens_ktime_to_host(timr->it_clock, expires); - sigev_none = timr->it_sigev_notify == SIGEV_NONE; if (kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none)) { if (!sigev_none) -- 2.43.0