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

Re: [PATCH] x86/shadow: don't use #if in macro invocations


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 20 Feb 2026 15:29:11 +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=s/Uh+wyylVdjbeX+zh6EIwRBAwtdJNEqW8o/Kesz8cM=; b=lEbvj1HD22eGxShqvWNIpG4SSu8J+E4f0Y4oDG47DOoLfba9qUVJgiEu1XlNlg6/HiV7zmX58T7ubye54XM5meTKMrp2X4sUJYjDaMoJ+cJeOq7jRWQFptNQA8bL68xEBEtMXrqFZN6VvaxbPKR7Nw8SOqIAAbnGbxv8cvt8BYOeFItl+hp6D878ka7iYaETiXoFKc/tWAxR6B6Le1zJsqhT5RoS6pgWbM0OL5ZKTWyMrscnfP6bBXml5yn8ZQS55fVRYRq0fKG2Y+NoIwure9ThKw4jNTdYqqMFCB1kGjVRS0Cqr/FO3eoulwFUnS6iPWShurkBmMAA3tWBFZY1KQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j5YjB4l4+RIBPd0dUjh178dQe0WQuNxr+YUijdKbwTOEIwZLdzZIbo4sXVJ2T48dqO5UKarbu5xGukH9uVBzl/5YeUmZjXvQPv4j2SJsND0F2el6J1ZnhPulv2ygsj2jCSDfN40N+JQKr6uq6UaH4n05wXzS5eShq44x5Q4hKouUHo2bSP4MsfcN61VKNBO9qtMUXsKiIxoyd68XiSMXJxrkGg0sYhfoKuRze0yvIb0pzP6ECLZ/FdNPHdJga/FWeOsd9h689dIAhqGhBsfpszmY8LNgbIm/ko/FdEjZvKJ1kopwwC/lZtPjn7HvNwcM5Jbj++7F0TFr5fcICNpUKA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 20 Feb 2026 15:29:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 18/02/2026 9:03 am, Jan Beulich wrote:
> As per the standard this is UB, i.e. we're building on a defacto extension
> in the compilers we use. Misra C:2012 rule 20.6 disallows this altogether,
> though. Use helper always-inline functions instead.
>
> In sh_audit_l1_table(), along with reducing the scope of "gfn", which now
> isn't used anymore by the if() side of the conditional, also reduce the
> scope of two other adjacent variables.
>
> For audit_magic() note that both which parameters are needed and what
> their types are is attributed to AUDIT_FAIL() accessing variables which
> aren't passed as arguments to it.
>
> No functional change intended. Of course codegen does change with this,
> first and foremost in register allocation.
>
> Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

I included this patch on an interim branch of other MISRA fixes of mine
to get a run.

https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/13198988953

There's one more violation still to fix:

    if ( unlikely((level == 1)
                  && sh_mfn_is_a_page_table(target_mfn)
#if (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC )
                  /* Unless the page is out of sync and the guest is
                     writing to it. */
                  && !(mfn_oos_may_write(target_mfn)
                       && (ft == ft_demand_write))
#endif /* OOS */
                  ) )
        sflags &= ~_PAGE_RW;



I also looked at this one previously.  Making mfn_oos_may_write()
visible outside of SHOPT_OUT_OF_SYNC is quite invasive.

Here, I suggest dropping the unlikely() as the easiest fix.  It's almost
certainly useless anyway.

~Andrew



 


Rackspace

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