Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6718560ybh; Thu, 8 Aug 2019 04:38:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzM2LGGrko2Cs4SBzRfcvmSvxb37IXVgLsk7+rWLj/XA0xWSHacvUJQ3b5dknCK4AhbeY/y X-Received: by 2002:a63:7709:: with SMTP id s9mr12013202pgc.296.1565264328227; Thu, 08 Aug 2019 04:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565264328; cv=none; d=google.com; s=arc-20160816; b=Nlq0hkEcGITB3HwepZYIogothnVf4H1yAT3PbPKZ3nqm3Zj8FTZ/Fkrz2HYN3Uywmz 8QknPVguL/RCIabiy57zQmwE9k5bXtCq1RKiRmmAXFQ4GiWwQf+8/k+6BBb62dUIYxcs ZqGIGnLcrynIFAzmhhHrN8AwMWK/ysCAF3XZK+atGg9Nc7ZyEN6LFAUQIxWs3Y9Mr+xI 4wS9yMkITnd9tzjWTNvCSqCXHKEzeivwWYqrxtQefcVEBNgqTzydkMuMLbGWJb/aaVCR vC6397kJmoPEpqaGaGyOEyjrA+K2bayilf4ZUQvLdJr1m6nM4cbNqTd+8VzFl5bLcyIs j//Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QV4T2UwRpsPNqnxBpreHIU6O2PTL4/iALQbn5gg1sBw=; b=DrPSPIf7B7D45WGjVoguBSuujcs8c4FPmbEQ023Foh1t6XUCwlD6V9c+eVt9x2bXNN HOXctFgAhTZNKNnmO+l6zIRrPVtfL8U/qpu6hnsgoj01DIk+AwVCatB6GptTbUo4LFOC 8hrCPkC9UkgK0sbazMjkdfMXycT0m/DlAtyOzfEkRMNX3nfB/LnwYHMG/WXqUQckWoFf Q9mZ72cGOBk9hXbPfp/pXgxKKQgyk6iEjWnTYsa3/3rtmacDZSTqJ4Dqy4HXUGqkiKYe NqXwZuCqgUMZK0cCCHx17fOrwwMiGIdmBaHiIPIvhzSMMIxYr64Mrz4YUOeseVczmW+3 trYA== 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 a21si54030911pfl.167.2019.08.08.04.38.32; Thu, 08 Aug 2019 04:38:48 -0700 (PDT) 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 S1728289AbfHHLgR (ORCPT + 99 others); Thu, 8 Aug 2019 07:36:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46648 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728693AbfHHLgQ (ORCPT ); Thu, 8 Aug 2019 07:36:16 -0400 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 19EF0300BEA9; Thu, 8 Aug 2019 11:36:16 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (unknown [10.65.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EF04612BF; Thu, 8 Aug 2019 11:36:13 +0000 (UTC) From: Pankaj Gupta To: amit@kernel.org, mst@redhat.com Cc: arnd@arndb.de, gregkh@linuxfoundation.org, virtualization@lists.linux-foundation.org, jasowang@redhat.com, linux-kernel@vger.kernel.org, pagupta@redhat.com Subject: [PATCH v2 1/2] virtio_console: free unused buffers with port delete Date: Thu, 8 Aug 2019 17:06:05 +0530 Message-Id: <20190808113606.19504-2-pagupta@redhat.com> In-Reply-To: <20190808113606.19504-1-pagupta@redhat.com> References: <20190808113606.19504-1-pagupta@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.42]); Thu, 08 Aug 2019 11:36:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit a7a69ec0d8e4 ("virtio_console: free buffers after reset") deferred 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. 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 7270e7b69262..e8be82f1bae9 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1494,15 +1494,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); } @@ -1938,11 +1948,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.21.0