From nobody Wed Dec 14 08:53:04 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 4NX8Jy4sk2z4k5QK; Wed, 14 Dec 2022 08:53:06 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) (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 4NX8Jy0t6kz3vpb; Wed, 14 Dec 2022 08:53:06 +0000 (UTC) (envelope-from mjguzik@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1442977d77dso15804856fac.6; Wed, 14 Dec 2022 00:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Zi+WEmh+pIMJ5Xdo+uXxvq84aRs7lsBzp3QJZ6Lzx14=; b=F7DIYGeNHCh6vVNvG6fkEu6w0vGlCJDYKriYba9tSoQs/eOvcPTNP1790orzBG1+db XCzsjQgwyabFvYh1d+YbuNwQ+UjtdXmz6pSEwCN8PNY1x0alJUQO1m3r+bIqAuSNcFmR 9i2pQRif+oChtrsv4+ncGb5hzTt9JWzqtMaUexqFSZOUrzuwdcR34OPGMUHOhxfBbSAa yL+c1bci94i1JXFH/v9eMqComJ+08bZ/jrEKb6UazoNyRnZoolC9jj5VSzVhJ1EcofLx IIT0J8yUV9bwndSCz/8bkfPcNyAg17vhFph6v2wpfpG0bymd6SEUnOOhyvgWvsLlQK4J udeQ== 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:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zi+WEmh+pIMJ5Xdo+uXxvq84aRs7lsBzp3QJZ6Lzx14=; b=LEJ+CbiMAFFT5hdpaRSy7T6DdNTRbJaT6GNWBt1dT41qx2+BdcJdLprfVXP3YAMfcs TD8PHTYwNKRJbvZY5CjUjP7Xh7VMsumV8QH1NDSoqaBlBUckgqv/CmA9LjWW3+u0YByn r2Bvopv8Zs7pO4zH8orUp5HY/ObHdBIIwcCpYgzKzP1Ap97lpbxodRpW9cGtTKx1Ie6k A8vU4iU4Lq1RYxe7flfEsxHstAgEXle8L00dZruD2D/4TlBpDIKgRxREExP3i8vQ0bHK CMp7J8KsrmLXed31hNDy7PN1D3qfHvwTzfosTa6yNcxz4eZFVvtbBblrQVZhw336QX/1 X5gw== X-Gm-Message-State: AFqh2krPjpFN/LZe4/desfRWvd0nZm82/1yrUMTYD2ekwJEQ7N/XfaCk 9x+Na9j9cRkQLZPF5XPIefC8sKC1J6/P6SEjkb2tavv9 X-Google-Smtp-Source: AMrXdXsT0agCnACoEkl8P1TSfmR79GNr1Jd2E8xgio+j/d5ZwE0f+Rdi9wxaVbCLMNAI4Yjc2tvse8lCt7LG8GeCqrY= X-Received: by 2002:a05:6870:4687:b0:143:8a81:116c with SMTP id a7-20020a056870468700b001438a81116cmr184618oap.96.1671007985352; Wed, 14 Dec 2022 00:53:05 -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 Received: by 2002:a8a:dd0:0:b0:48f:2c93:a3ef with HTTP; Wed, 14 Dec 2022 00:53:04 -0800 (PST) In-Reply-To: References: <202212132047.2BDKl92M065327@gitrepo.freebsd.org> From: Mateusz Guzik Date: Wed, 14 Dec 2022 09:53:04 +0100 Message-ID: Subject: Re: git: e6bc24b0385a - main - kref: switch internal type to atomic_t and bring back const to kref_read To: Gleb Smirnoff 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-Rspamd-Queue-Id: 4NX8Jy0t6kz3vpb X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2001:4860:4864::/48, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 12/14/22, Gleb Smirnoff wrote: > One u_int32_t sneaked in between multiple uint32_t in this change. > Does not matter, it all is going to be replaced with refcount_t soon(tm) -- there are numerous other violations all over the codebase before I can do it though. > 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 > -- Mateusz Guzik