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

[PATCH] x86: harden use of calc_ler_msr()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 30 May 2022 17:48: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=B+nWreY+WnPK6i+bgNybqgeha/kLJooNellhfaQljnw=; b=f0DeWM2JaYqkHqQ8EBd107G2dqiaiqAQ07/suu46Vzr4AP0cnwhhPXtT1Ae0ivJbQX7G47UkwfhfCIsydqfINIPCMlyApN0rYuncnfElD/+6KnWhbodqO7DavyD872Xq8gvyzRPtyUZF3yGxTPySk7sdo72fvnBzEr9XgXFMbmeRiTqhkr+uT+62BUMAhQ9gN6nlo2+TFiUSkuQ4A7V4fl1P4iclXcXeTzEkwycomg0N2c3uTqwkwssdFyXkZ2XNnjX5v3/fkx9PFGxKx6HW0OguF4+Efln+wpNovo5lQ0/CBoSHITsyEFKx9FqnVv/FzYarPiQfrMET5UMHPEUR8g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EfMQ3DlNN+E+/Wb/zPc9IWWCco1RX9KFpZmxVXot0lAwiFSmiMqgbP/rF3bcrxgtaxBHcCTHllTU3WPCM1ALeAYGy7eK00iINAPA1mqfKsOJMhCV/mgyOEgblCEN39Gh6PwhTXCjcJxRaK5IMIUqKBRjN8VWIaNOUYX2oTg4Q058ThxYht6YJeBYAVOiURnPDRvVmurt5QcOnT6Y6BMmG2jSAJ67TwpODf9jXAZSGGNTH+evk3fyAo9aTsH48a74DXAVDJwA2IboXnATXNZj+q2j6Fb1vEwIKyr3/eOr7dNn5ARuVumrWFSE2UkIc74QwMnmRoPzWx6A8L51B8DLGw==
  • 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>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 30 May 2022 15:49:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Avoid calling the function more than once, thus making sure we won't,
under any unusual circumstances, attempt to enable XEN_LER late (which
can't work, for setup_force_cpu_cap() being __init. In turn this then
allows making the function itself __init, too.

While fiddling with section attributes in this area, also move the two
involved variables to .data.ro_after_init.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -126,11 +126,11 @@ DEFINE_PER_CPU_PAGE_ALIGNED(struct tss_p
 static int debug_stack_lines = 20;
 integer_param("debug_stack_lines", debug_stack_lines);
 
-static bool opt_ler;
+static bool __ro_after_init opt_ler;
 boolean_param("ler", opt_ler);
 
 /* LastExceptionFromIP on this hardware.  Zero if LER is not in use. */
-unsigned int __read_mostly ler_msr;
+unsigned int __ro_after_init ler_msr;
 
 const unsigned int nmi_cpu;
 
@@ -2133,7 +2133,7 @@ static void __init set_intr_gate(unsigne
     __set_intr_gate(n, 0, addr);
 }
 
-static unsigned int calc_ler_msr(void)
+static unsigned int noinline __init calc_ler_msr(void)
 {
     switch ( boot_cpu_data.x86_vendor )
     {
@@ -2171,8 +2171,17 @@ void percpu_traps_init(void)
     if ( !opt_ler )
         return;
 
-    if ( !ler_msr && (ler_msr = calc_ler_msr()) )
+    if ( !ler_msr )
+    {
+        ler_msr = calc_ler_msr();
+        if ( !ler_msr )
+        {
+            opt_ler = false;
+            return;
+        }
+
         setup_force_cpu_cap(X86_FEATURE_XEN_LBR);
+    }
 
     if ( cpu_has_xen_lbr )
         wrmsrl(MSR_IA32_DEBUGCTLMSR, IA32_DEBUGCTLMSR_LBR);




 


Rackspace

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