Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp924153rdd; Wed, 10 Jan 2024 03:51:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHElGu2ydH3vfcX1Su7PIYKVFfGpmfhxsozTSKY1Nk4SbCEmy4hxjm1QxAMz687AObOGJR2 X-Received: by 2002:a17:907:7b8f:b0:a2c:1132:6b51 with SMTP id ne15-20020a1709077b8f00b00a2c11326b51mr60055ejc.41.1704887496925; Wed, 10 Jan 2024 03:51:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704887496; cv=none; d=google.com; s=arc-20160816; b=awyzEbnURZnN1UAYwCT6Nijc1Ks6kRVpdk7FjJh9aKxAVz8LogmXVmJlXjhM9onQIu gsf8CS/zf5Td4NzdhMthYDZV7pyYzsQqpOZBz62H7WNRq4dYld+m2gcaYk0cF4yRmAQu Uwyyk4W5pO2myyEdsTJeLk5ADaN+oZMZmvPLl885HZVDyTEPnMaJsew/mq+Ax4zzLjs3 YUPrY2GfQe0zMEyd52VU35bVNhAcGV8BTixGYj7jZzGTiA9S861zthxCTgRbNG+MgBUb VQ88/MGaw0FftyddZTAHJgAXlUrpZ1BcBFiNqSiOA8tgrmpBJGRUaKlp7rI9RI6eDaPY Iviw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=AReSS1bmszMZC1ld2pSzzq6JVX8J9+zKoXoi9idF5hs=; fh=xc5gbk/fV5lpm8YAtFD9GA7yuEn3IfzAJVxk9pym034=; b=fdAuUgmcd9JzktiRS6WTzPCjo/gLtJUZGY17dGKhVPwSXONWoM/dI4quJbyl5DIgwo 4Zsj60EGVl3D5Bate9EIkUnxfNWEMJeDbpR7YXS1s8Y1SNkMbQS5ndfi9dt2w0QWoQb1 ZPUnSHUXmoQppNSSOqxWymMoLl1zTlr/4JP0KA2un5ASFNxOorEOkTEYxkDUTz4YG1FR pA9B8wQOfvgSObQ9ll7ENNWuPmT1me88G1w81CM3hvEQ+V1VtGmJar5CovbRVoLDXyyy 5DGW+A8/kPijSKo/zwzl2tdtIjpT/o/aSxfNQDxxFuC1VZAJRYaLzIm1gbEdPDIhZ3Cc QE9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Agtz1M7D; spf=pass (google.com: domain of linux-kernel+bounces-22130-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22130-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a20-20020a17090680d400b00a28e758c286si1640499ejx.61.2024.01.10.03.51.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 03:51:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22130-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=@intel.com header.s=Intel header.b=Agtz1M7D; spf=pass (google.com: domain of linux-kernel+bounces-22130-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22130-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 AA2A11F21689 for ; Wed, 10 Jan 2024 11:51:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48EBC4D13E; Wed, 10 Jan 2024 11:45:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Agtz1M7D" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 048454D589 for ; Wed, 10 Jan 2024 11:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704887122; x=1736423122; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=3hr8WKe3hLRmQmvxepGB6Y30XVCdzwD/ynaPZtClRaU=; b=Agtz1M7DVualQghZ4zcpwpcoeN22cLhbsgq/1DIjFQVY2YTLmi4LtBHy 10dTfF9tliZHp2vFw5Fl/OKmUX9lSpkkLNLIWPfi0mmlO1IionVBxPjxR LAh2xlllt+6FCESpi8+p0kkK3qBCfzG2wqRR66ZiTeqoy91nBdwNlp3ko JDBls9oHKB9g7S5KpVdo1bPiSxFBGRHFSod+Sf2dPJ06R1fKxmmG4p3Mo Hjiy7Cw2lMGAjQP7zPEnQSqlWBJYFZc6ilUWiQHQbM44xV8dZ4Lv93aSJ 5HSs8eDtvX2FJ9/DdOBCdXUqQABO17GxDgA//csQy4CbDWR+I7BJR6GxG g==; X-IronPort-AV: E=McAfee;i="6600,9927,10948"; a="397345288" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="397345288" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 03:45:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10948"; a="901127739" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="901127739" Received: from tassilo.jf.intel.com (HELO tassilo) ([10.54.38.190]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 03:45:19 -0800 Date: Wed, 10 Jan 2024 03:45:13 -0800 From: Andi Kleen To: Kevin Loughlin 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 , Rick Edgecombe , Kees Cook , "Masami Hiramatsu (Google)" , Ze Gao , Josh Poimboeuf , Pengfei Xu , Brijesh Singh , Michael Roth , Ashish Kalra , "Kirill A. Shutemov" , Tom Lendacky , Joerg Roedel , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-coco@lists.linux.dev, Adam Dunlap , Peter Gonda , Jacob Xu , Sidharth Telang Subject: Re: [RFC PATCH] x86/sev: x86/sev: enforce PC-relative addressing in clang Message-ID: References: <20240110012640.1335694-1-kevinloughlin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240110012640.1335694-1-kevinloughlin@google.com> On Wed, Jan 10, 2024 at 01:26:39AM +0000, Kevin Loughlin wrote: > SEV/SME code can execute prior to page table fixups for kernel That seems to be fundamental problem. > relocation. However, as with global variables accessed in > __startup_64(), clang does not currently generate PC-relative accesses > for SEV/SME global variables, causing certain flavors of SEV hosts and > guests to crash. And that's a hack to work around it. > > While an attempt was made to force PC-relative addressing for certain > global SEV/SME variables via inline assembly (see snp_cpuid_get_table() > for example), PC-relative addressing must be pervasively-enforced for > SEV/SME global variables that can be accessed prior to page table > fixups. > > To avoid the error-prone approach of manually referencing each SEV/SME > global variable via a general form of snp_cpuid_get_table(), it is > preferable to use compiler flags for position-independent code (ex: But if gcc doesn't support it then it doesn't work. It seems your approach with incompatible execution models between the compilers is just a recipe for future patches only working on one of the compilers because most code submitters probably won't test both. It would be better to at least use a unified execution model, if you want to extend the hack and not fix the underlying issue. -Andi