From patchwork Wed Mar 3 00:22:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12114195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36DF5C433E0 for ; Wed, 3 Mar 2021 20:33:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3773C64F02 for ; Wed, 3 Mar 2021 20:33:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3773C64F02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=advOwH8ZLIQWOjainb8O1aM2XfhFt/rcTLC+awhz6I0=; b=AOgLZJJol7DgF/5fy0LIMfcas ezWpsezEEhhfc5FoJFJLr6K0WyHE2WHhaBgxkSEUv0B8ZQCuTVj3vhcHmE/4JZ77AwNIzdW2W4d5k aMvry76ngv1SDNO6ssj4oee0YLzcqaEVGEaCfRh2EL/1L4cZ91HZDNvNX1gQm8I8t9aWbSC6/dM5c a7i4jh3j2sRTtRGTdnkgpawk4cVoGPh9zf+BtxRXGeTIjPq1kDtGpg1tvXX6CetpcjdkhwQ7rwwnk 3RTZCCW9xlY6O69KwSBs3IcX/r35NLf6xW+tr8FmqJaXFqh1gyIjzaFZjmJHMwOCFnmq5POd8GnAY +IkYI/eeA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHY7h-006Q6L-Jw; Wed, 03 Mar 2021 20:29:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT5f-005IpM-D4 for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:07:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=CkOHd4Ubs6QxUZPpaIRvKfllHz4QaZDE7Cb9NwMEurE=; b=dOGn17Ljpu8dKn/REohe48yr3M mFb5yx7TZXJMUi+2TluzI0ZyllLu1VoLdXAS54m6ltJyO2zkwZUhpRXy+tnpR0C02aPt++ZWVItZv UhWWe8E8VNfRZ29dGwSZ3nFQYmBB74g9KLJ0LXUME9CtyrnagA5foVnqpqgNNuIfZzVgD08riHkZb s1XjzJV6s9D/ur1wrfNoqA+ryYSOGuCBBkCYXHly43vTjrsIZDBRhvkjsSazaYUFajjbhlo8Yz1nB TZnOgsOLbVZEB5Yx4GQ1fdT/ZpqiqX+Vripxg74NpmZle50J+rQ0zzVVVpVFJPiBpWMwxlnDIMGsF f7C6a2uQ==; Received: from mail-qt1-x832.google.com ([2607:f8b0:4864:20::832]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFQD-000kUq-0w for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:31:25 +0000 Received: by mail-qt1-x832.google.com with SMTP id j3so589192qtj.12 for ; Tue, 02 Mar 2021 16:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=CkOHd4Ubs6QxUZPpaIRvKfllHz4QaZDE7Cb9NwMEurE=; b=kv+djcD5Dn8tl5qEcKKg9wUfgrKRtIeHMDiyEGXGQs7F/ZmuhWe//JnMzxmKu3F7AH 88SbhKfkE78CfHCAU44Ln2BV0iQYNwXNNODQZqJTwJvNp3lruyG1V2IxzYqcxJbNeIZ6 girfcwSI1nPDGrreCNMXLSEJQko02mF+3Yihp7JjLbeVQdjBz1rF1xU7FCCpI1MADl1I pOeZtuW+wh2ejaP/7dgGE0DRh69BVBAUaJ+0RDEenZ88YSFdaBOLm7hTX3jYfk39tjpV 9gPTcFqCKqbCgpdfet/cTN4tW9o3BcjhJkKgOcD4wkV5+2WV0S3t0adzPBj5dTCa3CUU saSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CkOHd4Ubs6QxUZPpaIRvKfllHz4QaZDE7Cb9NwMEurE=; b=LGnQQNhURvdGAOi/fjGsiZhDDsOc7Vkf9kO2ciRHvCtGnPaQASBhftvf+PoeBNF5my plVutyxUa1c6j700uJdwB9kW1G2Bru3OLJjU28XRCy4p9jqXYUB2bpNTCmZqXgtK/lRN NLImskIKPX5Q/HJJQppB3drDLIs+WBqq7Vll3W/jb/zMXrnkPpk8ETXsfiqttL8qQtsa R4ZV2L7Df/QDQBYUmaLCULlgTz+bt7iuuc96g6T6/fsosrj/w604JyXpF5pEfR1fj5AC +fgOaHcJ4smxEfS+CL6GdkNHEX7K4omCG84N8hUC4VEjyjoVvh3XvuDHUohbROnRipMP 4Qog== X-Gm-Message-State: AOAM530BBh+pij3nGs1nD+l6p/V3DN4ab9hgVgdGySOED9Y9ZZmf0hXe qsyo5Sjc45hrHYWQIRNxC5NE0NWCh4jXGQ== X-Google-Smtp-Source: ABdhPJzh2Sttz/3luOleODmtp3yKBF23rhlq0H6VUfZnw3KEBQCZesiL+EeFQlA4puGBiExt3HvrBQ== X-Received: by 2002:ac8:5947:: with SMTP id 7mr8369297qtz.60.1614730967312; Tue, 02 Mar 2021 16:22:47 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id r3sm16690512qkm.129.2021.03.02.16.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:46 -0800 (PST) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com Subject: [PATCH v12 11/17] arm64: kexec: kexec may require EL2 vectors Date: Tue, 2 Mar 2021 19:22:24 -0500 Message-Id: <20210303002230.1083176-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303002230.1083176-1-pasha.tatashin@soleen.com> References: <20210303002230.1083176-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210303_003125_338646_C8393A0A X-CRM114-Status: GOOD ( 18.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If we have a EL2 mode without VHE, the EL2 vectors are needed in order to switch to EL2 and jump to new world with hypervisor privileges. In preporation to MMU enabled relocation, configure our EL2 table now. Suggested-by: James Morse Signed-off-by: Pavel Tatashin --- arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/kexec.h | 1 + arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kernel/machine_kexec.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1f212b47a48a..825fe88b7c08 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1141,7 +1141,7 @@ config CRASH_DUMP config TRANS_TABLE def_bool y - depends on HIBERNATION + depends on HIBERNATION || KEXEC_CORE config XEN_DOM0 def_bool y diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 9befcd87e9a8..305cf0840ed3 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -96,6 +96,7 @@ struct kimage_arch { void *dtb; phys_addr_t dtb_mem; phys_addr_t kern_reloc; + phys_addr_t el2_vectors; /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_mem; diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 0c92e193f866..2e3278df1fc3 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -157,6 +157,7 @@ int main(void) #endif #ifdef CONFIG_KEXEC_CORE DEFINE(KIMAGE_ARCH_DTB_MEM, offsetof(struct kimage, arch.dtb_mem)); + DEFINE(KIMAGE_ARCH_EL2_VECTORS, offsetof(struct kimage, arch.el2_vectors)); DEFINE(KIMAGE_HEAD, offsetof(struct kimage, head)); DEFINE(KIMAGE_START, offsetof(struct kimage, start)); BLANK(); diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 2e734e4ae12e..fb03b6676fb9 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "cpu-reset.h" @@ -42,7 +43,9 @@ static void _kexec_image_info(const char *func, int line, pr_debug(" start: %lx\n", kimage->start); pr_debug(" head: %lx\n", kimage->head); pr_debug(" nr_segments: %lu\n", kimage->nr_segments); + pr_debug(" dtb_mem: %pa\n", &kimage->arch.dtb_mem); pr_debug(" kern_reloc: %pa\n", &kimage->arch.kern_reloc); + pr_debug(" el2_vectors: %pa\n", &kimage->arch.el2_vectors); for (i = 0; i < kimage->nr_segments; i++) { pr_debug(" segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n", @@ -137,9 +140,27 @@ static void kexec_segment_flush(const struct kimage *kimage) } } +/* Allocates pages for kexec page table */ +static void *kexec_page_alloc(void *arg) +{ + struct kimage *kimage = (struct kimage *)arg; + struct page *page = kimage_alloc_control_pages(kimage, 0); + + if (!page) + return NULL; + + memset(page_address(page), 0, PAGE_SIZE); + + return page_address(page); +} + int machine_kexec_post_load(struct kimage *kimage) { void *reloc_code = page_to_virt(kimage->control_code_page); + struct trans_pgd_info info = { + .trans_alloc_page = kexec_page_alloc, + .trans_alloc_arg = kimage, + }; /* If in place, relocation is not used, only flush next kernel */ if (kimage->head & IND_DONE) { @@ -148,6 +169,14 @@ int machine_kexec_post_load(struct kimage *kimage) return 0; } + kimage->arch.el2_vectors = 0; + if (is_hyp_callable()) { + int rc = trans_pgd_copy_el2_vectors(&info, + &kimage->arch.el2_vectors); + if (rc) + return rc; + } + memcpy(reloc_code, arm64_relocate_new_kernel, arm64_relocate_new_kernel_size); kimage->arch.kern_reloc = __pa(reloc_code); @@ -200,6 +229,8 @@ void machine_kexec(struct kimage *kimage) restart(is_hyp_callable(), kimage->start, kimage->arch.dtb_mem, 0, 0); } else { + if (is_hyp_callable()) + __hyp_set_vectors(kimage->arch.el2_vectors); cpu_soft_restart(kimage->arch.kern_reloc, virt_to_phys(kimage), 0, 0); }