Received: by 10.192.165.148 with SMTP id m20csp1021637imm; Wed, 25 Apr 2018 11:16:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/O7Otgh30BZvNsqf8FAy/AFOUuNGTu6CzlH9l3GsgKWByTVxQ8b8RkrwM47I/rOKNX49Qb X-Received: by 10.101.101.206 with SMTP id y14mr25032050pgv.220.1524680160414; Wed, 25 Apr 2018 11:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524680160; cv=none; d=google.com; s=arc-20160816; b=OAdg6wELK4kOvE1JMDIt3NYAgoEneUyVMuFqmtwddcnw1LqpRY8mV8hDy6EVIjYAxD q0ZJIp0Ae868PzaxMrbMZ/DsoKPp52H5p4Mj4K5znjj05ErCsyY7bHhUC+HV7dYgdqVD 5ukKmdq3fW5byIo5FMVyo9DUVaj8BClKjrErb1Tk9SKM6oT18h/WcpCP+vV5yn/eRnYC Qc2PbRWK6O9Mdz15/1vnS0wvbqzvC6S28T+0/3WPUt1Yr2yNh7bZKWqOqtyjduyOQqOn jgRDLa1cFwQBaIMwAljeNLIhM3ntF+2hyAKCJVGfTqj5pH6m1jMiZpbh8bV8xlSHid6I 2Tyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=Q6Lig8O2/mDS6IbpL/WT+GJy+URc4Np8oxg9Lx8xPYo=; b=X6ZrPAJmPtzCq5jB29B2zbGAkDy5RopBfb7qV/v69gLgCwkYmXXDS9h+VkQMc8aUc/ N/Uoq+m+MGxSq1BHr9QRMHrYKfDfNOkEwritJ98NrxWjIsl3RdVPWeDRO2PZbEhQLeWL ahgv//w3X9z7k21gkfcWNY9nItyHhemnaqZ1bTBU9B2o0Cx+VWN/n6+t5JK+5mXYSrB8 0npdEzXBSbdp8TJxX/nduobYfUhVAGH/eoDjiTSsIScxEJgCbd7Gs4N26p863ycCLv9i yAcz9aWXR+Rolm8V5xTCp6hpMwTbOOWjmHeVrCe+w5J7KX8F7ViD9LVqFqNTukyKCR7P d+4Q== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m68si16464593pfm.0.2018.04.25.11.15.46; Wed, 25 Apr 2018 11:16:00 -0700 (PDT) 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 S1756124AbeDYSN4 (ORCPT + 99 others); Wed, 25 Apr 2018 14:13:56 -0400 Received: from a2nlsmtp01-04.prod.iad2.secureserver.net ([198.71.225.38]:40942 "EHLO a2nlsmtp01-04.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754974AbeDYSNx (ORCPT ); Wed, 25 Apr 2018 14:13:53 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id BOuSfOOvEGqYmBOuSfxhiA; Wed, 25 Apr 2018 11:12:52 -0700 x-originating-ip: 107.180.71.197 Received: from kys by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.89_1) (envelope-from ) id 1fBOuS-0002Hm-DU; Wed, 25 Apr 2018 11:12:52 -0700 From: kys@linuxonhyperv.com To: x86@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, tglx@linutronix.de, hpa@zytor.com, sthemmin@microsoft.com, Michael.H.Kelley@microsoft.com, vkuznets@redhat.com Cc: "K. Y. Srinivasan" Subject: [PATCH 1/5] X86: Hyper-V: Enlighten APIC access Date: Wed, 25 Apr 2018 11:12:46 -0700 Message-Id: <20180425181250.8740-1-kys@linuxonhyperv.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180425181110.8683-1-kys@linuxonhyperv.com> References: <20180425181110.8683-1-kys@linuxonhyperv.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfP3dQv1AtB5b4NXkE3+Gl5QqS/eH1xc28P99OFqjDpYCcwcDOqfxWGyjB31v7+C53u0FNOF007dy4oYjz4QdNytLA+Q5eghDYmQWREzxCE0TTgRMk93v e3rPX0bXY6Sv4kVilGsdEFnlQjzboyeYsRklW/gl8bOBacdOKg70QVnmOShTYFlZ8LfpPBI3d+gaiFBdd86qiKa2ouO03NgN9VX68mYkn/B2T20o+NdkQ43s awZsbZYSMZC+i0emaOg+KYBGQIZB27UzWaVrFMx6O8hTYZaRDDP5MzvQoNryRWjKXIi8+Xfy/ZOIf/hRGOnchfsWkd0EjT75Q37NBAn+9U58Cf9yklIzt2Pe hZtWmCZmUn67qnIK+2Zu5MJzYUh9S1pFmKZH6juyW7ikUVkDQB9EofYGXMfnCatiUvx/plQXVRwCWo+fHfyjPl1ZjYfQOSLfJ2tdeaE9/zHgOZ+RznrY2hdW D6tXtLnJWq2HqoLBBcOyQN503XL5oAp4Io3J1p923A2ywcaY53TEEshlXpI2/3sP14mMtmI1VQfXi3fMKkJbA/s8SbiPpHBAfBp6BV1i2NlXx/n0Cgtia0k+ yFU8Lj6Sv/AXZ4YmogWEk6sr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "K. Y. Srinivasan" Hyper-V supports MSR based APIC access; implement the enlightenment. Signed-off-by: K. Y. Srinivasan --- arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/hv_apic.c | 98 +++++++++++++++++++++++++++++++++++++++++ arch/x86/hyperv/hv_init.c | 5 ++- arch/x86/include/asm/mshyperv.h | 6 ++- 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 arch/x86/hyperv/hv_apic.c diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile index 367a8203cfcf..00ce4df01a09 100644 --- a/arch/x86/hyperv/Makefile +++ b/arch/x86/hyperv/Makefile @@ -1 +1 @@ -obj-y := hv_init.o mmu.o +obj-y := hv_init.o mmu.o hv_apic.o diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c new file mode 100644 index 000000000000..e0a5b36208fc --- /dev/null +++ b/arch/x86/hyperv/hv_apic.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V specific APIC code. + * + * Copyright (C) 2018, Microsoft, Inc. + * + * Author : K. Y. Srinivasan + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u64 hv_apic_icr_read(void) +{ + u64 reg_val; + + rdmsrl(HV_X64_MSR_ICR, reg_val); + return reg_val; +} + +static void hv_apic_icr_write(u32 low, u32 id) +{ + u64 reg_val; + + reg_val = SET_APIC_DEST_FIELD(id); + reg_val = reg_val << 32; + reg_val |= low; + + wrmsrl(HV_X64_MSR_ICR, reg_val); +} + +static u32 hv_apic_read(u32 reg) +{ + u32 reg_val, hi; + + switch (reg) { + case APIC_EOI: + rdmsr(HV_X64_MSR_EOI, reg_val, hi); + return reg_val; + case APIC_TASKPRI: + rdmsr(HV_X64_MSR_TPR, reg_val, hi); + return reg_val; + + default: + return native_apic_mem_read(reg); + } +} + +static void hv_apic_write(u32 reg, u32 val) +{ + switch (reg) { + case APIC_EOI: + wrmsr(HV_X64_MSR_EOI, val, 0); + break; + case APIC_TASKPRI: + wrmsr(HV_X64_MSR_TPR, val, 0); + break; + default: + native_apic_mem_write(reg, val); + } +} + +static void hv_apic_eoi_write(u32 reg, u32 val) +{ + wrmsr(HV_X64_MSR_EOI, val, 0); +} + +void __init hv_apic_init(void) +{ + if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) { + pr_info("Hyper-V: Using MSR ased APIC access\n"); + apic_set_eoi_write(hv_apic_eoi_write); + apic->read = hv_apic_read; + apic->write = hv_apic_write; + apic->icr_write = hv_apic_icr_write; + apic->icr_read = hv_apic_icr_read; + } +} diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index cfecc2272f2d..71e50fc2b7ef 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -242,8 +242,9 @@ static int hv_cpu_die(unsigned int cpu) * * 1. Setup the hypercall page. * 2. Register Hyper-V specific clocksource. + * 3. Setup Hyper-V specific APIC entry points. */ -void hyperv_init(void) +void __init hyperv_init(void) { u64 guest_id, required_msrs; union hv_x64_msr_hypercall_contents hypercall_msr; @@ -298,6 +299,8 @@ void hyperv_init(void) hyper_alloc_mmu(); + hv_apic_init(); + /* * Register Hyper-V specific clocksource. */ diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index b90e79610cf7..bcced50037c1 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -258,7 +258,7 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number) return hv_vp_index[cpu_number]; } -void hyperv_init(void); +void __init hyperv_init(void); void hyperv_setup_mmu_ops(void); void hyper_alloc_mmu(void); void hyperv_report_panic(struct pt_regs *regs, long err); @@ -269,14 +269,16 @@ void hyperv_reenlightenment_intr(struct pt_regs *regs); void set_hv_tscchange_cb(void (*cb)(void)); void clear_hv_tscchange_cb(void); void hyperv_stop_tsc_emulation(void); +void hv_apic_init(void); #else /* CONFIG_HYPERV */ -static inline void hyperv_init(void) {} +static __init inline void hyperv_init(void) {} static inline bool hv_is_hyperv_initialized(void) { return false; } static inline void hyperv_cleanup(void) {} static inline void hyperv_setup_mmu_ops(void) {} static inline void set_hv_tscchange_cb(void (*cb)(void)) {} static inline void clear_hv_tscchange_cb(void) {} static inline void hyperv_stop_tsc_emulation(void) {}; +static inline void hv_apic_init(void) {} static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) { return NULL; -- 2.15.1