From nobody Sun May 5 06:08:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1555421055; cv=none; d=zoho.com; s=zohoarc; b=SSqe8tpZkZzdjHKAeTewQtYP8DkW4dcCapr4Z1WkDa6fy4DDKIQgRrXh0TX26BO3sC/s4RcaU8T2rQZn0z0mMh4k2Z/MTaO+icTRlZsC3poNcJxEKoiiTOhgYrUdEl1G5pgxZmFibrMeKwIIVEJ+mGth07610v6tvVcVHvQhvPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555421055; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=e2JtH7krSyKhhuS6XhE+iZmIweMnN9Gq6tcyXtUXsMg=; b=CVc7yxmrL5+OykpFaXou2yhjKYdbQb1d1rM26crBkP2i4bFodQlQOnlCkaRuDE2p0MbflcHrBnXer0vRIx/DJz2oJAPcW0x6A8oHtvopna4V2DGodz6LIMd7T54dQxHf7N/SqbaXwDyVYPb1AKw7QYLT1HXUXLaryWJ3yxKlSCk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555421055473616.7369666585498; Tue, 16 Apr 2019 06:24:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:36733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGO4H-0008NC-Es for importer@patchew.org; Tue, 16 Apr 2019 09:24:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGNga-00064O-7E for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGNgY-00022c-3s for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:40 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:37994) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGNgX-00021t-Pf for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:38 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCxTmU055626; Tue, 16 Apr 2019 12:59:36 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2rusnetf76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 12:59:36 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCwAUL185417; Tue, 16 Apr 2019 12:59:35 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2rwe79s8ag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 12:59:35 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x3GCxXGX020497; Tue, 16 Apr 2019 12:59:34 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 Apr 2019 05:59:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=/f6Vn0qOWjqIheyoMHr5MtfUPS8Upb1rVgZ3o5Gcs3s=; b=IxTpEU+1oXtFTLCfD7pqlb4x7sT+xoRA+0kK62O2EZ84BetkPkosnMK2Gu0w8EKI5QyC 7w47ffzqdJEDOgSJ7wp/XAqyNXUTk9tXKUNOeq2YtMU4P0NtjaYqiOjii3IGCWOZCQgs Cz1IIXVHD8cLkxuzQAFpBwywhaQSA4KsKmdysYV3qzQ9Xb2UAq7/nJi7D0awK6yWJSGg qGrpUfj1guRYBF6OL8ICdeMrn1OH9BEiYO9wpZr8/7TpB6O/1uxRkKxxk4+5OPah+ZB5 UZE/xf7ECOYSa3aiNu3CrB/MX40V6dpB8oH8fDYhnbKrM7uYNCunnQWXZGaGfqpsqZ2/ 9A== From: Liran Alon To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2019 15:59:10 +0300 Message-Id: <20190416125912.44001-2-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416125912.44001-1-liran.alon@oracle.com> References: <20190416125912.44001-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id x3GCxTmU055626 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 1/3] vhost-scsi: The vhost backend should be stopped when the VM is not running 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: ehabkost@redhat.com, stefanha@gmail.com, mtosatti@redhat.com, bijan.mottahedeh@oracle.com, Liran Alon , pbonzini@redhat.com, nir.weiner@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Nir Weiner vhost-scsi doesn=E2=80=99t takes into account whether the VM is running or = not in order to decide if it should start/stop vhost backend. This would lead to vhost backend still being active when VM's RunState suddenly change to stopped. An example of when this issue is encountered is when Live-Migration Pre-Copy phase completes. As in this case, VM state will be changed to stopped (while vhost backend is still active), which will result in virtio_vmstate_change() -> virtio_set_status() -> vhost_scsi_set_status() executed but vhost_scsi_set_status() will just return without stopping vhost backend. To handle this, change code to consider that vhost processing should be stopped when VM is not running. Similar to how it is done in vhost-vsock device at vhost_vsock_set_status(). Fixes: 5e9be92d7752 ("vhost-scsi: new device supporting the tcm_vhost Linux= kernel module=E2=80=9D) Reviewed-by: Bijan Mottahedeh Reviewed-by: Liran Alon Signed-off-by: Nir Weiner Reviewed-by: Stefan Hajnoczi --- hw/scsi/vhost-scsi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 61e2e57da9d5..ca42cff1b907 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -114,6 +114,10 @@ static void vhost_scsi_set_status(VirtIODevice *vdev, = uint8_t val) VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(s); bool start =3D (val & VIRTIO_CONFIG_S_DRIVER_OK); =20 + if (!vdev->vm_running) { + start =3D false; + } + if (vsc->dev.started =3D=3D start) { return; } --=20 2.20.1 From nobody Sun May 5 06:08:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1555420972; cv=none; d=zoho.com; s=zohoarc; b=V0slW5ka8ozvDCaB8UXDCruhw91+qSF9hz2Bb5I+JnbwtBOwvOHodRKnopQ8CV/xf6eQLuRgCgps74X37BG6NLeRMsmdx+BBdbw4JwffW1HdnkTo++fzOR3f1XXrG8vkS5+lK/5myjbpdeaUApNxqva/x5+WAo6761XtG1XZ7UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555420972; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PEaRySssFHES3H8no9BPl//7xT8rmTgGrD5Zwuhz53M=; b=YJqNcX3bdUYxnnf9ktAmKJoqFfYJXdzw+y9jss3zxPMyoCikAnq4P4/4tYyTiR9OmIk9YooKaXkehMNtzXbi2Op+fs5ACitGRQQOjQlXA1EwiVkYkNTPdkGPhutw4g9eC8DjI8gX6l/TVs5Zvke1yhxJn0EGY2IP4V5tYVLnH7s= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555420972682577.5983224709346; Tue, 16 Apr 2019 06:22:52 -0700 (PDT) Received: from localhost ([127.0.0.1]:36693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGO2v-0007JO-M2 for importer@patchew.org; Tue, 16 Apr 2019 09:22:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGNgb-00065O-B4 for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGNga-00024K-Ce for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:41 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:43166) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGNga-00023G-1f for qemu-devel@nongnu.org; Tue, 16 Apr 2019 08:59:40 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCxWxE038905; Tue, 16 Apr 2019 12:59:38 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2rvwk3mk3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 12:59:38 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCw9qu185364; Tue, 16 Apr 2019 12:59:37 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2rwe79s8b0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 12:59:37 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3GCxapL007010; Tue, 16 Apr 2019 12:59:36 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 Apr 2019 05:59:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=+iZ36eJcL1K2wKNm+8unx5+IkEBFjcTbyMt7Zw3EHHM=; b=S14w4/N8yZtaSScb2hX6q7ZzHJYODIhDIAjvB6Z+m5Y78qMr5l+NK/KM5dd0sf2+pJ5r fxkGhiJtCRtN9b0W/vTeRDhiUAgvFoaElu1nBPjCvi05uz+EAGkPosSEh8Z8Vs3SlcHV W1gmvcxpAyrin5Yq81UDnLuLy3xSF1QzvhZoIP1EzVIf3yIEOrPOq2eydi7zGjPBzMtB Q80iAPfDLMcLToAX1UrsfN19wubVzKrNO7u39NxhdBdbwvhyWhrW3wV63TJDCrOw8ikX iXzyMsqeTl0CCdododEZib695mFLP57E6iYSx0ssgvRgpCT4h5ZJceS74jFisMmMadvE 8w== From: Liran Alon To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2019 15:59:11 +0300 Message-Id: <20190416125912.44001-3-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416125912.44001-1-liran.alon@oracle.com> References: <20190416125912.44001-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by userp2130.oracle.com id x3GCxWxE038905 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v2 2/3] vhost-scsi: Add VMState descriptor 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: ehabkost@redhat.com, stefanha@gmail.com, mtosatti@redhat.com, bijan.mottahedeh@oracle.com, Liran Alon , pbonzini@redhat.com, nir.weiner@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Nir Weiner As preparation of enabling migration of vhost-scsi device, define it=E2=80=99s VMState. Note, we keep the convention of verifying in the pre_save() method that the vhost backend must be stopped before attempting to save the device state. Similar to how it is done for vhost-vsock. Reviewed-by: Bijan Mottahedeh Reviewed-by: Liran Alon Signed-off-by: Nir Weiner Reviewed-by: Stefan Hajnoczi --- hw/scsi/vhost-scsi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index ca42cff1b907..eb0cf9e1312f 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -139,6 +139,28 @@ static void vhost_dummy_handle_output(VirtIODevice *vd= ev, VirtQueue *vq) { } =20 +static int vhost_scsi_pre_save(void *opaque) +{ + VHostSCSICommon *vsc =3D opaque; + + /* At this point, backend must be stopped, otherwise + * it might keep writing to memory. */ + assert(!vsc->dev.started); + + return 0; +} + +static const VMStateDescription vmstate_virtio_vhost_scsi =3D { + .name =3D "virtio-vhost_scsi", + .minimum_version_id =3D 1, + .version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_VIRTIO_DEVICE, + VMSTATE_END_OF_LIST() + }, + .pre_save =3D vhost_scsi_pre_save, +}; + static void vhost_scsi_realize(DeviceState *dev, Error **errp) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(dev); @@ -256,6 +278,7 @@ static void vhost_scsi_class_init(ObjectClass *klass, v= oid *data) FWPathProviderClass *fwc =3D FW_PATH_PROVIDER_CLASS(klass); =20 dc->props =3D vhost_scsi_properties; + dc->vmsd =3D &vmstate_virtio_vhost_scsi; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); vdc->realize =3D vhost_scsi_realize; vdc->unrealize =3D vhost_scsi_unrealize; --=20 2.20.1 From nobody Sun May 5 06:08:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1555421118; cv=none; d=zoho.com; s=zohoarc; b=FzqlsubKkEMVfQEyJ1UAnxhmDoRYKEq5TuNBnR1JSh3qAyajVdcGTYIF1ZCSBcJNWLIckMh+LAnf9Fkye530ZK80kn8jWakbxMAdUTNwLXSOhBjVrr/4SYrp15PKVaRoX8FWV10eIqbiIZgY6oMQqminHdeAAYmSzEQPj9/4BeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555421118; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=nzQCwehGS0m8OEqyrIxYTzNMI4+W8+4hirRq2xRSAbo=; b=KF3rPt7mo2r8csVuDNmuXDCUjUh/3fSD5+Lkyjzex+Sl5+GAQoUjQPDvhGbxE61HPb5OzJGu7YMZkSWLpvCINDTulYpTkPCCmRzq6VlTQ+eU72NrVgWs8hVXhxfxbR+nJQwbsYBcaA08oKhslsurofLZZj7J4bByTyVRzysYu+A= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555421118314378.48649801289855; Tue, 16 Apr 2019 06:25:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:36737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGO5K-0000mA-RL for importer@patchew.org; Tue, 16 Apr 2019 09:25:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGNic-0007pQ-Og for qemu-devel@nongnu.org; Tue, 16 Apr 2019 09:01:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGNia-0003WY-Tq for qemu-devel@nongnu.org; Tue, 16 Apr 2019 09:01:46 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGNiY-0003VZ-Vh for qemu-devel@nongnu.org; Tue, 16 Apr 2019 09:01:43 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCxRQa038580; Tue, 16 Apr 2019 13:01:41 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2rvwk3mkj6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 13:01:39 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3GCwNwq154506; Tue, 16 Apr 2019 12:59:39 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2rubq6ad5m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Apr 2019 12:59:38 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3GCxcIX007021; Tue, 16 Apr 2019 12:59:38 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 Apr 2019 05:59:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=nzQCwehGS0m8OEqyrIxYTzNMI4+W8+4hirRq2xRSAbo=; b=R16DFiKdZ3la1n0XgcEu++bE329aIK4P4gNNgHez4yDp3tg3FvaRltQJGEIILw7HLndH D1ndWeWG4cpLvFJHRf7YFTklz/m1+/y63HwSpl9bqIdUCrusnlQmywjrnXPyGZmZt5mh 6uHnlxT0JSwbDZU4w53jvV+/4v8nfPIfQXKhB88UhbsarTPegqGndH4wsd50Zg8mLhHi p1q7kJc3IAJW2aA0LszQsYFp5U0MhCJeBiqVobnlcHyybJhsWYX2nyQ2KzqBqbhzWrg3 8W/ITfSxDq/VfvA3EJ533YohtRvisohOEqQN9ebddOEbhCxwSU1C+uR2SzBppCFUciN4 OA== From: Liran Alon To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2019 15:59:12 +0300 Message-Id: <20190416125912.44001-4-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416125912.44001-1-liran.alon@oracle.com> References: <20190416125912.44001-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9228 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904160088 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v2 3/3] vhost-scsi: Allow user to enable migration 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: ehabkost@redhat.com, stefanha@gmail.com, mtosatti@redhat.com, bijan.mottahedeh@oracle.com, Liran Alon , pbonzini@redhat.com, nir.weiner@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In order to perform a valid migration of a vhost-scsi device, the following requirements must be met: (1) The virtio-scsi device state needs to be saved & loaded. (2) The vhost backend must be stopped before virtio-scsi device state is saved: (2.1) Sync vhost backend state to virtio-scsi device state. (2.2) No further I/O requests are made by vhost backend to target SCSI device. (2.3) No further guest memory access takes place after VM is stopped. (3) Requests in-flight to target SCSI device are completed before migration handover. (4) Target SCSI device state needs to be saved & loaded into the destination host target SCSI device. Previous commit ("vhost-scsi: Add VMState descriptor") add support to save & load the device state using VMState. This meets requirement (1). When VM is stopped by migration thread (On Pre-Copy complete), the following code path is executed: migration_completion() -> vm_stop_force_state() -> vm_stop() -> do_vm_stop(). do_vm_stop() calls first pause_all_vcpus() which pause all guest vCPUs and then call vm_state_notify(). In case of vhost-scsi device, this will lead to the following code path to be executed: vm_state_notify() -> virtio_vmstate_change() -> virtio_set_status() -> vhost_scsi_set_status() -> vhost_scsi_stop(). vhost_scsi_stop() then calls vhost_scsi_clear_endpoint() and vhost_scsi_common_stop(). vhost_scsi_clear_endpoint() sends VHOST_SCSI_CLEAR_ENDPOINT ioctl to vhost backend which will reach kernel's vhost_scsi_clear_endpoint() which process all pending I/O requests and wait for them to complete (vhost_scsi_flush()). This meets requirement (3). vhost_scsi_common_stop() will stop the vhost backend. As part of this stop, dirty-bitmap is synced and vhost backend state is synced with virtio-scsi device state. As at this point guest vCPUs are already paused, this meets requirement (2). At this point we are left with requirement (4) which is target SCSI device specific and therefore cannot be done by QEMU. Which is the main reason why vhost-scsi adds a migration blocker. However, as this can be handled either by an external orchestrator or by using shared-storage (i.e. iSCSI), there is no reason to limit the orchestrator from being able to explictly specify it wish to enable migration even when VM have a vhost-scsi device. Considering all the above, this commit allows orchestrator to explictly specify that it is responsbile for taking care of requirement (4) and therefore vhost-scsi should not add a migration blocker. Reviewed-by: Nir Weiner Reviewed-by: Bijan Mottahedeh Signed-off-by: Liran Alon Reviewed-by: Stefan Hajnoczi --- hw/scsi/vhost-scsi.c | 30 ++++++++++++++++++--------- include/hw/virtio/vhost-scsi-common.h | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index eb0cf9e1312f..6b01accf61ad 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -199,13 +199,18 @@ static void vhost_scsi_realize(DeviceState *dev, Erro= r **errp) goto close_fd; } =20 - error_setg(&vsc->migration_blocker, - "vhost-scsi does not support migration"); - migrate_add_blocker(vsc->migration_blocker, &err); - if (err) { - error_propagate(errp, err); - error_free(vsc->migration_blocker); - goto close_fd; + if (!vsc->migratable) { + error_setg(&vsc->migration_blocker, + "vhost-scsi does not support migration in all cases. " + "When external environment supports it (Orchestrator migra= tes " + "target SCSI device state or use shared storage over netwo= rk), " + "set 'migratable' property to true to enable migration."); + migrate_add_blocker(vsc->migration_blocker, &err); + if (err) { + error_propagate(errp, err); + error_free(vsc->migration_blocker); + goto close_fd; + } } =20 vsc->dev.nvqs =3D VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; @@ -230,7 +235,9 @@ static void vhost_scsi_realize(DeviceState *dev, Error = **errp) return; =20 free_vqs: - migrate_del_blocker(vsc->migration_blocker); + if (!vsc->migratable) { + migrate_del_blocker(vsc->migration_blocker); + } g_free(vsc->dev.vqs); close_fd: close(vhostfd); @@ -243,8 +250,10 @@ static void vhost_scsi_unrealize(DeviceState *dev, Err= or **errp) VHostSCSICommon *vsc =3D VHOST_SCSI_COMMON(dev); struct vhost_virtqueue *vqs =3D vsc->dev.vqs; =20 - migrate_del_blocker(vsc->migration_blocker); - error_free(vsc->migration_blocker); + if (!vsc->migratable) { + migrate_del_blocker(vsc->migration_blocker); + error_free(vsc->migration_blocker); + } =20 /* This will stop vhost backend. */ vhost_scsi_set_status(vdev, 0); @@ -268,6 +277,7 @@ static Property vhost_scsi_properties[] =3D { DEFINE_PROP_BIT64("t10_pi", VHostSCSICommon, host_features, VIRTIO_SCSI_F_T10_PI, false), + DEFINE_PROP_BOOL("migratable", VHostSCSICommon, migratable, false), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhos= t-scsi-common.h index 57fb1d87b51d..4eab767ee89f 100644 --- a/include/hw/virtio/vhost-scsi-common.h +++ b/include/hw/virtio/vhost-scsi-common.h @@ -36,6 +36,7 @@ typedef struct VHostSCSICommon { int target; int lun; uint64_t host_features; + bool migratable; } VHostSCSICommon; =20 int vhost_scsi_common_start(VHostSCSICommon *vsc); --=20 2.20.1