From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751132AbdAQVpq (ORCPT ); Tue, 17 Jan 2017 16:45:46 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:46513 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751012AbdAQVpp (ORCPT ); Tue, 17 Jan 2017 16:45:45 -0500 Date: Tue, 17 Jan 2017 22:24:50 +0100 (CET) From: Thomas Gleixner To: Borislav Petkov cc: X86 ML , LKML Subject: Re: [PATCH 13/13] x86/microcode/AMD: Remove AP scanning optimization In-Reply-To: <20170117173734.14251-14-bp@alien8.de> Message-ID: References: <20170117173734.14251-1-bp@alien8.de> <20170117173734.14251-14-bp@alien8.de> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 17 Jan 2017, Borislav Petkov wrote: > From: Borislav Petkov > > The idea was to not scan the microcode blob on each AP (Application > Processor) during boot and thus save us some milliseconds. However, on > architectures where the microcode engine is shared between threads, this > doesn't work. Here's why: > > The microcode on CPU0, i.e., the first thread, gets updated. The second > thread, i.e., CPU1, i.e., the first AP walks into load_ucode_amd_ap(), > sees that there's no container cached and goes and scans for the proper > blob. > > It finds it and as a last step of apply_microcode_early_amd(), it tries > to apply the patch but that core has already the updated microcode > revision which it has received through CPU0's update. So it returns > false and we do desc->size = -1 to prevent other APs from scanning. > > However, the next AP, CPU2, has a different microcode engine which > hasn't been updated yet. The desc->size == -1 test prevents it from > scanning the blob anew and we fail to update it. Well, that could be solved by a proper state member in the global container descriptor. But your solution is better in the end. > The fix is much more straight-forward than it looks: the BSP > (BootStrapping Processor), i.e., CPU0, caches the microcode patch > in amd_ucode_patch. We use that on the AP and try to apply it. > In the 99.9999% of cases where we have homogeneous cores - *not* > mixed-steppings - the application will be successful and we're good to > go. > > In the remaining small set of systems, we will simply rescan the blob > and find (or not, if none present) the proper patch and apply it then. Makes sense, but how does such a system handle the suspend/resume case when the micro code is in the initrd? Are you caching the per cpu patches somewhere? Reviewed-by: Thomas Gleixner