Skip to content

Commit 18c83d2

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "Fixes in qemu, vhost and virtio" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: fw_cfg: fix the command line module name vhost/vsock: fix uninitialized vhost_vsock->guest_cid vhost: fix end of range for access_ok vhost/scsi: Use safe iteration in vhost_scsi_complete_cmd_work() virtio_balloon: fix deadlock on OOM
2 parents 051089a + c1d0c3f commit 18c83d2

File tree

7 files changed

+84
-21
lines changed

7 files changed

+84
-21
lines changed

drivers/firmware/qemu_fw_cfg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* and select subsets of aarch64), a Device Tree node (on arm), or using
1111
* a kernel module (or command line) parameter with the following syntax:
1212
*
13-
* [fw_cfg.]ioport=<size>@<base>[:<ctrl_off>:<data_off>]
13+
* [qemu_fw_cfg.]ioport=<size>@<base>[:<ctrl_off>:<data_off>]
1414
* or
15-
* [fw_cfg.]mmio=<size>@<base>[:<ctrl_off>:<data_off>]
15+
* [qemu_fw_cfg.]mmio=<size>@<base>[:<ctrl_off>:<data_off>]
1616
*
1717
* where:
1818
* <size> := size of ioport or mmio range
@@ -21,9 +21,9 @@
2121
* <data_off> := (optional) offset of data register
2222
*
2323
* e.g.:
24-
* fw_cfg.ioport=2@0x510:0:1 (the default on x86)
24+
* qemu_fw_cfg.ioport=2@0x510:0:1 (the default on x86)
2525
* or
26-
* fw_cfg.mmio=0xA@0x9020000:8:0 (the default on arm)
26+
* qemu_fw_cfg.mmio=0xA@0x9020000:8:0 (the default on arm)
2727
*/
2828

2929
#include <linux/module.h>

drivers/vhost/scsi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,15 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
519519
vs_completion_work);
520520
DECLARE_BITMAP(signal, VHOST_SCSI_MAX_VQ);
521521
struct virtio_scsi_cmd_resp v_rsp;
522-
struct vhost_scsi_cmd *cmd;
522+
struct vhost_scsi_cmd *cmd, *t;
523523
struct llist_node *llnode;
524524
struct se_cmd *se_cmd;
525525
struct iov_iter iov_iter;
526526
int ret, vq;
527527

528528
bitmap_zero(signal, VHOST_SCSI_MAX_VQ);
529529
llnode = llist_del_all(&vs->vs_completion_list);
530-
llist_for_each_entry(cmd, llnode, tvc_completion_list) {
530+
llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) {
531531
se_cmd = &cmd->tvc_se_cmd;
532532

533533
pr_debug("%s tv_cmd %p resid %u status %#02x\n", __func__,

drivers/vhost/vhost.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,15 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
11751175
{
11761176
const struct vhost_umem_node *node;
11771177
struct vhost_umem *umem = vq->iotlb;
1178-
u64 s = 0, size, orig_addr = addr;
1178+
u64 s = 0, size, orig_addr = addr, last = addr + len - 1;
11791179

11801180
if (vhost_vq_meta_fetch(vq, addr, len, type))
11811181
return true;
11821182

11831183
while (len > s) {
11841184
node = vhost_umem_interval_tree_iter_first(&umem->umem_tree,
11851185
addr,
1186-
addr + len - 1);
1186+
last);
11871187
if (node == NULL || node->start > addr) {
11881188
vhost_iotlb_miss(vq, addr, access);
11891189
return false;

drivers/vhost/vsock.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file)
518518
goto out;
519519
}
520520

521+
vsock->guest_cid = 0; /* no CID assigned yet */
522+
521523
atomic_set(&vsock->queued_replies, 0);
522524

523525
vqs[VSOCK_VQ_TX] = &vsock->vqs[VSOCK_VQ_TX];

drivers/virtio/virtio_balloon.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,17 @@ static void set_page_pfns(struct virtio_balloon *vb,
143143

144144
static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
145145
{
146-
struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info;
147146
unsigned num_allocated_pages;
147+
unsigned num_pfns;
148+
struct page *page;
149+
LIST_HEAD(pages);
148150

149151
/* We can only do one array worth at a time. */
150152
num = min(num, ARRAY_SIZE(vb->pfns));
151153

152-
mutex_lock(&vb->balloon_lock);
153-
for (vb->num_pfns = 0; vb->num_pfns < num;
154-
vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
155-
struct page *page = balloon_page_enqueue(vb_dev_info);
154+
for (num_pfns = 0; num_pfns < num;
155+
num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE) {
156+
struct page *page = balloon_page_alloc();
156157

157158
if (!page) {
158159
dev_info_ratelimited(&vb->vdev->dev,
@@ -162,6 +163,19 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
162163
msleep(200);
163164
break;
164165
}
166+
167+
balloon_page_push(&pages, page);
168+
}
169+
170+
mutex_lock(&vb->balloon_lock);
171+
172+
vb->num_pfns = 0;
173+
174+
while ((page = balloon_page_pop(&pages))) {
175+
balloon_page_enqueue(&vb->vb_dev_info, page);
176+
177+
vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE;
178+
165179
set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
166180
vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
167181
if (!virtio_has_feature(vb->vdev,

include/linux/balloon_compaction.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/gfp.h>
5151
#include <linux/err.h>
5252
#include <linux/fs.h>
53+
#include <linux/list.h>
5354

5455
/*
5556
* Balloon device information descriptor.
@@ -67,7 +68,9 @@ struct balloon_dev_info {
6768
struct inode *inode;
6869
};
6970

70-
extern struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info);
71+
extern struct page *balloon_page_alloc(void);
72+
extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
73+
struct page *page);
7174
extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
7275

7376
static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
@@ -193,4 +196,34 @@ static inline gfp_t balloon_mapping_gfp_mask(void)
193196
}
194197

195198
#endif /* CONFIG_BALLOON_COMPACTION */
199+
200+
/*
201+
* balloon_page_push - insert a page into a page list.
202+
* @head : pointer to list
203+
* @page : page to be added
204+
*
205+
* Caller must ensure the page is private and protect the list.
206+
*/
207+
static inline void balloon_page_push(struct list_head *pages, struct page *page)
208+
{
209+
list_add(&page->lru, pages);
210+
}
211+
212+
/*
213+
* balloon_page_pop - remove a page from a page list.
214+
* @head : pointer to list
215+
* @page : page to be added
216+
*
217+
* Caller must ensure the page is private and protect the list.
218+
*/
219+
static inline struct page *balloon_page_pop(struct list_head *pages)
220+
{
221+
struct page *page = list_first_entry_or_null(pages, struct page, lru);
222+
223+
if (!page)
224+
return NULL;
225+
226+
list_del(&page->lru);
227+
return page;
228+
}
196229
#endif /* _LINUX_BALLOON_COMPACTION_H */

mm/balloon_compaction.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,38 @@
1010
#include <linux/export.h>
1111
#include <linux/balloon_compaction.h>
1212

13+
/*
14+
* balloon_page_alloc - allocates a new page for insertion into the balloon
15+
* page list.
16+
*
17+
* Driver must call it to properly allocate a new enlisted balloon page.
18+
* Driver must call balloon_page_enqueue before definitively removing it from
19+
* the guest system. This function returns the page address for the recently
20+
* allocated page or NULL in the case we fail to allocate a new page this turn.
21+
*/
22+
struct page *balloon_page_alloc(void)
23+
{
24+
struct page *page = alloc_page(balloon_mapping_gfp_mask() |
25+
__GFP_NOMEMALLOC | __GFP_NORETRY);
26+
return page;
27+
}
28+
EXPORT_SYMBOL_GPL(balloon_page_alloc);
29+
1330
/*
1431
* balloon_page_enqueue - allocates a new page and inserts it into the balloon
1532
* page list.
1633
* @b_dev_info: balloon device descriptor where we will insert a new page to
34+
* @page: new page to enqueue - allocated using balloon_page_alloc.
1735
*
18-
* Driver must call it to properly allocate a new enlisted balloon page
36+
* Driver must call it to properly enqueue a new allocated balloon page
1937
* before definitively removing it from the guest system.
2038
* This function returns the page address for the recently enqueued page or
2139
* NULL in the case we fail to allocate a new page this turn.
2240
*/
23-
struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info)
41+
void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
42+
struct page *page)
2443
{
2544
unsigned long flags;
26-
struct page *page = alloc_page(balloon_mapping_gfp_mask() |
27-
__GFP_NOMEMALLOC | __GFP_NORETRY);
28-
if (!page)
29-
return NULL;
3045

3146
/*
3247
* Block others from accessing the 'page' when we get around to
@@ -39,7 +54,6 @@ struct page *balloon_page_enqueue(struct balloon_dev_info *b_dev_info)
3954
__count_vm_event(BALLOON_INFLATE);
4055
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
4156
unlock_page(page);
42-
return page;
4357
}
4458
EXPORT_SYMBOL_GPL(balloon_page_enqueue);
4559

0 commit comments

Comments
 (0)