Skip to content

Commit 461fbbd

Browse files
NunoDasNevesliuw
authored andcommitted
hyperv: Add CONFIG_MSHV_ROOT to gate root partition support
CONFIG_MSHV_ROOT allows kernels built to run as a normal Hyper-V guest to exclude the root partition code, which is expected to grow significantly over time. This option is a tristate so future driver code can be built as a (m)odule, allowing faster development iteration cycles. If CONFIG_MSHV_ROOT is disabled, don't compile hv_proc.c, and stub hv_root_partition() to return false unconditionally. This allows the compiler to optimize away root partition code blocks since they will be disabled at compile time. In the case of booting as root partition *without* CONFIG_MSHV_ROOT enabled, print a critical error (the kernel will likely crash). Signed-off-by: Nuno Das Neves <[email protected]> Reviewed-by: Easwar Hariharan <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/1740167795-13296-4-git-send-email-nunodasneves@linux.microsoft.com Signed-off-by: Wei Liu <[email protected]> Message-ID: <1740167795-13296-4-git-send-email-nunodasneves@linux.microsoft.com>
1 parent db912b8 commit 461fbbd

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

drivers/hv/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,20 @@ config HYPERV_BALLOON
5555
help
5656
Select this option to enable Hyper-V Balloon driver.
5757

58+
config MSHV_ROOT
59+
tristate "Microsoft Hyper-V root partition support"
60+
depends on HYPERV && (X86_64 || ARM64)
61+
depends on !HYPERV_VTL_MODE
62+
# The hypervisor interface operates on 4k pages. Enforcing it here
63+
# simplifies many assumptions in the root partition code.
64+
# e.g. When withdrawing memory, the hypervisor gives back 4k pages in
65+
# no particular order, making it impossible to reassemble larger pages
66+
depends on PAGE_SIZE_4KB
67+
default n
68+
help
69+
Select this option to enable support for booting and running as root
70+
partition on Microsoft Hyper-V.
71+
72+
If unsure, say N.
73+
5874
endmenu

drivers/hv/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o
1313
hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o
1414

1515
# Code that must be built-in
16-
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o hv_proc.o
16+
obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o
17+
obj-$(subst m,y,$(CONFIG_MSHV_ROOT)) += hv_proc.o

drivers/hv/hv_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@ void hv_identify_partition_type(void)
734734
(ms_hyperv.priv_high & HV_CPU_MANAGEMENT) &&
735735
!(ms_hyperv.priv_high & HV_ISOLATION)) {
736736
pr_info("Hyper-V: running as root partition\n");
737-
hv_curr_partition_type = HV_PARTITION_TYPE_ROOT;
737+
if (IS_ENABLED(CONFIG_MSHV_ROOT))
738+
hv_curr_partition_type = HV_PARTITION_TYPE_ROOT;
739+
else
740+
pr_crit("Hyper-V: CONFIG_MSHV_ROOT not enabled!\n");
738741
}
739742
}

include/asm-generic/mshyperv.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ void *hv_alloc_hyperv_page(void);
223223
void *hv_alloc_hyperv_zeroed_page(void);
224224
void hv_free_hyperv_page(void *addr);
225225

226-
int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
227-
int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
228-
int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
229-
230226
/**
231227
* hv_cpu_number_to_vp_number() - Map CPU to VP.
232228
* @cpu_number: CPU number in Linux terms
@@ -327,9 +323,29 @@ static inline enum hv_isolation_type hv_get_isolation_type(void)
327323
}
328324
#endif /* CONFIG_HYPERV */
329325

326+
#if IS_ENABLED(CONFIG_MSHV_ROOT)
330327
static inline bool hv_root_partition(void)
331328
{
332329
return hv_curr_partition_type == HV_PARTITION_TYPE_ROOT;
333330
}
331+
int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
332+
int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
333+
int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
334+
335+
#else /* CONFIG_MSHV_ROOT */
336+
static inline bool hv_root_partition(void) { return false; }
337+
static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
338+
{
339+
return -EOPNOTSUPP;
340+
}
341+
static inline int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id)
342+
{
343+
return -EOPNOTSUPP;
344+
}
345+
static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
346+
{
347+
return -EOPNOTSUPP;
348+
}
349+
#endif /* CONFIG_MSHV_ROOT */
334350

335351
#endif

0 commit comments

Comments
 (0)