From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH v4 2/4] KVM: Add SMAP support when setting CR4 Date: Fri, 11 Apr 2014 20:14:06 -0400 Message-ID: <5348854E.4010007@redhat.com> References: <1396345596-25682-1-git-send-email-feng.wu@intel.com> <1396345596-25682-3-git-send-email-feng.wu@intel.com> <20140410201234.GB26092@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: gleb@redhat.com, hpa@zytor.com, kvm@vger.kernel.org To: Marcelo Tosatti , Feng Wu Return-path: Received: from mail-yh0-f49.google.com ([209.85.213.49]:58615 "EHLO mail-yh0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750842AbaDLAOU (ORCPT ); Fri, 11 Apr 2014 20:14:20 -0400 Received: by mail-yh0-f49.google.com with SMTP id z6so5993239yhz.22 for ; Fri, 11 Apr 2014 17:14:20 -0700 (PDT) In-Reply-To: <20140410201234.GB26092@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: Il 10/04/2014 16:12, Marcelo Tosatti ha scritto: > On Tue, Apr 01, 2014 at 05:46:34PM +0800, Feng Wu wrote: >> This patch adds SMAP handling logic when setting CR4 for guests >> >> Thanks a lot to Paolo Bonzini for his suggestion to use the branchless >> way to detect SMAP violation. >> >> Signed-off-by: Feng Wu >> >> @@ -110,10 +118,30 @@ static inline bool is_write_protection(struct kvm_vcpu *vcpu) >> * Will a fault with a given page-fault error code (pfec) cause a permission >> * fault with the given access (in ACC_* format)? >> */ >> -static inline bool permission_fault(struct kvm_mmu *mmu, unsigned pte_access, >> - unsigned pfec) >> +static inline bool permission_fault(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, >> + unsigned pte_access, unsigned pfec) >> { >> - return (mmu->permissions[pfec >> 1] >> pte_access) & 1; >> + int cpl = kvm_x86_ops->get_cpl(vcpu); >> + unsigned long rflags = kvm_x86_ops->get_rflags(vcpu); > > Some branches added here (can't think of anything useful to avoid them). Yeah, but most of them should be well predicted. Paolo