From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 322622F4A for ; Fri, 12 Apr 2024 03:51:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712893910; cv=none; b=HowyXlnU1FZP1mlr6NEXlbchK003f+Ypluv27GS9C/meCH/JiKuO+wTNnzbCE5esec64j68Nn37uM5cw29lvo94YHRWtj7IPelepdhdnGJHP4+cn7eYcBgLG2OGT5f4cJAiX6k1qlgaJKaTpx0WMDqP73deTWn0QHG2qHX6IfCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712893910; c=relaxed/simple; bh=k8NPmLHb7VcvG/I1xAtlykNpAPN7h2//v5aR2565ZXc=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To; b=DD2ePeR0W4y8De4ylI2n+by6vk//1VqtsR2LpriGr/tM44HrC4fxOWJ/aIoa3zv58fariG6YqE/12/U0boZEDbuPoz31r0aKoZD5Uv1qWkTKFPRHHMEkNgtgPG0byiJHHPJakWTT8zaE9TL8Ppkb/pWUF53pDSfkabKy4TvUuQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=nU6VTF61; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="nU6VTF61" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1712893899; h=Message-ID:Subject:Date:From:To; bh=nLQq2C5f+HDUM/3iQjQBwSnuQxU6DtazhwiQIJpzSD0=; b=nU6VTF617nycj+3FomFwGM6s95vX+NQClc+o8VdjldCIzPUpNZmjPVsV8ZmO/LomzZgv2I2ZOeUMyIdvxnyibjOB5ojFYfpKDV0A1Pxf2d8t13Yn1ZihgvIwdpu5Hq8qvbW5piETVRZw8VFE9n/hS2Fo4fulLfH1Sb5DyWzz0NI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0W4MqNih_1712893898; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W4MqNih_1712893898) by smtp.aliyun-inc.com; Fri, 12 Apr 2024 11:51:39 +0800 Message-ID: <1712893694.0185902-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH vhost 1/6] virtio_ring: introduce dma map api for page Date: Fri, 12 Apr 2024 11:48:14 +0800 From: Xuan Zhuo To: Alexander Lobakin Cc: , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , References: <20240411025127.51945-1-xuanzhuo@linux.alibaba.com> <20240411025127.51945-2-xuanzhuo@linux.alibaba.com> <1db181fd-8d08-4f6d-b32f-20d06029360c@intel.com> In-Reply-To: <1db181fd-8d08-4f6d-b32f-20d06029360c@intel.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: On Thu, 11 Apr 2024 13:45:28 +0200, Alexander Lobakin wrote: > From: Xuan Zhuo > Date: Thu, 11 Apr 2024 10:51:22 +0800 > > > The virtio-net big mode sq will use these APIs to map the pages. > > > > dma_addr_t virtqueue_dma_map_page_attrs(struct virtqueue *_vq, struct page *page, > > size_t offset, size_t size, > > enum dma_data_direction dir, > > unsigned long attrs); > > void virtqueue_dma_unmap_page_attrs(struct virtqueue *_vq, dma_addr_t addr, > > size_t size, enum dma_data_direction dir, > > unsigned long attrs); > > > > Signed-off-by: Xuan Zhuo > > --- > > drivers/virtio/virtio_ring.c | 52 ++++++++++++++++++++++++++++++++++++ > > include/linux/virtio.h | 7 +++++ > > 2 files changed, 59 insertions(+) > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > index 70de1a9a81a3..1b9fb680cff3 100644 > > --- a/drivers/virtio/virtio_ring.c > > +++ b/drivers/virtio/virtio_ring.c > > @@ -3100,6 +3100,58 @@ void virtqueue_dma_unmap_single_attrs(struct virtqueue *_vq, dma_addr_t addr, > > } > > EXPORT_SYMBOL_GPL(virtqueue_dma_unmap_single_attrs); > > > > +/** > > + * virtqueue_dma_map_page_attrs - map DMA for _vq > > + * @_vq: the struct virtqueue we're talking about. > > + * @page: the page to do dma > > + * @offset: the offset inside the page > > + * @size: the size of the page to do dma > > + * @dir: DMA direction > > + * @attrs: DMA Attrs > > + * > > + * The caller calls this to do dma mapping in advance. The DMA address can be > > + * passed to this _vq when it is in pre-mapped mode. > > + * > > + * return DMA address. Caller should check that by virtqueue_dma_mapping_error(). > > + */ > > +dma_addr_t virtqueue_dma_map_page_attrs(struct virtqueue *_vq, struct page *page, > > + size_t offset, size_t size, > > + enum dma_data_direction dir, > > + unsigned long attrs) > > +{ > > + struct vring_virtqueue *vq = to_vvq(_vq); > > + > > + if (!vq->use_dma_api) > > + return page_to_phys(page) + offset; > > page_to_phys() and the actual page DMA address may differ. See > page_to_dma()/virt_to_dma(). I believe this is not correct. For the virtio, if use_dma_api is false, we do not try to get the dma address. We try to get the physical address. > > > + > > + return dma_map_page_attrs(vring_dma_dev(vq), page, offset, size, dir, attrs); > > +} > > +EXPORT_SYMBOL_GPL(virtqueue_dma_map_page_attrs); > > Could you try make these functions static inlines and run bloat-o-meter? > They seem to be small and probably you'd get better performance. YES. But struct vring_virtqueue is in the .c file, we must do that with moving structure to the .h file. I plan to do that in the future. Thanks > > > + > > +/** > > + * virtqueue_dma_unmap_page_attrs - unmap DMA for _vq > > + * @_vq: the struct virtqueue we're talking about. > > + * @addr: the dma address to unmap > > + * @size: the size of the buffer > > + * @dir: DMA direction > > + * @attrs: DMA Attrs > > + * > > + * Unmap the address that is mapped by the virtqueue_dma_map_* APIs. > > + * > > + */ > > +void virtqueue_dma_unmap_page_attrs(struct virtqueue *_vq, dma_addr_t addr, > > + size_t size, enum dma_data_direction dir, > > + unsigned long attrs) > > +{ > > + struct vring_virtqueue *vq = to_vvq(_vq); > > + > > + if (!vq->use_dma_api) > > + return; > > + > > + dma_unmap_page_attrs(vring_dma_dev(vq), addr, size, dir, attrs); > > +} > > +EXPORT_SYMBOL_GPL(virtqueue_dma_unmap_page_attrs); > > + > > /** > > * virtqueue_dma_mapping_error - check dma address > > * @_vq: the struct virtqueue we're talking about. > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > > index 26c4325aa373..d6c699553979 100644 > > --- a/include/linux/virtio.h > > +++ b/include/linux/virtio.h > > @@ -228,6 +228,13 @@ dma_addr_t virtqueue_dma_map_single_attrs(struct virtqueue *_vq, void *ptr, size > > void virtqueue_dma_unmap_single_attrs(struct virtqueue *_vq, dma_addr_t addr, > > size_t size, enum dma_data_direction dir, > > unsigned long attrs); > > +dma_addr_t virtqueue_dma_map_page_attrs(struct virtqueue *_vq, struct page *page, > > + size_t offset, size_t size, > > + enum dma_data_direction dir, > > + unsigned long attrs); > > +void virtqueue_dma_unmap_page_attrs(struct virtqueue *_vq, dma_addr_t addr, > > + size_t size, enum dma_data_direction dir, > > + unsigned long attrs); > > int virtqueue_dma_mapping_error(struct virtqueue *_vq, dma_addr_t addr); > > > > bool virtqueue_dma_need_sync(struct virtqueue *_vq, dma_addr_t addr); > > Thanks, > Olek