Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1704042ybh; Tue, 14 Jul 2020 05:17:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTbVI5RUQ3/yz8TkBWlZQXWPmLORJrLuW3ooXmsDWsWwOCl0aPzKoIclnznq00SCswtHx0 X-Received: by 2002:a17:906:8595:: with SMTP id v21mr4279834ejx.333.1594729029639; Tue, 14 Jul 2020 05:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729029; cv=none; d=google.com; s=arc-20160816; b=A/O3QdxTTWMYXAG8UJEBPRVlg9lGXeQSrzufWTB6kD2cHMfTQ+kK1WSy/iRGTQftlz Sc3ARlE0oV6NMM3X+7UXZ2DFlI+iSPotTz9D2zuRa2aDLJQk91H1/xopfuI886UW0I02 ETGcZ4Wr6WqEpfWcTZodn4HHjlLSwF1XyS57huvTVpJV+9/ZKfLoz+tV5V7smrUA6ad1 awqcs0IgTtIpAK6EJNYxzuz9o7algLNvp9z8ymdHNYDM7IduvrgwoUrtJFT3LOaASyXo y7Z8VCca+eNPOaEAKEynKT/xBTRozbdQNytGBeMyk4EaauBw0gPQq8I9vdLnFDr/Uqif /B1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EKgKU4BPMmhzuc+S4x4jvLP/Fb7IngWH2/I9VHltfR4=; b=SzeiQ78GHCrg/WeiUBuL3KPOkD3Zb/vv9zpIZCV5nBGmBCxSJN9ChTJYcJSMHU9MfO TgM3b0OrKFlzgo+Hnzb/3f510k4dJqCcO+8fw8ppmYHargUCXVRiTP/qDqoKx/6+SYqU Pd0rOsgW0oZuVe0K7LejrjQlwv5p0mIs9sHAB9kNdI/7fArtNhtVVp4kT9yl2pMfmVz5 jtRKN9qwb/OJA1lz66aIOMVp6COE/9T85+xsiyRrPLp1yQwL5TLtafddGYTH6f/P0dXu gZabtPR5PGFGTkUaBt/pcmj1xCE+h8Mu39qsMIPDPikCvJaYU97d8rCcxjkQA3k/evxT ygqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si10768641eds.85.2020.07.14.05.16.45; Tue, 14 Jul 2020 05:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728721AbgGNMPM (ORCPT + 99 others); Tue, 14 Jul 2020 08:15:12 -0400 Received: from 8bytes.org ([81.169.241.247]:53684 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728335AbgGNMK4 (ORCPT ); Tue, 14 Jul 2020 08:10:56 -0400 Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 5BFB8F5C; Tue, 14 Jul 2020 14:10:52 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 36/75] x86/head/64: Move early exception dispatch to C code Date: Tue, 14 Jul 2020 14:08:38 +0200 Message-Id: <20200714120917.11253-37-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Move the assembly coded dispatch between page-faults and all other exceptions to C code to make it easier to maintain and extend. Also change the return-type of early_make_pgtable() to bool and make it static. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/asm/setup.h | 1 - arch/x86/kernel/head64.c | 19 +++++++++++++++---- arch/x86/kernel/head_64.S | 11 +---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 76aa21e8128d..001b719a5e29 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -28,7 +28,7 @@ #include extern pgd_t early_top_pgt[PTRS_PER_PGD]; -int __init __early_make_pgtable(unsigned long address, pmdval_t pmd); +bool __init __early_make_pgtable(unsigned long address, pmdval_t pmd); void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm); void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm, diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index 19ccb1211004..5b3a9883ecc7 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -49,7 +49,6 @@ extern void reserve_standard_io_resources(void); extern void i386_reserve_resources(void); extern unsigned long __startup_64(unsigned long physaddr, struct boot_params *bp); extern unsigned long __startup_secondary_64(void); -extern int early_make_pgtable(unsigned long address); extern void early_idt_setup_early_handler(unsigned long descr_addr, unsigned long physaddr); #ifdef CONFIG_X86_INTEL_MID diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 3598c091ff24..32080e34ba92 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include /* * Manage page tables very early on. @@ -316,7 +318,7 @@ static void __init reset_early_page_tables(void) } /* Create a new PMD entry */ -int __init __early_make_pgtable(unsigned long address, pmdval_t pmd) +bool __init __early_make_pgtable(unsigned long address, pmdval_t pmd) { unsigned long physaddr = address - __PAGE_OFFSET; pgdval_t pgd, *pgd_p; @@ -326,7 +328,7 @@ int __init __early_make_pgtable(unsigned long address, pmdval_t pmd) /* Invalid address or early pgt is done ? */ if (physaddr >= MAXMEM || read_cr3_pa() != __pa_nodebug(early_top_pgt)) - return -1; + return false; again: pgd_p = &early_top_pgt[pgd_index(address)].pgd; @@ -383,10 +385,10 @@ int __init __early_make_pgtable(unsigned long address, pmdval_t pmd) } pmd_p[pmd_index(address)] = pmd; - return 0; + return true; } -int __init early_make_pgtable(unsigned long address) +static bool __init early_make_pgtable(unsigned long address) { unsigned long physaddr = address - __PAGE_OFFSET; pmdval_t pmd; @@ -396,6 +398,15 @@ int __init early_make_pgtable(unsigned long address) return __early_make_pgtable(address, pmd); } +void __init do_early_exception(struct pt_regs *regs, int trapnr) +{ + if (trapnr == X86_TRAP_PF && + early_make_pgtable(native_read_cr2())) + return; + + early_fixup_exception(regs, trapnr); +} + /* Don't add a printk in there. printk relies on the PDA which is not initialized yet. */ static void __init clear_bss(void) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 8f9548071e84..86473d49619d 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -375,18 +375,9 @@ SYM_CODE_START_LOCAL(early_idt_handler_common) pushq %r15 /* pt_regs->r15 */ UNWIND_HINT_REGS - cmpq $14,%rsi /* Page fault? */ - jnz 10f - GET_CR2_INTO(%rdi) /* can clobber %rax if pv */ - call early_make_pgtable - andl %eax,%eax - jz 20f /* All good */ - -10: movq %rsp,%rdi /* RDI = pt_regs; RSI is already trapnr */ - call early_fixup_exception + call do_early_exception -20: decl early_recursion_flag(%rip) jmp restore_regs_and_return_to_kernel SYM_CODE_END(early_idt_handler_common) -- 2.27.0