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

Re: [PATCH] x86/altp2m: pause the vCPU before taking the altp2m list lock


  • To: lluisbessasanz <lluisbessasanz@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 26 Oct 2026 12:45:17 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:From:Cc:Content-Language:References:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: evilbootloader@xxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
  • Delivery-date: Mon, 26 Oct 2026 11:45:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.10.2026 09:28, lluisbessasanz wrote:
> From: Lluís Bessa <evilbootloader@xxxxxxxxx>
> 
> p2m_switch_vcpu_altp2m_by_id() takes the altp2m list lock and then
> updates the vCPU's EPTP. For a vCPU other than current,
> vmx_vcpu_update_eptp() -> vmx_vmcs_enter() pauses it and waits in
> vcpu_sleep_sync() until it is off its pCPU, with the lock still held.
> 
> A vCPU on its way off its pCPU may need the p2m lock: context_switch()
> updates its runstate area, which for an area registered by guest virtual
> address (VCPUOP_register_runstate_memory_area, as Linux does) is a copy
> to guest memory and needs a p2m lookup. A vCPU handling a log-dirty
> write fault holds the host p2m lock in p2m_change_type_one() and waits
> for the altp2m list lock in p2m_altp2m_propagate_change(). That closes
> a cycle:
> 
>   dom0 vCPU, vm_event_resume() -> p2m_altp2m_check():
>     holds the altp2m list lock, waits for vCPU X to be descheduled
>   vCPU X, context_switch() -> update_runstate_area():
>     waits for the host p2m lock
>   vCPU Y, hvm_hap_nested_page_fault() -> p2m_change_type_one():
>     holds the host p2m lock, waits for the altp2m list lock
> 
> A vm_event consumer switching views in its responses
> (VM_EVENT_FLAG_ALTERNATE_P2M) hits it with a Linux HVM guest while QEMU
> tracks dirty VRAM for a VNC client. The dom0 vCPUs involved spin in Xen
> and stop handling interrupts, and dom0 hangs.
> 
> Pause the vCPU before taking the lock, like
> p2m_switch_domain_altp2m_by_id() does with domain_pause_except_self().
> The pause in vmx_vmcs_enter() then finds the vCPU already descheduled.
> Only vm_event_resume() switches another vCPU's view, the other callers
> switch current and are unaffected.
> 
> Signed-off-by: Lluís Bessa <evilbootloader@xxxxxxxxx>
> Co-Authored-By: Claude Opus 5.5 <noreply@xxxxxxxxxxxxx>

The code change itself looks good to me, but as to the tags: The latter
one wants to be Assisted-by: and move ahead of your S-o-b (tags want to
be chronologically ordered). And then there's the issue of sender and
(last) S-o-b not agreeing. Yes, the "real" names are pretty similar, yet
even if they were identical that still wouldn't mean it's one and the
same person. Is there a reason you can't use an S-o-b matching the email
address you send from?

You also would have wanted to Cc maintainers plus perhaps Tamas. Added
now, and hence retaining full patch contents below.

Jan

> --- a/xen/arch/x86/mm/altp2m.c
> +++ b/xen/arch/x86/mm/altp2m.c
> @@ -220,6 +220,17 @@ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, 
> unsigned int idx)
>      if ( idx >= d->nr_altp2m )
>          return rc;
>  
> +    /*
> +     * Updating another vCPU's EPTP (vmx_vmcs_enter()) waits until that vCPU
> +     * is off its pCPU. Wait for it before taking the altp2m list lock: the
> +     * vCPU may need the p2m lock to get off its pCPU (to update its runstate
> +     * area in guest memory), while a vCPU handling a log-dirty fault holds 
> the
> +     * p2m lock and waits for the altp2m list lock in
> +     * p2m_altp2m_propagate_change().
> +     */
> +    if ( v != current )
> +        vcpu_pause(v);
> +
>      altp2m_list_lock(d);
>  
>      if ( d->arch.altp2m_eptp[idx] != mfn_x(INVALID_MFN) )
> @@ -230,6 +241,10 @@ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, 
> unsigned int idx)
>      }
>  
>      altp2m_list_unlock(d);
> +
> +    if ( v != current )
> +        vcpu_unpause(v);
> +
>      return rc;
>  }
>  




 


Rackspace

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