From patchwork Wed Dec 18 01:32:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eslam Elnikety X-Patchwork-Id: 11299281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96204109A for ; Wed, 18 Dec 2019 01:34:40 +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 6807021582 for ; Wed, 18 Dec 2019 01:34:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="DQqklKWB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6807021582 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none 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.89) (envelope-from ) id 1ihODY-0005w3-8q; Wed, 18 Dec 2019 01:33:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihODW-0005vy-Oe for xen-devel@lists.xenproject.org; Wed, 18 Dec 2019 01:33:34 +0000 X-Inumbo-ID: 6778ea9c-2136-11ea-b6f1-bc764e2007e4 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6778ea9c-2136-11ea-b6f1-bc764e2007e4; Wed, 18 Dec 2019 01:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1576632815; x=1608168815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=YX5aKn14c6/o2NvUIllJEdUbLgeEiYMz5ia17hfFzfI=; b=DQqklKWBt4x9r8Eo74urI5aHrt9n+aJF4SAY4HGAmdmapT6vVi7CfsPr +fVIhpRzPg0hOqfG/4PnUWtrbUMXRJQKWNkUxPf0j9ruOjv6ldcJ8wmiH qEIZylGJdjRD4SsMG/5lbWWFRANnr0YlMD2XzSqvbyIjpm4T3cFu7/+d5 M=; IronPort-SDR: 8jg9l1qXJNeLlvGj91S/r/z8ZpEt5MpSF7/8NLhVa9BBiQYL+s7ybfv1FX7t9qn3eFA0nraswT khfX5LY2kT1Q== X-IronPort-AV: E=Sophos;i="5.69,327,1571702400"; d="scan'208";a="5740179" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 18 Dec 2019 01:33:33 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-c7131dcf.us-west-2.amazon.com (Postfix) with ESMTPS id 3EDFAA2704; Wed, 18 Dec 2019 01:33:32 +0000 (UTC) Received: from EX13D08UEE003.ant.amazon.com (10.43.62.118) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Dec 2019 01:33:31 +0000 Received: from EX13MTAUEA002.ant.amazon.com (10.43.61.77) by EX13D08UEE003.ant.amazon.com (10.43.62.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Dec 2019 01:33:31 +0000 Received: from dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (10.15.63.96) by mail-relay.amazon.com (10.43.61.169) with Microsoft SMTP Server id 15.0.1236.3 via Frontend Transport; Wed, 18 Dec 2019 01:33:31 +0000 Received: by dev-dsk-elnikety-1b-cd63f796.eu-west-1.amazon.com (Postfix, from userid 6438462) id 3AD62A0141; Wed, 18 Dec 2019 01:33:31 +0000 (UTC) From: Eslam Elnikety To: Date: Wed, 18 Dec 2019 01:32:57 +0000 Message-ID: X-Mailer: git-send-email 2.16.5 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 2/4] x86/microcode: avoid unnecessary xmalloc/memcpy of ucode data X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Eslam Elnikety , Paul Durrant , Jan Beulich , David Woodhouse Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When using `ucode=scan` and if a matching module is found, the microcode payload is maintained in an xmalloc()'d region. This is unnecessary since the bootmap would just do. Remove the xmalloc and xfree on the microcode module scan path. This commit also does away with the restriction on the microcode module size limit. The concern that a large microcode module would consume too much memory preventing guests launch is misplaced since this is all the init path. While having such safeguards is valuable, this should apply across the board for all early/late microcode loading. Having it just on the `scan` path is confusing. Looking forward, we are a bit closer (i.e., one xmalloc down) to pulling the early microcode loading of the BSP a bit earlier in the early boot process. This commit is the low hanging fruit. There is still a sizable amount of work to get there as there are still a handful of xmalloc in microcode_{amd,intel}.c. First, there are xmallocs on the path of finding a matching microcode update. Similar to the commit at hand, searching through the microcode blob can be done on the already present buffer with no need to xmalloc any further. Even better, do the filtering in microcode.c before requesting the microcode update on all CPUs. The latter requires careful restructuring and exposing the arch-specific logic for iterating over patches and declaring a match. Second, there are xmallocs for the microcode cache. Here, we would need to ensure that the cache corresponding to the BSP gets xmalloc()'d and populated after the fact. Signed-off-by: Eslam Elnikety Acked-by: Jan Beulich --- xen/arch/x86/microcode.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 8b4d87782c..c878fc71ff 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -138,11 +138,6 @@ static int __init parse_ucode_param(const char *s) } custom_param("ucode", parse_ucode_param); -/* - * 8MB ought to be enough. - */ -#define MAX_EARLY_CPIO_MICROCODE (8 << 20) - void __init microcode_scan_module( unsigned long *module_map, const multiboot_info_t *mbi) @@ -187,31 +182,12 @@ void __init microcode_scan_module( cd = find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */); if ( cd.data ) { - /* - * This is an arbitrary check - it would be sad if the blob - * consumed most of the memory and did not allow guests - * to launch. - */ - if ( cd.size > MAX_EARLY_CPIO_MICROCODE ) - { - printk("Multiboot %d microcode payload too big! (%ld, we can do %d)\n", - i, cd.size, MAX_EARLY_CPIO_MICROCODE); - goto err; - } - ucode_blob.size = cd.size; - ucode_blob.data = xmalloc_bytes(cd.size); - if ( !ucode_blob.data ) - cd.data = NULL; - else - memcpy(ucode_blob.data, cd.data, cd.size); + ucode_blob.size = cd.size; + ucode_blob.data = cd.data; + break; } bootstrap_map(NULL); - if ( cd.data ) - break; } - return; -err: - bootstrap_map(NULL); } void __init microcode_grab_module( unsigned long *module_map, @@ -725,7 +701,7 @@ static int __init microcode_init(void) */ if ( ucode_blob.size ) { - xfree(ucode_blob.data); + bootstrap_map(NULL); ucode_blob.size = 0; ucode_blob.data = NULL; }