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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA6A6C54EAA for ; Mon, 30 Jan 2023 16:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237788AbjA3Qvb (ORCPT ); Mon, 30 Jan 2023 11:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237786AbjA3Qv3 (ORCPT ); Mon, 30 Jan 2023 11:51:29 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9860D3D924; Mon, 30 Jan 2023 08:51:28 -0800 (PST) Received: by linux.microsoft.com (Postfix, from userid 1112) id 545E520E9F90; Mon, 30 Jan 2023 08:51:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 545E520E9F90 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1675097488; bh=Rre807gZOD8p3UjEPIEDW03aOt59zeNQl9BBuzqfJEk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cVGOuGrQcD9FeB99Y2w7DhbLdk5fP+8qpcUKdTU62R8tBsyKuLpz6sI4v6/NlW8dX NvQGyCzW1L4zCTqRT1ktmHEXfdOWqW+AaoCg3UPP5xdzq4J0wOpDs2KBkhI2mMAKTl +T7ZzjIP0llz6bMj7OBnHGBplAF96j6oXZ4cpPmM= Date: Mon, 30 Jan 2023 08:51:28 -0800 From: Jeremi Piotrowski To: "Michael Kelley (LINUX)" Cc: "linux-kernel@vger.kernel.org" , Wei Liu , Dexuan Cui , Tianyu Lan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "linux-hyperv@vger.kernel.org" , Brijesh Singh , Michael Roth , Ashish Kalra , Tom Lendacky Subject: Re: [RFC PATCH v1 3/6] x86/sev: Maintain shadow rmptable on Hyper-V Message-ID: <20230130165128.GC27645@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20230123165128.28185-1-jpiotrowski@linux.microsoft.com> <20230123165128.28185-4-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 29, 2023 at 04:37:24AM +0000, Michael Kelley (LINUX) wrote: > From: Jeremi Piotrowski Sent: Monday, January 23, 2023 8:51 AM > > > > Hyper-V can expose the SEV-SNP feature to guests, and manages the > > system-wide RMP (Reverse Map) table. The SNP implementation in the > > kernel needs access to the rmptable for tracking pages and deciding > > when/how to issue rmpupdate/psmash. When running as a Hyper-V guest > > with SNP support, an rmptable is allocated by the kernel during boot for > > this purpose. Keep the table in sync with issued rmpupdate/psmash > > instructions. > > > > The logic for how to update the rmptable comes from "AMD64 Architecture > > Programmer’s Manual, Volume 3" which describes the psmash and rmpupdate > > instructions. To ensure correctness of the SNP host code, the most > > important fields are "assigned" and "page size". > > > > Signed-off-by: Jeremi Piotrowski > > --- > > arch/x86/kernel/sev.c | 59 +++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 59 insertions(+) > > > > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > > index 95404c7e5150..edec1ccb80b1 100644 > > --- a/arch/x86/kernel/sev.c > > +++ b/arch/x86/kernel/sev.c > > @@ -26,6 +26,7 @@ > > #include > > #include > > > > +#include > > The code in sev.c should be generic and appropriate for use with any > hypervisor. As such, I think we want to avoid sev.c having a dependency > on Hyper-V specific code, such as the include file > and the ms_hyperv.nested_features variable as used below. > > Instead, create a boolean static variable in the sev.c module along with > a wrapper function to set it. The logic that tests hv_no_rmp_table() > should test this static variable instead, which would default to "false". > Hypervisor-specific initialization code can call the wrapper function > to set the variable to "true" based on whatever logic is appropriate for > the hypervisor. This approach reverses the dependency and hopefully > is usable by other hypervisors that want to offer nested SNP support. > ok, this makes sense. I've added a call to the wrapper to the init_mem_mapping callback added before so that it is enabled together with allocating the rmptable.