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

Re: [PATCH] domain: add barrier in vcpu_create()


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 26 Nov 2025 11:09:47 +0000
  • 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=aRnrKSlf1pDoETxfuuM9KyGVSvKeS01dXGHvW0X8Tbg=; b=rN052pVqHddHXduZEHyC5m1lduF31uotTFl4Tow8L0iD/5V/SKG0hhg+p0DWD6IQ3df7alxnUs5lP3os0pd7mwJjLkAKyWc28/GU/n2v6yxvpdbmrNGKnykqZZvh8tfPNvxWjpMEF5r7PEE2p4ZWWVsGB5vTKxavWQ/aojd3+oNKJfpJpYZeOf9AjLz/uj1KXPYwxm6PsO49bx/gIzLaKB2ra5xQJBplP1nzsUkontESL8NUMIDt8lkUi4wDe8fApmEQmz263CufzDvt3YqxAXt1Oo4zFHIsH7dN10CYGcd8DqNMQIP5QN2AfTkgiJ8eFKzxtId+Ddp+znJW8qeGwg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uslhlsluc4DT54IxEJSKMcU38WHey9FRyZ/R+k+jFegUoW9gmBP0lcup8GWEIh7W0SsXnqrlLswcobfmEjBRtWt33LzVXSAgVuR/SUqTuc96E5Dhyp742hLHwngu5wxHOkOwjXIevek2CSiyPZ1fy617iWH73vMcXLQgkrSfVssU7yPCR4SjlX1Arky41dmW/On9tRJGDUIqk5e2yrT8Z7hM7BZNgRRyZejT/7sRAltepTBzgMQJd3aq4uMO3KImo8oS6bRBoMtGsYEPzURhaygCtlQArz4DYtH01sjiQ/5TEaz+lYjxhICURg3MhwAx38qf6CzEYoVPwlZe/nl40w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Wed, 26 Nov 2025 11:10:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 26/11/2025 10:13 am, Jan Beulich wrote:
> The lock-less list updating isn't safe against racing for_each_vcpu(),
> unless done (by hardware) in exactly the order written.
>
> Fixes: 3037c5a2cb82 ("arm: domain")
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> The Fixes: tag is pretty arbitrary; the issue was becoming non-latent when
> Arm support was added. (Strictly speaking IA-64 and PPC would have been
> affected too afaict, just that now that doesn't matter anymore [or, for
> PPC, not yet, seeing that its support is being re-built from scratch].)
>
> I'm not quite happy about prev_id being plain int, but changing it to
> unsigned (with suitable other adjustments) actually makes gcc15 generate
> worse code on x86.
>
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -464,6 +464,7 @@ struct vcpu *vcpu_create(struct domain *
>              prev_id--;
>          BUG_ON(prev_id < 0);
>          v->next_in_list = d->vcpu[prev_id]->next_in_list;
> +        smp_wmb();
>          d->vcpu[prev_id]->next_in_list = v;
>      }
>  

Where's the matching smp_rmb()?  There needs to be one for this
smp_wmb() to be correct.

It's rather rhetorical, because clearly the smp_rmb() needs to be in
for_each_vcpu() given your commit message, but we obviously don't want
to do that.

This list can only be changed once during a VM's lifecycle, and even
then it only gets appended to.  i.e. this particular piece of logic to
splice a vCPU into the middle of a single linked list can be simplified
to the second assignment, as the first is always copying NULL.

~Andrew



 


Rackspace

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