From patchwork Wed Jun 6 13:24:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10450235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C540160467 for ; Wed, 6 Jun 2018 13:27:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B539428F64 for ; Wed, 6 Jun 2018 13:27:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A929328F69; Wed, 6 Jun 2018 13:27:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4DA6228F64 for ; Wed, 6 Jun 2018 13:27:28 +0000 (UTC) Received: from localhost ([::1]:52437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQYTH-0006SG-8J for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jun 2018 09:27:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQYRp-0005rf-PS for qemu-devel@nongnu.org; Wed, 06 Jun 2018 09:25:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQYRm-0005hN-LC for qemu-devel@nongnu.org; Wed, 06 Jun 2018 09:25:57 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:35384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fQYRm-0005go-El for qemu-devel@nongnu.org; Wed, 06 Jun 2018 09:25:54 -0400 Received: by mail-pf0-x241.google.com with SMTP id c22-v6so2728140pfi.2 for ; Wed, 06 Jun 2018 06:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Xrh/eMR65kieVcffT7KHEcpzlmy5GAyaDE5BU3lVavw=; b=LakTVBAwaRJ7RG03v7pM4bOgGTJMsAM8cPpe3LAgWkQuoFLRPXPpJVsyT3l9nOwCYl Rb26jsWH95bY5OTxTyHzFtVmMxyIXiLPKSProVI6ZGVzSxZsWEDlk3TRc0zbnjjRUJI/ Ri4C7ix7fKtcRArQIsphLh2wgt0uZ3zNnl+670d/YE8WLVKUpR5/T8YAgRRaGBxGf6Xl nVcf8ObQ8IrR2fu5VtG5lBB6rrAsuYCx/z94IaZpmdkpHiOh4pKXGK+eLaR4SngjMYXR j7lEQaJpOSC2k8+I8h3ur11u2L41T0zSUisfRiZNPu5I+9S3vj9iaCwE8Wbv2igpynrI AG4A== 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; bh=Xrh/eMR65kieVcffT7KHEcpzlmy5GAyaDE5BU3lVavw=; b=kGWnp+oKuABlu24p/RI17lCTlTX+L2m+apFfduCWVgnZpCxmXxIYemqEVNbpNRi63E zagApdVBRh2Jto6wT0DLSTaEB06JFdPT2wVbItnXkOgz4BZJNxmu67BKYSDF4K6cspOY G62WprphX+y9faiAO1sBX5c/Fae36nRf5vGWp4CtkMgd9iLUAn8RN23ANZKnhj2IuOfS OlwShBmWlHqR3ydm7twjW3ff7b7yShEYYbQg4tIM8wQksbgcmV3//eCvLdw7K1NkNccf aoItiuDDeBiVSwmdVH9ucbiBH37LtrxuveFeE7xajXnptFqin9MwPVwdWolfUY0dYB5m ZtTQ== X-Gm-Message-State: APt69E1SyfxsT7u+rDJDMAh3Zi7mUoe3sEXbPVE7KtRwXkC6mqDSaUn5 hVAKL2DKKgUpLMfERcLMI+I= X-Google-Smtp-Source: ADUXVKKsh3yGiSibFYQK9cCWDvl1RKSZewRz5ZAMGpeIzfdorPSXhyLdrcZzciqx39TLPXpJbBzk4w== X-Received: by 2002:a63:9a52:: with SMTP id e18-v6mr2574982pgo.188.1528291553476; Wed, 06 Jun 2018 06:25:53 -0700 (PDT) Received: from localhost ([61.171.230.176]) by smtp.gmail.com with ESMTPSA id a14-v6sm15336629pgv.4.2018.06.06.06.25.52 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 06 Jun 2018 06:25:52 -0700 (PDT) From: Yongji Xie X-Google-Original-From: Yongji Xie To: mst@redhat.com, stefanha@redhat.com, changpeng.liu@intel.com Date: Wed, 6 Jun 2018 21:24:48 +0800 Message-Id: <1528291488-2586-1-git-send-email-xieyongji@baidu.com> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v2] vhost-user-blk: start vhost when guest kicks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elohimes@gmail.com, nixun@baidu.com, qemu-devel@nongnu.org, chaiwen@baidu.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early") kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This violates the virtio spec. But virtio 1.0 transitional devices support this behaviour. So we should start vhost when guest kicks in this case. Signed-off-by: Yongji Xie Signed-off-by: Chai Wen Signed-off-by: Ni Xun Reviewed-by: Stefan Hajnoczi --- hw/block/vhost-user-blk.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index d755223..1451940 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -217,7 +217,32 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev, static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { + VHostUserBlk *s = VHOST_USER_BLK(vdev); + int i; + + if (!(virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && + !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1))) { + return; + } + + if (s->dev.started) { + return; + } + + /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start + * vhost here instead of waiting for .set_status(). + */ + vhost_user_blk_start(vdev); + /* Kick right away to begin processing requests already in vring */ + for (i = 0; i < s->dev.nvqs; i++) { + VirtQueue *kick_vq = virtio_get_queue(vdev, i); + + if (!virtio_queue_get_desc_addr(vdev, i)) { + continue; + } + event_notifier_set(virtio_queue_get_host_notifier(kick_vq)); + } } static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)