Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1294824rdb; Tue, 30 Jan 2024 14:09:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPTxuzK04yhD4GUlpI3Zwxcb4sW/TeBL9+JUc7zEZrBmCCcG3nadWZ8DCfwNG9QjOLv6vS X-Received: by 2002:a17:906:3752:b0:a28:c04e:315b with SMTP id e18-20020a170906375200b00a28c04e315bmr2637387ejc.13.1706652542574; Tue, 30 Jan 2024 14:09:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706652542; cv=pass; d=google.com; s=arc-20160816; b=FAUmHOO4xXC0azQMb6XsYsR9ToIGFkH8dPAOc4kAqBDeP+dQYHEGxwkWOV0i8uWmYE eWzitMvTZeYm/py/3HXjukaWpI24EuFFfYIOwkea4me07BZkU3MzYKT1MaBj9zc4iUhu bhXHjEqcoPa142PUfG4wvQ6OK8ExCCCbIxgkiiYIZYupDHeFNeXoFiQMZ7QCKeTZJC5M i486NomWfXSKUAnsyL82lBoFUBtTk8bMHLCcMiEKQ6VSLgGFkUtHaWSKuW5PgL+W+sob tGmDJ30qfo08lghFJ32PAy1xbmjXdrvWuTnvtkQ0pQB+bs9+sog1u5hxXKXKaXFQioRD iCNw== 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=g4o2DS6nz22ReCocFZD628QsKvugxD4ZslaXCuzueXU=; fh=C5cIcIMzbYhc9oRyhoT0Fgv5yooWpPbZcCuB0C7Gx3I=; b=xQ44ZDInZayTNdDfNPROX/zncxoJ80AqtI70Tvin2BiptJl7k/dN6F5Afms8/JHTMZ 4XFb2kuG7Ofsn7+AXrIA5Wn5MscsIW+fadSd8mdOUqfQ7NbVLUTrtrkolNfphbScTyYb zWJlCflbUxM9nySA1GwkNyu16mrvLBzS+qlrwhWVzlAp9GMPwtuWQdmg/uw17cwXjrSD kjLmycMFwsijCRY1SNabrxv+NsXM5xFMYJeRlIC3n6LDgQDGyRGqzpiBIVN6yv3390lp cU/scEsJSqMBhhCAqSV5U4BJIrY+A0H2OXZFZwjPGPg/w5WYN6Ha0C1ss63QuQ65bwdb jhMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DfwzKkph; arc=pass (i=1 spf=pass spfdomain=flex--kevinloughlin.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-45369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c20-20020a170906695400b00a3582419e01si2999841ejs.817.2024.01.30.14.09.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 14:09:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DfwzKkph; arc=pass (i=1 spf=pass spfdomain=flex--kevinloughlin.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-45369-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45369-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2A0AE1F25C9A for ; Tue, 30 Jan 2024 22:09:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F4227D407; Tue, 30 Jan 2024 22:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DfwzKkph" Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (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 BF66E78666 for ; Tue, 30 Jan 2024 22:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706652533; cv=none; b=Inn1id/Q0piB33/4QI8/6MpzrqIxPa5y/4/KRFBVVRhjYTyFlA4XgYlOtNJaXoqKfLSO2ck719Pl4OiNpbSfQ7T8jTmdnCbMo73iD/1mEbkqFzBMCUwkG0uuYhAcitW6v0K6sa2BPF/wsNX58sZJTL+xm97RXwKq0CEOw6ajvtE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706652533; c=relaxed/simple; bh=wLXGJX7ZPdzpVptP9s9CeY5Mk/dYYO7q22+aMQXDhEk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tnFjtQEvgjIrV/kkY64R5K/DFfzkIb5g5wxENUCxjCT8R6FD/s0GAsasadKxF+UE+p35tX5ZQBOnvuFZbsba3OuqSXEFyUnEDOXmataJXIOq6mvxiwr1XDbjfA5f+yzsdPI0ZUezAZrauSrSew6NJvcwnOHg2DW4vZOJf4W01qQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kevinloughlin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DfwzKkph; arc=none smtp.client-ip=209.85.166.74 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--kevinloughlin.bounces.google.com Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-7bfeba24176so190195339f.3 for ; Tue, 30 Jan 2024 14:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706652531; x=1707257331; 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=g4o2DS6nz22ReCocFZD628QsKvugxD4ZslaXCuzueXU=; b=DfwzKkphw8jwyDxJz9WhaQDTNiKDQV5tBFiKlNr+Zqp1BnHq+QU5MSjB1R+Yt6iTLg pFDTZcM+hR2Km1eLLeH28rO9iFEDeZGyCMQabNMFvJJ43DtN008EBwmG2d4MY5LHT2Ma muaJILsQfTlExfDhgteyQE1VB8u1CmOxuHATGBSWiN1GLFlA5IpVuSLapRLezgq0dtt0 ICJ16ofmfI9pGGQI1IawQqtqk2yJdRhugCQCRd61yG7AXTkb0uI4yTuNUuzOj7zACg2A 7esCWmbadlYzakLT2/UZhkQdByT7OAhbEYdN+Myo4BSRspMnD0lY6HiCDJ0AnGnZPBuI J6jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706652531; x=1707257331; 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=g4o2DS6nz22ReCocFZD628QsKvugxD4ZslaXCuzueXU=; b=NvHAwZj2U+kDGADbDoqnA8HNIvDi1WPjinJGC6v5Dw5V3iprvXy5sSVcz0oD38OEFp nEfsPESVBB5zObgsTM2PD0LCbrhpWDKzrK/v43OU8FWMAQTQiQhiUvkfLAxQmWez8D1h nJQYTnQP3WVgaz/96zRxtytlWNtLWFXc3lzF/27YCqKb+VoScJ3stF1jDlRx+dX/Od3D nn+MPQgugtJAmcd+zAiW9gE0sT1uSft/5KtH6vjcAh4FhIP8sbzUlA1ekMkMvsB8NAus 6zDpQHFrxSJT0lyqVq/GwOnJAmDLwsNZa1Mh/Y6bf7JCrL8q7VUyh6fKEHUkryFNRIjH goBg== X-Gm-Message-State: AOJu0YwHrxUwgXpQXwxaWX6OuriPlOVAYW0N9NkTrEQ92kUo83D2//QA s+wBD/pcpIVUA7e5ioDAGFJYLu8buRZk+PBNth6xzMbzjuCMzuorPvR96F3JnpYKaRwJpmsLEgp 1dNN+jlppuvprmxEln+6G23wnlC9Baw== X-Received: from loughlin00.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:1b6f]) (user=kevinloughlin job=sendgmr) by 2002:a5d:9907:0:b0:7bf:e3a5:ccea with SMTP id x7-20020a5d9907000000b007bfe3a5cceamr11521iol.0.1706652530978; Tue, 30 Jan 2024 14:08:50 -0800 (PST) Date: Tue, 30 Jan 2024 22:08:43 +0000 In-Reply-To: <20240121182040.GBZa1geI5NxWSslvt0@fat_crate.local> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240121182040.GBZa1geI5NxWSslvt0@fat_crate.local> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240130220845.1978329-1-kevinloughlin@google.com> Subject: [PATCH v3 0/2] x86: enforce and cleanup RIP-relative accesses in early boot code From: Kevin Loughlin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Nick Desaulniers , Justin Stitt , Tom Lendacky , Kevin Loughlin , Pankaj Gupta , Hou Wenlong , Ard Biesheuvel , Dionna Glaze , Brijesh Singh , Michael Roth , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-coco@lists.linux.dev, Ashish Kalra , Andi Kleen Cc: Adam Dunlap , Peter Gonda , Jacob Xu , Sidharth Telang Content-Type: text/plain; charset="UTF-8" SEV/SME code can execute prior to page table fixups for kernel relocation. However, as with global variables accessed in __startup_64(), the compiler is not required to generate RIP-relative accesses for SEV/SME global variables, causing certain flavors of SEV hosts and guests built with clang to crash during boot. These crashes highlight a broader problem wherein the toolchain does not guarantee that early x86-64 code executes correctly at any offset. While Ard has been looking into overhauling the early x86-64 code going forward [0], the signficant proposed changes are unfortunately not backport-friendly. Instead, this patchset continues the approach of fixing the immediate problem of SEV-SNP boots crashing when built by clang, providing a backport-friendly set of changes needed to successfully boot SEV-SNP hosts and guests. In particular, this patchset is a cleanup of V2 [1], which introduces a macro to force RIP-relative addressing in early SEV/SME global variable accesses and existing head64 global accesses. V2 -> V3: Rename RIP_RELATIVE_ADDR(), remove fixup_*(), cleanup style V1 -> V2: Use GET_RIP_RELATIVE_PTR() macro to avoid -fPIE compilation [0] https://lore.kernel.org/lkml/20240129180502.4069817-23-ardb+git@google.com/T/ [1] https://lore.kernel.org/lkml/20240111223650.3502633-1-kevinloughlin@google.com/ Kevin Loughlin (2): x86/sev: enforce RIP-relative accesses in early SEV/SME code x86/head64: Replace pointer fixups with RIP_RELATIVE_ADDR() arch/x86/coco/core.c | 22 +++++--- arch/x86/include/asm/mem_encrypt.h | 32 +++++++++-- arch/x86/kernel/head64.c | 88 +++++++++++++----------------- arch/x86/kernel/head_64.S | 4 +- arch/x86/kernel/sev-shared.c | 52 +++++++++--------- arch/x86/kernel/sev.c | 13 +++-- arch/x86/mm/mem_encrypt_identity.c | 50 +++++++++-------- 7 files changed, 143 insertions(+), 118 deletions(-) -- 2.43.0.429.g432eaa2c6b-goog