Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753338AbdHXRyT (ORCPT ); Thu, 24 Aug 2017 13:54:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752640AbdHXRyS (ORCPT ); Thu, 24 Aug 2017 13:54:18 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E275A7DD0B Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH 1/3] KVM: x86: block guest protection keys unless the host has them enabled To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: junkang.fjk@alibaba-inc.com, yang.zhang.wz@gmail.com References: <1503569573-55057-1-git-send-email-pbonzini@redhat.com> <1503569573-55057-2-git-send-email-pbonzini@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <77a8f441-651e-c77a-4c5c-e9a6b93f7480@redhat.com> Date: Thu, 24 Aug 2017 19:54:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1503569573-55057-2-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 Aug 2017 17:54:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1196 Lines: 35 On 24.08.2017 12:12, Paolo Bonzini wrote: > If the host has protection keys disabled, we cannot read and write the > guest PKRU---RDPKRU and WRPKRU fail with #GP(0) if CR4.PKE=0. Block > the PKU cpuid bit in that case. > > This ensures that guest_CR4.PKE=1 implies host_CR4.PKE=1. > > Fixes: 1be0e61c1f255faaeab04a390e00c8b9b9042870 > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/cpuid.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 59ca2eea522c..19adbb418443 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -469,7 +469,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > entry->ecx &= kvm_cpuid_7_0_ecx_x86_features; > cpuid_mask(&entry->ecx, CPUID_7_ECX); > /* PKU is not yet implemented for shadow paging. */ > - if (!tdp_enabled) > + if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE)) > entry->ecx &= ~F(PKU); > entry->edx &= kvm_cpuid_7_0_edx_x86_features; > entry->edx &= get_scattered_cpuid_leaf(7, 0, CPUID_EDX); > Reviewed-by: David Hildenbrand -- Thanks, David