From patchwork Fri Feb 3 14:07:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eugenio Perez Martin X-Patchwork-Id: 52525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp863475wrn; Fri, 3 Feb 2023 06:18:09 -0800 (PST) X-Google-Smtp-Source: AK7set99iH2BOdC/fAjaWWESS0xCyYPZLGsARoYX76zu9okDHo7Ab92bqIfKNoobfOHFuXWzcNHJ X-Received: by 2002:aa7:d8d5:0:b0:499:b3db:6aa3 with SMTP id k21-20020aa7d8d5000000b00499b3db6aa3mr10687143eds.1.1675433889807; Fri, 03 Feb 2023 06:18:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675433889; cv=none; d=google.com; s=arc-20160816; b=0sK2F63RmdSMHBmYerm4nXRubBEwMHkKYAz4I2bq3EPmFpPcfRiQTKP3UklqY/eE+H mdC4Ajff0XZ5sxg6FJv7akUMzPJ+mouDjDFw++oV26uJjAi/DdtYIJDP/sOsqZ3wu1at FX5QoGNsN9/6fMBKqm6y30HnpRW5KKKH8YrAR1sZbCjQqhCdDId43NDtafWhtY3xZ/Tq EoJEoRp8g8Y8fFlboblcfIT8kvvWixxP2jUHKqw46vukR/LiFe+XWfQfzvm0NcXUwjEN dKBgPHJAgA2hBLnThL26TufpIkRi+22/uarZ+whYyLymgXyZJW4gFeexSltMOBa7w4JD YNWQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zHARmurPMwXjzg/iTA25e7HTaItvenPwiLDL5I5d/cI=; b=jgx/21frnAScHNAlDd43a9ScSYXrmuK7WpC5xqan+snMDNxU1zv5wjPnWDsdReYrpL kR3MrSRuvH/8Z3gjYK6C020eP4AjhLBP5Attmh0DVLskEh0iJ9+yve4aGeJRFeh6dMVH IMYdsDnfUtkAi0rAq+MqWHx9Ze7Ir6MKGyMHNmFj2g6tPX5YL5BS3YYrRTnXk6qeDuqG VU89/2mmRV7P5i8QWra3NCDt/mNfq9oCW+8EfD5nO8ENscY3vgs6TkNRl779ZNrC7teQ 5Pa+Eow4Tr3++bSivWUaXpQgw6RbUzuvwQ0iaYD47Ks3Wt51wvMxSUMrCd585+bJQnX9 P/eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G0W+hZ72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020aa7df95000000b004a2224ff345si2657167edy.68.2023.02.03.06.17.42; Fri, 03 Feb 2023 06:18:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G0W+hZ72; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233663AbjBCOLc (ORCPT + 99 others); Fri, 3 Feb 2023 09:11:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233074AbjBCOLP (ORCPT ); Fri, 3 Feb 2023 09:11:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B96077FA19 for ; Fri, 3 Feb 2023 06:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675433265; 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: content-transfer-encoding:content-transfer-encoding; bh=zHARmurPMwXjzg/iTA25e7HTaItvenPwiLDL5I5d/cI=; b=G0W+hZ72GSPtyx85bOxn9EIVrqALCpsh+86I+0alRPAzwiliP9kDkmoNMIgID6x/qf/Zn8 MZHQu16L/zOF8WhFSv0+HFha9nV/z7Z655qRGf6/VLicn0MvPhN7Gqa3xFqFsTRVFa7DzK fqfX517qcIqASgnLd591FqVBpCMKAEM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-T2FMldIKNUGZ0W5Wv2uHVQ-1; Fri, 03 Feb 2023 09:07:43 -0500 X-MC-Unique: T2FMldIKNUGZ0W5Wv2uHVQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C8E1384798B; Fri, 3 Feb 2023 14:07:43 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.194.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 991F8404CD80; Fri, 3 Feb 2023 14:07:40 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: mst@redhat.com Cc: parav@nvidia.com, Eli Cohen , alvaro.karsz@solid-run.com, virtualization@lists.linux-foundation.org, Zhu Lingshan , lulu@redhat.com, Gautam Dawar , Laurent Vivier , linux-kernel@vger.kernel.org, si-wei.liu@oracle.com, sgarzare@redhat.com, leiyang@redhat.com, longpeng2@huawei.com Subject: [PATCH] vdpa_sim: set last_used_idx as last_avail_idx in vdpasim_queue_ready Date: Fri, 3 Feb 2023 15:07:36 +0100 Message-Id: <20230203140736.298564-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756819766620056874?= X-GMAIL-MSGID: =?utf-8?q?1756819766620056874?= Starting from an used_idx different than 0 is needed in use cases like virtual machine migration. Not doing so and letting the caller set an avail idx different than 0 causes destination device to try to use old buffers that source driver already recover and are not available anymore. Since vdpa_sim does not support receive inflight descriptors as a destination of a migration, let's set both avail_idx and used_idx the same at vq start. This is how vhost-user works in a VHOST_SET_VRING_BASE call. Although the simple fix is to set last_used_idx at vdpasim_set_vq_state, it would be reset at vdpasim_queue_ready. The last_avail_idx case is fixed with commit a09f493c ("vdpa_sim: not reset state in vdpasim_queue_ready"). Since the only option is to make it equal to last_avail_idx, adding the only change needed here. This was discovered and tested live migrating the vdpa_sim_net device. Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") Signed-off-by: Eugenio PĂ©rez --- Cherry-picked from patch 2/2 of the series [1]. Differences are: * Set the value of used_idx at vdpasim_queue_ready instead of fetching from the guest vring like vhost-kernel. Note that commit id present in the patch text is not in master but in maintainer branch. [1] https://lkml.org/lkml/2023/1/18/1041 --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 6a0a65814626..1b780e852359 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -68,6 +68,7 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx) (uintptr_t)vq->device_addr); vq->vring.last_avail_idx = last_avail_idx; + vq->vring.last_used_idx = last_avail_idx; vq->vring.notify = vdpasim_vq_notify; } @@ -282,6 +283,7 @@ static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx, spin_lock(&vdpasim->lock); vrh->last_avail_idx = state->split.avail_index; + vrh->last_used_idx = state->split.avail_index; spin_unlock(&vdpasim->lock); return 0;