Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5627782rwb; Tue, 1 Aug 2023 05:51:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGrT8irT0t6udWsAJDc+yqmb5L4Ku+qX7zYHB5z9P5hzJeBcoGj9xt8SL4knxchuAo+3mp3 X-Received: by 2002:a17:907:3f1f:b0:98d:abd4:4000 with SMTP id hq31-20020a1709073f1f00b0098dabd44000mr2473363ejc.35.1690894305702; Tue, 01 Aug 2023 05:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690894305; cv=none; d=google.com; s=arc-20160816; b=zh4hsJxV1BiOqVte+x0S1X2tEOh/2MKNiGFwNJWgLGfLAxdU72UHIEGZz6w98PWRJO MmBpC3VXM/BeuYejTcFHzUmQ7jOXhmw8ndSJSyoJIxhJtaEW84vzRglh+ofOeyhM6wKD BDh69/km/preIrJ7kEet1taMb4FqrH0rxkoyGKyfriINM5wu6z90PzZBjren4cvb3KGP JZEMg5J8WW7FYt50kd+K8gb5J2ED6eYNVnUfzqmAlHhXDKCakA1mK/NaM5kYPYKblFm7 sodvVUSEH04ZVDnX0jENLLrbJSv+l7hYeLca3ZG5dOow6avMCChyZxVeVITpabSxG5Iw vZYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=FxuoKK6iA7jCc7CzQE8tdfsQIpWnMGHsxXnMGYPo8xE=; fh=smwlySTEPN7NbtuvxBDR0YLYw0n8sfL/zSNxRQmJRvQ=; b=LAseyeWh9Ce99X71LkElQs5tJdSjx0ed3Jm3v8HXSBQX6/KOmYX2gbAaFpaBJpngil d7p21F9oE/HFvAJ596L5BPS/VXc8j209JQzXc4jyD552VIwOtTbaV15pqFIMIlOB7d6G pDNzTNJZOWZUKGbHeefrcgr7fe8W3rFBDj/zg/9sbGF/sJ/4h+Kw2gJsg4OB+tggKbYd onhe7m2Ws+qtmULF3ukTRRLUMZvBUhze2/s8RGoigPBUF0lCUgu8jBjITjSlJhlkK+0Z us+QqyXHAp0Lb7RApSPh+IrpMv882B3461KlLwJxE7Q1IfduGU6GjgCCjEP8CEkFGu1N cOFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=R1puegKK; dkim=pass header.i=@alien8.de header.s=alien8 header.b=RMpBPOf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cd17-20020a170906b35100b00983f499fbd7si546393ejb.836.2023.08.01.05.51.20; Tue, 01 Aug 2023 05:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=R1puegKK; dkim=pass header.i=@alien8.de header.s=alien8 header.b=RMpBPOf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbjHAMI6 (ORCPT + 99 others); Tue, 1 Aug 2023 08:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231904AbjHAMI4 (ORCPT ); Tue, 1 Aug 2023 08:08:56 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EED11982; Tue, 1 Aug 2023 05:08:55 -0700 (PDT) Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 137E31EC0532; Tue, 1 Aug 2023 14:08:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1690891734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=FxuoKK6iA7jCc7CzQE8tdfsQIpWnMGHsxXnMGYPo8xE=; b=R1puegKKMwq9A7Ettla/ygoHluAOB+uuC+jY4GkGwfhZ8BKNCVDNt7WUPn/f5IxzkS2WJz pEQTFswPQcfVT0N7nH0rDmxVwczi15U4BCd15xjZn+HXJgzkHLXs4iIqIirGpbN0jk9xnQ XS/nJuAKAioJ2k4ttVsc8Vnn32pM9d8= X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id d3fCGvSyTQ2D; Tue, 1 Aug 2023 12:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1690891731; bh=FxuoKK6iA7jCc7CzQE8tdfsQIpWnMGHsxXnMGYPo8xE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RMpBPOf+j+s+T/X+E3mpvvRXJCKfNR0pdYDI3FMeamHCVEM3xqx22cAnHTNVKrYgr ZjI4e2X7BIf3rq+Zw/azZ55JnIwFkhVnm7nE1fVf+uE2Cqc7OEOLMPXCUtzEzI5xQI aPkNFwuD+OMikuyEHL7HId4vWjPFnUchRUHHRlQfkgApk0Tvu5aLHES00/iVyTkiPO 3XUbaqpkK08/EnXk7N+25wYJkGpVZgPz1SZsd/UqUJIfEMZ6mGTa8njnIfiLF73hI0 iypIVStCIbnuz1ZEX371VznoV4pSsZiFcZ6OCxIdbWp4kcrAV3cGUvxNnlczdWhZOK /ppc46se1Krl6fbo23wOTE61QJxm+dCA6plkP3E4ZXBHm+xjU/UH4TSfOIAcKkEfAh VOl+kw1TxZTdpiSFzAny9A7Mor1hVOrMwC7F7JVB2GfQe3A57SA0L04VWmlxYkuBXB Yl9rF8p8nVWc0qRHkd4HEGHIpZn6PgdceUMuvyew1N7vxWu7XfToypFqmzNMxHwzvm jOepzoE57PH5fXTh6pXj8KveZayIh6M0i4ueTttScFANvxwbN5dMvRq0FXgYeKfDbq pJOKictcqgEZEZym0f6OcE1/7rphFnCegCT8yl+82yRYq+hLuG6+NQnwh31BuoIeB2 MQux4kQSDzjROF8BqJEftI90= Received: from zn.tnic (pd9530d32.dip0.t-ipconnect.de [217.83.13.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 57E5440E019D; Tue, 1 Aug 2023 12:08:32 +0000 (UTC) Date: Tue, 1 Aug 2023 14:08:27 +0200 From: Borislav Petkov To: Ard Biesheuvel Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Evgeniy Baskov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds , Joerg Roedel Subject: Re: [PATCH v7 14/22] x86/decompressor: Merge trampoline cleanup with switching code Message-ID: <20230801120827.GFZMj1uzNMDs2gIi1f@fat_crate.local> References: <20230728090916.1538550-1-ardb@kernel.org> <20230728090916.1538550-15-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230728090916.1538550-15-ardb@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 28, 2023 at 11:09:08AM +0200, Ard Biesheuvel wrote: > diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c > index 4016444e6788304f..4f50af23a0854f18 100644 > --- a/arch/x86/boot/compressed/pgtable_64.c > +++ b/arch/x86/boot/compressed/pgtable_64.c > @@ -101,9 +101,10 @@ static unsigned long find_trampoline_placement(void) > return bios_start - TRAMPOLINE_32BIT_SIZE; > } > > -asmlinkage void set_paging_levels(void *rmode) > +asmlinkage void set_paging_levels(void *rmode, void *pgtable) Please get rid of this silly rmode arg which gets passed in here as boot_params and then gets assigned to an extern pointer to boot_params. This is just silly. Just do what the other functions get from %r15 now - a struct boot_params *bp arg. But perhaps in a separate patch. > { > void (*toggle_la57)(void *trampoline, bool enable_5lvl); > + void *trampoline_pgtable; > bool l5_required = false; > > /* Initialize boot_params. Required for cmdline_find_option_bool(). */ > @@ -133,7 +134,7 @@ asmlinkage void set_paging_levels(void *rmode) > * the desired one. > */ > if (l5_required == !!(native_read_cr4() & X86_CR4_LA57)) > - return; > + goto out; > > trampoline_32bit = (unsigned long *)find_trampoline_placement(); > > @@ -163,6 +164,8 @@ asmlinkage void set_paging_levels(void *rmode) > * The new page table will be used by trampoline code for switching > * from 4- to 5-level paging or vice versa. > */ > + trampoline_pgtable = trampoline_32bit + > + TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long); > > if (l5_required) { > /* > @@ -182,31 +185,21 @@ asmlinkage void set_paging_levels(void *rmode) > * may be above 4G. > */ > src = *(unsigned long *)__native_read_cr3() & PAGE_MASK; > - memcpy(trampoline_32bit + TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long), > - (void *)src, PAGE_SIZE); > + memcpy(trampoline_pgtable, (void *)src, PAGE_SIZE); > } > > toggle_la57(trampoline_32bit, l5_required); > -} > - > -void cleanup_trampoline(void *pgtable) > -{ > - void *trampoline_pgtable; > - > - trampoline_pgtable = trampoline_32bit + TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long); > > /* > - * Move the top level page table out of trampoline memory, > - * if it's there. > + * Move the top level page table out of trampoline memory. > */ > - if ((void *)__native_read_cr3() == trampoline_pgtable) { > - memcpy(pgtable, trampoline_pgtable, PAGE_SIZE); > - native_write_cr3((unsigned long)pgtable); > - } > + memcpy(pgtable, trampoline_pgtable, PAGE_SIZE); > + native_write_cr3((unsigned long)pgtable); > > /* Restore trampoline memory */ > memcpy(trampoline_32bit, trampoline_save, TRAMPOLINE_32BIT_SIZE); > > +out: > /* Initialize variables for 5-level paging */ > #ifdef CONFIG_X86_5LEVEL > if (__read_cr4() & X86_CR4_LA57) { > @@ -215,4 +208,5 @@ void cleanup_trampoline(void *pgtable) > ptrs_per_p4d = 512; > } > #endif > + return; No need for that one. It'll return without it. :-) -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette