From patchwork Fri Mar 4 20:46:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 63611 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp281539lbc; Fri, 4 Mar 2016 12:49:35 -0800 (PST) X-Received: by 10.67.1.237 with SMTP id bj13mr15143779pad.130.1457124574200; Fri, 04 Mar 2016 12:49:34 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66si7940989pfm.92.2016.03.04.12.49.33; Fri, 04 Mar 2016 12:49:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760248AbcCDUtU (ORCPT + 30 others); Fri, 4 Mar 2016 15:49:20 -0500 Received: from mail-bn1bon0072.outbound.protection.outlook.com ([157.56.111.72]:52864 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1760228AbcCDUtQ (ORCPT ); Fri, 4 Mar 2016 15:49:16 -0500 Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.415.20; Fri, 4 Mar 2016 20:49:10 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit Subject: [PART1 RFC v2 08/10] svm: Do not expose x2APIC when enable AVIC Date: Fri, 4 Mar 2016 14:46:06 -0600 Message-ID: <1457124368-2025-9-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457124368-2025-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1457124368-2025-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SINPR01CA0045.apcprd01.prod.exchangelabs.com (10.141.109.45) To SN1PR12MB0445.namprd12.prod.outlook.com (25.162.105.139) X-MS-Office365-Filtering-Correlation-Id: 40d641f2-79d4-45bd-3312-08d3446e7204 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:pQHN3Y5JLvqXrszvxwk3TCmYwKquSD9OvIii9bz/euP81t0UleUAd+yZVfpnMuAcjkqshn49QEyMwYD8FKWpN/F2wO7G4w59w8YUIjI5sSA4IgJNtSojG7ey45Rfx3sCws8x9EwBJ2sWA76REyn+TnAceQNnkpLseszpRvimeau+QkmFLqL5qzHdk4T3e0jT; 3:IwE8knjjgArPtm2c08rw3QoTc2+Li0U4jKeO2pLI7/0JlZ4NGfHb+e1u8F6Q97kbkHOSvye2ICisFGxvdqhud35XVjFnPzp8RUYciUeE9hqWuSHFZ5KA0jGMo/FZSxOi; 25:di3Ux4q6HZMDt9GR7rNw+lI9ebYnYB5H3hciHtQubBmCTZkqFLpQDGK6m4+3ewP8jnLQolDVopZqr2Q2YiD7lvlhmiqcRdlQMctMCZx5zpnUwW6v3ViOHRtdsbwxM1bxVPgg/2206NRse4nlNrFM/kNwf8EMv2rVsufk8ki0z2+Lm8ok3hRQOIaox2pXcBQIyVRU92nU7iRvPUwRwZAjiiQZF7CXVSOICD1uX6I8Ry2abgv2mIAh0VDuBuIq4QATmZzMuNJQ6kUTChlHt9x8YqGNnq/ncIKjKhiSAbmY1QviXcW3GAxHh34UKQyYO0oyyHx6eUvapxZ2FZDyR3UUvOVmxIoOwwYPCajkKWuLSvE= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0445; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 20:QitxdZhcoyjtBAtZXDVyFDgicybArMRoYs6XhVDe+93YRPSuPKsZXHVm8Z/LJM7blOSqCZqANImjzPU/wI1JslabHLYyvUO12owh0F53RhZVsfKIh6ZP28v0nCjTnr4bHcInrtAu1zo5p0fU5mtnXejj5ngF/S/154tlu4yj6z6huMIAFc6ldSFyGzU2ESR7HKgXixP6menjACR/7IykTTKpi7uVc54JUoRqP3SXUOsK4F+x2LAJpUbR3jZEyxi7IL+uyFMP/SduwFHdozTLzbdZ+Oss7kFJZ91Tw61AW2tTiw6v8y7RfnbfhMW2IlG6WzEEWnTU+S2nl0LZz1xsI8lgeIlSZlx25KfEkMtTUpkDbDsAyfgi4hCgM7OvvoyZ/Ua0LvV3Qb0aqPDVCpwT3adbcV0ALxAsYtuwWH/TdUmpsK7hKpfinmcfajtAd6RBgD1ncxXPAPdt6H92kJJR/I/r34xRzgcynjbFp/PhJG774XBMBnUeOwHS2Q487dQ7; 4:hQ0JtTvdKcGJVgcle10YkJd531ubJ+C+bLi6O6+cTEPfu6FxI4Vq/18FOHNivDQmHOr4OgHxNebzZcy1azRzcifb8mVXJa5g/hoibBE1PdeScsFMBNjISSBw2EGBWDG3rIraOimQBic+GZ4PP9NYbcEUlvRxhyv/yUPB98/ekpdcTWC0vBf7Mud5OlXWG8GTNq0rb/OBFja7L6A+pmKcZoT2auQd7pWafbJEA3f40nkKESbAyZvXpQW+4sc801KJjZUaLre8qGursGC0crgw9HgiyrpbAlrK98vR5V56JZqqoBYSAN/IIcKhcWELoOq8lUnCye/CTneQ5Q7K3cyunArxYy9J73suw54w/SsyKbo= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Forefront-PRVS: 0871917CDA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(77096005)(5001770100001)(87976001)(48376002)(47776003)(229853001)(36756003)(2201001)(66066001)(81166005)(50466002)(2950100001)(5004730100002)(189998001)(40100003)(50226001)(5003940100001)(122386002)(5008740100001)(19580405001)(2906002)(19580395003)(86362001)(4326007)(42186005)(50986999)(6116002)(3846002)(1096002)(92566002)(586003)(76176999); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0445; 23:1b6TCJnSc1E7V1N2EtqfdIGxLaMUalJwWPmfWQ9Sa?= =?us-ascii?Q?u53plAvgwe09evuWkBiNCD3Wy/fW+xYEo8E49m/3mYc/QAZFYRov+PDwqFYE?= =?us-ascii?Q?mCA0QxqJTdGl2CtF7q8KurWmJn9q/OEPP6uE1wHArE7geyULQqAKTjAAHBfm?= =?us-ascii?Q?wEB2atw0nzuZsFw6ndCxTTqVCWQV0j0iyyRUL0FvM6BP4qsZ/12iTlc3Bhi4?= =?us-ascii?Q?2H14VUvbq/th9zL0NP9Ghe6vvHxpBnR4XCmx5ZDg7Wk/R/d6LNyv3CmHA1z/?= =?us-ascii?Q?JNgyLlaDnGhFFoEEUVGinct1IF8JcazAUa+S5s8/M1vt0aLbDU2rl0b/iWAt?= =?us-ascii?Q?EtUcHAaB6xQA2CuJevRkVFP4qiPv5Vmhp5YJv2DRQgeHLCSM5aC3GY/ecQtv?= =?us-ascii?Q?RaaxSQH9mZiej12b+Ds+pjVNLxFm3k0R//q830h1AaMV4wrpvQ6FkM/3/dXr?= =?us-ascii?Q?sBna0wJy3NYjlVA1pGX+IudBOshXHuwU7Tx17aMBUfAi5HhEe74B5N7dGSKr?= =?us-ascii?Q?1GFqEIQqIohznaAbKSY8UTlao1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eZyxUlFUoYHqaal9xwfOX5k+y68 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2016 20:49:10.7308 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit Since AVIC only virtualizes xAPIC hardware for the guest, we need to: * Intercept APIC BAR msr accesses to disable x2APIC * Intercept CPUID access to not advertise x2APIC support * Hide x2APIC support when checking via KVM ioctl Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index a177781..02cd8d0 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -228,6 +228,7 @@ static const struct svm_direct_access_msrs { { .index = MSR_IA32_LASTBRANCHTOIP, .always = false }, { .index = MSR_IA32_LASTINTFROMIP, .always = false }, { .index = MSR_IA32_LASTINTTOIP, .always = false }, + { .index = MSR_IA32_APICBASE, .always = false }, { .index = MSR_INVALID, .always = false }, }; @@ -855,6 +856,9 @@ static void svm_vcpu_init_msrpm(u32 *msrpm) set_msr_interception(msrpm, direct_access_msrs[i].index, 1, 1); } + + if (avic) + set_msr_interception(msrpm, MSR_IA32_APICBASE, 1, 1); } static void add_msr_offset(u32 offset) @@ -3490,6 +3494,18 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = 0x1E; } break; + case MSR_IA32_APICBASE: + if (avic) { + /* Note: + * For AVIC, we need to disable X2APIC + * and enable XAPIC + */ + kvm_get_msr_common(vcpu, msr_info); + msr_info->data &= ~X2APIC_ENABLE; + msr_info->data |= XAPIC_ENABLE; + break; + } + /* Follow through if not AVIC */ default: return kvm_get_msr_common(vcpu, msr_info); } @@ -3618,6 +3634,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) case MSR_VM_IGNNE: vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data); break; + case MSR_IA32_APICBASE: + if (avic) + avic_update_vapic_bar(to_svm(vcpu), data); + /* Follow through */ default: return kvm_set_msr_common(vcpu, msr); } @@ -4754,11 +4774,26 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu) /* Update nrips enabled cache */ svm->nrips_enabled = !!guest_cpuid_has_nrips(&svm->vcpu); + + /* Do not support X2APIC when enable AVIC */ + if (avic) { + int i; + + for (i = 0 ; i < vcpu->arch.cpuid_nent ; i++) { + if (vcpu->arch.cpuid_entries[i].function == 1) + vcpu->arch.cpuid_entries[i].ecx &= ~(1 << 21); + } + } } static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) { switch (func) { + case 0x00000001: + /* Do not support X2APIC when enable AVIC */ + if (avic) + entry->ecx &= ~(1 << 21); + break; case 0x80000001: if (nested) entry->ecx |= (1 << 2); /* Set SVM bit */