Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1152370pxy; Fri, 23 Apr 2021 01:12:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTMlVOVAei4sAIbWyxAsoJ36mye1wbb/OpADiBQBV2gOV+nb8sf70q6JUf1ZjZ2NR9TIYi X-Received: by 2002:a17:907:33cb:: with SMTP id zk11mr2933282ejb.231.1619165558362; Fri, 23 Apr 2021 01:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619165558; cv=none; d=google.com; s=arc-20160816; b=cI3b29eURLAB5TsP/NMQry66x1UYhEDV52w7/45SSm31bncF1uWsIeV7vk1GgzICFa vrRaIaPU91MMYbx0r/2LzQeIq/qZ57IADFMinicRK11nKo3bpU8cgrlMBZBxuYj13ya0 9UG+IBVuqoi5dZJ74nthd+RiEZd8AN2uR4xwJBvmvOqHFOG9YgOvIOrtzQt/7O83zySL htKyBAqm0q3K//KEG/EBJwh87cMoM070GQE03I4hyhGgIulkxbaxio2Ug++UKvnrevnF pX5C/tFMUCoBIMF8UbkeKjINfSLRhu4LQageJFoeeUXKa2C2VdI44jmRxSaP4Y95pV6z bMwQ== 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=pueseaxcZOwlP6qfuGPWprIWYCt1cs/IoMkOSoirRnc=; b=qa1djf34k3kt0tlhVZ2Bblmo0pcRg4zmoIdv+VzuU/6Dwat9Bb71wg3yAme6SZwdZu dr/XwDYyRwQowRUXWal3VhkjQpZgozpEUA0TExT7cj9y7qxFwBfv6MnQBhFHulC2XEOb YhOkukwQhoxvMXahuwCj02NaBOVpX31LiTtwI8LPeXnDLeKUsQMfCnGCqCTqe4HwFc2z mTMY8GqBTPPsxW/BFU1EktxIEAUya7gSCQB1qECEJUkBT/iwsI+H97gy9MT5yAdZPpZV ZgA7GZTnFlGU+7ibGMifK5djglxHvP7NyNNB+IuE+KYSdi5xpDAOFIeyU872Ua2yA2rq JOFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PLYDdndL; 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 gy24si4743262ejb.740.2021.04.23.01.12.14; Fri, 23 Apr 2021 01:12:38 -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=PLYDdndL; 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 S241493AbhDWILn (ORCPT + 99 others); Fri, 23 Apr 2021 04:11:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37408 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241447AbhDWILf (ORCPT ); Fri, 23 Apr 2021 04:11:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619165459; 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=pueseaxcZOwlP6qfuGPWprIWYCt1cs/IoMkOSoirRnc=; b=PLYDdndLKbq2qNwB9IG7BCqxgYZnSnWSrliCuc/W1Oya6txr14fcXHp8Rg8VlPYjM1/CX4 bHhXJBtvENzchkkdf0pwxeJB8rCkB7qtnoaHhnuFS+ma8stdXYv8rhqW4BvHRqkhl3wbSN 4KfWPYiNBLV+LEMMMauBuIXC5I6TR+8= 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-256-Z8zLkpJfMtaKIIZasDKaKw-1; Fri, 23 Apr 2021 04:10:57 -0400 X-MC-Unique: Z8zLkpJfMtaKIIZasDKaKw-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 55CBB18397A8; Fri, 23 Apr 2021 08:10:56 +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 7B7825C541; Fri, 23 Apr 2021 08:10:51 +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 5/7] virtio_ring: introduce virtqueue_desc_add_split() Date: Fri, 23 Apr 2021 16:09:40 +0800 Message-Id: <20210423080942.2997-6-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 This patch introduces a helper for storing descriptor in the descriptor table for split virtqueue. Signed-off-by: Jason Wang --- drivers/virtio/virtio_ring.c | 39 ++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 5509c2643fb1..11dfa0dc8ec1 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -412,6 +412,20 @@ static struct vring_desc *alloc_indirect_split(struct virtqueue *_vq, return desc; } +static inline unsigned int virtqueue_add_desc_split(struct virtqueue *vq, + struct vring_desc *desc, + unsigned int i, + dma_addr_t addr, + unsigned int len, + u16 flags) +{ + desc[i].flags = cpu_to_virtio16(vq->vdev, flags); + desc[i].addr = cpu_to_virtio64(vq->vdev, addr); + desc[i].len = cpu_to_virtio32(vq->vdev, len); + + return virtio16_to_cpu(vq->vdev, desc[i].next); +} + static inline int virtqueue_add_split(struct virtqueue *_vq, struct scatterlist *sgs[], unsigned int total_sg, @@ -484,11 +498,9 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, if (vring_mapping_error(vq, addr)) goto unmap_release; - desc[i].flags = cpu_to_virtio16(_vq->vdev, VRING_DESC_F_NEXT); - desc[i].addr = cpu_to_virtio64(_vq->vdev, addr); - desc[i].len = cpu_to_virtio32(_vq->vdev, sg->length); prev = i; - i = virtio16_to_cpu(_vq->vdev, desc[i].next); + i = virtqueue_add_desc_split(_vq, desc, i, addr, sg->length, + VRING_DESC_F_NEXT); } } for (; n < (out_sgs + in_sgs); n++) { @@ -497,11 +509,11 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, if (vring_mapping_error(vq, addr)) goto unmap_release; - desc[i].flags = cpu_to_virtio16(_vq->vdev, VRING_DESC_F_NEXT | VRING_DESC_F_WRITE); - desc[i].addr = cpu_to_virtio64(_vq->vdev, addr); - desc[i].len = cpu_to_virtio32(_vq->vdev, sg->length); prev = i; - i = virtio16_to_cpu(_vq->vdev, desc[i].next); + i = virtqueue_add_desc_split(_vq, desc, i, addr, + sg->length, + VRING_DESC_F_NEXT | + VRING_DESC_F_WRITE); } } /* Last one doesn't continue. */ @@ -515,13 +527,10 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, if (vring_mapping_error(vq, addr)) goto unmap_release; - vq->split.vring.desc[head].flags = cpu_to_virtio16(_vq->vdev, - VRING_DESC_F_INDIRECT); - vq->split.vring.desc[head].addr = cpu_to_virtio64(_vq->vdev, - addr); - - vq->split.vring.desc[head].len = cpu_to_virtio32(_vq->vdev, - total_sg * sizeof(struct vring_desc)); + virtqueue_add_desc_split(_vq, vq->split.vring.desc, + head, addr, + total_sg * sizeof(struct vring_desc), + VRING_DESC_F_INDIRECT); } /* We're using some buffers from the free list. */ -- 2.25.1