From nobody Sun Nov 24 18:36:33 2024 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 DE7271C07F7 for ; Mon, 4 Nov 2024 16:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730737177; cv=none; b=AbojaQ9jy3KgRliBhCDNMAE9Aqm8DzSwmiysGO3UibyNcM5Aq+b5uNKc8V8aj6o1KRHZ0LYHgVPkT7v9LZZfBQa0Xhw0iM43W06gkbVtFTyxB6gDXW4MUomIuuCL/JTdicVC6qaBCd0XwaL7G1R++J1pqbDNtMgO7ITnQ4KJPl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730737177; c=relaxed/simple; bh=2Zf6Wh7WwMTJz5DSSx3o7r0wmY9f2/IMOwLW/s4U3UQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=asfLZxpawLz32cFh/eb/BQScI2+wW9bsVIJaZv30USC/BbNSyuopTMY1sl9tkwc4AODV7wGQEQOZYBxTMsaHhh5fJ2g8/oVJzeZKzCRni5BIj51zLIr5TfClYpBw/7ePfQsW8dZCHKKokpU4tyEGsPdTL6QuyN8+R1oySHTbNEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OpJAcVhN; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OpJAcVhN" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-a9a1be34c61so150222166b.1 for ; Mon, 04 Nov 2024 08:19:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730737174; x=1731341974; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=D01NtyTMk6i2oodCmqKoOULZz5EC2eZ4CIhcaLc7Lms=; b=OpJAcVhNuDY/xvw8cHPEeBBJktdGIcXB7dAGEs5Lw2+N10jK8DKZP4f1uCbxVHU+nO iiWhrtkeeWSkGtZXZ1Q6J+eHj1nuX0VdRLhrCDtSx3WFe0JF0fTmPiOrskuUfvBWV6iT LskDZRwINdN4zhirCkT1PkZZpFCDJB6lRF2I7G/vnK7+0txm3Zg+BY6P6+Qt37RmIBjx /vmydqSATjAPUxakqo4DMzNMpCaN9NFEC/iCpOobpESZrxQF3ANYm8Uz2/cgEBK88+Qj dtruB9c+FLhnPLqVj9paGhbFkdgzUiDd7GY0XoUv6kilgVqqVHWsG89dNzXerbYyZab5 aHEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730737174; x=1731341974; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D01NtyTMk6i2oodCmqKoOULZz5EC2eZ4CIhcaLc7Lms=; b=Va3sYkCmu4mPku9cM+bpXOzgN50CMeDhDJWl88zA8CygeRjiX7UM1HT0Yr2m95Ipc5 W1mMcv5h/aXAR5LBZOkevQKIIxYzOb6yuiZxqjNodljA/KgqU7+J2TrDfXHXfItQWgPu 90kmcTyfmRYHRhAz4Y4xPjcHLTiPJzVP4mcdBbNBH9bQnV5Xks4YmHOaZjClSIWvSBMd 3R/OAo2dIOE8U4dFxz8RIaGIR9RKiirn8Es4HuwN3ljy4nwXTX+7gQlp1mM9Op/a5TyR LQe6Dup5CMaeyvao0RWPXMudKEB793Mz47bNmXiYUv8yFutrYdSybs+Q76oCdfc3OORM GltQ== X-Forwarded-Encrypted: i=1; AJvYcCUjBL/5PgIMUjEw6gVMTo50d+9jYe6HQwBIF1lGbdXmEzmF23kT8DV7gBsLsi7BCIS7mGtdNkjh2s9hd34=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj5/QYzzop/AACFn5nJnIMHA5gu3ub5G+W4+xYY8xT52fnnZx7 GMP2rtgEuFfJyDJlFmR1icepza9OxHCjZSo+HHdccck90dfqdYHOmXluNU/BC+FNUEjqhRv9+g= = X-Google-Smtp-Source: AGHT+IE04dEG4Y5MUmrGycRsDe0dmIy+dy7/bFzFTwDynvSgS0Tjs/YvxNAZJ2cTxdozb20CkU05HfKJJA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:dc4d:3b27:d746:73ee]) (user=elver job=sendgmr) by 2002:a17:906:c0c1:b0:a99:fa8a:9783 with SMTP id a640c23a62f3a-a9e654bee59mr296866b.3.1730737174017; Mon, 04 Nov 2024 08:19:34 -0800 (PST) Date: Mon, 4 Nov 2024 16:43:08 +0100 In-Reply-To: <20241104161910.780003-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241104161910.780003-1-elver@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241104161910.780003-5-elver@google.com> Subject: [PATCH v2 4/5] seqlock, treewide: Switch to non-raw seqcount_latch interface From: Marco Elver To: elver@google.com, Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Cc: "Paul E. McKenney" , Thomas Gleixner , Mark Rutland , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch all instrumentable users of the seqcount_latch interface over to the non-raw interface. Link: https://lore.kernel.org/all/20241030204815.GQ14555@noisy.programming.= kicks-ass.net/ Co-developed-by: Peter Zijlstra (Intel) Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Marco Elver --- v2: * New patch. --- arch/x86/kernel/tsc.c | 5 +++-- include/linux/rbtree_latch.h | 20 +++++++++++--------- kernel/printk/printk.c | 9 +++++---- kernel/time/sched_clock.c | 12 +++++++----- kernel/time/timekeeping.c | 12 +++++++----- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index dfe6847fd99e..67aeaba4ba9c 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -174,10 +174,11 @@ static void __set_cyc2ns_scale(unsigned long khz, int= cpu, unsigned long long ts =20 c2n =3D per_cpu_ptr(&cyc2ns, cpu); =20 - raw_write_seqcount_latch(&c2n->seq); + write_seqcount_latch_begin(&c2n->seq); c2n->data[0] =3D data; - raw_write_seqcount_latch(&c2n->seq); + write_seqcount_latch(&c2n->seq); c2n->data[1] =3D data; + write_seqcount_latch_end(&c2n->seq); } =20 static void set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long lon= g tsc_now) diff --git a/include/linux/rbtree_latch.h b/include/linux/rbtree_latch.h index 6a0999c26c7c..2f630eb8307e 100644 --- a/include/linux/rbtree_latch.h +++ b/include/linux/rbtree_latch.h @@ -14,7 +14,7 @@ * * If we need to allow unconditional lookups (say as required for NMI cont= ext * usage) we need a more complex setup; this data structure provides this = by - * employing the latch technique -- see @raw_write_seqcount_latch -- to + * employing the latch technique -- see @write_seqcount_latch_begin -- to * implement a latched RB-tree which does allow for unconditional lookups = by * virtue of always having (at least) one stable copy of the tree. * @@ -132,7 +132,7 @@ __lt_find(void *key, struct latch_tree_root *ltr, int i= dx, * @ops: operators defining the node order * * It inserts @node into @root in an ordered fashion such that we can alwa= ys - * observe one complete tree. See the comment for raw_write_seqcount_latch= (). + * observe one complete tree. See the comment for write_seqcount_latch_beg= in(). * * The inserts use rcu_assign_pointer() to publish the element such that t= he * tree structure is stored before we can observe the new @node. @@ -145,10 +145,11 @@ latch_tree_insert(struct latch_tree_node *node, struct latch_tree_root *root, const struct latch_tree_ops *ops) { - raw_write_seqcount_latch(&root->seq); + write_seqcount_latch_begin(&root->seq); __lt_insert(node, root, 0, ops->less); - raw_write_seqcount_latch(&root->seq); + write_seqcount_latch(&root->seq); __lt_insert(node, root, 1, ops->less); + write_seqcount_latch_end(&root->seq); } =20 /** @@ -159,7 +160,7 @@ latch_tree_insert(struct latch_tree_node *node, * * Removes @node from the trees @root in an ordered fashion such that we c= an * always observe one complete tree. See the comment for - * raw_write_seqcount_latch(). + * write_seqcount_latch_begin(). * * It is assumed that @node will observe one RCU quiescent state before be= ing * reused of freed. @@ -172,10 +173,11 @@ latch_tree_erase(struct latch_tree_node *node, struct latch_tree_root *root, const struct latch_tree_ops *ops) { - raw_write_seqcount_latch(&root->seq); + write_seqcount_latch_begin(&root->seq); __lt_erase(node, root, 0); - raw_write_seqcount_latch(&root->seq); + write_seqcount_latch(&root->seq); __lt_erase(node, root, 1); + write_seqcount_latch_end(&root->seq); } =20 /** @@ -204,9 +206,9 @@ latch_tree_find(void *key, struct latch_tree_root *root, unsigned int seq; =20 do { - seq =3D raw_read_seqcount_latch(&root->seq); + seq =3D read_seqcount_latch(&root->seq); node =3D __lt_find(key, root, seq & 1, ops->comp); - } while (raw_read_seqcount_latch_retry(&root->seq, seq)); + } while (read_seqcount_latch_retry(&root->seq, seq)); =20 return node; } diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index beb808f4c367..19911c8fa7b6 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -560,10 +560,11 @@ bool printk_percpu_data_ready(void) /* Must be called under syslog_lock. */ static void latched_seq_write(struct latched_seq *ls, u64 val) { - raw_write_seqcount_latch(&ls->latch); + write_seqcount_latch_begin(&ls->latch); ls->val[0] =3D val; - raw_write_seqcount_latch(&ls->latch); + write_seqcount_latch(&ls->latch); ls->val[1] =3D val; + write_seqcount_latch_end(&ls->latch); } =20 /* Can be called from any context. */ @@ -574,10 +575,10 @@ static u64 latched_seq_read_nolock(struct latched_seq= *ls) u64 val; =20 do { - seq =3D raw_read_seqcount_latch(&ls->latch); + seq =3D read_seqcount_latch(&ls->latch); idx =3D seq & 0x1; val =3D ls->val[idx]; - } while (raw_read_seqcount_latch_retry(&ls->latch, seq)); + } while (read_seqcount_latch_retry(&ls->latch, seq)); =20 return val; } diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 29bdf309dae8..fcca4e72f1ef 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -71,13 +71,13 @@ static __always_inline u64 cyc_to_ns(u64 cyc, u32 mult,= u32 shift) =20 notrace struct clock_read_data *sched_clock_read_begin(unsigned int *seq) { - *seq =3D raw_read_seqcount_latch(&cd.seq); + *seq =3D read_seqcount_latch(&cd.seq); return cd.read_data + (*seq & 1); } =20 notrace int sched_clock_read_retry(unsigned int seq) { - return raw_read_seqcount_latch_retry(&cd.seq, seq); + return read_seqcount_latch_retry(&cd.seq, seq); } =20 static __always_inline unsigned long long __sched_clock(void) @@ -132,16 +132,18 @@ unsigned long long notrace sched_clock(void) static void update_clock_read_data(struct clock_read_data *rd) { /* steer readers towards the odd copy */ - raw_write_seqcount_latch(&cd.seq); + write_seqcount_latch_begin(&cd.seq); =20 /* now its safe for us to update the normal (even) copy */ cd.read_data[0] =3D *rd; =20 /* switch readers back to the even copy */ - raw_write_seqcount_latch(&cd.seq); + write_seqcount_latch(&cd.seq); =20 /* update the backup (odd) copy with the new data */ cd.read_data[1] =3D *rd; + + write_seqcount_latch_end(&cd.seq); } =20 /* @@ -279,7 +281,7 @@ void __init generic_sched_clock_init(void) */ static u64 notrace suspended_sched_clock_read(void) { - unsigned int seq =3D raw_read_seqcount_latch(&cd.seq); + unsigned int seq =3D read_seqcount_latch(&cd.seq); =20 return cd.read_data[seq & 1].epoch_cyc; } diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7e6f409bf311..18752983e834 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -411,7 +411,7 @@ static inline u64 timekeeping_get_ns(const struct tk_re= ad_base *tkr) * We want to use this from any context including NMI and tracing / * instrumenting the timekeeping code itself. * - * Employ the latch technique; see @raw_write_seqcount_latch. + * Employ the latch technique; see @write_seqcount_latch. * * So if a NMI hits the update of base[0] then it will use base[1] * which is still consistent. In the worst case this can result is a @@ -424,16 +424,18 @@ static void update_fast_timekeeper(const struct tk_re= ad_base *tkr, struct tk_read_base *base =3D tkf->base; =20 /* Force readers off to base[1] */ - raw_write_seqcount_latch(&tkf->seq); + write_seqcount_latch_begin(&tkf->seq); =20 /* Update base[0] */ memcpy(base, tkr, sizeof(*base)); =20 /* Force readers back to base[0] */ - raw_write_seqcount_latch(&tkf->seq); + write_seqcount_latch(&tkf->seq); =20 /* Update base[1] */ memcpy(base + 1, base, sizeof(*base)); + + write_seqcount_latch_end(&tkf->seq); } =20 static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf) @@ -443,11 +445,11 @@ static __always_inline u64 __ktime_get_fast_ns(struct= tk_fast *tkf) u64 now; =20 do { - seq =3D raw_read_seqcount_latch(&tkf->seq); + seq =3D read_seqcount_latch(&tkf->seq); tkr =3D tkf->base + (seq & 0x01); now =3D ktime_to_ns(tkr->base); now +=3D __timekeeping_get_ns(tkr); - } while (raw_read_seqcount_latch_retry(&tkf->seq, seq)); + } while (read_seqcount_latch_retry(&tkf->seq, seq)); =20 return now; } --=20 2.47.0.163.g1226f6d8fa-goog