From patchwork Fri Jun 2 19:31:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9763275 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 3BC80602BF for ; Fri, 2 Jun 2017 19:34:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EE9327F60 for ; Fri, 2 Jun 2017 19:34:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23D0B2838B; Fri, 2 Jun 2017 19:34:37 +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 87B9227F60 for ; Fri, 2 Jun 2017 19:34:36 +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 1dGsIp-0004N2-DK; Fri, 02 Jun 2017 19:32:07 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGsIn-0004JB-KJ for xen-devel@lists.xen.org; Fri, 02 Jun 2017 19:32:05 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 01/83-03371-43DB1395; Fri, 02 Jun 2017 19:32:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVybKJssq7JXsN Ig92TJC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyuPdeZC75JV7RMjm5gbJPoYuTiEBJoY5I4 8mIjYxcjJweLgIPE5lOPmboYOTgYBWIkHvywBgkzCoRJTL68hBXEZhMwlPj7ZBMbiC0iIC1x7 fNlRpA5zAKTGSVev/vFDJIQFjCV+NTUxwwxU1XiyPx/YM28Au4SL9/tB7MlBOQkTh6bDGZzAs XXHXvKDHFQO6PEubfzWSYw8i5gZFjFqF6cWlSWWqRrrpdUlJmeUZKbmJmja2hgppebWlycmJ6 ak5hUrJecn7uJERgMDECwg3HmZf9DjJIcTEqivKbGhpFCfEn5KZUZicUZ8UWlOanFhxhlODiU JHg/7wbKCRalpqdWpGXmAMMSJi3BwaMkwiu1ByjNW1yQmFucmQ6ROsWoy7Fh9fovTEIsefl5q VLivF9AZgiAFGWU5sGNgMXIJUZZKWFeRqCjhHgKUotyM0tQ5V8xinMwKgnzsoBM4cnMK4Hb9A roCCagI15s0wc5oiQRISXVwFh+58CeR1tXvDn+cvoZw+NSXWU3FPmsFq7osIpfsf7G4y9p3wz 5FBfaRHGFxH3LuWh0wac6Rj8zumz9AnFrl8staSs/Xlgd8Ihlfqrl1wVGOcdOSB+YclXtWrLJ gkSD1yIap3Zcfb9/+dfHZ8pYHb5d8VnyZP2z/3evmUuz8fB8SJ2ddyx2Ta2dEktxRqKhFnNRc SIAPsqgyYwCAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-10.tower-27.messagelabs.com!1496431923!82640213!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 22281 invoked from network); 2 Jun 2017 19:32:04 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Jun 2017 19:32:04 -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 8809E23A33; Fri, 2 Jun 2017 19:32:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8809E23A33 From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Fri, 2 Jun 2017 12:31:53 -0700 Message-Id: <1496431915-20774-16-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1496431915-20774-1-git-send-email-sstabellini@kernel.org> References: <1496431915-20774-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 v3 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 0283d49..e7d2b85 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -101,6 +101,81 @@ static int pvcalls_back_release_active(struct xenbus_device *dev, static void pvcalls_conn_back_read(unsigned long 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 > 0 && 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) @@ -173,6 +248,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_on(iow->cpu, iow->wq, &iow->register_work); } static struct sock_mapping *pvcalls_new_active_socket(