| .. | .. |
|---|
| 1 | | -#include <linux/bootmem.h> |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 2 | +#include <linux/memblock.h> |
|---|
| 2 | 3 | #include <linux/gfp.h> |
|---|
| 3 | 4 | #include <linux/export.h> |
|---|
| 4 | 5 | #include <linux/spinlock.h> |
|---|
| .. | .. |
|---|
| 61 | 62 | |
|---|
| 62 | 63 | unsigned long __pfn_to_mfn(unsigned long pfn) |
|---|
| 63 | 64 | { |
|---|
| 64 | | - struct rb_node *n = phys_to_mach.rb_node; |
|---|
| 65 | + struct rb_node *n; |
|---|
| 65 | 66 | struct xen_p2m_entry *entry; |
|---|
| 66 | 67 | unsigned long irqflags; |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | read_lock_irqsave(&p2m_lock, irqflags); |
|---|
| 70 | + n = phys_to_mach.rb_node; |
|---|
| 69 | 71 | while (n) { |
|---|
| 70 | 72 | entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys); |
|---|
| 71 | 73 | if (entry->pfn <= pfn && |
|---|
| 72 | 74 | entry->pfn + entry->nr_pages > pfn) { |
|---|
| 75 | + unsigned long mfn = entry->mfn + (pfn - entry->pfn); |
|---|
| 73 | 76 | read_unlock_irqrestore(&p2m_lock, irqflags); |
|---|
| 74 | | - return entry->mfn + (pfn - entry->pfn); |
|---|
| 77 | + return mfn; |
|---|
| 75 | 78 | } |
|---|
| 76 | 79 | if (pfn < entry->pfn) |
|---|
| 77 | 80 | n = n->rb_left; |
|---|
| .. | .. |
|---|
| 151 | 154 | int rc; |
|---|
| 152 | 155 | unsigned long irqflags; |
|---|
| 153 | 156 | struct xen_p2m_entry *p2m_entry; |
|---|
| 154 | | - struct rb_node *n = phys_to_mach.rb_node; |
|---|
| 157 | + struct rb_node *n; |
|---|
| 155 | 158 | |
|---|
| 156 | 159 | if (mfn == INVALID_P2M_ENTRY) { |
|---|
| 157 | 160 | write_lock_irqsave(&p2m_lock, irqflags); |
|---|
| 161 | + n = phys_to_mach.rb_node; |
|---|
| 158 | 162 | while (n) { |
|---|
| 159 | 163 | p2m_entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys); |
|---|
| 160 | 164 | if (p2m_entry->pfn <= pfn && |
|---|
| .. | .. |
|---|
| 185 | 189 | rc = xen_add_phys_to_mach_entry(p2m_entry); |
|---|
| 186 | 190 | if (rc < 0) { |
|---|
| 187 | 191 | write_unlock_irqrestore(&p2m_lock, irqflags); |
|---|
| 192 | + kfree(p2m_entry); |
|---|
| 188 | 193 | return false; |
|---|
| 189 | 194 | } |
|---|
| 190 | 195 | write_unlock_irqrestore(&p2m_lock, irqflags); |
|---|