Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1697384rdb; Thu, 25 Jan 2024 03:36:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFWDfYTSfQfekFKzxfukJ/4INnW2RFp4bGUoM8Sw3H4YJBjMCwJNdE+f1TCi9mlrao6WMh X-Received: by 2002:a05:6808:130e:b0:3bd:68be:407c with SMTP id y14-20020a056808130e00b003bd68be407cmr767199oiv.46.1706182587108; Thu, 25 Jan 2024 03:36:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706182587; cv=pass; d=google.com; s=arc-20160816; b=XkmzwN5kyBCqeskhegpPCZEChxZjpd1SkrCF7JfFzVHkIDvyli/qJQV2zQlJtYhV+3 Miw7B9tg2OgOmKvwxeEMU+AKKydYFIlfnlqT6RP0WiOJBJNAWobIlPx8SOoHvqbiYt+O 6F+BXC3jzxbsq5zUibOtbHafbKJhnV5teTG40Y1JtBBWMW8jVHuDtBdVI6Y/5nbXOb+S i0ftAI6qAOkaN0BXG5LCUAYfmyRPVhC5fMX0MFj/a4EZMzX9Z4VcHm86VorAOkdTl3LP vygro7qvfYcHZBdInGjQl0S2FviCizxlQkkYRXaeFhBmW5JQgfdJHesuOg5hBP32rfcv pVjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=7LDdj00C7C86np8himWDzcjTQoz4YXOOGxPlqG/+mK0=; fh=Mjd69IxHltS/Jba8SYEPy4aDMrScq2KBDxG2XjETtWk=; b=g9LWBYgrH2Yhp0tbEmacEhhngPsIC/CnuvEL+8MeNkUk6n6Sra4M2dV3CgWdO2x3SN rXI+Kz3WHVrIYkw7Drd7VrVJGs5FnE1JCbjjJYbHaWOtJfDFJAQQItqyayEvLDPgRkjA weMbhaXmKTQEkPKea0PkdD1JRha6F+2GVdzHnfe8dtJw4lWMmy5gBHG4ow0LZfFkbxTf yrGf/7OCFu0PZcWfbMJEH1Cf6cU8sixKkEhcpKPKAiMMVbYAIws1WPS1tkf7iJiePV1y qFsljG5alNZ40TVhOJvpKEirAR9yFlQN04fMuz1ITA2L7t11tqfRFLR6qL4OZkiboiDf fgCA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=taaxhFRv; 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-38519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j9-20020a37ef09000000b00783a15f80d4si8232434qkk.373.2024.01.25.03.36.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 03:36:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=taaxhFRv; 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-38519-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38519-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 716531C237F4 for ; Thu, 25 Jan 2024 11:36:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C31958AAC; Thu, 25 Jan 2024 11:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="taaxhFRv" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 C59F557331 for ; Thu, 25 Jan 2024 11:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182394; cv=none; b=krlnG0qlmkIuE/b/Iy6bK6i9JveCXcn7RtC+XJyRp5vBwWScTmmHe0iS+/tpY2r9pyDxQmIJZF/9XvGy8nIUMOxobm0OulaitoHbgYp9R4y+iqAMmhSteDGZQ5aZOM0/ORGi+4Tbh377a8FZ6o0HaPZhLIVP0HUH8YYiVbcNdik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706182394; c=relaxed/simple; bh=53cr8/bRwWd0m61pZCiciaZiTFFAHiTaLmG9qZPd8js=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tdSpCu95tmq2nZFiFfXICyigkK4zFQbfLHrUqqXnucw1f4NdcL99ifjVsJQQVJgbop8n8vEOgSCt/ueCotywld1Ch6YKhelygmaM5rxGh37FLLZtKNXV8AaGecM1iiDp4S3poDlSwOgkU8WP/c2Rhll5zIb9PrrTK5CTG+8KqvQ= 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=taaxhFRv; arc=none smtp.client-ip=209.85.219.202 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-yb1-f202.google.com with SMTP id 3f1490d57ef6-d9a541b720aso9713596276.0 for ; Thu, 25 Jan 2024 03:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706182392; x=1706787192; darn=vger.kernel.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=7LDdj00C7C86np8himWDzcjTQoz4YXOOGxPlqG/+mK0=; b=taaxhFRvBJ7x27l0OSpr3vw8YcmBhyQ4c2nMIVUArmpw+BcvPfxbwyrfACHztLpiTk knCWGvpQr2vejXCH8yeUeWNrLRxBNfuRWLE0bdc07HrlzEQihHZu1oBwoAcf4F+c8SAI 9HJ3QelivOwHj0HG8vIqJSxsZEcqq531Eo6CZixbSsPOCJtOSd0fYwI/4isy6Gp/jzHp W5PccyVU8g+03rE5zXUChfWQb0IxL1w3Pu2XziIEViFfESgzYW8TTXNDuFcBkQ5xM64L 1p6H4uN7aYsC0okITA86UF+N9/r93rJBrs1wuHgsa2ec2aDhd9rSMJZtlDVXaVD9Yr0y nOrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706182392; x=1706787192; 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=7LDdj00C7C86np8himWDzcjTQoz4YXOOGxPlqG/+mK0=; b=MTgFn0BDlOWaEjax88cRWu8GkIIBZ6KjxBU73ImtjHyrIpFlJxTMio/ISnDeaVyVtl 6R2JldYJJFKiIYbLE8s4hjLCFKiEYApibhdhnvND3rULlVSCGG6web5Hn6XTwJXaIZKm DGs9cAZqJz/GvRVPpPxs0q2WZvLD+F2yXbolMpMGViT4e9Rf35xcV/DkvS68ooxXcykh 116pWgy7/PRHbuwiA2pMfyxNxW2uQrQDrxHMArBZdL+J5laqEmlUPJAYfr9oOZAXzh+j W4aSVk/Y/ACWMc0qNuaIPFwrLYPHTwTyTsvkw/G6ZcU3PJ/pdxoWlMtPhwi384kfiLF0 hjGA== X-Gm-Message-State: AOJu0YwVFGtu1sU5SqX8kQDG73FWiUf+nRnwF2SWnkjDXQpY7d4cgQpD YIC6I9j9yKtRzfk0JrM7wg0U/tTakGYasXeIHCHpMMMdJmllHhuQsNI2Q1juA+mryQF/7xxRJ6f I2GK6ILrPUYESWv4p66wOKDDL8AydPlPYEWJMHAT7+79R4ggqAPULhXvRVpdRs37ChmF/KgfXDT GhFabys+MfHg7XF9Bm+TU+nWAM2OV/fg== X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:108f:b0:dc2:23d8:722d with SMTP id v15-20020a056902108f00b00dc223d8722dmr436585ybu.13.1706182391890; Thu, 25 Jan 2024 03:33:11 -0800 (PST) Date: Thu, 25 Jan 2024 12:28:34 +0100 In-Reply-To: <20240125112818.2016733-19-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240125112818.2016733-19-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2380; i=ardb@kernel.org; h=from:subject; bh=NfyMVMLTwE2gaCOtLA5OAbEVC8C/2zEsck2HEztektc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXWT678l+dzpjnF+wZfLxO/X9M9rvaB34Fq1rvE771Va/ 2WDd+/oKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOZG8TIcPHCL6dXrmYPXq0u +/nAkX3twjvhvyf4n/khfu+DqbPAJz2Gv5KiT+q1eYp+JNx95BpofMp0+aemWZPF3+8rX3BPpu7 OSnYA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240125112818.2016733-34-ardb+git@google.com> Subject: [PATCH v2 15/17] x86/sev: Use PIC codegen for early SEV startup code From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Kevin Loughlin , Tom Lendacky , Dionna Glaze , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Justin Stitt , Brian Gerst , linux-arch@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel Use PIC codegen for the compilation units containing code that may be called very early during the boot, at which point the CPU still runs from the 1:1 mapping of memory. This is necessary to prevent the compiler from emitting absolute symbol references to addresses that are not mapped yet. Signed-off-by: Ard Biesheuvel --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/vmlinux.lds.S | 1 + arch/x86/lib/Makefile | 2 +- arch/x86/mm/Makefile | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 65194ca79b5c..65677b25d803 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -24,6 +24,7 @@ endif # head64.c contains C code that may execute from a different virtual address # than it was linked at, so we always build it using PIE codegen CFLAGS_head64.o += $(PIE_CFLAGS) +CFLAGS_sev.o += $(PIE_CFLAGS) KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 77262e804250..bbdccb6362a9 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -182,6 +182,7 @@ SECTIONS DATA_DATA CONSTRUCTORS + *(.data.rel .data.rel.*) /* rarely changed data like cpu maps */ READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES) diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index ea3a28e7b613..87c79bb8d386 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg endif -CFLAGS_cmdline.o := -fno-stack-protector -fno-jump-tables +CFLAGS_cmdline.o := $(PIE_CFLAGS) endif inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index c80febc44cd2..b412009ae588 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -31,7 +31,8 @@ obj-y += pat/ # Make sure __phys_addr has no stackprotector CFLAGS_physaddr.o := -fno-stack-protector -CFLAGS_mem_encrypt_identity.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o := $(PIE_CFLAGS) +CFLAGS_pti.o := $(PIE_CFLAGS) CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace -- 2.43.0.429.g432eaa2c6b-goog