Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <nunodasneves@linux.microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/1740167795-13296-4-git-send-email-nunodasneves@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1740167795-13296-4-git-send-email-nunodasneves@linux.microsoft.com>

authored by

Nuno Das Neves and committed by
Wei Liu
461fbbd0 db912b89

+42 -6
+16
drivers/hv/Kconfig
··· 55 55 help 56 56 Select this option to enable Hyper-V Balloon driver. 57 57 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 + 58 74 endmenu
+2 -1
drivers/hv/Makefile
··· 13 13 hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o 14 14 15 15 # 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
+4 -1
drivers/hv/hv_common.c
··· 734 734 (ms_hyperv.priv_high & HV_CPU_MANAGEMENT) && 735 735 !(ms_hyperv.priv_high & HV_ISOLATION)) { 736 736 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"); 738 741 } 739 742 }
+20 -4
include/asm-generic/mshyperv.h
··· 223 223 void *hv_alloc_hyperv_zeroed_page(void); 224 224 void hv_free_hyperv_page(void *addr); 225 225 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 - 230 226 /** 231 227 * hv_cpu_number_to_vp_number() - Map CPU to VP. 232 228 * @cpu_number: CPU number in Linux terms ··· 323 327 } 324 328 #endif /* CONFIG_HYPERV */ 325 329 330 + #if IS_ENABLED(CONFIG_MSHV_ROOT) 326 331 static inline bool hv_root_partition(void) 327 332 { 328 333 return hv_curr_partition_type == HV_PARTITION_TYPE_ROOT; 329 334 } 335 + int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); 336 + int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); 337 + int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); 338 + 339 + #else /* CONFIG_MSHV_ROOT */ 340 + static inline bool hv_root_partition(void) { return false; } 341 + static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) 342 + { 343 + return -EOPNOTSUPP; 344 + } 345 + static inline int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id) 346 + { 347 + return -EOPNOTSUPP; 348 + } 349 + static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags) 350 + { 351 + return -EOPNOTSUPP; 352 + } 353 + #endif /* CONFIG_MSHV_ROOT */ 330 354 331 355 #endif