Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3315588ybt; Mon, 29 Jun 2020 22:49:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/I/h7SOzGCE9iZnAHIwMpanc+lbHzQj94lNt996FGnLS57CQ/nMH1SxkhbPadQZjej9fL X-Received: by 2002:a17:906:c18d:: with SMTP id g13mr14656783ejz.239.1593496162225; Mon, 29 Jun 2020 22:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593496162; cv=none; d=google.com; s=arc-20160816; b=OZHKG5KiZL7lQC7ifHkVVkEIXhNA8A5Tqxt0jg0CA+KRVydXRiivPfB+l2tcjVyenm rqTpo88qX3K9Ez7+OU+3MYkgSlu3AH8b+m8EjARXZ654NVilwFcc9KPaPCyCmrfo88RZ PLiPmJLqsoZRyGiGDMxpZ7Ok4aaLeZpv4bIigq4dSqvIOrxxeiSavvEW7+Mg48f2lqKP 30mnbzipCfMuX+t1oxtu8QRLkhNuNIjwFs0n90xVsNAFmNzvVeQYpIYMeRXzLTp1tw2b jlF6lKU0PaP8nI3HS8qt9NORqvbJEqbquZAeiTxpWm+EYBwBpkPOMGxKYeA40F4KgMxC eLpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=GofmFicM0Ot7KWATWSSEdP5X+bhnBzrS2jXewofFGIY=; b=h3m+J4/TiZNh3taQS8LS618YUaU24NHpg/bm/vn98ASSlkiSrkkHVhy6ZYxQ5au5Br OaXVfWQo5CQGgkJY+OcfwTEJXgBYMbGZNoeOZw8x6k2bUX432kWGpeeIEEnPdp4ZtRQp 2Yl/KEZLyGVTih6XACa0jvpwhh5YX8GOuhmUas86RBYtlvAfdfb+QVXpqM8ognHdSzsS MVwBPPkZjZHI+E+103cRSifDCDX8NzofDOC4XayQ+kqcjc7IGkj7OnvZ6EC6RLlSQSVY /KG3uqqKNmOgjI5H7MLGuOEVtMBWxhlqdIYUoWAKyM/BY/L+wrrrA//1lhHHDyIPAY9l 90PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kqT6pe5d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc24si1271780edb.15.2020.06.29.22.48.59; Mon, 29 Jun 2020 22:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kqT6pe5d; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729949AbgF3FqE (ORCPT + 99 others); Tue, 30 Jun 2020 01:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729941AbgF3FqC (ORCPT ); Tue, 30 Jun 2020 01:46:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE64BC03E979 for ; Mon, 29 Jun 2020 22:46:01 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1593495960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GofmFicM0Ot7KWATWSSEdP5X+bhnBzrS2jXewofFGIY=; b=kqT6pe5d+ywJEQM3b0TTNx5/R+dEd3w5ZvCRXzmdlBKadJbpHbkRTw/kbTJDyv4x9j6uHN V4Nvmkz536Qs6hIi7Z9hGJf/NxpFkO7VuXTxI2s4F/qv1XLzCamlxSRlNCIM5Dq60nlz+A U9qxL8x3Z70zsFmMLQuSU3PancZKIKgHnchM5wuiVpAgZ5jMdtucCGAJ5kzlAXp3xupas4 vguMIdIMgSrrwO8rV6+9iRTfanhbZHNPNLxWGCbeK/NqyA8r5vhGWHj21UFie5E+6ANysn hYxhtH9yXFgud8UXRfOP46gtFOa+kUexIZPHMvYgtGYIwPIi8DBVprRYMy4p5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1593495960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GofmFicM0Ot7KWATWSSEdP5X+bhnBzrS2jXewofFGIY=; b=4TrtQC+KizuLTg10cuqZBWFg8S9iRoVB7uzNi73Qci2//bZiyuf7TVj6e2uGi49ogjzXUx 3kk8VRA/xXOljmAw== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" , John Stultz , Stephen Boyd Subject: [PATCH v3 13/20] timekeeping: Use sequence counter with associated raw spinlock Date: Tue, 30 Jun 2020 07:44:45 +0200 Message-Id: <20200630054452.3675847-14-a.darwish@linutronix.de> In-Reply-To: <20200630054452.3675847-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200630054452.3675847-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_raw_spinlock_t data type, which allows to associate a raw spinlock with the sequence counter. This enables lockdep to verify that the raw spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish --- kernel/time/timekeeping.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index d20d489841c8..05ecfd8a3314 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -39,18 +39,19 @@ enum timekeeping_adv_mode { TK_ADV_FREQ }; +static DEFINE_RAW_SPINLOCK(timekeeper_lock); + /* * The most important data for readout fits into a single 64 byte * cache line. */ static struct { - seqcount_t seq; + seqcount_raw_spinlock_t seq; struct timekeeper timekeeper; } tk_core ____cacheline_aligned = { - .seq = SEQCNT_ZERO(tk_core.seq), + .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_core.seq, &timekeeper_lock), }; -static DEFINE_RAW_SPINLOCK(timekeeper_lock); static struct timekeeper shadow_timekeeper; /** @@ -63,7 +64,7 @@ static struct timekeeper shadow_timekeeper; * See @update_fast_timekeeper() below. */ struct tk_fast { - seqcount_t seq; + seqcount_raw_spinlock_t seq; struct tk_read_base base[2]; }; @@ -80,11 +81,13 @@ static struct clocksource dummy_clock = { }; static struct tk_fast tk_fast_mono ____cacheline_aligned = { + .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_fast_mono.seq, &timekeeper_lock), .base[0] = { .clock = &dummy_clock, }, .base[1] = { .clock = &dummy_clock, }, }; static struct tk_fast tk_fast_raw ____cacheline_aligned = { + .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_fast_raw.seq, &timekeeper_lock), .base[0] = { .clock = &dummy_clock, }, .base[1] = { .clock = &dummy_clock, }, }; @@ -157,7 +160,7 @@ static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta) * tk_clock_read - atomic clocksource read() helper * * This helper is necessary to use in the read paths because, while the - * seqlock ensures we don't return a bad value while structures are updated, + * seqcount ensures we don't return a bad value while structures are updated, * it doesn't protect from potential crashes. There is the possibility that * the tkr's clocksource may change between the read reference, and the * clock reference passed to the read function. This can cause crashes if @@ -222,10 +225,10 @@ static inline u64 timekeeping_get_delta(const struct tk_read_base *tkr) unsigned int seq; /* - * Since we're called holding a seqlock, the data may shift + * Since we're called holding a seqcount, the data may shift * under us while we're doing the calculation. This can cause * false positives, since we'd note a problem but throw the - * results away. So nest another seqlock here to atomically + * results away. So nest another seqcount here to atomically * grab the points we are checking with. */ do { @@ -486,7 +489,7 @@ EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns); * * To keep it NMI safe since we're accessing from tracing, we're not using a * separate timekeeper with updates to monotonic clock and boot offset - * protected with seqlocks. This has the following minor side effects: + * protected with seqcounts. This has the following minor side effects: * * (1) Its possible that a timestamp be taken after the boot offset is updated * but before the timekeeper is updated. If this happens, the new boot offset -- 2.20.1