Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2032C433E0 for ; Mon, 18 May 2020 13:14:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 78F1E20671 for ; Mon, 18 May 2020 13:14:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78F1E20671 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jafaC-0006Ww-RY; Mon, 18 May 2020 13:13:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jafaB-0006Wr-TV for xen-devel@lists.xenproject.org; Mon, 18 May 2020 13:13:27 +0000 X-Inumbo-ID: 5bafc226-9909-11ea-a860-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5bafc226-9909-11ea-a860-12813bfff9fa; Mon, 18 May 2020 13:13:26 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0491BB1F7; Mon, 18 May 2020 13:13:27 +0000 (UTC) Subject: Re: [PATCH v4] x86: clear RDRAND CPUID bit on AMD family 15h/16h To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <69382ba7-b562-2c8c-1843-b17ce6c512f1@suse.com> <20200515151838.GU54375@Air-de-Roger> From: Jan Beulich Message-ID: Date: Mon, 18 May 2020 15:13:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200515151838.GU54375@Air-de-Roger> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: "xen-devel@lists.xenproject.org" , Wei Liu , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 15.05.2020 17:18, Roger Pau Monné wrote: > On Mon, Mar 09, 2020 at 10:08:50AM +0100, Jan Beulich wrote: >> Inspired by Linux commit c49a0a80137c7ca7d6ced4c812c9e07a949f6f24: >> >> There have been reports of RDRAND issues after resuming from suspend on >> some AMD family 15h and family 16h systems. This issue stems from a BIOS >> not performing the proper steps during resume to ensure RDRAND continues >> to function properly. >> >> Update the CPU initialization to clear the RDRAND CPUID bit for any family >> 15h and 16h processor that supports RDRAND. If it is known that the family >> 15h or family 16h system does not have an RDRAND resume issue or that the >> system will not be placed in suspend, the "cpuid=rdrand" kernel parameter >> can be used to stop the clearing of the RDRAND CPUID bit. >> >> Note, that clearing the RDRAND CPUID bit does not prevent a processor >> that normally supports the RDRAND instruction from executing it. So any >> code that determined the support based on family and model won't #UD. >> >> Warn if no explicit choice was given on affected hardware. >> >> Check RDRAND functions at boot as well as after S3 resume (the retry >> limit chosen is entirely arbitrary). >> >> Signed-off-by: Jan Beulich > > Reviewed-by: Roger Pau Monné Thanks much. >> @@ -646,6 +647,25 @@ static void init_amd(struct cpuinfo_x86 >> if (acpi_smi_cmd && (acpi_enable_value | acpi_disable_value)) >> amd_acpi_c1e_quirk = true; >> break; >> + >> + case 0x15: case 0x16: >> + /* >> + * There are too many Fam15/Fam16 systems where upon resume >> + * from S3 firmware fails to re-setup properly functioning >> + * RDRAND. Clear the feature unless force-enabled on the >> + * command line. >> + */ >> + if (c == &boot_cpu_data && >> + cpu_has(c, X86_FEATURE_RDRAND) && >> + !is_forced_cpu_cap(X86_FEATURE_RDRAND)) { > > Given this is the only user of is_forced_cpu_cap... > >> + static const char __initconst text[] = >> + "RDRAND may cease to work on this hardware upon resume from S3.\n" >> + "Please choose an explicit cpuid={no-}rdrand setting.\n"; >> + >> + setup_clear_cpu_cap(X86_FEATURE_RDRAND); >> + warning_add(text); >> + } >> + break; >> } >> >> display_cacheinfo(c); >> --- a/xen/arch/x86/cpu/common.c >> +++ b/xen/arch/x86/cpu/common.c >> @@ -11,6 +11,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include /* for XEN_INVALID_{SOCKET,CORE}_ID */ >> @@ -98,6 +99,11 @@ void __init setup_force_cpu_cap(unsigned >> __set_bit(cap, boot_cpu_data.x86_capability); >> } >> >> +bool is_forced_cpu_cap(unsigned int cap) > > ... I think this could be made __init? Ah, now it can be again, yes. It was an endless back and forth between the various versions (some not even posted). Jan