hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/arch/arm/xen/p2m.c
....@@ -1,4 +1,5 @@
1
-#include <linux/bootmem.h>
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+#include <linux/memblock.h>
23 #include <linux/gfp.h>
34 #include <linux/export.h>
45 #include <linux/spinlock.h>
....@@ -61,17 +62,19 @@
6162
6263 unsigned long __pfn_to_mfn(unsigned long pfn)
6364 {
64
- struct rb_node *n = phys_to_mach.rb_node;
65
+ struct rb_node *n;
6566 struct xen_p2m_entry *entry;
6667 unsigned long irqflags;
6768
6869 read_lock_irqsave(&p2m_lock, irqflags);
70
+ n = phys_to_mach.rb_node;
6971 while (n) {
7072 entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys);
7173 if (entry->pfn <= pfn &&
7274 entry->pfn + entry->nr_pages > pfn) {
75
+ unsigned long mfn = entry->mfn + (pfn - entry->pfn);
7376 read_unlock_irqrestore(&p2m_lock, irqflags);
74
- return entry->mfn + (pfn - entry->pfn);
77
+ return mfn;
7578 }
7679 if (pfn < entry->pfn)
7780 n = n->rb_left;
....@@ -151,10 +154,11 @@
151154 int rc;
152155 unsigned long irqflags;
153156 struct xen_p2m_entry *p2m_entry;
154
- struct rb_node *n = phys_to_mach.rb_node;
157
+ struct rb_node *n;
155158
156159 if (mfn == INVALID_P2M_ENTRY) {
157160 write_lock_irqsave(&p2m_lock, irqflags);
161
+ n = phys_to_mach.rb_node;
158162 while (n) {
159163 p2m_entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys);
160164 if (p2m_entry->pfn <= pfn &&
....@@ -185,6 +189,7 @@
185189 rc = xen_add_phys_to_mach_entry(p2m_entry);
186190 if (rc < 0) {
187191 write_unlock_irqrestore(&p2m_lock, irqflags);
192
+ kfree(p2m_entry);
188193 return false;
189194 }
190195 write_unlock_irqrestore(&p2m_lock, irqflags);