Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7803204ybh; Thu, 8 Aug 2019 23:50:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMzq48QNxd0cn84GIA+u3O9ogEmnKLcTEPgne+vqU/OWjBHc4bL+8G/aMUs9bGbzi9gdQV X-Received: by 2002:aa7:8102:: with SMTP id b2mr19973843pfi.105.1565333400297; Thu, 08 Aug 2019 23:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565333400; cv=none; d=google.com; s=arc-20160816; b=OGHH3dM5zWbBhyuQvaDjnIlZ5yKjq3BwLu5zgTMtIa8q1Hau4lS/QzrMXKvHGLQ4r8 qaLgz3yKU7vFN/n8E+U0GIVUn7XbxHJ0vXVQ4heGVYPEq74f5lVMSTuOOVqfd6R1Geli j0h5OBz4koXW65yJxwa7tj2+SBkekmb9baHAWHGe5udQsFZJuqxhWddj1BzscIknseGG tyTvApSruIuY++1Zg4C/0SSdkuu+qtVhpeohU4V6yakEGzJV1SiiOAeBjgNpSxkCq/0x Ub1hN25RF2O+1YO+TNRVJsYAxQkXDryk7aanaD0n68otVVrRnbj1fF2vsQFwIZh8p2MX j9FQ== 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=K6dylLh+49rlYEDyUKCpe42oxc2VFMxU5DLbQ3imuWo=; b=tBn2C8oXr8/UQk+M8BJa4lUeyNy5QLi6JYXoWTUe45hmCupW3TYykzAs4CvWRpyi5W oeG+ZQowZIGrQ9omaLt2FxjxKLUoD0h7ZQjGj5DUHbBg2pb+wAq2yQS7dVvR0V3etWNN kaUPGrueh8rdAofua03EriaqKopKteLf9YoYmPdl+qQNuZvj+bg6KYjsinwMiJ0h8dCD 6TXiaGnXjL0fkdfP7lRv/45iBdq6L1OTJREciwIV7e802lRJCvNU7nX5UN96KLbvgLtm cDy+u6+xHL1DqIHN3tWEtLxX+nPW1pxejoanUMcwIEC/bglBZO0di4PyY8SE+WtlEJqi zrlA== 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 o3si560034pjt.107.2019.08.08.23.49.41; Thu, 08 Aug 2019 23:50:00 -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 S2405617AbfHIGs7 (ORCPT + 99 others); Fri, 9 Aug 2019 02:48:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44328 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405239AbfHIGs7 (ORCPT ); Fri, 9 Aug 2019 02:48:59 -0400 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 0227130860DE; Fri, 9 Aug 2019 06:48:59 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (unknown [10.65.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id D44661001925; Fri, 9 Aug 2019 06:48:54 +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, xiaohli@redhat.com Subject: [PATCH v3 1/2] virtio_console: free unused buffers with port delete Date: Fri, 9 Aug 2019 12:18:46 +0530 Message-Id: <20190809064847.28918-2-pagupta@redhat.com> In-Reply-To: <20190809064847.28918-1-pagupta@redhat.com> References: <20190809064847.28918-1-pagupta@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.44]); Fri, 09 Aug 2019 06:48:59 +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: a7a69ec0d8e4 ("virtio_console: free buffers after reset") Cc: stable@vger.kernel.org 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