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

Re: [PATCH] x86: harden use of calc_ler_msr()


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 30 May 2022 18:07:23 +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=jP3OldByQNgi3aLknkPv0jNYUP6XcA/mWBkKrAJ6ZNs=; b=T9qRFCWvSVVETkYlagYRo7qLzQxE1hzbL4YmUubHFYF6qMi9yKdqHJwHyx9w4Wde3kRXgBqeOoGN38C2vvFQ04frBFQqIpLJ3FLkI00HCo238ds1cO0I01DJy2O/dbIBElWibWbQsPJGKbLpFC1wWJiqn6MisDokX8/nfwe7W7R9V+Rm3KMryONGAQ48f5oyJYBL8uz8B6fTsRBqBOXobmaefkIMW/Pz6/hzEZFTVYXWraA9WbYhG4hRGQmZgEdX1gc0+F5jp75GtaRgaVLVBChsuJJv/FuDsBB7ZqL3XhRTYjJmsUS2vF2+IvpEbqcJcX9QxUucNhLGwiSTTmJyfg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hhP/M9nTw2hG0oDnESPLD+ZOoV9ZvQJRR0T0K3aP1MfNdt4+haUsP05PvJbuOrFtc3eUcuAh5AURlNgLmz9mbZpmHjie9TvaHbHjKj1igz4jSwgqaMiGGQryS1RsxzQAXBkyCcZmnZioImINH5V2MTr7ZJFwmHhaWt5djzmluvPRZgJ4ruuf6ULIOn7Q/jaRrOs46LulwqbZ9AwNz5Lc0ydi8LXo0SdxlhyroVRrvW0JyubdY9S2AJha/8S28cx1WpmvJiEHgY09jCsQ3bzaumGskSHmCDY9LvGx2vS48wHaJkBm6t0ZKjKW4kXU7TLTeKPLqe+LrekAgRWTqyMsoQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Mon, 30 May 2022 16:07:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 30.05.2022 17:58, Roger Pau Monné wrote:
> On Mon, May 30, 2022 at 05:48:51PM +0200, Jan Beulich wrote:
>> 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 )
>> +        {
> 
> While doing this rework it might make sense to print some message
> here, like: "LER option requested but no LBR support available" or
> similar IMO.

Hmm, yes, but you look to do so in your series already. Could we
leave things silent here (as it always was) until your adding of
arch-LBR support, and then taking care of both failure conditions
with a single log message? Of course I could add a message here
just for you to then (likely) alter it again ...

> The rest LGTM:
> 
> Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thanks, but I'll wait with applying this.

Jan




 


Rackspace

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