Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp535165lqd; Wed, 24 Apr 2024 09:23:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2gvMnfjmEM+LVw9jvTnqwwLPOwvYnvUQ5aT74NVojO1834ctJQ+Dq1Q+QF5ncUqxou7yKI07UDmEwrrg/MfVUoKW/9KZKGvFVr9TyfA== X-Google-Smtp-Source: AGHT+IGNsSbky7lUzGloH5XDCDn3xkXmqD1bUA/9goSKOdmS0z6H8V1u+ZO9OAKLKckaOK+xgykM X-Received: by 2002:a05:6a20:3945:b0:1ac:4ef9:3d53 with SMTP id r5-20020a056a20394500b001ac4ef93d53mr3477931pzg.5.1713975784875; Wed, 24 Apr 2024 09:23:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713975784; cv=pass; d=google.com; s=arc-20160816; b=GkdnutmPpbGvur8G4ihe7+31qbSR+WpT/3h9JX2XJ6Zd5MIg4VYg2Wtlm5cE6rP/xT 72keEdSfTvImAc1dYOm/A05dRjLjduVornLgKI/KSaEOh/B7wn43yFe6mowY/rc/3SkE aaO7qeZ4j/sIfsKkrNucn+xFqI1fbNVTSuRm6h0WiAG86jWSeWenb1xDIuKs2bjlN/cP 4v30J9hfhzv6+qFlSJ3oUvvgCmeG0SheJLKmtzVIW1IKW73kSrDTXEgJ5CophF0qX3jf TQym5TiWP0esQV3u7cfqzvD7Dc7UfQ6ADFP8F1+iTVzvDQuCPS68wEHs+hrAyMr0yOWW oR7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=qhjj4lZ1BD8EjRsdlA75QEwqazDOqFi5p2t0e/m1hPo=; fh=FsvQoRfUYCb7YWgVN8g3QkTLNjgBrJZxscq7eE3+/Gs=; b=QY2v8AC17nXqksuczMyTZIJoQbIZv2hN3zJD+S3rLXbK8SZzFnRIGlj1FH2IrEFY2x SK3L5X5nfRh/AOnZRBwlZXE0m3wItIWIO1ozyUG5KZzVZnSaEfaTiZCDuD+pdlfWDNyX 8xYLIevARjnbKkbaFCq29e1S43oj/1vjX5KNs5zuGQEhRGp1Bjp3Mv6BTH8aZPoEPsnw RuLHHiXUBCqWh5+caJkihq1aYgiBJjPjYakun7evntEQZt+/Rwa8+PPxqTp70LxK7dBy vWJ8k90mjk8P7FHo0wyTaMGBqDPnLDqKxTXj+Mm/bgb+VPHOD4+XRTcQisJjnSRG7aGU 3sFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sfuR3PJT; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157253-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q9-20020a656a89000000b005feabc95aa9si6049181pgu.403.2024.04.24.09.23.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:23:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sfuR3PJT; arc=pass (i=1 spf=pass spfdomain=flex--ardb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-157253-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157253-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E3271B26BD1 for ; Wed, 24 Apr 2024 15:53:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8075A15FD07; Wed, 24 Apr 2024 15:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sfuR3PJT" Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DE3113DBB2 for ; Wed, 24 Apr 2024 15:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974016; cv=none; b=OCpYv3UVgFJ3sFwE8ZVu0chpd+X1Ai3oU65JR4M+emPxZqu0GV0VAwyhvVwDChU6G0/243JIkd1jorVYJ9VmQMWCwaqufth63vYa0cBJUIo+GLpjkAMwbZ0yKnmprcjyVwV5lo0CpWA8IVc3y0NfFyS8jL/2CuATvESKCx8EVhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713974016; c=relaxed/simple; bh=P7tOci3FIvCaUgN5ShYb22FrHmvvfi3TSK49QcbCOaA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=OjgVk2XGndGYs2ya7ccLfwOBA0beVlPKOjHoj3VBtcn2mpUviE1b+QCfK+0JF2VzvjsJxshMAxCdGyE98/I8V+hcg/rsu/krM3/v72eI5+vgpCdMR5fAMJi4qVzOLu6Atn+L718yb9HTmA9926msxmBGkr4D7jiU+9/ma66rRkg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sfuR3PJT; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-34b40e8482aso2426606f8f.0 for ; Wed, 24 Apr 2024 08:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713974013; x=1714578813; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=qhjj4lZ1BD8EjRsdlA75QEwqazDOqFi5p2t0e/m1hPo=; b=sfuR3PJTx2j3BI0M8lKez/iUgNqLalteVKayl7v1DMGAnTuKzngLGrs52ABJNVsjzk meKURXLBqTO7j7Av/SXdUQQUhmVEnKSTjBX7mhPAGZHXaWSLr3b0L2hg0cqOlZ0iauHE ZgStj0mwQCY5EowFfa4zWVHS0RQgcbThhg83Ja73iEf79meP/F/XWNOYWXtbp5EPZKPs IgCOvAFGTm9Mmn5JwhcADfY5seSW/zIwNzap4z0z4pr2qMcl5um8g3uihwcyKPRNyhbl 0kANY9E0VbJ/Sg8Bqec9e5lF9YlubDMgxKRE89TtfBCRcLoXGZeN/X1bX9Esg0gx5xLs z5Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713974013; x=1714578813; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qhjj4lZ1BD8EjRsdlA75QEwqazDOqFi5p2t0e/m1hPo=; b=QHgVUD0DK7DlnItXtJYBNZccVMXsULtg0eOn1IJqAmIpwzJs3+LCWeR0GUio4sn91V hRG3h62OPRlMDiIMoPAIFoRHLZQlgweTB8jnpN+tf0SsSgJD04E1v6euwRw4cwKUkUH5 901TP+l1tkQ2oLydVR0Heg6XG81spUT22uHVs6iyZ0d5t4ITOs75DWZebDHcAg4qlp2F AJaUOS8TvVz1AmGKNqyPsGxJMrLQ8wr0T6Ik+B9v0tSlM8aZDaES5TtS6M2G7LMLQHQp UVtzX//VL00yjnkjLsnAkjHzqaLaRm3+9rpN9KNoSZmidAPNqBvN9qt5SbQU+WxjA0Me p+pQ== X-Gm-Message-State: AOJu0YyMrEjMh3mZIi7oKCUXjvm8a51fJUHIUKVHXJYkIcjX3Q+HM28Z 5zF4rFxN/FevA5M7dAP/CSz9i176jmUgKsavzQw5iKtrntgwpA0XZbs/L//lzBn1Ii/d1eFIcYe ectPQtp+08f3xjZngzvSgHKh+E7HLOws67pN1oy6ceS0jytePfEsRPu/J12qAmuDzEhpdkC6vJt 34tTm7te7NJR46nH0of0SRXmt80o9v6Q== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a5d:4689:0:b0:33e:d448:987d with SMTP id u9-20020a5d4689000000b0033ed448987dmr10048wrq.6.1713974012466; Wed, 24 Apr 2024 08:53:32 -0700 (PDT) Date: Wed, 24 Apr 2024 17:53:10 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=3265; i=ardb@kernel.org; h=from:subject; bh=idgDjYiAKHOsQh6BKM4ksIPor6eEyvMhl8OTBBlOdlM=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIU1T62nHZLEFLnn/7goFXZk7X0zg32aVqSkSCrp9mx0CW iq9Nq/sKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOZ/JuR4aWxdVvw7dwFEfua V5SfUPZ+VSsleLNLaYHDFdfAyz+alzMy3G/ST9E741D48UDWgZrsN1vdT0290aCf+NZ+VqXi3u0 NnAA= X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240424155309.1719454-11-ardb+git@google.com> Subject: [RFC PATCH 0/9] kexec x86 purgatory cleanup From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Ard Biesheuvel , Arnd Bergmann , Eric Biederman , kexec@lists.infradead.org, Nathan Chancellor , Nick Desaulniers , Kees Cook , Bill Wendling , Justin Stitt , Masahiro Yamada Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel The kexec purgatory is built like a kernel module, i.e., a partially linked ELF object where each section is allocated and placed individually, and all relocations need to be fixed up, even place relative ones. This makes sense for kernel modules, which share the address space with the core kernel, and contain unresolved references that need to be wired up to symbols in other modules or the kernel itself. The purgatory, however, is a fully linked binary without any external references, or any overlap with the kernel's virtual address space. So it makes much more sense to create a fully linked ELF executable that can just be loaded and run anywhere in memory. The purgatory build on x86 has already switched over to position independent codegen, which only leaves a handful of absolute references, which can either be dropped (patch #3) or converted into a RIP-relative one (patch #4). That leaves a purgatory executable that can run at any offset in memory with applying any relocations whatsoever. Some tweaks are needed to deal with the difference between partially (ET_REL) and fully (ET_DYN/ET_EXEC) linked ELF objects, but with those in place, a substantial amount of complicated ELF allocation, placement and patching/relocation code can simply be dropped. The last patch in the series removes this code from the generic kexec implementation, but this can only be done once other architectures apply the same changes proposed here for x86 (powerpc, s390 and riscv all implement the purgatory using the shared logic) Link: https://lore.kernel.org/all/CAKwvOd=3Jrzju++=Ve61=ZdeshxUM=K3-bGMNREnGOQgNw=aag@mail.gmail.com/ Link: https://lore.kernel.org/all/20240418201705.3673200-2-ardb+git@google.com/ Cc: Arnd Bergmann Cc: Eric Biederman Cc: kexec@lists.infradead.org Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Kees Cook Cc: Bill Wendling Cc: Justin Stitt Cc: Masahiro Yamada Ard Biesheuvel (9): x86/purgatory: Drop function entry padding from purgatory x86/purgatory: Simplify stack handling x86/purgatory: Drop pointless GDT switch x86/purgatory: Avoid absolute reference to GDT x86/purgatory: Simplify GDT and drop data segment kexec: Add support for fully linked purgatory executables x86/purgatory: Use fully linked PIE ELF executable x86/purgatory: Simplify references to regs array kexec: Drop support for partially linked purgatory executables arch/x86/include/asm/kexec.h | 8 - arch/x86/kernel/kexec-bzimage64.c | 8 - arch/x86/kernel/machine_kexec_64.c | 127 ---------- arch/x86/purgatory/Makefile | 17 +- arch/x86/purgatory/entry64.S | 96 ++++---- arch/x86/purgatory/setup-x86_64.S | 31 +-- arch/x86/purgatory/stack.S | 18 -- include/asm-generic/purgatory.lds | 34 +++ kernel/kexec_file.c | 255 +++----------------- 9 files changed, 125 insertions(+), 469 deletions(-) delete mode 100644 arch/x86/purgatory/stack.S create mode 100644 include/asm-generic/purgatory.lds -- 2.44.0.769.g3c40516874-goog