From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 2/2] microcode: Check whether the microcode is correct. Date: Wed, 25 Sep 2013 15:10:10 +0100 Message-ID: <5242EEC2.600@citrix.com> References: <1380113870-3641-1-git-send-email-konrad.wilk@oracle.com> <1380113870-3641-3-git-send-email-konrad.wilk@oracle.com> <5242E184.9080303@citrix.com> <20130925135927.GA3834@phenom.dumpdata.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VOpnD-0002eV-Ie for xen-devel@lists.xenproject.org; Wed, 25 Sep 2013 14:10:15 +0000 In-Reply-To: <20130925135927.GA3834@phenom.dumpdata.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Konrad Rzeszutek Wilk Cc: xen-devel@lists.xenproject.org, david.vrabel@citrix.com, jbeulich@suse.com List-Id: xen-devel@lists.xenproject.org On 25/09/13 14:59, Konrad Rzeszutek Wilk wrote: > On Wed, Sep 25, 2013 at 02:13:40PM +0100, Andrew Cooper wrote: >> On 25/09/13 13:57, Konrad Rzeszutek Wilk wrote: >>> We do the microcode code update in two steps - the presmp: >>> 'microcode_presmp_init' and when CPUs are brought up: >>> 'microcode_init'. The earlier performs the microcode update >>> on the BSP - but unfortunately it does not check whether the >>> update failed. Which means that we might try later to update >>> a incorrect payload on the rest of CPUs. >>> >>> This patch handles this odd situation. >>> >>> Signed-off-by: Konrad Rzeszutek Wilk >> While not strictly relevant to this patch, I simply noticed when >> reviewing it that ucode_blob is __initdata. Given the comment "The >> cached microcode patch is applied when CPUs resume from a sleep state." >> in the previous patch, what is the policy for reloading microcode after >> deep sleep / cpu hotplug ? > The underlaying architecture microcode (microcode_intel or microcode_amd) > end up saving it in 'struct ucode_cpu_info' which is a per-cpu data > structure (see ucode_cpu_info). They end up saving it when doing the > pre-SMP (for CPU0) and SMP (for the rest) microcode loading. > > And naturally if one does a hypercall to update the microcode and it is > newer, then the old per-cpu data is replaced. Ah ok - I missed that. > > Would you like me to update the git commit description with this? It might be worth having a note to this effect in the commit message of the previous patch. ~Andrew >>> [v2: Redid it as we are not doing scan and at the same time] >>> --- >>> xen/arch/x86/microcode.c | 16 +++++++++++++++- >>> 1 file changed, 15 insertions(+), 1 deletion(-) >>> >>> diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c >>> index 8136d44..0bc95e6 100644 >>> --- a/xen/arch/x86/microcode.c >>> +++ b/xen/arch/x86/microcode.c >>> @@ -419,6 +419,7 @@ static int __init microcode_presmp_init(void) >>> { >>> void *data; >>> size_t len; >>> + int rc = 0; >>> >>> if ( ucode_blob.size ) >>> { >>> @@ -431,10 +432,23 @@ static int __init microcode_presmp_init(void) >>> data = ucode_mod_map(&ucode_mod); >>> } >>> if ( data ) >>> - microcode_update_cpu(data, len); >>> + rc = microcode_update_cpu(data, len); >>> + else >>> + rc = -ENOMEM; >>> >>> if ( !ucode_blob.size ) >>> ucode_mod_map(NULL); >>> + >>> + if ( rc ) >>> + { >>> + if ( ucode_blob.size ) >>> + { >>> + xfree(ucode_blob.data); >>> + ucode_blob.size = 0; >>> + ucode_blob.data = NULL; >>> + } else >>> + ucode_mod.mod_end = 0; >>> + } >>> } >>> >>> register_cpu_notifier(µcode_percpu_nfb);