Skip to content

Commit a4d7e8a

Browse files
kelleymhliuw
authored andcommitted
Drivers: hv: Move Hyper-V extended capability check to arch neutral code
The extended capability query code is currently under arch/x86, but it is architecture neutral, and is used by arch neutral code in the Hyper-V balloon driver. Hence the balloon driver fails to build on other architectures. Fix by moving the ext cap code out from arch/x86. Because it is also called from built-in architecture specific code, it can't be in a module, so the Makefile treats as built-in even when CONFIG_HYPERV is "m". Also drivers/Makefile is tweaked because this is the first occurrence of a Hyper-V file that is built-in even when CONFIG_HYPERV is "m". While here, update the hypercall status check to use the new helper function instead of open coding. No functional change. Signed-off-by: Michael Kelley <[email protected]> Reviewed-by: Sunil Muthuswamy <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 9de6655 commit a4d7e8a

File tree

4 files changed

+70
-48
lines changed

4 files changed

+70
-48
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -614,50 +614,3 @@ bool hv_is_isolation_supported(void)
614614
return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE;
615615
}
616616
EXPORT_SYMBOL_GPL(hv_is_isolation_supported);
617-
618-
/* Bit mask of the extended capability to query: see HV_EXT_CAPABILITY_xxx */
619-
bool hv_query_ext_cap(u64 cap_query)
620-
{
621-
/*
622-
* The address of the 'hv_extended_cap' variable will be used as an
623-
* output parameter to the hypercall below and so it should be
624-
* compatible with 'virt_to_phys'. Which means, it's address should be
625-
* directly mapped. Use 'static' to keep it compatible; stack variables
626-
* can be virtually mapped, making them imcompatible with
627-
* 'virt_to_phys'.
628-
* Hypercall input/output addresses should also be 8-byte aligned.
629-
*/
630-
static u64 hv_extended_cap __aligned(8);
631-
static bool hv_extended_cap_queried;
632-
u64 status;
633-
634-
/*
635-
* Querying extended capabilities is an extended hypercall. Check if the
636-
* partition supports extended hypercall, first.
637-
*/
638-
if (!(ms_hyperv.priv_high & HV_ENABLE_EXTENDED_HYPERCALLS))
639-
return false;
640-
641-
/* Extended capabilities do not change at runtime. */
642-
if (hv_extended_cap_queried)
643-
return hv_extended_cap & cap_query;
644-
645-
status = hv_do_hypercall(HV_EXT_CALL_QUERY_CAPABILITIES, NULL,
646-
&hv_extended_cap);
647-
648-
/*
649-
* The query extended capabilities hypercall should not fail under
650-
* any normal circumstances. Avoid repeatedly making the hypercall, on
651-
* error.
652-
*/
653-
hv_extended_cap_queried = true;
654-
status &= HV_HYPERCALL_RESULT_MASK;
655-
if (status != HV_STATUS_SUCCESS) {
656-
pr_err("Hyper-V: Extended query capabilities hypercall failed 0x%llx\n",
657-
status);
658-
return false;
659-
}
660-
661-
return hv_extended_cap & cap_query;
662-
}
663-
EXPORT_SYMBOL_GPL(hv_query_ext_cap);

drivers/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ obj-$(CONFIG_SOUNDWIRE) += soundwire/
161161

162162
# Virtualization drivers
163163
obj-$(CONFIG_VIRT_DRIVERS) += virt/
164-
obj-$(CONFIG_HYPERV) += hv/
164+
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv/
165165

166166
obj-$(CONFIG_PM_DEVFREQ) += devfreq/
167167
obj-$(CONFIG_EXTCON) += extcon/

drivers/hv/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ hv_vmbus-y := vmbus_drv.o \
1111
channel_mgmt.o ring_buffer.o hv_trace.o
1212
hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o
1313
hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o
14+
15+
# Code that must be built-in
16+
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o

drivers/hv/hv_common.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/*
4+
* Architecture neutral utility routines for interacting with
5+
* Hyper-V. This file is specifically for code that must be
6+
* built-in to the kernel image when CONFIG_HYPERV is set
7+
* (vs. being in a module) because it is called from architecture
8+
* specific code under arch/.
9+
*
10+
* Copyright (C) 2021, Microsoft, Inc.
11+
*
12+
* Author : Michael Kelley <[email protected]>
13+
*/
14+
15+
#include <linux/types.h>
16+
#include <linux/export.h>
17+
#include <linux/bitfield.h>
18+
#include <asm/hyperv-tlfs.h>
19+
#include <asm/mshyperv.h>
20+
21+
22+
/* Bit mask of the extended capability to query: see HV_EXT_CAPABILITY_xxx */
23+
bool hv_query_ext_cap(u64 cap_query)
24+
{
25+
/*
26+
* The address of the 'hv_extended_cap' variable will be used as an
27+
* output parameter to the hypercall below and so it should be
28+
* compatible with 'virt_to_phys'. Which means, it's address should be
29+
* directly mapped. Use 'static' to keep it compatible; stack variables
30+
* can be virtually mapped, making them imcompatible with
31+
* 'virt_to_phys'.
32+
* Hypercall input/output addresses should also be 8-byte aligned.
33+
*/
34+
static u64 hv_extended_cap __aligned(8);
35+
static bool hv_extended_cap_queried;
36+
u64 status;
37+
38+
/*
39+
* Querying extended capabilities is an extended hypercall. Check if the
40+
* partition supports extended hypercall, first.
41+
*/
42+
if (!(ms_hyperv.priv_high & HV_ENABLE_EXTENDED_HYPERCALLS))
43+
return false;
44+
45+
/* Extended capabilities do not change at runtime. */
46+
if (hv_extended_cap_queried)
47+
return hv_extended_cap & cap_query;
48+
49+
status = hv_do_hypercall(HV_EXT_CALL_QUERY_CAPABILITIES, NULL,
50+
&hv_extended_cap);
51+
52+
/*
53+
* The query extended capabilities hypercall should not fail under
54+
* any normal circumstances. Avoid repeatedly making the hypercall, on
55+
* error.
56+
*/
57+
hv_extended_cap_queried = true;
58+
if (!hv_result_success(status)) {
59+
pr_err("Hyper-V: Extended query capabilities hypercall failed 0x%llx\n",
60+
status);
61+
return false;
62+
}
63+
64+
return hv_extended_cap & cap_query;
65+
}
66+
EXPORT_SYMBOL_GPL(hv_query_ext_cap);

0 commit comments

Comments
 (0)