Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2447847imb; Mon, 4 Mar 2019 05:31:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyoP9HRH//NETauw9D+iwbW5OqrR6JxrJtcGS4WM2jXN0mtCNVAHsHN5CLWArjvbGHqhRku X-Received: by 2002:a63:d4f:: with SMTP id 15mr18571949pgn.162.1551706310449; Mon, 04 Mar 2019 05:31:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551706310; cv=none; d=google.com; s=arc-20160816; b=y23vPHOip+W2nhZvDEi7+buEaqip4sxrdXitX+M7dLgkCXMp+lV4aRSngNSWsbTGyu cu6wEhXKQpm4AP+ViSHomiFTaYid4G48ogki/ZyRo+bgju5fN2FkA6nJegWEKqcG2GE/ Ou7JCxmsMd3qZreouEViJEpDjrsmWkToQp80xd+dwtS0riME5huX+0bFkpeHxyebR1Ia rw86zDSHR+yUbxUVtlwD30ksQ9589hcKGROAE8mFcuuoa3R0DVj5hryWOZAsmslSiQ3a VTD0STnptT2J8Cd8YsqyBcxgKFkoch2KDwARXCGOXW636f2QrtvZ2lYbd8ZZ9ybuXyvn /gjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=3Kx6GdOcKrUrSMCoExddiu+p7z/MXpYdn8Cw9HmMggI=; b=c9gQeDyti7ObAf3vowiQgLgcH8GBiJPcFM2sPN1tr9dXlm9Co0w/SfbQeeQtc1nMFi EyRFa5ruqGA7w6EilKMxJQ45br5BYo4Pn/yI5rG6AhYzTJWvjgW2Sm0lJSoR/rABP6qG grTW7C/IjfkpVWQdkh4p+hCAEhE/R1zdjDhFW2dEG837imI0GUutoX+RdOeaoKt/bUV1 eUmvta6+NMPJE6apfipEvgwM5KCxhERZdFLVt1gTPedVCuAA2qoruIL7qNZc2ZxNo4hF fzUmLNJrRa7Ne2I9/1GuLrg1G9bs6uwReD1DSSggij8ka0Cl//3d7Emn9CRxyBu8SHwc xrgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si5009946pgp.187.2019.03.04.05.31.33; Mon, 04 Mar 2019 05:31:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbfCDN2p (ORCPT + 99 others); Mon, 4 Mar 2019 08:28:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42380 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726186AbfCDN2o (ORCPT ); Mon, 4 Mar 2019 08:28:44 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83ED53082E6A; Mon, 4 Mar 2019 13:28:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 730685D9CA; Mon, 4 Mar 2019 13:28:44 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5DF493FB10; Mon, 4 Mar 2019 13:28:44 +0000 (UTC) Date: Mon, 4 Mar 2019 08:28:44 -0500 (EST) From: Pankaj Gupta To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: amit@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org, mst@redhat.com, xiaohli@redhat.com, Gal Hammer Message-ID: <50743754.9007443.1551706124243.JavaMail.zimbra@redhat.com> In-Reply-To: <20190304130511.14450-1-pagupta@redhat.com> References: <20190304130511.14450-1-pagupta@redhat.com> Subject: Re: [PATCH] virtio_console: free unused buffers with virtio port MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.116.187, 10.4.195.25] Thread-Topic: virtio_console: free unused buffers with virtio port Thread-Index: ZAH3uJ1zSiTXVyemOaDMFn8IcxOfmg== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 04 Mar 2019 13:28:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Gal in CC [Forgot to add] > > The commit a7a69ec0d8e4 ("virtio_console: free buffers after reset") > deffered detaching of unused buffer to virtio device unplug time. > > This causes unplug/replug of single port in virtio device with an > error "Error allocating inbufs\n". As we don't free the unused buffers > attached with the port. Re-plug the same port tries to allocate new > buffers in virtqueue and results in this error if queue is full. > > This patch removes the unused buffers in vq's when we unplug the port. > This is the best we can do as we cannot call device_reset because virtio > device is still active. This was the working behaviour before the change > introduced in commit b3258ff1d6. > > Reported-by: Xiaohui Li > Fixes: b3258ff1d6 ("virtio_console: free buffers after reset") > Signed-off-by: Pankaj Gupta > --- > drivers/char/virtio_console.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c > index fbeb71953526..5fbf2ac73111 100644 > --- a/drivers/char/virtio_console.c > +++ b/drivers/char/virtio_console.c > @@ -1506,15 +1506,25 @@ static void remove_port(struct kref *kref) > kfree(port); > } > > +static void remove_unused_bufs(struct virtqueue *vq) > +{ > + struct port_buffer *buf; > + > + while ((buf = virtqueue_detach_unused_buf(vq))) > + free_buf(buf, true); > +} > + > static void remove_port_data(struct port *port) > { > spin_lock_irq(&port->inbuf_lock); > /* Remove unused data this port might have received. */ > discard_port_data(port); > + remove_unused_bufs(port->in_vq); > spin_unlock_irq(&port->inbuf_lock); > > spin_lock_irq(&port->outvq_lock); > reclaim_consumed_buffers(port); > + remove_unused_bufs(port->out_vq); > spin_unlock_irq(&port->outvq_lock); > } > > @@ -1950,11 +1960,9 @@ static void remove_vqs(struct ports_device *portdev) > struct virtqueue *vq; > > virtio_device_for_each_vq(portdev->vdev, vq) { > - struct port_buffer *buf; > > flush_bufs(vq, true); > - while ((buf = virtqueue_detach_unused_buf(vq))) > - free_buf(buf, true); > + remove_unused_bufs(vq); > } > portdev->vdev->config->del_vqs(portdev->vdev); > kfree(portdev->in_vqs); > -- > 2.20.1 > >