From patchwork Fri Jun 2 19:31:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9763283 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 BE94A602BF for ; Fri, 2 Jun 2017 19:34:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1799285A8 for ; Fri, 2 Jun 2017 19:34:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A63D3285B0; Fri, 2 Jun 2017 19:34:45 +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 2CC97285A8 for ; Fri, 2 Jun 2017 19:34:45 +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 1dGsJ4-0004dL-Pi; Fri, 02 Jun 2017 19:32:22 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGsJ3-0004bZ-BX for xen-devel@lists.xen.org; Fri, 02 Jun 2017 19:32:21 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 28/7B-03620-44DB1395; Fri, 02 Jun 2017 19:32:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVybKJssq7zXsN Ig84DVhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aDj5IF2yUqzu89wtzAeFOki5GLQ0igjUni 8eqrTF2MnBwsAg4SK1vbgWwODkaBGIkHP6xBwowCYRKTLy9hBbHZBAwl/j7ZxAZiiwhIS1z7f JkRZA6zwGRGidfvfjGDJIQFzCSmP9nKBjFTVWLm0e9gzbwC7hIPplxiAbElBOQkTh6bDBbnBI qvO/aUGeKgdkaJc2/ns0xg5F3AyLCKUaM4tagstUjXyEwvqSgzPaMkNzEzR9fQwEwvN7W4ODE 9NScxqVgvOT93EyMwHBiAYAfjmQWBhxglOZiURHlNjQ0jhfiS8lMqMxKLM+KLSnNSiw8xynBw KEnwNu0GygkWpaanVqRl5gADEyYtwcGjJMJ7FyTNW1yQmFucmQ6ROsWoy7Fh9fovTEIsefl5q VLivDEgRQIgRRmleXAjYFFyiVFWSpiXEegoIZ6C1KLczBJU+VeM4hyMSsK8LCBTeDLzSuA2vQ I6ggnoiBfb9EGOKElESEk1MBYFLQlhe/7e4O33dYdTbt3f1TPv1rqGxCBr9izRgADlmScNVpk mq6nU7lWv9j4saHT4kX/iy+eJ6uIRbl4sp1ulfQ/z1EdblLnMSJZrfzG77qbgacPDFywaW21f XuP0ufC00fzffp0XBoIbqkWET7X9eL1ps93iOyeZRO3/3p5c/erPr8vT5iuxFGckGmoxFxUnA gB1cSB7jQIAAA== X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-8.tower-21.messagelabs.com!1496431938!71948299!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 7120 invoked from network); 2 Jun 2017 19:32:19 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-8.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Jun 2017 19:32:19 -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 DA85323A31; Fri, 2 Jun 2017 19:32:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA85323A31 From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Fri, 2 Jun 2017 12:31:54 -0700 Message-Id: <1496431915-20774-17-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 17/18] xen/pvcalls: implement write 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 the other end notifies us that there is data to be written (pvcalls_back_conn_event), increment the io and write counters, and schedule the ioworker. Implement the write function called by ioworker by reading the data from the data ring, writing it to the socket by calling inet_sendmsg. Set out_error on error. Signed-off-by: Stefano Stabellini CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- drivers/xen/pvcalls-back.c | 74 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index e7d2b85..fe3e70f 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -180,7 +180,66 @@ static void pvcalls_conn_back_read(unsigned long opaque) static int pvcalls_conn_back_write(struct sock_mapping *map) { - return 0; + struct pvcalls_data_intf *intf = map->ring; + struct pvcalls_data *data = &map->data; + struct msghdr msg; + struct kvec vec[2]; + RING_IDX cons, prod, size, ring_size; + int ret; + + cons = intf->out_cons; + prod = intf->out_prod; + /* read the indexes before dealing with the data */ + virt_mb(); + + ring_size = XEN_FLEX_RING_SIZE(map->ring_order); + size = pvcalls_queued(prod, cons, ring_size); + if (size == 0) + return 0; + + memset(&msg, 0, sizeof(msg)); + msg.msg_flags |= MSG_DONTWAIT; + msg.msg_iter.type = ITER_KVEC|READ; + msg.msg_iter.count = size; + if (pvcalls_mask(prod, ring_size) > pvcalls_mask(cons, ring_size)) { + vec[0].iov_base = data->out + pvcalls_mask(cons, ring_size); + vec[0].iov_len = size; + msg.msg_iter.kvec = vec; + msg.msg_iter.nr_segs = 1; + } else { + vec[0].iov_base = data->out + pvcalls_mask(cons, ring_size); + vec[0].iov_len = ring_size - pvcalls_mask(cons, ring_size); + vec[1].iov_base = data->out; + vec[1].iov_len = size - vec[0].iov_len; + msg.msg_iter.kvec = vec; + msg.msg_iter.nr_segs = 2; + } + + atomic_set(&map->write, 0); + ret = inet_sendmsg(map->sock, &msg, size); + if (ret == -EAGAIN || ret < size) { + atomic_inc(&map->write); + atomic_inc(&map->io); + } + if (ret == -EAGAIN) + return ret; + + /* write the data, then update the indexes */ + virt_wmb(); + if (ret < 0) { + intf->out_error = ret; + } else { + intf->out_error = 0; + intf->out_cons = cons + ret; + prod = intf->out_prod; + } + /* update the indexes, then notify the other end */ + virt_wmb(); + if (prod != cons + ret) + atomic_inc(&map->write); + notify_remote_via_irq(map->irq); + + return ret; } static void pvcalls_back_ioworker(struct work_struct *work) @@ -837,6 +896,19 @@ static irqreturn_t pvcalls_back_event(int irq, void *dev_id) static irqreturn_t pvcalls_back_conn_event(int irq, void *sock_map) { + struct sock_mapping *map = sock_map; + struct pvcalls_ioworker *iow; + + if (map == NULL || map->sock == NULL || map->sock->sk == NULL || + map->sock->sk->sk_user_data != map) + return IRQ_HANDLED; + + iow = &map->ioworker; + + atomic_inc(&map->write); + atomic_inc(&map->io); + queue_work_on(iow->cpu, iow->wq, &iow->register_work); + return IRQ_HANDLED; }