Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1362528rwb; Tue, 29 Nov 2022 12:30:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GIhJBt623gsEbRJFGyP1nyAh8g26af1mEFYxx8OykNL0r5zzQHvEF5qSLl12cOJDcfG+k X-Received: by 2002:a63:1817:0:b0:477:fd2e:370d with SMTP id y23-20020a631817000000b00477fd2e370dmr14972888pgl.121.1669753843559; Tue, 29 Nov 2022 12:30:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669753843; cv=none; d=google.com; s=arc-20160816; b=QMMxpY7PkBIYqxvMfbmqadiXj6Ki/74bGRY183Eb6iFigNu/o1dQL0nTAMlcQ2DDxP 8fhlzghsF/Gw2gqHgWY7bYFUIFJuKy52ZSzAzuVo2IKKvbzGczjT0VEh4oQQDFXt1a5E 1cYHmAXhIBTNytdqQeb8pz0fSq5SuvABOWjt1RpX4RQLrWexva+0rq/7cE7QS+weNa1S KCtr93oFEKWfMgWdt+GyOO4jSz1cOpX/yG5CLkM8LpicZlLKL2olT1i2gS2McLHjiIyq gzb4PMIkFSdw+SSNFSG+cyUaXcPSBiEf8umhV4S7WHiAaSTpCmIk8g2E31MkvxZEhuaX 2/jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IsK6SeDRcKB0ngx9XBGmKXR4JOxNBat2MjmDlSq9EM0=; b=TyB1O9Bmb1oNb1f03eJpwvbst6TyIVX9u08LexwuBkPZ8tJ6qqt/sHTyLhjCgCbOW9 RMT2S8avyIN0fB67OGjbzEOFQkz7Ao1RcdkwXA3cV+ndwQInDbOl7HHy4HcIPZkP82Ci 3l++2jZ+COyFKgGDl4DsGB9lYEqZyxuccXSQK3fiZC0ZKG7cayg1imyhO5hS6JzGi2N6 IUE+Xv2dy9WZx3x3rpBhyCClGXQjZjUVey10t5KGlGQEZwCSyCf/XQB/XIbwwDNsBhFf fFnc+13pCPNcSBnR7KRvhUaWmVamwfFVJnLam33j/2gz27SrZ+ebrj45aCF/47MSeuxJ DLRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d7CfkZ02; 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 d18-20020a170902ced200b0018946b0b641si17613261plg.371.2022.11.29.12.30.31; Tue, 29 Nov 2022 12:30:43 -0800 (PST) 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=d7CfkZ02; 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 S237121AbiK2Tkp (ORCPT + 84 others); Tue, 29 Nov 2022 14:40:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236072AbiK2TkU (ORCPT ); Tue, 29 Nov 2022 14:40:20 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020CFE75 for ; Tue, 29 Nov 2022 11:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669750655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IsK6SeDRcKB0ngx9XBGmKXR4JOxNBat2MjmDlSq9EM0=; b=d7CfkZ02PyamPHn618NQc3H0ZxH0am2qPWhPquEKJ+R9Cf9h2IzG7akOnevRl5uc4bv8xK MQK296EWd9PCCJGHECxIHu94VBZXxwR0aTxkUnXW+vLIdXt8F4DMN3n+dZFN0E9MXs5poF pj/6AxTnjpV30bDfgN0KTWQxQF0v7W8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-m87UuQubOz2LL_yd13l6nA-1; Tue, 29 Nov 2022 14:37:32 -0500 X-MC-Unique: m87UuQubOz2LL_yd13l6nA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03F3D86EB22; Tue, 29 Nov 2022 19:37:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43C6A2027061; Tue, 29 Nov 2022 19:37:27 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Sandipan Das , Paolo Bonzini , Jim Mattson , Peter Zijlstra , Dave Hansen , Borislav Petkov , Pawan Gupta , Thomas Gleixner , Ingo Molnar , Josh Poimboeuf , Daniel Sneddon , Jiaxi Chen , Babu Moger , linux-kernel@vger.kernel.org, Jing Liu , Wyes Karny , x86@kernel.org, "H. Peter Anvin" , Sean Christopherson , Maxim Levitsky Subject: [PATCH v2 02/11] KVM: nSVM: clean up the copying of V_INTR bits from vmcb02 to vmcb12 Date: Tue, 29 Nov 2022 21:37:08 +0200 Message-Id: <20221129193717.513824-3-mlevitsk@redhat.com> In-Reply-To: <20221129193717.513824-1-mlevitsk@redhat.com> References: <20221129193717.513824-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 the V_IRQ and v_TPR bits don't exist when virtual interrupt masking is not enabled, therefore the KVM should not copy these bits regardless of V_IRQ intercept. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 37af0338da7c32..aad3145b2f62fe 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -412,24 +412,17 @@ void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm, */ void nested_sync_control_from_vmcb02(struct vcpu_svm *svm) { - u32 mask; + u32 mask = 0; svm->nested.ctl.event_inj = svm->vmcb->control.event_inj; svm->nested.ctl.event_inj_err = svm->vmcb->control.event_inj_err; - /* Only a few fields of int_ctl are written by the processor. */ - mask = V_IRQ_MASK | V_TPR_MASK; - if (!(svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK) && - svm_is_intercept(svm, INTERCEPT_VINTR)) { - /* - * In order to request an interrupt window, L0 is usurping - * svm->vmcb->control.int_ctl and possibly setting V_IRQ - * even if it was clear in L1's VMCB. Restoring it would be - * wrong. However, in this case V_IRQ will remain true until - * interrupt_window_interception calls svm_clear_vintr and - * restores int_ctl. We can just leave it aside. - */ - mask &= ~V_IRQ_MASK; - } + /* + * Only a few fields of int_ctl are written by the processor. + * Copy back only the bits that are passed through to the L2. + */ + + if (svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK) + mask = V_IRQ_MASK | V_TPR_MASK; if (nested_vgif_enabled(svm)) mask |= V_GIF_MASK; -- 2.26.3