Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1542934rdb; Wed, 31 Jan 2024 01:36:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV+4Vk0WhSwVKdnsjs+/Zbz2RW07aiB/svo76+iy/4p86+Lr8W1g5AFhPOLxOQV+hVRnV6 X-Received: by 2002:a50:e612:0:b0:55e:f37f:7fc5 with SMTP id y18-20020a50e612000000b0055ef37f7fc5mr700844edm.14.1706693804935; Wed, 31 Jan 2024 01:36:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706693804; cv=pass; d=google.com; s=arc-20160816; b=BpD3cj5RpZePsWIh+ushsmFkNQFbTmCvDIMAng6ude+aBu8ycLKTsM0JQ+JGqTY88W B3CKN1JkLWnHHw9HT2oiDXh4Usf1LiWjUPLyf3lvAHqf8FWc+0o2gbPeHYzJBgrbn5UY 4FeD5sQgyIY4F9QN+8Nveo3RutfzVTzHJwppVBz/25P+GiAR9klpc+ftH9MM3HerllX0 r7zkpW8EI0j8hBZ98TCBu0caKkP8+MdZtFGxFNtJ0eMRD/XHJvCTwCCbx+CzqLR5sruK a+4vMTM49DjpuUBc8RMlYMoAoP4B2Mdwupa1gaURr4u/9lasFAJJITAwqmiMCGcyg3p2 B4yQ== ARC-Message-Signature: i=2; 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=yq04UwTxclfBTnFy5Mbh/qb05029ngBZG7oqlMpt1cA=; fh=EatoDzUyXjkIWpwfsdcXRi97wapW+x/Ex8BCdlVyyJs=; b=y7DqY+tfgsKP8lU9/hXaHMnSo3VHu6ENT+4zitsAE+QvM40EXrQqzP0i7pj0wywslo 9NiIFcYYJ0lgIahduKeCeSK1H04Bj+vRDiY87ocGS1tru3Iz9hh5MLRabmCIYVpjV6/c PlR+1GEVGgI9qKbimqpLE8BYqI1ZBYC8D7mmPF75XezKBxvLl67nEvwr1LMmnRpOoluF fnLLdk1LBqrvR891zK+F67IXQ+5N+tcDq70c0vT7KJDq8B7xSRLDxhURHPoU1RZYYPHp YOY17nIFCX4lkIFPuAitrxIgIMIFNij1s8RoOE5yrRauk27WMMvClcUg/XA47ugDD987 tHpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iRxQFIrn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUhX6NthmS/h6XUwMsAA2gZgbbTXE8T2r4ILNoMnNiYbKmgOUekiJwhjyA/3T3OCYRjXhmy0r39BtUjRWlLOzMvU2CFdJDmNLZH+BS9hg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v13-20020aa7d80d000000b0055f28ce36fdsi2021835edq.664.2024.01.31.01.36.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 01:36:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45985-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=iRxQFIrn; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45985-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45985-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 904261F26CBF for ; Wed, 31 Jan 2024 08:20:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE28F5810E; Wed, 31 Jan 2024 08:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iRxQFIrn" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 7874E57895 for ; Wed, 31 Jan 2024 08:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706689238; cv=none; b=STkLzH3poqAM+ycM1uRtCEza5W4bhJID9M7Mr/XpJMwgOghAuf4mDwjV1h7n6JlYlS3+SWT22G6sSAbpBwWRRLKGmArmGlVQPMzwoWuKuwYUWiog8xFN2GhFTnnoxuAiaMUpEJw3BwFVUTlUfuLAd/PZgV5nHB/CQTi3ofSw7ok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706689238; c=relaxed/simple; bh=SGzk9JA5A4WdBx6j64XS/jDdmN0WOY6psDzBiqQDpNc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hz45pmBBeRIXaGZmhDk1vNhefd+tzcxnYe4AYBHApzx4wwEn5NSpFf49cSwbAdub+NznC5ZaEI1cBimtp/Y6PQCfdaPj3cRepTpbZIOoSMOostqvsO45+MDJXUOwOjBfKuBVwpPejdP0BVn13swUSbEuv8k/zauiGUjnCz9XmQo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iRxQFIrn; arc=none smtp.client-ip=198.175.65.9 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=1706689238; x=1738225238; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=SGzk9JA5A4WdBx6j64XS/jDdmN0WOY6psDzBiqQDpNc=; b=iRxQFIrnH4IFoaWsM9BdI1qOQ2RvYKorE0hGBsYDw97EnJe9tTJuDoDF yldgXjW08t7JXK/trzvnWqfy9dyOm984wHmVKRZ95jVuSdGH+bPgjSJ43 2d7CEWzIgHOQiNDzQwVxbco/NlyXhy2pf7Agf4QMfgxrtqHIGJw+Gf6+U QtPlflGrTeWOVoB82azGDykvqBKBQdI9p0HS3uIdhLwwuBTNnzglmne7w TzOpkxOs8HvYQZNP07TN4EGvc9A4xMPnAukPIOao/ojQ/6gCxpgp02cxq a163HC+WsbMq7rO09i2+Zpmtaz9XQ2AIq79rbGLhMYuWSg3sSyMQvMfAA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="22041371" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="22041371" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 00:20:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="738021278" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="738021278" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 31 Jan 2024 00:20:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 146D22D5; Wed, 31 Jan 2024 10:20:29 +0200 (EET) Date: Wed, 31 Jan 2024 10:20:28 +0200 From: "Kirill A. Shutemov" To: Kevin Loughlin Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Nick Desaulniers , Justin Stitt , Tom Lendacky , Pankaj Gupta , Hou Wenlong , Ard Biesheuvel , 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 Subject: Re: [PATCH v3 1/2] x86/sev: enforce RIP-relative accesses in early SEV/SME code Message-ID: <4ljfvg7c23g2wx4hcqz6x6tx7uvp6fffayqvu4ptsmfqajlujr@zngokbd2awma> References: <20240121182040.GBZa1geI5NxWSslvt0@fat_crate.local> <20240130220845.1978329-2-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: <20240130220845.1978329-2-kevinloughlin@google.com> On Tue, Jan 30, 2024 at 10:08:44PM +0000, Kevin Loughlin wrote: > diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h > index 359ada486fa9..b65e66ee79c4 100644 > --- a/arch/x86/include/asm/mem_encrypt.h > +++ b/arch/x86/include/asm/mem_encrypt.h > @@ -17,6 +17,20 @@ > > #include > > +/* > + * Like the address operator "&", evaluates to the address of a LHS variable > + * "var", but also enforces the use of RIP-relative logic. This macro can be > + * used to safely access global data variables prior to kernel relocation. > + */ > +#define RIP_RELATIVE_ADDR(var) \ > +({ \ > + void *rip_rel_ptr; \ > + asm ("lea "#var"(%%rip), %0" \ > + : "=r" (rip_rel_ptr) \ > + : "p" (&var)); \ > + rip_rel_ptr; \ > +}) > + I don't think it is the right place for the macro. The next patch uses for things unrelated to memory encryption. > @@ -239,14 +244,14 @@ unsigned long __head __startup_64(unsigned long physaddr, > */ > > next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr); > - pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); > - pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr); > + early_dynamic_pgts_ptr = fixup_pointer(early_dynamic_pgts, physaddr); > + pud = (pudval_t *) early_dynamic_pgts_ptr[(*next_pgt_ptr)++]; > + pmd = (pmdval_t *) early_dynamic_pgts_ptr[(*next_pgt_ptr)++]; > This change doesn't belong to this patch. Maybe move it into the next patch and combine with removing fixup_pointer(). -- Kiryl Shutsemau / Kirill A. Shutemov