From: Matthew Wilcox <willy@infradead.org>
To: Oded Gabbay <ogabbay@kernel.org>
Cc: "Michał Winiarski" <michal.winiarski@intel.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
intel-gfx@lists.freedesktop.org,
"David Airlie" <airlied@linux.ie>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Simon Ser" <contact@emersion.fr>
Subject: Re: [PATCH v5 1/3] drm: Use XArray instead of IDR for minors
Date: Mon, 7 Nov 2022 16:20:07 +0000 [thread overview]
Message-ID: <Y2kwN5TRsAKTZmsN@casper.infradead.org> (raw)
In-Reply-To: <CAFCwf12+piEABvv=nxFJCzUU4XdZw5Pu=r=i3aKQGZrBeraFqw@mail.gmail.com>
On Sun, Nov 06, 2022 at 04:51:39PM +0200, Oded Gabbay wrote:
> I tried executing the following code in a dummy driver I wrote:
You don't need to write a dummy driver; you can write test-cases
entirely in userspace. Just add them to lib/test_xarray.c and then
make -C tools/testing/radix-tree/
> static DEFINE_XARRAY_ALLOC(xa_dummy);
> void check_xa(void *pdev)
> {
> void *entry;
> int ret, index;
>
> ret = xa_alloc(&xa_dummy, &index, NULL, XA_LIMIT(0, 63), GFP_NOWAIT);
> if (ret < 0)
> return ret;
>
> entry = xa_cmpxchg(&xa_dummy, index, NULL, pdev, GFP_KERNEL);
> if (xa_is_err(entry))
> return;
>
> xa_lock(&xa_dummy);
> xa_dev = xa_load(&xa_dummy, index);
> xa_unlock(&xa_dummy);
> }
>
> And to my surprise xa_dev is always NULL, when it should be pdev.
> I believe that because we first allocate the entry with NULL, it is
> considered a "zero" entry in the XA.
> And when we replace it, this attribute doesn't change so when we do
> xa_load, the xa code thinks the entry is a "zero" entry and returns
> NULL.
There's no "attribute" to mark a zero entry. It's just a zero entry.
The problem is that you're cmpxchg'ing against NULL, and it's not NULL,
it's the ZERO entry. This is even documented in the test code:
/* cmpxchg sees a reserved entry as ZERO */
XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY,
xa_mk_value(12345678), GFP_NOWAIT) != NULL);
I'm not quite sure why you're using xa_cmpxchg() here anyway; if you
allocated it, it's yours and you can just xa_store() to it.
next prev parent reply other threads:[~2022-11-07 16:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-11 21:14 [PATCH v5 0/3] drm: Use full allocated minor range for DRM Michał Winiarski
2022-09-11 21:14 ` [PATCH v5 1/3] drm: Use XArray instead of IDR for minors Michał Winiarski
2022-10-25 13:56 ` Jeffrey Hugo
2022-11-02 14:23 ` Oded Gabbay
2022-11-06 14:51 ` Oded Gabbay
2022-11-07 16:20 ` Matthew Wilcox [this message]
2022-11-07 19:18 ` Oded Gabbay
2022-11-07 17:52 ` Michał Winiarski
2022-09-11 21:14 ` [PATCH v5 2/3] drm: Expand max DRM device number to full MINORBITS Michał Winiarski
2022-09-11 21:14 ` [PATCH v5 3/3] drm: Introduce skip_legacy_minors modparam Michał Winiarski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2kwN5TRsAKTZmsN@casper.infradead.org \
--to=willy@infradead.org \
--cc=airlied@linux.ie \
--cc=contact@emersion.fr \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=michal.winiarski@intel.com \
--cc=mripard@kernel.org \
--cc=ogabbay@kernel.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®