Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp633944ybm; Wed, 27 May 2020 04:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIHTxiF5MfYWPuoz+pHJZ4AetTLsQ3QTb61IACXFzmFE2gzMCu6q+GBCuKg+OgN57fK+Zw X-Received: by 2002:a17:906:f06:: with SMTP id z6mr5517047eji.105.1590578594050; Wed, 27 May 2020 04:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590578594; cv=none; d=google.com; s=arc-20160816; b=z7yj3UbjczaI0cOqx8EIOmeJzes5Pvzzq1W7ZUkc4ZRF4JyqCAYtnmWHOTp0Kvw0pb DjT0nul+HAl4gMNThjFx4ncZRbCZhy8L97SiE/+btp9NpQ/PEaKHzXht24Qdd0b4Bhq4 LzWF92LlG1mMb9Dmk7QjZtad0S5g18YjKFhZz7wIGMLBE+US38gnWiHICfTklo6WWwz9 EST/5g3q5kPWfMbYPx0q49RsVtVIuKGWcOq+TSXa5oc+mSAINjokIIYxDCDUSC1r4gX/ 0vKWy/s1gx2vl1Rpb4OrZ66gsIEUVaN/s8NW1CSmq6nNhov2EbluNUofhrzRVEa3ZRbD s8AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=q0jQ9rk7E8qWsNw4CvaH5Ijy3rWfI32LAIicudtolMY=; b=KeECSntdT8FH059JGpbeMLC7veX87//XK7/Pn+Gw1k+ylvR6FTMVbYZVAxprxYlZoQ 6gi7uUJu5qvQ31CyXOramM8z589CL4HqJGwaZO8AZXQpI4YrfbRcQjuB9hVqn5bhjhtW HVhx/cp/ngKdU7/uU/MVB6d/hPhSoVLI8B8opwwCmYV+SRlm01uKXKgGejMqvdxhjgEg zW2295IJEpqKwMK4xVoTVQLw10eWN7FBrOZH6AdS4JDIaiYcHBZBwxwBqR7jmfmXC/yC ZWCrsML0EAJiPc2att6Qd/w/84nXVKpOAhpn8DNIo7l866fNHmUdXt+EgygkHzAew9sQ qIPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p90si1362964edd.284.2020.05.27.04.22.51; Wed, 27 May 2020 04:23:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388304AbgE0IwP (ORCPT + 99 others); Wed, 27 May 2020 04:52:15 -0400 Received: from mga07.intel.com ([134.134.136.100]:8402 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388070AbgE0IwO (ORCPT ); Wed, 27 May 2020 04:52:14 -0400 IronPort-SDR: nSAUr2I8YR2pNQ161YXOcfaZO9jMc7IXHbF1FJ27YGZuJIqAXheMPDba4dc5yahZzAKnOlYqyL bnH3DJjxLm5Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 01:52:14 -0700 IronPort-SDR: iEFBK9hw43SNyYE55/qG1GyBCco/ur0BvGwY2RTz4cHM3tJcOd6sfeM9yd3g9AojAeW0S1+lph ri5MUuys8bRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,440,1583222400"; d="scan'208";a="414132602" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by orsmga004.jf.intel.com with ESMTP; 27 May 2020 01:52:14 -0700 Date: Wed, 27 May 2020 01:52:14 -0700 From: Sean Christopherson To: Vitaly Kuznetsov Cc: "Kirill A. Shutemov" , David Rientjes , Andrea Arcangeli , Kees Cook , Will Drewry , "Edgecombe, Rick P" , "Kleen, Andi" , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: Re: [RFC 02/16] x86/kvm: Introduce KVM memory protection feature Message-ID: <20200527085214.GP31696@linux.intel.com> References: <20200522125214.31348-1-kirill.shutemov@linux.intel.com> <20200522125214.31348-3-kirill.shutemov@linux.intel.com> <87d06s83is.fsf@vitty.brq.redhat.com> <20200525151525.qmfvzxbl7sq46cdq@box> <20200527050350.GK31696@linux.intel.com> <87eer56abe.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eer56abe.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2020 at 10:39:33AM +0200, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > On Mon, May 25, 2020 at 06:15:25PM +0300, Kirill A. Shutemov wrote: > >> On Mon, May 25, 2020 at 04:58:51PM +0200, Vitaly Kuznetsov wrote: > >> > > @@ -727,6 +734,15 @@ static void __init kvm_init_platform(void) > >> > > { > >> > > kvmclock_init(); > >> > > x86_platform.apic_post_init = kvm_apic_init; > >> > > + > >> > > + if (kvm_para_has_feature(KVM_FEATURE_MEM_PROTECTED)) { > >> > > + if (kvm_hypercall0(KVM_HC_ENABLE_MEM_PROTECTED)) { > >> > > + pr_err("Failed to enable KVM memory protection\n"); > >> > > + return; > >> > > + } > >> > > + > >> > > + mem_protected = true; > >> > > + } > >> > > } > >> > > >> > Personally, I'd prefer to do this via setting a bit in a KVM-specific > >> > MSR instead. The benefit is that the guest doesn't need to remember if > >> > it enabled the feature or not, it can always read the config msr. May > >> > come handy for e.g. kexec/kdump. > >> > >> I think we would need to remember it anyway. Accessing MSR is somewhat > >> expensive. But, okay, I can rework it MSR if needed. > > > > I think Vitaly is talking about the case where the kernel can't easily get > > at its cached state, e.g. after booting into a new kernel. The kernel would > > still have an X86_FEATURE bit or whatever, providing a virtual MSR would be > > purely for rare slow paths. > > > > That being said, a hypercall plus CPUID bit might be better, e.g. that'd > > allow the guest to query the state without risking a #GP. > > We have rdmsr_safe() for that! :-) MSR (and hypercall to that matter) > should have an associated CPUID feature bit of course. rdmsr_safe() won't fly in early boot, e.g. verify_cpu. It probably doesn't matter for late enabling, but it might save some headache if there's ever a handoff from vBIOS. > Yes, hypercall + CPUID would do but normally we treat CPUID data as > static and in this case we'll make it a dynamically flipping There are multiple examples of dynamic CPUID, e.g. MWAIT and OSPKE. > bit. Especially if we introduce 'KVM_HC_DISABLE_MEM_PROTECTED' later. > > > > >> Note, that we can avoid the enabling algother, if we modify BIOS to deal > >> with private/shared memory. Currently BIOS get system crash if we enable > >> the feature from time zero. > > > > Which would mesh better with a CPUID feature bit. > > > > And maybe even help us to resolve 'reboot' problem. > > -- > Vitaly >