linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Han Xing Yi <hxingyi104@gmail.com>
Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] Xarray: Fix race in xa_get_order()
Date: Sun, 3 Mar 2024 12:11:05 +0000	[thread overview]
Message-ID: <ZeRo2Y_RKEZ2op4i@casper.infradead.org> (raw)
In-Reply-To: <ZeM0CBHF3mfz847s@desktop-cluster-2.tailce565.ts.net>

On Sat, Mar 02, 2024 at 10:13:28PM +0800, Han Xing Yi wrote:
> Hello! This is my first patch ever, so please bear with me if I make some rookie
> mistakes. I've tried my best to follow the documentation :) 

Thanks!  This is indeed a mistake.  Probably a harmless one, but worth
fixing to silence the warning.

Annoyingly, building with C=1 (sparse) finds the problem:

  CHECK   ../lib/xarray.c
../lib/xarray.c:1779:54: warning: incorrect type in argument 1 (different address spaces)
../lib/xarray.c:1779:54:    expected void const *entry
../lib/xarray.c:1779:54:    got void [noderef] __rcu *

so that means I got out of the habit of running sparse, and for some
reason none of the build bots notified me of the new warning (or I
missed that email).

> +++ b/lib/xarray.c
> @@ -1776,7 +1776,7 @@ int xa_get_order(struct xarray *xa, unsigned long index)
>  
>  		if (slot >= XA_CHUNK_SIZE)
>  			break;
> -		if (!xa_is_sibling(xas.xa_node->slots[slot]))
> +		if (!xa_is_sibling(rcu_dereference(xas.xa_node->slots[slot])))

This is such a common thing to do that I have a helper for it.
So what I'll actually commit is:

-               if (!xa_is_sibling(xas.xa_node->slots[slot]))
+               if (!xa_is_sibling(xa_entry(xas.xa, xas.xa_node, slot)))

but I'll leave your name on it since you did the actual work.

  reply	other threads:[~2024-03-03 12:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 14:13 [PATCH] Xarray: Fix race in xa_get_order() Han Xing Yi
2024-03-03 12:11 ` Matthew Wilcox [this message]
2024-03-03 14:40   ` Han Xing Yi

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=ZeRo2Y_RKEZ2op4i@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=hxingyi104@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).