From nobody Wed Nov 27 18:41:04 2024 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 8228A188739; Wed, 9 Oct 2024 08:29:17 +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=1728462559; cv=none; b=D3rxKmCkc0xDzUuw731t1qIlwj0HlfTsTLuCL9i9f6emokJ7b03ewb6Rq1KEq9oFxT2VFGtVltYGLvqDvlDnw1yItfR2Ttk0XAsXJPI7Hi0sYMMzWwXt7ILEySaSscvFptHbXJjW0qvorRbVPjh1wmeOK9awtzP0IKlFdW8Wn3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728462559; c=relaxed/simple; bh=zlJbCDZ6B9SeUKQDoLwvls4pdXQE7EYEHEQq9ledjk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AQnltbBGpcUPM4D0LWtcI2lH/HKrqhabBSSp3WEiEnJa+xVaMSR85paeTI/lMJQioE15kd7wmAU/Rjjs13WA+IOegEPjth67mHBqGqx64tQ0YeCZNSpXGl4IPoP5MuNv5bet1sv66MbvcKFp4j3Z4yXeZ0qwnQtz4wx3GOweo2E= 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=Tl8D/Rr4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q/jxvWJF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Tl8D/Rr4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q/jxvWJF" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728462555; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+wzvWtgEBSrKgOrWII19Tdc3v5jZTMrQEdlErVE1mMc=; b=Tl8D/Rr4dRkEQBUdDIEJQIy8B3ylOFTKqY+ynnnRegsIc2USTBxv1X3rhThZf3y4T/sptX oMmpfloa58p1T93bhifLCu4KoLk8CMbEmMT4sYG4g8qdl75PLJP56walDndjzsFbN5syzv ErSSnwcPKozTkKbmhVERas53tEDXG+evmgxczKLRpnr/xRa2NjPvzQEfOV/rPdrHFvJskt VOJjtlLquTSz9QeMOBbajhO/tTHGyxZez95c/J79RnHaZKN8r3B5xcbOOZolrRV/xcc2bf urdfJPfGTWox4x/wX3VxJDnkq9O4aEb63rE1R7u2n62pWe3PB9g/AenseG4jcw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728462555; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+wzvWtgEBSrKgOrWII19Tdc3v5jZTMrQEdlErVE1mMc=; b=Q/jxvWJFjHojB2i1lX6/MZ1fDbU5/1AKfPXakao1PdpAsHR9JeN6RVhTLv50sRgVRwVWXN a4JGbe1T/S+RIUCg== Date: Wed, 09 Oct 2024 10:28:57 +0200 Subject: [PATCH v2 04/25] timekeeping: Abort clocksource change in case of failure 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" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-devel-anna-maria-b4-timers-ptp-timekeeping-v2-4-554456a44a15@linutronix.de> References: <20241009-devel-anna-maria-b4-timers-ptp-timekeeping-v2-0-554456a44a15@linutronix.de> In-Reply-To: <20241009-devel-anna-maria-b4-timers-ptp-timekeeping-v2-0-554456a44a15@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner From: Thomas Gleixner There is no point to go through a full timekeeping update when acquiring a module reference or enabling the new clocksource fails. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/timekeeping.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index c4dd460b6f2b..0ae35a71f8cc 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1577,33 +1577,29 @@ static void __timekeeping_set_tai_offset(struct tim= ekeeper *tk, s32 tai_offset) static int change_clocksource(void *data) { struct timekeeper *tk =3D &tk_core.timekeeper; - struct clocksource *new, *old =3D NULL; + struct clocksource *new =3D data, *old =3D NULL; unsigned long flags; - bool change =3D false; - - new =3D (struct clocksource *) data; =20 /* - * If the cs is in module, get a module reference. Succeeds - * for built-in code (owner =3D=3D NULL) as well. + * If the clocksource is in a module, get a module reference. + * Succeeds for built-in code (owner =3D=3D NULL) as well. Abort if the + * reference can't be acquired. */ - if (try_module_get(new->owner)) { - if (!new->enable || new->enable(new) =3D=3D 0) - change =3D true; - else - module_put(new->owner); + if (!try_module_get(new->owner)) + return 0; + + /* Abort if the device can't be enabled */ + if (new->enable && new->enable(new) !=3D 0) { + module_put(new->owner); + return 0; } =20 raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); =20 timekeeping_forward_now(tk); - - if (change) { - old =3D tk->tkr_mono.clock; - tk_setup_internals(tk, new); - } - + old =3D tk->tkr_mono.clock; + tk_setup_internals(tk, new); timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); =20 write_seqcount_end(&tk_core.seq); @@ -1612,7 +1608,6 @@ static int change_clocksource(void *data) if (old) { if (old->disable) old->disable(old); - module_put(old->owner); } =20 --=20 2.39.5