From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6EBC433EF for ; Thu, 16 Dec 2021 23:40:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBF5C6B0071; Thu, 16 Dec 2021 18:39:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6F5A6B0073; Thu, 16 Dec 2021 18:39:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0F586B0074; Thu, 16 Dec 2021 18:39:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id AE5116B0071 for ; Thu, 16 Dec 2021 18:39:50 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 606F2180D32EC for ; Thu, 16 Dec 2021 23:39:40 +0000 (UTC) X-FDA: 78925276920.31.57E3790 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by imf03.hostedemail.com (Postfix) with ESMTP id 04F3A20006 for ; Thu, 16 Dec 2021 23:39:39 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id k37so1114498lfv.3 for ; Thu, 16 Dec 2021 15:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m/LjgsVegt/HRyKkkM2n6c0UK9wyNwAZfK1yqCRibBE=; b=ZjNYT24fop4NBsOLESN28pcPFI76P21GY15lEKVa1tKR8Y6MixFR71XXHM7GhfF9Om Mic+/EDIsAL+Oy0aBQJNKwWOjgm51UPxF4cZ/YnojHbYK5t7OKs/w0RJ0fMV/Jty5UP3 GD7cR728r/nXnJAOmo8UvAJPlaoac5Lt5ox6J43oGgiSlI+tzAmdbkGHwKtBLR6b03CD 7oHTeGaKYJVODZhzKZPRa/GHySInjAASy4QEqvKVn6IABK89mCJ8zObuLFxxpFd4M9oY nNbcSS9gTr2YJoL93pnZ4nD3gzT76+OThD67D+uVZQJZKT64KbSwJ1kM4lJaQvROfOCD Mpsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m/LjgsVegt/HRyKkkM2n6c0UK9wyNwAZfK1yqCRibBE=; b=FkUCxGspGXwMEO4Rvm/WdHd29v3trwHjOImaA+9KA/Dqh+awDU8FyikQPbzME5R5wC 1yKVJgoWHV520j17l9sPB4IWz/waoDL2vZgpNvhFK3eOE0IiLN0HF91ILIEPCDVViS9o vWUkPbp/6+MsTn31xQRnCXeNui4QPZe9GEDPTakVcjfkMWoNoFljng7VPoFZZuKR1dU5 EkbUpMXiWGQGM83ZLRCXySeWB0dvaPvzmABr0+Sr7gn/BMwjDb/GusvCdeLN3S2Ig+N5 9jaWj1kdXlfvkng8pUyM89MjVk7g1OdK8Fic44jpWdFobqa1fN/PjI4bens43aeiFdu/ EP8Q== X-Gm-Message-State: AOAM532w0rHN0s/Og3Dbqs2hFTrjcCiX2fYuX10dnDzu2vSpJchGZkn5 ogyYXec1EQlLj6adPxlrDOHGN+S/ZJyPRDJ5I7dxrA== X-Google-Smtp-Source: ABdhPJzJ3Ag+Yv1KTmSJebYEdW20IHyaYIzqo6gVs4G5mbbZ7dHZUudFFNmxFE9zK8L0+gvaxQYp82IZFk5AQAuq/rc= X-Received: by 2002:a05:6512:1324:: with SMTP id x36mr432363lfu.495.1639697978059; Thu, 16 Dec 2021 15:39:38 -0800 (PST) MIME-Version: 1.0 References: <20211210154332.11526-1-brijesh.singh@amd.com> <20211210154332.11526-9-brijesh.singh@amd.com> In-Reply-To: From: Mikolaj Lisik Date: Thu, 16 Dec 2021 15:39:26 -0800 Message-ID: Subject: Re: [PATCH v8 08/40] x86/sev: Check the vmpl level To: Venu Busireddy Cc: Brijesh Singh , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 04F3A20006 X-Stat-Signature: 4si461dqimzrghh43xiua4d1fk8crwt9 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZjNYT24f; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of lisik@google.com designates 209.85.167.43 as permitted sender) smtp.mailfrom=lisik@google.com X-Rspamd-Server: rspam11 X-HE-Tag: 1639697979-72877 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Dec 16, 2021 at 12:24 PM Venu Busireddy wrote: > > On 2021-12-10 09:43:00 -0600, Brijesh Singh wrote: > > Virtual Machine Privilege Level (VMPL) feature in the SEV-SNP architecture > > allows a guest VM to divide its address space into four levels. The level > > can be used to provide the hardware isolated abstraction layers with a VM. > > The VMPL0 is the highest privilege, and VMPL3 is the least privilege. > > Certain operations must be done by the VMPL0 software, such as: > > > > * Validate or invalidate memory range (PVALIDATE instruction) > > * Allocate VMSA page (RMPADJUST instruction when VMSA=1) > > > > The initial SEV-SNP support requires that the guest kernel is running on > > VMPL0. Add a check to make sure that kernel is running at VMPL0 before > > continuing the boot. There is no easy method to query the current VMPL > > level, so use the RMPADJUST instruction to determine whether the guest is > > running at the VMPL0. > > > > Signed-off-by: Brijesh Singh > > --- > > arch/x86/boot/compressed/sev.c | 34 ++++++++++++++++++++++++++++--- > > arch/x86/include/asm/sev-common.h | 1 + > > arch/x86/include/asm/sev.h | 16 +++++++++++++++ > > 3 files changed, 48 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c > > index a0708f359a46..9be369f72299 100644 > > --- a/arch/x86/boot/compressed/sev.c > > +++ b/arch/x86/boot/compressed/sev.c > > @@ -212,6 +212,31 @@ static inline u64 rd_sev_status_msr(void) > > return ((high << 32) | low); > > } > > > > +static void enforce_vmpl0(void) > > +{ > > + u64 attrs; > > + int err; > > + > > + /* > > + * There is no straightforward way to query the current VMPL level. The > > + * simplest method is to use the RMPADJUST instruction to change a page > > + * permission to a VMPL level-1, and if the guest kernel is launched at > > + * a level <= 1, then RMPADJUST instruction will return an error. > > Perhaps a nit. When you say "level <= 1", do you mean a level lower than or > equal to 1 semantically, or numerically? > +1 to this. Additionally I found the "level-1" confusing which I interpreted as "level minus one". Perhaps phrasing it as "level one", or "level=1" would be more explicit?