From nobody Wed Dec 14 00:39:26 2022 X-Original-To: dev-commits-src-all@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 4NWxMM2h5yz4kG2H; Wed, 14 Dec 2022 00:39:27 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from glebi.us (glebi.us [162.251.186.162]) by mx1.freebsd.org (Postfix) with ESMTP id 4NWxMM1XrFz43hf; Wed, 14 Dec 2022 00:39:27 +0000 (UTC) (envelope-from glebius@freebsd.org) Authentication-Results: mx1.freebsd.org; none Received: by glebi.us (Postfix, from userid 1000) id 59B222E4D2; Tue, 13 Dec 2022 16:39:26 -0800 (PST) Date: Tue, 13 Dec 2022 16:39:26 -0800 From: Gleb Smirnoff To: Mateusz Guzik Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: e6bc24b0385a - main - kref: switch internal type to atomic_t and bring back const to kref_read Message-ID: References: <202212132047.2BDKl92M065327@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202212132047.2BDKl92M065327@gitrepo.freebsd.org> X-Rspamd-Queue-Id: 4NWxMM1XrFz43hf X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N One u_int32_t sneaked in between multiple uint32_t in this change. On Tue, Dec 13, 2022 at 08:47:09PM +0000, Mateusz Guzik wrote: M> The branch main has been updated by mjg: M> M> URL: https://cgit.FreeBSD.org/src/commit/?id=e6bc24b0385a166526d20b2eb0cbb6a116350075 M> M> commit e6bc24b0385a166526d20b2eb0cbb6a116350075 M> Author: Mateusz Guzik M> AuthorDate: 2022-12-13 20:42:32 +0000 M> Commit: Mateusz Guzik M> CommitDate: 2022-12-13 20:46:58 +0000 M> M> kref: switch internal type to atomic_t and bring back const to kref_read M> M> This unbreak drm-kmod build. M> M> the const is part of Linux API M> M> Unfortunately drm-kmod uses hand-rolled refcount* calls on a kref M> object. For now go the easy route of keeping it operational by casting M> stuff internally. M> M> The general goal here is to make FreeBSD refcount API use an opaque M> type, hence the ongoing removal of hand-rolled accesses. M> M> Reported by: emaste M> --- M> sys/compat/linuxkpi/common/include/linux/kref.h | 22 +++++++++++----------- M> 1 file changed, 11 insertions(+), 11 deletions(-) M> M> diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h M> index 9a6814175223..5a1fd834a58d 100644 M> --- a/sys/compat/linuxkpi/common/include/linux/kref.h M> +++ b/sys/compat/linuxkpi/common/include/linux/kref.h M> @@ -44,35 +44,35 @@ M> M> struct kref { M> /* XXX In Linux this is a refcount_t */ M> - volatile u_int32_t refcount; M> + atomic_t refcount; M> }; M> M> static inline void M> kref_init(struct kref *kref) M> { M> M> - refcount_init(&kref->refcount, 1); M> + refcount_init((uint32_t *)&kref->refcount, 1); M> } M> M> static inline unsigned int M> -kref_read(struct kref *kref) M> +kref_read(const struct kref *kref) M> { M> M> - return (refcount_load(&kref->refcount)); M> + return (refcount_load(__DECONST(u_int32_t *, &kref->refcount))); M> } M> M> static inline void M> kref_get(struct kref *kref) M> { M> M> - refcount_acquire(&kref->refcount); M> + refcount_acquire((uint32_t *)&kref->refcount); M> } M> M> static inline int M> kref_put(struct kref *kref, void (*rel)(struct kref *kref)) M> { M> M> - if (refcount_release(&kref->refcount)) { M> + if (refcount_release((uint32_t *)&kref->refcount)) { M> rel(kref); M> return 1; M> } M> @@ -84,7 +84,7 @@ kref_put_lock(struct kref *kref, void (*rel)(struct kref *kref), M> spinlock_t *lock) M> { M> M> - if (refcount_release(&kref->refcount)) { M> + if (refcount_release((uint32_t *)&kref->refcount)) { M> spin_lock(lock); M> rel(kref); M> return (1); M> @@ -98,7 +98,7 @@ kref_sub(struct kref *kref, unsigned int count, M> { M> M> while (count--) { M> - if (refcount_release(&kref->refcount)) { M> + if (refcount_release((uint32_t *)&kref->refcount)) { M> rel(kref); M> return 1; M> } M> @@ -110,16 +110,16 @@ static inline int __must_check M> kref_get_unless_zero(struct kref *kref) M> { M> M> - return refcount_acquire_if_not_zero(&kref->refcount); M> + return refcount_acquire_if_not_zero((uint32_t *)&kref->refcount); M> } M> M> static inline int kref_put_mutex(struct kref *kref, M> void (*release)(struct kref *kref), struct mutex *lock) M> { M> WARN_ON(release == NULL); M> - if (unlikely(!refcount_release_if_not_last(&kref->refcount))) { M> + if (unlikely(!refcount_release_if_not_last((uint32_t *)&kref->refcount))) { M> mutex_lock(lock); M> - if (unlikely(!refcount_release(&kref->refcount))) { M> + if (unlikely(!refcount_release((uint32_t *)&kref->refcount))) { M> mutex_unlock(lock); M> return 0; M> } -- Gleb Smirnoff