From nobody Wed Dec 14 22:25:23 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 4NXVLT70J6z4kk6c; Wed, 14 Dec 2022 22:25:37 +0000 (UTC) (envelope-from arichardson.kde@gmail.com) Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NXVLT005dz4J61; Wed, 14 Dec 2022 22:25:36 +0000 (UTC) (envelope-from arichardson.kde@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of arichardson.kde@gmail.com designates 209.85.166.173 as permitted sender) smtp.mailfrom=arichardson.kde@gmail.com; dmarc=none Received: by mail-il1-f173.google.com with SMTP id y2so7328770ily.5; Wed, 14 Dec 2022 14:25:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hwggWRoaTfV9gng3Q9aGlrAq2AtzgwNar+I26c/g6Nw=; b=Lmkgo7S/O8dM2/iTrOYZ1qD34G+D8Tm/jKv4xBOOioI8b0SH3RUG9ZYEUhrPGfKirR bt6ZnuL/S8g4kTcgDhFGMKeDBdEYslrOu9gpWxhpvtk09SThTdgybN3v91Ul/Odyacsr D3FAWnlja+q/c1Cy55z6zHQBLDPdh0+5bjvpaBaGg2UmAZN6Yx3KEjBU7VR5fxtnpdWy HIEcQtrbsBeR2tokYriYyGFwdL+aPQNriUdb/9OvWlXyrxfhg9BxL92WK19OHbVD3jIR /KPlRAGcQGzTOQ7yqRGIw2DHWorWbT0XgmvQ7g8jLVKwaVIjocZj0QUwkOlh2GV2enAD NtIA== X-Gm-Message-State: AFqh2koxNsVidvQvYOkeDaLyeNR8r8OLkP+QRAkv1HkRdFU0D0hX1AKY Xlh8PbDo2iu0U9jKFIFuaHWqDFtkZH7lnKio X-Google-Smtp-Source: AMrXdXsCorGMu4+1RIugE1jGetKfmXKOQhv/QcmMesYQ7Z8TeT46k8b+pK3GpUrF7uDPOogapDKIYQ== X-Received: by 2002:a05:6e02:f88:b0:305:e0e1:56c5 with SMTP id v8-20020a056e020f8800b00305e0e156c5mr2214957ilo.19.1671056735671; Wed, 14 Dec 2022 14:25:35 -0800 (PST) Received: from mail-il1-f175.google.com (mail-il1-f175.google.com. [209.85.166.175]) by smtp.gmail.com with ESMTPSA id h18-20020a02cd32000000b00389de6759b8sm2089294jaq.162.2022.12.14.14.25.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Dec 2022 14:25:35 -0800 (PST) Received: by mail-il1-f175.google.com with SMTP id z18so7322380ils.3; Wed, 14 Dec 2022 14:25:35 -0800 (PST) X-Received: by 2002:a05:6e02:58c:b0:303:a45:573a with SMTP id c12-20020a056e02058c00b003030a45573amr26980627ils.1.1671056734844; Wed, 14 Dec 2022 14:25:34 -0800 (PST) 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 References: <202212132047.2BDKl92M065327@gitrepo.freebsd.org> In-Reply-To: <202212132047.2BDKl92M065327@gitrepo.freebsd.org> From: Alexander Richardson Date: Wed, 14 Dec 2022 22:25:23 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: git: e6bc24b0385a - main - kref: switch internal type to atomic_t and bring back const to kref_read To: Mateusz Guzik Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Spamd-Result: default: False [-2.97 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.97)[-0.971]; FORGED_SENDER(0.30)[arichardson@freebsd.org,arichardsonkde@gmail.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; RCVD_IN_DNSWL_NONE(0.00)[209.85.166.173:from,209.85.166.175:received]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; MIME_TRACE(0.00)[0:+]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.166.173:from]; FREEMAIL_ENVFROM(0.00)[gmail.com]; R_DKIM_NA(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; FROM_NEQ_ENVFROM(0.00)[arichardson@freebsd.org,arichardsonkde@gmail.com]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_THREE(0.00)[4]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_LAST(0.00)[]; TAGGED_FROM(0.00)[] X-Rspamd-Queue-Id: 4NXVLT005dz4J61 X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N On Tue, 13 Dec 2022 at 20:47, Mateusz Guzik wrote: > > The branch main has been updated by mjg: > > URL: https://cgit.FreeBSD.org/src/commit/?id=e6bc24b0385a166526d20b2eb0cbb6a116350075 > > commit e6bc24b0385a166526d20b2eb0cbb6a116350075 > Author: Mateusz Guzik > AuthorDate: 2022-12-13 20:42:32 +0000 > Commit: Mateusz Guzik > CommitDate: 2022-12-13 20:46:58 +0000 > > kref: switch internal type to atomic_t and bring back const to kref_read > > This unbreak drm-kmod build. > > the const is part of Linux API > > Unfortunately drm-kmod uses hand-rolled refcount* calls on a kref > object. For now go the easy route of keeping it operational by casting > stuff internally. > > The general goal here is to make FreeBSD refcount API use an opaque > type, hence the ongoing removal of hand-rolled accesses. > > Reported by: emaste > --- > sys/compat/linuxkpi/common/include/linux/kref.h | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h > index 9a6814175223..5a1fd834a58d 100644 > --- a/sys/compat/linuxkpi/common/include/linux/kref.h > +++ b/sys/compat/linuxkpi/common/include/linux/kref.h > @@ -44,35 +44,35 @@ > > struct kref { > /* XXX In Linux this is a refcount_t */ > - volatile u_int32_t refcount; > + atomic_t refcount; > }; > > static inline void > kref_init(struct kref *kref) > { > > - refcount_init(&kref->refcount, 1); > + refcount_init((uint32_t *)&kref->refcount, 1); > } > > static inline unsigned int > -kref_read(struct kref *kref) > +kref_read(const struct kref *kref) > { > > - return (refcount_load(&kref->refcount)); > + return (refcount_load(__DECONST(u_int32_t *, &kref->refcount))); This is rather ugly IMO, can't we change refcount_load() to take a const pointer? It looks like the problem might be __atomic_load_int_relaxed(), but that could use const as well? > } > > static inline void > kref_get(struct kref *kref) > { > > - refcount_acquire(&kref->refcount); > + refcount_acquire((uint32_t *)&kref->refcount); > } > > static inline int > kref_put(struct kref *kref, void (*rel)(struct kref *kref)) > { > > - if (refcount_release(&kref->refcount)) { > + if (refcount_release((uint32_t *)&kref->refcount)) { > rel(kref); > return 1; > } > @@ -84,7 +84,7 @@ kref_put_lock(struct kref *kref, void (*rel)(struct kref *kref), > spinlock_t *lock) > { > > - if (refcount_release(&kref->refcount)) { > + if (refcount_release((uint32_t *)&kref->refcount)) { > spin_lock(lock); > rel(kref); > return (1); > @@ -98,7 +98,7 @@ kref_sub(struct kref *kref, unsigned int count, > { > > while (count--) { > - if (refcount_release(&kref->refcount)) { > + if (refcount_release((uint32_t *)&kref->refcount)) { > rel(kref); > return 1; > } > @@ -110,16 +110,16 @@ static inline int __must_check > kref_get_unless_zero(struct kref *kref) > { > > - return refcount_acquire_if_not_zero(&kref->refcount); > + return refcount_acquire_if_not_zero((uint32_t *)&kref->refcount); > } > > static inline int kref_put_mutex(struct kref *kref, > void (*release)(struct kref *kref), struct mutex *lock) > { > WARN_ON(release == NULL); > - if (unlikely(!refcount_release_if_not_last(&kref->refcount))) { > + if (unlikely(!refcount_release_if_not_last((uint32_t *)&kref->refcount))) { > mutex_lock(lock); > - if (unlikely(!refcount_release(&kref->refcount))) { > + if (unlikely(!refcount_release((uint32_t *)&kref->refcount))) { > mutex_unlock(lock); > return 0; > }