Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp200569pxj; Tue, 1 Jun 2021 19:16:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7tnrbsrhToAfOmNw0ohHpAUEP4YLjUM3DF2ynaZkMZ1yegf2eYGcWYmmsh/mTWWxHtc7i X-Received: by 2002:a5d:9a0b:: with SMTP id s11mr12073181iol.166.1622600200444; Tue, 01 Jun 2021 19:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622600200; cv=none; d=google.com; s=arc-20160816; b=uS9kQkGBw9G4E4aDD0qz2bf49jNkG9KE35QSIKGn2oeVzGb6kJifrH00M1UJuEOeem HtKC+lqI5ew9NCzAZ0E+b67CKEmR81kqhSAbQJNYAhdCYsVsgld1baD56smfFIbqkQSK s4h6j/azIDRqvIEXcDm8hCBFJO856VwqOqkvhAXA9eNv4nqiYC4FE6LZzzQKu+ZMY2su VBIX9K5yYilrF5ul0O5VKqIUl4Y4cWy4OcxZLYBJDwJ8Q65x1My/sZEeNoCGDfZSr+q7 7xuOtiCoEfvuh15EF7bK390/PGjBJ9lrTM+aZYzS0+MG03/Ntx4Ah/UESILg/mu+lzHZ HqCw== 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=WrB6mvofF/eyGV52SKIt7JTVB1esFhxct19/WhmLXiU=; b=MKZyB7th5J0G7AE9+CBfOCylJ8Cn1nhLgJunZQtzzWLJCQxW57iesIqORj28VR8VmE 5mzN3qsq7oyAMcE/JZ39cOcnIIFPBZEisNOMguJJo1H0Ccbtf5PI7ZN+xO9PtfOBIX/q pDPG9mdW95utJJW+cvCRljhhf7uiaWOFHKyl1/wJ8jfiDGAFY1b048+h6vsOFjEPCnvw c/LkIObyiM+BXC+hseBhCP3PLYd5vpf9GlqUOxi+KBTjHcVZHThA0S3XegrdxLtzIK7b twHR2mbVwGZzGsDyOQ2gbP+DMxgl/3h2ab/mWx0xpHJnvVDFWtjwXn+yCgJTcuZZBWAD +aLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dKYv+VFe; 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 s11si6158318ilo.100.2021.06.01.19.16.27; Tue, 01 Jun 2021 19:16:40 -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=dKYv+VFe; 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 S230272AbhFBCMz (ORCPT + 99 others); Tue, 1 Jun 2021 22:12:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24092 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbhFBCMt (ORCPT ); Tue, 1 Jun 2021 22:12:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622599866; 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=WrB6mvofF/eyGV52SKIt7JTVB1esFhxct19/WhmLXiU=; b=dKYv+VFeAp4blaZwpomxBIVGsXwM3DHhuInMq6gAjI+g7vC4l4Pr6ZVSsNzirLa0a7XWGc bUW7IYIy+15gRExT08cvM1nmZk6Zs+5AuTT+sKhZTcGHYl7v2uxJuJtav/OYjtOSl66WuN JozYrtDZc9M58DodWOAgAFTCXEbxpVo= 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-589-QUMcm96xNXuVvu3xnwUhLw-1; Tue, 01 Jun 2021 22:11:03 -0400 X-MC-Unique: QUMcm96xNXuVvu3xnwUhLw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E7C6180FD6D; Wed, 2 Jun 2021 02:11:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-99.pek2.redhat.com [10.72.12.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96EAD5D6CF; Wed, 2 Jun 2021 02:10:59 +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 Subject: [PATCH V2 3/4] vp_vdpa: allow set vq state to initial state after reset Date: Wed, 2 Jun 2021 10:10:42 +0800 Message-Id: <20210602021043.39201-4-jasowang@redhat.com> In-Reply-To: <20210602021043.39201-1-jasowang@redhat.com> References: <20210602021043.39201-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We used to fail the set_vq_state() since it was not supported yet by the virtio spec. But if the bus tries to set the state which is equal to the device initial state after reset, we can let it go. This is a must for virtio_vdpa() to set vq state during probe which is required for some vDPA parents. Signed-off-by: Jason Wang --- drivers/vdpa/virtio_pci/vp_vdpa.c | 42 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c index c76ebb531212..18bf4a422772 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -210,13 +210,49 @@ static int vp_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 qid, return -EOPNOTSUPP; } +static int vp_vdpa_set_vq_state_split(struct vdpa_device *vdpa, + const struct vdpa_vq_state *state) +{ + const struct vdpa_vq_state_split *split = &state->split; + + if (split->avail_index == 0) + return 0; + + return -EOPNOTSUPP; +} + +static int vp_vdpa_set_vq_state_packed(struct vdpa_device *vdpa, + const struct vdpa_vq_state *state) +{ + const struct vdpa_vq_state_packed *packed = &state->packed; + + if (packed->last_avail_counter == 1 && + packed->last_avail_idx == 0 && + packed->last_used_counter == 1 && + packed->last_used_idx == 0) + return 0; + + return -EOPNOTSUPP; +} + static int vp_vdpa_set_vq_state(struct vdpa_device *vdpa, u16 qid, const struct vdpa_vq_state *state) { - /* Note that this is not supported by virtio specification, so - * we return -ENOPOTSUPP here. This means we can't support live - * migration, vhost device start/stop. + struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa); + + /* Note that this is not supported by virtio specification. + * But if the state is by chance equal to the device initial + * state, we can let it go. */ + if ((vp_modern_get_status(mdev) & VIRTIO_CONFIG_S_FEATURES_OK) && + !vp_modern_get_queue_enable(mdev, qid)) { + if (vp_modern_get_driver_features(mdev) & + BIT_ULL(VIRTIO_F_RING_PACKED)) + return vp_vdpa_set_vq_state_packed(vdpa, state); + else + return vp_vdpa_set_vq_state_split(vdpa, state); + } + return -EOPNOTSUPP; } -- 2.25.1