From nobody Thu Dec 01 14:04:40 2022 X-Original-To: dev-commits-src-main@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 4NNHrS5tz8z4jHhh; Thu, 1 Dec 2022 14:04:40 +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 4NNHrS56Kwz3nmg; Thu, 1 Dec 2022 14:04:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669903480; 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=qd0Tn2cd+jFhL4YXHTrgum/DUzmeZHz5TYe/hDYALuM=; b=noTSF4YweEcc5PeEn2UZsWkkKR/2hoTyl5m9WlmGQyMl8bL9VC834SwFtWB1Gsw+BbRDdX Ca8tQP22eE1gHz50fAd8wLpPJzXPfO5nBaCy9SvQ+bcO+c0VHZc/2v5vn1qZiQWoAT52PL CzMUtGEeMiGV9cQjEQBU30w9UgsLXXMn8urSArgYl263S6JjI6dtSwKdRaYgRKlp7ytHW0 XRMPU6bJho0mlDNpUi3XZSJ2RG4J3t7fG7eoI9InIeE9vsVRAv/Wfqv66hvf2IYd+1+JcE qj7qq12wPwQBAS0pT76NcKohp/v30rktP4XJ/OGicDL1fzpAwRkBq0+qFgaHhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669903480; 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=qd0Tn2cd+jFhL4YXHTrgum/DUzmeZHz5TYe/hDYALuM=; b=PaCwGJmx1/LG6uaIwmGROFsNsTILSMZ9KBV10++E0yduVWWiQQMB77LMsE5VG6a85Ermcc 2LlSh4YdiR9XRStmBNJCvbqFcfV6HE4Rx1m87jYdTnfFFK+Hn2CRglkvKXTowRTwDimKpV SFWOE+b09/miWeO1+nS18mVCf6ZyjDAJ+il6BGH6v7LPFbp8IUIquOvjkG89yx9Sq0O2zJ Yy6HIKcSKr6sH8wQu1krP9aqO8rvuYHCZf8CwkRBOoGsR3hDlRDgyduCokLCI8bV4SguAU DFe+aqwsfxFN1ZXhrdBWa090Ov1NhU648TD37I8iI3IANhGONquIIB+S1aaXCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669903480; a=rsa-sha256; cv=none; b=EC0KQ8dxvhpDTFz6Y/Enltoq8Sz1EgCrh5mxgJB173fqrANhfbSFDEU9F1SZZsQKmZDyvT Z3NsfF6tL7CGc6TcVgfH0KakPW2Mlpipn2FuochnEkkfqvEf1UPW3erxuZpZYX0FWSQ8z5 zDcXv9SyQqwbbb1rojmdwJXeJCKAjP/ei5imG67RXohzEwVp2x1gpvssUuia4CPltSJt4G YrdADHFtqavpok4VJcpXr5I0gKV6hraIlF763HEa092PKcSKzdwU53YzjrjezFsLVOYbt9 6HkDTdnxUky8DFt9o03sNTbJ/MwgofBnLStEn6pD2BejdgtosF3p53Wh+IJfdw== 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 4NNHrS47NxzfsM; Thu, 1 Dec 2022 14:04:40 +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 2B1E4eMu050723; Thu, 1 Dec 2022 14:04:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B1E4eJE050722; Thu, 1 Dec 2022 14:04:40 GMT (envelope-from git) Date: Thu, 1 Dec 2022 14:04:40 GMT Message-Id: <202212011404.2B1E4eJE050722@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 18e411233722 - main - linuxkpi: Add `seqcount_mutex_t` support in List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 18e411233722088400624f21b66eb6687ebe8861 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=18e411233722088400624f21b66eb6687ebe8861 commit 18e411233722088400624f21b66eb6687ebe8861 Author: Jean-Sébastien Pédron AuthorDate: 2022-12-01 13:58:27 +0000 Commit: Emmanuel Vadot CommitDate: 2022-12-01 13:58:27 +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. Differential Revision: https://reviews.freebsd.org/D36965 --- 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 6e81e7a0fa45..4a5385f5e095 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_no_fence(&(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_no_fence(&(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) {