/* Incoming XPMEM command from enclave - enqueue and wake up kthread */ static void xpmem_ctrl_handler(u8 * data, u32 data_len, void * priv_data) { struct pisces_xpmem_state * state = (struct pisces_xpmem_state *)priv_data; struct xpmem_cmd_ringbuf * buf = &(state->xpmem_buf); if (data_len != sizeof(struct xpmem_cmd_ex)) { printk(KERN_ERR "ERROR: DROPPING XPMEM CMD: MALFORMED CMD\n"); return; } /* Find open entry */ if (push_active_entry(buf, (struct xpmem_cmd_ex *)data) != 0) { printk(KERN_ERR "ERROR: DROPPING XPMEM CMD: NO ENTRIES AVAILABLE\n"); return; } atomic_inc(&(buf->active_entries)); mb(); waitq_wakeup(&(state->waitq)); /* Xbuf now complete */ pisces_xbuf_complete(state->xbuf_desc, NULL, 0); }
// This has to be done in a single operation static ssize_t cmd_write(struct file * filp, const char __user * ubuf, size_t size, loff_t * off) { u8 * resp = NULL; cmd_data = NULL; cmd_len = 0; resp = kmem_alloc(size); if (!resp) { printk(KERN_ERR "Unable to allocate buffer for command response\n"); return -ENOMEM; } // write response to buffer if (copy_from_user(resp, ubuf, size)) { return -EINVAL; } pisces_xbuf_complete(xbuf_desc, resp, size); kmem_free(resp); return size; }