Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4479350imw; Tue, 19 Jul 2022 07:22:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tff3ceFoPhDvTgqn6ncFLC3JIQNlNl8XZkNgThS0HNtqpagw2RL4b+A61GaVO6rHbn36Xs X-Received: by 2002:a05:6870:599:b0:f1:67f6:5860 with SMTP id m25-20020a056870059900b000f167f65860mr20485076oap.114.1658240568116; Tue, 19 Jul 2022 07:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240568; cv=none; d=google.com; s=arc-20160816; b=p5daIpMThvxRi2R8p4rDu+U94ocIh4aKLj/L9573qo8Nl+WOtbvBsAe374/G3jBCc9 Xyzp9BHqtmmc1PWP6gN6wYxJfUBizd+YsG5ep37jWGTD2Gv4UFMwd1P1ezzrQlachk5a or3ERNB7OMxJxdfzUMoxvGRpssGv/7jiSkVCIJoc1BvpVX0JTRDcLMC3U1wxG5SNEQAy SVpVE35Zi7c+V9j/mb5yndUvkRNqXFOqEfhBJT8/As7+pCP1jLuYTjTbipiA1tE9JUSD mM0vkkbk8mBOLtPYvAh9RaCbiN+Izr/Hw1EhOZun6onMzG/fE/pW3wBOtLWJisKOuCuF x0pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Z97Q++kaRsbHjLNBJx5eb9ljkY//zciSeUOYhhgbfqc=; b=XfaG2xY0XXqIn3+aWmcU0TwvLjRdEbAFFgDmmN/1XdCG7dv+RT29fVmvCN3vyFGJRX A8l+euM6atu3uabloU0HDa5me552P8r9BZC8/cprH8cACZtxp51qwBMTHLqOf+nsUEi+ g54om5yj8P+1Be8grV6v1ZJ2FxxsjrseNyR3NctTLOJT+guprQ15XazE36H+Kl4ZQSUj g4Fnls2E1JmvjJVANuApHIwu+Aww1Sdu79T28cuBzND7oEVPI2JmcaVQvt9+rkPjLYFC qZDP3+10oPf3x5EzzTp9yL9CqHTWAPEtUsViIMjwgSWuVx3DrKJcEScVUmBYPvHpSgdA bftA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SyDWbG16; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056808201600b003377b9458aesi14572862oiw.234.2022.07.19.07.22.35; Tue, 19 Jul 2022 07:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SyDWbG16; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237534AbiGSN4w (ORCPT + 99 others); Tue, 19 Jul 2022 09:56:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237779AbiGSN4e (ORCPT ); Tue, 19 Jul 2022 09:56:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFF62BB20F for ; Tue, 19 Jul 2022 06:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658236070; 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=Z97Q++kaRsbHjLNBJx5eb9ljkY//zciSeUOYhhgbfqc=; b=SyDWbG16UD+sG7TTd1YVFuD2PGKedKAnxRj/wrW7wxTsIq5BwhESXg12hoC2q1648sHoCg UZJPAhfRsHFQNf7APnI6LWhV8X2pe5haaMOjUgA7/81h7W4/oBy4YVmNUBMdzIueOOltqT tQRDcUfoISXWIJ3QrRh0BwA65HGZvtU= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-WU0sIOv4OH6gD7jGNmJUFw-1; Tue, 19 Jul 2022 09:07:49 -0400 X-MC-Unique: WU0sIOv4OH6gD7jGNmJUFw-1 Received: by mail-ed1-f72.google.com with SMTP id w13-20020a05640234cd00b0043a991fb3f3so9856204edc.3 for ; Tue, 19 Jul 2022 06:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Z97Q++kaRsbHjLNBJx5eb9ljkY//zciSeUOYhhgbfqc=; b=fvDPNRAF0OCXj3JPDxryCIGhx0JHGYGKFN91Jo4u7EOEkKBTqf27gOULuDr4sJulZk KREtXg9ux27mNQ0CQYumzHjSuCtSGU4id746kq65pPs3nevBDshQZzqziuaduTuRn577 LpoPs5WZCiAKd12wg1YlYPIqZfLtyxVAsmk3qRfsEU6NZ1db8AMj7eJ0Xq5dXO25zJYX OLSIKX//c0ptZgXwAiiVP6uGgvkryJl/tmhuaBlOgxzHoI9mFbGQwp7vLCsTpdkqqr/V LqaRbnUuM0oz7jILWYl5ZJlUxa8XhoNTaTxS/v4bzGTMRVOrURiQZI9tLV6Zo8V2iP2o Cdeg== X-Gm-Message-State: AJIora+wT0/i6zX4J00Dmre7UIQo4PwG9gv4kj/bs9IZ8DxpZv4YBN5I aqCvHvNzBnUwACXbH64YtyiyRv/ka5peB8XIz2PqBxD5by/tBDIZ/bny7S85DEL5LZz10QDUcj9 OICdnNCrKbXwvhhKsHwA2KV5O X-Received: by 2002:a17:907:a052:b0:72b:1d92:2aaf with SMTP id gz18-20020a170907a05200b0072b1d922aafmr31030394ejc.197.1658236067467; Tue, 19 Jul 2022 06:07:47 -0700 (PDT) X-Received: by 2002:a17:907:a052:b0:72b:1d92:2aaf with SMTP id gz18-20020a170907a05200b0072b1d922aafmr31030380ejc.197.1658236067249; Tue, 19 Jul 2022 06:07:47 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:9af8:e5f5:7516:fa89? ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.googlemail.com with ESMTPSA id fg14-20020a056402548e00b0043a45dc7158sm10410243edb.72.2022.07.19.06.07.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Jul 2022 06:07:46 -0700 (PDT) Message-ID: <78ba738c-cdf4-350f-119f-298081f215d6@redhat.com> Date: Tue, 19 Jul 2022 15:07:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] KVM: nSVM: Pull CS.Base from actual VMCB12 for soft int/ex re-injection Content-Language: en-US To: "Maciej S. Szmigiero" , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Maxim Levitsky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <4caa0f67589ae3c22c311ee0e6139496902f2edc.1658159083.git.maciej.szmigiero@oracle.com> From: Paolo Bonzini In-Reply-To: <4caa0f67589ae3c22c311ee0e6139496902f2edc.1658159083.git.maciej.szmigiero@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/18/22 17:47, Maciej S. Szmigiero wrote: > From: "Maciej S. Szmigiero" > > enter_svm_guest_mode() first calls nested_vmcb02_prepare_control() to copy > control fields from VMCB12 to the current VMCB, then > nested_vmcb02_prepare_save() to perform a similar copy of the save area. > > This means that nested_vmcb02_prepare_control() still runs with the > previous save area values in the current VMCB so it shouldn't take the L2 > guest CS.Base from this area. > > Explicitly pull CS.Base from the actual VMCB12 instead in > enter_svm_guest_mode(). > > Granted, having a non-zero CS.Base is a very rare thing (and even > impossible in 64-bit mode), having it change between nested VMRUNs is > probably even rarer, but if it happens it would create a really subtle bug > so it's better to fix it upfront. > > Fixes: 6ef88d6e36c2 ("KVM: SVM: Re-inject INT3/INTO instead of retrying the instruction") > Signed-off-by: Maciej S. Szmigiero > --- > arch/x86/kvm/svm/nested.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) Queued, thanks. Paolo > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > index adf4120b05d90..23252ab821941 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -639,7 +639,8 @@ static bool is_evtinj_nmi(u32 evtinj) > } > > static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, > - unsigned long vmcb12_rip) > + unsigned long vmcb12_rip, > + unsigned long vmcb12_csbase) > { > u32 int_ctl_vmcb01_bits = V_INTR_MASKING_MASK; > u32 int_ctl_vmcb12_bits = V_TPR_MASK | V_IRQ_INJECTION_BITS_MASK; > @@ -711,7 +712,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, > svm->nmi_l1_to_l2 = is_evtinj_nmi(vmcb02->control.event_inj); > if (is_evtinj_soft(vmcb02->control.event_inj)) { > svm->soft_int_injected = true; > - svm->soft_int_csbase = svm->vmcb->save.cs.base; > + svm->soft_int_csbase = vmcb12_csbase; > svm->soft_int_old_rip = vmcb12_rip; > if (svm->nrips_enabled) > svm->soft_int_next_rip = svm->nested.ctl.next_rip; > @@ -800,7 +801,7 @@ int enter_svm_guest_mode(struct kvm_vcpu *vcpu, u64 vmcb12_gpa, > nested_svm_copy_common_state(svm->vmcb01.ptr, svm->nested.vmcb02.ptr); > > svm_switch_vmcb(svm, &svm->nested.vmcb02); > - nested_vmcb02_prepare_control(svm, vmcb12->save.rip); > + nested_vmcb02_prepare_control(svm, vmcb12->save.rip, vmcb12->save.cs.base); > nested_vmcb02_prepare_save(svm, vmcb12); > > ret = nested_svm_load_cr3(&svm->vcpu, svm->nested.save.cr3, > @@ -1663,7 +1664,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, > nested_copy_vmcb_control_to_cache(svm, ctl); > > svm_switch_vmcb(svm, &svm->nested.vmcb02); > - nested_vmcb02_prepare_control(svm, svm->vmcb->save.rip); > + nested_vmcb02_prepare_control(svm, svm->vmcb->save.rip, svm->vmcb->save.cs.base); > > /* > * While the nested guest CR3 is already checked and set by >