Received: by 10.192.165.148 with SMTP id m20csp567189imm; Fri, 20 Apr 2018 11:19:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx497oBMOjAVK5JvHQ7KIhYfoP5t2VIQcC+HEI5zeu3vO8I5kTqAdupiq1TEM927BZXrnId1T X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr11297294plt.142.1524248384308; Fri, 20 Apr 2018 11:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524248384; cv=none; d=google.com; s=arc-20160816; b=YVwqXhqeo/4V1sUvKa/BAhoQVj1CnpS0rpvNZiQUzpzRaKM/utCxRcZCyCNPy+dJx0 0ql1J4sU9GiDWs2EgW3D6UQg6hTjxpvx6p6wiDtvTcKlXQ1eEGc8NE5KE99PrqGvF2TA 1EukOkPsoaZaMmHKu8NajtA6+YQ636uqbxaqnMXhtEjoLoYVPIbSU2lKd7/yO8EbSfXR NCnnJnRx40gEidgidBIA0jYvwpVk34o4fwFz4FjEQzlapZtOHMhPcZsVQMVg9LpI+j8G o/mioURTtt1LypBNsjYZqvh/JvexubPKJleQYKMcpF8kHCnK5dP378pc0fAjaTiuQzAP xbsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=FLUkdZVh7gFWYW247XCVS+eQEx055Zbaghoy6MYFS6U=; b=z2xqyzppBHzW8yGjIjHpJ1CZm30lZe+TJIyvfcWhLgmNIu/RCe+aAybzRhjEJefszB FmUId6nU93zlQilhaZU3VO79IT7LRmXvlrzH/0wolbtRjeVrI1dAjmr+IX8jUQSwkl3s zGMH1ws84jOLiyuokZb464Pqprnedi/hFEy46G3rHJNu58KEoDD2cd2YlYp1RONkKfwr 4Q1oJa5kcJ4pgLmlVweTGPcYliyIF/4kH4V9PxsmR00YSVzdORfBF4qCo/Pa3/LvfHQA 6U3wwGJByUqIzdsN8Ap+QFaqQU0wx7yUAPvXIEZxwc0AgSvyfQugD0SXdjVcwVqxtT5T 5mBg== 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 k24si5328299pgn.24.2018.04.20.11.19.30; Fri, 20 Apr 2018 11:19:44 -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 S1753848AbeDTSSM (ORCPT + 99 others); Fri, 20 Apr 2018 14:18:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59682 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753566AbeDTSSH (ORCPT ); Fri, 20 Apr 2018 14:18:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DAC974072458; Fri, 20 Apr 2018 18:18:06 +0000 (UTC) Received: from redhat.com (ovpn-126-37.rdu2.redhat.com [10.10.126.37]) by smtp.corp.redhat.com (Postfix) with SMTP id 64FCA11701C7; Fri, 20 Apr 2018 18:18:06 +0000 (UTC) Date: Fri, 20 Apr 2018 21:18:06 +0300 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Amit Shah , Arnd Bergmann , Greg Kroah-Hartman , virtualization@lists.linux-foundation.org, stable@vger.kernel.org, Tiwei Bie , Jason Wang Subject: [PATCH 6/6] virtio_console: reset on out of memory Message-ID: <1524248223-393618-7-git-send-email-mst@redhat.com> References: <1524248223-393618-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1524248223-393618-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 20 Apr 2018 18:18:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 20 Apr 2018 18:18:06 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When out of memory and we can't add ctrl vq buffers, probe fails. Unfortunately the error handling is out of spec: it calls del_vqs without bothering to reset the device first. To fix, call the full cleanup function in this case. Cc: stable@vger.kernel.org Signed-off-by: Michael S. Tsirkin --- drivers/char/virtio_console.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index e8480fe..2108551 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2090,6 +2090,7 @@ static int virtcons_probe(struct virtio_device *vdev) spin_lock_init(&portdev->ports_lock); INIT_LIST_HEAD(&portdev->ports); + INIT_LIST_HEAD(&portdev->list); virtio_device_ready(portdev->vdev); @@ -2107,8 +2108,15 @@ static int virtcons_probe(struct virtio_device *vdev) if (!nr_added_bufs) { dev_err(&vdev->dev, "Error allocating buffers for control queue\n"); - err = -ENOMEM; - goto free_vqs; + /* + * The host might want to notify mgmt sw about device + * add failure. + */ + __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, + VIRTIO_CONSOLE_DEVICE_READY, 0); + /* Device was functional: we need full cleanup. */ + virtcons_remove(vdev); + return -ENOMEM; } } else { /* @@ -2139,11 +2147,6 @@ static int virtcons_probe(struct virtio_device *vdev) return 0; -free_vqs: - /* The host might want to notify mgmt sw about device add failure */ - __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, - VIRTIO_CONSOLE_DEVICE_READY, 0); - remove_vqs(portdev); free_chrdev: unregister_chrdev(portdev->chr_major, "virtio-portsdev"); free: -- MST