Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2780906rwb; Mon, 15 Aug 2022 11:14:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6aoaN7/8XtaedSE6i1qtImFVEQLbmVUjbMm38pr3yA7fVaO/4Nb0Dn3eTd9ryzaHizi5Ey X-Received: by 2002:a05:6402:4312:b0:43d:b9c0:65ee with SMTP id m18-20020a056402431200b0043db9c065eemr15665724edc.205.1660587287225; Mon, 15 Aug 2022 11:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660587287; cv=none; d=google.com; s=arc-20160816; b=CKVPhUCKHVdqco0s0BaJ4uOZ/97cquQz2aIiDI5CFBRrD+9MtkWkz8Tq9a9U3Cabah DwNrZiV0CKj5Et9ICbnXbbmLUiIolMIvmQnGziVvtaHmhSBvzDzzCtmQ9YegMqSZxs5Z ABYjlUQnUT8VNL0CPdlqDmc0C5DfBQGHOioYzxbX+yxypMLScp2dPZqW2miUPK2WvA8Q Oxc2BGzwjRbCWtxd/1KMTd9/8/LHdoaKXjlekJmfjHyZf9Z0LPBxGIc7UT9OQmx1Y4lw +QbvHV/i1ib93MCMFfKgzSKleCLKZQz5h6yta2VVN+G7KJaZAyvWWLrpHp3XWGSgsgRe mFWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0RJHfed+jRQniNEgBz8w4HYP5Z9aKBBKPSPpaEsO1s0=; b=iQPgnyS6C0Q3ZP59naSh6GRwLjymW7Olp7O29+U2Scj+BMPOD0TkvokiZ++q71Kz83 lScBN2sIM+FoKS9uRDkYQNaq0RbfRUF+vz1YJCIP7KOWH6A93oae/x/+0KSZOTgJOcno 1JjpQUC3VwZKpS7yY7MmJ0IcWaBc/6X5sIVEoGXgwNFDro5qTid+vcaAooWstKGfHIQ5 P21FUNjArUv6nT5GGOaBt6KKlUtLUItZC6Xw+h0LkmXCla9GcfOuoAF1rUZTfLnhl3oZ 52hM4S4hKX8PL87RsfoaMEwGJcJQeBEbdNQaxzcwL3eVSsYjkeNkmPfPyFNPLLWwykWP zJqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eUeguH1x; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a1709060d9300b007309d40276esi7073818eji.538.2022.08.15.11.13.37; Mon, 15 Aug 2022 11:14:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eUeguH1x; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232526AbiHOSHW (ORCPT + 99 others); Mon, 15 Aug 2022 14:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbiHOSHU (ORCPT ); Mon, 15 Aug 2022 14:07:20 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30E5F29C96; Mon, 15 Aug 2022 11:07:19 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id j3so8405057ljo.0; Mon, 15 Aug 2022 11:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=0RJHfed+jRQniNEgBz8w4HYP5Z9aKBBKPSPpaEsO1s0=; b=eUeguH1xX17loOK1eWgABdF5x35FeNK2teQ78Ln6YIinBCzdyXfEVjeWnZp0CLVHu+ YZdyJK214SktzPznc2Jhi7XDBQzY8GU/FU6260B9LK3YDtQ91USAwgiGhqSSHL8wBe6+ /hO3lf09o9Efuyeb5lI8Ik1Q9Mvm/cMCMGV0lqTC/88RghyyquhuKixI5IvQtX2Jaa6b mVZkdj6O6EqNQjcMpJd2g0LEcKAAES2SlTjAi4QuY8wo55e02Hjh0VukxzR5g4grE/sp tsZp/Gy71VWemqTcfvX0v/cb5PuyLKMfyXQuT2ftGmfCEKJuHu9n9pzQW3C7gz+T0vRv H8xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=0RJHfed+jRQniNEgBz8w4HYP5Z9aKBBKPSPpaEsO1s0=; b=e7/XVoexNqRpsbV3oHu9nQvtcjun16lIL5dT6Lvf06Thu2UeGbUF8FtnINC51eqMTF TXZRBMCVJINdtrFaqeV00I31Nqgn/Q6uPOWPE7yRTnkqe/YpYcOwvq+Iq+7EYKIMz/q1 V7dUsPrBi5e2VAQTC08iAVCM5RWFIxTLEmA8luOuWL1rPI5lhQsZw5/fyhFR+sf4CkGc kG4OnGed8xCiZK8+G7wa9/Ku+S7/dVp6UIa1hE6izWEASbLx54ZF5mciDNsoFa31SMAb e0Wq5U1Mm14Gj7R7pQIUDAJz8vyf5QY/AiJ614XRN3GyEH+mRpItNSjbTsFPZT+Kkqao Rkag== X-Gm-Message-State: ACgBeo0Mbmzf+FfglRHZicT+K7hotpGKDeGnFZNhsi1UsH61grtA+1Zp YOMAGOhST3fVw+JtKJthf8FXiy6vwroHLFRrapQAbb+6KHk= X-Received: by 2002:a05:651c:4d4:b0:25e:c766:202e with SMTP id e20-20020a05651c04d400b0025ec766202emr5009874lji.423.1660586837284; Mon, 15 Aug 2022 11:07:17 -0700 (PDT) MIME-Version: 1.0 References: <20220811094542.268519-1-mst@redhat.com> In-Reply-To: <20220811094542.268519-1-mst@redhat.com> From: Luiz Augusto von Dentz Date: Mon, 15 Aug 2022 11:07:05 -0700 Message-ID: Subject: Re: [PATCH v3] Bluetooth: virtio_bt: fix device removal To: "Michael S. Tsirkin" Cc: Linux Kernel Mailing List , Dan Carpenter , Hulk Robot , Yang Yingliang , Marcel Holtmann , Johan Hedberg , "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Michael, On Thu, Aug 11, 2022 at 2:46 AM Michael S. Tsirkin wrote: > > Device removal is clearly out of virtio spec: it attempts to remove > unused buffers from a VQ before invoking device reset. To fix, make > open/close NOPs and do all cleanup/setup in probe/remove. > > NB: This is a hacky way to handle this - virtbt_{open,close} as NOP is > not really what a driver is supposed to be doing. These are transport > enable/disable callbacks from the BT core towards the driver. It maps to > a device being enabled/disabled by something like bluetoothd for > example. So if disabled, users expect that no resources/queues are in > use. It does work with all other transports like USB, SDIO, UART etc. > There should be no buffer used if the device is powered off. We also > don=E2=80=99t have any USB URBs in-flight if the transport is not active. > > The way to implement a proper fix would be using vq reset if supported, > or even using a full device reset. > > The cost of the hack is a single skb wasted on an unused bt device. > > NB2: with this fix in place driver still suffers from a race condition > if an interrupt triggers while device is being reset. To fix, in the > virtbt_close() callback we should deactivate all interrupts. To be > fixed. > > squashed fixup: bluetooth: virtio_bt: fix an error code in probe() Shouldn't the line above be a Fixes tag with the commit hash you are attempting to fix, other than that I'd be fine to apply these changes. > Signed-off-by: Dan Carpenter > Reported-by: Hulk Robot > Signed-off-by: Yang Yingliang > Signed-off-by: Michael S. Tsirkin > Message-Id: <20220811080943.198245-1-mst@redhat.com> > --- > > changes from v2: > tkeaked commit log to make lines shorter > changes from v1: > fixed error handling > > drivers/bluetooth/virtio_bt.c | 19 +++++++++++++++++-- > 1 file changed, 17 insertions(+), 2 deletions(-) > > diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.= c > index 67c21263f9e0..f6d699fed139 100644 > --- a/drivers/bluetooth/virtio_bt.c > +++ b/drivers/bluetooth/virtio_bt.c > @@ -50,8 +50,11 @@ static int virtbt_add_inbuf(struct virtio_bluetooth *v= bt) > > static int virtbt_open(struct hci_dev *hdev) > { > - struct virtio_bluetooth *vbt =3D hci_get_drvdata(hdev); > + return 0; > +} > > +static int virtbt_open_vdev(struct virtio_bluetooth *vbt) > +{ > if (virtbt_add_inbuf(vbt) < 0) > return -EIO; > > @@ -61,7 +64,11 @@ static int virtbt_open(struct hci_dev *hdev) > > static int virtbt_close(struct hci_dev *hdev) > { > - struct virtio_bluetooth *vbt =3D hci_get_drvdata(hdev); > + return 0; > +} > + > +static int virtbt_close_vdev(struct virtio_bluetooth *vbt) > +{ > int i; > > cancel_work_sync(&vbt->rx); > @@ -354,8 +361,15 @@ static int virtbt_probe(struct virtio_device *vdev) > goto failed; > } > > + virtio_device_ready(vdev); > + err =3D virtbt_open_vdev(vbt); > + if (err) > + goto open_failed; > + > return 0; > > +open_failed: > + hci_free_dev(hdev); > failed: > vdev->config->del_vqs(vdev); > return err; > @@ -368,6 +382,7 @@ static void virtbt_remove(struct virtio_device *vdev) > > hci_unregister_dev(hdev); > virtio_reset_device(vdev); > + virtbt_close_vdev(vbt); > > hci_free_dev(hdev); > vbt->hdev =3D NULL; > -- > MST > --=20 Luiz Augusto von Dentz