From nobody Sun Apr 28 21:19:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1679946138; cv=none; d=zohomail.com; s=zohoarc; b=fAYh4FdCcSQmEdZyl070qibt5ERwcAFzD7bDOraJ6p8wib5WqPgJdJBzByflf4aInzNUg0i2OatH/2l064WsSq/nFQx6C4XfCpSWNf8jJa6uwc87729U1HaakroDI0SrOsPJn2B4OS3hrhax1f1fFTJyTIQvzEVDzyMUDsptH2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679946138; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ASDkNEPHlBQJ+tayElQ81QloLJbiyGsqvSDd0VaW9I0=; b=aalTfyij9fMNJiTMU5yc1jqqdhGC5Bc9jOmyKy3YICqtwtGRT3GJWcDlcz6Itk0CoIRjhf9gUJ898L3DpRW/4KMx+UrlO/RcodMO0oCzOdScqmMBv2hN0Pwcd6H47zIu5ZlZ0r5eO3JkfWFGt831ZyOC+Qvq0jQepPDMXJFa7h8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1679946138259527.9572928676871; Mon, 27 Mar 2023 12:42:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515453.798333 (Exim 4.92) (envelope-from ) id 1pgsis-0002jP-Po; Mon, 27 Mar 2023 19:41:42 +0000 Received: by outflank-mailman (output) from mailman id 515453.798333; Mon, 27 Mar 2023 19:41:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsis-0002jI-NG; Mon, 27 Mar 2023 19:41:42 +0000 Received: by outflank-mailman (input) for mailman id 515453; Mon, 27 Mar 2023 19:41:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsir-0002j7-PD for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 19:41:42 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 62f0e800-ccd7-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 21:41:38 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 62f0e800-ccd7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679946098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qHxoaXcYTvK6LrtavVTEPpXmEC/muoBbiaV4h46YBMA=; b=R2aKa0qEOt6uVQ9A1QIMt9c8NaZjDlVvmlonnFgeG25wWVYK044tzGqR kyXzdVzkB7M7Swz7IFqcfy4IoJ2uLaJoWuB3TldSLGpmEey0KcmdBwjwq AtXn24YKrBBANxg2ZJrZ9IsWjoXScKgCbuwRpk0+YEV3nYnDFAgscashT o=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 103008786 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:2TsHU6PFZ10BXH/vrR2ol8FynXyQoLVcMsEvi/4bfWQNrUorhjRWy GMcWD2POqmDamvxe9B1PISz9BwH6pLSmNJiQAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvLrRC9H5qyo42tD5ANmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0vddXUpW6 8MfFAI2UzyIm/6J+b6JddA506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w2Nk+ojx5nYz/7DLoXmuuyi2a5WDpfsF+P/oI84nTJzRw327/oWDbQUoXSHp0NzhnI+ Aoq+Uz2XjcLDp+k9QOrySz8nM/trSr5RacdQejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasnDQRRt5RGO0S8xyWx+zf5APxLncAZi5MbpohrsBeeNAx/ gbXxZWzX2Up6eDLDyvHrd94sA9eJwAEBzMpfTE7Sjc32OTPq50vsSvDfOlaRfvdYsLOJd3g/ 9ybhHFg2ORN05NRjP3TEUPv2Gz1+MWQJuIhzkCOBz/+sFskDGKwT9bwgWU3+8qsO2pworOpm HEf0/aT4+kVZX1mvHzcGb5ddF1FChvsDdE9vbKMN8N7n9hV0yT/Fb28Gg1WKkZzKdojcjT0e kLVsg45zMYNYyr7MfYnON3rVZxCIU3c+TLNDKi8gj1mPPBMmPKvpnkyNSZ8IUi0+KTTrU3PE cjCKpv9ZZrrIa9m0CC3V48g7FPf/QhnnTm7bcmin3yaPU+2OCb9Ya0bK2GHcu1RxPrC+G05B f4DbZrVo/ieOcWiChTqHXk7dAlTdiJnXMCn8qS6tIere2JbJY3oMNeJqZtJRmCvt/49ejvgl p1lZnJl9Q== IronPort-HdrOrdr: A9a23:cyh7iqGKBec31Sn8pLqEL8eALOsnbusQ8zAXP0AYc20yTiX4ra CTdZEgviMc5wxxZJhNo6HkBEDiewKkyXcW2/hoAV7KZmCP1wWVxelZnPDfKlbbaknDH4BmpM BdWpk7JefcSX5dpq/BjDVQFexL/PC3tJqFv6P16VBDbS9XUIlczyFfTjy2LyRNNWp7LKt8G5 qY6tBGtDa7EE57Uu2wGmMZWezOvP3n/aiWAyI7Ow== X-IronPort-AV: E=Sophos;i="5.98,295,1673931600"; d="scan'208";a="103008786" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Sergey Dyasli Subject: [PATCH 1/5] xen/earlycpio: Drop nextoff parameter Date: Mon, 27 Mar 2023 20:41:22 +0100 Message-ID: <20230327194126.3573997-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327194126.3573997-1-andrew.cooper3@citrix.com> References: <20230327194126.3573997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1679946139579100009 This is imported from Linux, but the parameter being signed is dubious in t= he first place and we're not plausibly going to gain a use for the functionali= ty. Linux has subsequently made it an optional parameter to avoid forcing calle= rs to pass a stack variable they don't care about using. In the unlikely case that we gain a usecase, we can reintroduce it, but in = the meantime simplify the single caller. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Sergey Dyasli --- xen/arch/x86/cpu/microcode/core.c | 3 +-- xen/common/earlycpio.c | 8 +------- xen/include/xen/earlycpio.h | 3 +-- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index cfa2d5053a52..11c471cc3f83 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -156,7 +156,6 @@ void __init microcode_scan_module( uint64_t *_blob_start; unsigned long _blob_size; struct cpio_data cd; - long offset; const char *p =3D NULL; int i; =20 @@ -189,7 +188,7 @@ void __init microcode_scan_module( } cd.data =3D NULL; cd.size =3D 0; - cd =3D find_cpio_data(p, _blob_start, _blob_size, &offset /* ignor= e */); + cd =3D find_cpio_data(p, _blob_start, _blob_size); if ( cd.data ) { ucode_blob.size =3D cd.size; diff --git a/xen/common/earlycpio.c b/xen/common/earlycpio.c index 4bcf32a51ceb..6c76307c2541 100644 --- a/xen/common/earlycpio.c +++ b/xen/common/earlycpio.c @@ -56,10 +56,6 @@ enum cpio_fields { * @path: The directory to search for, including a slash at the end * @data: Pointer to the the cpio archive or a header inside * @len: Remaining length of the cpio based on data pointer - * @nextoff: When a matching file is found, this is the offset from the - * beginning of the cpio to the beginning of the next file, n= ot the - * matching file itself. It can be used to iterate through th= e cpio - * to find all files inside of a directory path. * * @return: struct cpio_data containing the address, length and * filename (with the directory path cut off) of the found fi= le. @@ -68,8 +64,7 @@ enum cpio_fields { * the match returned an empty filename string. */ =20 -struct cpio_data __init find_cpio_data(const char *path, void *data, - size_t len, long *nextoff) +struct cpio_data __init find_cpio_data(const char *path, void *data, size_= t len) { const size_t cpio_header_len =3D 8*C_NFIELDS - 2; struct cpio_data cd =3D { NULL, 0, "" }; @@ -129,7 +124,6 @@ struct cpio_data __init find_cpio_data(const char *path= , void *data, if ((ch[C_MODE] & 0170000) =3D=3D 0100000 && ch[C_NAMESIZE] >=3D mypathsize && !memcmp(p, path, mypathsize)) { - *nextoff =3D (long)nptr - (long)data; if (ch[C_NAMESIZE] - mypathsize >=3D MAX_CPIO_FILE_NAME) { printk( "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n", diff --git a/xen/include/xen/earlycpio.h b/xen/include/xen/earlycpio.h index 16d9404d739e..d4992035982d 100644 --- a/xen/include/xen/earlycpio.h +++ b/xen/include/xen/earlycpio.h @@ -9,7 +9,6 @@ struct cpio_data { char name[MAX_CPIO_FILE_NAME]; }; =20 -struct cpio_data find_cpio_data(const char *path, void *data, size_t len, - long *offset); +struct cpio_data find_cpio_data(const char *path, void *data, size_t len); =20 #endif /* _EARLYCPIO_H */ --=20 2.30.2 From nobody Sun Apr 28 21:19:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1679946136; cv=none; d=zohomail.com; s=zohoarc; b=LEEtmtSEX1yTnRvQB2ojYr9KLvpYF84rOYWCDCvXDdT+209oy+9yA21d8F1OTNm+sWIMSnR8E8dgp6v55kjCI4GnZwn6F92ZKBOaytXH2ues9Ufp9uIYYvZkahfQxFSONH108cmGyLHhgjXhcI959vqU6T3nLItw6tNV5Bqclxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679946136; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JiJBbIqVFDb0Km60E7VKjjyF8AcOKqvA+0DIiaWu9bY=; b=dTVTyjr9Yh4i/1Ln0gplGbA4+7ZAbMW/jfm/ZqdqJYIFOObXUhb1ePddHxsECEYQDFmYuF1zTf66+l8SPZo/7zQbLEkxZoLiZGlOE+hnsGVJa6xApkbwQbnb/yfqSVn87zvmY/A3d0NBCm/ghXb731RDdwo3ttnYCZ6PXucNizA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1679946136319130.5410621419055; Mon, 27 Mar 2023 12:42:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515458.798383 (Exim 4.92) (envelope-from ) id 1pgsiy-000425-FD; Mon, 27 Mar 2023 19:41:48 +0000 Received: by outflank-mailman (output) from mailman id 515458.798383; Mon, 27 Mar 2023 19:41:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiy-00041s-Bi; Mon, 27 Mar 2023 19:41:48 +0000 Received: by outflank-mailman (input) for mailman id 515458; Mon, 27 Mar 2023 19:41:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiw-0002j7-Du for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 19:41:46 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 66e52436-ccd7-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 21:41:43 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 66e52436-ccd7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679946103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A4IRiksY66q+14P3ogmWDrkQ7IqWvKWCQhasxkw28Ak=; b=LAkwARIq+I+QU2FFcMsqWq/v0WT3eHmyvBn7MTt8YQXs1KVZBQ21PHqS CvTngYcwlBvRg/zcnZBH80ntUDmpoGKcL7l6tYXQ/eXQOCZ2NBFBgxcwQ EGKSrZjJ+Q1bKkhzbKUilXQehUJvDsiKm9fY+M4rAmFSBhEYMdZhzZ1K2 U=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 103008793 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:T2PxKa/qUbeyCuyvy2XTDrUDjX6TJUtcMsCJ2f8bNWPcYEJGY0x3n GQZDDvUOfuCNmP8c48iPt639k0GscSBnddhSwNopCw8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKicYXoZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kI/1BjOkGlA5AdmPqoU5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0adu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";a="103008793" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Sergey Dyasli Subject: [PATCH 2/5] x86/ucode: Fold early_update_cache() into microcode_init_cache() Date: Mon, 27 Mar 2023 20:41:23 +0100 Message-ID: <20230327194126.3573997-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327194126.3573997-1-andrew.cooper3@citrix.com> References: <20230327194126.3573997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1679946137619100006 It is not valid to retain a bootstrap_map() across returning back to __start_xen(), but various pointers get stashed across calls. Begin to address this by folding early_update_cache() into it's single call= er, rearranging the exit path to always invalidate the mapping. No practical change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Sergey Dyasli --- xen/arch/x86/cpu/microcode/core.c | 54 +++++++++++++++++-------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 11c471cc3f83..3d23e3ed7ee4 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -755,47 +755,51 @@ int microcode_update_one(void) return microcode_update_cpu(NULL); } =20 -static int __init early_update_cache(const void *data, size_t len) +int __init microcode_init_cache(unsigned long *module_map, + const struct multiboot_info *mbi) { int rc =3D 0; struct microcode_patch *patch; + struct ucode_mod_blob blob =3D {}; =20 - if ( !data ) - return -ENOMEM; + if ( ucode_scan ) + /* Need to rescan the modules because they might have been relocat= ed */ + microcode_scan_module(module_map, mbi); + + if ( ucode_mod.mod_end ) + { + blob.data =3D bootstrap_map(&ucode_mod); + blob.size =3D ucode_mod.mod_end; + } + else if ( ucode_blob.size ) + { + blob =3D ucode_blob; + } =20 - patch =3D parse_blob(data, len); + if ( !blob.data ) + return 0; + + patch =3D parse_blob(blob.data, blob.size); if ( IS_ERR(patch) ) { - printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", - PTR_ERR(patch)); - return PTR_ERR(patch); + rc =3D PTR_ERR(patch); + printk(XENLOG_WARNING "Parsing microcode blob error %d\n", rc); + goto out; } =20 if ( !patch ) - return -ENOENT; + { + rc =3D -ENOENT; + goto out; + } =20 spin_lock(µcode_mutex); rc =3D microcode_update_cache(patch); spin_unlock(µcode_mutex); ASSERT(rc); =20 - return rc; -} - -int __init microcode_init_cache(unsigned long *module_map, - const struct multiboot_info *mbi) -{ - int rc =3D 0; - - if ( ucode_scan ) - /* Need to rescan the modules because they might have been relocat= ed */ - microcode_scan_module(module_map, mbi); - - if ( ucode_mod.mod_end ) - rc =3D early_update_cache(bootstrap_map(&ucode_mod), - ucode_mod.mod_end); - else if ( ucode_blob.size ) - rc =3D early_update_cache(ucode_blob.data, ucode_blob.size); + out: + bootstrap_map(NULL); =20 return rc; } --=20 2.30.2 From nobody Sun Apr 28 21:19:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1679946132; cv=none; d=zohomail.com; s=zohoarc; b=mKNqTeCvK9KU3n/qe504I0AdA0VoeFXqCg39zlvS+/0NkV36HGUpUch15JZnUxinWrWJpteA6FCd0MKdLdX3o5Cm+VZqLXGnywbVzq5v1oapCO/u1AQsCh8Eac6RkFbwSkYoP/1e0G/x2emj89dAezQxbH0EoBM1mkvWtUN1pl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679946132; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=owPkAQE6QUMBs4PIhWd6gvaQ4xs1Loixspqr2f7TX5k=; b=cH453MoOl3EmZavE5iOo3dLMT92bb8EONCcyDjoSUcqaXfXY2PChV2fJE9mFeIyNmiyATDI0nqG6PEK86fgtO2u+d0hUHpbQH798f21/txvodRK4JBFHd55bReZBl3wHzRrQwigVL0VJHTj+EcoIygjjv+0PJGDbN14stj82spQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 167994613284074.55452456440128; Mon, 27 Mar 2023 12:42:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515457.798374 (Exim 4.92) (envelope-from ) id 1pgsix-0003ij-19; Mon, 27 Mar 2023 19:41:47 +0000 Received: by outflank-mailman (output) from mailman id 515457.798374; Mon, 27 Mar 2023 19:41:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiw-0003iD-Sd; Mon, 27 Mar 2023 19:41:46 +0000 Received: by outflank-mailman (input) for mailman id 515457; Mon, 27 Mar 2023 19:41:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiv-0002j7-Dt for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 19:41:45 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 65bdbad7-ccd7-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 21:41:43 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 65bdbad7-ccd7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679946102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LsekXLTw0DjPTzJsgqE8jFzXfBBPFxBP5u5EwDgnQTo=; b=PsKJoU5VoM6ym3ON0I2H/5duSvBza1Q1OIi0J9EYG51NS2kONfizgEQP AKtlDCf/H0wK5Bo6TdhSVNWyk4IRFOuiqmvwPn7qhPiaKOBtU/vRy/nyN kJVvevfwbNo4URNcd86KKxH0tBMqNYMAJQ4I3V5YneEX1v6dCbXB5jZ22 g=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 103008790 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:LMLZAqktGizZl7cFfGK/wRzo5gyMJkRdPkR7XQ2eYbSJt1+Wr1Gzt xIbWGqCPq7ZNmumL4skPYS/8E1QsZGGmodmHAM+/i48FSMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aSaVA8w5ARkPqgQ5gCGzRH5MbpETU2PByqgKmVrNrbSq 9brlNmR4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+tbKL OsosVGoja7eWcadK2Aa0UtVfTYutvOmInHTHc9dnwa1DU= X-IronPort-AV: E=Sophos;i="5.98,295,1673931600"; d="scan'208";a="103008790" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Sergey Dyasli Subject: [PATCH 3/5] x86/ucode: Fold early_microcode_update_cpu() into early_microcode_init() Date: Mon, 27 Mar 2023 20:41:24 +0100 Message-ID: <20230327194126.3573997-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327194126.3573997-1-andrew.cooper3@citrix.com> References: <20230327194126.3573997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1679946134060100001 It is not valid to retain a bootstrap_map() across returning back to __start_xen(), but various pointers get stashed across calls. Begin to address this by folding early_update_cache() into it's single call= er, rearranging the exit path to always invalidate the mapping. No practical change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Sergey Dyasli --- xen/arch/x86/cpu/microcode/core.c | 70 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 3d23e3ed7ee4..4d2a896fe78d 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -804,45 +804,12 @@ int __init microcode_init_cache(unsigned long *module= _map, return rc; } =20 -/* BSP calls this function to parse ucode blob and then apply an update. */ -static int __init early_microcode_update_cpu(void) -{ - const void *data =3D NULL; - size_t len; - struct microcode_patch *patch; - - if ( ucode_blob.size ) - { - len =3D ucode_blob.size; - data =3D ucode_blob.data; - } - else if ( ucode_mod.mod_end ) - { - len =3D ucode_mod.mod_end; - data =3D bootstrap_map(&ucode_mod); - } - - if ( !data ) - return -ENOMEM; - - patch =3D ucode_ops.cpu_request_microcode(data, len, false); - if ( IS_ERR(patch) ) - { - printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", - PTR_ERR(patch)); - return PTR_ERR(patch); - } - - if ( !patch ) - return -ENOENT; - - return microcode_update_cpu(patch); -} - int __init early_microcode_init(unsigned long *module_map, const struct multiboot_info *mbi) { const struct cpuinfo_x86 *c =3D &boot_cpu_data; + struct microcode_patch *patch; + struct ucode_mod_blob blob =3D {}; int rc =3D 0; =20 switch ( c->x86_vendor ) @@ -868,8 +835,37 @@ int __init early_microcode_init(unsigned long *module_= map, =20 ucode_ops.collect_cpu_info(); =20 - if ( ucode_mod.mod_end || ucode_blob.size ) - rc =3D early_microcode_update_cpu(); + if ( ucode_blob.data ) + { + blob =3D ucode_blob; + } + else if ( ucode_mod.mod_end ) + { + blob.data =3D bootstrap_map(&ucode_mod); + blob.size =3D ucode_mod.mod_end; + } + + if ( !blob.data ) + return 0; + + patch =3D ucode_ops.cpu_request_microcode(blob.data, blob.size, false); + if ( IS_ERR(patch) ) + { + rc =3D PTR_ERR(patch); + printk(XENLOG_WARNING "Parsing microcode blob error %d\n", rc); + goto out; + } + + if ( !patch ) + { + rc =3D -ENOENT; + goto out; + } + + rc =3D microcode_update_cpu(patch); + + out: + bootstrap_map(NULL); =20 return rc; } --=20 2.30.2 From nobody Sun Apr 28 21:19:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1679946135; cv=none; d=zohomail.com; s=zohoarc; b=MwjoJrYxtu37IQtzLJcFfW/0TulCzsAs5X4J7lA74nYM/QjHfe5+8BIgxJGI4ejgc6guLw6URiCf+y2UJlXDeKQgoJhHm4meg9WO2XotonUhwysaTG/2dsOlZWbhU3bVgZPEXROAPNrX9/yc/dHo4L4nUFL+lYuyprhi0zxr2Xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679946135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0iwejR257wpMAT7CoGS0K1VgLIHIR4I9ZaJXdqdGOls=; b=EidNUDczXJn72mfG8rc0pyBoIiYqicypIMX44OGn0wLRvvcohlIIxcbF3lKB8ODwICbTte0HE3wQ/FXOQuAHOfoH4Ds4fLaGGngDfmHnAYETZHF0+puoP4iZCAsKz+ExgNk6RDTobLojo4D3llChFXFLxU6Vvt+J8oVM1QwXYT4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1679946135903604.4774044875516; Mon, 27 Mar 2023 12:42:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515454.798344 (Exim 4.92) (envelope-from ) id 1pgsiu-0002yX-6H; Mon, 27 Mar 2023 19:41:44 +0000 Received: by outflank-mailman (output) from mailman id 515454.798344; Mon, 27 Mar 2023 19:41:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiu-0002yQ-2e; Mon, 27 Mar 2023 19:41:44 +0000 Received: by outflank-mailman (input) for mailman id 515454; Mon, 27 Mar 2023 19:41:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsis-0002j7-De for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 19:41:42 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 62f618e2-ccd7-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 21:41:39 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 62f618e2-ccd7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679946098; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zXrYZq0YbjQfrHz+D24bJPE28LLfa/PMxOmz2kUZMhI=; b=ctJbWgX1qxk3abg3PZsD1sPghlIXUnMqBAigEjSdWNbBttBzjZj3iIxr PXhf5RLym/mtS3qTCXAD8sipb2h7WBDFFYXMh4h754XTiqS3Sh+/8wDno 7ygldHb2najrY/Nt9Al3QhwvUROdVu8JKXk7j6uzpMcs2XzPhrd2apW8Z A=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 103115614 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:pgESI6A8heWN5RVW/1Pjw5YqxClBgxIJ4kV8jS/XYbTApD0ngTRRz WoeDz2Eb/yJZzD3LtlwPoy+oxtQucLWy4RmQQY4rX1jcSlH+J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iBIKoaSvp037Eqv3oBLyC9E/b5qy nKpp8mPHDP6Qr5NEtQ/OxoW5PwOE80l6QFmbX5VI3KNGaJhILBFvAY0WKI+UyFJ8SRzJ876Y 5QN4VFJZnXK3MSt6rHCQ+DeeoI8Z283Jrtr8H44FdCcTpDVoFHyENCJjvzKDwUeCB2QZU4EZ aH5tlKvVObFEg/ZNigG38AU/PiirTw5fDbXSI= X-IronPort-AV: E=Sophos;i="5.98,295,1673931600"; d="scan'208";a="103115614" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Sergey Dyasli Subject: [PATCH 4/5] x86/ucode: Cache results in microcode_scan_module() Date: Mon, 27 Mar 2023 20:41:25 +0100 Message-ID: <20230327194126.3573997-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327194126.3573997-1-andrew.cooper3@citrix.com> References: <20230327194126.3573997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1679946137608100005 When microcode_scan_module() is used, it's used twice. The caching of the bootstrap_map() pointer in ucode_blob.data is buggy for multiple reasons and is going to be removed. Right now, the boot flow depends on the second pass over bootstrap_map()/find_cpio_data() altering ucode_blob.data to use the direct= map alias of the CPIO module, where previously it caches the early boostrap mapping. If the scan is successful, it will be successful the second time too, but there's no point repeating the work. Cache the module index, offset and si= ze to short circuit things the second time around. While rearranging this, reduce the scope of the internals of the loop, changing the type of _blob_start to void and droping the dead stores into c= d. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Sergey Dyasli --- xen/arch/x86/cpu/microcode/core.c | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 4d2a896fe78d..7d32bc13db6f 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -152,14 +152,30 @@ void __init microcode_scan_module( unsigned long *module_map, const multiboot_info_t *mbi) { + static __initdata struct { /* Cached details of a previous successful = scan. */ + unsigned long offset; /* Offset from the start of the CPIO archiv= e. */ + unsigned long size; /* Size of the CPIO file. */ + unsigned int mod_idx; /* Which multiboot module the CPIO archive = is. */ + } scan; + module_t *mod =3D (module_t *)__va(mbi->mods_addr); - uint64_t *_blob_start; - unsigned long _blob_size; - struct cpio_data cd; const char *p =3D NULL; int i; =20 ucode_blob.size =3D 0; + + if ( scan.mod_idx ) /* Previous scan was successful. */ + { + void *map =3D bootstrap_map(&mod[scan.mod_idx]); + + if ( !map ) + return; + + ucode_blob.size =3D scan.size; + ucode_blob.data =3D map + scan.offset; + return; + } + if ( !ucode_scan ) return; =20 @@ -175,6 +191,10 @@ void __init microcode_scan_module( */ for ( i =3D 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) { + void *_blob_start; + unsigned long _blob_size; + struct cpio_data cd; + if ( !test_bit(i, module_map) ) continue; =20 @@ -186,15 +206,19 @@ void __init microcode_scan_module( i, _blob_size); continue; } - cd.data =3D NULL; - cd.size =3D 0; + cd =3D find_cpio_data(p, _blob_start, _blob_size); if ( cd.data ) { + scan.mod_idx =3D i; + scan.offset =3D cd.data - _blob_start; + scan.size =3D cd.size; + ucode_blob.size =3D cd.size; ucode_blob.data =3D cd.data; break; } + bootstrap_map(NULL); } } --=20 2.30.2 From nobody Sun Apr 28 21:19:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1679946135; cv=none; d=zohomail.com; s=zohoarc; b=cvaXcyuIG2M9JPmC0QoIhNh7b9hvVeqrOPkmxSEUut0UlU+0c3LjtEBwyOse/W+G41DVKhx9m+vzdpPoqeeDjkvu7XQLmXnALuRG9teBTwOD5Tt/jzx9E/hOPfslIWcnllWp5vkweQ9lW/0N8olH0lpDGJkOOIp74zw/AK4RDMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679946135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HIF0V+Nf4Cn5y6BBvnYHPBUSmUZ1cYs+IdGK5sSm2Lg=; b=al0EDcndqZohdTO7A06P5MkUgImZ8F1ibubkImqwz9rP8vAMBlJMLa+HevASMmnovSvo0Y62mLMFNUzQVpaxTJAQIPkBuWNZJwMi72NDRPwokJ8HN1pBIFZ+CfLU7B2J8Ak15wg53GSDC8C7XMpF6HZELuX5zNJq62i0VIHEWYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1679946135051140.63393495131322; Mon, 27 Mar 2023 12:42:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.515456.798360 (Exim 4.92) (envelope-from ) id 1pgsiv-0003H5-Pc; Mon, 27 Mar 2023 19:41:45 +0000 Received: by outflank-mailman (output) from mailman id 515456.798360; Mon, 27 Mar 2023 19:41:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiv-0003Gg-JF; Mon, 27 Mar 2023 19:41:45 +0000 Received: by outflank-mailman (input) for mailman id 515456; Mon, 27 Mar 2023 19:41:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pgsiu-0002j7-Dp for xen-devel@lists.xenproject.org; Mon, 27 Mar 2023 19:41:44 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 65bbf68f-ccd7-11ed-b464-930f4c7d94ae; Mon, 27 Mar 2023 21:41:41 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 65bbf68f-ccd7-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679946101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ycSPzPhEBhMtNfmYAIo5IKgNH3bA3cjpPAQnh0Y1CjM=; b=Za7FuoYXny5HaZx7CwZZwwnK5L7JmrWwz1JRXckx6o+JPc2Jaikx6cPT mYtzcXdXTPNkBSGYrTujTffDV1Eim2cjp1IVdFR8u0uo2nrHHowzRRoIO fXLeSZINi89oyyFLZtNhiLbfEqv4DHIgESpgDnxS4Jd44/BYgii1T3WKR 0=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 103115617 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-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sPvsTPP9r 4wOaKNnCnx3DIXDX8Ug2ddKdAtQcSFrVMmeRg4+XrfrHzeK0VoJU5f5qY7NsaQ890iJvo8kJ k2AZ3I= IronPort-HdrOrdr: A9a23:kV1XHKgXmofnPIpRnl/2v2WnuHBQXh0ji2hC6mlwRA09TySZ// re+sjztCWVtN91YhodcL+7WZVoLUmskKKdgrNhRItKPjOWwFdARbsKheSN/9SJIVyEygc379 YFT0ERMqyWMXFKyevBzU2fNf1I+rW6GaaT79v2/jNWYTsvQYdGwCdWNj2yL21RY019KadRLu v+2uN34zWhfHgMbte2HBA+MtTrrcHQiZTjbQUnKnccmWuzsQ8= X-IronPort-AV: E=Sophos;i="5.98,295,1673931600"; d="scan'208";a="103115617" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Sergey Dyasli Subject: [PATCH 5/5] x86/ucode: Drop ucode_mod and ucode_blob Date: Mon, 27 Mar 2023 20:41:26 +0100 Message-ID: <20230327194126.3573997-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327194126.3573997-1-andrew.cooper3@citrix.com> References: <20230327194126.3573997-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1679946135787100003 These both incorrectly cache bootstrap_map()'d pointers across returns back= to __start_xen(). This is never valid, and such pointers may fault, or point = to something unrelated. With the refactoring work in the previous patches, they're clearly now just non-standard function return parameters. Rename struct ucode_mod_blob to just struct blob for breviy and because there's nothing really ucode-specific about it. Introduce find_microcode_blob(), to replace microcode_grab_module(), and rework microcode_scan_module() so they both return a pointer/size tuple, and don't cache their return values in global state. This allows us to remove the microcode_init() initcall, the comments of whi= ch gives the false impression that either of the cached pointers are safe to u= se. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Sergey Dyasli --- xen/arch/x86/cpu/microcode/core.c | 154 +++++++++++++----------------- 1 file changed, 68 insertions(+), 86 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 7d32bc13db6f..0ae628ba99d4 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -55,7 +55,6 @@ */ #define MICROCODE_UPDATE_TIMEOUT_US 1000000 =20 -static module_t __initdata ucode_mod; static signed int __initdata ucode_mod_idx; static bool_t __initdata ucode_mod_forced; static unsigned int nr_cores; @@ -76,18 +75,11 @@ static enum { LOADING_EXIT, } loading_state; =20 -/* - * If we scan the initramfs.cpio for the early microcode code - * and find it, then 'ucode_blob' will contain the pointer - * and the size of said blob. It is allocated from Xen's heap - * memory. - */ -struct ucode_mod_blob { +struct blob { const void *data; size_t size; }; =20 -static struct ucode_mod_blob __initdata ucode_blob; /* * By default we will NOT parse the multiboot modules to see if there is * cpio image with the microcode images. @@ -148,7 +140,15 @@ static int __init cf_check parse_ucode(const char *s) } custom_param("ucode", parse_ucode); =20 -void __init microcode_scan_module( +/* + * Scan all unclaimed modules, looking for a decompressed CPIO archive + * containing a microcode file according to the Linux early microcode API. + * + * Always caches the results, positive or negative. + * + * Returns a ptr/size tupe. Either NULL/0, or a bootstrap_map()'d region. + */ +static struct blob __init microcode_scan_module( unsigned long *module_map, const multiboot_info_t *mbi) { @@ -159,32 +159,35 @@ void __init microcode_scan_module( } scan; =20 module_t *mod =3D (module_t *)__va(mbi->mods_addr); + struct blob blob =3D {}; const char *p =3D NULL; int i; =20 - ucode_blob.size =3D 0; - if ( scan.mod_idx ) /* Previous scan was successful. */ { void *map =3D bootstrap_map(&mod[scan.mod_idx]); =20 if ( !map ) - return; + return blob; + + blob.size =3D scan.size; + blob.data =3D map + scan.offset; =20 - ucode_blob.size =3D scan.size; - ucode_blob.data =3D map + scan.offset; - return; + return blob; } =20 if ( !ucode_scan ) - return; + return blob; + + /* Only scan once, whatever the outcome. */ + ucode_scan =3D false; =20 if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD ) p =3D "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL ) p =3D "kernel/x86/microcode/GenuineIntel.bin"; else - return; + return blob; =20 /* * Try all modules and see whichever could be the microcode blob. @@ -214,30 +217,15 @@ void __init microcode_scan_module( scan.offset =3D cd.data - _blob_start; scan.size =3D cd.size; =20 - ucode_blob.size =3D cd.size; - ucode_blob.data =3D cd.data; + blob.size =3D cd.size; + blob.data =3D cd.data; break; } =20 bootstrap_map(NULL); } -} - -static void __init microcode_grab_module( - unsigned long *module_map, - const multiboot_info_t *mbi) -{ - module_t *mod =3D (module_t *)__va(mbi->mods_addr); =20 - if ( ucode_mod_idx < 0 ) - ucode_mod_idx +=3D mbi->mods_count; - if ( ucode_mod_idx <=3D 0 || ucode_mod_idx >=3D mbi->mods_count || - !__test_and_clear_bit(ucode_mod_idx, module_map) ) - goto scan; - ucode_mod =3D mod[ucode_mod_idx]; -scan: - if ( ucode_scan ) - microcode_scan_module(module_map, mbi); + return blob; } =20 static struct microcode_ops __ro_after_init ucode_ops; @@ -746,28 +734,6 @@ int microcode_update(XEN_GUEST_HANDLE(const_void) buf,= unsigned long len) microcode_update_helper, buffer); } =20 -static int __init cf_check microcode_init(void) -{ - /* - * At this point, all CPUs should have updated their microcode - * via the early_microcode_* paths so free the microcode blob. - */ - if ( ucode_blob.size ) - { - bootstrap_map(NULL); - ucode_blob.size =3D 0; - ucode_blob.data =3D NULL; - } - else if ( ucode_mod.mod_end ) - { - bootstrap_map(NULL); - ucode_mod.mod_end =3D 0; - } - - return 0; -} -__initcall(microcode_init); - /* Load a cached update to current cpu */ int microcode_update_one(void) { @@ -779,26 +745,53 @@ int microcode_update_one(void) return microcode_update_cpu(NULL); } =20 +/* + * Find microcode within the boot modules provided. + * + * This is called twice on boot, once very early to find the BSP microcode, + * and a second time in order to initalise the cache once we've set up the + * heap to use. + * + * Returns a ptr/size tuple, either NULL/0 or a bootstrap_map()'d region. + */ +static struct blob __init find_microcode_blob( + unsigned long *module_map, const multiboot_info_t *mbi) +{ + struct blob blob =3D {}; + + if ( ucode_mod_idx !=3D 0 ) + { + module_t *mod =3D __va(mbi->mods_addr); + + /* Adjust to support negative backreferences. */ + if ( ucode_mod_idx < 0 ) + ucode_mod_idx +=3D mbi->mods_count; + + if ( ucode_mod_idx > 0 && + ucode_mod_idx < mbi->mods_count && + __test_and_clear_bit(ucode_mod_idx, module_map) ) + { + mod +=3D ucode_mod_idx; + + blob.data =3D bootstrap_map(mod); + blob.size =3D mod->mod_end; + + return blob; + } + + /* Still not valid. Ignore it next time around. */ + ucode_mod_idx =3D 0; + } + + return microcode_scan_module(module_map, mbi); +} + int __init microcode_init_cache(unsigned long *module_map, const struct multiboot_info *mbi) { int rc =3D 0; struct microcode_patch *patch; - struct ucode_mod_blob blob =3D {}; - - if ( ucode_scan ) - /* Need to rescan the modules because they might have been relocat= ed */ - microcode_scan_module(module_map, mbi); - - if ( ucode_mod.mod_end ) - { - blob.data =3D bootstrap_map(&ucode_mod); - blob.size =3D ucode_mod.mod_end; - } - else if ( ucode_blob.size ) - { - blob =3D ucode_blob; - } + struct blob blob =3D find_microcode_blob(module_map, mbi); =20 if ( !blob.data ) return 0; @@ -833,7 +826,7 @@ int __init early_microcode_init(unsigned long *module_m= ap, { const struct cpuinfo_x86 *c =3D &boot_cpu_data; struct microcode_patch *patch; - struct ucode_mod_blob blob =3D {}; + struct blob blob =3D {}; int rc =3D 0; =20 switch ( c->x86_vendor ) @@ -855,20 +848,9 @@ int __init early_microcode_init(unsigned long *module_= map, return -ENODEV; } =20 - microcode_grab_module(module_map, mbi); - ucode_ops.collect_cpu_info(); =20 - if ( ucode_blob.data ) - { - blob =3D ucode_blob; - } - else if ( ucode_mod.mod_end ) - { - blob.data =3D bootstrap_map(&ucode_mod); - blob.size =3D ucode_mod.mod_end; - } - + blob =3D find_microcode_blob(module_map, mbi); if ( !blob.data ) return 0; =20 --=20 2.30.2