mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mukesh R <mrathor@linux.microsoft.com>
To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	iommu@lists.linux.dev, linux-arch@vger.kernel.org
Cc: jgg@nvidia.com, jacob.pan@linux.microsoft.com,
	haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
	joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
	arnd@arndb.de, mrathor@linux.microsoft.com
Subject: [PATCH V3 1/5] mshv: Add gfp flags to deposit memory logic
Date: Mon,  2 Nov 2026 18:51:46 -0800	[thread overview]
Message-ID: <20261103025150.3192119-2-mrathor@linux.microsoft.com> (raw)
In-Reply-To: <20261103025150.3192119-1-mrathor@linux.microsoft.com>

Currently GFP_KERNEL is hard coded in hv_alloc_dep_pages(). Add gfp_flags
parameter so it can be called in atomic context from map_pages callback in
struct iommu_domain_ops and other places in future. A new function
hv_deposit_memory_gfp() is added to facilitate this, so hv_deposit_memory()
can continue to function as is.

Signed-off-by: Mukesh R <mrathor@linux.microsoft.com>
---
 drivers/hv/hv_proc.c           | 20 +++++++++++---------
 include/asm-generic/mshyperv.h | 14 +++++++++++---
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index f811bb5c42a1..8380e9050f46 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -22,7 +22,7 @@
  * Returns: number of pages allocated or -ENOMEM
  */
 static int hv_alloc_dep_pages(int node, u64 *pfna, u64 *lastpfnp, int num_pages,
-			      bool single)
+			      bool single, gfp_t gfp_flags)
 {
 	struct page *page;
 	int num_allocd, count = 0;
@@ -37,7 +37,6 @@ static int hv_alloc_dep_pages(int node, u64 *pfna, u64 *lastpfnp, int num_pages,
 	while (num_pages) {
 		/* Find highest order we can actually allocate */
 		int order = 31 - __builtin_clz(num_pages);
-		gfp_t gfp_flags = GFP_KERNEL;
 
 		if (!single)
 			gfp_flags |= __GFP_NOWARN;
@@ -81,7 +80,8 @@ static int hv_alloc_dep_pages(int node, u64 *pfna, u64 *lastpfnp, int num_pages,
  * so we must split that also. Lastly, HV_MAX_CONTIGUOUS_ALLOCATION_PAGES is
  * not guaranteed to always be power of 2.
  */
-static int hv_call_deposit_pages(int node, u64 partition_id, bool contiguous)
+static int hv_call_deposit_pages(int node, u64 partition_id, bool contiguous,
+				 gfp_t gfp_flags)
 {
 	struct hv_deposit_memory *hc_input;
 	int i, rc, num_pages;
@@ -98,14 +98,15 @@ static int hv_call_deposit_pages(int node, u64 partition_id, bool contiguous)
 		num_pages = HV_DEPOSIT_MAX;
 	}
 
-	hc_input = (struct hv_deposit_memory *)get_zeroed_page(GFP_KERNEL);
+	hc_input = (struct hv_deposit_memory *)get_zeroed_page(gfp_flags);
 	if (hc_input == NULL)
 		return -ENOMEM;
 
 	hc_input->partition_id = partition_id;
 	pfna = hc_input->gpa_page_list;
 
-	rc = hv_alloc_dep_pages(node, pfna, &lastpfn, num_pages, contiguous);
+	rc = hv_alloc_dep_pages(node, pfna, &lastpfn, num_pages, contiguous,
+				gfp_flags);
 	if (rc < 0)
 		goto out_free;
 
@@ -159,7 +160,7 @@ static int hv_call_deposit_pages(int node, u64 partition_id, bool contiguous)
 	return rc;
 }
 
-int hv_deposit_memory_node(int node, u64 pt_id, u64 hv_status)
+int hv_deposit_memory_node(int node, u64 pt_id, u64 hv_status, gfp_t gfp_flags)
 {
 	int result = hv_result(hv_status);
 	bool contiguous = false;
@@ -179,7 +180,7 @@ int hv_deposit_memory_node(int node, u64 pt_id, u64 hv_status)
 	    result == HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY)
 		contiguous = true;
 
-	return hv_call_deposit_pages(node, pt_id, contiguous);
+	return hv_call_deposit_pages(node, pt_id, contiguous, gfp_flags);
 }
 EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
 
@@ -232,7 +233,7 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 			break;
 		}
 		ret = hv_deposit_memory_node(node, hv_current_partition_id,
-					     status);
+					     status, GFP_KERNEL);
 	} while (!ret);
 
 	return ret;
@@ -266,7 +267,8 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
 			}
 			break;
 		}
-		ret = hv_deposit_memory_node(node, partition_id, status);
+		ret = hv_deposit_memory_node(node, partition_id, status,
+					     GFP_KERNEL);
 
 	} while (!ret);
 
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index 4c9f3353074a..2584e693d7b3 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -346,7 +346,7 @@ static inline bool hv_parent_partition(void)
 }
 
 bool hv_result_needs_memory(u64 status);
-int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
+int hv_deposit_memory_node(int node, u64 partition_id, u64 status, gfp_t gfp);
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
 int hv_call_notify_all_processors_started(void);
 bool hv_lp_exists(u32 lp_index);
@@ -357,7 +357,8 @@ static inline bool hv_root_partition(void) { return false; }
 static inline bool hv_l1vh_partition(void) { return false; }
 static inline bool hv_parent_partition(void) { return false; }
 static inline bool hv_result_needs_memory(u64 status) { return false; }
-static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
+static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status,
+					 gfp_t gfp)
 {
 	return -EOPNOTSUPP;
 }
@@ -379,9 +380,16 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
 }
 #endif /* CONFIG_MSHV_ROOT */
 
+/* Generic deposit function with no default numa node and GFP_KERNEL */
 static inline int hv_deposit_memory(u64 partition_id, u64 status)
 {
-	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
+	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status,
+				      GFP_KERNEL);
+}
+
+static inline int hv_deposit_memory_gfp(u64 partition_id, u64 status, gfp_t gfp)
+{
+	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status, gfp);
 }
 
 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
-- 
2.51.2.vfs.0.1


  reply	other threads:[~2026-11-03  2:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  2:51 [PATCH V3 0/5] Hyper-V: root VM iommu kernel only driver Mukesh R
2026-11-03  2:51 ` Mukesh R [this message]
2026-11-03  2:51 ` [PATCH V3 2/5] PCI: hv: Export hv_build_devid_type_pci() and change return type Mukesh R
2026-11-03  2:51 ` [PATCH V3 3/5] mshv: Import data structs around device domains from hyperv headers Mukesh R
2026-11-03  3:17   ` Easwar Hariharan
2026-11-03  2:51 ` [PATCH V3 4/5] iommu/hyperv: Only call pviommu init on non-root VMs Mukesh R
2026-11-03  2:51 ` [PATCH V3 5/5] x86/hyperv: Implement root partition IOMMU kernel only driver Mukesh R

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103025150.3192119-2-mrathor@linux.microsoft.com \
    --to=mrathor@linux.microsoft.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=iommu@lists.linux.dev \
    --cc=jacob.pan@linux.microsoft.com \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=tglx@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®