From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by sourceware.org (Postfix) with ESMTPS id 7F26F3857C66 for ; Thu, 28 Sep 2023 20:21:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F26F3857C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695932510; 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: in-reply-to:in-reply-to:references:references; bh=DmX9bKSrcJ3gg7QbnQ5HyzLMjN52R6w5zfPwPk6xm2I=; b=YHT9m7xPV8mIUJbLtJqCcLFzUFa4VSLHpjgkGY3cd4OsQhGGJgLg1e37/hA4+6GMM4768U J25l2Ijl5q2Dr3EN5sV1sW5qOUs6yOKu0Riai6pRlhAkAIDZJr2/z5n6bLp/vMjHgJ+Gt8 63LUYOG1iK4A0Zkv/x961yPdotSWh/SOFx/NVCyhNci9dTYBETgAAOOicW6ltIasTVrzML PrMeIDKfE7VwKrI5Sn/Ar4iVv2LH2liLUD3belCuqIgfums7+W1d5fGNCGiQjZartkoR+z gUfdlE3SjYRXr6yMe/vD0mOpT499Ao6EyQxB6mxpa1onD+YQCdM+hq/cTMS7ww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695932510; 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: in-reply-to:in-reply-to:references:references; bh=DmX9bKSrcJ3gg7QbnQ5HyzLMjN52R6w5zfPwPk6xm2I=; b=caIsx9kL4G5PovmJ3A6YjoJRCjOZI7Nd/fXke7hfbfjDaR9tlUHt4i1fkUBLXVsyc5lCpC yR+HpMzGp3/N7MDA== To: Mathieu Desnoyers , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Chris Kennelly , Ingo Molnar , Darren Hart , Davidlohr Bueso , =?utf-8?Q?An?= =?utf-8?Q?dr=C3=A9?= Almeida , libc-alpha@sourceware.org, Steven Rostedt , Jonathan Corbet , Noah Goldstein , Daniel Colascione , longman@redhat.com, Mathieu Desnoyers , Florian Weimer Subject: Re: [RFC PATCH v2 1/4] rseq: Add sched_state field to struct rseq In-Reply-To: <20230529191416.53955-2-mathieu.desnoyers@efficios.com> References: <20230529191416.53955-1-mathieu.desnoyers@efficios.com> <20230529191416.53955-2-mathieu.desnoyers@efficios.com> Date: Thu, 28 Sep 2023 22:21:49 +0200 Message-ID: <87r0midp5u.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, May 29 2023 at 15:14, Mathieu Desnoyers wrote: > +void __rseq_set_sched_state(struct task_struct *t, unsigned int state); > + > +static inline void rseq_set_sched_state(struct task_struct *t, unsigned int state) > +{ > + if (t->rseq_sched_state) > + __rseq_set_sched_state(t, state); This is invoked on every context switch and writes over that state unconditionally even in the case that the state was already cleared. There are enough situations where tasks are scheduled out several times while being in the kernel. > /* rseq_preempt() requires preemption to be disabled. */ > static inline void rseq_preempt(struct task_struct *t) > { > __set_bit(RSEQ_EVENT_PREEMPT_BIT, &t->rseq_event_mask); > rseq_set_notify_resume(t); > + rseq_set_sched_state(t, 0); This code is already stupid to begin with. __set_bit() is cheap, but rseq_set_notify_resume() is not as it has a conditional and a locked instruction and now you add two more conditionals into the context switch path. Thanks, tglx