From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>, Wei Liu <wl@xen.org>,
xen-devel@lists.xenproject.org
Subject: Re: [RFC PATCH] x86/p2m-pt: do type recalculations with p2m read lock
Date: Mon, 3 Apr 2023 17:42:42 +0200 [thread overview]
Message-ID: <ZCrz8kDM6EB8t0Le@Air-de-Roger> (raw)
In-Reply-To: <5fc00c1a-11ea-905e-49eb-d70caaf71041@suse.com>
On Mon, Apr 03, 2023 at 05:30:37PM +0200, Jan Beulich wrote:
> On 03.04.2023 16:27, Roger Pau Monné wrote:
> > On Mon, Apr 03, 2023 at 02:39:08PM +0200, Jan Beulich wrote:
> >> On 03.04.2023 12:14, Roger Pau Monne wrote:
> >>> --- a/xen/arch/x86/mm/p2m-pt.c
> >>> +++ b/xen/arch/x86/mm/p2m-pt.c
> >>> @@ -486,9 +486,6 @@ static int cf_check do_recalc(struct p2m_domain *p2m, unsigned long gfn)
> >>> p2m_type_t ot, nt;
> >>> unsigned long mask = ~0UL << (level * PAGETABLE_ORDER);
> >>>
> >>> - if ( !valid_recalc(l1, e) )
> >>> - P2M_DEBUG("bogus recalc leaf at d%d:%lx:%u\n",
> >>> - p2m->domain->domain_id, gfn, level);
> >>> ot = p2m_flags_to_type(l1e_get_flags(e));
> >>> nt = p2m_recalc_type_range(true, ot, p2m, gfn & mask, gfn | ~mask);
> >>> if ( nt != ot )
> >>
> >> I'm afraid I neither understand why you make this change, nor why you
> >> then leave the other use of valid_recalc() in place.
> >
> > The message can be bogus if we allow concurrent do_recalc(), and I
> > did miss the previous one.
> >
> > I missed the one at the top. Originally I wanted to send the RFC with
> > just changing the lock to read mode, but then I though I might as
> > well fix that (now bogus) print message.
> >
> >>> @@ -538,9 +535,9 @@ int p2m_pt_handle_deferred_changes(uint64_t gpa)
> >>> */
> >>> ASSERT(!altp2m_active(current->domain));
> >>>
> >>> - p2m_lock(p2m);
> >>> + p2m_read_lock(p2m);
> >>> rc = do_recalc(p2m, PFN_DOWN(gpa));
> >>> - p2m_unlock(p2m);
> >>> + p2m_read_unlock(p2m);
> >>>
> >>> return rc;
> >>> }
> >>
> >> How can this be safe, when do_recalc() involves p2m_next_level(), which
> >> may install new (intermediate) page tables?
> >
> > Oh, great, didn't realize it was capable of doing so, it's more hidden
> > than in the EPT case. Seems like this will only happen if a superpage
> > needs to be split because a lower order frame is being used as an
> > ioreq server page.
> >
> > Do you think it would be safe to try to attempt to perform the recalc
> > with the read lock only and fallback to the write lock if there's a
> > need to call p2m_next_level()?
>
> Yes, that ought to be okay.
>
> > Do you agree it might be possible to do the recalc with just the read
> > lock if it's updating of PTE type / recalc flags only?
>
> Technically this looks to be possible, yes. Question is whether we do
> ourselves much good by introducing such a special case of permitting
> a certain kind of writes with the lock only held in read mode. The
> latest when we find a second (more or less similar) use case thing
> are likely to become difficult.
Yes, it's not very nice. I'm open to suggestions of other ways to
remove some of the contention. If we go down this route it would need
to be clearly documented.
Thanks, Roger.
next prev parent reply other threads:[~2023-04-03 15:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 10:14 [RFC PATCH] x86/p2m-pt: do type recalculations with p2m read lock Roger Pau Monne
2023-04-03 12:39 ` Jan Beulich
2023-04-03 14:27 ` Roger Pau Monné
2023-04-03 15:30 ` Jan Beulich
2023-04-03 15:42 ` Roger Pau Monné [this message]
2023-04-03 15:32 ` Jan Beulich
2023-04-03 15:38 ` Roger Pau Monné
2023-04-03 16:07 ` Jan Beulich
2023-04-04 9:49 ` Roger Pau Monné
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=ZCrz8kDM6EB8t0Le@Air-de-Roger \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.