Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2353345pxt; Sun, 8 Aug 2021 21:00:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3zEacU9nHjq5HaEXLPqkLARJmRC8mC8qEPjo4G1PicnfI4OCFB3CjzKTVM8D+6RpZABL8 X-Received: by 2002:a17:906:72ce:: with SMTP id m14mr20189001ejl.394.1628481648231; Sun, 08 Aug 2021 21:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628481648; cv=none; d=google.com; s=arc-20160816; b=yk04XOQ1p9qEflR4TBcgs/m0RMR6OoDrD9GF9jc7YyO+X7MP1ZE6qkXVsxLgkqXtx2 RMvXPAHYdW2cCzszgnEV1oYNotAJrYn4P1sWxW6yWGBnvU9BB1W+yZfmamzmi0yLf7bz JHF90nl/H7cQ3M1zNqUVE5F33cYeJIk7vYtBSO8f/CLQasJVMfH6PCkjJ/HYMtYD5Lmb iq9iTq8Ytz8Glv8WTE5mvdOYvjIUHIWIXK7wcsn2eABUmcZ5islyszmTvSD62F1v1j1a dCieyOF9xVfHKcWiDps6PSasc8x0WuFxkUws+C+ZFC5+JtVR3wy9WP9blgdD0fsJPqzJ BUQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=2nwKIW3Kn+HhP8b9bTAUr2CFIrVR4l0B7T2wqrV8sAk=; b=rNsZGw30Pui69H/xfIz9WjY2qyPE87opaalvwJdyqbwvqA/4qah4pYoBU4PSliovwq aLfTDfWDmoe/E4VCW9Gos/YCUK5wG8N/VI9+JxtdXGvx1sYz7poiIixAnkvziyJUKNum bXnbk4acxmcewprvTP/zDXdi8fjVCHF2aECBXGVexyjGgOUwoG+vroNIVL0Ah2eTVVMv Dlf3V6/6o8kCYfPUm98klPpb/V92pQEePDpIHfU96zRo/l4kPU+pL+874TI5iBGdYu0O QI/4LXkmexPYwz11KltxLENMSYcELElHCZnlKH/zChMff5To2HEbP4TdwBUZeNdVwPV4 eM6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si16586471ejy.710.2021.08.08.21.00.25; Sun, 08 Aug 2021 21:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232953AbhHIDzP (ORCPT + 99 others); Sun, 8 Aug 2021 23:55:15 -0400 Received: from mga05.intel.com ([192.55.52.43]:23274 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232948AbhHIDzO (ORCPT ); Sun, 8 Aug 2021 23:55:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10070"; a="300206608" X-IronPort-AV: E=Sophos;i="5.84,305,1620716400"; d="scan'208";a="300206608" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2021 20:54:54 -0700 X-IronPort-AV: E=Sophos;i="5.84,305,1620716400"; d="scan'208";a="483125279" Received: from arthur-vostro-3668.sh.intel.com ([10.239.13.1]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2021 20:54:49 -0700 From: Zeng Guang To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Dave Hansen , Tony Luck , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , Kai Huang Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Robert Hu , Gao Chao , Zeng Guang Subject: [PATCH v4 5/6] KVM: x86: Support interrupt dispatch in x2APIC mode with APIC-write VM exit Date: Mon, 9 Aug 2021 11:29:24 +0800 Message-Id: <20210809032925.3548-6-guang.zeng@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210809032925.3548-1-guang.zeng@intel.com> References: <20210809032925.3548-1-guang.zeng@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since IA x86 platform introduce features of IPI virtualization and User Interrupts, new behavior applies to the execution of WRMSR ICR register that causes APIC-write VM exit instead of MSR-write VM exit in x2APIC mode. This requires KVM to emulate writing 64-bit value to offset 300H on the virtual-APIC page(VICR) for guest running in x2APIC mode when APIC-wrtie VM exit occurs. Prevoisely KVM doesn't consider this situation as CPU never produce APIC-write VM exit in x2APIC mode before. Signed-off-by: Zeng Guang --- arch/x86/kvm/lapic.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index ba5a27879f1d..0b0f0ce96679 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2188,7 +2188,14 @@ void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset) /* hw has done the conditional check and inst decode */ offset &= 0xff0; - kvm_lapic_reg_read(vcpu->arch.apic, offset, 4, &val); + if (apic_x2apic_mode(vcpu->arch.apic) && (offset == APIC_ICR)) { + u64 icr_val = *((u64 *)(vcpu->arch.apic->regs + offset)); + + kvm_lapic_reg_write(vcpu->arch.apic, APIC_ICR2, (u32)(icr_val>>32)); + val = (u32)icr_val; + } else { + kvm_lapic_reg_read(vcpu->arch.apic, offset, 4, &val); + } /* TODO: optimize to just emulate side effect w/o one more write */ kvm_lapic_reg_write(vcpu->arch.apic, offset, val); -- 2.25.1