Skip to content

Commit 05c8c94

Browse files
committed
Merge tag 'hyperv-fixes-signed-20231121' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux
Pull hyperv fixes from Wei Liu: - One fix for the KVP daemon (Ani Sinha) - Fix for the detection of E820_TYPE_PRAM in a Gen2 VM (Saurabh Sengar) - Micro-optimization for hv_nmi_unknown() (Uros Bizjak) * tag 'hyperv-fixes-signed-20231121' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux: x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM hv/hv_kvp_daemon: Some small fixes for handling NM keyfiles
2 parents 125b0bb + 1828688 commit 05c8c94

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/io.h>
1616
#include <asm/apic.h>
1717
#include <asm/desc.h>
18+
#include <asm/e820/api.h>
1819
#include <asm/sev.h>
1920
#include <asm/ibt.h>
2021
#include <asm/hypervisor.h>
@@ -286,15 +287,31 @@ static int hv_cpu_die(unsigned int cpu)
286287

287288
static int __init hv_pci_init(void)
288289
{
289-
int gen2vm = efi_enabled(EFI_BOOT);
290+
bool gen2vm = efi_enabled(EFI_BOOT);
290291

291292
/*
292-
* For Generation-2 VM, we exit from pci_arch_init() by returning 0.
293-
* The purpose is to suppress the harmless warning:
293+
* A Generation-2 VM doesn't support legacy PCI/PCIe, so both
294+
* raw_pci_ops and raw_pci_ext_ops are NULL, and pci_subsys_init() ->
295+
* pcibios_init() doesn't call pcibios_resource_survey() ->
296+
* e820__reserve_resources_late(); as a result, any emulated persistent
297+
* memory of E820_TYPE_PRAM (12) via the kernel parameter
298+
* memmap=nn[KMG]!ss is not added into iomem_resource and hence can't be
299+
* detected by register_e820_pmem(). Fix this by directly calling
300+
* e820__reserve_resources_late() here: e820__reserve_resources_late()
301+
* depends on e820__reserve_resources(), which has been called earlier
302+
* from setup_arch(). Note: e820__reserve_resources_late() also adds
303+
* any memory of E820_TYPE_PMEM (7) into iomem_resource, and
304+
* acpi_nfit_register_region() -> acpi_nfit_insert_resource() ->
305+
* region_intersects() returns REGION_INTERSECTS, so the memory of
306+
* E820_TYPE_PMEM won't get added twice.
307+
*
308+
* We return 0 here so that pci_arch_init() won't print the warning:
294309
* "PCI: Fatal: No config space access function found"
295310
*/
296-
if (gen2vm)
311+
if (gen2vm) {
312+
e820__reserve_resources_late();
297313
return 0;
314+
}
298315

299316
/* For Generation-1 VM, we'll proceed in pci_arch_init(). */
300317
return 1;

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void)
262262
static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs)
263263
{
264264
static atomic_t nmi_cpu = ATOMIC_INIT(-1);
265+
unsigned int old_cpu, this_cpu;
265266

266267
if (!unknown_nmi_panic)
267268
return NMI_DONE;
268269

269-
if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1)
270+
old_cpu = -1;
271+
this_cpu = raw_smp_processor_id();
272+
if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu))
270273
return NMI_HANDLED;
271274

272275
return NMI_DONE;

tools/hv/hv_kvp_daemon.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
14211421
if (error)
14221422
goto setval_error;
14231423

1424-
if (new_val->addr_family == ADDR_FAMILY_IPV6) {
1424+
if (new_val->addr_family & ADDR_FAMILY_IPV6) {
14251425
error = fprintf(nmfile, "\n[ipv6]\n");
14261426
if (error < 0)
14271427
goto setval_error;
@@ -1455,14 +1455,18 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
14551455
if (error < 0)
14561456
goto setval_error;
14571457

1458-
error = fprintf(nmfile, "gateway=%s\n", (char *)new_val->gate_way);
1459-
if (error < 0)
1460-
goto setval_error;
1461-
1462-
error = fprintf(nmfile, "dns=%s\n", (char *)new_val->dns_addr);
1463-
if (error < 0)
1464-
goto setval_error;
1458+
/* we do not want ipv4 addresses in ipv6 section and vice versa */
1459+
if (is_ipv6 != is_ipv4((char *)new_val->gate_way)) {
1460+
error = fprintf(nmfile, "gateway=%s\n", (char *)new_val->gate_way);
1461+
if (error < 0)
1462+
goto setval_error;
1463+
}
14651464

1465+
if (is_ipv6 != is_ipv4((char *)new_val->dns_addr)) {
1466+
error = fprintf(nmfile, "dns=%s\n", (char *)new_val->dns_addr);
1467+
if (error < 0)
1468+
goto setval_error;
1469+
}
14661470
fclose(nmfile);
14671471
fclose(ifcfg_file);
14681472

tools/hv/hv_set_ifconfig.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
# or "manual" if no boot-time protocol should be used)
5454
#
5555
# address1=ipaddr1/plen
56-
# address=ipaddr2/plen
56+
# address2=ipaddr2/plen
5757
#
5858
# gateway=gateway1;gateway2
5959
#
6060
# dns=dns1;
6161
#
6262
# [ipv6]
6363
# address1=ipaddr1/plen
64-
# address2=ipaddr1/plen
64+
# address2=ipaddr2/plen
6565
#
6666
# gateway=gateway1;gateway2
6767
#

0 commit comments

Comments
 (0)