From patchwork Sat Dec 31 05:45:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suravee Suthikulpanit X-Patchwork-Id: 9492613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2824360416 for ; Sat, 31 Dec 2016 05:49:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1688422689 for ; Sat, 31 Dec 2016 05:49:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 088C125250; Sat, 31 Dec 2016 05:49:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2742D22689 for ; Sat, 31 Dec 2016 05:49:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cNCVi-000485-9X; Sat, 31 Dec 2016 05:47:18 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cNCVg-00046I-QB for xen-devel@lists.xen.org; Sat, 31 Dec 2016 05:47:17 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id CC/48-18129-36647685; Sat, 31 Dec 2016 05:47:15 +0000 X-Brightmail-Tracker: H4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X-Originating-IP: [104.47.41.42] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51983 invoked from network); 31 Dec 2016 05:47:14 -0000 Received: from mail-dm3nam03on0042.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) (104.47.41.42) by server-7.tower-206.messagelabs.com with AES256-SHA256 encrypted SMTP; 31 Dec 2016 05:47:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=9LEbmFsWz0dQG7H7zCCl9Ez2RjjdfW2FPL2mfmdJLys=; b=IsmBG6pFrM2orwXkR8zMQZmVp/PRlX/EyTh5NPDWNEUNE7+FeCjbXLLGNmTttWglYYXrG2zy/fF1eLXKNcJfGjPd1cv7w+9E7r75AgiImwT4gUWybJX5GpqFWlxWr2dBV6PBFiIxy93X/5pTdIcHYCVM6NEtB0h7prQeSdV/nQU= Received: from localhost.localdomain (114.109.128.54) by MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.789.14; Sat, 31 Dec 2016 05:47:03 +0000 From: Suravee Suthikulpanit To: Date: Fri, 30 Dec 2016 23:45:57 -0600 Message-ID: <1483163161-2402-7-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483163161-2402-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1483163161-2402-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: PS1PR0601CA0058.apcprd06.prod.outlook.com (10.167.43.154) To MWHPR12MB1453.namprd12.prod.outlook.com (10.172.55.22) X-MS-Office365-Filtering-Correlation-Id: 5e5dbea2-3792-441e-3c85-08d43140770e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:MWHPR12MB1453; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 3:OTlpIpe7VxnX+7EYafRgJcPYJer7H605MWNeF9SICifoqz3Ia4gPGjti5P88d255SbrrWI6UV2mno/NfcM0k8grIn0n8YwIRs4h/29LKC1uEASP50epcHTNNHNfrc400JwGB+te9BBOmK4R45an8ruE/FW7naHjf1j3undz/VdAtgHPzN+X37ir6e7LlqXlfkcyV5ngoyoZA6TvG/6uuiob59hKuOauDnbQlIrp4ZZ52eANVJptpRNXjW6Qcn7EhlD8qpuuqT0aMYtp7fsjGxw==; 25:WtPBMq34oJB2MmlEQWyY5Zx8NTjtUUPfuCobsMbLlm9W663LWa41g5n5kp5o0HRTmy98RH0JNX/9oBAIuAndIhCqW+RdtwVVnwqZDkuHFG5V14/b+zaOwmZpecCvv+ZwPOIzR/0dJ7MLDapJNTYiBHXrLSZX60zsIXbbsCtQUUoy8DV2GDnlIoL+9Ct/BP6uhXgyHyF5C4X33tijxld1jsMK1ydGVR3A1XcKIu5AYY3/qDHtjgQ+V95EvAkORDIbYiD0PkJ7oYe5l3eFgy/jj2mXpHSJCE3GV/BcLSgXjaSliiWRmB5jfFyL2y7jn/SMgnTahihNWr5yRh636ftSw175lJSkB1rJpWaY8s5StwPqIgE0+mraEEK8+1aLp6isDBWCat66aFFgi8Rtf2wbSYCL4ZymKKHrSiK/0wTGcW+ETsmGuuZCDFUVuGw1sty7/Qfixa9fvyvdSXrxnuClag== X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 31:iQL3MhOCN7+D63z3joKbHiORFI0N5mEIK/1eVv6d1Dkd85gvzWhvWoIstO20275plOyECqjP/xXUVuZy7Qwy6+HA3nCcsiFH2t07VTEQsK30KJIMHsY18xF2tSD8hnaCEe1aGi05SLMNInR7l8K5ugtTx2MQfGsCG7EQJgbHwuxbMrAXS1VIKafU5VZWecEBnT1OvIgNujxLcnAX0erAY95BlUMUqOxn5bKREq3O1lLJ8OUt1kEQI/co6lplCtJ9bh859XRFEathjna6fH2tRKl7IuoML9W/0vwhF2kn/1g=; 20:eKwa1jvzAK5+1PxuFclEuf8KN0gtjW0MBmmD3Lcw6zw5+6BxvDNSehNvNqRT+kOwmS0U2y5JTPUKQzDs5hfiwAHM1RNMZqtIAsucbBefxJl33cOVothHsk0iv+E0g050VXozLOEjeRnNpOKIzHaZ9k9gy51+2qARZmPoYEig+YysNJtEEQX+KY2sOrnXBU0mYfIpaI6ZCD82U+yWyhlcFYUo9ZEa7ih3ZanpOgnfkngppqAL8UnaNdD5Pe7SCyaUkEQSDx5xLHmRcQN3CqZbPySTPstKLzgjF2H0p3ocXQU8EttK9NQc1e4HmdIxbsSZX1j0311AmRYBohqzs5wrh6lftgTu1SCN1lt5CBDPymJcXE9y4eLzO6tYccpZmg9+T0ZKP9DNqHXsM76Vvym6qgIX8Xs0HjMV6pnyGmj+CHN8qjOYV2/JW/UZwOLWggz/UXn8UUJqzpJCemegZAxB/F1a14jtnT/bIg+XNLoIc+0DpfCDpUd0/AOVIAaLu4Ar X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(6072148); SRVR:MWHPR12MB1453; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1453; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 4:KGqAJuaxBD4LNDpCcNhujS4Gkd4rGKjeVjSzTL05oA7L3S+bVl4VX2RbK/UpEWm64KxzuV1j18BIrSfS1EC1Gmy1BHlNArOTbKwEeF728Kl++quWm+m0kUzElqj484KWWCOYJtg68P11Ssd36SEpKgkdnYBNieKhizbBHlQrVJWDusZ2Kl/x+B0Q8dxM/Gm4C/dMXXgx1yg0qPlhBquOS343QhBc9CFc0jN+gPhg66l+n10BZyq4wcHsVCOgzUguO656tLGvQRCfLMTHQpmPj1izTP7ih0c3aN1aQrVEqZI4eO4/IO1hF9aWTBAzYZFCKcDSneAdyW8qf+OTQwm1koTjjQaO/xEa5vKgBFknjxtxTfWAyZR7lFoonUbnzVmoVmt8+BkPSD7gdQ6ZqMK+uugYPEovgjQmhxHHZ+eVMTTEg33+nLyyUCwQK9+snZCYLHyBn6yM9YFHUgdAWWFkWa8zu2iPOVsSovs+uKRlCIaYFQaGTwjN3+OikBda2NGdR6glKUj3eU5IreBfHyUpqRDCxFDsohuMmcDwMpN2rev3vGGu+yYwe3MN7ljRuJwBFD0DYTSwEHyGNHAXoJGNu7vFA8/0JwqH2+SLWo8WWjpl5ve+cwz5umQmZFmKtQSbNOq2Le+51DhJZ7s+kGfdurQBL/H7a4EBBSBHERnUkcE= X-Forefront-PRVS: 0173C6D4D5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(39860400002)(39840400002)(39850400002)(39410400002)(39450400003)(199003)(189002)(92566002)(68736007)(4326007)(25786008)(105586002)(48376002)(50466002)(81166006)(101416001)(305945005)(110136003)(7736002)(5003940100001)(8676002)(2351001)(3846002)(36756003)(106356001)(50986999)(6116002)(8666007)(81156014)(189998001)(42186005)(2950100002)(33646002)(76176999)(97736004)(575784001)(66066001)(47776003)(54906002)(6666003)(86362001)(38730400001)(5660300001)(2906002)(6486002)(6506006)(6916009)(50226002)(6512006); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1453; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1453; 23:I78c97rjsXuQidQc3v46h9gINne/FNJb9d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savYoRhNDUhyS1BOCbfkB6HUaM8dzruuZH1UHv+/xKDnZ5373miMsKOKtcZy5J0QwfJ66uWirTjz6txruYdlgS+uh7eKMPc3+h8NYc=; 24:Vkci9Ex7fK0mlkoM54khmHDtlzI3v+amhfrgaGvJmUbeEKOXmr70aJTJzYa9wIZjw/EGYMOMDIvCgwvOpydDUUWI0+mFdanbG7Y2MMdAuos= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1453; 7:ZAeFWn7+d6NgY8c6EiTrS8+oiPRfEdz9P1s2juCyQjesKIWoOBq5/TMVDVrh7nePUraKGgo/7FZnh/In/0Q/4M1JFPWrR6wRRNO8kbJUaCWicefXJkzfkfeUHVlxfXF1l/nPkWMKc0WHCHloVMX6klfTg/JgbusdUCoJxDS2b55L/tWshk6Xs6Y91wYQBFKCO0PSOhI2xuMBaLqb21Pcqh1uvzHUxqIQdtlBhnOwDL5pu1DlvsCDG5Uqj0T/ydpEpGqloqMIIEjXKCrFL+7Fq8Rj9yOfCNpnw18gDdYN7Eqd+5TWjpGjDQ6TPPUK118MuGOMuZ1N+9NEtZb0lO99o+umQkY3Cl7taWU+qG0wUiLCNWoRHPsIyrlO772b1fjPZzYTlhlNCuBawyB/DUNGi1izc27+nW4rVLpk+Q9SaeGskYrbcOw/6NkvsRBmLWJ3yZsiBKmWDuBqvcGGr8aIog==; 20:3K4bIbThaJZz8jYrozvFDatXWGT6eOkGg/nTQT1372NzuycBWpwRftwDcnpli90ss9ix5EQk5Nlwhk0FFK4UnY15dNFxN97lilEBr48NbBJKyVGaiSADpk9ipn1s70jDLHokxFj6/4ylZzVTJJh/NNacrmtZPWR8ijt6akWjDa94OhqDOuVDoK+OrU9VD/Df2oF7Rv6eiR/H2H5MID62aXWD99JWAOfFk9y48zQzXR673fYacO8uEDZvXOJ8J1br X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Dec 2016 05:47:03.2265 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1453 Cc: Jan Beulich , andrew.cooper3@citrix.com, Suravee Suthikulpanit , sherry.hurwitz@amd.com, boris.ostrovsky@oracle.com Subject: [Xen-devel] [PATCH v2 06/10] x86/SVM: Add AVIC vmexit handlers X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP AVIC introduces two new #vmexit handlers: VMEXIT_INCOMP_IPI: This occurs when an IPI could not be delivered to all targeted guest virtual processors because at least one guest virtual processor was not allocated to a physical core at the time. In this case, Xen would try to emulate IPI. VMEXIT_DO_NOACCEL: This oocurs when a guest access to an APIC register that cannot be accelerated by AVIC. In this case, Xen tries to emulate register accesses. This fault is also generated if an EOI isattempted when the highest priority in-service interrupt is set for level-triggered mode. Signed-off-by: Suravee Suthikulpanit Cc: Konrad Rzeszutek Wilk Cc: Jan Beulich Cc: Boris Ostrovsky --- xen/arch/x86/hvm/svm/avic.c | 337 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/svm/svm.c | 8 + xen/include/asm-x86/apic.h | 2 + xen/include/asm-x86/hvm/svm/avic.h | 3 + xen/include/asm-x86/hvm/svm/vmcb.h | 2 + 5 files changed, 352 insertions(+) diff --git a/xen/arch/x86/hvm/svm/avic.c b/xen/arch/x86/hvm/svm/avic.c index b62f982..c0b7151 100644 --- a/xen/arch/x86/hvm/svm/avic.c +++ b/xen/arch/x86/hvm/svm/avic.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,8 @@ #define AVIC_HPA_MASK (((1ULL << 40) - 1) << AVIC_HPA_SHIFT) #define AVIC_VAPIC_BAR_MASK AVIC_HPA_MASK +#define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0 + /* * Note: * Currently, svm-avic mode is not supported with nested virtualization. @@ -122,6 +125,8 @@ int svm_avic_dom_init(struct domain *d) clear_domain_page(_mfn(mfn)); d->arch.hvm_domain.svm.avic_phy_apic_id_table_mfn = mfn; + spin_lock_init(&d->arch.hvm_domain.svm.avic_ldr_mode_lock); + return ret; err_out: svm_avic_dom_destroy(d); @@ -222,6 +227,338 @@ int svm_avic_init_vmcb(struct vcpu *v) } /* + * Note: + * This function handles the AVIC_INCOMP_IPI #vmexit when AVIC is enabled. + * The hardware generates this fault when an IPI could not be delivered + * to all targeted guest virtual processors because at least one guest + * virtual processor was not allocated to a physical core at the time. + */ +void svm_avic_vmexit_do_incomp_ipi(struct cpu_user_regs *regs) +{ + struct vcpu *curr = current; + struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb; + u32 icrh = vmcb->exitinfo1 >> 32; + u32 icrl = vmcb->exitinfo1; + u32 id = vmcb->exitinfo2 >> 32; + u32 index = vmcb->exitinfo2 && 0xFF; + + switch ( id ) + { + case AVIC_INCMP_IPI_ERR_INVALID_INT_TYPE: + /* + * AVIC hardware handles the delivery of + * IPIs when the specified Message Type is Fixed + * (also known as fixed delivery mode) and + * the Trigger Mode is edge-triggered. The hardware + * also supports self and broadcast delivery modes + * specified via the Destination Shorthand(DSH) + * field of the ICRL. Logical and physical APIC ID + * formats are supported. All other IPI types cause + * a #VMEXIT, which needs to emulated. + */ + vlapic_reg_write(curr, APIC_ICR2, icrh); + vlapic_reg_write(curr, APIC_ICR, icrl); + break; + case AVIC_INCMP_IPI_ERR_TARGET_NOT_RUN: + { + /* + * At this point, we expect that the AVIC HW has already + * set the appropriate IRR bits on the valid target + * vcpus. So, we just need to kick the appropriate vcpu. + */ + struct vcpu *curc; + struct domain *curd = curr->domain; + uint32_t dest = GET_xAPIC_DEST_FIELD(icrh); + uint32_t short_hand = icrl & APIC_SHORT_MASK; + bool dest_mode = !!(icrl & APIC_DEST_MASK); + + for_each_vcpu ( curd, curc ) + { + if ( curc != curr && + vlapic_match_dest(vcpu_vlapic(curc), vcpu_vlapic(curr), + short_hand, dest, dest_mode) ) + { + vcpu_kick(curc); + break; + } + } + break; + } + case AVIC_INCMP_IPI_ERR_INV_TARGET: + dprintk(XENLOG_ERR, + "SVM: %s: Invalid IPI target (icr=%#08x:%08x, idx=%u)\n", + __func__, icrh, icrl, index); + break; + case AVIC_INCMP_IPI_ERR_INV_BK_PAGE: + dprintk(XENLOG_ERR, + "SVM: %s: Invalid bk page (icr=%#08x:%08x, idx=%u)\n", + __func__, icrh, icrl, index); + break; + default: + dprintk(XENLOG_ERR, "SVM: %s: Unknown IPI interception (%#x)\n", + __func__, id); + } +} + +static struct avic_log_apic_id_ent * +avic_get_logical_id_entry(const struct vcpu *v, u32 ldr, bool flat) +{ + unsigned int index; + struct avic_log_apic_id_ent *avic_log_apid_id_table; + const struct svm_domain *d = &v->domain->arch.hvm_domain.svm; + unsigned int dest_id = GET_APIC_LOGICAL_ID(ldr); + + if ( !dest_id ) + return NULL; + + if ( flat ) + { + index = ffs(dest_id) - 1; + if ( index > 7 ) + return NULL; + } + else + { + unsigned int cluster = (dest_id & 0xf0) >> 4; + int apic = ffs(dest_id & 0x0f) - 1; + + if ( (apic < 0) || (apic > 7) || (cluster >= 0xf) ) + return NULL; + index = (cluster << 2) + apic; + } + + ASSERT(index <= 255); + + avic_log_apid_id_table = mfn_to_virt(d->avic_log_apic_id_table_mfn); + + return &avic_log_apid_id_table[index]; +} + +static int avic_ldr_write(struct vcpu *v, u8 g_phy_id, u32 ldr, bool valid) +{ + struct avic_log_apic_id_ent *entry, new_entry; + u32 *bp = avic_get_bk_page_entry(v, APIC_DFR); + + if ( !bp ) + return -EINVAL; + + entry = avic_get_logical_id_entry(v, ldr, (*bp == APIC_DFR_FLAT)); + if (!entry) + return -EINVAL; + + new_entry = *entry; + smp_rmb(); + new_entry.guest_phy_apic_id = g_phy_id; + new_entry.valid = valid; + *entry = new_entry; + smp_wmb(); + + return 0; +} + +static int avic_handle_ldr_update(struct vcpu *v) +{ + int ret = 0; + u32 *ldr = avic_get_bk_page_entry(v, APIC_LDR); + u32 *apic_id_reg = avic_get_bk_page_entry(v, APIC_ID); + + if ( !ldr || !*ldr || !apic_id_reg ) + return -EINVAL; + + ret = avic_ldr_write(v, GET_APIC_PHYSICAL_ID(*apic_id_reg), *ldr, true); + if ( ret && v->arch.hvm_svm.avic_last_ldr ) + { + /* + * Note: + * In case of failure to update LDR register, + * we set the guest physical APIC ID to 0, + * and set the entry logical APID ID entry + * to invalid (false). + */ + avic_ldr_write(v, 0, v->arch.hvm_svm.avic_last_ldr, false); + v->arch.hvm_svm.avic_last_ldr = 0; + } + else + { + /* + * Note: + * This saves the last valid LDR so that we + * know which entry in the local APIC ID + * to clean up when the LDR is updated. + */ + v->arch.hvm_svm.avic_last_ldr = *ldr; + } + + return ret; +} + +static int avic_handle_apic_id_update(struct vcpu *v, bool init) +{ + struct avic_phy_apic_id_ent *old, *new; + struct arch_svm_struct *s = &v->arch.hvm_svm; + u32 *apic_id_reg = avic_get_bk_page_entry(v, APIC_ID); + + if ( !apic_id_reg ) + return -EINVAL; + + old = s->avic_last_phy_id; + ASSERT(old); + + new = avic_get_phy_apic_id_ent(v, GET_APIC_PHYSICAL_ID(*apic_id_reg)); + if ( !new ) + return 0; + + /* We need to move physical_id_entry to new offset */ + *new = *old; + *((u64 *)old) = 0ULL; + s->avic_last_phy_id = new; + + /* + * Update the guest physical APIC ID in the logical + * APIC ID table entry if LDR is already setup. + */ + if ( v->arch.hvm_svm.avic_last_ldr ) + avic_handle_ldr_update(v); + + return 0; +} + +static int avic_handle_dfr_update(struct vcpu *v) +{ + u32 mod; + struct svm_domain *d = &v->domain->arch.hvm_domain.svm; + u32 *dfr = avic_get_bk_page_entry(v, APIC_DFR); + + if ( !dfr ) + return -EINVAL; + + mod = (*dfr >> 28) & 0xFu; + + spin_lock(&d->avic_ldr_mode_lock); + if ( d->avic_ldr_mode != mod ) + { + /* + * We assume that all local APICs are using the same type. + * If LDR mode changes, we need to flush the domain AVIC logical + * APIC id table. + */ + clear_domain_page(_mfn(d->avic_log_apic_id_table_mfn)); + smp_wmb(); + d->avic_ldr_mode = mod; + } + spin_unlock(&d->avic_ldr_mode_lock); + + if ( v->arch.hvm_svm.avic_last_ldr ) + avic_handle_ldr_update(v); + + return 0; +} + +static int avic_unaccel_trap_write(struct vcpu *v) +{ + struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; + u32 offset = vmcb->exitinfo1 & AVIC_UNACCEL_ACCESS_OFFSET_MASK; + u32 *reg = avic_get_bk_page_entry(v, offset); + + if ( !reg ) + return X86EMUL_UNHANDLEABLE; + + switch ( offset ) + { + case APIC_ID: + if ( avic_handle_apic_id_update(v, false) ) + return X86EMUL_UNHANDLEABLE; + break; + case APIC_LDR: + if ( avic_handle_ldr_update(v) ) + return X86EMUL_UNHANDLEABLE; + break; + case APIC_DFR: + if ( avic_handle_dfr_update(v) ) + return X86EMUL_UNHANDLEABLE; + break; + default: + break; + } + + vlapic_reg_write(v, offset, *reg); + + return X86EMUL_OKAY; +} + +/* + * Note: + * This function handles the AVIC_NOACCEL #vmexit when AVIC is enabled. + * The hardware generates this fault when : + * - A guest access to an APIC register that is not accelerated + * by AVIC hardware. + * - EOI is attempted when the highest priority in-service interrupt + * is level-triggered. + */ +void svm_avic_vmexit_do_noaccel(struct cpu_user_regs *regs) +{ + struct vcpu *curr = current; + struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb; + u32 offset = vmcb->exitinfo1 & 0xFF0; + u32 rw = (vmcb->exitinfo1 >> 32) & 0x1; + + switch ( offset ) + { + case APIC_ID: + case APIC_EOI: + case APIC_RRR: + case APIC_LDR: + case APIC_DFR: + case APIC_SPIV: + case APIC_ESR: + case APIC_ICR: + case APIC_LVTT: + case APIC_LVTTHMR: + case APIC_LVTPC: + case APIC_LVT0: + case APIC_LVT1: + case APIC_LVTERR: + case APIC_TMICT: + case APIC_TDCR: + /* + * Handling AVIC Trap (intercept right after the access). + */ + if ( !rw ) + { + /* + * If a read trap happens, the CPU microcode does not + * implement the spec. + */ + BUG(); + } + if ( avic_unaccel_trap_write(curr) != X86EMUL_OKAY ) + { + gprintk(XENLOG_ERR, "%s: Failed to handle trap write (%#x)\n", + __func__, offset); + return; + } + break; + default: + /* + * Handling AVIC Fault (intercept before the access). + */ + if ( !rw ) + { + u32 *entry = avic_get_bk_page_entry(curr, offset); + + if ( !entry ) + return; + + *entry = vlapic_read_aligned(vcpu_vlapic(curr), offset); + } + hvm_emulate_one_vm_event(EMUL_KIND_NORMAL, TRAP_invalid_op, + HVM_DELIVER_NO_ERROR_CODE); + } + + return; +} + +/* * Local variables: * mode: C * c-file-style: "BSD" diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index cef29b2..cb5281c 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2682,6 +2682,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) svm_vmexit_do_pause(regs); break; + case VMEXIT_AVIC_INCOMP_IPI: + svm_avic_vmexit_do_incomp_ipi(regs); + break; + + case VMEXIT_AVIC_NOACCEL: + svm_avic_vmexit_do_noaccel(regs); + break; + default: unexpected_exit_type: gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", " diff --git a/xen/include/asm-x86/apic.h b/xen/include/asm-x86/apic.h index be9a535..aa5e7ec 100644 --- a/xen/include/asm-x86/apic.h +++ b/xen/include/asm-x86/apic.h @@ -16,6 +16,8 @@ #define APIC_DEBUG 2 #define SET_APIC_LOGICAL_ID(x) (((x)<<24)) +#define GET_APIC_LOGICAL_ID(x) (((x)>>24) & 0xFFu) +#define GET_APIC_PHYSICAL_ID(x) (((x)>>24) & 0xFFu) #define IO_APIC_REDIR_VECTOR_MASK 0x000FF #define IO_APIC_REDIR_DEST_LOGICAL 0x00800 diff --git a/xen/include/asm-x86/hvm/svm/avic.h b/xen/include/asm-x86/hvm/svm/avic.h index 16b433c..7e0abcb 100644 --- a/xen/include/asm-x86/hvm/svm/avic.h +++ b/xen/include/asm-x86/hvm/svm/avic.h @@ -37,4 +37,7 @@ bool_t svm_avic_vcpu_enabled(const struct vcpu *v); void svm_avic_update_vapic_bar(const struct vcpu *v,uint64_t data); int svm_avic_init_vmcb(struct vcpu *v); +void svm_avic_vmexit_do_incomp_ipi(struct cpu_user_regs *regs); +void svm_avic_vmexit_do_noaccel(struct cpu_user_regs *regs); + #endif /* _SVM_AVIC_H_ */ diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h b/xen/include/asm-x86/hvm/svm/vmcb.h index d3d045f..9abf077 100644 --- a/xen/include/asm-x86/hvm/svm/vmcb.h +++ b/xen/include/asm-x86/hvm/svm/vmcb.h @@ -302,6 +302,8 @@ enum VMEXIT_EXITCODE VMEXIT_MWAIT_CONDITIONAL= 140, /* 0x8c */ VMEXIT_XSETBV = 141, /* 0x8d */ VMEXIT_NPF = 1024, /* 0x400, nested paging fault */ + VMEXIT_AVIC_INCOMP_IPI = 1025, /* 0x401 */ + VMEXIT_AVIC_NOACCEL = 1026, /* 0x402 */ VMEXIT_INVALID = -1 };