Merge tag 'hyperv-fixes-signed-20240411' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Apr 2024 23:23:56 +0000 (16:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Apr 2024 23:23:56 +0000 (16:23 -0700)
Pull hyperv fixes from Wei Liu:

 - Some cosmetic changes (Erni Sri Satya Vennela, Li Zhijian)

 - Introduce hv_numa_node_to_pxm_info() (Nuno Das Neves)

 - Fix KVP daemon to handle IPv4 and IPv6 combination for keyfile format
   (Shradha Gupta)

 - Avoid freeing decrypted memory in a confidential VM (Rick Edgecombe
   and Michael Kelley)

* tag 'hyperv-fixes-signed-20240411' of git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux:
  Drivers: hv: vmbus: Don't free ring buffers that couldn't be re-encrypted
  uio_hv_generic: Don't free decrypted memory
  hv_netvsc: Don't free decrypted memory
  Drivers: hv: vmbus: Track decrypted status in vmbus_gpadl
  Drivers: hv: vmbus: Leak pages if set_memory_encrypted() fails
  hv/hv_kvp_daemon: Handle IPv4 and Ipv6 combination for keyfile format
  hv: vmbus: Convert sprintf() family to sysfs_emit() family
  mshyperv: Introduce hv_numa_node_to_pxm_info()
  x86/hyperv: Cosmetic changes for hv_apic.c

1  2 
drivers/hv/vmbus_drv.c
include/asm-generic/hyperv-tlfs.h
include/asm-generic/mshyperv.h

diff --combined drivers/hv/vmbus_drv.c
index 4cb17603a8289b259e64dc6a5be215cb1e1a8a57,121f1ab32b51c54ed42e4b269db6358e854eaccd..12a707ab73f85cf363e6503346741a85bc9b82df
@@@ -131,7 -131,7 +131,7 @@@ static ssize_t id_show(struct device *d
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n", hv_dev->channel->offermsg.child_relid);
+       return sysfs_emit(buf, "%d\n", hv_dev->channel->offermsg.child_relid);
  }
  static DEVICE_ATTR_RO(id);
  
@@@ -142,7 -142,7 +142,7 @@@ static ssize_t state_show(struct devic
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n", hv_dev->channel->state);
+       return sysfs_emit(buf, "%d\n", hv_dev->channel->state);
  }
  static DEVICE_ATTR_RO(state);
  
@@@ -153,7 -153,7 +153,7 @@@ static ssize_t monitor_id_show(struct d
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid);
+       return sysfs_emit(buf, "%d\n", hv_dev->channel->offermsg.monitorid);
  }
  static DEVICE_ATTR_RO(monitor_id);
  
@@@ -164,8 -164,8 +164,8 @@@ static ssize_t class_id_show(struct dev
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "{%pUl}\n",
-                      &hv_dev->channel->offermsg.offer.if_type);
+       return sysfs_emit(buf, "{%pUl}\n",
+                         &hv_dev->channel->offermsg.offer.if_type);
  }
  static DEVICE_ATTR_RO(class_id);
  
@@@ -176,8 -176,8 +176,8 @@@ static ssize_t device_id_show(struct de
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "{%pUl}\n",
-                      &hv_dev->channel->offermsg.offer.if_instance);
+       return sysfs_emit(buf, "{%pUl}\n",
+                         &hv_dev->channel->offermsg.offer.if_instance);
  }
  static DEVICE_ATTR_RO(device_id);
  
@@@ -186,7 -186,7 +186,7 @@@ static ssize_t modalias_show(struct dev
  {
        struct hv_device *hv_dev = device_to_hv_device(dev);
  
-       return sprintf(buf, "vmbus:%*phN\n", UUID_SIZE, &hv_dev->dev_type);
+       return sysfs_emit(buf, "vmbus:%*phN\n", UUID_SIZE, &hv_dev->dev_type);
  }
  static DEVICE_ATTR_RO(modalias);
  
@@@ -199,7 -199,7 +199,7 @@@ static ssize_t numa_node_show(struct de
        if (!hv_dev->channel)
                return -ENODEV;
  
-       return sprintf(buf, "%d\n", cpu_to_node(hv_dev->channel->target_cpu));
+       return sysfs_emit(buf, "%d\n", cpu_to_node(hv_dev->channel->target_cpu));
  }
  static DEVICE_ATTR_RO(numa_node);
  #endif
@@@ -212,9 -212,8 +212,8 @@@ static ssize_t server_monitor_pending_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_pending(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[0]));
+       return sysfs_emit(buf, "%d\n", channel_pending(hv_dev->channel,
+                         vmbus_connection.monitor_pages[0]));
  }
  static DEVICE_ATTR_RO(server_monitor_pending);
  
@@@ -226,9 -225,8 +225,8 @@@ static ssize_t client_monitor_pending_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_pending(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[1]));
+       return sysfs_emit(buf, "%d\n", channel_pending(hv_dev->channel,
+                         vmbus_connection.monitor_pages[1]));
  }
  static DEVICE_ATTR_RO(client_monitor_pending);
  
@@@ -240,9 -238,8 +238,8 @@@ static ssize_t server_monitor_latency_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_latency(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[0]));
+       return sysfs_emit(buf, "%d\n", channel_latency(hv_dev->channel,
+                         vmbus_connection.monitor_pages[0]));
  }
  static DEVICE_ATTR_RO(server_monitor_latency);
  
@@@ -254,9 -251,8 +251,8 @@@ static ssize_t client_monitor_latency_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_latency(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[1]));
+       return sysfs_emit(buf, "%d\n", channel_latency(hv_dev->channel,
+                         vmbus_connection.monitor_pages[1]));
  }
  static DEVICE_ATTR_RO(client_monitor_latency);
  
@@@ -268,9 -264,8 +264,8 @@@ static ssize_t server_monitor_conn_id_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_conn_id(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[0]));
+       return sysfs_emit(buf, "%d\n", channel_conn_id(hv_dev->channel,
+                         vmbus_connection.monitor_pages[0]));
  }
  static DEVICE_ATTR_RO(server_monitor_conn_id);
  
@@@ -282,9 -277,8 +277,8 @@@ static ssize_t client_monitor_conn_id_s
  
        if (!hv_dev->channel)
                return -ENODEV;
-       return sprintf(buf, "%d\n",
-                      channel_conn_id(hv_dev->channel,
-                                      vmbus_connection.monitor_pages[1]));
+       return sysfs_emit(buf, "%d\n", channel_conn_id(hv_dev->channel,
+                         vmbus_connection.monitor_pages[1]));
  }
  static DEVICE_ATTR_RO(client_monitor_conn_id);
  
@@@ -303,7 -297,7 +297,7 @@@ static ssize_t out_intr_mask_show(struc
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", outbound.current_interrupt_mask);
+       return sysfs_emit(buf, "%d\n", outbound.current_interrupt_mask);
  }
  static DEVICE_ATTR_RO(out_intr_mask);
  
@@@ -321,7 -315,7 +315,7 @@@ static ssize_t out_read_index_show(stru
                                          &outbound);
        if (ret < 0)
                return ret;
-       return sprintf(buf, "%d\n", outbound.current_read_index);
+       return sysfs_emit(buf, "%d\n", outbound.current_read_index);
  }
  static DEVICE_ATTR_RO(out_read_index);
  
@@@ -340,7 -334,7 +334,7 @@@ static ssize_t out_write_index_show(str
                                          &outbound);
        if (ret < 0)
                return ret;
-       return sprintf(buf, "%d\n", outbound.current_write_index);
+       return sysfs_emit(buf, "%d\n", outbound.current_write_index);
  }
  static DEVICE_ATTR_RO(out_write_index);
  
@@@ -359,7 -353,7 +353,7 @@@ static ssize_t out_read_bytes_avail_sho
                                          &outbound);
        if (ret < 0)
                return ret;
-       return sprintf(buf, "%d\n", outbound.bytes_avail_toread);
+       return sysfs_emit(buf, "%d\n", outbound.bytes_avail_toread);
  }
  static DEVICE_ATTR_RO(out_read_bytes_avail);
  
@@@ -378,7 -372,7 +372,7 @@@ static ssize_t out_write_bytes_avail_sh
                                          &outbound);
        if (ret < 0)
                return ret;
-       return sprintf(buf, "%d\n", outbound.bytes_avail_towrite);
+       return sysfs_emit(buf, "%d\n", outbound.bytes_avail_towrite);
  }
  static DEVICE_ATTR_RO(out_write_bytes_avail);
  
@@@ -396,7 -390,7 +390,7 @@@ static ssize_t in_intr_mask_show(struc
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", inbound.current_interrupt_mask);
+       return sysfs_emit(buf, "%d\n", inbound.current_interrupt_mask);
  }
  static DEVICE_ATTR_RO(in_intr_mask);
  
@@@ -414,7 -408,7 +408,7 @@@ static ssize_t in_read_index_show(struc
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", inbound.current_read_index);
+       return sysfs_emit(buf, "%d\n", inbound.current_read_index);
  }
  static DEVICE_ATTR_RO(in_read_index);
  
@@@ -432,7 -426,7 +426,7 @@@ static ssize_t in_write_index_show(stru
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", inbound.current_write_index);
+       return sysfs_emit(buf, "%d\n", inbound.current_write_index);
  }
  static DEVICE_ATTR_RO(in_write_index);
  
@@@ -451,7 -445,7 +445,7 @@@ static ssize_t in_read_bytes_avail_show
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", inbound.bytes_avail_toread);
+       return sysfs_emit(buf, "%d\n", inbound.bytes_avail_toread);
  }
  static DEVICE_ATTR_RO(in_read_bytes_avail);
  
@@@ -470,7 -464,7 +464,7 @@@ static ssize_t in_write_bytes_avail_sho
        if (ret < 0)
                return ret;
  
-       return sprintf(buf, "%d\n", inbound.bytes_avail_towrite);
+       return sysfs_emit(buf, "%d\n", inbound.bytes_avail_towrite);
  }
  static DEVICE_ATTR_RO(in_write_bytes_avail);
  
@@@ -480,7 -474,7 +474,7 @@@ static ssize_t channel_vp_mapping_show(
  {
        struct hv_device *hv_dev = device_to_hv_device(dev);
        struct vmbus_channel *channel = hv_dev->channel, *cur_sc;
-       int buf_size = PAGE_SIZE, n_written, tot_written;
+       int n_written;
        struct list_head *cur;
  
        if (!channel)
  
        mutex_lock(&vmbus_connection.channel_mutex);
  
-       tot_written = snprintf(buf, buf_size, "%u:%u\n",
-               channel->offermsg.child_relid, channel->target_cpu);
+       n_written = sysfs_emit(buf, "%u:%u\n",
+                              channel->offermsg.child_relid,
+                              channel->target_cpu);
  
        list_for_each(cur, &channel->sc_list) {
-               if (tot_written >= buf_size - 1)
-                       break;
  
                cur_sc = list_entry(cur, struct vmbus_channel, sc_list);
-               n_written = scnprintf(buf + tot_written,
-                                    buf_size - tot_written,
-                                    "%u:%u\n",
-                                    cur_sc->offermsg.child_relid,
-                                    cur_sc->target_cpu);
-               tot_written += n_written;
+               n_written += sysfs_emit_at(buf, n_written, "%u:%u\n",
+                                         cur_sc->offermsg.child_relid,
+                                         cur_sc->target_cpu);
        }
  
        mutex_unlock(&vmbus_connection.channel_mutex);
  
-       return tot_written;
+       return n_written;
  }
  static DEVICE_ATTR_RO(channel_vp_mapping);
  
@@@ -516,7 -506,7 +506,7 @@@ static ssize_t vendor_show(struct devic
  {
        struct hv_device *hv_dev = device_to_hv_device(dev);
  
-       return sprintf(buf, "0x%x\n", hv_dev->vendor_id);
+       return sysfs_emit(buf, "0x%x\n", hv_dev->vendor_id);
  }
  static DEVICE_ATTR_RO(vendor);
  
@@@ -526,7 -516,7 +516,7 @@@ static ssize_t device_show(struct devic
  {
        struct hv_device *hv_dev = device_to_hv_device(dev);
  
-       return sprintf(buf, "0x%x\n", hv_dev->device_id);
+       return sysfs_emit(buf, "0x%x\n", hv_dev->device_id);
  }
  static DEVICE_ATTR_RO(device);
  
@@@ -551,7 -541,7 +541,7 @@@ static ssize_t driver_override_show(str
        ssize_t len;
  
        device_lock(dev);
-       len = snprintf(buf, PAGE_SIZE, "%s\n", hv_dev->driver_override);
+       len = sysfs_emit(buf, "%s\n", hv_dev->driver_override);
        device_unlock(dev);
  
        return len;
@@@ -2359,9 -2349,10 +2349,9 @@@ static int vmbus_platform_driver_probe(
                return vmbus_acpi_add(pdev);
  }
  
 -static int vmbus_platform_driver_remove(struct platform_device *pdev)
 +static void vmbus_platform_driver_remove(struct platform_device *pdev)
  {
        vmbus_mmio_remove();
 -      return 0;
  }
  
  #ifdef CONFIG_PM_SLEEP
@@@ -2541,7 -2532,7 +2531,7 @@@ static const struct dev_pm_ops vmbus_bu
  
  static struct platform_driver vmbus_platform_driver = {
        .probe = vmbus_platform_driver_probe,
 -      .remove = vmbus_platform_driver_remove,
 +      .remove_new = vmbus_platform_driver_remove,
        .driver = {
                .name = "vmbus",
                .acpi_match_table = ACPI_PTR(vmbus_acpi_device_ids),
index 87e3d49a4e29bf7af1de43d1da45bfd9ca3791ea,69f3f68dc249a2e96f96b5a1e329894fe4f53374..814207e7c37fcf17a65638f68ceda02e400c58fa
@@@ -512,13 -512,9 +512,9 @@@ struct hv_proximity_domain_flags 
        u32 proximity_info_valid : 1;
  } __packed;
  
- /* Not a union in windows but useful for zeroing */
- union hv_proximity_domain_info {
-       struct {
-               u32 domain_id;
-               struct hv_proximity_domain_flags flags;
-       };
-       u64 as_uint64;
+ struct hv_proximity_domain_info {
+       u32 domain_id;
+       struct hv_proximity_domain_flags flags;
  } __packed;
  
  struct hv_lp_startup_status {
  } __packed;
  
  /* HvAddLogicalProcessor hypercall */
- struct hv_add_logical_processor_in {
+ struct hv_input_add_logical_processor {
        u32 lp_index;
        u32 apic_id;
-       union hv_proximity_domain_info proximity_domain_info;
-       u64 flags;
+       struct hv_proximity_domain_info proximity_domain_info;
  } __packed;
  
- struct hv_add_logical_processor_out {
+ struct hv_output_add_logical_processor {
        struct hv_lp_startup_status startup_status;
  } __packed;
  
@@@ -560,7 -555,7 +555,7 @@@ struct hv_create_vp 
        u8 padding[3];
        u8 subnode_type;
        u64 subnode_id;
-       union hv_proximity_domain_info proximity_domain_info;
+       struct hv_proximity_domain_info proximity_domain_info;
        u64 flags;
  } __packed;
  
@@@ -625,37 -620,6 +620,37 @@@ struct hv_retarget_device_interrupt 
        struct hv_device_interrupt_target int_target;
  } __packed __aligned(8);
  
 +/*
 + * These Hyper-V registers provide information equivalent to the CPUID
 + * instruction on x86/x64.
 + */
 +#define HV_REGISTER_HYPERVISOR_VERSION                0x00000100 /*CPUID 0x40000002 */
 +#define HV_REGISTER_FEATURES                  0x00000200 /*CPUID 0x40000003 */
 +#define HV_REGISTER_ENLIGHTENMENTS            0x00000201 /*CPUID 0x40000004 */
 +
 +/*
 + * Synthetic register definitions equivalent to MSRs on x86/x64
 + */
 +#define HV_REGISTER_GUEST_CRASH_P0    0x00000210
 +#define HV_REGISTER_GUEST_CRASH_P1    0x00000211
 +#define HV_REGISTER_GUEST_CRASH_P2    0x00000212
 +#define HV_REGISTER_GUEST_CRASH_P3    0x00000213
 +#define HV_REGISTER_GUEST_CRASH_P4    0x00000214
 +#define HV_REGISTER_GUEST_CRASH_CTL   0x00000215
 +
 +#define HV_REGISTER_GUEST_OS_ID               0x00090002
 +#define HV_REGISTER_VP_INDEX          0x00090003
 +#define HV_REGISTER_TIME_REF_COUNT    0x00090004
 +#define HV_REGISTER_REFERENCE_TSC     0x00090017
 +
 +#define HV_REGISTER_SINT0             0x000A0000
 +#define HV_REGISTER_SCONTROL          0x000A0010
 +#define HV_REGISTER_SIEFP             0x000A0012
 +#define HV_REGISTER_SIMP              0x000A0013
 +#define HV_REGISTER_EOM                       0x000A0014
 +
 +#define HV_REGISTER_STIMER0_CONFIG    0x000B0000
 +#define HV_REGISTER_STIMER0_COUNT     0x000B0001
  
  /* HvGetVpRegisters hypercall input with variable size reg name list*/
  struct hv_get_vp_registers_input {
        } element[];
  } __packed;
  
 -
  /* HvGetVpRegisters returns an array of these output elements */
  struct hv_get_vp_registers_output {
        union {
@@@ -817,29 -782,6 +812,29 @@@ struct hv_input_unmap_device_interrupt 
  #define HV_SOURCE_SHADOW_NONE               0x0
  #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE   0x1
  
 +/*
 + * Version info reported by hypervisor
 + */
 +union hv_hypervisor_version_info {
 +      struct {
 +              u32 build_number;
 +
 +              u32 minor_version : 16;
 +              u32 major_version : 16;
 +
 +              u32 service_pack;
 +
 +              u32 service_number : 24;
 +              u32 service_branch : 8;
 +      };
 +      struct {
 +              u32 eax;
 +              u32 ebx;
 +              u32 ecx;
 +              u32 edx;
 +      };
 +};
 +
  /*
   * The whole argument should fit in a page to be able to pass to the hypervisor
   * in one hypercall.
index 99935779682dc29180f556469c4487603b082740,cfb0b51a0998262d98099235572031fffed8c410..8fe7aaab25990aa2fdebd81463b9ac9dedd36945
@@@ -21,6 -21,7 +21,7 @@@
  #include <linux/types.h>
  #include <linux/atomic.h>
  #include <linux/bitops.h>
+ #include <acpi/acpi_numa.h>
  #include <linux/cpumask.h>
  #include <linux/nmi.h>
  #include <asm/ptrace.h>
@@@ -67,6 -68,19 +68,19 @@@ extern u64 hv_do_fast_hypercall8(u16 co
  bool hv_isolation_type_snp(void);
  bool hv_isolation_type_tdx(void);
  
+ static inline struct hv_proximity_domain_info hv_numa_node_to_pxm_info(int node)
+ {
+       struct hv_proximity_domain_info pxm_info = {};
+       if (node != NUMA_NO_NODE) {
+               pxm_info.domain_id = node_to_pxm(node);
+               pxm_info.flags.proximity_info_valid = 1;
+               pxm_info.flags.proximity_preferred = 1;
+       }
+       return pxm_info;
+ }
  /* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
  static inline int hv_result(u64 status)
  {
@@@ -157,12 -171,10 +171,12 @@@ static inline void vmbus_signal_eom(str
                 * possibly deliver another msg from the
                 * hypervisor
                 */
 -              hv_set_register(HV_REGISTER_EOM, 0);
 +              hv_set_msr(HV_MSR_EOM, 0);
        }
  }
  
 +int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
 +
  void hv_setup_vmbus_handler(void (*handler)(void));
  void hv_remove_vmbus_handler(void);
  void hv_setup_stimer0_handler(void (*handler)(void));
@@@ -195,7 -207,6 +209,7 @@@ extern u64 (*hv_read_reference_counter)
  
  int __init hv_common_init(void);
  void __init hv_common_free(void);
 +void __init ms_hyperv_late_init(void);
  int hv_common_cpu_init(unsigned int cpu);
  int hv_common_cpu_die(unsigned int cpu);
  
@@@ -293,7 -304,6 +307,7 @@@ void hv_setup_dma_ops(struct device *de
  static inline bool hv_is_hyperv_initialized(void) { return false; }
  static inline bool hv_is_hibernation_supported(void) { return false; }
  static inline void hyperv_cleanup(void) {}
 +static inline void ms_hyperv_late_init(void) {}
  static inline bool hv_is_isolation_supported(void) { return false; }
  static inline enum hv_isolation_type hv_get_isolation_type(void)
  {