From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E28C433E0 for ; Tue, 2 Feb 2021 17:29:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E60C264F69 for ; Tue, 2 Feb 2021 17:29:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237509AbhBBR3h (ORCPT ); Tue, 2 Feb 2021 12:29:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60424 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237531AbhBBR0A (ORCPT ); Tue, 2 Feb 2021 12:26:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612286674; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0TUQT22ZC2nt5C6/vYK8TRYYduebyaAtrXwi+hOcJow=; b=JuJ8pUL/QQ3szxUVr0ulsHGHWx3XrvibxGIVxGKKw/xgxks6C4AizZauwRD9SEJfbYU50W B0ORYaKbLQdLX3/2Pgy4ViBFXxNYMtPbpZB8P7IQDzeQLlOO76ZxKfWk4bgze3/O519W+q PmlHGOzZctGUU/XYOsy0dvC5StuhY8s= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-198-opwVtqk4N_u-ZPf0zfw8dg-1; Tue, 02 Feb 2021 12:24:33 -0500 X-MC-Unique: opwVtqk4N_u-ZPf0zfw8dg-1 Received: by mail-ej1-f69.google.com with SMTP id dc21so10325421ejb.19 for ; Tue, 02 Feb 2021 09:24:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=0TUQT22ZC2nt5C6/vYK8TRYYduebyaAtrXwi+hOcJow=; b=fHUb9b6lnYZ52ghZEP4tjjBYdXrqPUvdcSPS6KsxhWjCMYsIr/+bmLCFRQ2D1lX015 9c+QBKG6j9TF+z1yCds7ORk1/LC3AdJK4sLWyvZqT0SxAdoVnBprWLvfpdF7dhKSsAVO dqLOMpmMFgCVv2iVsrXEpeJhEK8/bRRFepEWAKYpY7bQ71R/drr8rd35LdMcd4xrrAUq dREwVaCY0a0GiWGK9Cj0v9+XaF7JsXNLikadC+raRxnKmO5IPbdvP+NFBsr4aLztz48f 7x0ooILz7vzh0IGCNkr86KCcOQQ8DcpVXSXogai4QmCFit2IWdI637h257/Z+h7r4KiM qKLw== X-Gm-Message-State: AOAM532n4AefvFbz6f26gj5++ssATF7AwCILc6PvKAesb5i9fCBNDb0c sdQRTVds/J4FGYdBqrwX6iR90o1KRJhhDw5ji86CNMzaebj/4/rr+1u5+auQd1cEmOAPsgUxxOW xkcDEumJzW6fJJLVDlvezH0e5 X-Received: by 2002:a17:906:f195:: with SMTP id gs21mr11533261ejb.225.1612286672197; Tue, 02 Feb 2021 09:24:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjVVBKcbBzllt4Zcf/z8kxqEOclKt76Dc3cq8QK9c4JMRXZl5/+9Xo95IdhsOb+mdQGQYFFA== X-Received: by 2002:a17:906:f195:: with SMTP id gs21mr11533245ejb.225.1612286671988; Tue, 02 Feb 2021 09:24:31 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f22sm9762527eje.34.2021.02.02.09.24.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Feb 2021 09:24:31 -0800 (PST) Subject: Re: [PATCH 1/3] KVM: x86: move kvm_inject_gp up from kvm_set_xcr to callers To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <20210202165141.88275-1-pbonzini@redhat.com> <20210202165141.88275-2-pbonzini@redhat.com> From: Paolo Bonzini Message-ID: <32428af8-85e7-8a4a-08ca-e1988a0775fd@redhat.com> Date: Tue, 2 Feb 2021 18:24:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/02/21 18:19, Sean Christopherson wrote: > On Tue, Feb 02, 2021, Paolo Bonzini wrote: >> Push the injection of #GP up to the callers, so that they can just use >> kvm_complete_insn_gp. > > The SVM and VMX code is identical, IMO we should push all the code to x86.c > instead of shuffling it around. > > I'd also like to change svm_exit_handlers to take @vcpu instead of @svm so that > SVM can invoke common handlers directly. > > If you agree, I'll send a proper series to do the above, plus whatever other > cleanups I find, e.g. INVD, WBINVD, etc... Yes, why not. There's a lot of things that are only slightly different between VMX and SVM for no particular reason. Paolo > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index fa7b2df6422b..bf917efde35c 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1530,7 +1530,7 @@ int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val); > unsigned long kvm_get_cr8(struct kvm_vcpu *vcpu); > void kvm_lmsw(struct kvm_vcpu *vcpu, unsigned long msw); > void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l); > -int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr); > +int kvm_emulate_xsetbv(struct kvm_vcpu *vcpu); > > int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr); > int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr); > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 687876211ebe..842a74d88f1b 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -2334,14 +2334,7 @@ static int wbinvd_interception(struct vcpu_svm *svm) > > static int xsetbv_interception(struct vcpu_svm *svm) > { > - u64 new_bv = kvm_read_edx_eax(&svm->vcpu); > - u32 index = kvm_rcx_read(&svm->vcpu); > - > - if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) { > - return kvm_skip_emulated_instruction(&svm->vcpu); > - } > - > - return 1; > + return kvm_emulate_xsetbv(&svm->vcpu); > } > > static int rdpru_interception(struct vcpu_svm *svm) > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index cf0c397dc3eb..474a169835de 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5218,16 +5218,6 @@ static int handle_wbinvd(struct kvm_vcpu *vcpu) > return kvm_emulate_wbinvd(vcpu); > } > > -static int handle_xsetbv(struct kvm_vcpu *vcpu) > -{ > - u64 new_bv = kvm_read_edx_eax(vcpu); > - u32 index = kvm_rcx_read(vcpu); > - > - if (kvm_set_xcr(vcpu, index, new_bv) == 0) > - return kvm_skip_emulated_instruction(vcpu); > - return 1; > -} > - > static int handle_apic_access(struct kvm_vcpu *vcpu) > { > if (likely(fasteoi)) { > @@ -5689,7 +5679,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { > [EXIT_REASON_APIC_WRITE] = handle_apic_write, > [EXIT_REASON_EOI_INDUCED] = handle_apic_eoi_induced, > [EXIT_REASON_WBINVD] = handle_wbinvd, > - [EXIT_REASON_XSETBV] = handle_xsetbv, > + [EXIT_REASON_XSETBV] = kvm_emulate_xsetbv, > [EXIT_REASON_TASK_SWITCH] = handle_task_switch, > [EXIT_REASON_MCE_DURING_VMENTRY] = handle_machine_check, > [EXIT_REASON_GDTR_IDTR] = handle_desc, > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 14fb8a138ec3..ef630f8d8bd2 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -984,16 +984,17 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) > return 0; > } > > -int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) > +int kvm_emulate_xsetbv(struct kvm_vcpu *vcpu) > { > if (static_call(kvm_x86_get_cpl)(vcpu) != 0 || > - __kvm_set_xcr(vcpu, index, xcr)) { > + __kvm_set_xcr(vcpu, kvm_rcx_read(vcpu), kvm_read_edx_eax(vcpu))) { > kvm_inject_gp(vcpu, 0); > return 1; > } > - return 0; > + > + return kvm_skip_emulated_instruction(vcpu); > } > -EXPORT_SYMBOL_GPL(kvm_set_xcr); > +EXPORT_SYMBOL_GPL(kvm_emulate_xsetbv); > > bool kvm_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) > { > >