From patchwork Fri Oct 20 11:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 156051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp992142vqb; Fri, 20 Oct 2023 04:41:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTd9FUAL0Tk05987jJaUpNr0NVuoSFLJprz+w+aWhDcENUaFYlIVLyXXJlLbh7GSqPcx6C X-Received: by 2002:a17:90b:35c4:b0:27c:f48e:e245 with SMTP id nb4-20020a17090b35c400b0027cf48ee245mr1564632pjb.24.1697802105601; Fri, 20 Oct 2023 04:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697802105; cv=none; d=google.com; s=arc-20160816; b=prMHu5pYm4GWY1HohHb7MpKbmKnbHEnqCuVJk7UMWzKMOZAXGeQSSCBWqFSDuvKVHj lcI9/ln4QoV74KSGhjp8tB5OeA2N0FsGa3XA8CkcCYaPKWlFRYJ9DIf6ZbNcnt4ooIK3 wjT3MXcUfBRWrGJRZAKcrFgR6Qdr51kwKtBxmPDpnwtydZrlgOU8FR9k7Cmo6xBNcamV pY4A2JdPqJSua4lj+exTrqTa5eO972Mj07yv+IbpWnEJ53qbbOGuydtsyqm/bRoyMLko 3W9A4IPzp65XsIiXZGTtsPOcwIvks5jPvfCXAluGI1mAO+j++Q5D7uQIzPQ45B6pvfd3 yqaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ATsUGzvnesAyW0GiLV/+K8CQ+agfx0W24nsA90MKCak=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=a4fZa2WexkpO30TIKaNUT1Fvpvm24XjdBdh0ssrbkypYw/kr9Hu6f1EIHUlSxdk/rA FrCt+KBgvDJDD6+5CDtasa7BKLm6GNj6aIPaDSaWi27RWKJwHE8UK0K0AxquARGGp1Mm FS5JSHD5vrr58byMaNfSrY6spVVaL2cbyTAgMeIDqWWREYQh3V1MVOiyIXa8Wby2PcFR 6EYDA0S7BZ+sc9F/kcxDnmDXBtTViOJU5eUTYzLs8RfAd5LjJF05xD4YpucXAwVjHaC+ Iw90sUpYLlrBJ95sym7muGJSvIyxGFOoO9yMJl1F+2yEnEX3dwWIM0UYoEqrvyuiHABw KiXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IodEItzd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id v14-20020a17090abb8e00b0027cdee52324si4053652pjr.74.2023.10.20.04.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:41:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IodEItzd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 94FD581F3D5A; Fri, 20 Oct 2023 04:41:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377186AbjJTLlM (ORCPT + 25 others); Fri, 20 Oct 2023 07:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377466AbjJTLkr (ORCPT ); Fri, 20 Oct 2023 07:40:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B456E10CB; Fri, 20 Oct 2023 04:39:00 -0700 (PDT) Date: Fri, 20 Oct 2023 11:38:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801885; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ATsUGzvnesAyW0GiLV/+K8CQ+agfx0W24nsA90MKCak=; b=IodEItzd361aRjvd1F2E9A+hUkwlnhzKJ+rmCsAF94tVeAZFvr3Pgu/TQMfZ/qX5IcxuGV BM4koP4WrRWOSm3pJvTaABjxEugGMEPpzD7n4ZuLr2FcFKoHhpAnGFn0h5ps178BWEdjoR r4qpoRxdDjv1valQ2YQ+IpTCzh7vugrBbWlKDqbkaqdeT/1b9NrnsbGjOAcgCO6cRCfii6 MR6pMnb38+L/r9f06TCOloAWWBYiL4dKhBCYCCNdaQfr+rPKjQSImQRozM8+I47qOb95tq 8OSb7ZQMthyO1Qw7ixSHLyF0CYFv5ZTHEQIs1ho6qqVglcaMSccNDJRsmRuANQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801885; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ATsUGzvnesAyW0GiLV/+K8CQ+agfx0W24nsA90MKCak=; b=VrF0BoCK8vcxAqAfM/x2xldMLjuyam8w//Vsy+emZZvrjxUDq52gxzyN6tn1zlbdL5sCz+ nzqOBkE5AL942ADQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231017211722.111059491@linutronix.de> References: <20231017211722.111059491@linutronix.de> MIME-Version: 1.0 Message-ID: <169780188492.3135.16075004518464321952.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:41:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780039381668819082 X-GMAIL-MSGID: 1780274540702836364 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: a62f4ca106fd250e9247decd100f3905131fc1fe Gitweb: https://git.kernel.org/tip/a62f4ca106fd250e9247decd100f3905131fc1fe Author: Thomas Gleixner AuthorDate: Tue, 17 Oct 2023 23:23:26 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 18 Oct 2023 18:27:30 +02:00 x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32() Move the ifdeffery out of the function and use proper typedefs to make it work for both 2 and 3 level paging. No functional change. [ bp: Move mk_early_pgtbl_32() declaration into a header. ] Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231017211722.111059491@linutronix.de --- arch/x86/include/asm/setup.h | 1 +- arch/x86/kernel/head32.c | 38 ++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index f349562..bf483fc 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -126,6 +126,7 @@ void clear_bss(void); #ifdef __i386__ asmlinkage void __init __noreturn i386_start_kernel(void); +void __init mk_early_pgtbl_32(void); #else asmlinkage void __init __noreturn x86_64_start_kernel(char *real_mode); diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c index 8fe0dd3..2b65998 100644 --- a/arch/x86/kernel/head32.c +++ b/arch/x86/kernel/head32.c @@ -69,41 +69,43 @@ asmlinkage __visible void __init __noreturn i386_start_kernel(void) * to the first kernel PMD. Note the upper half of each PMD or PTE are * always zero at this stage. */ -void __init mk_early_pgtbl_32(void); +#ifdef CONFIG_X86_PAE +typedef pmd_t pl2_t; +#define pl2_base initial_pg_pmd +#define SET_PL2(val) { .pmd = (val), } +#else +typedef pgd_t pl2_t; +#define pl2_base initial_page_table +#define SET_PL2(val) { .pgd = (val), } +#endif void __init __no_stack_protector mk_early_pgtbl_32(void) { - pte_t pte, *ptep; - int i; - unsigned long *ptr; /* Enough space to fit pagetables for the low memory linear map */ const unsigned long limit = __pa_nodebug(_end) + (PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT); -#ifdef CONFIG_X86_PAE - pmd_t pl2, *pl2p = (pmd_t *)__pa_nodebug(initial_pg_pmd); -#define SET_PL2(pl2, val) { (pl2).pmd = (val); } -#else - pgd_t pl2, *pl2p = (pgd_t *)__pa_nodebug(initial_page_table); -#define SET_PL2(pl2, val) { (pl2).pgd = (val); } -#endif + pte_t pte, *ptep = (pte_t *)__pa_nodebug(__brk_base); + pl2_t *pl2p = (pl2_t *)__pa_nodebug(pl2_base); + unsigned long *ptr; + int i; - ptep = (pte_t *)__pa_nodebug(__brk_base); pte.pte = PTE_IDENT_ATTR; while ((pte.pte & PTE_PFN_MASK) < limit) { + pl2_t pl2 = SET_PL2((unsigned long)ptep | PDE_IDENT_ATTR); - SET_PL2(pl2, (unsigned long)ptep | PDE_IDENT_ATTR); *pl2p = pl2; -#ifndef CONFIG_X86_PAE - /* Kernel PDE entry */ - *(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2; -#endif + + if (!IS_ENABLED(CONFIG_X86_PAE)) { + /* Kernel PDE entry */ + *(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2; + } + for (i = 0; i < PTRS_PER_PTE; i++) { *ptep = pte; pte.pte += PAGE_SIZE; ptep++; } - pl2p++; }