[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: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 3 Apr 2023 17:30:37 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=B67imkZ+mLCqggN+D+FxYzH+CtFN8swOWJXmBPyZXY4=; b=iWFL42km80Gcki3XEjk4p89LcvTQoi0p5tS8GBbrOLU97lmFOxjBLIUN9R6Ab+tOMK8wjLXhIpq9Vs1gh0EThO11LfnYQAXnsweEqib1jirosvRsky5WmSnBHmDfXOw+f501n+eGV1G943+D7cbr9sx1nOo880AqeMWqIC6Lvq8LbtJMwo2habZ1PSb68djIqozRW3hlxhf35JoMZ2rbbb/F1P9RRmGWhI+YnATmIN08QqCClvFGOYx+5XpvhglMsCOawfSb3Gfb4PActUJn3l0ApAj14h/an6jrifwyaP6IAAfar8PBr+JpYbgSP+obBk2p0Qh4vRp+vhkx/k0cZg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HhGGfpap+l/uzAzkgDekyM8UEe4jxBRuMVoSlTvL71XzqzRpfVBdwCWx9tNc7qpCecxqD87EXzv+vChtJMS42AQo9ZviLy6p4jCkP+DcVRWX0/bG3fO5291dEckEaSITWHSBxq+8r7e9B9fe4Oy2zMSe2zWDSuzQ4tWXJeOJmt7iDlYyZCZr9skDIC+mV7bzU2bdWYdavDI9m6rTrwQT3dz/UAsLALptCW4vck014hBoYm9YLWl/LMWgLeFn/LtqGoRVfkJn7UHAn7UPbR+f3OshC2ZjDuYfegnAMP6DYU3rtV2sqHsDJ7LF13vuLny5wbFiBUN/mXYuKPyrWoLrEA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.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 15:30:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Jan



 


Rackspace

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