[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <420bf947-2dc5-4a6b-9766-0eff4d1e1618@linux.microsoft.com>
Date: Fri, 23 Jan 2026 10:23:04 -0800
From: Nuno Das Neves <nunodasneves@...ux.microsoft.com>
To: Mukesh R <mrathor@...ux.microsoft.com>, linux-kernel@...r.kernel.org,
linux-hyperv@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
iommu@...ts.linux.dev, linux-pci@...r.kernel.org, linux-arch@...r.kernel.org
Cc: kys@...rosoft.com, haiyangz@...rosoft.com, wei.liu@...nel.org,
decui@...rosoft.com, longli@...rosoft.com, catalin.marinas@....com,
will@...nel.org, tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, hpa@...or.com, joro@...tes.org,
lpieralisi@...nel.org, kwilczynski@...nel.org, mani@...nel.org,
robh@...nel.org, bhelgaas@...gle.com, arnd@...db.de, mhklinux@...look.com,
romank@...ux.microsoft.com
Subject: Re: [PATCH v0 04/15] mshv: Provide a way to get partition id if
running in a VMM process
On 1/19/2026 10:42 PM, Mukesh R wrote:
> From: Mukesh Rathor <mrathor@...ux.microsoft.com>
>
> Many PCI passthru related hypercalls require partition id of the target
> guest. Guests are actually managed by MSHV driver and the partition id
> is only maintained there. Add a field in the partition struct in MSHV
> driver to save the tgid of the VMM process creating the partition,
> and add a function there to retrieve partition id if valid VMM tgid.
>
> Signed-off-by: Mukesh Rathor <mrathor@...ux.microsoft.com>
> ---
> drivers/hv/mshv_root.h | 1 +
> drivers/hv/mshv_root_main.c | 35 +++++++++++++++++++++++++++-------
> include/asm-generic/mshyperv.h | 1 +
> 3 files changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h
> index 3c1d88b36741..c3753b009fd8 100644
> --- a/drivers/hv/mshv_root.h
> +++ b/drivers/hv/mshv_root.h
> @@ -134,6 +134,7 @@ struct mshv_partition {
>
> struct mshv_girq_routing_table __rcu *pt_girq_tbl;
> u64 isolation_type;
> + pid_t pt_vmm_tgid;
> bool import_completed;
> bool pt_initialized;
> };
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 1134a82c7881..83c7bad269a0 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -1823,6 +1823,20 @@ mshv_partition_release(struct inode *inode, struct file *filp)
> return 0;
> }
>
> +/* Given a process tgid, return partition id if it is a VMM process */
> +u64 mshv_pid_to_partid(pid_t tgid)
> +{
> + struct mshv_partition *pt;
> + int i;
> +
> + hash_for_each_rcu(mshv_root.pt_htable, i, pt, pt_hnode)
> + if (pt->pt_vmm_tgid == tgid)
> + return pt->pt_id;
> +
> + return HV_PARTITION_ID_INVALID;
> +}
> +EXPORT_SYMBOL_GPL(mshv_pid_to_partid);
> +
> static int
> add_partition(struct mshv_partition *partition)
> {
> @@ -1987,13 +2001,20 @@ mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
> goto delete_partition;
>
> ret = mshv_init_async_handler(partition);
> - if (!ret) {
> - ret = FD_ADD(O_CLOEXEC, anon_inode_getfile("mshv_partition",
> - &mshv_partition_fops,
> - partition, O_RDWR));
> - if (ret >= 0)
> - return ret;
> - }
> + if (ret)
> + goto rem_partition;
> +
> + ret = FD_ADD(O_CLOEXEC, anon_inode_getfile("mshv_partition",
> + &mshv_partition_fops,
> + partition, O_RDWR));
> + if (ret < 0)
> + goto rem_partition;
> +
> + partition->pt_vmm_tgid = current->tgid;
> +
> + return ret;
> +
> +rem_partition:
> remove_partition(partition);
> delete_partition:
> hv_call_delete_partition(partition->pt_id);
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index ecedab554c80..e46a38916e76 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -211,6 +211,7 @@ void __init ms_hyperv_late_init(void);
> int hv_common_cpu_init(unsigned int cpu);
> int hv_common_cpu_die(unsigned int cpu);
> void hv_identify_partition_type(void);
> +u64 mshv_pid_to_partid(pid_t tgid);
This should go inside the #if IS_ENABLED(CONFIG_MSHV_ROOT) section.
>
> /**
> * hv_cpu_number_to_vp_number() - Map CPU to VP.
Powered by blists - more mailing lists