Commit 173c07278763850bfee57eec442dce38855d6f13

Authored by Ashutosh Dixit
Committed by Greg Kroah-Hartman
1 parent 1e31aa9270

misc: mic: Fix endianness issues.

Endianness issues are now consistent as per the documentation in
host/mic_virtio.h. Sparse warnings related to endianness are also fixed.
Note that the MIC driver implementation assumes that the host can be
both BE or LE whereas the card is always LE.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com>
Reviewed-by: Nikhil Rao <nikhil.rao@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 6 changed files with 28 additions and 28 deletions Side-by-side Diff

Documentation/mic/mpssd/mpssd.c
... ... @@ -445,8 +445,8 @@
445 445 __func__, mic->name, vr0->va, vr0->info, vr_size,
446 446 vring_size(MIC_VRING_ENTRIES, MIC_VIRTIO_RING_ALIGN));
447 447 mpsslog("magic 0x%x expected 0x%x\n",
448   - vr0->info->magic, MIC_MAGIC + type);
449   - assert(vr0->info->magic == MIC_MAGIC + type);
  448 + le32toh(vr0->info->magic), MIC_MAGIC + type);
  449 + assert(le32toh(vr0->info->magic) == MIC_MAGIC + type);
450 450 if (vr1) {
451 451 vr1->va = (struct mic_vring *)
452 452 &va[MIC_DEVICE_PAGE_END + vr_size];
... ... @@ -458,8 +458,8 @@
458 458 __func__, mic->name, vr1->va, vr1->info, vr_size,
459 459 vring_size(MIC_VRING_ENTRIES, MIC_VIRTIO_RING_ALIGN));
460 460 mpsslog("magic 0x%x expected 0x%x\n",
461   - vr1->info->magic, MIC_MAGIC + type + 1);
462   - assert(vr1->info->magic == MIC_MAGIC + type + 1);
  461 + le32toh(vr1->info->magic), MIC_MAGIC + type + 1);
  462 + assert(le32toh(vr1->info->magic) == MIC_MAGIC + type + 1);
463 463 }
464 464 done:
465 465 return va;
drivers/misc/mic/card/mic_virtio.c
... ... @@ -248,17 +248,16 @@
248 248 /* First assign the vring's allocated in host memory */
249 249 vqconfig = mic_vq_config(mvdev->desc) + index;
250 250 memcpy_fromio(&config, vqconfig, sizeof(config));
251   - _vr_size = vring_size(config.num, MIC_VIRTIO_RING_ALIGN);
  251 + _vr_size = vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN);
252 252 vr_size = PAGE_ALIGN(_vr_size + sizeof(struct _mic_vring_info));
253   - va = mic_card_map(mvdev->mdev, config.address, vr_size);
  253 + va = mic_card_map(mvdev->mdev, le64_to_cpu(config.address), vr_size);
254 254 if (!va)
255 255 return ERR_PTR(-ENOMEM);
256 256 mvdev->vr[index] = va;
257 257 memset_io(va, 0x0, _vr_size);
258   - vq = vring_new_virtqueue(index,
259   - config.num, MIC_VIRTIO_RING_ALIGN, vdev,
260   - false,
261   - va, mic_notify, callback, name);
  258 + vq = vring_new_virtqueue(index, le16_to_cpu(config.num),
  259 + MIC_VIRTIO_RING_ALIGN, vdev, false, va,
  260 + mic_notify, callback, name);
262 261 if (!vq) {
263 262 err = -ENOMEM;
264 263 goto unmap;
... ... @@ -273,7 +272,8 @@
273 272  
274 273 /* Allocate and reassign used ring now */
275 274 mvdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 +
276   - sizeof(struct vring_used_elem) * config.num);
  275 + sizeof(struct vring_used_elem) *
  276 + le16_to_cpu(config.num));
277 277 used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
278 278 get_order(mvdev->used_size[index]));
279 279 if (!used) {
drivers/misc/mic/host/mic_boot.c
... ... @@ -62,7 +62,7 @@
62 62 {
63 63 struct mic_bootparam *bootparam = mdev->dp;
64 64  
65   - bootparam->magic = MIC_MAGIC;
  65 + bootparam->magic = cpu_to_le32(MIC_MAGIC);
66 66 bootparam->c2h_shutdown_db = mdev->shutdown_db;
67 67 bootparam->h2c_shutdown_db = -1;
68 68 bootparam->h2c_config_db = -1;
drivers/misc/mic/host/mic_virtio.c
... ... @@ -293,8 +293,8 @@
293 293 continue;
294 294 }
295 295 mvdev->mvr[i].vrh.vring.used =
296   - mvdev->mdev->aper.va +
297   - le64_to_cpu(vqconfig[i].used_address);
  296 + mvdev->mdev->aper.va
  297 + + le64_to_cpu(vqconfig[i].used_address);
298 298 }
299 299  
300 300 mvdev->dc->used_address_updated = 0;
... ... @@ -525,6 +525,7 @@
525 525 char irqname[10];
526 526 struct mic_bootparam *bootparam = mdev->dp;
527 527 u16 num;
  528 + dma_addr_t vr_addr;
528 529  
529 530 mutex_lock(&mdev->mic_mutex);
530 531  
531 532  
... ... @@ -559,17 +560,16 @@
559 560 }
560 561 vr->len = vr_size;
561 562 vr->info = vr->va + vring_size(num, MIC_VIRTIO_RING_ALIGN);
562   - vr->info->magic = MIC_MAGIC + mvdev->virtio_id + i;
563   - vqconfig[i].address = mic_map_single(mdev,
564   - vr->va, vr_size);
565   - if (mic_map_error(vqconfig[i].address)) {
  563 + vr->info->magic = cpu_to_le32(MIC_MAGIC + mvdev->virtio_id + i);
  564 + vr_addr = mic_map_single(mdev, vr->va, vr_size);
  565 + if (mic_map_error(vr_addr)) {
566 566 free_pages((unsigned long)vr->va, get_order(vr_size));
567 567 ret = -ENOMEM;
568 568 dev_err(mic_dev(mvdev), "%s %d err %d\n",
569 569 __func__, __LINE__, ret);
570 570 goto err;
571 571 }
572   - vqconfig[i].address = cpu_to_le64(vqconfig[i].address);
  572 + vqconfig[i].address = cpu_to_le64(vr_addr);
573 573  
574 574 vring_init(&vr->vr, num, vr->va, MIC_VIRTIO_RING_ALIGN);
575 575 ret = vringh_init_kern(&mvr->vrh,
drivers/misc/mic/host/mic_x100.c
... ... @@ -397,8 +397,8 @@
397 397 * so copy over the ramdisk @ 128M.
398 398 */
399 399 memcpy_toio(mdev->aper.va + (mdev->bootaddr << 1), fw->data, fw->size);
400   - iowrite32(cpu_to_le32(mdev->bootaddr << 1), &bp->hdr.ramdisk_image);
401   - iowrite32(cpu_to_le32(fw->size), &bp->hdr.ramdisk_size);
  400 + iowrite32(mdev->bootaddr << 1, &bp->hdr.ramdisk_image);
  401 + iowrite32(fw->size, &bp->hdr.ramdisk_size);
402 402 release_firmware(fw);
403 403 error:
404 404 return rc;
include/uapi/linux/mic_common.h
... ... @@ -43,7 +43,7 @@
43 43 __u8 feature_len;
44 44 __u8 config_len;
45 45 __u8 status;
46   - __u64 config[0];
  46 + __le64 config[0];
47 47 } __attribute__ ((aligned(8)));
48 48  
49 49 /**
... ... @@ -61,7 +61,7 @@
61 61 * @h2c_vdev_db: The doorbell number to be used by host. Set by guest.
62 62 */
63 63 struct mic_device_ctrl {
64   - __u64 vdev;
  64 + __le64 vdev;
65 65 __u8 config_change;
66 66 __u8 vdev_reset;
67 67 __u8 guest_ack;
... ... @@ -82,7 +82,7 @@
82 82 * @shutdown_card: Set to 1 by the host when a card shutdown is initiated
83 83 */
84 84 struct mic_bootparam {
85   - __u32 magic;
  85 + __le32 magic;
86 86 __s8 c2h_shutdown_db;
87 87 __s8 h2c_shutdown_db;
88 88 __s8 h2c_config_db;
... ... @@ -111,9 +111,9 @@
111 111 * @num: The number of entries in the virtio_ring
112 112 */
113 113 struct mic_vqconfig {
114   - __u64 address;
115   - __u64 used_address;
116   - __u16 num;
  114 + __le64 address;
  115 + __le64 used_address;
  116 + __le16 num;
117 117 } __attribute__ ((aligned(8)));
118 118  
119 119 /*
... ... @@ -149,7 +149,7 @@
149 149 */
150 150 struct _mic_vring_info {
151 151 __u16 avail_idx;
152   - int magic;
  152 + __le32 magic;
153 153 };
154 154  
155 155 /**