History

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio/vhost fixes from Michael Tsirkin: - Fixes in the iommu and balloon devices. - Disable the meta-data optimization for now - I hope we can get it fixed shortly, but there's no point in making users suffer crashes while we are working on that. * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: disable metadata prefetch optimization iommu/virtio: Update to most recent specification balloon: fix up comments mm/balloon_compaction: avoid duplicate page removal

Linus Torvalds committed 7 years ago

Commit 2a11c762 parents 45aee68 73f628e4 files · +89 −54Browse files

Unified · Split

4 files
  1. drivers/iommu/virtio-iommu.c +29 −11
  2. drivers/vhost/vhost.h +1 −1
  3. include/uapi/linux/virtio_iommu.h +18 −14
  4. mm/balloon_compaction.c +41 −28
drivers/iommu/virtio-iommu.c+29−11
@@ -2,7 +2,7 @@ · 1 unmodified line
22 /*
33 * Virtio driver for the paravirtualized IOMMU
44 *
5− * Copyright (C) 2018 Arm Limited
5+ * Copyright (C) 2019 Arm Limited
66 */
77
88 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -47,7 +47,10 @@ struct viommu_dev { · 38 unmodified lines
4747 /* Device configuration */
4848 struct iommu_domain_geometry geometry;
4949 u64 pgsize_bitmap;
50− u8 domain_bits;
50+ u32 first_domain;
51+ u32 last_domain;
52+ /* Supported MAP flags */
53+ u32 map_flags;
5154 u32 probe_size;
5255 };
5356
@@ -62,6 +65,7 @@ struct viommu_domain { · 8 unmodified lines
6265 struct viommu_dev *viommu;
6366 struct mutex mutex; /* protects viommu pointer */
6467 unsigned int id;
68+ u32 map_flags;
6569
6670 spinlock_t mappings_lock;
6771 struct rb_root_cached mappings;
@@ -113,6 +117,8 @@ static int viommu_get_req_errno(void *buf, size_t len) · 45 unmodified lines
113117 return -ENOENT;
114118 case VIRTIO_IOMMU_S_FAULT:
115119 return -EFAULT;
120+ case VIRTIO_IOMMU_S_NOMEM:
121+ return -ENOMEM;
116122 case VIRTIO_IOMMU_S_IOERR:
117123 case VIRTIO_IOMMU_S_DEVERR:
118124 default:
@@ -607,15 +613,15 @@ static int viommu_domain_finalise(struct viommu_dev *viommu, · 488 unmodified lines
607613 {
608614 int ret;
609615 struct viommu_domain *vdomain = to_viommu_domain(domain);
610− unsigned int max_domain = viommu->domain_bits > 31 ? ~0 :
611− (1U << viommu->domain_bits) - 1;
612616
613617 vdomain->viommu = viommu;
618+ vdomain->map_flags = viommu->map_flags;
614619
615620 domain->pgsize_bitmap = viommu->pgsize_bitmap;
616621 domain->geometry = viommu->geometry;
617622
618− ret = ida_alloc_max(&viommu->domain_ids, max_domain, GFP_KERNEL);
623+ ret = ida_alloc_range(&viommu->domain_ids, viommu->first_domain,
624+ viommu->last_domain, GFP_KERNEL);
619625 if (ret >= 0)
620626 vdomain->id = (unsigned int)ret;
621627
@@ -710,7 +716,7 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova, · 88 unmodified lines
710716 phys_addr_t paddr, size_t size, int prot)
711717 {
712718 int ret;
713− int flags;
719+ u32 flags;
714720 struct virtio_iommu_req_map map;
715721 struct viommu_domain *vdomain = to_viommu_domain(domain);
716722
@@ -718,6 +724,9 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova, · 1 unmodified line
718724 (prot & IOMMU_WRITE ? VIRTIO_IOMMU_MAP_F_WRITE : 0) |
719725 (prot & IOMMU_MMIO ? VIRTIO_IOMMU_MAP_F_MMIO : 0);
720726
727+ if (flags & ~vdomain->map_flags)
728+ return -EINVAL;
729+
721730 ret = viommu_add_mapping(vdomain, iova, paddr, size, flags);
722731 if (ret)
723732 return ret;
@@ -1027,7 +1036,8 @@ static int viommu_probe(struct virtio_device *vdev) · 303 unmodified lines
10271036 goto err_free_vqs;
10281037 }
10291038
1030− viommu->domain_bits = 32;
1039+ viommu->map_flags = VIRTIO_IOMMU_MAP_F_READ | VIRTIO_IOMMU_MAP_F_WRITE;
1040+ viommu->last_domain = ~0U;
10311041
10321042 /* Optional features */
10331043 virtio_cread_feature(vdev, VIRTIO_IOMMU_F_INPUT_RANGE,
@@ -1038,9 +1048,13 @@ static int viommu_probe(struct virtio_device *vdev) · 4 unmodified lines
10381048 struct virtio_iommu_config, input_range.end,
10391049 &input_end);
10401050
1041− virtio_cread_feature(vdev, VIRTIO_IOMMU_F_DOMAIN_BITS,
1042− struct virtio_iommu_config, domain_bits,
1043− &viommu->domain_bits);
1051+ virtio_cread_feature(vdev, VIRTIO_IOMMU_F_DOMAIN_RANGE,
1052+ struct virtio_iommu_config, domain_range.start,
1053+ &viommu->first_domain);
1054+
1055+ virtio_cread_feature(vdev, VIRTIO_IOMMU_F_DOMAIN_RANGE,
1056+ struct virtio_iommu_config, domain_range.end,
1057+ &viommu->last_domain);
10441058
10451059 virtio_cread_feature(vdev, VIRTIO_IOMMU_F_PROBE,
10461060 struct virtio_iommu_config, probe_size,
@@ -1052,6 +1066,9 @@ static int viommu_probe(struct virtio_device *vdev) · 5 unmodified lines
10521066 .force_aperture = true,
10531067 };
10541068
1069+ if (virtio_has_feature(vdev, VIRTIO_IOMMU_F_MMIO))
1070+ viommu->map_flags |= VIRTIO_IOMMU_MAP_F_MMIO;
1071+
10551072 viommu_ops.pgsize_bitmap = viommu->pgsize_bitmap;
10561073
10571074 virtio_device_ready(vdev);
@@ -1130,9 +1147,10 @@ static void viommu_config_changed(struct virtio_device *vdev) · 72 unmodified lines
11301147
11311148 static unsigned int features[] = {
11321149 VIRTIO_IOMMU_F_MAP_UNMAP,
1133− VIRTIO_IOMMU_F_DOMAIN_BITS,
11341150 VIRTIO_IOMMU_F_INPUT_RANGE,
1151+ VIRTIO_IOMMU_F_DOMAIN_RANGE,
11351152 VIRTIO_IOMMU_F_PROBE,
1153+ VIRTIO_IOMMU_F_MMIO,
11361154 };
11371155
11381156 static struct virtio_device_id id_table[] = {
drivers/vhost/vhost.h+1−1
@@ -96,7 +96,7 @@ struct vhost_uaddr { · 95 unmodified lines
9696 };
9797
9898 #if defined(CONFIG_MMU_NOTIFIER) && ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 0
99−#define VHOST_ARCH_CAN_ACCEL_UACCESS 1
99+#define VHOST_ARCH_CAN_ACCEL_UACCESS 0
100100 #else
101101 #define VHOST_ARCH_CAN_ACCEL_UACCESS 0
102102 #endif
include/uapi/linux/virtio_iommu.h+18−14
@@ -1,8 +1,8 @@
11 /* SPDX-License-Identifier: BSD-3-Clause */
22 /*
3− * Virtio-iommu definition v0.9
3+ * Virtio-iommu definition v0.12
44 *
5− * Copyright (C) 2018 Arm Ltd.
5+ * Copyright (C) 2019 Arm Ltd.
66 */
77 #ifndef _UAPI_LINUX_VIRTIO_IOMMU_H
88 #define _UAPI_LINUX_VIRTIO_IOMMU_H
@@ -11,26 +11,31 @@ · 2 unmodified lines
1111
1212 /* Feature bits */
1313 #define VIRTIO_IOMMU_F_INPUT_RANGE 0
14−#define VIRTIO_IOMMU_F_DOMAIN_BITS 1
14+#define VIRTIO_IOMMU_F_DOMAIN_RANGE 1
1515 #define VIRTIO_IOMMU_F_MAP_UNMAP 2
1616 #define VIRTIO_IOMMU_F_BYPASS 3
1717 #define VIRTIO_IOMMU_F_PROBE 4
18+#define VIRTIO_IOMMU_F_MMIO 5
1819
19−struct virtio_iommu_range {
20− __u64 start;
21− __u64 end;
20+struct virtio_iommu_range_64 {
21+ __le64 start;
22+ __le64 end;
23+};
24+
25+struct virtio_iommu_range_32 {
26+ __le32 start;
27+ __le32 end;
2228 };
2329
2430 struct virtio_iommu_config {
2531 /* Supported page sizes */
26− __u64 page_size_mask;
32+ __le64 page_size_mask;
2733 /* Supported IOVA range */
28− struct virtio_iommu_range input_range;
34+ struct virtio_iommu_range_64 input_range;
2935 /* Max domain ID size */
30− __u8 domain_bits;
31− __u8 padding[3];
36+ struct virtio_iommu_range_32 domain_range;
3237 /* Probe buffer size */
33− __u32 probe_size;
38+ __le32 probe_size;
3439 };
3540
3641 /* Request types */
@@ -49,6 +54,7 @@ struct virtio_iommu_config { · 12 unmodified lines
4954 #define VIRTIO_IOMMU_S_RANGE 0x05
5055 #define VIRTIO_IOMMU_S_NOENT 0x06
5156 #define VIRTIO_IOMMU_S_FAULT 0x07
57+#define VIRTIO_IOMMU_S_NOMEM 0x08
5258
5359 struct virtio_iommu_req_head {
5460 __u8 type;
@@ -78,12 +84,10 @@ struct virtio_iommu_req_detach { · 23 unmodified lines
7884
7985 #define VIRTIO_IOMMU_MAP_F_READ (1 << 0)
8086 #define VIRTIO_IOMMU_MAP_F_WRITE (1 << 1)
81−#define VIRTIO_IOMMU_MAP_F_EXEC (1 << 2)
82−#define VIRTIO_IOMMU_MAP_F_MMIO (1 << 3)
87+#define VIRTIO_IOMMU_MAP_F_MMIO (1 << 2)
8388
8489 #define VIRTIO_IOMMU_MAP_F_MASK (VIRTIO_IOMMU_MAP_F_READ | \
8590 VIRTIO_IOMMU_MAP_F_WRITE | \
86− VIRTIO_IOMMU_MAP_F_EXEC | \
8791 VIRTIO_IOMMU_MAP_F_MMIO)
8892
8993 struct virtio_iommu_req_map {
mm/balloon_compaction.c+41−28
@@ -21,7 +21,6 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info, · 20 unmodified lines
2121 * memory corruption is possible and we should stop execution.
2222 */
2323 BUG_ON(!trylock_page(page));
24− list_del(&page->lru);
2524 balloon_page_insert(b_dev_info, page);
2625 unlock_page(page);
2726 __count_vm_event(BALLOON_INFLATE);
@@ -33,8 +32,8 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info, · 5 unmodified lines
3332 * @b_dev_info: balloon device descriptor where we will insert a new page to
3433 * @pages: pages to enqueue - allocated using balloon_page_alloc.
3534 *
36− * Driver must call it to properly enqueue a balloon pages before definitively
37− * removing it from the guest system.
35+ * Driver must call this function to properly enqueue balloon pages before
36+ * definitively removing them from the guest system.
3837 *
3938 * Return: number of pages that were enqueued.
4039 */
@@ -47,6 +46,7 @@ size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info, · 6 unmodified lines
4746
4847 spin_lock_irqsave(&b_dev_info->pages_lock, flags);
4948 list_for_each_entry_safe(page, tmp, pages, lru) {
49+ list_del(&page->lru);
5050 balloon_page_enqueue_one(b_dev_info, page);
5151 n_pages++;
5252 }
@@ -63,12 +63,13 @@ EXPORT_SYMBOL_GPL(balloon_page_list_enqueue); · 10 unmodified lines
6363 * @n_req_pages: number of requested pages.
6464 *
6565 * Driver must call this function to properly de-allocate a previous enlisted
66− * balloon pages before definetively releasing it back to the guest system.
66+ * balloon pages before definitively releasing it back to the guest system.
6767 * This function tries to remove @n_req_pages from the ballooned pages and
6868 * return them to the caller in the @pages list.
6969 *
70− * Note that this function may fail to dequeue some pages temporarily empty due
71− * to compaction isolated pages.
70+ * Note that this function may fail to dequeue some pages even if the balloon
71+ * isn't empty - since the page list can be temporarily empty due to compaction
72+ * of isolated pages.
7273 *
7374 * Return: number of pages that were added to the @pages list.
7475 */
@@ -112,12 +113,13 @@ EXPORT_SYMBOL_GPL(balloon_page_list_dequeue); · 37 unmodified lines
112113
113114 /*
114115 * balloon_page_alloc - allocates a new page for insertion into the balloon
115− * page list.
116+ * page list.
117+ *
118+ * Driver must call this function to properly allocate a new balloon page.
119+ * Driver must call balloon_page_enqueue before definitively removing the page
120+ * from the guest system.
116121 *
117− * Driver must call it to properly allocate a new enlisted balloon page.
118− * Driver must call balloon_page_enqueue before definitively removing it from
119− * the guest system. This function returns the page address for the recently
120− * allocated page or NULL in the case we fail to allocate a new page this turn.
122+ * Return: struct page for the allocated page or NULL on allocation failure.
121123 */
122124 struct page *balloon_page_alloc(void)
123125 {
@@ -128,15 +130,17 @@ struct page *balloon_page_alloc(void) · 4 unmodified lines
128130 EXPORT_SYMBOL_GPL(balloon_page_alloc);
129131
130132 /*
131− * balloon_page_enqueue - allocates a new page and inserts it into the balloon
132− * page list.
133− * @b_dev_info: balloon device descriptor where we will insert a new page to
133+ * balloon_page_enqueue - inserts a new page into the balloon page list.
134+ *
135+ * @b_dev_info: balloon device descriptor where we will insert a new page
134136 * @page: new page to enqueue - allocated using balloon_page_alloc.
135137 *
136− * Driver must call it to properly enqueue a new allocated balloon page
137− * before definitively removing it from the guest system.
138− * This function returns the page address for the recently enqueued page or
139− * NULL in the case we fail to allocate a new page this turn.
138+ * Drivers must call this function to properly enqueue a new allocated balloon
139+ * page before definitively removing the page from the guest system.
140+ *
141+ * Drivers must not call balloon_page_enqueue on pages that have been pushed to
142+ * a list with balloon_page_push before removing them with balloon_page_pop. To
143+ * enqueue a list of pages, use balloon_page_list_enqueue instead.
140144 */
141145 void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
142146 struct page *page)
@@ -151,14 +155,23 @@ EXPORT_SYMBOL_GPL(balloon_page_enqueue); · 8 unmodified lines
151155
152156 /*
153157 * balloon_page_dequeue - removes a page from balloon's page list and returns
154− * the its address to allow the driver release the page.
158+ * its address to allow the driver to release the page.
155159 * @b_dev_info: balloon device decriptor where we will grab a page from.
156160 *
157− * Driver must call it to properly de-allocate a previous enlisted balloon page
158− * before definetively releasing it back to the guest system.
159− * This function returns the page address for the recently dequeued page or
160− * NULL in the case we find balloon's page list temporarily empty due to
161− * compaction isolated pages.
161+ * Driver must call this function to properly dequeue a previously enqueued page
162+ * before definitively releasing it back to the guest system.
163+ *
164+ * Caller must perform its own accounting to ensure that this
165+ * function is called only if some pages are actually enqueued.
166+ *
167+ * Note that this function may fail to dequeue some pages even if there are
168+ * some enqueued pages - since the page list can be temporarily empty due to
169+ * the compaction of isolated pages.
170+ *
171+ * TODO: remove the caller accounting requirements, and allow caller to wait
172+ * until all pages can be dequeued.
173+ *
174+ * Return: struct page for the dequeued page, or NULL if no page was dequeued.
162175 */
163176 struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
164177 {
@@ -171,9 +184,9 @@ struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info) · 6 unmodified lines
171184 if (n_pages != 1) {
172185 /*
173186 * If we are unable to dequeue a balloon page because the page
174− * list is empty and there is no isolated pages, then something
187+ * list is empty and there are no isolated pages, then something
175188 * went out of track and some balloon pages are lost.
176− * BUG() here, otherwise the balloon driver may get stuck into
189+ * BUG() here, otherwise the balloon driver may get stuck in
177190 * an infinite loop while attempting to release all its pages.
178191 */
179192 spin_lock_irqsave(&b_dev_info->pages_lock, flags);
@@ -224,8 +237,8 @@ int balloon_page_migrate(struct address_space *mapping, · 44 unmodified lines
224237
225238 /*
226239 * We can not easily support the no copy case here so ignore it as it
227− * is unlikely to be use with ballon pages. See include/linux/hmm.h for
228− * user of the MIGRATE_SYNC_NO_COPY mode.
240+ * is unlikely to be used with balloon pages. See include/linux/hmm.h
241+ * for a user of the MIGRATE_SYNC_NO_COPY mode.
229242 */
230243 if (mode == MIGRATE_SYNC_NO_COPY)
231244 return -EINVAL;