From patchwork Wed Apr 6 03:43:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuan Zhuo X-Patchwork-Id: 12803480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 008C8C43217 for ; Wed, 6 Apr 2022 13:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234113AbiDFOB4 (ORCPT ); Wed, 6 Apr 2022 10:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234026AbiDFOB2 (ORCPT ); Wed, 6 Apr 2022 10:01:28 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D18262D74; Tue, 5 Apr 2022 20:44:14 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=34;SR=0;TI=SMTPD_---0V9K2X73_1649216648; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0V9K2X73_1649216648) by smtp.aliyun-inc.com(127.0.0.1); Wed, 06 Apr 2022 11:44:09 +0800 From: Xuan Zhuo To: virtualization@lists.linux-foundation.org Cc: Jeff Dike , Richard Weinberger , Anton Ivanov , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Hans de Goede , Mark Gross , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , Cornelia Huck , Halil Pasic , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Sven Schnelle , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Johannes Berg , Xuan Zhuo , Vincent Whitchurch , linux-um@lists.infradead.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v9 10/32] virtio_ring: split: introduce virtqueue_reinit_split() Date: Wed, 6 Apr 2022 11:43:24 +0800 Message-Id: <20220406034346.74409-11-xuanzhuo@linux.alibaba.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220406034346.74409-1-xuanzhuo@linux.alibaba.com> References: <20220406034346.74409-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 881cb3483d12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Introduce a function to initialize vq without allocating new ring, desc_state, desc_extra. Subsequent patches will call this function after reset vq to reinitialize vq. Signed-off-by: Xuan Zhuo Acked-by: Jason Wang --- drivers/virtio/virtio_ring.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 874f878087a3..3dc6ace2ba7a 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -953,6 +953,25 @@ static void vring_virtqueue_init_split(struct vring_virtqueue *vq, vq->free_head = 0; } +static void virtqueue_reinit_split(struct vring_virtqueue *vq) +{ + struct virtio_device *vdev = vq->vq.vdev; + int size, i; + + memset(vq->split.vring.desc, 0, vq->split.queue_size_in_bytes); + + size = sizeof(struct vring_desc_state_split) * vq->split.vring.num; + memset(vq->split.desc_state, 0, size); + + size = sizeof(struct vring_desc_extra) * vq->split.vring.num; + memset(vq->split.desc_extra, 0, size); + + for (i = 0; i < vq->split.vring.num - 1; i++) + vq->split.desc_extra[i].next = i + 1; + + vring_virtqueue_init_split(vq, vdev, true); +} + static void vring_virtqueue_attach_split(struct vring_virtqueue *vq, struct vring vring, struct vring_desc_state_split *desc_state,