From patchwork Thu Mar 2 18:18:57 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: 63515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4850wrd; Thu, 2 Mar 2023 10:29:17 -0800 (PST) X-Google-Smtp-Source: AK7set8IcM5c8kgcPn3ec/QLv0CXwqyKCzO8Jz/eokDns2xW8RMtSAFK6wmOO1+HzTaHQzFonxZS X-Received: by 2002:aa7:c481:0:b0:4c5:506d:52a2 with SMTP id m1-20020aa7c481000000b004c5506d52a2mr508658edq.25.1677781757732; Thu, 02 Mar 2023 10:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677781757; cv=none; d=google.com; s=arc-20160816; b=PGW25mnYleJZk27GsjB9PjUXjLaSNMVqVb7PXqpl5j00jO8VO+TGLJBQWx4w2KyGMx SHh33Bo+YNtPR66aKqkkVp1oHkhJPtoaWvZ6BIOJRMtpoeIPX5oLnndmFRSU5vEyvaOG 5kIKBhKu1eE4GMbp88egG+gocIrPx72ZgpEkPIPQhzHHQXWWt9G1nIR4hvQY6b4rs0Re s4+mGXx3P/Yw2ebNOe8Jfa3qKe4ymv5/LmxBcpzvxjQ5AvVMAQ7D8pNG5HYqOHfKW14l I18E1AMCixzBDV0nFw4W62EGUDVJ7pt5jAoMnE7VVjqCNtw39e6R8QeqXLNAAs4+GwCZ QbqA== 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=zNb9G022CJaLitYkR75dWvbL+tzU0OIY68F+4x3NvFU=; b=GM8L9oAOQJLTp8jDPxzX5BOQ2RXvVMj+N7eTWbx8MsUfJRVnqGr6O6iCwhHXHsUqLE CQO6SA/5+eTdpBDMANev/4YYNF1T0bZi6IYbk4M/2uBx55e7xwQfjjgEBMfTACcrqVCE jrM47V95Nc7uHavR5Ag4YPlJl0Wtz9bZ6MtAP7avPklOK3Vi5RverF3iqbqbn8TYtTJo Pf4Yh4ydH7Hw6E3wCevbyfLiKQryYWBYFh7CFbXtPyKMTLLH4byITTuRIonBs+TtQK+0 27laBdvoLbiIuzfahJG2gSPrLQD6k++SLEKX55Z6A4CILUqLgbrbs0iMEb4NDElwkiFD PXkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=foLBudfe; 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 n23-20020a05640206d700b004bf34252ffasi282255edy.603.2023.03.02.10.28.54; Thu, 02 Mar 2023 10:29:17 -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=foLBudfe; 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 S229705AbjCBSTw (ORCPT + 99 others); Thu, 2 Mar 2023 13:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjCBSTu (ORCPT ); Thu, 2 Mar 2023 13:19:50 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 103F834018 for ; Thu, 2 Mar 2023 10:19:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677781146; 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=zNb9G022CJaLitYkR75dWvbL+tzU0OIY68F+4x3NvFU=; b=foLBudfeKdoVNlduyV5w5zzW8Xxj70ePneJF4n3gYhsjCPOwylmK0XM3BuNaeByizyEufb /NRr4OUve9nfYayFVz5zyFdYMj2e4kWD7+WpFoVNO/jlPuiYzfdhQteQPi6Dm/LPTHDzJx 6s/BfjnhJWRYP+KcYW1/1e6w+m2kki0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-Y4RiKZHtNR-CrzCYnLW_HA-1; Thu, 02 Mar 2023 13:19:02 -0500 X-MC-Unique: Y4RiKZHtNR-CrzCYnLW_HA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E4AD101A52E; Thu, 2 Mar 2023 18:19:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F33A51FF; Thu, 2 Mar 2023 18:18:59 +0000 (UTC) From: =?utf-8?q?Eugenio_P=C3=A9rez?= To: mst@redhat.com Cc: lulu@redhat.com, parav@nvidia.com, longpeng2@huawei.com, Zhu Lingshan , Gautam Dawar , alvaro.karsz@solid-run.com, Laurent Vivier , sgarzare@redhat.com, si-wei.liu@oracle.com, Eli Cohen , linux-kernel@vger.kernel.org, leiyang@redhat.com, virtualization@lists.linux-foundation.org Subject: [PATCH v3] vdpa_sim: set last_used_idx as last_avail_idx in vdpasim_queue_ready Date: Thu, 2 Mar 2023 19:18:57 +0100 Message-Id: <20230302181857.925374-1-eperezma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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?1759281684245035866?= X-GMAIL-MSGID: =?utf-8?q?1759281684245035866?= 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 0e84f918fac8 ("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") Reviewed-by: Stefano Garzarella 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. v3: * Fix commit id in the patch message. * Add in code comment following the patch message about why it is done this way. v2: Actually update last_used_idx only at vdpasim_queue_ready. Note that commit id present in the patch text is not in master but in git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git. [1] https://lkml.org/lkml/2023/1/18/1041 --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 6a0a65814626..eea23c630f7c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -68,6 +68,17 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx) (uintptr_t)vq->device_addr); vq->vring.last_avail_idx = last_avail_idx; + + /* + * 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. + */ + vq->vring.last_used_idx = last_avail_idx; vq->vring.notify = vdpasim_vq_notify; }