Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1233289ybg; Thu, 11 Jun 2020 04:40:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3EgPTyo2eVW8L6guthg7eIQIcYYVWsDrQVk0nxMNmDBoYzX4lG4UC9RR9Fcv91qJgiOML X-Received: by 2002:a17:906:4dc2:: with SMTP id f2mr8326230ejw.402.1591875612354; Thu, 11 Jun 2020 04:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591875612; cv=none; d=google.com; s=arc-20160816; b=rOobSGVzU5G2LpjJyixCK7mXzxBxKNkwPuLHKa9GhQfDzLYLzrHL6c6Y10LOaAd2u6 Cilq9V46NLYAv/AOvu3UbkiEwuTyZygbUZbLICqrRySDUdrdNIZkKZWvNKWNAJh5gQvJ OtwLn+isF4t2t1+Mrgk53210rJe+HWPW0l4WkNd7YbQZVmWz35gLqPurwzZRpgFkIVCj ckaaRrvnn6OVfvvcm46oXaH2wSxIyFocSfTaQWYsrP9qWbWUcXvBNbyLiLHf7rfDj7eQ J7/+xjdPy7OsvknxfsLOq8UuVWq3kXK2BdJefYT6Fm4dXCZRPdJ2hJQecnW6x1sSNE91 NE8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=dyvL3TJdoghmFE7taHXWfXC0TleKg1Dbjs9VDE83TZ8=; b=Be35BvpV5CPO7eXz33v0wMrfHzUeLYA3vjpGmpqKuCuH658siK/9QByM7uUvdjKJsL 42Wn9GzFP6edhru3lMP2c6LIYkcMaVaCoC8pWFZESlspf82+nOn95RlVdeuu1Ggl6TQL k1Qg+tvRDiik0THxNB/x4DgbIn4o/rFEflWaNp15YWaeVZdDRymM4lkdADcjbAs7PxqF bWguz1IVQGlkVlRLXna3zyH/eb7NDB386LTfgpJNaVU1El6eYMCseqWDxKqar8TapPZS MgCiyVPcy47XGO73Ph0vyt/B3ifwOXkbSLCRjkQlz8ZR3cJBVxjqIpzl0J5q5cSrJ87m y1gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZfZnAmQe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si1758835ejk.51.2020.06.11.04.39.49; Thu, 11 Jun 2020 04:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZfZnAmQe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728186AbgFKLe5 (ORCPT + 99 others); Thu, 11 Jun 2020 07:34:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26164 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728153AbgFKLeq (ORCPT ); Thu, 11 Jun 2020 07:34:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591875284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dyvL3TJdoghmFE7taHXWfXC0TleKg1Dbjs9VDE83TZ8=; b=ZfZnAmQerM1W2uVxoXNjbmFgMqZrwioaa4+zeyJ+GtdAQ0RpDzBfy9+NKl4hnppkUjiZwF oL9cR0TYWQd/0L5Kv10BYxww2ZOatUBBwWY05nog5h3b1LVUP4TxGQ21zF2TvKfc1WTIYt Y0u1tUhW6cozBqfBS0JOFUuhUkKvyKg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-c7bSdMe6OOa4QLSOm4Hqlg-1; Thu, 11 Jun 2020 07:34:40 -0400 X-MC-Unique: c7bSdMe6OOa4QLSOm4Hqlg-1 Received: by mail-wr1-f72.google.com with SMTP id t5so2436546wro.20 for ; Thu, 11 Jun 2020 04:34:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dyvL3TJdoghmFE7taHXWfXC0TleKg1Dbjs9VDE83TZ8=; b=tVmwQCI9Y69sXcyKS1carIYFDDWAHzDJGWmJ0WO3R5Ie+L5FGk90v+An5sEFm8PdM9 XDtTJ0Ul1Ckxm1rdx3dOgUG6pYVxQPMnBGWhA3Uy/zyvsUSQVCHKpLzDzd088oMrUxZ+ JwpijQNF8Mrao1MP8RflgTKhmFgQK96xX/v7chG+OLMTrI5ZfiITEHu7lKWTD7oRrziy a/pBUaQ8kG8ldyyKIQ+/sBDkPLc9bpEc56tB6Mj7R2rRDbWYDaZYZJq9CJwX1EbqW+yM hCTqAwoFmI7awJdZXGSwVTOK2poDMX5613gH4y/Z/FCnKVVj5h5Q9etBxHMo0Y/fm9y7 SRHw== X-Gm-Message-State: AOAM530SWqirltgBe4HqFOn0DVU0+E/j10KL8C+MFTVmwOyDCeKaDX1Y eBYTW8C6599G0j3iOv4xHH5TXccFleaNgmQ5DJwe4T6xN6iXzc/lwmpGy0lYyEgh3EhBy1Rt+Xc 80RRf11lzxX9ufZssJ3GnGBNk X-Received: by 2002:a05:6000:114e:: with SMTP id d14mr8888250wrx.110.1591875279144; Thu, 11 Jun 2020 04:34:39 -0700 (PDT) X-Received: by 2002:a05:6000:114e:: with SMTP id d14mr8888227wrx.110.1591875278776; Thu, 11 Jun 2020 04:34:38 -0700 (PDT) Received: from redhat.com (bzq-79-181-55-232.red.bezeqint.net. [79.181.55.232]) by smtp.gmail.com with ESMTPSA id 14sm1902431wmi.20.2020.06.11.04.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 04:34:38 -0700 (PDT) Date: Thu, 11 Jun 2020 07:34:36 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, Jason Wang , eperezma@redhat.com, Paolo Bonzini , Stefan Hajnoczi Subject: [PATCH RFC v8 09/11] vhost/scsi: switch to buf APIs Message-ID: <20200611113404.17810-10-mst@redhat.com> References: <20200611113404.17810-1-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200611113404.17810-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switch to buf APIs. Doing this exposes a spec violation in vhost scsi: all used bufs are marked with length 0. Fix that is left for another day. Signed-off-by: Michael S. Tsirkin --- drivers/vhost/scsi.c | 73 ++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 0cbaa0b3893d..a5cdd4c01a3a 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -71,8 +71,8 @@ struct vhost_scsi_inflight { }; struct vhost_scsi_cmd { - /* Descriptor from vhost_get_vq_desc() for virt_queue segment */ - int tvc_vq_desc; + /* Descriptor from vhost_get_avail_buf() for virt_queue segment */ + struct vhost_buf tvc_vq_desc; /* virtio-scsi initiator task attribute */ int tvc_task_attr; /* virtio-scsi response incoming iovecs */ @@ -213,7 +213,7 @@ struct vhost_scsi { * Context for processing request and control queue operations. */ struct vhost_scsi_ctx { - int head; + struct vhost_buf buf; unsigned int out, in; size_t req_size, rsp_size; size_t out_size, in_size; @@ -443,6 +443,20 @@ static int vhost_scsi_check_stop_free(struct se_cmd *se_cmd) return target_put_sess_cmd(se_cmd); } +/* Signal to guest that request finished with no input buffer. */ +/* TODO calling this when writing into buffer and most likely a bug */ +static void vhost_scsi_signal_noinput(struct vhost_dev *vdev, + struct vhost_virtqueue *vq, + struct vhost_buf *bufp) +{ + struct vhost_buf buf = *bufp; + + buf.in_len = 0; + vhost_put_used_buf(vq, &buf); + vhost_signal(vdev, vq); +} + + static void vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) { @@ -450,7 +464,8 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) struct virtio_scsi_event *event = &evt->event; struct virtio_scsi_event __user *eventp; unsigned out, in; - int head, ret; + struct vhost_buf buf; + int ret; if (!vhost_vq_get_backend(vq)) { vs->vs_events_missed = true; @@ -459,14 +474,14 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) again: vhost_disable_notify(&vs->dev, vq); - head = vhost_get_vq_desc(vq, vq->iov, - ARRAY_SIZE(vq->iov), &out, &in, - NULL, NULL); - if (head < 0) { + ret = vhost_get_avail_buf(vq, &buf, + vq->iov, ARRAY_SIZE(vq->iov), &out, &in, + NULL, NULL); + if (ret < 0) { vs->vs_events_missed = true; return; } - if (head == vq->num) { + if (!ret) { if (vhost_enable_notify(&vs->dev, vq)) goto again; vs->vs_events_missed = true; @@ -488,7 +503,7 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) eventp = vq->iov[out].iov_base; ret = __copy_to_user(eventp, event, sizeof(*event)); if (!ret) - vhost_add_used_and_signal(&vs->dev, vq, head, 0); + vhost_scsi_signal_noinput(&vs->dev, vq, &buf); else vq_err(vq, "Faulted on vhost_scsi_send_event\n"); } @@ -549,7 +564,7 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work) ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); if (likely(ret == sizeof(v_rsp))) { struct vhost_scsi_virtqueue *q; - vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0); + vhost_put_used_buf(cmd->tvc_vq, &cmd->tvc_vq_desc); q = container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq); vq = q - vs->vqs; __set_bit(vq, signal); @@ -793,7 +808,7 @@ static void vhost_scsi_submission_work(struct work_struct *work) static void vhost_scsi_send_bad_target(struct vhost_scsi *vs, struct vhost_virtqueue *vq, - int head, unsigned out) + struct vhost_buf *buf, unsigned out) { struct virtio_scsi_cmd_resp __user *resp; struct virtio_scsi_cmd_resp rsp; @@ -804,7 +819,7 @@ vhost_scsi_send_bad_target(struct vhost_scsi *vs, resp = vq->iov[out].iov_base; ret = __copy_to_user(resp, &rsp, sizeof(rsp)); if (!ret) - vhost_add_used_and_signal(&vs->dev, vq, head, 0); + vhost_scsi_signal_noinput(&vs->dev, vq, buf); else pr_err("Faulted on virtio_scsi_cmd_resp\n"); } @@ -813,21 +828,21 @@ static int vhost_scsi_get_desc(struct vhost_scsi *vs, struct vhost_virtqueue *vq, struct vhost_scsi_ctx *vc) { - int ret = -ENXIO; + int r, ret = -ENXIO; - vc->head = vhost_get_vq_desc(vq, vq->iov, - ARRAY_SIZE(vq->iov), &vc->out, &vc->in, - NULL, NULL); + r = vhost_get_avail_buf(vq, &vc->buf, + vq->iov, ARRAY_SIZE(vq->iov), &vc->out, &vc->in, + NULL, NULL); - pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n", - vc->head, vc->out, vc->in); + pr_debug("vhost_get_avail_buf: buf: %d, out: %u in: %u\n", + vc->buf.id, vc->out, vc->in); /* On error, stop handling until the next kick. */ - if (unlikely(vc->head < 0)) + if (unlikely(r < 0)) goto done; /* Nothing new? Wait for eventfd to tell us they refilled. */ - if (vc->head == vq->num) { + if (!r) { if (unlikely(vhost_enable_notify(&vs->dev, vq))) { vhost_disable_notify(&vs->dev, vq); ret = -EAGAIN; @@ -1093,11 +1108,11 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) } } /* - * Save the descriptor from vhost_get_vq_desc() to be used to + * Save the descriptor from vhost_get_avail_buf() to be used to * complete the virtio-scsi request in TCM callback context via * vhost_scsi_queue_data_in() and vhost_scsi_queue_status() */ - cmd->tvc_vq_desc = vc.head; + cmd->tvc_vq_desc = vc.buf; /* * Dispatch cmd descriptor for cmwq execution in process * context provided by vhost_scsi_workqueue. This also ensures @@ -1117,7 +1132,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) if (ret == -ENXIO) break; else if (ret == -EIO) - vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); + vhost_scsi_send_bad_target(vs, vq, &vc.buf, vc.out); } while (likely(!vhost_exceeds_weight(vq, ++c, 0))); out: mutex_unlock(&vq->mutex); @@ -1139,9 +1154,9 @@ vhost_scsi_send_tmf_reject(struct vhost_scsi *vs, iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp)); ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); - if (likely(ret == sizeof(rsp))) - vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); - else + if (likely(ret == sizeof(rsp))) { + vhost_scsi_signal_noinput(&vs->dev, vq, &vc->buf); + } else pr_err("Faulted on virtio_scsi_ctrl_tmf_resp\n"); } @@ -1162,7 +1177,7 @@ vhost_scsi_send_an_resp(struct vhost_scsi *vs, ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); if (likely(ret == sizeof(rsp))) - vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); + vhost_scsi_signal_noinput(&vs->dev, vq, &vc->buf); else pr_err("Faulted on virtio_scsi_ctrl_an_resp\n"); } @@ -1269,7 +1284,7 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) if (ret == -ENXIO) break; else if (ret == -EIO) - vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); + vhost_scsi_send_bad_target(vs, vq, &vc.buf, vc.out); } while (likely(!vhost_exceeds_weight(vq, ++c, 0))); out: mutex_unlock(&vq->mutex); -- MST