From patchwork Fri Nov 24 10:19:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13467447 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B92B1C61DF7 for ; Fri, 24 Nov 2023 10:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TC7oWd0xzWK7MFQwMKg4l/N2mBY84Z3y9DZXreE3T2M=; b=C/VWhDwxqaaRswPS1NsoZJFfwI W0BIkj2b8j/ZJCnrnAnZmuJmrwxJzElQ8OmGkdGyQmZKjjFSeH6zWQ0yg5c5xcQta94NPXlR+5Luf OjVUmQjI/PJ2vGZcfTgZAThRjPW4LUM61H9qgDi5RYFej8NXtWScMcUnW5FYJoAMk0TVAEcJG1vq7 aplWTB1zOfH9ozPygoK5puoqdYUZCe2GGdfe+QAisx0sCXR1upVtCmzaHJvZlFG2/US+VOm0woO9o RsQanXHuRANotdlCShu0ObAHSaRbt/XkTdcsX7QuaJwdIs10cBtQbMFJOJqnANs2pdsPfXXAfU0XK ykH92pjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r6TJX-006pGB-2o; Fri, 24 Nov 2023 10:21:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r6TJF-006p1t-0E for linux-arm-kernel@bombadil.infradead.org; Fri, 24 Nov 2023 10:21:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cngrmd8oycagSPoZSvoHKPsQhFg1xaF7tU7fqPfLIP0=; b=ZUe01ABFK3ksdxSLYTAtSqAnlP F8JoVj4GhpMIoa+vZb9iEYujjwrsJZVCNNunweCBA2BdX9ZE/W2X3E7MDa8FlXQ9l2O3fb1u+8RzC zCpwysUVsnF499IiiXRkfqzxgzvdC8W8jy0qGCnOZym5A8YNb6yvuGKdjl1vMd2+qKibEVuaMYZPt ijL/U713yB1kNKw5g6Z9nLInbTjsCDQXzV6KY6Ndk4agv7oyWPjpaOMnXM27xebpxjpKY2Fuufkhy YSGZp8pakFfS3fkHPEjtqYu/LLx6l5dw4yB72xBEJ+94lTv5mp55p/90OBZeyz0f+WKf7FsZEgH/L GKycU7Iw==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r6TJ9-00DqTQ-2B for linux-arm-kernel@lists.infradead.org; Fri, 24 Nov 2023 10:21:15 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da31ec03186so1221376276.1 for ; Fri, 24 Nov 2023 02:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700821268; x=1701426068; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cngrmd8oycagSPoZSvoHKPsQhFg1xaF7tU7fqPfLIP0=; b=oRr7vcfwWlsfal0fymnWVHJkxujbvXdlqDT2WV0l8DAAr7+CjONCAsMcR0BWW/1H5v 6BO8I90fnAzk/71s+E7pehL2gV9u/Xcs52q7qY4Mc28NNx3MeJFc39ZP3nl/1kXpff+M BQj9HcX9vyDvzIZHSrfQEmMqc59nXeiSrSOlAiOAmhij0KiiXUymKTozy40OaYDKv6Zr AD3ZTcE+Gnl/T5DeJ3h+YZBDPobMgWLpwjR7K93V1Nr3KxJHsYfRiZhKocwTm1t8b5jm AUj01K7TNzOzPGSh1jMxaBUDZ3vfAoR/DvqB2WD4xzxjnCnQwyAW5CoD0z91qiDhxV00 nKpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700821268; x=1701426068; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cngrmd8oycagSPoZSvoHKPsQhFg1xaF7tU7fqPfLIP0=; b=lQDJGh2iV3E/XPKs1VxCL05abYSA5RtRbI0Pgt3ugnb03H5M1NkVE80eGwFIhK5fhP qghuRZO7eGPSVYvamX+GQYlQxteD9V/xvrYepZQN0Dj8Yef/VLLBlyjhYRdaFZV7+PGk /q2gIs8cbp6Y/St1lEENr9jTv1glsc3RO2E+kTrmNXvCJZK6GSmr47e16iaCagY6HeHk 4yoQEUxo7JwgeHF9pY8q1Xu238zM/I8dwWYFjFoFVbClxCeM3x+mdokVlgt0vc2hXXZg ipTBrL+Cl7Qyd/d13z3H/Z849ZpsmDP3AirzRXBe2jwXnmNfpJbc8O83lwntd8UfrbpB ZFwA== X-Gm-Message-State: AOJu0Ywkhb88jHXWR2SgB2vllDBD6c9MtShjMZiB58QfkAyu60nuiABE mIP9SUox56NeLnMyxz0ioZYV+/8AMvINLb2VH3prBL9vQhLDiuytdyEBXrRdfLzaZZSMqvZSPqj oPyb0tlwJP+xPrXT12Cg695vFndeT8dkP/8rZ8XfuDvxcdSsJOw2sE1Pbc0/WSl3us8pOLG+YnP g= X-Google-Smtp-Source: AGHT+IF+Tzfknw68/7awEs3CcmlIetn8vgw9BLHRYQYb+aZSnRl+IbRdYQ53JzgYw1wGMf7q4bGBcyBo X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:dd07:0:b0:daf:3e84:d016 with SMTP id u7-20020a25dd07000000b00daf3e84d016mr78242ybg.2.1700821268525; Fri, 24 Nov 2023 02:21:08 -0800 (PST) Date: Fri, 24 Nov 2023 11:19:04 +0100 In-Reply-To: <20231124101840.944737-41-ardb@google.com> Mime-Version: 1.0 References: <20231124101840.944737-41-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2829; i=ardb@kernel.org; h=from:subject; bh=AOSTHt9JvO/4iRzuZocBqHtffwUhdcZrrydQAmtcn8o=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JITWhYrHe/cUx//sqdnJcZrVQmpjgumCNa/CKvkN1IX+3H tRc9baro5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAExkvj/D/5yMruuFLkWXH2p8 3b53/eXDd29OmGYbr3vT4ZOIjuaZi6KMDDsk78Sxy6xhfDvnwfzVKk9E48/vfsx4N8G4Y0/WQwH xMBYA X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231124101840.944737-65-ardb@google.com> Subject: [PATCH v5 24/39] arm64: head: Run feature override detection before mapping the kernel From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231124_102112_043273_565D48D2 X-CRM114-Status: GOOD ( 13.65 ) 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 From: Ard Biesheuvel To permit the feature overrides to be taken into account before the KASLR init code runs and the kernel mapping is created, move the detection code to an earlier stage in the boot. In a subsequent patch, this will be taken advantage of by merging the preliminary and permanent mappings of the kernel text and data into a single one that gets created and relocated before start_kernel() is called. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 17 +++++++++-------- arch/arm64/kernel/vmlinux.lds.S | 4 +--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 2af518161f3a..865ecc1f8255 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -375,9 +375,9 @@ SYM_FUNC_START_LOCAL(create_idmap) map_memory x0, x1, x3, x6, x7, x3, IDMAP_PGD_ORDER, x10, x11, x12, x13, x14, EXTRA_SHIFT - /* Remap BSS and the kernel page tables r/w in the ID map */ + /* Remap [.init].data, BSS and the kernel page tables r/w in the ID map */ adrp x1, _text - adrp x2, __bss_start + adrp x2, __initdata_begin adrp x3, _end bic x4, x2, #SWAPPER_BLOCK_SIZE - 1 mov_q x5, SWAPPER_RW_MMUFLAGS @@ -491,9 +491,6 @@ SYM_FUNC_START_LOCAL(__primary_switched) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif - mov x0, x20 // pass the full boot status - mov x1, x22 // pass the low FDT mapping - bl __pi_init_feature_override // Parse cpu feature overrides #ifdef CONFIG_UNWIND_PATCH_PAC_INTO_SCS bl scs_patch_vmlinux #endif @@ -772,12 +769,16 @@ SYM_FUNC_START_LOCAL(__primary_switch) bl __pi_memset dsb ishst // Make zero page visible to PTW -#ifdef CONFIG_RELOCATABLE - adrp x23, KERNEL_START - and x23, x23, MIN_KIMG_ALIGN - 1 adrp x1, early_init_stack mov sp, x1 mov x29, xzr + mov x0, x20 // pass the full boot status + mov x1, x22 // pass the low FDT mapping + bl __pi_init_feature_override // Parse cpu feature overrides + +#ifdef CONFIG_RELOCATABLE + adrp x23, KERNEL_START + and x23, x23, MIN_KIMG_ALIGN - 1 #ifdef CONFIG_RANDOMIZE_BASE mov x0, x22 bl __pi_kaslr_early_init diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 8a3c6aacc355..3afb4223a5e8 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -320,10 +320,8 @@ SECTIONS init_pg_end = .; /* end of zero-init region */ -#ifdef CONFIG_RELOCATABLE - . += SZ_4K; /* stack for the early relocation code */ + . += SZ_4K; /* stack for the early C runtime */ early_init_stack = .; -#endif . = ALIGN(SEGMENT_ALIGN); __pecoff_data_size = ABSOLUTE(. - __initdata_begin);