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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F14BC433F5 for ; Fri, 12 Nov 2021 20:55:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B4A661073 for ; Fri, 12 Nov 2021 20:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235612AbhKLU6h (ORCPT ); Fri, 12 Nov 2021 15:58:37 -0500 Received: from mail.skyhub.de ([5.9.137.197]:48400 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235576AbhKLU6h (ORCPT ); Fri, 12 Nov 2021 15:58:37 -0500 Received: from zn.tnic (p4fed33a9.dip0.t-ipconnect.de [79.237.51.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 85A0B1EC0529; Fri, 12 Nov 2021 21:55:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1636750544; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=YSgDHuKhBpkqw17ADxN7YSfqRqwjIHqhI8doQGc8d10=; b=rbgux9nzUu8Q/zoKBmWrR/YgJ7Ku6OSXgzE0pVkFuiK98PVCh6uGpkU3qd4ejG1hZQ7mp0 6OYwPqXWT3HM/txQIgbGGHLUQZNj1c2qPLne7SUNQZX6A5W69/5rZTzSp7wTk98BqH/qd/ hzKC4giut7QEt0uq7X0O2e4KkbVFJzM= Date: Fri, 12 Nov 2021 21:53:28 +0100 From: Borislav Petkov To: Sean Christopherson Cc: Dave Hansen , Peter Gonda , Brijesh Singh , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH Part2 v5 00/45] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support Message-ID: References: <20210820155918.7518-1-brijesh.singh@amd.com> <061ccd49-3b9f-d603-bafd-61a067c3f6fa@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Nov 12, 2021 at 08:37:59PM +0000, Sean Christopherson wrote: > Let userspace decide what is mapped shared and what is mapped private. With "userspace", you mean the *host* userspace? > The kernel and KVM provide the APIs/infrastructure to do the actual > conversions in a thread-safe fashion and also to enforce the current > state, but userspace is the control plane. > > It would require non-trivial changes in userspace if there are multiple processes > accessing guest memory, e.g. Peter's networking daemon example, but it _is_ fully > solvable. The exit to userspace means all three components (guest, kernel, > and userspace) have full knowledge of what is shared and what is private. There > is zero ambiguity: > > - if userspace accesses guest private memory, it gets SIGSEGV or whatever. That SIGSEGV is generated by the host kernel, I presume, after it checks whether the memory belongs to the guest? > - if kernel accesses guest private memory, it does BUG/panic/oops[*] If *it* is the host kernel, then you probably shouldn't do that - otherwise you just killed the host kernel on which all those guests are running. > - if guest accesses memory with the incorrect C/SHARED-bit, it gets killed. Yah, that's the easy one. > This is the direction KVM TDX support is headed, though it's obviously still a WIP. > > And ideally, to avoid implicit conversions at any level, hardware vendors' ABIs > define that: > > a) All convertible memory, i.e. RAM, starts as private. > b) Conversions between private and shared must be done via explicit hypercall. I like the explicit nature of this but devil's in the detail and I'm no virt guy... > Without (b), userspace and thus KVM have to treat guest accesses to the incorrect > type as implicit conversions. > > [*] Sadly, fully preventing kernel access to guest private is not possible with > TDX, especially if the direct map is left intact. But maybe in the future > TDX will signal a fault instead of poisoning memory and leaving a #MC mine. Yah, the #MC thing sounds like someone didn't think things through. ;-\ Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette