Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp244458rdb; Mon, 22 Jan 2024 19:51:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHy3sMtrTAJRXV0/Gkt8tOSR0LUaYPDJkn7TyoJ0KQ8t9oWaoplmaSfiWVvkTc7lEH62ZYE X-Received: by 2002:a17:90a:e547:b0:290:2d2:6a8 with SMTP id ei7-20020a17090ae54700b0029002d206a8mr2117705pjb.58.1705981860252; Mon, 22 Jan 2024 19:51:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705981860; cv=pass; d=google.com; s=arc-20160816; b=KZMNUv20xZEaIdkujPVGNuN2QtpuA110TidVs7MnxmRW/v+wLGawb4qr3CppxDy0rW QU6G1GlU04qg2gbkFlqoiBPPDUdSqvZdx3a+IERtNHg/qlblHL8AnrN5FuBdwZq9+KxY 6CPnGlkQ97eIos96Zit0qzuqrs0BTPfIG7ieEyy+/zpA/PYZk+lYkLlgfdzdr9JlWfeZ oD3s7BYDozfHTpGaiL6c7etNQwJ92fhAcpOrKJORSnvbVE4w1bCjjJelyDxxV0ZFwAp1 rG8FNyCSLhNMx2R/LS1LIO5mo6/z6X/l5fPVKtiw+O+TBfsN2HPanNPU0ppQh96mFHNt EKYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=YBJbKQX0OEBxeprRN+v16JluNv16fHJFSLP63KZqjwQ=; fh=buhX3izhRrzqMspBrXCzvYQRKjlTXTM41NrpNMbE0Dg=; b=Y2ThtERpGoRPWHn5nN/jH8Xh9qx1A31+GsE1XTu1ulWQ4fJFY5CA8JFnTzt8LVXNdo HHH1bYT6s2zB3xL/2UUaddOVA9qVWUOJTtL5DuFJX4+EsKPSEwwEoq3Xf22vsYEhQFK9 lTS8wJ5sdBLDk/NQCdhv32co+ON4Pc4MrqyWZ4WKLR1hHT0FRD2H24IUOb92nB0QaeaE 7i4cZwzmd6ZcGjQtwDLp+GbwH4WiMg9vkoRpV0k+m2JpzWccH1pW3RzBZzpL9sbVGgSZ j9dx9856VO9Sl22r3F5kUUKXcgxn8AGhuyHgyISCH5w/x80knpxvJe4ebOs84Bwoic52 74Cw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c16XrNBA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34675-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w13-20020a17090a8a0d00b0029079ae51c2si4433616pjn.147.2024.01.22.19.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:51:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34675-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c16XrNBA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34675-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 37ABEB24739 for ; Tue, 23 Jan 2024 03:28:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B59E185B; Tue, 23 Jan 2024 03:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c16XrNBA" Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADF8FA47; Tue, 23 Jan 2024 03:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980500; cv=none; b=D47dfTr5xYTXD4kLSB3nrH/32/fUbOFeCp4du2IqOKz/m9RcgToaL+drFcXwc1B+6kOpLkKwaXfPPj8Z4hfrVgAjyhrlc49NVTayCUs+p3/ado0vu2aD2A1NjklAsg0aBki1sa/TYTE1CdWRCrI/q9IJ0v0sCKHAnqKDCmbNark= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980500; c=relaxed/simple; bh=WYhT1KSTjcRFHQZ0dFY+HaX12W5Ope1cBkdGfWhmFm0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=pErhr9R7MUFLuevn3EIOOD9fi/Am54ZEJScUPiWIDHsP+mcEuUhj6/+B/KPcYkhsJO2rdlgaiqW35dAoFUzXE9+Ob0zUjekUrNt/7qJQsH30pFEj8RuThqMOk+Wl2kVaOvG6EbyM2rfcD+7pGV4rsQ6WoQD6aY1YnPRQjpt0ql0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c16XrNBA; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-50e741123acso4431501e87.0; Mon, 22 Jan 2024 19:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705980497; x=1706585297; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YBJbKQX0OEBxeprRN+v16JluNv16fHJFSLP63KZqjwQ=; b=c16XrNBAHTxbbk2F6TzvQhKsQ7p91SuUQh3d9nHSS4DIp1TNR0lPEe9Kh4DGi8726Y WKfDT/ngsw9mbyg6TMKrf1urJsnYQylYY+Fo5PB4XeJHjoqgSu9w11zn0Wo3joA9idLr eENRZx9JxnYadHJVLUyfwKpe1lBdqgR8oil1xcXshcoSTFwrfuUqgfOBKEjHlYoO+fI1 m/CvYBPB54iB/0BWxkFRGTPGQ44JpuHCChfzZzVyhiDm+mprp6dp84yHy5Z9iDkyHQ/M QGeb8UDIbaG/H6KppnJQG8KF5CNKpqC2lmuRettafpQ9Gve9Y2PXv6495tWUvf4TR40+ CEiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705980497; x=1706585297; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YBJbKQX0OEBxeprRN+v16JluNv16fHJFSLP63KZqjwQ=; b=B3LDRR96cc+KSrAFL1cLyzCPwdNU9Nw3Tn3WeprRUsOuOzNjGnv1RiumInbKfgJZl6 izbb3OI6NMCgWVQuDTcLCFSooC2gQfwqwujh2rsNS+AmHPpNDQ1vUPAxjvcXtj5/1LgS Re0UKQuGWrGWa2dVhw+PpfrjqIgZ5RaJ/d1kUzUmNFz7tUOOauKaiEh1LueUS7dLgVlM rlFfudeWNBwnii4moplUscc3AxdxNPMyk/BH1Y/CVtbWAeaWVpdZ0jDBlVFzTs7zQMsc gJb0Jg1iV785uBB0jsZsDsQr/a5d+xQV64GGQC5mWX86WuM3m/LSUKNQC7RMPGK0k6xM FiaQ== X-Gm-Message-State: AOJu0YysbZ+5L9Hw2kH5E88YFTgDQX19QSJ85V3O4vjLNG7LiZOhmya6 EfkwK3GrbCRUiGU/BVwt4qlauwdXnJPE+XgMOyWpacyyhOfbDsBYMPgqNn2G5coP9v9igz7iHo2 25dry+4SLw5GlxW4G5Z7CpZdc8ig= X-Received: by 2002:a05:6512:6d3:b0:50e:e0af:4efb with SMTP id u19-20020a05651206d300b0050ee0af4efbmr2673823lff.104.1705980496515; Mon, 22 Jan 2024 19:28:16 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122110722.690223-1-yi.sun@unisoc.com> <20240122110722.690223-3-yi.sun@unisoc.com> <20240122154255.GA389442@fedora> In-Reply-To: <20240122154255.GA389442@fedora> From: yi sun Date: Tue, 23 Jan 2024 11:27:40 +0800 Message-ID: Subject: Re: [PATCH 2/2] virtio-blk: Ensure no requests in virtqueues before deleting vqs. To: Stefan Hajnoczi Cc: Yi Sun , axboe@kernel.dk, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, pbonzini@redhat.com, virtualization@lists.linux.dev, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhiguo.niu@unisoc.com, hongyu.jin@unisoc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 22, 2024 at 11:43=E2=80=AFPM Stefan Hajnoczi wrote: > > On Mon, Jan 22, 2024 at 07:07:22PM +0800, Yi Sun wrote: > > Ensure no remaining requests in virtqueues before resetting vdev and > > deleting virtqueues. Otherwise these requests will never be completed. > > It may cause the system to become unresponsive. So it is better to plac= e > > blk_mq_quiesce_queue() in front of virtio_reset_device(). > > QEMU's virtio-blk device implementation completes all requests during > device reset. Most device implementations have to do the same to avoid > leaving dangling requests in flight across device reset. > > Which device implementation are you using and why is it safe for the > device is simply drop requests across device reset? > > Stefan Virtio-blk device implementation completes all requests during device reset= , but this can only ensure that the device has finished using virtqueue. We shoul= d also consider the driver's use of virtqueue. I caught such an example. Before del_vqs, the request had been processed by the device, but it had not been processed by the driver. Although I am using kernel5.4, I think this problem may also occur with the latest version of kernel. The debug code I added is as follows: virtblk_freeze() { vdev reset(); quiesce queue(); if (virtqueue->num_free !=3D 1024) //1024 is the init value. BUG_ON(1); vdev del_vqs(); } BUG_ON triggered the dump, the analysis is as follows: There is one request left in request_queue. crash_arm64> struct request ffffff81f0560000 | grep -e state -e __data_len __data_len =3D 20480, state =3D MQ_RQ_IN_FLIGHT, crash_arm64> vring_virtqueue.packed,last_used_idx,broken,vq 0xffffff8086f92= 900 | grep -e num -e used_wrap_counter -e last_used_idx -e broken -e num_free -e desc_state -e "desc =3D" num =3D 1024, desc =3D 0xffffff8085ff8000, used_wrap_counter =3D false, desc_state =3D 0xffffff8085610000, last_used_idx =3D 487, broken =3D false, num_free =3D 1017, Find desc based on last_used_idx. Through flags, we can know that the reque= st has been processed by the device, but it is still in flight state because it has not had time to run virtblk_done(). crash_arm> vring_packed_desc ffffff8085ff9e70 struct vring_packed_desc { addr =3D 10474619192, len =3D 20481, id =3D 667, flags =3D 2 } I'm using a closed source virtual machine, so I can't see the source code for it, but I'm guessing it's similar to qemu. After the device completes the request, we must also ensure that the driver= can complete the request in virtblk_done().