[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH] x86/p2m-pt: do type recalculations with p2m read lock


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Mon, 3 Apr 2023 16:27:46 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IAfwAS67uPv82PW8HQEBVpAbw93Rh6M0Lh2mOQ5+z9k=; b=bXsUw9zjHuDG2HSDd8wCzEAeZeGUHYpq++tz0tYcvFmd++auWVhyKJNtLLifl6AV88jXskCdMUJ5uRM3C6k3pHXgJvzNbqQ4ToOjS88AGocnSjSmg0Cp1o0Q/5g1dyOHlBZ+EJGI83udAIqG8bWhAiQKJMKW1k0OzjKgOe3+E6L7b+CgNTPdKO7+g2Vts//2fxM14WnPkHXdD8mEka73rB2bCkglAyo9TshovP05NXZNS7YsJ8iSH2QHKZErmGttVY+cMsCMC6llBFMUZsafL9/q1dVsvAYm6t2TxCygD2sURiWtogY+dMqCDuandO6aFo7F48wVi6UGATuCI2puGQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YWu362jbBNliunOyuAp3h3gdwvNH/X19HuMKSGO0atc0oGVimOcA8ph/O1pm7mDP8ml+jmJsgydSIgBOmaxEAPE1/d7K3+0V1CQlZufiTTGfLlL4RmAgCYXQQppeWtBAiEZGPOsO2Yygfz2IDSnyzE7/cYVJHYbU5CczvZD0i//V/uV6W4Chy95/UPUwurd5KP7JsaFyj6/RRcGNAIUycsCe05rXmOJxF1MECwNhx3Cd3wTjXSx0bdxDGL5fvBUjN/zNfr8RdUEuB7tzmp8i1NJ+WlNeeol2qT/EHeywuohzaaECIRT3SxafSTw/WLQiGkRzoB8RjATP43T4jnXPhA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 03 Apr 2023 14:28:21 +0000
  • Ironport-data: A9a23:W0OpQ6liXCLCJColnsL7jnro5gynJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xJKWG6HaKuNYDCkfNp+b9m39BtXvMPRyNRqHlFu+yoyFCMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aSaVA8w5ARkPqgX5ASGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 eM+eWtONA2pu8C/yraBd/g3tJotJvC+aevzulk4pd3YJdAPZMmbBonvu5pf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVw3ieC3WDbWUoXiqcF9hEGXq 3iA523kKhobKMae2XyO9XfEaurnxHugBdpLS+bhnhJsqACJ/2AwBjZJb2GyhPWhukesae1xA kNBr0LCqoB3riRHVOLVXRe1vXqFtR40QMdLHqsx7wTl4rXQyxaUAC4DVDEpQMwrsoo6SCIn0 neNnsj1Hnp/vbuNU3Wf+7yI6zSoNkAowXQqYCYFSU4J5oflqYRq1hbXFI87Suiyk8H/Hiz2z 3aSti8iir4PjMkNkaKm4VTAhDHqrZ/MJuIo2jjqsquexlsRTOaYi0aAsDA3Md4owF6lc2S8
  • Ironport-hdrordr: A9a23:Wgm9aqBUpm9+gGflHemV55DYdb4zR+YMi2TDtnoBMCC9F/bzqy nApoV/6faZskdyZJhko6HiBEDiexLhHPxOkO0s1N6ZNWGMhILrFuFfBODZslrd8kPFh4hgPG RbH5SWyuecMbG3t6nHCcCDfeod/A==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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()?

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?

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.