From nobody Sat Jan 07 19:16:56 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Nq91j02bWz2sMKK; Sat, 7 Jan 2023 19:16:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Nq91h6lJQz3jbr; Sat, 7 Jan 2023 19:16:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673119016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZPRJSeZJW79g5SRDmHA/266w84g4YTtsy9hw0ZYOFCU=; b=F9+U3OjEMEuhs6EndMrPd/Zhfni1clc/yFrddyD3jX3f6pM8UOTUfaUm14acRR3wWWHUsr nzaQd4c37OybCQiAHu1Q/I0L/F0c9v9vCvZRImg0JLnj6Se1vOOyjeYlUHRXaznBDfLLox nLJcplx/+2Qmi9toQEApcN/fMS7X3Qo8Hrt4lXocjMG4hvS/5rzzHjepyFz61cWDK7PEpS mQ26Ln5QsXiOh0f4tcBP9a6TicmOFuW5+seD+Mjj1z78XL3nYr4obPrIS4fSE0ceK/YNzs ZyeY1IMkfUbAtl3ml9vB+FkDYQjwOJTWzhoSDDD4Y8Pcws/5jEpOCHrP5YVEhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673119016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZPRJSeZJW79g5SRDmHA/266w84g4YTtsy9hw0ZYOFCU=; b=ZowUWNwH116I3VojQziVhQfn1+PLuU7sZ8eQRx6XyW9CB6SJniLNiRz2FG4WqQ1Zq1sHJ1 DzaICI2gnzyr3HN/xWV6q8bEdnotLF6pD6vPZ5QzsYu0C1mGd0IWUgiyno8fWGPIAM4Fmd /Dx96MU6CaorgF/KU0dmTnF2BNC1CTXXIeiqbKpcaOk6VSSBEp2F/fUnYt15o8PN25xh2Y Rr3ZmccyaB0GWCoT32apanRr08UgPjSEOoK1K6XYJ0qWcH/x3OlB5dPAfyqpxB9w7RXG21 hUsOaZqYzoPxkVxO/6T+etXWLmZ35t1T1HOeveiBkxWbn3lF8zwA0bm+JhhIDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673119016; a=rsa-sha256; cv=none; b=QBbaq2edkwoEgUKrfGWKl95P5gN2yXUHdmZr5NyQ6mwlPEMwDL1byajS/oReWDvB96qTwO tYbeABwmYok7Knk33/LFZm14O4P4Z7zOj4VY8Y1jRwgBGzyEy8pewWEZWZmJe1kKrxPMHF fsPL8UA0y4AZCzcUiX+tz/eZPBkj0nxPuJw3OLs2fmlbclLbcN46PBZOtvQx8coq52MfkG Kyx5AAJvvcnjy/OzNjofW9O7f1TCvddil2YoYMS5h7GzssUMlEz4pIf8lkiJ7s6/3Yjksx Ahysk+U7X5F2sDvDlnP03BqpAwKITxbbAEXvOZmrTSZNnSRtFD/ew6SCPV/jJA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Nq91h5nybzKt6; Sat, 7 Jan 2023 19:16:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 307JGu77070174; Sat, 7 Jan 2023 19:16:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 307JGu5B070173; Sat, 7 Jan 2023 19:16:56 GMT (envelope-from git) Date: Sat, 7 Jan 2023 19:16:56 GMT Message-Id: <202301071916.307JGu5B070173@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 84839d66d583 - stable/13 - linuxkpi: Add `seqcount_mutex_t` support in List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 84839d66d583ad97603eba210d42f993445a1e5c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=84839d66d583ad97603eba210d42f993445a1e5c commit 84839d66d583ad97603eba210d42f993445a1e5c Author: Jean-Sébastien Pédron AuthorDate: 2022-12-01 13:58:27 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-01-07 12:30:18 +0000 linuxkpi: Add `seqcount_mutex_t` support in To achieve that, the header uses the C11 type generic selection keyboard _Generic() because the macros are supposed to work with seqcount_t and seqcount_mutex_t. (cherry picked from commit 18e411233722088400624f21b66eb6687ebe8861) --- sys/compat/linuxkpi/common/include/linux/seqlock.h | 91 +++++++++++++++++++--- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/seqlock.h b/sys/compat/linuxkpi/common/include/linux/seqlock.h index 2f4892525e8a..c520de90eca8 100644 --- a/sys/compat/linuxkpi/common/include/linux/seqlock.h +++ b/sys/compat/linuxkpi/common/include/linux/seqlock.h @@ -33,8 +33,11 @@ #include #include #include +#include #include +#include + struct lock_class_key; struct seqcount { @@ -48,6 +51,12 @@ struct seqlock { }; typedef struct seqlock seqlock_t; +struct seqcount_mutex { + struct mutex *seqm_lock; + struct seqcount seqm_count; +}; +typedef struct seqcount_mutex seqcount_mutex_t; + static inline void __seqcount_init(struct seqcount *seqcount, const char *name __unused, struct lock_class_key *key __unused) @@ -57,37 +66,99 @@ __seqcount_init(struct seqcount *seqcount, const char *name __unused, #define seqcount_init(seqcount) __seqcount_init(seqcount, NULL, NULL) static inline void -write_seqcount_begin(struct seqcount *seqcount) +seqcount_mutex_init(struct seqcount_mutex *seqcount, struct mutex *mutex) +{ + seqcount->seqm_lock = mutex; + seqcount_init(&seqcount->seqm_count); +} + +#define write_seqcount_begin(s) \ + _Generic(*(s), \ + struct seqcount: lkpi_write_seqcount_begin, \ + struct seqcount_mutex: lkpi_write_seqcount_mutex_begin \ + )(s) + +static inline void +lkpi_write_seqcount_begin(struct seqcount *seqcount) { seqc_sleepable_write_begin(&seqcount->seqc); } static inline void -write_seqcount_end(struct seqcount *seqcount) +lkpi_write_seqcount_mutex_begin(struct seqcount_mutex *seqcount) +{ + mutex_lock(seqcount->seqm_lock); + lkpi_write_seqcount_begin(&seqcount->seqm_count); +} + +#define write_seqcount_end(s) \ + _Generic(*(s), \ + struct seqcount: lkpi_write_seqcount_end, \ + struct seqcount_mutex: lkpi_write_seqcount_mutex_end \ + )(s) + +static inline void +lkpi_write_seqcount_end(struct seqcount *seqcount) { seqc_sleepable_write_end(&seqcount->seqc); } -/* - * XXX: Are predicts from inline functions still not honored by clang? - */ -#define __read_seqcount_retry(seqcount, gen) \ - (!seqc_consistent_nomb(&(seqcount)->seqc, gen)) -#define read_seqcount_retry(seqcount, gen) \ - (!seqc_consistent(&(seqcount)->seqc, gen)) +static inline void +lkpi_write_seqcount_mutex_end(struct seqcount_mutex *seqcount) +{ + lkpi_write_seqcount_end(&seqcount->seqm_count); + mutex_unlock(seqcount->seqm_lock); +} + +#define read_seqcount_begin(s) \ + _Generic(*(s), \ + struct seqcount: lkpi_read_seqcount_begin, \ + struct seqcount_mutex: lkpi_read_seqcount_mutex_begin \ + )(s) static inline unsigned -read_seqcount_begin(const struct seqcount *seqcount) +lkpi_read_seqcount_begin(const struct seqcount *seqcount) { return (seqc_read(&seqcount->seqc)); } +static inline unsigned +lkpi_read_seqcount_mutex_begin(const struct seqcount_mutex *seqcount) +{ + return (lkpi_read_seqcount_begin(&seqcount->seqm_count)); +} + static inline unsigned raw_read_seqcount(const struct seqcount *seqcount) { return (seqc_read_any(&seqcount->seqc)); } +/* + * XXX: Are predicts from inline functions still not honored by clang? + */ +#define __read_seqcount_retry(seqcount, gen) \ + (!seqc_consistent_nomb(&(seqcount)->seqc, gen)) +#define read_seqcount_retry(s, old) \ + _Generic(*(s), \ + struct seqcount: lkpi_read_seqcount_retry, \ + struct seqcount_mutex: lkpi_read_seqcount_mutex_retry \ + )(s, old) + +static inline int +lkpi_read_seqcount_retry( + const struct seqcount *seqcount, unsigned int old) +{ + return (!seqc_consistent(&seqcount->seqc, old)); +} + +static inline int +lkpi_read_seqcount_mutex_retry( + const struct seqcount_mutex *seqcount, unsigned int old) +{ + return (!seqc_consistent(&seqcount->seqm_count.seqc, old)); +} + static inline void seqlock_init(struct seqlock *seqlock) {