Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp664958pxt; Thu, 5 Aug 2021 08:42:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdWyep6LA+96EWQS52vsYkG089E8xgn10b34FaDFnHYqNyFTcN5sciBvhjg1GxYjRqGKay X-Received: by 2002:a17:906:5ac5:: with SMTP id x5mr5408311ejs.271.1628178167762; Thu, 05 Aug 2021 08:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628178167; cv=none; d=google.com; s=arc-20160816; b=Zre5DBPrrGelDRaXJkf7OPCCrFOY1PQL+hGyHhaD42A5RcKkIc8F8ygoEBQxXQqq0K qSnH4WKB88mg2gyqcDvxhbD/PAF+o0QHqfHkxk0Y3mLEftkiRvxnGccg86wCuKY2NugG kSd4wSjgvvVO33zOPXonS3b+LMKbQUaYgl/ELcEqUqzSnpdvh26ijWZ50qdVqLS0jzd1 JDCHHwPIvjJEhvvnCparvvM65affZ6GxmcnwLIH+Z877Je4y1y6DsTW60ZmfvapFTax3 GMcVw1ShP7tGK2bBePaIHW33tgbKGdISEglJXCImqesbYoAfUPGC52JQjreMCGfxm03p nyIQ== 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=B8N08FW9O2MVl/M1xf9NSONdRZjzCDl8mjyaRbCfqb2IvxiKOQqOZNf/jZlaGXTVh2 TBWIka36kY4pOWZcx207bqFWeF6Mb05kUe4q/UrOldHzWt2wwrYAEI9NiZTqpxTkqNeD SKZawBg9I+JAGDrz0sbGtmclo+kKP6TEAsi/0UhRz/jsHndlrxiSWPL+Gdt6sQb1vBEe oQygeYFOZGUFwEeK6aKzRp7ZH/8sXV6DK9Yz+CEOY+DFBVXtw5CmJu/cpvl86fP8O4+R TG2MD6+7SrssJlqd3o2Hsh4933yf0TjJvUUfFEYkFvVJhYmHQtd9mEGOa3JoOF0uRF28 W47g== 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 u9si2815768edf.583.2021.08.05.08.42.24; Thu, 05 Aug 2021 08:42:47 -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 S242248AbhHEPkK (ORCPT + 99 others); Thu, 5 Aug 2021 11:40:10 -0400 Received: from mga18.intel.com ([134.134.136.126]:50700 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242170AbhHEPjF (ORCPT ); Thu, 5 Aug 2021 11:39:05 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10067"; a="201369443" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="201369443" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 08:38:34 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="512734393" Received: from arthur-vostro-3668.sh.intel.com ([10.239.13.1]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2021 08:38:28 -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 v3 5/6] KVM: x86: Support interrupt dispatch in x2APIC mode with APIC-write VM exit Date: Thu, 5 Aug 2021 23:13:16 +0800 Message-Id: <20210805151317.19054-6-guang.zeng@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210805151317.19054-1-guang.zeng@intel.com> References: <20210805151317.19054-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