Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1191579lqd; Thu, 25 Apr 2024 08:20:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8uNBXcjyrhWI0pStJfE6wFP6uzhMIVVz25YQVYbJ9jCZ6HnUk3rKMvY+PREFn4K/w++eqgfLERzIUKU9NogepVXg5IzjEZgrpTLgQIg== X-Google-Smtp-Source: AGHT+IEhjly3tDOXuY1DeuzEdpehG3440P8KfNKfu/YoaTGklXIB8irQ5wFlSiiCG3lBgnRZMrnt X-Received: by 2002:a05:6a20:2d26:b0:1aa:930d:3dd7 with SMTP id g38-20020a056a202d2600b001aa930d3dd7mr8794238pzl.6.1714058433321; Thu, 25 Apr 2024 08:20:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714058433; cv=pass; d=google.com; s=arc-20160816; b=P/7h2o39sm82DodiYrhdFiLOCmMYLArlP3rPwvvmHHccYC0TU3q5CtYr7Hz49HPCQ+ If0TGEvW49zCxCWtVjT+ezbh+7F8Hz/OnN0ZwNoU2yzBDvBEKmNYiKmzUeIsuoS5i7je qD7EmEZ2idxTwwyCPJ26CoqsEvRAkkE2Aq7VPop6ZR2oXyOSawSYJ/f9WrLvzQelPR84 /zGHwOboodGrsFxkiJAFoJPXlJ2A7X3+NNYrbMTiUcMxfP0J2k6dnJNougqKDB4z9196 PXpdyow1OSiz0wkjyVFTIOgAPuUB9D3uxMLc0LVLxaAUxv+uPLF7pJEM1kf5uijxiU/8 QwWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=hagq2h2jnnv75srLIprAocYGXcrvhuL6tYuMjuGpuwg=; fh=Xi+WReo1vRbc0tmLnxHzjtVwrJe3+PSRi3c87fXUVWA=; b=JHvJ6a8sxsvX7yx8kVJ87wF39RzTBywjKzHLBPZClGnMnDzst49SRWNL42MkM73OTN QQdGIseC7IXP/EM0Hhq1MhlCEdK4cxwy9dxxv0TrKH6Hb6f86ZD9LllAJgIcAM080vr7 Tl8h8wdKB6OamDd1bgASvu5cojgmPGn+lI8MzAwzUw932xwe7yQDUs//V6MSkJuvWFRl mrtbJvCb7+V3GzjWK6Fxo2VH7EY9ZfgAi3FT7vw3CKaVEWT4OGEDtSXPnhzXm66m7OM3 DX5LIdn8KLaXId90dEwXPQux1v01zBEuCKL6I9lXGhX0wZJDoEtsRfbNBgwMzCP8OaFC /vPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xOUKbG9P; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-158771-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ko20-20020a056a00461400b006eaa98c88b5si13629810pfb.64.2024.04.25.08.20.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 08:20:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158771-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=@linutronix.de header.s=2020 header.b=xOUKbG9P; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-158771-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 2AA7F28ACAB for ; Thu, 25 Apr 2024 15:08:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5806414AD2D; Thu, 25 Apr 2024 15:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xOUKbG9P"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="auyRLV2z" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A4A343BBE6; Thu, 25 Apr 2024 15:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714057683; cv=none; b=jbcPvtKdirCoL88IeDaUCA6yzrujEj/AA09PNWm09sqZsT3ZbXkzv3ZyAgpx13qBX1cI2OPBrTLKDTy17TB+qHUGv5+MiU8TQzabBIWkXAnmrgyoF9vrJBmYiYzG+c7KqUJgwkzTMSDNUtspC3R16XxJeQF4PMQfg1CoRq/inE4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714057683; c=relaxed/simple; bh=m74eck4gMpgLFFE08BXb5e06v+Za3er5MGng6KoZ4tA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=PvPXOCElrhIF+Pui7YkxpEYcxWdH2Y5Khd1PxDSX9rDVO3CE4xhbWnG3pAmLe9s+/GcVL3P0IcF7lp1/gO8IISg1TjWOujkq/nia+h+3T8yuwLSLdnAIvmic7BwENcP2NwP5RblTTbY+6roBOHgeEux1otKZY+EmVA7zeMRhZ3I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xOUKbG9P; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=auyRLV2z; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 25 Apr 2024 15:07:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1714057680; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hagq2h2jnnv75srLIprAocYGXcrvhuL6tYuMjuGpuwg=; b=xOUKbG9PfkuhbGh+cVJ4omuyahJKxX98L27N2ZeQnsar6g1L5ZohNvMKDcb7PEEuQbJQIJ kFYSB22ufru9VYpbs4BoNEhzVNuUhzW4katdpbxXB8iQTSJzuaXv7U8GqXKrA5BNtqtvTl reNbTbKAibuST/hW08be/yOKmSazmdAGqj6LN88CFaQjCiwi0bef39en8jg7s3p0WnEWDF RlEbkhVH0e4okFoT+shm/ex3yomNmXx95up/VxVMibYfElmK+0gkckOn+9ITXtoadWTufX czFRuy8Hfsvbpvqy2IV66PBdsfZnrMFZhRaHH+LwZaAc1PWOfZHjHkaozMn7tQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1714057680; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hagq2h2jnnv75srLIprAocYGXcrvhuL6tYuMjuGpuwg=; b=auyRLV2zIO1FsLQh1KjcAeH8Yww109LBnqswt29IkpoX7Ia7XrcokgoQph5vq4xJwP3rXK 8Of67MqGQ+jH+qBg== From: "tip-bot2 for Tom Lendacky" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/sev: Make the VMPL0 checking more straight forward Cc: Tom Lendacky , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Ced01ddf04bfb475596b24b634fd26cffaa85173a=2E17139?= =?utf-8?q?74291=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= References: =?utf-8?q?=3Ced01ddf04bfb475596b24b634fd26cffaa85173a=2E171397?= =?utf-8?q?4291=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171405767963.10875.6117170160698989836.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/sev branch of tip: Commit-ID: e2f4c8c319abd1afbedb7a31877cb569265db1b4 Gitweb: https://git.kernel.org/tip/e2f4c8c319abd1afbedb7a31877cb569265db1b4 Author: Tom Lendacky AuthorDate: Wed, 24 Apr 2024 10:57:59 -05:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 25 Apr 2024 16:14:25 +02:00 x86/sev: Make the VMPL0 checking more straight forward Currently, the enforce_vmpl0() function uses a set argument when modifying the VMPL1 permissions used to test for VMPL0. If the guest is not running at VMPL0, the guest self-terminates. The function is just a wrapper for a fixed RMPADJUST function. Eliminate the function and perform the RMPADJUST directly. No functional change. Signed-off-by: Tom Lendacky Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/ed01ddf04bfb475596b24b634fd26cffaa85173a.1713974291.git.thomas.lendacky@amd.com --- arch/x86/boot/compressed/sev.c | 35 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 5ad0ff4..0457a9d 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -335,26 +335,6 @@ finish: sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ); } -static void enforce_vmpl0(void) -{ - u64 attrs; - int err; - - /* - * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically - * higher) privilege level. Here, clear the VMPL1 permission mask of the - * GHCB page. If the guest is not running at VMPL0, this will fail. - * - * If the guest is running at VMPL0, it will succeed. Even if that operation - * modifies permission bits, it is still ok to do so currently because Linux - * SNP guests are supported only on VMPL0 so VMPL1 or higher permission masks - * changing is a don't-care. - */ - attrs = 1; - if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, attrs)) - sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); -} - /* * SNP_FEATURES_IMPL_REQ is the mask of SNP features that will need * guest side implementation for proper functioning of the guest. If any @@ -588,7 +568,20 @@ void sev_enable(struct boot_params *bp) if (!(get_hv_features() & GHCB_HV_FT_SNP)) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); - enforce_vmpl0(); + /* + * Enforce running at VMPL0. + * + * RMPADJUST modifies RMP permissions of a lesser-privileged (numerically + * higher) privilege level. Here, clear the VMPL1 permission mask of the + * GHCB page. If the guest is not running at VMPL0, this will fail. + * + * If the guest is running at VMPL0, it will succeed. Even if that operation + * modifies permission bits, it is still ok to do so currently because Linux + * SNP guests running at VMPL0 only run at VMPL0, so VMPL1 or higher + * permission mask changes are a don't-care. + */ + if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0); } if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED))