From patchwork Thu Jul 29 07:34:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 12407955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B831C432BE for ; Thu, 29 Jul 2021 07:36:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 366B660F02 for ; Thu, 29 Jul 2021 07:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235001AbhG2Hga (ORCPT ); Thu, 29 Jul 2021 03:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235144AbhG2Hg1 (ORCPT ); Thu, 29 Jul 2021 03:36:27 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A7FC061796 for ; Thu, 29 Jul 2021 00:36:24 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d1so5984744pll.1 for ; Thu, 29 Jul 2021 00:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X6m+j6D+552UMlknTc2y1DCtUDa099ibFfLa+38yD24=; b=L80tblxe3wtC2HKOtW3renZJvhfc7GFjS2AU2pPB5D73BMRY5myTcL/dhJfOO3bvlS JtQFCV+tA2gcpqYeaWfCYxb8vXm8jpR+HCadwYr5BhMkmKpmvKsmqB9UTRdts+3U9SP1 z3jVWGbtk9bPdxyirEaJmHDRgjeE+wxcZ6RxbnBwB78D9RNokjcCtEUjS/aYPQ1BGtRp QFcakWAIabACF+QbfqNnv3dJP3ygewcdcN8WcuxnO6USt7gbjEjTS14J3bC3C+ylNHGA u7uQ2WlKZfweCuq8ckMwiJvO3WR69GUOvElFAR5Jm7PnsV3dbG2bnld3LKJUmpYFmdKv gQ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X6m+j6D+552UMlknTc2y1DCtUDa099ibFfLa+38yD24=; b=LsfD/BTsQdvhmtoTJl01gfv4FA/o2k4ZFisL4CXgKkS2hD3ikaZJ4ZK1mWvLsYa1rj Vo9EOSFJL2vlYGI1/T+qanWlfq9AKopeavertjGIbnUecZymKiOjczW6W2BFTTw1Vd8u 35f4/1Se3RPwt54v0TDx1TLjNdY2KJ7DtkNFuPrHGRYGrvGC6KeOuIjdf/GeFefFraMP 1Z0x+U4f7oYvC8ZXqtTe5wd/a/+yUGPdzDdzAWQPYJB7qznXUFA9zFZ9xbZSbr96+bHc K5mXQ9xsZeT9Bqq4qELCbLc0GWy8v8tH7fwPwOrOnNVcg4XBn6+sh0ywEPWSccV3Q5wh 3jhg== X-Gm-Message-State: AOAM532Oi+orAiIP13Dqq1+kB9Gjc+X2AcFpzvfLyDRbcwdinlU10LyU tD8Z8fmynouw4njlz1WBv2sz X-Google-Smtp-Source: ABdhPJzL8jwmp/JqGX6fQcP4HFWd79KgnMjKHajdRntovUI/IJhBr5JEygiGnHX6aUTtQVmAfW1PyA== X-Received: by 2002:a62:e90b:0:b029:30e:4530:8dca with SMTP id j11-20020a62e90b0000b029030e45308dcamr3799994pfh.17.1627544184395; Thu, 29 Jul 2021 00:36:24 -0700 (PDT) Received: from localhost ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id l10sm2164343pjg.11.2021.07.29.00.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 00:36:23 -0700 (PDT) From: Xie Yongji To: mst@redhat.com, jasowang@redhat.com, stefanha@redhat.com, sgarzare@redhat.com, parav@nvidia.com, hch@infradead.org, christian.brauner@canonical.com, rdunlap@infradead.org, willy@infradead.org, viro@zeniv.linux.org.uk, axboe@kernel.dk, bcrl@kvack.org, corbet@lwn.net, mika.penttila@nextfour.com, dan.carpenter@oracle.com, joro@8bytes.org, gregkh@linuxfoundation.org, zhe.he@windriver.com, xiaodong.liu@intel.com, joe@perches.com Cc: songmuchun@bytedance.com, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v10 05/17] vhost-vdpa: Fail the vhost_vdpa_set_status() on reset failure Date: Thu, 29 Jul 2021 15:34:51 +0800 Message-Id: <20210729073503.187-6-xieyongji@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210729073503.187-1-xieyongji@bytedance.com> References: <20210729073503.187-1-xieyongji@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Re-read the device status to ensure it's set to zero during resetting. Otherwise, fail the vhost_vdpa_set_status() after timeout. Signed-off-by: Xie Yongji --- drivers/vhost/vdpa.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index b07aa161f7ad..dd05c1e1133c 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -157,7 +157,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; u8 status, status_old; - int nvqs = v->nvqs; + int timeout = 0, nvqs = v->nvqs; u16 i; if (copy_from_user(&status, statusp, sizeof(status))) @@ -173,6 +173,15 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) return -EINVAL; ops->set_status(vdpa, status); + if (status == 0) { + while (ops->get_status(vdpa)) { + timeout += 20; + if (timeout > VDPA_RESET_TIMEOUT_MS) + return -EIO; + + msleep(20); + } + } if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK)) for (i = 0; i < nvqs; i++)