[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+CK2bB5K5zUg+-PZ2xs+iRhQskGzNgt8+ELN501ni9SM98srQ@mail.gmail.com>
Date: Fri, 23 May 2025 14:09:34 -0400
From: Pasha Tatashin <pasha.tatashin@...een.com>
To: James Houghton <jthoughton@...gle.com>
Cc: pratyush@...nel.org, jasonmiu@...gle.com, graf@...zon.com,
changyuanl@...gle.com, rppt@...nel.org, dmatlack@...gle.com,
rientjes@...gle.com, corbet@....net, rdunlap@...radead.org,
ilpo.jarvinen@...ux.intel.com, kanie@...ux.alibaba.com, ojeda@...nel.org,
aliceryhl@...gle.com, masahiroy@...nel.org, akpm@...ux-foundation.org,
tj@...nel.org, yoann.congal@...le.fr, mmaurer@...gle.com,
roman.gushchin@...ux.dev, chenridong@...wei.com, axboe@...nel.dk,
mark.rutland@....com, jannh@...gle.com, vincent.guittot@...aro.org,
hannes@...xchg.org, dan.j.williams@...el.com, david@...hat.com,
joel.granados@...nel.org, rostedt@...dmis.org, anna.schumaker@...cle.com,
song@...nel.org, zhangguopeng@...inos.cn, linux@...ssschuh.net,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org, linux-mm@...ck.org,
gregkh@...uxfoundation.org, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
rafael@...nel.org, dakr@...nel.org, bartosz.golaszewski@...aro.org,
cw00.choi@...sung.com, myungjoo.ham@...sung.com, yesanishhere@...il.com,
Jonathan.Cameron@...wei.com, quic_zijuhu@...cinc.com,
aleksander.lobakin@...el.com, ira.weiny@...el.com,
andriy.shevchenko@...ux.intel.com, leon@...nel.org, lukas@...ner.de,
bhelgaas@...gle.com, wagi@...nel.org, djeffery@...hat.com,
stuart.w.hayes@...il.com, ptyadav@...zon.de
Subject: Re: [RFC v2 08/16] luo: luo_files: add infrastructure for FDs
On Thu, May 15, 2025 at 7:16 PM James Houghton <jthoughton@...gle.com> wrote:
>
> On Thu, May 15, 2025 at 11:23 AM Pasha Tatashin
> <pasha.tatashin@...een.com> wrote:
> > +/**
> > + * luo_retrieve_file - Find a registered file instance by its token.
> > + * @token: The unique token of the file instance to retrieve.
> > + * @file: Output parameter. On success (return value 0), this will point
> > + * to the retrieved "struct file".
> > + *
> > + * Searches the global list for a &struct luo_file matching the @token. Uses a
> > + * read lock, allowing concurrent retrievals.
> > + *
> > + * Return: 0 on success. Negative errno on failure.
> > + */
> > +int luo_retrieve_file(u64 token, struct file **file)
> > +{
> > + struct luo_file *luo_file;
> > + int ret = 0;
> > +
> > + luo_files_recreate_luo_files_xa_in();
> > + luo_state_read_enter();
> > + if (!liveupdate_state_updated()) {
> > + pr_warn("File can be retrieved only in updated state\n");
> > + luo_state_read_exit();
> > + return -EBUSY;
> > + }
> > +
> > + luo_file = xa_load(&luo_files_xa_in, token);
> > + if (luo_file && !luo_file->reclaimed) {
> > + luo_file->reclaimed = true;
>
> I haven't been able to pay too much attention to the series yet, and I
> know this was posted as an RFC, so pardon my nit-picking.
>
> I think you need to have xchg here for this not to be racy, so something like:
>
> `if (luo_file && !xchg(&luo_file->reclaimed, true))`
>
> Or maybe you meant to avoid this race some other way; IIUC,
> luo_state_read_enter() is not sufficient.
Thank you for catching this. This is a bug, I actually added a per fd
mutex lock to struct luo_file that is supposed to be used here. I am
going to address this in the next version.
Thanks,
Pasha
>
> Thanks!
>
> > + ret = luo_file->fs->retrieve(luo_file->fs->arg,
> > + luo_file->private_data,
> > + file);
> > + if (!ret)
> > + luo_file->file = *file;
> > + } else if (luo_file && luo_file->reclaimed) {
> > + pr_err("The file descriptor for token %lld has already been retrieved\n",
> > + token);
> > + ret = -EINVAL;
> > + } else {
> > + ret = -ENOENT;
> > + }
> > +
> > + luo_state_read_exit();
> > +
> > + return ret;
> > +}
Powered by blists - more mailing lists