From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CBF9C10F0E for ; Mon, 15 Apr 2019 19:27:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D0DA82075B for ; Mon, 15 Apr 2019 19:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555356460; bh=ql1tjAa0nD6jAbAc6C4t4vMQZMq5/nysHOewJu/DL6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PRXKD910uoDuQv5VYwLZQdnOelKrKfLD27MKRiEVTKJLhxAxhyCLinOBu4Ycdtb0P cSgxqen2Ut8V++vMCmf5WWqXVivZpQzfiqb+aKnOvUptTWCOH5IWvD3ng4AyMs7vgX 1yrLHqfeNJGOR9LdPzxlV1q6RerSx01HAJ9GuA84= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729319AbfDOTDn (ORCPT ); Mon, 15 Apr 2019 15:03:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:35790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729312AbfDOTDm (ORCPT ); Mon, 15 Apr 2019 15:03:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8D9E6218FE; Mon, 15 Apr 2019 19:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355022; bh=ql1tjAa0nD6jAbAc6C4t4vMQZMq5/nysHOewJu/DL6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XbSocjekMEZWHsUEUTTna4e60+T9y1ZIIM7CrG89qTgPbdFBFg0TAiuhnp9V4gbWq qlkZoYBgNHIaVPzig9RKNzJ1jWn+lC5n3lrJ3bKqiqqAT6DJVS5bnf3CbkBCAf/k/V pRX7mp0QW7OgNVyp4E9wwJbVtlwo5+zQPD9MK40I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cornelia Huck , "Michael S. Tsirkin" , Halil Pasic , Jens Freimann Subject: [PATCH 4.14 53/69] virtio: Honour may_reduce_num in vring_create_virtqueue Date: Mon, 15 Apr 2019 20:59:11 +0200 Message-Id: <20190415183734.540083630@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183726.036654568@linuxfoundation.org> References: <20190415183726.036654568@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Cornelia Huck commit cf94db21905333e610e479688add629397a4b384 upstream. 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 Signed-off-by: Michael S. Tsirkin Reviewed-by: Halil Pasic Reviewed-by: Jens Freimann Signed-off-by: Greg Kroah-Hartman --- drivers/virtio/virtio_ring.c | 2 ++ include/linux/virtio_ring.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1087,6 +1087,8 @@ struct virtqueue *vring_create_virtqueue GFP_KERNEL|__GFP_NOWARN|__GFP_ZERO); if (queue) break; + if (!may_reduce_num) + return NULL; } if (!num) --- 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,