Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp372106pxa; Thu, 27 Aug 2020 04:55:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqybhed+b5RJP0ok2cUKJW+eByUmrTuh89fwwj9t8qDM+nv1pUNWu9Q1bjudAaN6RdmwQG X-Received: by 2002:a17:907:72d2:: with SMTP id du18mr7055950ejc.359.1598529348123; Thu, 27 Aug 2020 04:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598529348; cv=none; d=google.com; s=arc-20160816; b=ZoekpxW7++ItpoJSLF4BN2L4cOih6mQ/pUxzDqO1oZlhxAlt8w/cRpxbHVg/66wgEK Hwo2d1EHMkTIQZ3VzTPzfBnjLEyqhRJYTOrpaDDvJ8vpeKkMqeZw8NRHmBE86nj3eAoM 4gO1rp52z86WfoWUTgcz4b+zDwZFAMeDgNM3+rl/Jaw9pIzIyWA1cgTupV7RIMzoKuyj aoRIiq82/izLSsekYVLGudzsb8DveM4h9S/72g/bCQqxpZlx2Wx1OshC42Xuj36CsYnn 74DLhbmYZwD4TuqX2E/TTTu0o1/Byvjv/6fnfqFf5aw4/KMnTfWnAnFahT+YOvMop3yG wQYA== 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=5yW6UWqShjkqpT4CJrOfJI69Xnpi5/tapvijWzXrGwU=; b=kWEPtvjWGYhrPBcUsUEWgSyQDQQ0TciSPB7H+TZwgfDer3XeMGN61G2jMAbxZigdWq 1ByJGEFO6XPy9PISDop5+/SPwmacdVlf9Ck0c2unsIDGzqlQ2pi78rds8MWNuPSLQOVf AsVWi8wPFiRW3FKnyk1Kaxtjfl0HxEExt1CCi0yeD1D1vaguKwDmhWL2V78lp1MNluYd cM4R9NT2OaW/Ri7VniNE0xZWpIX64nAxdxmBv02Me9Wal2Qv+14IYcoL1XNxIxFDKIr/ 6QKX5W47fhSUBB9FIWwxgy4z0lMk49SNnTp009moEgATvbCcUJLg7Dn0l1yd+QiikL+O jolg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mKp2X5xO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CzVsPmaG; 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 b4si1272525edr.513.2020.08.27.04.55.25; Thu, 27 Aug 2020 04:55:48 -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=mKp2X5xO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=CzVsPmaG; 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 S1728907AbgH0Ly4 (ORCPT + 99 others); Thu, 27 Aug 2020 07:54:56 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38254 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728802AbgH0LlE (ORCPT ); Thu, 27 Aug 2020 07:41:04 -0400 From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598528462; 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=5yW6UWqShjkqpT4CJrOfJI69Xnpi5/tapvijWzXrGwU=; b=mKp2X5xOPvrMJfz7ehRotTqQGzLs1tyMTWC6dIKAL1DTsjE9HllSC+a3+YPSUsD7BP2fSr 5FhzBehT+C4VMTrz8dnkrSPDCYfFsE4D/b3R8Zn6lML84U6q+KtN6a71kZqYYplj96DwDh 3/mRnAQHh/yKZ1kMfbjaQiy7/5jzD5sRSkVQISe22wSE1E0DBF4nzaaiCL3vWWpwhf2KLx dFdWMecfUIEEe2wOVAihScYuHLpItCA1sKkosNwzx+VzrIa/gtmy4R/lwmALJEr+T7YIVq 94vWP+1CvDW2N3jHyNPxGeuhxI4pHSuFuiiX8rYnRAAZshqxR/XU1GB3SNUFBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598528462; 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=5yW6UWqShjkqpT4CJrOfJI69Xnpi5/tapvijWzXrGwU=; b=CzVsPmaGkSspWa8Wm5KuG2pXNR4xBNdreEC90d3BfrzRp8L/yAYTxhFvledQceg+/t5JkV dXTW+AXL321RZ+DQ== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Sebastian A. Siewior" , LKML , "Ahmed S. Darwish" Subject: [PATCH v1 8/8] seqlock: seqcount latch APIs: Only allow seqcount_latch_t Date: Thu, 27 Aug 2020 13:40:44 +0200 Message-Id: <20200827114044.11173-9-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 All latch sequence counter call-sites have now been converted from plain seqcount_t to the new seqcount_latch_t data type. Enforce type-safety by modifying seqlock.h latch APIs to only accept seqcount_latch_t. Signed-off-by: Ahmed S. Darwish --- include/linux/seqlock.h | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index f83fbf2180db..04db28499331 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -620,7 +620,7 @@ static inline void seqcount_latch_init(seqcount_latch_t *s) /** * raw_read_seqcount_latch() - pick even/odd latch data copy - * @s: Pointer to seqcount_t, seqcount_raw_spinlock_t, or seqcount_latch_t + * @s: Pointer to seqcount_latch_t * * See raw_write_seqcount_latch() for details and a full reader/writer * usage example. @@ -629,17 +629,14 @@ static inline void seqcount_latch_init(seqcount_latch_t *s) * picking which data copy to read. The full counter must then be checked * with read_seqcount_latch_retry(). */ -#define raw_read_seqcount_latch(s) \ -({ \ - /* \ - * Pairs with the first smp_wmb() in raw_write_seqcount_latch(). \ - * Due to the dependent load, a full smp_rmb() is not needed. \ - */ \ - _Generic(*(s), \ - seqcount_t: READ_ONCE(((seqcount_t *)s)->sequence), \ - seqcount_raw_spinlock_t: READ_ONCE(((seqcount_raw_spinlock_t *)s)->seqcount.sequence), \ - seqcount_latch_t: READ_ONCE(((seqcount_latch_t *)s)->seqcount.sequence)); \ -}) +static inline unsigned raw_read_seqcount_latch(const seqcount_latch_t *s) +{ + /* + * Pairs with the first smp_wmb() in raw_write_seqcount_latch(). + * Due to the dependent load, a full smp_rmb() is not needed. + */ + return READ_ONCE(s->seqcount.sequence); +} /** * read_seqcount_latch_retry() - end a seqcount_latch_t read section @@ -656,7 +653,7 @@ read_seqcount_latch_retry(const seqcount_latch_t *s, unsigned start) /** * raw_write_seqcount_latch() - redirect latch readers to even/odd copy - * @s: Pointer to seqcount_t, seqcount_raw_spinlock_t, or seqcount_latch_t + * @s: Pointer to seqcount_latch_t * * The latch technique is a multiversion concurrency control method that allows * queries during non-atomic modifications. If you can guarantee queries never @@ -735,14 +732,11 @@ read_seqcount_latch_retry(const seqcount_latch_t *s, unsigned start) * When data is a dynamic data structure; one should use regular RCU * patterns to manage the lifetimes of the objects within. */ -#define raw_write_seqcount_latch(s) \ -{ \ - smp_wmb(); /* prior stores before incrementing "sequence" */ \ - _Generic(*(s), \ - seqcount_t: ((seqcount_t *)s)->sequence++, \ - seqcount_raw_spinlock_t:((seqcount_raw_spinlock_t *)s)->seqcount.sequence++, \ - seqcount_latch_t: ((seqcount_latch_t *)s)->seqcount.sequence++); \ - smp_wmb(); /* increment "sequence" before following stores */ \ +static inline void raw_write_seqcount_latch(seqcount_latch_t *s) +{ + smp_wmb(); /* prior stores before incrementing "sequence" */ + s->seqcount.sequence++; + smp_wmb(); /* increment "sequence" before following stores */ } /* -- 2.28.0