From patchwork Thu Jun 22 19:14:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9805189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46C84600C5 for ; Thu, 22 Jun 2017 19:17:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A895028138 for ; Thu, 22 Jun 2017 19:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CC292866E; Thu, 22 Jun 2017 19:17:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 296432864C for ; Thu, 22 Jun 2017 19:17:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dO7ZN-0000LX-Am; Thu, 22 Jun 2017 19:15:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dO7ZM-000086-0v for xen-devel@lists.xen.org; Thu, 22 Jun 2017 19:15:08 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 1A/88-03620-B371C495; Thu, 22 Jun 2017 19:15:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVybKJssq61uE+ kwbKHQhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bTLz/YCq5JVxw784+5gfGNeBcjF4eQQBuT xKWJcxm7GDk5WAQcJA69aWbqYuTgYBSIkXjwwxokzCgQJjH58hJWEJtNwFDi75NNbCC2iIC0x LXPlxlB5jALTGaUeP3uFzNIr7CAqcSK+yUQI1UlJp4/xwRi8wq4S+yYvRvMlhCQkzh5bDLYTE 6geFPzOTaIe9oZJXo/v2SfwMi7gJFhFaNGcWpRWWqRrpGJXlJRZnpGSW5iZo6uoYGZXm5qcXF iempOYlKxXnJ+7iZGYDgwAMEOxn0fIw8xSnIwKYnybi72jhTiS8pPqcxILM6ILyrNSS0+xCjD waEkwRsn5hMpJFiUmp5akZaZAwxMmLQEB4+SCO8XPqA0b3FBYm5xZjpE6hSjLseG1eu/MAmx5 OXnpUqJ8+aDzBAAKcoozYMbAYuSS4yyUsK8jEBHCfEUpBblZpagyr9iFOdgVBLmNQKZwpOZVw K36RXQEUxAR7w44gFyREkiQkqqgZH96VKD1fEzv7v0dRhmV/wvZZ9wLr6dtdtHSKxr+nJ/d/8 JE3Vbth18/8j1r8z16HtOPKnrPxdMKdqidL7oTqrIgpn+G9lc2HfvWHrpQemh5z8fn1jPPOOH nOSN5LbqpMA7Gw8vyvxzlKFiX8HxhMcLzu1TDJ+xcmp0WYjnwx87nFac3jbxYBqbEktxRqKhF nNRcSIA3eJcWY0CAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-13.tower-27.messagelabs.com!1498158906!99522661!1 X-Originating-IP: [198.145.29.99] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41875 invoked from network); 22 Jun 2017 19:15:07 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-13.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Jun 2017 19:15:07 -0000 Received: from localhost.localdomain (unknown [99.165.194.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B4EE22B6E; Thu, 22 Jun 2017 19:14:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B4EE22B6E From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Thu, 22 Jun 2017 12:14:25 -0700 Message-Id: <1498158867-25426-16-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498158867-25426-1-git-send-email-sstabellini@kernel.org> References: <1498158867-25426-1-git-send-email-sstabellini@kernel.org> Cc: jgross@suse.com, Stefano Stabellini , boris.ostrovsky@oracle.com, sstabellini@kernel.org, linux-kernel@vger.kernel.org Subject: [Xen-devel] [PATCH v5 16/18] xen/pvcalls: implement read X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When an active socket has data available, increment the io and read counters, and schedule the ioworker. Implement the read function by reading from the socket, writing the data to the data ring. Set in_error on error. Signed-off-by: Stefano Stabellini CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- drivers/xen/pvcalls-back.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index ab7882a..ccceabd 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -100,6 +100,81 @@ static int pvcalls_back_release_active(struct xenbus_device *dev, static void pvcalls_conn_back_read(void *opaque) { + struct sock_mapping *map = (struct sock_mapping *)opaque; + struct msghdr msg; + struct kvec vec[2]; + RING_IDX cons, prod, size, wanted, array_size, masked_prod, masked_cons; + int32_t error; + struct pvcalls_data_intf *intf = map->ring; + struct pvcalls_data *data = &map->data; + unsigned long flags; + int ret; + + array_size = XEN_FLEX_RING_SIZE(map->ring_order); + cons = intf->in_cons; + prod = intf->in_prod; + error = intf->in_error; + /* read the indexes first, then deal with the data */ + virt_mb(); + + if (error) + return; + + size = pvcalls_queued(prod, cons, array_size); + if (size >= array_size) + return; + spin_lock_irqsave(&map->sock->sk->sk_receive_queue.lock, flags); + if (skb_queue_empty(&map->sock->sk->sk_receive_queue)) { + atomic_set(&map->read, 0); + spin_unlock_irqrestore(&map->sock->sk->sk_receive_queue.lock, + flags); + return; + } + spin_unlock_irqrestore(&map->sock->sk->sk_receive_queue.lock, flags); + wanted = array_size - size; + masked_prod = pvcalls_mask(prod, array_size); + masked_cons = pvcalls_mask(cons, array_size); + + memset(&msg, 0, sizeof(msg)); + msg.msg_iter.type = ITER_KVEC|WRITE; + msg.msg_iter.count = wanted; + if (masked_prod < masked_cons) { + vec[0].iov_base = data->in + masked_prod; + vec[0].iov_len = wanted; + msg.msg_iter.kvec = vec; + msg.msg_iter.nr_segs = 1; + } else { + vec[0].iov_base = data->in + masked_prod; + vec[0].iov_len = array_size - masked_prod; + vec[1].iov_base = data->in; + vec[1].iov_len = wanted - vec[0].iov_len; + msg.msg_iter.kvec = vec; + msg.msg_iter.nr_segs = 2; + } + + atomic_set(&map->read, 0); + ret = inet_recvmsg(map->sock, &msg, wanted, MSG_DONTWAIT); + WARN_ON(ret > wanted); + if (ret == -EAGAIN) /* shouldn't happen */ + return; + if (!ret) + ret = -ENOTCONN; + spin_lock_irqsave(&map->sock->sk->sk_receive_queue.lock, flags); + if (ret > 0 && !skb_queue_empty(&map->sock->sk->sk_receive_queue)) + atomic_inc(&map->read); + spin_unlock_irqrestore(&map->sock->sk->sk_receive_queue.lock, flags); + + /* write the data, then modify the indexes */ + virt_wmb(); + if (ret < 0) + intf->in_error = ret; + else + intf->in_prod = prod + ret; + /* update the indexes, then notify the other end */ + virt_wmb(); + notify_remote_via_irq(map->irq); + + return; } static int pvcalls_conn_back_write(struct sock_mapping *map) @@ -172,6 +247,16 @@ static void pvcalls_sk_state_change(struct sock *sock) static void pvcalls_sk_data_ready(struct sock *sock) { + struct sock_mapping *map = sock->sk_user_data; + struct pvcalls_ioworker *iow; + + if (map == NULL) + return; + + iow = &map->ioworker; + atomic_inc(&map->read); + atomic_inc(&map->io); + queue_work(iow->wq, &iow->register_work); } static struct sock_mapping *pvcalls_new_active_socket(