Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2522599yba; Mon, 15 Apr 2019 13:30:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoXpmJSyXSThiNaZchWNbpEVN2RRaH8GMqKVuKy5nFuZTQOaojiUsc5op1BXWpBHasNvo6 X-Received: by 2002:a65:6545:: with SMTP id a5mr60964771pgw.264.1555360255571; Mon, 15 Apr 2019 13:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555360255; cv=none; d=google.com; s=arc-20160816; b=GJdf6+TskumbeWM+GfPkkPQIiRxBMQTnXCAb18t9BfRkT5GT0SLismk82RFbEjMF6F ESG2WPWcosBezEwWRHaVu1+gHVXQ7fBoPbh6/I0lnHn4CylmTXGuR7+7bb2rrFlx9AN2 1RjhGD47pL7+vs09ip5/IK1BGKod1BI6gm5KV1Ed3oItSabjAWhBZDeVKcTJAz29u3LR Hiz3hflpa3kIL42mjrJZXEaKhZDoRodJh2YpQXCgRMSpXUzqUJSPIlVd01LUCGhtOtvh msfX+pe3lrm3fl3LA+Pz5kFGcFmTyTV6yItd7uzXCwVFg/t/MLjq7kGbWNDttrBmxLZZ 6+bQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oQjI5V9DLnfbbWj2F1sI1DIZskzBGIH3D7CV4McjMXE=; b=wnXletyAV060TALKlNvF95+bY91+dyzehlWjgY5dO4N4rjN990wDqbUPBGD+vcyqec QdtUXcqedE1+wVuEOFO5mcVTP7wXFRGJDRnws/SPi6dlvGHvnCt8SmLCE48MOITceFyO 8VtZsGbwPUjbFArPWsx0N9DZVmUKxViDzyYFbPHkM5QmNReyS1dLSFtMVmwkeog2LfYu mtlb9yRIpnemnIQzzIzvIVLGePqCs5rLvq8azMJbqzSLLYCXNb6OfcBkKtv6bByfv2hs QZXf9O8WWVJaeUnaUoVtNK1dcenE00siV6U3SqN+7J8vXUP3Rj4YBb9C+YwiozP3/E7r AEhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TDWKNGAV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si18832427pgv.299.2019.04.15.13.30.39; Mon, 15 Apr 2019 13:30:55 -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; dkim=pass header.i=@kernel.org header.s=default header.b=TDWKNGAV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730654AbfDOTJJ (ORCPT + 99 others); Mon, 15 Apr 2019 15:09:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:44750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730649AbfDOTJF (ORCPT ); Mon, 15 Apr 2019 15:09:05 -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 C0A0021900; Mon, 15 Apr 2019 19:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355345; bh=MuWSN6d9k3a76+0XIDz9vmfjWYJOuzSLm1pEe0R5Mek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDWKNGAVt2Tl+lC4PlXy+EyRaw6jBFZy0qNCMqvso5+Nhq/QUtqQkQ2S44MS5B3yz PUKeTyEUjjEB6rDUiN8cSyDR6drPWqlMLfxJPBuZTV/Ja6Tfwy0fyBUpRs0gxA7KpT VEv7oHnmsheqlkfDJJwRbj21D9yRnmIKRbwChgAA= 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.19 075/101] virtio: Honour may_reduce_num in vring_create_virtqueue Date: Mon, 15 Apr 2019 20:59:13 +0200 Message-Id: <20190415183744.420914642@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -1086,6 +1086,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,