Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1098118pxv; Thu, 22 Jul 2021 22:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwW4cHtDmLrRwDeCj2o9zF1lPPhJoKVhO5pVxZXwBH9ZSsaWLNCz7p39tETSgLB2Mtv15AD X-Received: by 2002:a05:6e02:1d0e:: with SMTP id i14mr2303364ila.50.1627019019189; Thu, 22 Jul 2021 22:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627019019; cv=none; d=google.com; s=arc-20160816; b=IS/T+Vo3texgNTkccgBESCNdDG1fTsYxbZ9eKLYiQ1Y00cqiPd8wkve6H9OVrAaG/6 nFPmF/2eGIJ13mCOMfgE6EHP00HHf/RlT7zvGo7mDX13feaT4xpUK2mMc0AhGGt0ioO9 sfHBcYrepQTnp+edQBxEkGQ07YJZM/Fy1sr+0ZmDQEtUA5ICutlYzZ3t9WOyoXYlKt1m Lyz5GG4U2IMQS4K8ZwZAj0hbpyGBOeqBxyAZ/6Ha1tl9ikgSYYPlDNQ0hn/8dt8KIqLl KTvGbsJlrwMXrNUg4bW1h+V9nlP1Miqwq4GB4uBZZJWWYlpm3fN+ycSEZ21flX2mV1Kz Kaog== 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=YQWeulm6yMWwnTa8s+mIbJ82QdyfavjJh+zr0BvZak4wCG8D/gCW1H2XIVF2cQuy+z 8wtn+iDZoAWegkGfWPfUQFDkUAA7sH/qP3hrFadF2uIsnU0spjph8ri9c7UV4UBmR13o 8Evshc/cAxnipLy/5V68326OWMai1h904aVaVh91IK5QVUrm/UumlGyQizDtaC50axqV 1DQ0MrK9Xxg8nAe8Rrza/yIb/lCT1Wm24po2hWfJxjsFLvh78uisvgdWMvC7+JTKyKf+ K9/JSMamNWEDoryn30J7dFpoOnxJrxm/dCSQIy9cMPnnPEiWbyiQiOLJuIHSrLD8J384 F0gw== 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 u4si22068257jak.4.2021.07.22.22.43.27; Thu, 22 Jul 2021 22:43:39 -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 S233889AbhGWFBE (ORCPT + 99 others); Fri, 23 Jul 2021 01:01:04 -0400 Received: from mga09.intel.com ([134.134.136.24]:34189 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233812AbhGWFBB (ORCPT ); Fri, 23 Jul 2021 01:01:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10053"; a="211818952" X-IronPort-AV: E=Sophos;i="5.84,263,1620716400"; d="scan'208";a="211818952" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2021 22:41:35 -0700 X-IronPort-AV: E=Sophos;i="5.84,263,1620716400"; d="scan'208";a="502383591" 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; 22 Jul 2021 22:41:30 -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 v2 5/6] KVM: x86: Support interrupt dispatch in x2APIC mode with APIC-write VM exit Date: Fri, 23 Jul 2021 13:16:25 +0800 Message-Id: <20210723051626.18364-6-guang.zeng@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210723051626.18364-1-guang.zeng@intel.com> References: <20210723051626.18364-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