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

Re: [PATCH v3 2/2] x86/flushtlb: remove flush_area check on system state


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 25 May 2022 10:41:51 +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=QDjnvdxJLioNfy/x/qT7aOKTN9KZ8mSz1GaRpPQ9z0o=; b=nR4crWXQconKDYEz230n/YdkcMPjg9ftdm6m8tZRtIbcFOFaf+YsY3hu332t3aMn8flMWB7Vvd7Yl3IrALRg8C69gcbgcVr0dgIMumofWuTtirh4oQKZCrypHriep/D3+UX/3i68NbuxsEaNRt/u1s5cZY/VAOqhvbpYJVFe66R426K56yiyFlBS+KiqElINZck6+6zaCbtqEb4PBKQJcznke2MEgdoZYnMPavmkfPrGTcMoBaJWtYhdhI7EiWWuw/jn38zUHkH3U5a5K0BJw9sUyXIQMnz8em03kTKLdE6WLr6pPLBMFSxeQGkiugVO6CjBwYpTWsqS5AXhz13IYQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X2MveAswbsFe0dwOaRER8HEPkA7avgQ/ihtX+aWIYrFGj15uxViJcfFWB+GUViL17ACeNWcSMKuPa4Fu2J0zviOlobZnF0GLrtTLqZTfEMTqRsmk1UBW6+tteGHrwl94XlHbbCiwFIRW7oLGeRNq9qAS3ZL/tQ5Doat8qmDCDtBskFjXKs43ew/Vk8oEiUke27KC+q4NtZD0XITV2Dd6rrqsEars1CQq7E3ZKeKYEhRa/3f2AH6A+b1gVkshy/g+3cfgHunFsjzfWztGUIsBRfkzxafiBacPesWTpmt2hQah2FCX2Kd7E4dfQasfc3wKFmsIo7+x7YjacAw+Mz8XoA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 25 May 2022 08:42:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 25.05.2022 10:13, Roger Pau Monne wrote:
> Booting with Shadow Stacks leads to the following assert on a debug
> hypervisor:
> 
> Assertion 'local_irq_is_enabled()' failed at arch/x86/smp.c:265
> ----[ Xen-4.17.0-10.24-d  x86_64  debug=y  Not tainted ]----
> CPU:    0
> RIP:    e008:[<ffff82d040345300>] flush_area_mask+0x40/0x13e
> [...]
> Xen call trace:
>    [<ffff82d040345300>] R flush_area_mask+0x40/0x13e
>    [<ffff82d040338a40>] F modify_xen_mappings+0xc5/0x958
>    [<ffff82d0404474f9>] F 
> arch/x86/alternative.c#_alternative_instructions+0xb7/0xb9
>    [<ffff82d0404476cc>] F alternative_branches+0xf/0x12
>    [<ffff82d04044e37d>] F __start_xen+0x1ef4/0x2776
>    [<ffff82d040203344>] F __high_start+0x94/0xa0
> 
> This is due to SYS_STATE_smp_boot being set before calling
> alternative_branches(), and the flush in modify_xen_mappings() then
> using flush_area_all() with interrupts disabled.  Note that
> alternative_branches() is called before APs are started, so the flush
> must be a local one (and indeed the cpumask passed to
> flush_area_mask() just contains one CPU).
> 
> Take the opportunity to simplify a bit the logic and make flush_area()
> an alias of flush_area_all() in mm.c, taking into account that
> cpu_online_map just contains the BSP before APs are started.  This
> requires widening the assert in flush_area_mask() to allow being
> called with interrupts disabled as long as it's strictly a local only
> flush.
> 
> The overall result is that a conditional can be removed from
> flush_area().
> 
> While there also introduce an ASSERT to check that a vCPU state flush
> is not issued for the local CPU only.
> 
> Fixes: (78e072bc37 'x86/mm: avoid inadvertently degrading a TLB flush to 
> local only')
> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
with ...

> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -5070,13 +5070,8 @@ l1_pgentry_t *virt_to_xen_l1e(unsigned long v)
>  #define l1f_to_lNf(f) (((f) & _PAGE_PRESENT) ? ((f) |  _PAGE_PSE) : (f))
>  #define lNf_to_l1f(f) (((f) & _PAGE_PRESENT) ? ((f) & ~_PAGE_PSE) : (f))
>  
> -/*
> - * map_pages_to_xen() can be called early in boot before any other
> - * CPUs are online. Use flush_area_local() in this case.
> - */
> -#define flush_area(v,f) (system_state < SYS_STATE_smp_boot ?    \
> -                         flush_area_local((const void *)v, f) : \
> -                         flush_area_all((const void *)v, f))
> +/* flush_area_all() can be used prior to any other CPU being online.  */
> +#define flush_area(v, f) flush_area_all((const void *)v, f)

... v properly parenthesized here as the code is being touched anyway:
One less Misra-C violation. This surely can be done while committing.

Jan




 


Rackspace

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