aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2015-05-08 08:31:44 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2015-06-19 11:16:25 -0400
commite73f61e41f3bb9bc453fd9c21b82d0b89c2b83e7 (patch)
tree83de18fd1a1c68c9fd14762e2b6a7faa0cd8d728
parent05fe125fa3237de2ec5bada80031e694de78909c (diff)
kvm: irqchip: Break up high order allocations of kvm_irq_routing_table
The allocation size of the kvm_irq_routing_table depends on the number of irq routing entries because they are all allocated with one kzalloc call. When the irq routing table gets bigger this requires high order allocations which fail from time to time: qemu-kvm: page allocation failure: order:4, mode:0xd0 This patch fixes this issue by breaking up the allocation of the table and its entries into individual kzalloc calls. These could all be satisfied with order-0 allocations, which are less likely to fail. The downside of this change is the lower performance, because of more calls to kzalloc. But given how often kvm_set_irq_routing is called in the lifetime of a guest, it doesn't really matter much. Signed-off-by: Joerg Roedel <jroedel@suse.de> [Avoid sparse warning through rcu_access_pointer. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--virt/kvm/irqchip.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/virt/kvm/irqchip.c b/virt/kvm/irqchip.c
index 1d56a901e791..21c14244f4c4 100644
--- a/virt/kvm/irqchip.c
+++ b/virt/kvm/irqchip.c
@@ -33,7 +33,6 @@
33 33
34struct kvm_irq_routing_table { 34struct kvm_irq_routing_table {
35 int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS]; 35 int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS];
36 struct kvm_kernel_irq_routing_entry *rt_entries;
37 u32 nr_rt_entries; 36 u32 nr_rt_entries;
38 /* 37 /*
39 * Array indexed by gsi. Each entry contains list of irq chips 38 * Array indexed by gsi. Each entry contains list of irq chips
@@ -118,11 +117,32 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
118 return ret; 117 return ret;
119} 118}
120 119
120static void free_irq_routing_table(struct kvm_irq_routing_table *rt)
121{
122 int i;
123
124 if (!rt)
125 return;
126
127 for (i = 0; i < rt->nr_rt_entries; ++i) {
128 struct kvm_kernel_irq_routing_entry *e;
129 struct hlist_node *n;
130
131 hlist_for_each_entry_safe(e, n, &rt->map[i], link) {
132 hlist_del(&e->link);
133 kfree(e);
134 }
135 }
136
137 kfree(rt);
138}
139
121void kvm_free_irq_routing(struct kvm *kvm) 140void kvm_free_irq_routing(struct kvm *kvm)
122{ 141{
123 /* Called only during vm destruction. Nobody can use the pointer 142 /* Called only during vm destruction. Nobody can use the pointer
124 at this stage */ 143 at this stage */
125 kfree(kvm->irq_routing); 144 struct kvm_irq_routing_table *rt = rcu_access_pointer(kvm->irq_routing);
145 free_irq_routing_table(rt);
126} 146}
127 147
128static int setup_routing_entry(struct kvm_irq_routing_table *rt, 148static int setup_routing_entry(struct kvm_irq_routing_table *rt,
@@ -173,25 +193,29 @@ int kvm_set_irq_routing(struct kvm *kvm,
173 193
174 nr_rt_entries += 1; 194 nr_rt_entries += 1;
175 195
176 new = kzalloc(sizeof(*new) + (nr_rt_entries * sizeof(struct hlist_head)) 196 new = kzalloc(sizeof(*new) + (nr_rt_entries * sizeof(struct hlist_head)),
177 + (nr * sizeof(struct kvm_kernel_irq_routing_entry)),
178 GFP_KERNEL); 197 GFP_KERNEL);
179 198
180 if (!new) 199 if (!new)
181 return -ENOMEM; 200 return -ENOMEM;
182 201
183 new->rt_entries = (void *)&new->map[nr_rt_entries];
184
185 new->nr_rt_entries = nr_rt_entries; 202 new->nr_rt_entries = nr_rt_entries;
186 for (i = 0; i < KVM_NR_IRQCHIPS; i++) 203 for (i = 0; i < KVM_NR_IRQCHIPS; i++)
187 for (j = 0; j < KVM_IRQCHIP_NUM_PINS; j++) 204 for (j = 0; j < KVM_IRQCHIP_NUM_PINS; j++)
188 new->chip[i][j] = -1; 205 new->chip[i][j] = -1;
189 206
190 for (i = 0; i < nr; ++i) { 207 for (i = 0; i < nr; ++i) {
208 struct kvm_kernel_irq_routing_entry *e;
209
210 r = -ENOMEM;
211 e = kzalloc(sizeof(*e), GFP_KERNEL);
212 if (!e)
213 goto out;
214
191 r = -EINVAL; 215 r = -EINVAL;
192 if (ue->flags) 216 if (ue->flags)
193 goto out; 217 goto out;
194 r = setup_routing_entry(new, &new->rt_entries[i], ue); 218 r = setup_routing_entry(new, e, ue);
195 if (r) 219 if (r)
196 goto out; 220 goto out;
197 ++ue; 221 ++ue;
@@ -209,6 +233,7 @@ int kvm_set_irq_routing(struct kvm *kvm,
209 r = 0; 233 r = 0;
210 234
211out: 235out:
212 kfree(new); 236 free_irq_routing_table(new);
237
213 return r; 238 return r;
214} 239}