From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D1A4C433FE for ; Wed, 2 Mar 2022 14:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243239AbiCBOvd (ORCPT ); Wed, 2 Mar 2022 09:51:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232191AbiCBOvb (ORCPT ); Wed, 2 Mar 2022 09:51:31 -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 ESMTP id F2A0B2B180 for ; Wed, 2 Mar 2022 06:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646232647; 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: in-reply-to:in-reply-to:references:references; bh=vyTbPbzLV6BhTjCf6yQIefb7DNZSD/rDYL7+DnSGw1A=; b=YZLdAd6V85Awe2c9qQHQLoXrERYxZDfGWwTNM3i5oQrNoMqghiPBn/DsnGvvVnWTz20qZM iYhffMhkhZ+yM7Je9hKmZEgRwhv0Ey52RvASc9SlKNGDP1+RRRd5jyxcVDTLoxHpxasHip wFLfl0hTxzAKP/M0UncNHd4VoUdluBo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-379-m-ShuNnXNzKV-A8MX03HHA-1; Wed, 02 Mar 2022 09:50:43 -0500 X-MC-Unique: m-ShuNnXNzKV-A8MX03HHA-1 Received: by mail-wr1-f71.google.com with SMTP id p9-20020adf9589000000b001e333885ac1so716549wrp.10 for ; Wed, 02 Mar 2022 06:50:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vyTbPbzLV6BhTjCf6yQIefb7DNZSD/rDYL7+DnSGw1A=; b=rIGUgwL2g+96jnim0MYPtGpHn1EWsFIZUIPXkkVczmnDoEpt6EFufhAH+kdoGCQs31 2asDORAq8CO2yke36HwvU06Bd4dxyQ9MrjYsFKeZxOqgRYB61C9lMSA2YIGS91YKC9E2 gGjwaKm7sVf6J6AatgpzvCtRJ9gH8+ZjqLn7lKnEuAX+N/dMgZ9lhKCqz5k0xDSk41QH USXlEl/8yB7wIkudMQ6IsMV0j6UVODni/GSQOfNAEhftKrw9X7ZKNgNTYl6+vpexteS6 8RPMJ3A0LJkHlpzhJa20mZtDSVp1oUQloR1Si41efYi44cJatPrYZ97u2fZPB7UiACdQ qB2Q== X-Gm-Message-State: AOAM533iptfiFoZswrlcG1RSBZeR944pIqFju3OTRmPqTpQvgBLkqmeZ phd05hl43z9vAVZlhFSoJbhce074R+t7zqZLYQSYmN5EEOs1ib/yKs/wVuZYmU1E0yeN/vxA9CC 5pEkyNb2xUZv+t8BeCxJPB8pj X-Received: by 2002:adf:f550:0:b0:1f0:2381:ac2c with SMTP id j16-20020adff550000000b001f02381ac2cmr4323635wrp.189.1646232642005; Wed, 02 Mar 2022 06:50:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQNu/fXS905mfblMrRA5G2rPob+EQ5Bu1JcHzO8Z63AfxXQlVwQA2iUhIru+dm9U5yRai4qA== X-Received: by 2002:adf:f550:0:b0:1f0:2381:ac2c with SMTP id j16-20020adff550000000b001f02381ac2cmr4323627wrp.189.1646232641759; Wed, 02 Mar 2022 06:50:41 -0800 (PST) Received: from redhat.com ([2a10:8006:355c:0:48d6:b937:2fb9:b7de]) by smtp.gmail.com with ESMTPSA id k19-20020adfd233000000b001f0358e47bdsm1971249wrh.50.2022.03.02.06.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 06:50:41 -0800 (PST) Date: Wed, 2 Mar 2022 09:50:38 -0500 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: Lee Jones , jasowang@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, stable@vger.kernel.org, syzbot+adc3cb32385586bec859@syzkaller.appspotmail.com Subject: Re: [PATCH 1/1] vhost: Protect the virtqueue from being cleared whilst still in use Message-ID: <20220302094946-mutt-send-email-mst@kernel.org> References: <20220302075421.2131221-1-lee.jones@linaro.org> <20220302093446.pjq3djoqi434ehz4@sgarzare-redhat> <20220302083413-mutt-send-email-mst@kernel.org> <20220302141121.sohhkhtiiaydlv47@sgarzare-redhat> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220302141121.sohhkhtiiaydlv47@sgarzare-redhat> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 02, 2022 at 03:11:21PM +0100, Stefano Garzarella wrote: > On Wed, Mar 02, 2022 at 08:35:08AM -0500, Michael S. Tsirkin wrote: > > On Wed, Mar 02, 2022 at 10:34:46AM +0100, Stefano Garzarella wrote: > > > On Wed, Mar 02, 2022 at 07:54:21AM +0000, Lee Jones wrote: > > > > vhost_vsock_handle_tx_kick() already holds the mutex during its call > > > > to vhost_get_vq_desc(). All we have to do is take the same lock > > > > during virtqueue clean-up and we mitigate the reported issues. > > > > > > > > Link: https://syzkaller.appspot.com/bug?extid=279432d30d825e63ba00 > > > > > > This issue is similar to [1] that should be already fixed upstream by [2]. > > > > > > However I think this patch would have prevented some issues, because > > > vhost_vq_reset() sets vq->private to NULL, preventing the worker from > > > running. > > > > > > Anyway I think that when we enter in vhost_dev_cleanup() the worker should > > > be already stopped, so it shouldn't be necessary to take the mutex. But in > > > order to prevent future issues maybe it's better to take them, so: > > > > > > Reviewed-by: Stefano Garzarella > > > > > > [1] > > > https://syzkaller.appspot.com/bug?id=993d8b5e64393ed9e6a70f9ae4de0119c605a822 > > > [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a58da53ffd70294ebea8ecd0eb45fd0d74add9f9 > > > > > > Right. I want to queue this but I would like to get a warning > > so we can detect issues like [2] before they cause more issues. > > I agree, what about moving the warning that we already have higher up, right > at the beginning of the function? > > I mean something like this: > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 59edb5a1ffe2..1721ff3f18c0 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -692,6 +692,8 @@ void vhost_dev_cleanup(struct vhost_dev *dev) > { > int i; > + WARN_ON(!llist_empty(&dev->work_list)); > + > for (i = 0; i < dev->nvqs; ++i) { > if (dev->vqs[i]->error_ctx) > eventfd_ctx_put(dev->vqs[i]->error_ctx); > @@ -712,7 +714,6 @@ void vhost_dev_cleanup(struct vhost_dev *dev) > dev->iotlb = NULL; > vhost_clear_msg(dev); > wake_up_interruptible_poll(&dev->wait, EPOLLIN | EPOLLRDNORM); > - WARN_ON(!llist_empty(&dev->work_list)); > if (dev->worker) { > kthread_stop(dev->worker); > dev->worker = NULL; > Hmm I'm not sure why it matters. > And maybe we can also check vq->private and warn in the loop, because the > work_list may be empty if the device is doing nothing. > > Thanks, > Stefano