Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2820593yba; Mon, 8 Apr 2019 05:34:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxw4tC+oTjT+xfo66RI/3uQwwSWnHWMaE7iGQdO47J9hROnJ6OHUcMDDN5ohxHFKPzPJ7Cx X-Received: by 2002:a63:158:: with SMTP id 85mr28214152pgb.351.1554726872089; Mon, 08 Apr 2019 05:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554726872; cv=none; d=google.com; s=arc-20160816; b=HrAXsWL7z+bASUUs7xtmtut0Q7smep8AZC5UNhvrVUhAiH0S5hpsActnqXKQmNlqUY Fy/iVMpADF3FF4/kD6JUMpRBSGnfMKW/5zuO8wzuM33juVD/4+RZoLTqQLtfzcIvabBP TVnK4DmlKX3ogl0ugceqqODF1CIdFNwCCJrvcAqu4Vv9Sowkn7n3hq47Mg9BeQTDUClB bbAgN51KkNJh39V242vVRe9xgo7zdXsY4+vcbYiNaYn6vx7fjei4Ft6LYZ3izx8AX+/y /ZdPzJG6rGtGohTltWTwbIDmRe5e7L2hUh3yNl/e1NoY1bbPW9Jsk1+VxzhENmIRq5o8 rySg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=fLftAKw1sPkp6EDQDwqkz4w1kRnv73mrqXSXS+7OLS8=; b=MCM8jITzkFJueLavPlEzGDJW3NYxCqwH44POCg2M1Ue6B13qpqdcXzCFeLewkKORoW QhRWorJKdwr7T6hS8EuM2DziGWJ1wvH/tuoYNMzfnTLK6Wpp32MeSq2m0CIbq7Po2/Sa Pw4rfYgiK++kqu1sH35jvVz5O/xuNRCi5+AL8qMmoAvv0YbQxpkNTAE/DvpeA51bKBRj 9HYP9M4Gxh9FJ/rQRhtuakyvDEKrz1fv5cGIx8huPv2Yvk7nB39t3xhljk4qbRKZMNAs s+Z5Px1Nb9yh9cZkKI6Xwo5eYKrlXEsaib4+9OK48ok6sGfYqaNGMSXCdYmNRrktaB8W bBBA== 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 r80si27041910pfa.128.2019.04.08.05.34.16; Mon, 08 Apr 2019 05:34:32 -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 S1726712AbfDHMd2 (ORCPT + 99 others); Mon, 8 Apr 2019 08:33:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726495AbfDHMd1 (ORCPT ); Mon, 8 Apr 2019 08:33:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72B98307D964; Mon, 8 Apr 2019 12:33:27 +0000 (UTC) Received: from localhost (ovpn-117-86.ams2.redhat.com [10.36.117.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 023115D719; Mon, 8 Apr 2019 12:33:26 +0000 (UTC) From: Cornelia Huck To: "Michael S . Tsirkin" , Jason Wang Cc: Halil Pasic , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Cornelia Huck , stable@vger.kernel.org Subject: [PATCH] virtio: Honour 'may_reduce_num' in vring_create_virtqueue Date: Mon, 8 Apr 2019 14:33:22 +0200 Message-Id: <20190408123322.24086-1-cohuck@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 08 Apr 2019 12:33:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vring_create_virtqueue() allows the caller to specify via the may_reduce_num parameter whether the vring code is allowed to allocate a smaller ring than specified. However, the split ring allocation code tries to allocate a smaller ring on allocation failure regardless of what the caller specified. This may cause trouble for e.g. virtio-pci in legacy mode, which does not support ring resizing. (The packed ring code does not resize in any case.) Let's fix this by bailing out immediately in the split ring code if the requested size cannot be allocated and may_reduce_num has not been specified. While at it, fix a typo in the usage instructions. Fixes: 2a2d1382fe9d ("virtio: Add improved queue allocation API") Cc: stable@vger.kernel.org # v4.6+ Signed-off-by: Cornelia Huck --- drivers/virtio/virtio_ring.c | 2 ++ include/linux/virtio_ring.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 18846afb39da..5df92c308286 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -882,6 +882,8 @@ static struct virtqueue *vring_create_virtqueue_split( GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO); if (queue) break; + if (!may_reduce_num) + return NULL; } if (!num) diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index fab02133a919..3dc70adfe5f5 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -63,7 +63,7 @@ struct virtqueue; /* * Creates a virtqueue and allocates the descriptor ring. If * may_reduce_num is set, then this may allocate a smaller ring than - * expected. The caller should query virtqueue_get_ring_size to learn + * expected. The caller should query virtqueue_get_vring_size to learn * the actual size of the ring. */ struct virtqueue *vring_create_virtqueue(unsigned int index, -- 2.17.2