Skip to content

Commit f2db736

Browse files
vdasahargregkh
authored andcommitted
VMCI: Support upto 64-bit PPNs
Add support in the VMCI driver to handle upto 64-bit PPNs when the VMCI device exposes the capability for 64-bit PPNs. Reviewed-by: Adit Ranadive <aditr@vmware.com> Reviewed-by: Jorgen Hansen <jhansen@vmware.com> Signed-off-by: Vishnu Dasa <vdasa@vmware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bede03a commit f2db736

7 files changed

Lines changed: 77 additions & 49 deletions

File tree

‎drivers/misc/vmw_vmci/vmci_doorbell.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int vmci_dbell_host_context_notify(u32 src_cid, struct vmci_handle handle)
330330
/*
331331
* Register the notification bitmap with the host.
332332
*/
333-
bool vmci_dbell_register_notification_bitmap(u32 bitmap_ppn)
333+
bool vmci_dbell_register_notification_bitmap(u64 bitmap_ppn)
334334
{
335335
int result;
336336
struct vmci_notify_bm_set_msg bitmap_set_msg;
@@ -340,11 +340,14 @@ bool vmci_dbell_register_notification_bitmap(u32 bitmap_ppn)
340340
bitmap_set_msg.hdr.src = VMCI_ANON_SRC_HANDLE;
341341
bitmap_set_msg.hdr.payload_size = sizeof(bitmap_set_msg) -
342342
VMCI_DG_HEADERSIZE;
343-
bitmap_set_msg.bitmap_ppn = bitmap_ppn;
343+
if (vmci_use_ppn64())
344+
bitmap_set_msg.bitmap_ppn64 = bitmap_ppn;
345+
else
346+
bitmap_set_msg.bitmap_ppn32 = (u32) bitmap_ppn;
344347

345348
result = vmci_send_datagram(&bitmap_set_msg.hdr);
346349
if (result != VMCI_SUCCESS) {
347-
pr_devel("Failed to register (PPN=%u) as notification bitmap (error=%d)\n",
350+
pr_devel("Failed to register (PPN=%llu) as notification bitmap (error=%d)\n",
348351
bitmap_ppn, result);
349352
return false;
350353
}

‎drivers/misc/vmw_vmci/vmci_doorbell.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct dbell_cpt_state {
4545
int vmci_dbell_host_context_notify(u32 src_cid, struct vmci_handle handle);
4646
int vmci_dbell_get_priv_flags(struct vmci_handle handle, u32 *priv_flags);
4747

48-
bool vmci_dbell_register_notification_bitmap(u32 bitmap_ppn);
48+
bool vmci_dbell_register_notification_bitmap(u64 bitmap_ppn);
4949
void vmci_dbell_scan_notification_entries(u8 *bitmap);
5050

5151
#endif /* VMCI_DOORBELL_H */

‎drivers/misc/vmw_vmci/vmci_driver.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ void vmci_guest_exit(void);
5454
bool vmci_guest_code_active(void);
5555
u32 vmci_get_vm_context_id(void);
5656

57+
bool vmci_use_ppn64(void);
58+
5759
#endif /* _VMCI_DRIVER_H_ */

‎drivers/misc/vmw_vmci/vmci_guest.c‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ struct vmci_guest_device {
6464
dma_addr_t notification_base;
6565
};
6666

67+
static bool use_ppn64;
68+
69+
bool vmci_use_ppn64(void)
70+
{
71+
return use_ppn64;
72+
}
73+
6774
/* vmci_dev singleton device and supporting data*/
6875
struct pci_dev *vmci_pdev;
6976
static struct vmci_guest_device *vmci_dev_g;
@@ -432,6 +439,7 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
432439
struct vmci_guest_device *vmci_dev;
433440
void __iomem *iobase;
434441
unsigned int capabilities;
442+
unsigned int caps_in_use;
435443
unsigned long cmd;
436444
int vmci_err;
437445
int error;
@@ -496,6 +504,23 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
496504
error = -ENXIO;
497505
goto err_free_data_buffer;
498506
}
507+
caps_in_use = VMCI_CAPS_DATAGRAM;
508+
509+
/*
510+
* Use 64-bit PPNs if the device supports.
511+
*
512+
* There is no check for the return value of dma_set_mask_and_coherent
513+
* since this driver can handle the default mask values if
514+
* dma_set_mask_and_coherent fails.
515+
*/
516+
if (capabilities & VMCI_CAPS_PPN64) {
517+
dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
518+
use_ppn64 = true;
519+
caps_in_use |= VMCI_CAPS_PPN64;
520+
} else {
521+
dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
522+
use_ppn64 = false;
523+
}
499524

500525
/*
501526
* If the hardware supports notifications, we will use that as
@@ -510,14 +535,14 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
510535
"Unable to allocate notification bitmap\n");
511536
} else {
512537
memset(vmci_dev->notification_bitmap, 0, PAGE_SIZE);
513-
capabilities |= VMCI_CAPS_NOTIFICATIONS;
538+
caps_in_use |= VMCI_CAPS_NOTIFICATIONS;
514539
}
515540
}
516541

517-
dev_info(&pdev->dev, "Using capabilities 0x%x\n", capabilities);
542+
dev_info(&pdev->dev, "Using capabilities 0x%x\n", caps_in_use);
518543

519544
/* Let the host know which capabilities we intend to use. */
520-
iowrite32(capabilities, vmci_dev->iobase + VMCI_CAPS_ADDR);
545+
iowrite32(caps_in_use, vmci_dev->iobase + VMCI_CAPS_ADDR);
521546

522547
/* Set up global device so that we can start sending datagrams */
523548
spin_lock_irq(&vmci_dev_spinlock);
@@ -529,13 +554,13 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
529554
* Register notification bitmap with device if that capability is
530555
* used.
531556
*/
532-
if (capabilities & VMCI_CAPS_NOTIFICATIONS) {
557+
if (caps_in_use & VMCI_CAPS_NOTIFICATIONS) {
533558
unsigned long bitmap_ppn =
534559
vmci_dev->notification_base >> PAGE_SHIFT;
535560
if (!vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
536561
dev_warn(&pdev->dev,
537-
"VMCI device unable to register notification bitmap with PPN 0x%x\n",
538-
(u32) bitmap_ppn);
562+
"VMCI device unable to register notification bitmap with PPN 0x%lx\n",
563+
bitmap_ppn);
539564
error = -ENXIO;
540565
goto err_remove_vmci_dev_g;
541566
}
@@ -611,7 +636,7 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
611636

612637
/* Enable specific interrupt bits. */
613638
cmd = VMCI_IMR_DATAGRAM;
614-
if (capabilities & VMCI_CAPS_NOTIFICATIONS)
639+
if (caps_in_use & VMCI_CAPS_NOTIFICATIONS)
615640
cmd |= VMCI_IMR_NOTIFICATION;
616641
iowrite32(cmd, vmci_dev->iobase + VMCI_IMR_ADDR);
617642

‎drivers/misc/vmw_vmci/vmci_queue_pair.c‎

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ static int qp_alloc_ppn_set(void *prod_q,
435435
void *cons_q,
436436
u64 num_consume_pages, struct ppn_set *ppn_set)
437437
{
438-
u32 *produce_ppns;
439-
u32 *consume_ppns;
438+
u64 *produce_ppns;
439+
u64 *consume_ppns;
440440
struct vmci_queue *produce_q = prod_q;
441441
struct vmci_queue *consume_q = cons_q;
442442
u64 i;
@@ -462,43 +462,20 @@ static int qp_alloc_ppn_set(void *prod_q,
462462
return VMCI_ERROR_NO_MEM;
463463
}
464464

465-
for (i = 0; i < num_produce_pages; i++) {
466-
unsigned long pfn;
467-
465+
for (i = 0; i < num_produce_pages; i++)
468466
produce_ppns[i] =
469467
produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
470-
pfn = produce_ppns[i];
471-
472-
/* Fail allocation if PFN isn't supported by hypervisor. */
473-
if (sizeof(pfn) > sizeof(*produce_ppns)
474-
&& pfn != produce_ppns[i])
475-
goto ppn_error;
476-
}
477-
478-
for (i = 0; i < num_consume_pages; i++) {
479-
unsigned long pfn;
480468

469+
for (i = 0; i < num_consume_pages; i++)
481470
consume_ppns[i] =
482471
consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
483-
pfn = consume_ppns[i];
484-
485-
/* Fail allocation if PFN isn't supported by hypervisor. */
486-
if (sizeof(pfn) > sizeof(*consume_ppns)
487-
&& pfn != consume_ppns[i])
488-
goto ppn_error;
489-
}
490472

491473
ppn_set->num_produce_pages = num_produce_pages;
492474
ppn_set->num_consume_pages = num_consume_pages;
493475
ppn_set->produce_ppns = produce_ppns;
494476
ppn_set->consume_ppns = consume_ppns;
495477
ppn_set->initialized = true;
496478
return VMCI_SUCCESS;
497-
498-
ppn_error:
499-
kfree(produce_ppns);
500-
kfree(consume_ppns);
501-
return VMCI_ERROR_INVALID_ARGS;
502479
}
503480

504481
/*
@@ -520,12 +497,28 @@ static void qp_free_ppn_set(struct ppn_set *ppn_set)
520497
*/
521498
static int qp_populate_ppn_set(u8 *call_buf, const struct ppn_set *ppn_set)
522499
{
523-
memcpy(call_buf, ppn_set->produce_ppns,
524-
ppn_set->num_produce_pages * sizeof(*ppn_set->produce_ppns));
525-
memcpy(call_buf +
526-
ppn_set->num_produce_pages * sizeof(*ppn_set->produce_ppns),
527-
ppn_set->consume_ppns,
528-
ppn_set->num_consume_pages * sizeof(*ppn_set->consume_ppns));
500+
if (vmci_use_ppn64()) {
501+
memcpy(call_buf, ppn_set->produce_ppns,
502+
ppn_set->num_produce_pages *
503+
sizeof(*ppn_set->produce_ppns));
504+
memcpy(call_buf +
505+
ppn_set->num_produce_pages *
506+
sizeof(*ppn_set->produce_ppns),
507+
ppn_set->consume_ppns,
508+
ppn_set->num_consume_pages *
509+
sizeof(*ppn_set->consume_ppns));
510+
} else {
511+
int i;
512+
u32 *ppns = (u32 *) call_buf;
513+
514+
for (i = 0; i < ppn_set->num_produce_pages; i++)
515+
ppns[i] = (u32) ppn_set->produce_ppns[i];
516+
517+
ppns = &ppns[ppn_set->num_produce_pages];
518+
519+
for (i = 0; i < ppn_set->num_consume_pages; i++)
520+
ppns[i] = (u32) ppn_set->consume_ppns[i];
521+
}
529522

530523
return VMCI_SUCCESS;
531524
}
@@ -951,13 +944,15 @@ static int qp_alloc_hypercall(const struct qp_guest_endpoint *entry)
951944
{
952945
struct vmci_qp_alloc_msg *alloc_msg;
953946
size_t msg_size;
947+
size_t ppn_size;
954948
int result;
955949

956950
if (!entry || entry->num_ppns <= 2)
957951
return VMCI_ERROR_INVALID_ARGS;
958952

953+
ppn_size = vmci_use_ppn64() ? sizeof(u64) : sizeof(u32);
959954
msg_size = sizeof(*alloc_msg) +
960-
(size_t) entry->num_ppns * sizeof(u32);
955+
(size_t) entry->num_ppns * ppn_size;
961956
alloc_msg = kmalloc(msg_size, GFP_KERNEL);
962957
if (!alloc_msg)
963958
return VMCI_ERROR_NO_MEM;

‎drivers/misc/vmw_vmci/vmci_queue_pair.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ typedef int (*vmci_event_release_cb) (void *client_data);
2828
struct ppn_set {
2929
u64 num_produce_pages;
3030
u64 num_consume_pages;
31-
u32 *produce_ppns;
32-
u32 *consume_ppns;
31+
u64 *produce_ppns;
32+
u64 *consume_ppns;
3333
bool initialized;
3434
};
3535

‎include/linux/vmw_vmci_defs.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define VMCI_CAPS_GUESTCALL 0x2
4646
#define VMCI_CAPS_DATAGRAM 0x4
4747
#define VMCI_CAPS_NOTIFICATIONS 0x8
48+
#define VMCI_CAPS_PPN64 0x10
4849

4950
/* Interrupt Cause register bits. */
5051
#define VMCI_ICR_DATAGRAM 0x1
@@ -569,8 +570,10 @@ struct vmci_resource_query_msg {
569570
*/
570571
struct vmci_notify_bm_set_msg {
571572
struct vmci_datagram hdr;
572-
u32 bitmap_ppn;
573-
u32 _pad;
573+
union {
574+
u32 bitmap_ppn32;
575+
u64 bitmap_ppn64;
576+
};
574577
};
575578

576579
/*

0 commit comments

Comments
 (0)