mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 23:14:31 +08:00
2bf16b7a73
Here is the big set of char/misc and other driver subsystem patches for 4.15-rc1. There are small changes all over here, hyperv driver updates, pcmcia driver updates, w1 driver updats, vme driver updates, nvmem driver updates, and lots of other little one-off driver updates as well. The shortlog has the full details. Note, there will be a merge conflict in drivers/misc/lkdtm_core.c when merging to your tree as one lkdtm patch came in through the perf tree as well as this one. The resolution is to take the const change that this tree provides. All of these have been in linux-next for quite a while with no reported issues. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCWg2Lnw8cZ3JlZ0Brcm9h aC5jb20ACgkQMUfUDdst+ymTUwCgwp46+I8yPlgDH8oe5TxyyJnpdHQAn1XW0i+a sBi6WS87In5v1QO1Rgfc =dH2a -----END PGP SIGNATURE----- Merge tag 'char-misc-4.15-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc Pull char/misc updates from Greg KH: "Here is the big set of char/misc and other driver subsystem patches for 4.15-rc1. There are small changes all over here, hyperv driver updates, pcmcia driver updates, w1 driver updats, vme driver updates, nvmem driver updates, and lots of other little one-off driver updates as well. The shortlog has the full details. All of these have been in linux-next for quite a while with no reported issues" * tag 'char-misc-4.15-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (90 commits) VME: Return -EBUSY when DMA list in use w1: keep balance of mutex locks and refcnts MAINTAINERS: Update VME subsystem tree. nvmem: sunxi-sid: add support for A64/H5's SID controller nvmem: imx-ocotp: Update module description nvmem: imx-ocotp: Enable i.MX7D OTP write support nvmem: imx-ocotp: Add i.MX7D timing write clock setup support nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function nvmem: imx-ocotp: Add support for banked OTP addressing nvmem: imx-ocotp: Pass parameters via a struct nvmem: imx-ocotp: Restrict OTP write to IMX6 processors nvmem: uniphier: add UniPhier eFuse driver dt-bindings: nvmem: add description for UniPhier eFuse nvmem: set nvmem->owner to nvmem->dev->driver->owner if unset nvmem: qfprom: fix different address space warnings of sparse nvmem: mtk-efuse: fix different address space warnings of sparse nvmem: mtk-efuse: use stack for nvmem_config instead of malloc'ing it nvmem: imx-iim: use stack for nvmem_config instead of malloc'ing it thunderbolt: tb: fix use after free in tb_activate_pcie_devices MAINTAINERS: Add git tree for Thunderbolt development ...
256 lines
6.1 KiB
C
256 lines
6.1 KiB
C
/*
|
|
* X86 specific Hyper-V initialization code.
|
|
*
|
|
* Copyright (C) 2016, Microsoft, Inc.
|
|
*
|
|
* Author : K. Y. Srinivasan <kys@microsoft.com>
|
|
*
|
|
* 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 <linux/types.h>
|
|
#include <asm/hypervisor.h>
|
|
#include <asm/hyperv.h>
|
|
#include <asm/mshyperv.h>
|
|
#include <linux/version.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/clockchips.h>
|
|
#include <linux/hyperv.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/cpuhotplug.h>
|
|
|
|
#ifdef CONFIG_HYPERV_TSCPAGE
|
|
|
|
static struct ms_hyperv_tsc_page *tsc_pg;
|
|
|
|
struct ms_hyperv_tsc_page *hv_get_tsc_page(void)
|
|
{
|
|
return tsc_pg;
|
|
}
|
|
|
|
static u64 read_hv_clock_tsc(struct clocksource *arg)
|
|
{
|
|
u64 current_tick = hv_read_tsc_page(tsc_pg);
|
|
|
|
if (current_tick == U64_MAX)
|
|
rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
|
|
|
|
return current_tick;
|
|
}
|
|
|
|
static struct clocksource hyperv_cs_tsc = {
|
|
.name = "hyperv_clocksource_tsc_page",
|
|
.rating = 400,
|
|
.read = read_hv_clock_tsc,
|
|
.mask = CLOCKSOURCE_MASK(64),
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
|
};
|
|
#endif
|
|
|
|
static u64 read_hv_clock_msr(struct clocksource *arg)
|
|
{
|
|
u64 current_tick;
|
|
/*
|
|
* Read the partition counter to get the current tick count. This count
|
|
* is set to 0 when the partition is created and is incremented in
|
|
* 100 nanosecond units.
|
|
*/
|
|
rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
|
|
return current_tick;
|
|
}
|
|
|
|
static struct clocksource hyperv_cs_msr = {
|
|
.name = "hyperv_clocksource_msr",
|
|
.rating = 400,
|
|
.read = read_hv_clock_msr,
|
|
.mask = CLOCKSOURCE_MASK(64),
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
|
};
|
|
|
|
void *hv_hypercall_pg;
|
|
EXPORT_SYMBOL_GPL(hv_hypercall_pg);
|
|
struct clocksource *hyperv_cs;
|
|
EXPORT_SYMBOL_GPL(hyperv_cs);
|
|
|
|
u32 *hv_vp_index;
|
|
EXPORT_SYMBOL_GPL(hv_vp_index);
|
|
|
|
u32 hv_max_vp_index;
|
|
|
|
static int hv_cpu_init(unsigned int cpu)
|
|
{
|
|
u64 msr_vp_index;
|
|
|
|
hv_get_vp_index(msr_vp_index);
|
|
|
|
hv_vp_index[smp_processor_id()] = msr_vp_index;
|
|
|
|
if (msr_vp_index > hv_max_vp_index)
|
|
hv_max_vp_index = msr_vp_index;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* This function is to be invoked early in the boot sequence after the
|
|
* hypervisor has been detected.
|
|
*
|
|
* 1. Setup the hypercall page.
|
|
* 2. Register Hyper-V specific clocksource.
|
|
*/
|
|
void hyperv_init(void)
|
|
{
|
|
u64 guest_id;
|
|
union hv_x64_msr_hypercall_contents hypercall_msr;
|
|
|
|
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
|
|
return;
|
|
|
|
/* Allocate percpu VP index */
|
|
hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index),
|
|
GFP_KERNEL);
|
|
if (!hv_vp_index)
|
|
return;
|
|
|
|
if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online",
|
|
hv_cpu_init, NULL) < 0)
|
|
goto free_vp_index;
|
|
|
|
/*
|
|
* Setup the hypercall page and enable hypercalls.
|
|
* 1. Register the guest ID
|
|
* 2. Enable the hypercall and register the hypercall page
|
|
*/
|
|
guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0);
|
|
wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
|
|
|
|
hv_hypercall_pg = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
|
|
if (hv_hypercall_pg == NULL) {
|
|
wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
|
|
goto free_vp_index;
|
|
}
|
|
|
|
rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
|
|
hypercall_msr.enable = 1;
|
|
hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
|
|
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
|
|
|
|
hyper_alloc_mmu();
|
|
|
|
/*
|
|
* Register Hyper-V specific clocksource.
|
|
*/
|
|
#ifdef CONFIG_HYPERV_TSCPAGE
|
|
if (ms_hyperv.features & HV_X64_MSR_REFERENCE_TSC_AVAILABLE) {
|
|
union hv_x64_msr_hypercall_contents tsc_msr;
|
|
|
|
tsc_pg = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL);
|
|
if (!tsc_pg)
|
|
goto register_msr_cs;
|
|
|
|
hyperv_cs = &hyperv_cs_tsc;
|
|
|
|
rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
|
|
|
|
tsc_msr.enable = 1;
|
|
tsc_msr.guest_physical_address = vmalloc_to_pfn(tsc_pg);
|
|
|
|
wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64);
|
|
|
|
hyperv_cs_tsc.archdata.vclock_mode = VCLOCK_HVCLOCK;
|
|
|
|
clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100);
|
|
return;
|
|
}
|
|
register_msr_cs:
|
|
#endif
|
|
/*
|
|
* For 32 bit guests just use the MSR based mechanism for reading
|
|
* the partition counter.
|
|
*/
|
|
|
|
hyperv_cs = &hyperv_cs_msr;
|
|
if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
|
|
clocksource_register_hz(&hyperv_cs_msr, NSEC_PER_SEC/100);
|
|
|
|
return;
|
|
|
|
free_vp_index:
|
|
kfree(hv_vp_index);
|
|
hv_vp_index = NULL;
|
|
}
|
|
|
|
/*
|
|
* This routine is called before kexec/kdump, it does the required cleanup.
|
|
*/
|
|
void hyperv_cleanup(void)
|
|
{
|
|
union hv_x64_msr_hypercall_contents hypercall_msr;
|
|
|
|
/* Reset our OS id */
|
|
wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
|
|
|
|
/* Reset the hypercall page */
|
|
hypercall_msr.as_uint64 = 0;
|
|
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
|
|
|
|
/* Reset the TSC page */
|
|
hypercall_msr.as_uint64 = 0;
|
|
wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64);
|
|
}
|
|
EXPORT_SYMBOL_GPL(hyperv_cleanup);
|
|
|
|
void hyperv_report_panic(struct pt_regs *regs, long err)
|
|
{
|
|
static bool panic_reported;
|
|
u64 guest_id;
|
|
|
|
/*
|
|
* We prefer to report panic on 'die' chain as we have proper
|
|
* registers to report, but if we miss it (e.g. on BUG()) we need
|
|
* to report it on 'panic'.
|
|
*/
|
|
if (panic_reported)
|
|
return;
|
|
panic_reported = true;
|
|
|
|
rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id);
|
|
|
|
wrmsrl(HV_X64_MSR_CRASH_P0, err);
|
|
wrmsrl(HV_X64_MSR_CRASH_P1, guest_id);
|
|
wrmsrl(HV_X64_MSR_CRASH_P2, regs->ip);
|
|
wrmsrl(HV_X64_MSR_CRASH_P3, regs->ax);
|
|
wrmsrl(HV_X64_MSR_CRASH_P4, regs->sp);
|
|
|
|
/*
|
|
* Let Hyper-V know there is crash data available
|
|
*/
|
|
wrmsrl(HV_X64_MSR_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY);
|
|
}
|
|
EXPORT_SYMBOL_GPL(hyperv_report_panic);
|
|
|
|
bool hv_is_hypercall_page_setup(void)
|
|
{
|
|
union hv_x64_msr_hypercall_contents hypercall_msr;
|
|
|
|
/* Check if the hypercall page is setup */
|
|
hypercall_msr.as_uint64 = 0;
|
|
rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
|
|
|
|
if (!hypercall_msr.enable)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
EXPORT_SYMBOL_GPL(hv_is_hypercall_page_setup);
|