Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp507460lqp; Mon, 10 Jun 2024 10:25:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKddovNNTjuVruJHyUW1/DvbwHaPe1PIIFe/yxOSUopDsmKVUNF46fVP3BvPMk75d4oiL7uCHdNvpzP+K0Qj4NCIyAegaUYJVYYoApxQ== X-Google-Smtp-Source: AGHT+IEV3IOvVrkIi7qEh1WZlZQbgG1epMgNxAXZJDanmlMzxS9jeZEoa4M0yVbJ7SfSnKx4Zpzu X-Received: by 2002:a17:902:728d:b0:1f6:6946:ef54 with SMTP id d9443c01a7336-1f6d039b242mr89732315ad.56.1718040315044; Mon, 10 Jun 2024 10:25:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718040315; cv=pass; d=google.com; s=arc-20160816; b=BTWRUU8Ukkc3KoNw01xaNbGdbR+ScD7DsRvkjBoLerV6OyWXq0j8gMqruJrFeTztxJ wDgbDIufOmxa/HSkrQUkgV11G9evDS4Y3jYaS1hjR8yj8TfyTvh7AdfOmPfzSybwbTj0 jyJsEW3qd3f0bevTBtoxYFjh0oxK+4v1WdwkeTQRdQyrW/vGQ8T94X7+NT9XzBLxlNB+ voOTbeA6/Za5C6sVoY/mLfYfYW/X8VOIW6dzCr5EgMs42K2Y2NxspR3vTVGqR1zOYE0w HBhXJJ6LS/30wcTyj1wOtqX0sy79opKHi16djCMM8aZAleDQuSsQTMilIdMrORNIEqix pHhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=7CK+FAEXH0tvW3CxjLUKVaxfftLEf1lOjkxUKErNSnE=; fh=joBs/8L+orz77ylyCy6wqNwwi35f7sYhLR+/TQjQjhI=; b=AQYA9dA//PRK9KUjCuy+XTJPR97mMm+0svdAX0m1JyHVOBe6VpN5qOFm5GmGX2J7hO 4P3rE7/kcJ/UkWzXeo17Ykx7B22OGpuYuXCRXHO/7vfPtWWs7nED1wNQXp9kF2rv8Q9B Y+aoG5iIIdbji7SiMs8xkoDsa03HyTj8gCSKPFHwpxdcucdpM8BVh6sAZRc+dj8+Dh1i Iy8p/TJD9I/0Lu7X/Ye4WlhBH4VZnjgFJwuwVOId9NkzsKuR4u/TsM2HvSXs66XsmFrU ovEgu3sSGslbBBoavqTouknEX0cGaJ4G7vsUzF124Ckm2SlPuzhYTFKIR9EtWhMQP3Gs ts/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="ztJs/u9a"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208592-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208592-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7f438bsi79854775ad.506.2024.06.10.10.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 10:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208592-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="ztJs/u9a"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208592-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208592-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 960EDB286B3 for ; Mon, 10 Jun 2024 16:48:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D5D1156881; Mon, 10 Jun 2024 16:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ztJs/u9a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qb3vq1eg" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D1E5B156641 for ; Mon, 10 Jun 2024 16:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037764; cv=none; b=YYL3o8wUP5Wr3FxsNA2nMCISwO06kssZCmia5Yy4Wizeodxeyxq24YfEptjksmb1xMPZUZ/OE9zrvcLBk4rWCLYNugLEfZh+5uqg9ckkNRO73B0seUemqat55WZ96zOTQ336CAMhZoXdX9Cr2IwwCAxUvdlESM9C44AOXU1ql8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718037764; c=relaxed/simple; bh=YH2GNJxCNBMbmtwU0fr39UpQz8wyT6gB/kPu6Cst2a0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=FP9tzDb7jpYV3bT1dhRgoRzWkNh9Us0PevO0pENH+v733+tNR2ytiVAVIgDeSid1+aVNAO1T7ZU5nAdRSwl5ajoVdkCopZ42c9zaN0BewEqe6SjTYCvmjY/wMbVJTA3/EAtIqEAsv64f4bzkk/7HeigUOrJee1NgDkaWYB6Rx0s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ztJs/u9a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qb3vq1eg; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240610164027.303056339@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718037761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7CK+FAEXH0tvW3CxjLUKVaxfftLEf1lOjkxUKErNSnE=; b=ztJs/u9ajzIRsznRPRxyZeDVlvQuouAZZx/Bsm3yOQzN787cQRuYagCrsNrkMTGxcCikwd 1ZmPt97/josOM6ZPUniDbpJgr03sq4HHyndPYizI2Mb3Mp4eNoctdkHHK8ES8UWRiF/yDi p5RjpqVLDCK+zCuHW7oE4S5SSZ3vMlfIrVl8BR+UKrOgpgT2jeD9gwyNxL54Q8tuaQFTmp kNeOwi25aUugSjitZSEfn8wW+JQ2snbn8jfDG5JYHNDWhjAr8XF9oUd+NKOw66G/W8oRNh 8Z0Kqbi81t3ZM7Vwo3FAMhzGuGTl2n7kJLlrQ7hi2H73jaNtyXhYRh66FOjDdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718037761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=7CK+FAEXH0tvW3CxjLUKVaxfftLEf1lOjkxUKErNSnE=; b=qb3vq1eg+tk9rQfpuDtolPFd2U1w1rQI1S4Wkai9LMXApyd+pZb2C+4LZwwKIxYQpKPwvR 9T7SkDvN+sTUp3Bw== From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch V3 29/51] signal: Allow POSIX timer signals to be dropped References: <20240610163452.591699700@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 10 Jun 2024 18:42:41 +0200 (CEST) In case that a timer was reprogrammed or deleted an already pending signal is obsolete. Right now such signals are kept around and eventually delivered. While POSIX is blury about this: - "The effect of disarming or resetting a timer with pending expiration notifications is unspecified." - "The disposition of pending signals for the deleted timer is unspecified." it is reasonable in both cases to expect that pending signals are discarded as they have no meaning anymore. Prepare the signal code to allow dropping posix timer signals. Signed-off-by: Thomas Gleixner --- include/linux/posix-timers.h | 5 +++-- kernel/signal.c | 7 +++++-- kernel/time/posix-timers.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) --- a/include/linux/posix-timers.h +++ b/include/linux/posix-timers.h @@ -100,8 +100,9 @@ static inline void posix_cputimers_rt_wa { pct->bases[CPUCLOCK_SCHED].nextevt = runtime; } + void posixtimer_rearm_itimer(struct task_struct *p); -void posixtimer_rearm(struct kernel_siginfo *info); +bool posixtimer_deliver_signal(struct kernel_siginfo *info); /* Init task static initializer */ #define INIT_CPU_TIMERBASE(b) { \ @@ -125,7 +126,7 @@ static inline void posix_cputimers_init( static inline void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit) { } static inline void posixtimer_rearm_itimer(struct task_struct *p) { } -static inline void posixtimer_rearm(struct kernel_siginfo *info) { } +static inline bool posixtimer_deliver_signal(struct kernel_siginfo *info) { return false; } #endif #ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK --- a/kernel/signal.c +++ b/kernel/signal.c @@ -585,6 +585,7 @@ int dequeue_signal(sigset_t *mask, kerne lockdep_assert_held(&tsk->sighand->siglock); +again: *type = PIDTYPE_PID; signr = __dequeue_signal(&tsk->pending, mask, info); if (!signr) { @@ -616,8 +617,10 @@ int dequeue_signal(sigset_t *mask, kerne } if (IS_ENABLED(CONFIG_POSIX_TIMERS)) { - if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) - posixtimer_rearm(info); + if (unlikely(info->si_code == SI_TIMER && info->si_sys_private)) { + if (!posixtimer_deliver_signal(info)) + goto again; + } } return signr; --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -254,7 +254,7 @@ static void common_hrtimer_rearm(struct * info::si_sys_private is not zero, which indicates that the timer has to * be rearmed. Restart the timer and update info::si_overrun. */ -void posixtimer_rearm(struct kernel_siginfo *info) +bool posixtimer_deliver_signal(struct kernel_siginfo *info) { struct k_itimer *timr; unsigned long flags; @@ -286,6 +286,7 @@ void posixtimer_rearm(struct kernel_sigi /* Don't expose the si_sys_private value to userspace */ info->si_sys_private = 0; + return true; } int posix_timer_queue_signal(struct k_itimer *timr)