Skip to content

Commit 45ba8d5

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: "Several fixes, most notably fix for virtio on swiotlb systems" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: silence an unused-variable warning virtio: hint if callbacks surprisingly might sleep virtio-ccw: wire up ->bus_name callback s390/virtio: handle find on invalid queue gracefully virtio-ccw: diag 500 may return a negative cookie virtio_balloon: remove the unnecessary 0-initialization virtio-balloon: improve update_balloon_size_func virtio-blk: Consider virtio_max_dma_size() for maximum segment size virtio: Introduce virtio_max_dma_size() dma: Introduce dma_max_mapping_size() swiotlb: Add is_swiotlb_active() function swiotlb: Introduce swiotlb_max_mapping_size()
2 parents bb97be2 + cfdbb4e commit 45ba8d5

File tree

15 files changed

+118
-9
lines changed

15 files changed

+118
-9
lines changed

Documentation/DMA-API.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ Requesting the required mask does not alter the current mask. If you
195195
wish to take advantage of it, you should issue a dma_set_mask()
196196
call to set the mask to the value returned.
197197

198+
::
199+
200+
size_t
201+
dma_direct_max_mapping_size(struct device *dev);
202+
203+
Returns the maximum size of a mapping for the device. The size parameter
204+
of the mapping functions like dma_map_single(), dma_map_page() and
205+
others should not be larger than the returned value.
198206

199207
Part Id - Streaming DMA mappings
200208
--------------------------------

Documentation/virtual/kvm/s390-diag.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ Subcode 3 - virtio-ccw notification
6868
identifier, it is ignored.
6969

7070
After completion of the DIAGNOSE call, general register 2 may contain
71-
a 64bit identifier (in the kvm_io_bus cookie case).
71+
a 64bit identifier (in the kvm_io_bus cookie case), or a negative
72+
error value, if an internal error occurred.
7273

7374
See also the virtio standard for a discussion of this hypercall.
7475

drivers/block/virtio_blk.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static int virtblk_probe(struct virtio_device *vdev)
723723
struct request_queue *q;
724724
int err, index;
725725

726-
u32 v, blk_size, sg_elems, opt_io_size;
726+
u32 v, blk_size, max_size, sg_elems, opt_io_size;
727727
u16 min_io_size;
728728
u8 physical_block_exp, alignment_offset;
729729

@@ -826,14 +826,16 @@ static int virtblk_probe(struct virtio_device *vdev)
826826
/* No real sector limit. */
827827
blk_queue_max_hw_sectors(q, -1U);
828828

829+
max_size = virtio_max_dma_size(vdev);
830+
829831
/* Host can optionally specify maximum segment size and number of
830832
* segments. */
831833
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SIZE_MAX,
832834
struct virtio_blk_config, size_max, &v);
833835
if (!err)
834-
blk_queue_max_segment_size(q, v);
835-
else
836-
blk_queue_max_segment_size(q, -1U);
836+
max_size = min(max_size, v);
837+
838+
blk_queue_max_segment_size(q, max_size);
837839

838840
/* Host can optionally specify the block size of the device */
839841
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,

drivers/s390/virtio/virtio_ccw.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ static void virtio_ccw_drop_indicators(struct virtio_ccw_device *vcdev)
272272
{
273273
struct virtio_ccw_vq_info *info;
274274

275+
if (!vcdev->airq_info)
276+
return;
275277
list_for_each_entry(info, &vcdev->virtqueues, node)
276278
drop_airq_indicator(info->vq, vcdev->airq_info);
277279
}
@@ -413,7 +415,7 @@ static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev,
413415
ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF);
414416
if (ret)
415417
return ret;
416-
return vcdev->config_block->num;
418+
return vcdev->config_block->num ?: -ENOENT;
417419
}
418420

419421
static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
@@ -973,6 +975,13 @@ static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
973975
kfree(ccw);
974976
}
975977

978+
static const char *virtio_ccw_bus_name(struct virtio_device *vdev)
979+
{
980+
struct virtio_ccw_device *vcdev = to_vc_device(vdev);
981+
982+
return dev_name(&vcdev->cdev->dev);
983+
}
984+
976985
static const struct virtio_config_ops virtio_ccw_config_ops = {
977986
.get_features = virtio_ccw_get_features,
978987
.finalize_features = virtio_ccw_finalize_features,
@@ -983,6 +992,7 @@ static const struct virtio_config_ops virtio_ccw_config_ops = {
983992
.reset = virtio_ccw_reset,
984993
.find_vqs = virtio_ccw_find_vqs,
985994
.del_vqs = virtio_ccw_del_vqs,
995+
.bus_name = virtio_ccw_bus_name,
986996
};
987997

988998

drivers/vhost/vhost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static bool vq_access_ok(struct vhost_virtqueue *vq, unsigned int num,
11881188
struct vring_used __user *used)
11891189

11901190
{
1191-
size_t s = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
1191+
size_t s __maybe_unused = vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX) ? 2 : 0;
11921192

11931193
return access_ok(desc, num * sizeof *desc) &&
11941194
access_ok(avail,

drivers/virtio/virtio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ EXPORT_SYMBOL_GPL(virtio_config_enable);
161161

162162
void virtio_add_status(struct virtio_device *dev, unsigned int status)
163163
{
164+
might_sleep();
164165
dev->config->set_status(dev, dev->config->get_status(dev) | status);
165166
}
166167
EXPORT_SYMBOL_GPL(virtio_add_status);
@@ -170,6 +171,7 @@ int virtio_finalize_features(struct virtio_device *dev)
170171
int ret = dev->config->finalize_features(dev);
171172
unsigned status;
172173

174+
might_sleep();
173175
if (ret)
174176
return ret;
175177

drivers/virtio/virtio_balloon.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,12 @@ static void update_balloon_size_func(struct work_struct *work)
457457
update_balloon_size_work);
458458
diff = towards_target(vb);
459459

460+
if (!diff)
461+
return;
462+
460463
if (diff > 0)
461464
diff -= fill_balloon(vb, diff);
462-
else if (diff < 0)
465+
else
463466
diff += leak_balloon(vb, -diff);
464467
update_balloon_size(vb);
465468

@@ -922,7 +925,6 @@ static int virtballoon_probe(struct virtio_device *vdev)
922925
VIRTIO_BALLOON_CMD_ID_STOP);
923926
vb->cmd_id_stop = cpu_to_virtio32(vb->vdev,
924927
VIRTIO_BALLOON_CMD_ID_STOP);
925-
vb->num_free_page_blocks = 0;
926928
spin_lock_init(&vb->free_page_list_lock);
927929
INIT_LIST_HEAD(&vb->free_page_list);
928930
if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) {

drivers/virtio/virtio_ring.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ static bool vring_use_dma_api(struct virtio_device *vdev)
271271
return false;
272272
}
273273

274+
size_t virtio_max_dma_size(struct virtio_device *vdev)
275+
{
276+
size_t max_segment_size = SIZE_MAX;
277+
278+
if (vring_use_dma_api(vdev))
279+
max_segment_size = dma_max_mapping_size(&vdev->dev);
280+
281+
return max_segment_size;
282+
}
283+
EXPORT_SYMBOL_GPL(virtio_max_dma_size);
284+
274285
static void *vring_alloc_queue(struct virtio_device *vdev, size_t size,
275286
dma_addr_t *dma_handle, gfp_t flag)
276287
{

include/linux/dma-mapping.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct dma_map_ops {
130130
enum dma_data_direction direction);
131131
int (*dma_supported)(struct device *dev, u64 mask);
132132
u64 (*get_required_mask)(struct device *dev);
133+
size_t (*max_mapping_size)(struct device *dev);
133134
};
134135

135136
#define DMA_MAPPING_ERROR (~(dma_addr_t)0)
@@ -259,6 +260,8 @@ static inline void dma_direct_sync_sg_for_cpu(struct device *dev,
259260
}
260261
#endif
261262

263+
size_t dma_direct_max_mapping_size(struct device *dev);
264+
262265
#ifdef CONFIG_HAS_DMA
263266
#include <asm/dma-mapping.h>
264267

@@ -463,6 +466,7 @@ int dma_supported(struct device *dev, u64 mask);
463466
int dma_set_mask(struct device *dev, u64 mask);
464467
int dma_set_coherent_mask(struct device *dev, u64 mask);
465468
u64 dma_get_required_mask(struct device *dev);
469+
size_t dma_max_mapping_size(struct device *dev);
466470
#else /* CONFIG_HAS_DMA */
467471
static inline dma_addr_t dma_map_page_attrs(struct device *dev,
468472
struct page *page, size_t offset, size_t size,
@@ -564,6 +568,10 @@ static inline u64 dma_get_required_mask(struct device *dev)
564568
{
565569
return 0;
566570
}
571+
static inline size_t dma_max_mapping_size(struct device *dev)
572+
{
573+
return 0;
574+
}
567575
#endif /* CONFIG_HAS_DMA */
568576

569577
static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,

include/linux/swiotlb.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
7373
size_t size, enum dma_data_direction dir, unsigned long attrs);
7474
void __init swiotlb_exit(void);
7575
unsigned int swiotlb_max_segment(void);
76+
size_t swiotlb_max_mapping_size(struct device *dev);
77+
bool is_swiotlb_active(void);
7678
#else
7779
#define swiotlb_force SWIOTLB_NO_FORCE
7880
static inline bool is_swiotlb_buffer(phys_addr_t paddr)
@@ -92,6 +94,15 @@ static inline unsigned int swiotlb_max_segment(void)
9294
{
9395
return 0;
9496
}
97+
static inline size_t swiotlb_max_mapping_size(struct device *dev)
98+
{
99+
return SIZE_MAX;
100+
}
101+
102+
static inline bool is_swiotlb_active(void)
103+
{
104+
return false;
105+
}
95106
#endif /* CONFIG_SWIOTLB */
96107

97108
extern void swiotlb_print_info(void);

include/linux/virtio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ int virtio_device_freeze(struct virtio_device *dev);
157157
int virtio_device_restore(struct virtio_device *dev);
158158
#endif
159159

160+
size_t virtio_max_dma_size(struct virtio_device *vdev);
161+
160162
#define virtio_device_for_each_vq(vdev, vq) \
161163
list_for_each_entry(vq, &vdev->vqs, list)
162164

include/linux/virtio_config.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
290290
/* Config space accessors. */
291291
#define virtio_cread(vdev, structname, member, ptr) \
292292
do { \
293+
might_sleep(); \
293294
/* Must match the member's type, and be integer */ \
294295
if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
295296
(*ptr) = 1; \
@@ -319,6 +320,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
319320
/* Config space accessors. */
320321
#define virtio_cwrite(vdev, structname, member, ptr) \
321322
do { \
323+
might_sleep(); \
322324
/* Must match the member's type, and be integer */ \
323325
if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
324326
BUG_ON((*ptr) == 1); \
@@ -358,6 +360,7 @@ static inline void __virtio_cread_many(struct virtio_device *vdev,
358360
vdev->config->generation(vdev) : 0;
359361
int i;
360362

363+
might_sleep();
361364
do {
362365
old = gen;
363366

@@ -380,27 +383,33 @@ static inline void virtio_cread_bytes(struct virtio_device *vdev,
380383
static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
381384
{
382385
u8 ret;
386+
387+
might_sleep();
383388
vdev->config->get(vdev, offset, &ret, sizeof(ret));
384389
return ret;
385390
}
386391

387392
static inline void virtio_cwrite8(struct virtio_device *vdev,
388393
unsigned int offset, u8 val)
389394
{
395+
might_sleep();
390396
vdev->config->set(vdev, offset, &val, sizeof(val));
391397
}
392398

393399
static inline u16 virtio_cread16(struct virtio_device *vdev,
394400
unsigned int offset)
395401
{
396402
u16 ret;
403+
404+
might_sleep();
397405
vdev->config->get(vdev, offset, &ret, sizeof(ret));
398406
return virtio16_to_cpu(vdev, (__force __virtio16)ret);
399407
}
400408

401409
static inline void virtio_cwrite16(struct virtio_device *vdev,
402410
unsigned int offset, u16 val)
403411
{
412+
might_sleep();
404413
val = (__force u16)cpu_to_virtio16(vdev, val);
405414
vdev->config->set(vdev, offset, &val, sizeof(val));
406415
}
@@ -409,13 +418,16 @@ static inline u32 virtio_cread32(struct virtio_device *vdev,
409418
unsigned int offset)
410419
{
411420
u32 ret;
421+
422+
might_sleep();
412423
vdev->config->get(vdev, offset, &ret, sizeof(ret));
413424
return virtio32_to_cpu(vdev, (__force __virtio32)ret);
414425
}
415426

416427
static inline void virtio_cwrite32(struct virtio_device *vdev,
417428
unsigned int offset, u32 val)
418429
{
430+
might_sleep();
419431
val = (__force u32)cpu_to_virtio32(vdev, val);
420432
vdev->config->set(vdev, offset, &val, sizeof(val));
421433
}
@@ -431,6 +443,7 @@ static inline u64 virtio_cread64(struct virtio_device *vdev,
431443
static inline void virtio_cwrite64(struct virtio_device *vdev,
432444
unsigned int offset, u64 val)
433445
{
446+
might_sleep();
434447
val = (__force u64)cpu_to_virtio64(vdev, val);
435448
vdev->config->set(vdev, offset, &val, sizeof(val));
436449
}

kernel/dma/direct.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,14 @@ int dma_direct_supported(struct device *dev, u64 mask)
393393
*/
394394
return mask >= __phys_to_dma(dev, min_mask);
395395
}
396+
397+
size_t dma_direct_max_mapping_size(struct device *dev)
398+
{
399+
size_t size = SIZE_MAX;
400+
401+
/* If SWIOTLB is active, use its maximum mapping size */
402+
if (is_swiotlb_active())
403+
size = swiotlb_max_mapping_size(dev);
404+
405+
return size;
406+
}

kernel/dma/mapping.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,17 @@ void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
360360
ops->cache_sync(dev, vaddr, size, dir);
361361
}
362362
EXPORT_SYMBOL(dma_cache_sync);
363+
364+
size_t dma_max_mapping_size(struct device *dev)
365+
{
366+
const struct dma_map_ops *ops = get_dma_ops(dev);
367+
size_t size = SIZE_MAX;
368+
369+
if (dma_is_direct(ops))
370+
size = dma_direct_max_mapping_size(dev);
371+
else if (ops && ops->max_mapping_size)
372+
size = ops->max_mapping_size(dev);
373+
374+
return size;
375+
}
376+
EXPORT_SYMBOL_GPL(dma_max_mapping_size);

kernel/dma/swiotlb.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,20 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
666666
return true;
667667
}
668668

669+
size_t swiotlb_max_mapping_size(struct device *dev)
670+
{
671+
return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
672+
}
673+
674+
bool is_swiotlb_active(void)
675+
{
676+
/*
677+
* When SWIOTLB is initialized, even if io_tlb_start points to physical
678+
* address zero, io_tlb_end surely doesn't.
679+
*/
680+
return io_tlb_end != 0;
681+
}
682+
669683
#ifdef CONFIG_DEBUG_FS
670684

671685
static int __init swiotlb_create_debugfs(void)

0 commit comments

Comments
 (0)