Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp50424rdb; Tue, 16 Jan 2024 14:44:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv6xA7/oBVnwwtF6lZv6lqNsUh27NFo3Ajui3ervyNRRF5APK+PYoOP1coooxL8C2p122z X-Received: by 2002:a05:6870:8093:b0:204:fcc:6c19 with SMTP id q19-20020a056870809300b002040fcc6c19mr8593883oab.109.1705445053138; Tue, 16 Jan 2024 14:44:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705445053; cv=pass; d=google.com; s=arc-20160816; b=Ygllm/3b2382Ene+5r1K1CxiC+RIJ+xp3OPUbUUMT0ZB5mVLzSRtN2GP9LX6D81486 KTXwaRajPVDnfvlGwF8l/gs+SP2BFN58i/lnP1GoiD2Vs1OYlttLiKoYPpmaPwzzHSI3 aW+nuqZBxagt9n+69/s8q+1wvoRAkKZYtF8hCF/XoT9i4XqcNoIx4DHUmw+Noue8pKna +4qz1toSKkiO1IsYRiUw3EmQFYlhQBhXDe5b016qsFqN/Zn1jbHBYUm/UGPUd2BqOFIG RZ9Ai6hVHdyyUQqEAu4mx/uzMtGUxHKQV4e2bg0zRxD4aYmp6mvcUwaiiGr2gW8OlLYv 7BZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=uXUySLhnCG85bx+rOKM7Gu9Ss1FziVWmsqNmRvNkWVg=; fh=u5Yb90RZoYdS8mC/KaDcu8fGsfoPGD+lheRx3fgZnI4=; b=g3//yZLR9u+VohSfAyRvgUpnm7muOMq+FlI63TGYiq3TtXzSHrfD+O81VCZYybkv0Z LfjCvZ87Rvo2aG5xs9m66SsP3XuEAGa5GnYypyZ/OsC4pHJDAvfheDGF/9Jk1+8ZhkZK bGMz2VQtVEYV7KGxW0vg86XCp1Cyk/hhLNqo62rN8Xu3S4DJn8flVvQsn2DtLCqCtxrZ GYVH1W1N0JMlUJ1IXD/QqutlI3MQOe0V+eiNDZ0VGVaMkxVEpWfblbMdNSml9mI8OjCS Zs9PJVMw7huJIYcv1S7Xh1AAt4X7W7rkDtCLm0pwb99mCdiPQ1dhduZPG8YxDBELXhtK ytVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=djKTlcZl; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-28336-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28336-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u186-20020a6379c3000000b005cf934981b1si199712pgc.414.2024.01.16.14.44.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 14:44:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28336-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=djKTlcZl; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-28336-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28336-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6E88328A11F for ; Tue, 16 Jan 2024 22:39:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B2BD1DA46; Tue, 16 Jan 2024 22:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="djKTlcZl" Received: from mail-ua1-f47.google.com (mail-ua1-f47.google.com [209.85.222.47]) (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 CF8071D548 for ; Tue, 16 Jan 2024 22:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705443218; cv=none; b=ojiIoEYEa+somY1X73ggzRn4uuNCIQ9+mLFIUmFqghymOwd9QbqY/q8+NqZiUcdyfPZxfT5FhMB8EkTU15v29bbKWJaDpuxFPTib/xiiNwWLi7S5hZfm2LfrsdU9/QgxwWLo17cU6l1QNZfgajsD8fJhNaKjCsNX1N41i1dnJ+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705443218; c=relaxed/simple; bh=uXUySLhnCG85bx+rOKM7Gu9Ss1FziVWmsqNmRvNkWVg=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=AvHTRwuxhQvQPLFYkDZITAac/qG5g+dTJC7VEYT7l5dFSYzAY7ksiOfQybWuE2o0muBJCjvnMXDMDrbd6z+LCfY124iCtbQNS63eu/Yipx2GPRU/6iru/NBsbGfl3RCUFxOdG6ujaprqUtjQ7w9Vi0FtVcF9bw3+LNAvcunCMbc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=djKTlcZl; arc=none smtp.client-ip=209.85.222.47 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=google.com Received: by mail-ua1-f47.google.com with SMTP id a1e0cc1a2514c-7cc92a83200so2364800241.3 for ; Tue, 16 Jan 2024 14:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705443215; x=1706048015; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uXUySLhnCG85bx+rOKM7Gu9Ss1FziVWmsqNmRvNkWVg=; b=djKTlcZldrYR3Hh/I0aB/6PG6VEejMgPy4idR7UDW5pJBNIzdV54mhDThSKhwovAFx qmWaOaiyB548PVe9tmuahtCx14MOxd0481mWNUxf9Nz/T0abmFShX/70Agbs98TgX4Fg Pvzl4v0kRdGmbKOzD9gM9iCd61BBnvLx50dlZ4rs9ciVyWT+7wwML4TeE6s0OeMaV+Mo mJgI0ZVV00G5Rx/wcA8GGAl6CF8lkJaHKOPrh1TPsoSDeNMvc4g9HtPyvI3tN++IdXzV sTfBVWXbaMDO7gG34b7StBKr9a5+U18MGlHq4bDcLF+4GjXbAU+pXkQpAQS5m05B6ko7 +/Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705443215; x=1706048015; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uXUySLhnCG85bx+rOKM7Gu9Ss1FziVWmsqNmRvNkWVg=; b=MZXF3J+o8jxaYJo+apar+V6W405dVBFsgltrIz2UB264pg4tSVZZQMJ42Qa627Sx4Q FtuBFZYWiHobZqiK3YEIGT/kPurH1NAPju2QbpTgacKtgEthbI6v7iivVRo95N222VuK TJfTniZlOBm+5E1KF7V8Tjw4hJXn/bRBHsXkN879VMYr7k/qcZYs9HvyBMTlQf8AceTt r1FlAREuX8WaVj2crO1KNPyUvpBnNEOl75MVlSkzh6Cp20Wj4rrkSgYwIVMy+w8MwcWt 4lW5NkTaHgnsDb7gMNuGhR2iE8R58irB0qk87uuklvDUnzcQaWVuF+NySv+clQA4GxS8 0E5g== X-Gm-Message-State: AOJu0YzZYtFb27LpYGijmYnnmWID5juGp7yhX+zJQ35TuQ6i2y+PZKVk qKDhc/MqcyAKnkesl1EQIJQYLfjEkdU1u16BSeR0EBEktKx2 X-Received: by 2002:a05:6102:1811:b0:467:f7eb:8074 with SMTP id jg17-20020a056102181100b00467f7eb8074mr3965650vsb.29.1705443215629; Tue, 16 Jan 2024 14:13:35 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240111223650.3502633-1-kevinloughlin@google.com> <20240112121725.3amxlumpifhagamb@box> <20240115101239.nab725vuazvutgw6@box.shutemov.name> In-Reply-To: <20240115101239.nab725vuazvutgw6@box.shutemov.name> From: Kevin Loughlin Date: Tue, 16 Jan 2024 14:13:24 -0800 Message-ID: Subject: Re: [RFC PATCH v2] x86/sev: enforce RIP-relative accesses in early SEV/SME code To: "Kirill A. Shutemov" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Tom Lendacky , Michael Kelley , Pankaj Gupta , Stephen Rothwell , Arnd Bergmann , Steve Rutherford , Alexander Shishkin , Hou Wenlong , Vegard Nossum , Josh Poimboeuf , Yuntao Wang , Wang Jinchao , David Woodhouse , Brian Gerst , Hugh Dickins , Ard Biesheuvel , Joerg Roedel , Randy Dunlap , Bjorn Helgaas , Dionna Glaze , Brijesh Singh , Michael Roth , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-coco@lists.linux.dev, Ashish Kalra , Andi Kleen , Adam Dunlap , Peter Gonda , Jacob Xu , Sidharth Telang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 15, 2024 at 2:12=E2=80=AFAM Kirill A. Shutemov wrote: > > On Fri, Jan 12, 2024 at 10:29:36AM -0800, Kevin Loughlin wrote: > > > > Per my tests, yes we can; I replaced the fixup_*() functions with > > GET_RIP_RELATIVE_PTR()/PTR_TO_RIP_RELATIVE_PTR(), and guests with and > > without SEV, SEV-ES, and SEV-SNP all successfully booted under both > > clang and gcc builds. > > BTW, do we need both macros? Caller can do &var, right? While I don't think the caller doing "&var" would work without passing it as a separate argument like `GET_RIP_RELATIVE_PTR(var, &var)` (as we would still need the original var's string name in the macro for the inline assembly `#var(%%rip)`), we should nonetheless be able to merge both into a single macro with one "var" argument. Specifically, the only current difference between the macros is the input operand constraint, and GET_RIP_RELATIVE_PTR()'s constraint will work for both. I will make this change in v3. > If we are okay with single macro, maybe rename it to RIP_RELATIVE_PTR(). With the merge into a single macro (and upon thinking about the macro's behavior), I have a slight preference for `RIP_RELATIVE_ADDR()` in v3 because it makes it clearer that the macro behaves like the address-of operator "&" (just guaranteeing the use of RIP-relative addressing to obtain the address). However, I'm happy to go with RIP_RELATIVE_PTR() if you feel that's better. > One other thing: I see you sprinkle casts to for every use of the macros. > But why? void* can cast to any other pointer without explicit casting. You're right; the casting is unnecessary. I'll eliminate it in v3. Thanks. > > On Fri, Jan 12, 2024 at 4:17=E2=80=AFAM Kirill A. Shutemov > > wrote: > > > > > > Also, is there any reason why GET_RIP_RELATIVE_PTR() and > > > PTR_TO_RIP_RELATIVE_PTR() have to be macros? Inline functions would b= e > > > cleaner. > > > > I used macros because we need to use both the global variable itself > > and the global variable's string name (obtained via #var in the macro) > > in the inline assembly. As a secondary reason, the macro also avoids > > the need to provide separate functions for each type of variable for > > which we'd like to get RIP-relative pointers (ex: u64, unsigned int, > > unsigned long, etc.). > > If we do it only on pointers, wouldn't void * -> void * be enough? Only using pointers would indeed eliminate the secondary factor as a reason to use macros. However, the primary motivation for a macro would remain: we still need the string name of the variable for the inline assembly.