Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3294245pxj; Tue, 1 Jun 2021 01:47:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3v9pPCpO9y62IlcwrlqACd2SK2nX/sMevF2EECjLLKCkfVw/ivWBTRhF/w26Xv91K5lxf X-Received: by 2002:a02:a10f:: with SMTP id f15mr24082475jag.124.1622537258814; Tue, 01 Jun 2021 01:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622537258; cv=none; d=google.com; s=arc-20160816; b=tO9oFKU+hbDeQCmSJmR1leApxRwYVtlH4rdHLr6ixrGqNu8QorMpi8ppei5qTuBonf AGPnbwSy4FfkD4AgfzR3oA3WWeDygvC62H2vXX9zpOZwN/BvhaRsdgs8yMQ1DMUTPlao BmmGh+aaqrzPyTMeW02d+Sr6rLanV50o7GNG69trZZUvbzJavaiY6QOrpIToHWpAPte0 GOJ6dHl1uJs5zIdgstJ6TBQqA/kjCFVB2UKyRJ5HFNMgIjFuK1++yU9DnY4DE8nZQkXo b32DUJM9NYXuXFWoTD9sdZaogZ2CfvwxmnYK2h7C/2LPi65VGeiVyZoMPAaxPn9HaTZ+ gpAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0N48jdl0LC6EEeO/MPQo8KIfakfiafpunndtsq1f0hA=; b=k8Vrlo6Z6aafvtVIuD6YY9r7EElsONLUXdft1sD225GZeD4XwTw6gC/5plosaNinhZ /LE6oAuLES3Ud1Uqbn/iIN1Gw3wLGTScPsjF+PKLGF8Prx93upV5KNZGb4RplPut/05m YFHNJxSzCjIXdGoFfsXKXjXk18Jo6qWShzIE21t4/+19uv5f5vi5T6Cvvuyf7nEY2PGi k1hx7fV8/2wjLtPuBu2cFKCK0eNI7Dat5SJRucdyfEMUNnwoFQhf5rEhtjDIgh1suxfd QKq2wWsXQ14lkERz8+ff3ruB5NYq3rxYSBafu1bOSTlhW7C9xKq0lUa1sjQO92pWtDYo 9bEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOgxd9Mp; 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 r21si7125168ioc.48.2021.06.01.01.47.25; Tue, 01 Jun 2021 01:47:38 -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=QOgxd9Mp; 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 S233711AbhFAIr1 (ORCPT + 99 others); Tue, 1 Jun 2021 04:47:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42193 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233571AbhFAIrS (ORCPT ); Tue, 1 Jun 2021 04:47:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622537137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0N48jdl0LC6EEeO/MPQo8KIfakfiafpunndtsq1f0hA=; b=QOgxd9MpoTi+pilPGEza1P7Yf3/ZdoxiE1hJ29DjtUuOihupQ6KuwouJypRnZkNK09HXM7 QOAjxGyKstWkVPL1D5NvSO5kAUJ1QUPzP1Hl8AEYRCPW/bFEzXyDZ2SVWeS4+Bie/h8LUr CtCwXM9GGg7RWC8PS610wz6tzcGjmYo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-Okf16E4rOF-PsWMWXG2vHg-1; Tue, 01 Jun 2021 04:45:36 -0400 X-MC-Unique: Okf16E4rOF-PsWMWXG2vHg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FEE3106BAEA; Tue, 1 Jun 2021 08:45:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-16.pek2.redhat.com [10.72.12.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id D050D100E113; Tue, 1 Jun 2021 08:45:28 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Cc: eli@mellanox.com, Eli Cohen Subject: [PATCH 4/4] virtio/vdpa: clear the virtqueue state during probe Date: Tue, 1 Jun 2021 16:45:03 +0800 Message-Id: <20210601084503.34724-5-jasowang@redhat.com> In-Reply-To: <20210601084503.34724-1-jasowang@redhat.com> References: <20210601084503.34724-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eli Cohen Clear the available index as part of the initialization process to clear and values that might be left from previous usage of the device. For example, if the device was previously used by vhost_vdpa and now probed by vhost_vdpa, you want to start with indices. Fixes: c043b4a8cf3b ("virtio: introduce a vDPA based transport") Signed-off-by: Eli Cohen Signed-off-by: Jason Wang --- drivers/virtio/virtio_vdpa.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c index e28acf482e0c..e1a141135992 100644 --- a/drivers/virtio/virtio_vdpa.c +++ b/drivers/virtio/virtio_vdpa.c @@ -142,6 +142,8 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, struct vdpa_callback cb; struct virtqueue *vq; u64 desc_addr, driver_addr, device_addr; + /* Assume split virtqueue, switch to packed if necessary */ + struct vdpa_vq_state state = {0}; unsigned long flags; u32 align, num; int err; @@ -191,6 +193,19 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index, goto err_vq; } + /* reset virtqueue state index */ + if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) { + struct vdpa_vq_state_packed *s = &state.packed; + + s->last_avail_counter = 1; + s->last_avail_idx = 0; + s->last_used_counter = 1; + s->last_used_idx = 0; + } + err = ops->set_vq_state(vdpa, index, &state); + if (err) + goto err_vq; + ops->set_vq_ready(vdpa, index, 1); vq->priv = info; -- 2.25.1