Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3663126yba; Tue, 9 Apr 2019 02:02:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8n++05f8NM+wmq1K41tT21nlJdsGi7wMRgfkwjoz4fwhfJmY/KbzoMfROIIbsPhSk+XMT X-Received: by 2002:a62:b411:: with SMTP id h17mr17049695pfn.61.1554800524331; Tue, 09 Apr 2019 02:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554800524; cv=none; d=google.com; s=arc-20160816; b=U8j/HSyda1gY5lRfVO6hQ/5LtVJprFJkiFBM5QJtsxsSJunrRnEXnk4gpPrKUI3qhr ch5n2R+n4NndHZYCmRQfhG/j/ILDyGrOzh4dfCkCQCHslpOqNaRm5NE8+aHntUpoiBWe TQ9ZsODu6v9SaDKrAl0LJOnWsUO/Kpbz7dMDU3jAm4IGY9H/N4QBw9M+AsIzKrHQ7lsZ ZFjh9u92Kabh8Kqo4zhONUdUa/HtQQJYlGu4C5NaX1GbJOM+v8dTqWF3+bzmRAvtsXNT U3vb7SX5toKyWsyAmavFeFL3we+w30aDvEIaRejx77nHEQUogjgVPcgNfpOtQh+3XDO3 mHVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+YESPARR5eVeIe97+RNJ1EWwhK9f/sZuuWLodhlKVW8=; b=WRiTqzy1Rm9xBXhjJ+Tb609rNROtzo6HYwHZbFf68IBpIGJ5yNzOU5INo9JgdVPb56 7MtX/nqElofuE3tA9PnKAarb6HKny/0CPENQFGY4BCgWx2gItqtxSf/WKtv2xhwA99Kh pmHGIdK9IqaEQadcCnLt9+uNu1SSjTnXZPA6aKPmOVd/X1aN4qZC4aFUdeDYIC189p3z oqy9TQjLYq9LmI0zNnSl+bKUGhoC4P4pdqyedXEd0+Zxhzwd2BilkuQdGMfUUTCkgTTo 4SnQDexZpb4+GTlrm2FaPbvd/b7aR5AeZrJPtN8jZqVcQSqh7rv5p6+pqEVhSs0unDVE SaXA== 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 p8si28330741plq.225.2019.04.09.02.01.48; Tue, 09 Apr 2019 02:02:04 -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 S1726535AbfDIJBH (ORCPT + 99 others); Tue, 9 Apr 2019 05:01:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41602 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbfDIJBH (ORCPT ); Tue, 9 Apr 2019 05:01:07 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B564E2D7F3; Tue, 9 Apr 2019 09:01:06 +0000 (UTC) Received: from [10.72.12.67] (ovpn-12-67.pek2.redhat.com [10.72.12.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id E65FA272C0; Tue, 9 Apr 2019 09:01:01 +0000 (UTC) Subject: Re: [PATCH] virtio: Honour 'may_reduce_num' in vring_create_virtqueue To: Cornelia Huck , "Michael S . Tsirkin" Cc: Halil Pasic , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20190408123322.24086-1-cohuck@redhat.com> From: Jason Wang Message-ID: <9b3d1789-33e1-3ad5-18cd-cacefec8bbb2@redhat.com> Date: Tue, 9 Apr 2019 17:00:59 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190408123322.24086-1-cohuck@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 09 Apr 2019 09:01:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/4/8 下午8:33, Cornelia Huck wrote: > 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, Acked-by: Jason Wang