From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D78EDC7619A for ; Wed, 12 Apr 2023 18:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjDLSpV (ORCPT ); Wed, 12 Apr 2023 14:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjDLSpM (ORCPT ); Wed, 12 Apr 2023 14:45:12 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F45740F2 for ; Wed, 12 Apr 2023 11:45:11 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1842e8a8825so14801824fac.13 for ; Wed, 12 Apr 2023 11:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325110; x=1683917110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RI1QKnyB9mb6UAnZmBnXQzU2ONFlsltTDGtKyyUD28o=; b=OYyMovplh1Vk8gmeTpVI2bCmkYXiwH5ziby48r9n0AvhtcqaTm8fO/ndGn4OpgUHDb 6sTNMGcYtsDrpzbMk+juJap0e2YXhwAdgK30G8fhDrq+Ua+541vkhpWMvJHXn7Gq+oC+ rGjlZIy1jH9isHXk2Fv/ojCUXjV5VDmUNwGHAUpupqPOCMfGdAiJaYGOpYmHFQzskV6d s91+npBXcNNXBiEscdIykjowHr4UHgXPLO0iXt1CbtMx65AsAluR+ebGxIQ41ntIvd7S RywhwBrf2n8a0QgD3NKT7NF4U/MzMB9oViG0bjhmJveAiY6lFhFLMl3bNKeLqi1BACJk shDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325110; x=1683917110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RI1QKnyB9mb6UAnZmBnXQzU2ONFlsltTDGtKyyUD28o=; b=MT8dJvcmpthqEIzN0Godw9KEBhcAQWkgmavPz3PQcPXuzxabTysoMbx0/8gAs63xej yP/6qM+AMMSYt2ENQSmjZi9vLrigMHAUBxRBvX35gMM7Iw8o0ejlZtKniR3p4uiG9Dsi qRRhYApHZ1vRHPD/YG13yROJPj31ndn7aHF6plnl9W2e2k0GFdc+U5tsa4v/GYQre4v5 FCVvGrLbbbG0YTJXnPyP/pbtIV52YTevy/n5fWZY3Fz9rhILshiunDsw7DeJK0SLYbRf QhAmQoJr00oFc5YdRPcjSj46fB6uQa93KBvT2AjruwbG9Xs4gSKk5DTCe+owWWHGOAfm 2FLw== X-Gm-Message-State: AAQBX9eRO/98huTdnN2f/zAtAQYd89DzdaGqo1eBLyRv2GfVMJMTtlgN uQPYCzQs556VysY8VlMHSIZaT0DrcA== X-Google-Smtp-Source: AKy350YX8yN8Syqj1ygwYeBSrMgOAmJalJlrS06q44scCicfTaqUNcvX+RlfVNhHq8rFZRD0VYisPg== X-Received: by 2002:a05:6870:40cc:b0:177:b9d3:c028 with SMTP id l12-20020a05687040cc00b00177b9d3c028mr7724458oal.12.1681325110388; Wed, 12 Apr 2023 11:45:10 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:10 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 1/6] x86/boot: Move sanitize_boot_params() Date: Wed, 12 Apr 2023 14:44:57 -0400 Message-Id: <20230412184502.145289-2-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" sanitize_boot_params() contains a static table that would need to be addressed in a PIC manner if it were executed early in the boot process while using the identity-mapped page tables. Separate it from copy_bootdata(). Signed-off-by: Brian Gerst --- arch/x86/kernel/head64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 387e4b12e823..4a3b195c9002 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -455,7 +455,6 @@ static void __init copy_bootdata(char *real_mode_data) sme_map_bootdata(real_mode_data); =20 memcpy(&boot_params, real_mode_data, sizeof(boot_params)); - sanitize_boot_params(&boot_params); cmd_line_ptr =3D get_cmd_line_ptr(); if (cmd_line_ptr) { command_line =3D __va(cmd_line_ptr); @@ -543,6 +542,8 @@ void __init x86_64_start_reservations(char *real_mode_d= ata) if (!boot_params.hdr.version) copy_bootdata(__va(real_mode_data)); =20 + sanitize_boot_params(&boot_params); + x86_early_init_platform_quirks(); =20 switch (boot_params.hdr.hardware_subarch) { --=20 2.39.2 From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79896C7619A for ; Wed, 12 Apr 2023 18:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbjDLSpY (ORCPT ); Wed, 12 Apr 2023 14:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjDLSpQ (ORCPT ); Wed, 12 Apr 2023 14:45:16 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E9E340F9 for ; Wed, 12 Apr 2023 11:45:12 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id q33-20020a056830442100b006a419d3fd20so1535945otv.7 for ; Wed, 12 Apr 2023 11:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325111; x=1683917111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gohAHfVouxgH+hJvQeBGsiMrbLKAn/aPyvmRUBO2xEM=; b=YW6v+uz3qLfkDmYU4CXaszKD4ilipn8i1QxYvhvAwxqWKFqzj7dFKLr203+A9asdY9 xjK0d/O6ztAML6al9g0iq8HgJAAsA5FmEqjokrczDgEanMZjS0B3rfWuahg/KlbImutI SEUvvyhmi5Xiv+Olkf2HYaHBd7G9WIUGFkSA4gsr7FXxtXDFjFXU08m1NXTodPKAjQwt QMevu8h3Bclig7Tr0zibaVAv8CKgdyzVITy2AP+xO3w9CQvHmME3J1aYyUL86vjqmt9H 4HNytispBkPMOieHPnA2fM+Z194+6c01Wm5TJK0rf3VqpWPKfrCnAPcvMDIRrYEXzzs5 XXbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325111; x=1683917111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gohAHfVouxgH+hJvQeBGsiMrbLKAn/aPyvmRUBO2xEM=; b=WO1Sgsi7ribYBD4NMcwAiM1gwrHOYaQN+M4ZNRRetvHgYM/f9edwYfjvIpxEBQ3Zpa r842cTgTYwcB+iUDZw7EhqOSLohKYG56/OBu6jDPKr9cF39QsuzxRb5xPFmuZNbzo648 UOMvnNAEAbquzhR71fTsXrJ+6tpmHX4sqYOC2nxMufpJ7opc0qPSzBUYmb4K0XuR4orf XvDBUHrD5J1F88N+fxSlEUX+pLAoiDSmEo0viPk51mPQARXfDlVEwaqSK0KYH0wtNzRr B6VxaN3ePfKP3Lcj3siK2pozDUzPy11eZVB+pjVyMifpTVqaQ3iWdvkp7JilKTID6FtV COUg== X-Gm-Message-State: AAQBX9erYVkhD2wMaKfJhIbzYBGVtIEULOm5qbNfNUtHYp7IIdgS+/CO bz5oBzoVuxNWHDsMui5C0Qo0z7iAsw== X-Google-Smtp-Source: AKy350YXw/BZt/KMMSlZbP+KGx81bHHOzcPZWxyKCSBi/ctfiWFTzfz9f6CbDPKvcIpKh7e5nT/MZw== X-Received: by 2002:a9d:7a8f:0:b0:6a4:2e4c:de05 with SMTP id l15-20020a9d7a8f000000b006a42e4cde05mr224447otn.1.1681325111484; Wed, 12 Apr 2023 11:45:11 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:11 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 2/6] x86/boot: Remove extra call to copy_bootdata() Date: Wed, 12 Apr 2023 14:44:58 -0400 Message-Id: <20230412184502.145289-3-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The call to copy_bootdata() in x86_64_start_reservations() is only applicable to Xen, since native has already call it. Xen on the other hand, has already filled in boot_params and just passes its address in, so the copy ends up being a no-op and can be removed. Signed-off-by: Brian Gerst --- arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/head64.c | 8 ++------ arch/x86/xen/enlighten_pv.c | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index f37cbff7354c..fd409b7dda74 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -129,7 +129,7 @@ asmlinkage void __init i386_start_kernel(void); =20 #else asmlinkage void __init x86_64_start_kernel(char *real_mode); -asmlinkage void __init x86_64_start_reservations(char *real_mode_data); +asmlinkage void __init x86_64_start_reservations(void); =20 #endif /* __i386__ */ #endif /* _SETUP */ diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 4a3b195c9002..6e0f53a66678 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -533,15 +533,11 @@ asmlinkage __visible void __init x86_64_start_kernel(= char * real_mode_data) /* set init_top_pgt kernel high mapping*/ init_top_pgt[511] =3D early_top_pgt[511]; =20 - x86_64_start_reservations(real_mode_data); + x86_64_start_reservations(); } =20 -void __init x86_64_start_reservations(char *real_mode_data) +void __init x86_64_start_reservations(void) { - /* version is always not zero if it is copied */ - if (!boot_params.hdr.version) - copy_bootdata(__va(real_mode_data)); - sanitize_boot_params(&boot_params); =20 x86_early_init_platform_quirks(); diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 5a034a994682..a4db5c28af57 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1430,7 +1430,7 @@ asmlinkage __visible void __init xen_start_kernel(str= uct start_info *si) =20 /* Start the world */ cr4_init_shadow(); /* 32b kernel does this in i386_start_kernel() */ - x86_64_start_reservations((char *)__pa_symbol(&boot_params)); + x86_64_start_reservations(); } =20 static int xen_cpu_up_prepare_pv(unsigned int cpu) --=20 2.39.2 From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6B52C7619A for ; Wed, 12 Apr 2023 18:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229541AbjDLSp1 (ORCPT ); Wed, 12 Apr 2023 14:45:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjDLSpR (ORCPT ); Wed, 12 Apr 2023 14:45:17 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B946188 for ; Wed, 12 Apr 2023 11:45:13 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id bm45so2703794oib.4 for ; Wed, 12 Apr 2023 11:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325112; x=1683917112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PRQeRpa+j7z3VGaqIAViY07xGVHNoffmRva1Ftuz2yI=; b=M+LxblnK1w1qQ2r8lojLBxu14Yd2MIrwnR53z51Tt9mgYjQBLuhPe/wJe0bQrPC3Au 0Viu5nBqadDJwBJIWVCxHREKg3rAiXZvJDrQzEevjg0zPme3Zq+xyM6CF59cJm1htHm9 8IhlTGbzlTu3vO9Vw1BARy9Zf+/DU2ImMBCDAI6YaL6I9k7jYaaEwC3n9XiSWK/vXpGi 8XrQLlC9EU4n+JbN+36vb4CC2OJDSpIj78FaHxZFxEypwFkHuIVtNyW9bFM55H3746pc C9UqPNRy/xhqEUJ2F/Xk59HnqIjV4APPQATAIFs5FBFayCev0TxJZTDN6ftHOx2/O+C+ 8qDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325112; x=1683917112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PRQeRpa+j7z3VGaqIAViY07xGVHNoffmRva1Ftuz2yI=; b=WlTJbOyaftJp8F5Jv/b40bjIxpIioWIwBbj9F7ClnovqeBQ+vT6UxccsOB2oi3Efsm /ad/h1BmK1Dy9MNG+IupK2CIymxLgX79fkRZeQIvSZG8Az/l7mOJwdfJ8qI3qF8C/Dqz FSlg4rIk2C0C9OPT/vRyj5ISZaaUfU3ehnysPci9wvWnvm2ylmEfApf+x0BXYHWbRebP d4oJpKJVdeA087dhSDzwSjvdAbGafpp6ST14maN9vndmEAc598zEm9NRmcuiODxi0gJx opcbqvU2Prxg8ro5362JR4ohPl4XiKjDc4oCrs9Ud0yhs4qxn/rpMVFpkqmxBO1pnnxr NHnw== X-Gm-Message-State: AAQBX9cqfYKTEIoz7cNKWA6H8f7SUxsihIJY+JJ+av3q7/qw3aw+DLEF f4Kh4cHuwtWdPtkOZa9RPezQ8kZj3Q== X-Google-Smtp-Source: AKy350aXOl5QGXWROTPG7eWOsFz3wZvizVTKy9Z0zZW5CwTsjwM7f5sDhasT1u5WsXwuzToDvKq6NA== X-Received: by 2002:a05:6808:2a02:b0:389:1c19:f684 with SMTP id ez2-20020a0568082a0200b003891c19f684mr1436523oib.23.1681325112348; Wed, 12 Apr 2023 11:45:12 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:12 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 3/6] x86/boot: Clean up get_cmd_line_ptr() Date: Wed, 12 Apr 2023 14:44:59 -0400 Message-Id: <20230412184502.145289-4-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Pass in the boot_params pointer, and use the appropriate return type. Signed-off-by: Brian Gerst --- arch/x86/kernel/head64.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 6e0f53a66678..08ea521041bf 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -434,19 +434,18 @@ void __init clear_bss(void) (unsigned long) __brk_limit - (unsigned long) __brk_base); } =20 -static unsigned long get_cmd_line_ptr(void) +static char *get_cmd_line_ptr(struct boot_params *bp) { - unsigned long cmd_line_ptr =3D boot_params.hdr.cmd_line_ptr; + unsigned long cmd_line_ptr =3D bp->hdr.cmd_line_ptr; =20 - cmd_line_ptr |=3D (u64)boot_params.ext_cmd_line_ptr << 32; + cmd_line_ptr |=3D (u64)bp->ext_cmd_line_ptr << 32; =20 - return cmd_line_ptr; + return (char *)cmd_line_ptr; } =20 static void __init copy_bootdata(char *real_mode_data) { - char * command_line; - unsigned long cmd_line_ptr; + char *cmd_line_ptr; =20 /* * If SME is active, this will create decrypted mappings of the @@ -455,11 +454,9 @@ static void __init copy_bootdata(char *real_mode_data) sme_map_bootdata(real_mode_data); =20 memcpy(&boot_params, real_mode_data, sizeof(boot_params)); - cmd_line_ptr =3D get_cmd_line_ptr(); - if (cmd_line_ptr) { - command_line =3D __va(cmd_line_ptr); - memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); - } + cmd_line_ptr =3D get_cmd_line_ptr(&boot_params); + if (cmd_line_ptr) + memcpy(boot_command_line, __va(cmd_line_ptr), COMMAND_LINE_SIZE); =20 /* * The old boot data is no longer needed and won't be reserved, --=20 2.39.2 From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A87DC7619A for ; Wed, 12 Apr 2023 18:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjDLSpb (ORCPT ); Wed, 12 Apr 2023 14:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjDLSpS (ORCPT ); Wed, 12 Apr 2023 14:45:18 -0400 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3961865AA for ; Wed, 12 Apr 2023 11:45:14 -0700 (PDT) Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1878a0bf68fso324203fac.7 for ; Wed, 12 Apr 2023 11:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325113; x=1683917113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kLfUCOkvkjyXKASrYl3qRN6UMeyF56v/rVBV6eIg7OU=; b=LXig5OVv0EMvil57sXSWTi76UfLZM8wn4OvA0mUUP/vvbDAUhBcNkNdWeurhAjohvM E2dbpblNPTfzJ6dpDqwo5QxROXDPTbmvGSGbP+Z4ViCRYMLdSTTsecKHqacyy/9nkDnL b77Jv6NAA4/7OOi++dLGOY/TUiEsGjaz05RbPU0N+JB0bk4n+PDgrEdIgbf1ulo7y4o1 2XKSZc/QsGw9ERkVML8ci/wFpG9NcyuSRZaTr13GcWkn6gwX7r1epZqfro81GZIWeXdE BfysPNlu1gSuszBwxA/3C7duFWmHpOPbqm+owmpLTVdvUJy9CN3YqA0t5IrIHLPuOv5x ZpAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325113; x=1683917113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kLfUCOkvkjyXKASrYl3qRN6UMeyF56v/rVBV6eIg7OU=; b=fdslBnOps2OqaAWkkc/n5sSy0XM6SERr8/aVZe/Zm5TgHnjW3aZiGl0McwgV3M+b/b a5qbU3ACC7jv4dLG8Dt0x8jTDPuDu9Viuumkho+d4MwX0WVWvEEWuLdO9oSYTZZBmQRC 7+KylErJEagAmOIV2EoWj+2DdADsV1zu3pRMoLbKI5wKzvHbymXft6pzy4RQekDbXPqI Bt+E1ATk2qC+amoXkNDWD3ghOCnh6nGqMMLdX1TOrV7siOvzlhPX0NQTtXxwYLj1RZfU 6/1o5fPZLUElV5djuqxonxafn2iUmsgkQZi55+U0KZoYnGbw0ziJYPWWbXY2K5Gogdc8 6Q7Q== X-Gm-Message-State: AAQBX9dlfHtw21cb2c+8rpvoozZ4MCUPjaPDHuEqwvM7XqKLvUHaOAww flso4bjerGcDBjJ7+UvUt+mp0CA5Yw== X-Google-Smtp-Source: AKy350b1DWOuoEhyCT/n3PsSepFtS53HZr1WIVAz6A4p6EVfGFc9QX8S0VATs2m6mFgswiakpXtoww== X-Received: by 2002:a05:6870:6488:b0:184:442a:96d2 with SMTP id cz8-20020a056870648800b00184442a96d2mr4539287oab.54.1681325113282; Wed, 12 Apr 2023 11:45:13 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:13 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 4/6] x86/boot: Move copy_bootdata() to very early boot. Date: Wed, 12 Apr 2023 14:45:00 -0400 Message-Id: <20230412184502.145289-5-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Copy the boot data very early in the boot process. Since at this point the kernel is running on identity-mapped pagetables, pointers to global data need to be adjusted. By copying the data early before memory encryption is enabled, it is no longer necessary to remap the real mode data as unencrypted. Signed-off-by: Brian Gerst --- arch/x86/include/asm/setup.h | 5 ++- arch/x86/kernel/head64.c | 29 +++++------------ arch/x86/kernel/head_64.S | 20 ++++-------- arch/x86/kernel/setup.c | 2 +- arch/x86/mm/mem_encrypt_amd.c | 61 ----------------------------------- 5 files changed, 19 insertions(+), 98 deletions(-) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index fd409b7dda74..47eac5d877a8 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -128,7 +128,10 @@ void clear_bss(void); asmlinkage void __init i386_start_kernel(void); =20 #else -asmlinkage void __init x86_64_start_kernel(char *real_mode); + +asmlinkage void __init copy_bootdata(unsigned long physbase, + struct boot_params *real_mode_data); +asmlinkage void __init x86_64_start_kernel(void); asmlinkage void __init x86_64_start_reservations(void); =20 #endif /* __i386__ */ diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 08ea521041bf..9be8ce41d021 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -443,31 +443,20 @@ static char *get_cmd_line_ptr(struct boot_params *bp) return (char *)cmd_line_ptr; } =20 -static void __init copy_bootdata(char *real_mode_data) +asmlinkage __visible void __init copy_bootdata(unsigned long physbase, + struct boot_params *real_mode_data) { char *cmd_line_ptr; + struct boot_params *bp =3D fixup_pointer(&boot_params, physbase); + char *command_line =3D fixup_pointer(&boot_command_line, physbase); =20 - /* - * If SME is active, this will create decrypted mappings of the - * boot data in advance of the copy operations. - */ - sme_map_bootdata(real_mode_data); - - memcpy(&boot_params, real_mode_data, sizeof(boot_params)); - cmd_line_ptr =3D get_cmd_line_ptr(&boot_params); + memcpy(bp, real_mode_data, sizeof(boot_params)); + cmd_line_ptr =3D get_cmd_line_ptr(bp); if (cmd_line_ptr) - memcpy(boot_command_line, __va(cmd_line_ptr), COMMAND_LINE_SIZE); - - /* - * The old boot data is no longer needed and won't be reserved, - * freeing up that memory for use by the system. If SME is active, - * we need to remove the mappings that were created so that the - * memory doesn't remain mapped as decrypted. - */ - sme_unmap_bootdata(real_mode_data); + memcpy(command_line, cmd_line_ptr, COMMAND_LINE_SIZE); } =20 -asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data) +asmlinkage __visible void __init x86_64_start_kernel(void) { /* * Build-time sanity checks on the kernel image and module @@ -520,8 +509,6 @@ asmlinkage __visible void __init x86_64_start_kernel(ch= ar * real_mode_data) /* Needed before cc_platform_has() can be used for TDX */ tdx_early_init(); =20 - copy_bootdata(__va(real_mode_data)); - /* * Load microcode early on BSP. */ diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index a5df3e994f04..83fb0dc97ba5 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -64,8 +64,6 @@ SYM_CODE_START_NOALIGN(startup_64) /* Set up the stack for verify_cpu() */ leaq (__end_init_task - PTREGS_SIZE)(%rip), %rsp =20 - leaq _text(%rip), %rdi - /* Setup GSBASE to allow stack canary access for C code */ movl $MSR_GS_BASE, %ecx leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx @@ -73,6 +71,12 @@ SYM_CODE_START_NOALIGN(startup_64) shrq $32, %rdx wrmsr =20 + leaq _text(%rip), %rdi + pushq %rsi + call copy_bootdata + popq %rsi + + leaq _text(%rip), %rdi pushq %rsi call startup_64_setup_env popq %rsi @@ -125,8 +129,6 @@ SYM_CODE_START(secondary_startup_64) * At this point the CPU runs in 64bit mode CS.L =3D 1 CS.D =3D 0, * and someone has loaded a mapped page table. * - * %rsi holds a physical pointer to real_mode_data. - * * We come here either from startup_64 (using physical addresses) * or from trampoline.S (using virtual addresses). * @@ -197,13 +199,9 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_= GLOBAL) * hypervisor could lie about the C-bit position to perform a ROP * attack on the guest by writing to the unencrypted stack and wait for * the next RET instruction. - * %rsi carries pointer to realmode data and is callee-clobbered. Save - * and restore it. */ - pushq %rsi movq %rax, %rdi call sev_verify_cbit - popq %rsi =20 /* * Switch to new page-table @@ -294,9 +292,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_G= LOBAL) wrmsr =20 /* Setup and Load IDT */ - pushq %rsi call early_setup_idt - popq %rsi =20 /* Check if nx is implemented */ movl $0x80000001, %eax @@ -332,10 +328,6 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_= GLOBAL) pushq $0 popfq =20 - /* rsi is pointer to real mode structure with interesting info. - pass it to C */ - movq %rsi, %rdi - .Ljump_to_C_code: /* * Jump to run C code and to be on a real kernel address. diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 16babff771bd..256262cb29c0 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -74,7 +74,7 @@ RESERVE_BRK(dmi_alloc, 65536); unsigned long _brk_start =3D (unsigned long)__brk_base; unsigned long _brk_end =3D (unsigned long)__brk_base; =20 -struct boot_params boot_params; +struct boot_params boot_params __section(".data"); =20 /* * These are the four main kernel memory regions, we put them into diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index e0b51c09109f..120e9c09c04b 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -154,67 +154,6 @@ void __init sme_early_decrypt(resource_size_t paddr, u= nsigned long size) __sme_early_enc_dec(paddr, size, false); } =20 -static void __init __sme_early_map_unmap_mem(void *vaddr, unsigned long si= ze, - bool map) -{ - unsigned long paddr =3D (unsigned long)vaddr - __PAGE_OFFSET; - pmdval_t pmd_flags, pmd; - - /* Use early_pmd_flags but remove the encryption mask */ - pmd_flags =3D __sme_clr(early_pmd_flags); - - do { - pmd =3D map ? (paddr & PMD_MASK) + pmd_flags : 0; - __early_make_pgtable((unsigned long)vaddr, pmd); - - vaddr +=3D PMD_SIZE; - paddr +=3D PMD_SIZE; - size =3D (size <=3D PMD_SIZE) ? 0 : size - PMD_SIZE; - } while (size); - - flush_tlb_local(); -} - -void __init sme_unmap_bootdata(char *real_mode_data) -{ - struct boot_params *boot_data; - unsigned long cmdline_paddr; - - if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) - return; - - /* Get the command line address before unmapping the real_mode_data */ - boot_data =3D (struct boot_params *)real_mode_data; - cmdline_paddr =3D boot_data->hdr.cmd_line_ptr | ((u64)boot_data->ext_cmd_= line_ptr << 32); - - __sme_early_map_unmap_mem(real_mode_data, sizeof(boot_params), false); - - if (!cmdline_paddr) - return; - - __sme_early_map_unmap_mem(__va(cmdline_paddr), COMMAND_LINE_SIZE, false); -} - -void __init sme_map_bootdata(char *real_mode_data) -{ - struct boot_params *boot_data; - unsigned long cmdline_paddr; - - if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) - return; - - __sme_early_map_unmap_mem(real_mode_data, sizeof(boot_params), true); - - /* Get the command line address after mapping the real_mode_data */ - boot_data =3D (struct boot_params *)real_mode_data; - cmdline_paddr =3D boot_data->hdr.cmd_line_ptr | ((u64)boot_data->ext_cmd_= line_ptr << 32); - - if (!cmdline_paddr) - return; - - __sme_early_map_unmap_mem(__va(cmdline_paddr), COMMAND_LINE_SIZE, true); -} - void __init sev_setup_arch(void) { phys_addr_t total_mem =3D memblock_phys_mem_size(); --=20 2.39.2 From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 772B3C7619A for ; Wed, 12 Apr 2023 18:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbjDLSpd (ORCPT ); Wed, 12 Apr 2023 14:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbjDLSpS (ORCPT ); Wed, 12 Apr 2023 14:45:18 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0842B5B8D for ; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-1878a0bf68fso324251fac.7 for ; Wed, 12 Apr 2023 11:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325114; x=1683917114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y9jW8lTjmlnLP+VaTuDA/cPZo6I/NjUdF+u0UYf+p20=; b=ChDtRmpS13uPH3Dv861bG+B2sL8tWVRy7GRpQmfuTTZCZlMDYKwSR6qtBTeOI62nvy jbs85WVcDZ9235GtwFnK3iMZxxy41JM44CrQuti5ws0GgBPHWLXig18nviJyCCdZou5D lfzOPN84k2YI0JSqg+JLBX8gBxsrQxRVqxF5jE7opuA7F0guOlaNb6rIVpqBPt669JHx 7PCog0ZqwIAeih6+gKh4nS8hzwx5r3XNsNS+FiAUVJyKCPV1FAv7VCyuEtUKRH1qOed/ 7v2BS0rpVsjF+4QT3qNX0Eyn9rPckIgEcbHil1Mqu+a46qgg6hQpnmjEmeCbFVqRoua9 kZsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325114; x=1683917114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y9jW8lTjmlnLP+VaTuDA/cPZo6I/NjUdF+u0UYf+p20=; b=OZB3hg+96QCcjGBTEDjp6Hvgb738Z6jHvRo5jietZNpabl+5uzkZvWXcGCbqL+L249 GbM15CexMGZzY6YDV0aeq7x8VUJcb86EKWIxLCb0tlXccg9J8+7KNHjVDeyufu2NToV1 FGhI13KaPA7lhd7HV/u2kUIPYSbOP5qTratqKriK/k4IkBpQlnwZv1uog0sLyOvbraNu 3tGd+uWAhKnjer5mv+M44yTkefOdr8NY3pZh5Dw1KX1YnN0Sw1HzRK9H3pDVt4pfKEN5 ArlFgwRAdbOey1POotmX4pQR7GJ+AEdNQYEgC7W6XyoyqOHEHn49GUok4fLC6puww6IQ jZKA== X-Gm-Message-State: AAQBX9eH2ZdyEPDtc5mtDJ2PXhWg+96kGcQ3k2ujzOiA/4/H9YQgg7O2 SyhthdSa/qoVJd+yOnpsVGx1yX7erA== X-Google-Smtp-Source: AKy350YohM5+e/jy0IztChAnlEb/v6rW9tdJCM42oFCfh9/d+HGmufr2GnbmOLQ8xyNkAYtH5FcmKQ== X-Received: by 2002:a05:6870:a116:b0:187:860f:ea31 with SMTP id m22-20020a056870a11600b00187860fea31mr776207oae.44.1681325114174; Wed, 12 Apr 2023 11:45:14 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:13 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 5/6] x86/boot: Use copied boot data in __startup_64() Date: Wed, 12 Apr 2023 14:45:01 -0400 Message-Id: <20230412184502.145289-6-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the copied version instead of the original real mode data. Signed-off-by: Brian Gerst --- arch/x86/include/asm/setup.h | 2 +- arch/x86/kernel/head64.c | 4 ++-- arch/x86/kernel/head_64.S | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index 47eac5d877a8..f6c04b137d67 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -49,7 +49,7 @@ extern unsigned long saved_video_mode; =20 extern void reserve_standard_io_resources(void); extern void i386_reserve_resources(void); -extern unsigned long __startup_64(unsigned long physaddr, struct boot_para= ms *bp); +extern unsigned long __startup_64(unsigned long physaddr); extern void startup_64_setup_env(unsigned long physbase); extern void early_setup_idt(void); extern void __init do_early_exception(struct pt_regs *regs, int trapnr); diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 9be8ce41d021..c7d3976a04d6 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -176,9 +176,9 @@ static unsigned long __head sme_postprocess_startup(str= uct boot_params *bp, pmdv * boot-time crashes. To work around this problem, every global pointer mu= st * be adjusted using fixup_pointer(). */ -unsigned long __head __startup_64(unsigned long physaddr, - struct boot_params *bp) +unsigned long __head __startup_64(unsigned long physaddr) { + struct boot_params *bp =3D fixup_pointer(&boot_params, physaddr); unsigned long load_delta, *p; unsigned long pgtable_flags; pgdval_t *pgd; diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 83fb0dc97ba5..c7b2ef379f42 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -113,9 +113,7 @@ SYM_CODE_START_NOALIGN(startup_64) * programmed into CR3. */ leaq _text(%rip), %rdi - pushq %rsi call __startup_64 - popq %rsi =20 /* Form the CR3 value being sure to include the CR3 modifier */ addq $(early_top_pgt - __START_KERNEL_map), %rax --=20 2.39.2 From nobody Tue Feb 10 09:22:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF229C7619A for ; Wed, 12 Apr 2023 18:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbjDLSph (ORCPT ); Wed, 12 Apr 2023 14:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjDLSpX (ORCPT ); Wed, 12 Apr 2023 14:45:23 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61E459C5 for ; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id i15-20020a9d610f000000b006a11f365d13so5253276otj.0 for ; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681325115; x=1683917115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/WxAOYQvB1/+zLeJWbAjVCxh3aoYklNTPW85OIPHgas=; b=OVQrLlD7CUCucbyt526lxhXpqj2jb03tYwsa6VKmMzp3SZ5Bv7OeZoh2U203GgurGr j4waufjf8DqD6BSm7Ia54o3w7PwG+R2chyOZq77K2DOTJ/ZTXUFiDBP05+BtIPwZVvPv IAq+qt1pN/Pwl0EQ29MzYFeX5KYJ1AQij3C35EATOFmfvzjccaGwqq38NareXFCRh1mM sLsUbwLllhT0QVPfbvBBY/O8CU9WOmBGzAf+dSt6N5aRkArRXlPUUw3DdMq+mqZMb+pD ZCGAg+QuImm0QsyVqj+TLXqr/8CpTte3db14IwhryHSfFV9pX9XXQhUfKv7ikkjOvhf0 2cPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325115; x=1683917115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/WxAOYQvB1/+zLeJWbAjVCxh3aoYklNTPW85OIPHgas=; b=BgUjy0fB6vS1YyjrKc1tUMjzGV7qUE6GlHgGsmlt5a1RTVku++5+18gAhInOG6BqlH Zf/skzdgXnlZ5rrHAaNUX3MS1zflgJc/1hvS34c/8P49dVdwLMKEJkj3ZuHQ2/Cg/ERu KHrkHmKBOF/At30bFlh26V17FWC69tQOWXN68j95BvRYCU8JsissfoxGGpoW4ko63REh KBQWDvPsx2koG8XhQ7cq0EH9jbkvR2Bp3EXsCGmTYFZmk6N3SbpnpiloeydTPZOgMGsC b3ZWkL/UnF2HE1MGVf5oGY3AU3Wn7hTxaVwbam6UuMLScN04h7WU6YaZ1PJLUnEoXUAT xBLA== X-Gm-Message-State: AAQBX9f5ihHXFkJ62EwRundA3can+zkASKj4wX49acdMIsdHEXSG4wQE pOy835j+oxLNqh/gya8g2jHw09d+vw== X-Google-Smtp-Source: AKy350ZGEux9XRh8Jcdm6CsOeqmso+rvsJ/sIkk3iShWOxI3u06/OaHS+jQFdQ1Kxvtq5qVyFY0bjQ== X-Received: by 2002:a05:6830:12cd:b0:6a3:3655:b8a7 with SMTP id a13-20020a05683012cd00b006a33655b8a7mr75639otq.14.1681325115058; Wed, 12 Apr 2023 11:45:15 -0700 (PDT) Received: from citadel.. (075-129-116-198.res.spectrum.com. [75.129.116.198]) by smtp.gmail.com with ESMTPSA id w24-20020a9d77d8000000b00690e990e61asm6706020otl.14.2023.04.12.11.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:45:14 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ingo Molnar , Brian Gerst Subject: [PATCH v2 6/6] x86/boot: Use copied boot data in sme_enable() Date: Wed, 12 Apr 2023 14:45:02 -0400 Message-Id: <20230412184502.145289-7-brgerst@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412184502.145289-1-brgerst@gmail.com> References: <20230412184502.145289-1-brgerst@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the copied version instead of the original real mode data. Signed-off-by: Brian Gerst --- arch/x86/include/asm/mem_encrypt.h | 4 +-- arch/x86/kernel/head_64.S | 8 +----- arch/x86/mm/mem_encrypt_identity.c | 42 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_= encrypt.h index b7126701574c..74f094eb88a6 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -40,7 +40,7 @@ void __init sme_early_init(void); void __init sev_setup_arch(void); =20 void __init sme_encrypt_kernel(struct boot_params *bp); -void __init sme_enable(struct boot_params *bp); +void __init sme_enable(void); =20 int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long s= ize); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long s= ize); @@ -70,7 +70,7 @@ static inline void __init sme_early_init(void) { } static inline void __init sev_setup_arch(void) { } =20 static inline void __init sme_encrypt_kernel(struct boot_params *bp) { } -static inline void __init sme_enable(struct boot_params *bp) { } +static inline void __init sme_enable(void) { } =20 static inline void sev_es_init_vc_handling(void) { } =20 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index c7b2ef379f42..c6ea37712921 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -72,14 +72,11 @@ SYM_CODE_START_NOALIGN(startup_64) wrmsr =20 leaq _text(%rip), %rdi - pushq %rsi + /* RSI contains address of real_mode_data */ call copy_bootdata - popq %rsi =20 leaq _text(%rip), %rdi - pushq %rsi call startup_64_setup_env - popq %rsi =20 #ifdef CONFIG_AMD_MEM_ENCRYPT /* @@ -88,10 +85,7 @@ SYM_CODE_START_NOALIGN(startup_64) * which needs to be done before any CPUID instructions are executed in * subsequent code. */ - movq %rsi, %rdi - pushq %rsi call sme_enable - popq %rsi #endif =20 /* Now switch to __KERNEL_CS so IRET works reliably */ diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_i= dentity.c index c6efcf559d88..e75e4f5a8a71 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -502,8 +502,9 @@ void __init sme_encrypt_kernel(struct boot_params *bp) native_write_cr3(__native_read_cr3()); } =20 -void __init sme_enable(struct boot_params *bp) +void __init sme_enable(void) { + struct boot_params *bp; const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; @@ -513,6 +514,27 @@ void __init sme_enable(struct boot_params *bp) bool snp; u64 msr; =20 + /* + * Fixups have not been applied to phys_base yet and we're running + * identity mapped, so we must obtain the address to global data + * using rip-relative addressing. + */ + asm("lea sme_cmdline_arg(%%rip), %0" + : "=3Dr" (cmdline_arg) + : "p" (sme_cmdline_arg)); + asm("lea sme_cmdline_on(%%rip), %0" + : "=3Dr" (cmdline_on) + : "p" (sme_cmdline_on)); + asm("lea sme_cmdline_off(%%rip), %0" + : "=3Dr" (cmdline_off) + : "p" (sme_cmdline_off)); + asm("lea boot_params(%%rip), %0" + : "=3Dr" (bp) + : "m" (boot_params)); + asm("lea boot_command_line(%%rip), %0" + : "=3Dr" (cmdline_ptr) + : "p" (boot_command_line)); + snp =3D snp_init(bp); =20 /* Check for the SME/SEV support leaf */ @@ -577,29 +599,11 @@ void __init sme_enable(struct boot_params *bp) goto out; } =20 - /* - * Fixups have not been applied to phys_base yet and we're running - * identity mapped, so we must obtain the address to the SME command - * line argument data using rip-relative addressing. - */ - asm ("lea sme_cmdline_arg(%%rip), %0" - : "=3Dr" (cmdline_arg) - : "p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - : "=3Dr" (cmdline_on) - : "p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - : "=3Dr" (cmdline_off) - : "p" (sme_cmdline_off)); - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) active_by_default =3D true; else active_by_default =3D false; =20 - cmdline_ptr =3D (const char *)((u64)bp->hdr.cmd_line_ptr | - ((u64)bp->ext_cmd_line_ptr << 32)); - if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer))= < 0) return; =20 --=20 2.39.2