Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3059387imb; Mon, 4 Mar 2019 23:11:20 -0800 (PST) X-Google-Smtp-Source: APXvYqzhpYfnZlL0Br9iUjOdpYTAfah/K3WJ4C6GF6HJ2whKsMjG3WPpY66iOCbC6PBb3wjF+aHQ X-Received: by 2002:a62:e0ca:: with SMTP id d71mr466908pfm.62.1551769880695; Mon, 04 Mar 2019 23:11:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551769880; cv=none; d=google.com; s=arc-20160816; b=qRdqRNbNZ4quWsev1tr7pg8kqPP5cGnduhNO4NFfGs+TusTDIe3oCkpAPylCXU5QIN 486wAHCaGkUDl9XtWysCFeYy4IVxIRHcuEpIjdqVIVr99SYCSfaPDG3qRs4HMBmybC1g r4wGxS3Clyc1ENqzwfxwasLy8dy3ITc457fhV1uTdHcE8N/blloulj7zLv7o03XswuZy uZOndqjwhlglclCL/LeyiD1iwHwd/3dRUI9DPwP1p6vqcIPyp3PyIKU3q0taZu80rQxC js7F/rK/ZyIrEMuCRggpFGRu5BePpJc9ETnOn75YoABkboEvxVvLRrLIHUTvofbP9SdU CgSQ== 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=vdQ1begKzIl3CIv2saDxaLqZdrgcZ7lx5cT+P5hAd5k=; b=i3Xa4Z1mYGx2tfaNkYtIxQGWtr41IGOlP0jTXCvjxP6xRnZ2p2BAkh65VFbscLH4oo YnylFNRmKUn/FUb+pBjGsUb96xByUBrxvDcrCjaHIxF5lXaCbBsMfZA9Uqsv9amXdD4X xrRkbF9BQvC0g/16YQvLSvFiZgdmC80fdwzOr0qWuAbOT3XHu6D7duGdgxYqJeVqAvHo uTr+uH1Uw6+XsRdZE3dkQOJM2THXXODBMlZthGcE3kM7B+m2JuKeiy85JZtUWxV1Ni/V ZxSuxV1+32ggXbKBUkgnVldUd6jLl3X52mvwcn9a+vJqzWVao72o/MDov4yW0KaTehfL xAjg== 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 j97si7660213plb.292.2019.03.04.23.11.04; Mon, 04 Mar 2019 23:11:20 -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 S1726934AbfCEHJH (ORCPT + 99 others); Tue, 5 Mar 2019 02:09:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47148 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725835AbfCEHJH (ORCPT ); Tue, 5 Mar 2019 02:09:07 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B08693082A32; Tue, 5 Mar 2019 07:09:06 +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 9E5AB1001E61; Tue, 5 Mar 2019 07:09:06 +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 7846141F3C; Tue, 5 Mar 2019 07:09:06 +0000 (UTC) Date: Tue, 5 Mar 2019 02:09:06 -0500 (EST) From: Pankaj Gupta To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, amit@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org, xiaohli@redhat.com, Gal Hammer Message-ID: <444210313.9669582.1551769746169.JavaMail.zimbra@redhat.com> In-Reply-To: <20190304142506-mutt-send-email-mst@kernel.org> References: <20190304130511.14450-1-pagupta@redhat.com> <20190304142506-mutt-send-email-mst@kernel.org> 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.65.161.16, 10.4.195.4] Thread-Topic: virtio_console: free unused buffers with virtio port Thread-Index: BFmvrGbWTg6avNTfy7ONAyFjOsQPeg== X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 05 Mar 2019 07:09:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Michael, Thanks for your reply. > > On Mon, Mar 04, 2019 at 06:35:11PM +0530, Pankaj Gupta wrote: > > 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 > > I think if you do this you need to add support > in the packed ring. o.k. I will look at the implementation details for "support of packed ring" for virtio_console. This will take some time. Meanwhile "virtio_console" port hotplug/unplug is broken in upstream. Can we accept this patch as it fixes the upstream and together with parent patch(b3258ff1d6) does nice cleanups as well. Thanks, Pankaj > > > --- > > 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 >