Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp508704pxa; Thu, 27 Aug 2020 08:13:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm6uNuMGQhWprIhqYXVdF9QqoQAyzUyBW4inkoTkxBk0qBjxu83tWkayvTvdIDbqW1ZWF9 X-Received: by 2002:a50:c089:: with SMTP id k9mr19756183edf.110.1598541199564; Thu, 27 Aug 2020 08:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598541199; cv=none; d=google.com; s=arc-20160816; b=Kpqeb2nVgixHBn48hjsMdKA5oHrXxkTX1F9mtubasmecZaeiRY5sIdBCsiPcFujOFJ sf2k+ZDhyf/5xCGSB1EbBUdW0kfmn9oV24JOwPReZh0iJoFaQQqAT3cn/9TpmiZ3vDUv /VXDBcwPBuaDHOihKc/o/eAriwy5rkMGEtmcMTSXFUs0SP2clZxZ5FGTi0WsUevVK2DJ f8LbEWDP63AWosuN1UpC2CJ8AiVI44/0R8L14+A5j6xGc9W1gDcABAo/mKBVTNYSgS85 cKfcef29C7kQnQ4f2eObJudMjMB//WNPwRmUAMz3GVqMiz77vnFdfYeaUOoazJIDJ0Em rzRQ== 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=9TountMAhWj6L2citLNZtIcuiTiV+gspqfLLvjcSxlQ=; b=b1qsfxi0MYMLhEoq2xgtEmirvPm9oz0fSJRuY3uN+mR7PuXjJTbDolM2zJA5LYo58w eA5CFP8B8xE9yenowKjfRxXxYREXoKKfCIWsVbs16U30qb8VpRZux0fJGhIjhZzanAzw CWD12QguH5Nw+nJ45Kb2LRMiaHEznegsBVKRAL4A6MTJ8/zOkH23zFCp8Rh3UnuWaXEs P4AKrotFnrUjM4yn6Hi9OgNq+GrGcJa9ydgEgCAT9YLsawkpMJiTDXNuOlP5KPudBPMM c4vsjv3mLPSIa1RuoJ3ht85GrdtoqBz3XqNGfGNOtCYh9WWeYNmAQvzx6yjRTEwMSJ6B ylXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XxK20qgz; dkim=neutral (no key) header.i=@vger.kernel.org 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 b1si1485001ejb.739.2020.08.27.08.12.55; Thu, 27 Aug 2020 08:13:19 -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=XxK20qgz; dkim=neutral (no key) header.i=@vger.kernel.org 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 S1728210AbgH0PLu (ORCPT + 99 others); Thu, 27 Aug 2020 11:11:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728735AbgH0Lkz (ORCPT ); Thu, 27 Aug 2020 07:40:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F120DC061232 for ; Thu, 27 Aug 2020 04:40:54 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598528453; 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=9TountMAhWj6L2citLNZtIcuiTiV+gspqfLLvjcSxlQ=; b=XxK20qgztTckGR2f0mHBViWulUtVbdJufdJHKQgUyZksVwy4NSJjzY653yTqIPAPbLCRJJ rfXOPqOqkxxJQ7vDhKVFgk0XUgHG3rP0KMr+Aniw1+iMm/evV1sBhsQjiGkP602pePxv77 fVuPFV5F9POtitq/3eyHz2bslWawd01JtQQDC+A2OWXsTcv2QNKl9nxUnf5nSZzs8WZdnJ nWS1tWZoEBkX4uZ0efeq2gXf6dptOZbgV27a0dmcXXSWpvWrnnbotwWiRfP5Edcb1yizq6 N2EuTQR6P5UTGmHS1B2904qnczaaa0/3FWz5jwXp956IQGmznOpvK8PB+gf8gA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598528453; 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=9TountMAhWj6L2citLNZtIcuiTiV+gspqfLLvjcSxlQ=; b=hvvxiz98eS4Ox+crMabgacjziunE5QupkEiScL9gG2bey14RIdrvuheoOxOpJh1onLeqRb MHks9DkACRdHBBBg== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Sebastian A. Siewior" , LKML , "Ahmed S. Darwish" , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v1 6/8] x86/tsc: Use seqcount_latch_t Date: Thu, 27 Aug 2020 13:40:42 +0200 Message-Id: <20200827114044.11173-7-a.darwish@linutronix.de> In-Reply-To: <20200827114044.11173-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200827114044.11173-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 Latch sequence counters have unique read and write APIs, and thus seqcount_latch_t was recently introduced at seqlock.h. Use that new data type instead of plain seqcount_t. This adds the necessary type-safety and ensures that only latching-safe seqcount APIs are to be used. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/tsc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 49d925043171..cbf17e9f1d03 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -54,7 +54,7 @@ struct clocksource *art_related_clocksource; struct cyc2ns { struct cyc2ns_data data[2]; /* 0 + 2*16 = 32 */ - seqcount_t seq; /* 32 + 4 = 36 */ + seqcount_latch_t seq; /* 32 + 4 = 36 */ }; /* fits one cacheline */ @@ -68,19 +68,21 @@ early_param("tsc_early_khz", tsc_early_khz_setup); __always_inline void cyc2ns_read_begin(struct cyc2ns_data *data) { + seqcount_latch_t *seqcount; int seq, idx; preempt_disable_notrace(); + seqcount = &this_cpu_ptr(&cyc2ns)->seq; do { - seq = this_cpu_read(cyc2ns.seq.sequence); + seq = raw_read_seqcount_latch(seqcount); idx = seq & 1; data->cyc2ns_offset = this_cpu_read(cyc2ns.data[idx].cyc2ns_offset); data->cyc2ns_mul = this_cpu_read(cyc2ns.data[idx].cyc2ns_mul); data->cyc2ns_shift = this_cpu_read(cyc2ns.data[idx].cyc2ns_shift); - } while (unlikely(seq != this_cpu_read(cyc2ns.seq.sequence))); + } while (read_seqcount_latch_retry(seqcount, seq)); } __always_inline void cyc2ns_read_end(void) @@ -186,7 +188,7 @@ static void __init cyc2ns_init_boot_cpu(void) { struct cyc2ns *c2n = this_cpu_ptr(&cyc2ns); - seqcount_init(&c2n->seq); + seqcount_latch_init(&c2n->seq); __set_cyc2ns_scale(tsc_khz, smp_processor_id(), rdtsc()); } @@ -203,7 +205,7 @@ static void __init cyc2ns_init_secondary_cpus(void) for_each_possible_cpu(cpu) { if (cpu != this_cpu) { - seqcount_init(&c2n->seq); + seqcount_latch_init(&c2n->seq); c2n = per_cpu_ptr(&cyc2ns, cpu); c2n->data[0] = data[0]; c2n->data[1] = data[1]; -- 2.28.0