Skip to content

Commit 1f1dc44

Browse files
NunoDasNevesliuw
authored andcommitted
mshyperv: Introduce hv_numa_node_to_pxm_info()
Factor out logic for converting numa node to hv_proximity_domain_info into a helper function. Change hv_proximity_domain_info to a struct to improve readability. While at it, rename hv_add_logical_processor_* structs to the correct hv_input_/hv_output_ prefix, and remove the flags field which is not present in the ABI. Signed-off-by: Nuno Das Neves <[email protected]> Reviewed-by: Wei Liu <[email protected]> Link: https://lore.kernel.org/r/1711141826-9458-1-git-send-email-nunodasneves@linux.microsoft.com Signed-off-by: Wei Liu <[email protected]> Message-ID: <1711141826-9458-1-git-send-email-nunodasneves@linux.microsoft.com>
1 parent e249884 commit 1f1dc44

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

arch/x86/hyperv/hv_proc.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <linux/vmalloc.h>
44
#include <linux/mm.h>
55
#include <linux/clockchips.h>
6-
#include <linux/acpi.h>
76
#include <linux/hyperv.h>
87
#include <linux/slab.h>
98
#include <linux/cpuhotplug.h>
@@ -116,12 +115,11 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
116115

117116
int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
118117
{
119-
struct hv_add_logical_processor_in *input;
120-
struct hv_add_logical_processor_out *output;
118+
struct hv_input_add_logical_processor *input;
119+
struct hv_output_add_logical_processor *output;
121120
u64 status;
122121
unsigned long flags;
123122
int ret = HV_STATUS_SUCCESS;
124-
int pxm = node_to_pxm(node);
125123

126124
/*
127125
* When adding a logical processor, the hypervisor may return
@@ -137,11 +135,7 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
137135

138136
input->lp_index = lp_index;
139137
input->apic_id = apic_id;
140-
input->flags = 0;
141-
input->proximity_domain_info.domain_id = pxm;
142-
input->proximity_domain_info.flags.reserved = 0;
143-
input->proximity_domain_info.flags.proximity_info_valid = 1;
144-
input->proximity_domain_info.flags.proximity_preferred = 1;
138+
input->proximity_domain_info = hv_numa_node_to_pxm_info(node);
145139
status = hv_do_hypercall(HVCALL_ADD_LOGICAL_PROCESSOR,
146140
input, output);
147141
local_irq_restore(flags);
@@ -166,7 +160,6 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
166160
u64 status;
167161
unsigned long irq_flags;
168162
int ret = HV_STATUS_SUCCESS;
169-
int pxm = node_to_pxm(node);
170163

171164
/* Root VPs don't seem to need pages deposited */
172165
if (partition_id != hv_current_partition_id) {
@@ -185,14 +178,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
185178
input->vp_index = vp_index;
186179
input->flags = flags;
187180
input->subnode_type = HvSubnodeAny;
188-
if (node != NUMA_NO_NODE) {
189-
input->proximity_domain_info.domain_id = pxm;
190-
input->proximity_domain_info.flags.reserved = 0;
191-
input->proximity_domain_info.flags.proximity_info_valid = 1;
192-
input->proximity_domain_info.flags.proximity_preferred = 1;
193-
} else {
194-
input->proximity_domain_info.as_uint64 = 0;
195-
}
181+
input->proximity_domain_info = hv_numa_node_to_pxm_info(node);
196182
status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
197183
local_irq_restore(irq_flags);
198184

include/asm-generic/hyperv-tlfs.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,9 @@ struct hv_proximity_domain_flags {
512512
u32 proximity_info_valid : 1;
513513
} __packed;
514514

515-
/* Not a union in windows but useful for zeroing */
516-
union hv_proximity_domain_info {
517-
struct {
518-
u32 domain_id;
519-
struct hv_proximity_domain_flags flags;
520-
};
521-
u64 as_uint64;
515+
struct hv_proximity_domain_info {
516+
u32 domain_id;
517+
struct hv_proximity_domain_flags flags;
522518
} __packed;
523519

524520
struct hv_lp_startup_status {
@@ -532,14 +528,13 @@ struct hv_lp_startup_status {
532528
} __packed;
533529

534530
/* HvAddLogicalProcessor hypercall */
535-
struct hv_add_logical_processor_in {
531+
struct hv_input_add_logical_processor {
536532
u32 lp_index;
537533
u32 apic_id;
538-
union hv_proximity_domain_info proximity_domain_info;
539-
u64 flags;
534+
struct hv_proximity_domain_info proximity_domain_info;
540535
} __packed;
541536

542-
struct hv_add_logical_processor_out {
537+
struct hv_output_add_logical_processor {
543538
struct hv_lp_startup_status startup_status;
544539
} __packed;
545540

@@ -560,7 +555,7 @@ struct hv_create_vp {
560555
u8 padding[3];
561556
u8 subnode_type;
562557
u64 subnode_id;
563-
union hv_proximity_domain_info proximity_domain_info;
558+
struct hv_proximity_domain_info proximity_domain_info;
564559
u64 flags;
565560
} __packed;
566561

include/asm-generic/mshyperv.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/types.h>
2222
#include <linux/atomic.h>
2323
#include <linux/bitops.h>
24+
#include <acpi/acpi_numa.h>
2425
#include <linux/cpumask.h>
2526
#include <linux/nmi.h>
2627
#include <asm/ptrace.h>
@@ -67,6 +68,19 @@ extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
6768
bool hv_isolation_type_snp(void);
6869
bool hv_isolation_type_tdx(void);
6970

71+
static inline struct hv_proximity_domain_info hv_numa_node_to_pxm_info(int node)
72+
{
73+
struct hv_proximity_domain_info pxm_info = {};
74+
75+
if (node != NUMA_NO_NODE) {
76+
pxm_info.domain_id = node_to_pxm(node);
77+
pxm_info.flags.proximity_info_valid = 1;
78+
pxm_info.flags.proximity_preferred = 1;
79+
}
80+
81+
return pxm_info;
82+
}
83+
7084
/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
7185
static inline int hv_result(u64 status)
7286
{

0 commit comments

Comments
 (0)