On 08.02.22 10:57, Jan Beulich wrote: > On 08.02.2022 08:35, Oleksandr Andrushchenko wrote: >> 1.1. Semi read lock upgrade in modify bars >> -------------------------------------------------------------- >> In this case both vpci_read and vpci_write take a read lock and when it comes >> to modify_bars: >> >> 1. read_unlock(d->vpci_lock) >> 2. write_lock(d->vpci_lock) >> 3. Check that pdev->vpci is still available and is the same object: >> if (pdev->vpci && (pdev->vpci == old_vpci) ) >> { >> /* vpci structure is valid and can be used. */ >> } >> else >> { >> /* vpci has gone, return an error. */ >> } >> >> Pros: >> - no per-device vpci lock is needed? >> - solves overlap code ABBA in modify_bars >> - readers and writers are NOT serialized >> - NO need to carefully select read paths, so they are guaranteed not to lead >> to lock upgrade use-cases >> >> Cons: >> - ??? > The "pdev->vpci == old_vpci" is fragile: The struct may have got re- > allocated, and it just so happened that the two pointers are identical. > > Same then for the subsequent variant 2. Yes, it is possible. We can add an ID number to pdev->vpci, so each new allocated vpci structure has a unique ID which can be used to compare vpci structures. It can be something like pdev->vpci->id = d->vpci_id++; with id being uint32_t for example > > Jan > >
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Roger Pau Monné
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Roger Pau Monné
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Roger Pau Monné
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Oleksandr Andrushchenko
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Roger Pau Monné
- Re: [PATCH v6 03/13] vpci: move lock outside of st... Jan Beulich