Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1151944pxy; Fri, 23 Apr 2021 01:11:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzurbUF1EwqxvcMzkpeGxmc3ppe62G9PbF9n5EFhoqX2yQoLyIpbhxWE1yvDrxjtblqmMqH X-Received: by 2002:a17:90a:6b84:: with SMTP id w4mr3085783pjj.134.1619165512244; Fri, 23 Apr 2021 01:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619165512; cv=none; d=google.com; s=arc-20160816; b=Tza7ZTBdkiHOLXUG1HKP2tv92Q7nSgWH+ppv8zEMcYR1M67v5puufXBaP/2z1BFWKq BseNAmywGDqYJxXlDGijziUv42UqJ9J1CGOFH3Ir2cdfdasJW4DmFkV33HmG+UDJMW0I 4SioRYPKwMcBCePWO9fozTZDg7pM5oTXs0+nX6o7/5O8RAXYqV8uh/CKhCDYq56c9KZX yurHP4xzFUEfrGi2l79wNarqoLdzYJ3Ed+4ta1HhsmFlQENAyqwRa66cBRabFWGcTubi +JqAO8eoss7DLr8yHK/sU7G5NXJ7DECnDJX/91dhTMwqygcjDy4LdEKbx2HyCqzI4RL2 z19A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=11TQ6i9OVoMbPFRqUnwUHbTRfc/PohdFDbCQomllfUE=; b=ii+n5ppclzKYMWkD0yCHH4B+EtMFSMr+FKPM4UnaP33bHVVvKXT5hsA//MeWCoL5Qu GNQ6j/TN2qxoM+/fW6D17eiyYKFpD7neV3WR/GFyBSVPD6geAl0jgxJHYcMd/6oQBtxa pP2sNopZ+RkxK4bM5DxQoZJXLdOTlKbjIJD1JRzj5UklG37Nm0qdNKTWPSvWYsYPbxK/ nJT3c5h2eU05YO4p0H/bZS+vRBnPuQ67Wpyn8PyWaim+MoOpg9aeGW+B04qkX/oUaTpD cL8jbjiSTHof1I167oMyGI/kJM1G7KwiXB6OjCppuZFxB7OZ5YD7xeMID8x/tOO4FxAX PsOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OY3yT6d4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si7241605pfa.326.2021.04.23.01.11.40; Fri, 23 Apr 2021 01:11:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OY3yT6d4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241439AbhDWILR (ORCPT + 99 others); Fri, 23 Apr 2021 04:11:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58658 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241391AbhDWILQ (ORCPT ); Fri, 23 Apr 2021 04:11:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619165440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=11TQ6i9OVoMbPFRqUnwUHbTRfc/PohdFDbCQomllfUE=; b=OY3yT6d4rNjz+prTyZbNRoPx1DdH7w1hrvd3Ve/JI2OTZEpWFefkCXfatuVEO7PEmALv0T GpegxQluPOcSghTRyj/05Ln/J8Z88O/lj/lThRzJMxgG8AuhihW4s0KP5OvSI0EDOK9t7k TYbSLGzy3Xlwp3nIn5//EsKi89Vh5tE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-548-qosNDfDJOgKmxNmXVdyOeg-1; Fri, 23 Apr 2021 04:10:36 -0400 X-MC-Unique: qosNDfDJOgKmxNmXVdyOeg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4006C87A826; Fri, 23 Apr 2021 08:10:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-225.pek2.redhat.com [10.72.13.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 722025C5E0; Fri, 23 Apr 2021 08:10:31 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, xieyongji@bytedance.com, stefanha@redhat.com, file@sect.tu-berlin.de, ashish.kalra@amd.com, konrad.wilk@oracle.com, kvm@vger.kernel.org, hch@infradead.org Subject: [RFC PATCH V2 3/7] virtio-ring: factor out desc_extra allocation Date: Fri, 23 Apr 2021 16:09:38 +0800 Message-Id: <20210423080942.2997-4-jasowang@redhat.com> In-Reply-To: <20210423080942.2997-1-jasowang@redhat.com> References: <20210423080942.2997-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A helper is introduced for the logic of allocating the descriptor extra data. This will be reused by split virtqueue. Signed-off-by: Jason Wang --- drivers/virtio/virtio_ring.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index c25ea5776687..0cdd965dba58 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1550,6 +1550,25 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq) return NULL; } +static struct vring_desc_extra *vring_alloc_desc_extra(struct vring_virtqueue *vq, + unsigned int num) +{ + struct vring_desc_extra *desc_extra; + unsigned int i; + + desc_extra = kmalloc_array(num, sizeof(struct vring_desc_extra), + GFP_KERNEL); + if (!desc_extra) + return NULL; + + memset(desc_extra, 0, num * sizeof(struct vring_desc_extra)); + + for (i = 0; i < num - 1; i++) + desc_extra[i].next = i + 1; + + return desc_extra; +} + static struct virtqueue *vring_create_virtqueue_packed( unsigned int index, unsigned int num, @@ -1567,7 +1586,6 @@ static struct virtqueue *vring_create_virtqueue_packed( struct vring_packed_desc_event *driver, *device; dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; size_t ring_size_in_bytes, event_size_in_bytes; - unsigned int i; ring_size_in_bytes = num * sizeof(struct vring_packed_desc); @@ -1650,18 +1668,10 @@ static struct virtqueue *vring_create_virtqueue_packed( /* Put everything in free lists. */ vq->free_head = 0; - vq->packed.desc_extra = kmalloc_array(num, - sizeof(struct vring_desc_extra), - GFP_KERNEL); + vq->packed.desc_extra = vring_alloc_desc_extra(vq, num); if (!vq->packed.desc_extra) goto err_desc_extra; - memset(vq->packed.desc_extra, 0, - num * sizeof(struct vring_desc_extra)); - - for (i = 0; i < num - 1; i++) - vq->packed.desc_extra[i].next = i + 1; - /* No callback? Tell other side not to bother us. */ if (!callback) { vq->packed.event_flags_shadow = VRING_PACKED_EVENT_FLAG_DISABLE; -- 2.25.1