From patchwork Wed Jul 5 21:50:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9827203 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 B309A603B5 for ; Wed, 5 Jul 2017 21:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6034C2853D for ; Wed, 5 Jul 2017 21:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5224725223; Wed, 5 Jul 2017 21:53:28 +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 C59D525223 for ; Wed, 5 Jul 2017 21:53:27 +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 1dSsCm-0003cg-78; Wed, 05 Jul 2017 21:51:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSsCk-0003Zl-8T for xen-devel@lists.xen.org; Wed, 05 Jul 2017 21:51:26 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 6F/9E-03406-D5F5D595; Wed, 05 Jul 2017 21:51:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHLMWRWlGSWpSXmKPExsVybKJssm5MfGy kQft+MYslHxezODB6HN39mymAMYo1My8pvyKBNePqgWfMBU0yFdt/TGJuYJwi0cXIxSEksI5J ouf9acYuRg4OFgEHiY0HdEFMRoEYiQc/rLsYOYHMMInJl5ewgthsAoYSf59sYgOxRQSkJa59v swIMoZZYDKjxOt3v5hBEsICphJzdl1kArFZBFQl/s9/DjaeV8Bd4sF9DZCwhICcxMljk8Fmcg KFz7QuZIU4p41RYu/zH0wTGHkXMDKsYlQvTi0qSy3SNddLKspMzyjJTczM0TU0MNPLTS0uTkx PzUlMKtZLzs/dxAgMBQYg2ME487L/IUZJDiYlUd4/+rGRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4 lCR4S+KAcoJFqempFWmZOcCghElLcPAoifCuFgZK8xYXJOYWZ6ZDpE4xGnNsWL3+CxPHqwn/v zEJseTl56VKifMKgUwSACnNKM2DGwSLlkuMslLCvIxApwnxFKQW5WaWoMq/YhTnYFQS5t0WCz SFJzOvBG7fK6BTmIBOUWyMATmlJBEhJdXA2MSS/NJ0RfQEW7Ptbmtm2hRlPT6jHaPys/bqp8q Of5v2ZFz9up/Fcsu0M+fjrLfEe77K3bvjb2JR9iKjw4vM+J/NtnloNL+hOqh0TVagRAa3OncW y8fkQ5oTClxezfvq/JepNe3hbtWJim2+jOHhNrHr16/alTXrdPsn5Yy4VZZLvzp2PO5iUGIpz kg01GIuKk4EACIOz5uRAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-11.tower-21.messagelabs.com!1499291482!71780987!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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3502 invoked from network); 5 Jul 2017 21:51:24 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-11.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Jul 2017 21:51:24 -0000 Received: from localhost.localdomain (162-198-228-33.lightspeed.wlfrct.sbcglobal.net [162.198.228.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 057D722C7D; Wed, 5 Jul 2017 21:51:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 057D722C7D From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Wed, 5 Jul 2017 14:50:56 -0700 Message-Id: <1499291458-30231-16-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499291458-30231-1-git-send-email-sstabellini@kernel.org> References: <1499291458-30231-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 v7 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 Reviewed-by: Juergen Gross 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 a5f11d5..970db9d 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -98,6 +98,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 void pvcalls_conn_back_write(struct sock_mapping *map) @@ -169,6 +244,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(