Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5820722pxb; Tue, 16 Feb 2021 08:22:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoC8CRso3bt/a1XSmbXsPo6Ns4BzLP7ESBP1o4uW43nJaAfMIQTM2FtzKXc91XwJHERcPp X-Received: by 2002:a17:906:1712:: with SMTP id c18mr21447745eje.417.1613492534361; Tue, 16 Feb 2021 08:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613492534; cv=none; d=google.com; s=arc-20160816; b=SXcalcKiYh4xcCE7QbDFOwQzEhrEOD2Bvyfhh9QLOi7LP5VFtla/EJSc7miXAF4phQ o9/09Ly8Xqjw4iQMwl5v8qcLeQ4rpsJj6839TFDmsI0oxkrSa0z3KF7fT7IaLCQwXcq5 665oAtbdmNQHYsrrV6+ZoQqSPJuN4CuqZPfWqowFsh2MgtBKEPAije/4+5eU29vkE6WR 5n6wus4/xqF7B2B+dwt1cqXjBhOdVQGEuXIey68CpxO/7U2i0Vi7M7ULbj20nbLrj2fl jXWtaHhLqAykFceaNcYKrpDdzV6IItSb6D/S3f2YhX0oxbGDgvutViFdnuV1O2mEL/DG Ke5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=kc8WQQ00x8KDTal1OlNbrMI+gHFHE5f0MPt31tY4EDc=; b=xg99oa0Qh7mT/jT5BaX6jjcgXlD1KpUrUxycPK82vRg7VTdII0nBVH4yhVVOaDD4rB KB5cNnXQfG5Ob0ruAWscH5UxDdAxynui30t08hWfk39ntJn2r83KhIbPwtGCKPqghN0C yRibBzruQJlMd97y8XSETmsRsZawESmQOUSU2GlA5hYW7gvag040iSiuEFc2gzIwZ0qj lrWapHBf2MRcfGeTcyv+uaWQ6PEZ4HitQ1VlRIPVpNkFWW3BPR2VLcB8HVrQ4oogH6+k KK/cdbTWZaCwH1XPK8SNlwYdR+mFLeB2kCcELGHyb0HOesII2LErLGRdRY4TLTXj9urx ELZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=TQr5ZunP; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd22si11327804edb.69.2021.02.16.08.21.50; Tue, 16 Feb 2021 08:22:14 -0800 (PST) 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=@nvidia.com header.s=n1 header.b=TQr5ZunP; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbhBPQUs (ORCPT + 99 others); Tue, 16 Feb 2021 11:20:48 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:17089 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbhBPQUr (ORCPT ); Tue, 16 Feb 2021 11:20:47 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 16 Feb 2021 08:20:06 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 16 Feb 2021 16:20:05 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 16 Feb 2021 16:20:04 +0000 From: Eli Cohen To: , , , , , CC: Subject: [PATCH 1/2] vdpa/mlx5: Fix suspend/resume index restoration Date: Tue, 16 Feb 2021 18:20:01 +0200 Message-ID: <20210216162001.83541-1-elic@nvidia.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1613492406; bh=kc8WQQ00x8KDTal1OlNbrMI+gHFHE5f0MPt31tY4EDc=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type; b=TQr5ZunPlptIn1FcOetUBfF5zVR0WjNhWUFeVAzcA5BAKo2gDXh5/EP/EJLpOPaYQ vKO+vc7JUOUWCLMtYIlRBtoKr4eVaicgdvw2Kv5ayqMFqctAUCoKXPGGI6z6AJrRXm /v8n5fpkHcrtt+LI8t/U0H8shg9TeykW8iNvCyLlbQgSWJ4wM4cnM7TXZqqCNN8dlH 7Nprp2BaNT/zIFoDTgyYQ+0cpj8SynrYGb4ZzWg7MmWfw/faP3LDSF2eovm3JReVNC 9ez9uPn8FnNAODATGUninHj6tkXBQ+pvrddpETJGulDYlmv7SKegCz/fuii+KNHgH/ Y0vrTwzcojS5Q== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we suspend the VM, the VDPA interface will be reset. When the VM is resumed again, clear_virtqueues() will clear the available and used indices resulting in hardware virqtqueue objects becoming out of sync. We can avoid this function alltogether since qemu will clear them if required, e.g. when the VM went through a reboot. Moreover, since the hw available and used indices should always be identical on query and should be restored to the same value same value for virtqueues that complete in order, we set the single value provided by set_vq_state(). In get_vq_state() we return the value of hardware used index. Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices= ") Signed-off-by: Eli Cohen --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index b8e9d525d66c..a51b0f86afe2 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1169,6 +1169,7 @@ static void suspend_vq(struct mlx5_vdpa_net *ndev, st= ruct mlx5_vdpa_virtqueue *m return; } mvq->avail_idx =3D attr.available_index; + mvq->used_idx =3D attr.used_index; } =20 static void suspend_vqs(struct mlx5_vdpa_net *ndev) @@ -1426,6 +1427,7 @@ static int mlx5_vdpa_set_vq_state(struct vdpa_device = *vdev, u16 idx, return -EINVAL; } =20 + mvq->used_idx =3D state->avail_index; mvq->avail_idx =3D state->avail_index; return 0; } @@ -1443,7 +1445,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device = *vdev, u16 idx, struct vdpa * that cares about emulating the index after vq is stopped. */ if (!mvq->initialized) { - state->avail_index =3D mvq->avail_idx; + state->avail_index =3D mvq->used_idx; return 0; } =20 @@ -1452,7 +1454,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device = *vdev, u16 idx, struct vdpa mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n"); return err; } - state->avail_index =3D attr.available_index; + state->avail_index =3D attr.used_index; return 0; } =20 @@ -1532,16 +1534,6 @@ static void teardown_virtqueues(struct mlx5_vdpa_net= *ndev) } } =20 -static void clear_virtqueues(struct mlx5_vdpa_net *ndev) -{ - int i; - - for (i =3D ndev->mvdev.max_vqs - 1; i >=3D 0; i--) { - ndev->vqs[i].avail_idx =3D 0; - ndev->vqs[i].used_idx =3D 0; - } -} - /* TODO: cross-endian support */ static inline bool mlx5_vdpa_is_little_endian(struct mlx5_vdpa_dev *mvdev) { @@ -1777,7 +1769,6 @@ static void mlx5_vdpa_set_status(struct vdpa_device *= vdev, u8 status) if (!status) { mlx5_vdpa_info(mvdev, "performing device reset\n"); teardown_driver(ndev); - clear_virtqueues(ndev); mlx5_vdpa_destroy_mr(&ndev->mvdev); ndev->mvdev.status =3D 0; ++mvdev->generation; --=20 2.29.2