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

Re: [PATCH v2] x86/hap: Defer NPT P2M TLB flushes


  • To: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Thu, 19 Mar 2026 15:06:03 +0100
  • 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=arcselector10001; 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=3rGKl0+Sfh9bPj0Veprpia7WYOYAqSDoin6XvLcuVN0=; b=Y+Tj9ZutI+cxSeRjelNvHiEgCSrR2pJLSdSL+v7ZeMGRXsRZ2eZYiXD/ag+77wN77/uCYoCne3g5Tfmqq1sHilAcMOw+ch2YUailERY1IUlvWLyMFOZgDwihS1PQMnJW8AgRPmQcLvsbf7D6VSaTUBfJR8Enm88oKsP5JSJxIS7gX+LNLCROZ0/L7+GbRQA1r1VDi7CiUPncN8qfObaai62xjjVaL+drISOH+JDBVgQ6hyWJCrBxXKOYlvFeXd03IjQBSsB9wRyLAz2jKkAJfhngwb5P+3ClnbSaV6hYorie/1Quw450GepB1+xSO631CekiZBZM3NvK0ij7uBuoKg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S71+cuuewWiUtWepsN0nouiGNiNiFFcie/41StyvWnJiy6HZfvXVErjZHRVQeq7a0nadVOjZnuXLpWpH3oHHtvX3Lm57bTfSSzX4Y5y36FkBpTAMceXDyrmG/v5XRatY4oFZlfTiHjXbg9KYCOK1TySca6KT0kBK0IJNLEvflk6jD8cshfTawQtdywCxphCYX6T3yc4ZReY0L0sTBPy2eb2F1zCF/XOpGk6nY4Md7P2N0bLhHO6NJ08HFy+CumlDEe66AcAEqpwf5Jy7hzjycbJd7mYbB1LPPswR9Ga0XmCG3u/p8n/Qnn25gOjoQKRzGDxfDw8mpStTAqXa6zBc9Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 19 Mar 2026 14:06:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Mar 19, 2026 at 11:40:41AM +0000, Ross Lagerwall wrote:
> Like the EPT code, defer TLB flushes for NPT to reduce the number of
> flushes and avoid holding the P2M lock while flushing. This can
> substantially improve performance in some scenarios.
> 
> The cases where the TLB needs to be flushed without deferring are
> already handled by the call to p2m_tlb_flush_sync() in p2m_free_ptp().
> 
> Suggested-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
> ---
> In v2:
> * Tweak commit message.
> * Call guest_flush_tlb_mask() if the assertion fails.
> 
>  xen/arch/x86/mm/hap/hap.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
> index a337752bf488..67137611d9db 100644
> --- a/xen/arch/x86/mm/hap/hap.c
> +++ b/xen/arch/x86/mm/hap/hap.c
> @@ -814,15 +814,33 @@ static void cf_check hap_update_paging_modes(struct 
> vcpu *v)
>  static void cf_check
>  hap_write_p2m_entry_post(struct p2m_domain *p2m, unsigned int oflags)
>  {
> -    struct domain *d = p2m->domain;
> +    if ( !(oflags & _PAGE_PRESENT) )
> +        return;
> +
> +    if ( unlikely(!p2m->defer_flush) )
> +    {
> +        struct domain *d = p2m->domain;

As you are moving this around, and seeing that guest_flush_tlb_mask()
takes a const domain parameter, I think you could make this local
variable const.  Possibly the same below with the other d local
variable.

With that:

Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thanks, Roger.



 


Rackspace

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