Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp960227imu; Wed, 23 Jan 2019 08:32:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN4kKOVybYL2RytoR+1KAvKyZ7NURRvfAChnU4Lekhys/8LinAhPoR3Rzlu5NYgY8DS5eGFe X-Received: by 2002:a17:902:24d:: with SMTP id 71mr2766365plc.225.1548261175367; Wed, 23 Jan 2019 08:32:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548261175; cv=none; d=google.com; s=arc-20160816; b=Zv8UImnl+kCYK68mmpiEELK681E5O4rHEQQfDDTT6IdfRol8/OtIvYhZCoiQCoK4/d Xk5PqxYrBNlOO8pYvfizauKLKm7sZaOQxBL8t3bbQZMXHDhP0jNTXcds3mMeTyDciqfk 4KZ8VcqVR+boqc3o62ZyTP/3Y5f6AMO/kWyS0dyVx//RNx68A7toqbhSoi2JgDKo41rO l5mUe6VWjqpSAM+tP9WGQtiaTGtIHYp7Iodwc1/n5P6IEmw2C1u4gQrQTuZw4ikBvtsG 9C4looaB0aFB4QgcCV3xJTRzqt7smkJrE1D8uq9CHJsdpfP5En3davf1TrntyWBCq8MB gybQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=x+fhr+6tA0QJrpj8/5PBQuoIc3UvKJSGCvbqX5tS0To=; b=eCf981ivjuocS9LSQ/lFea3MHrnokTlFJaGcNh0OCz6ShvXYJoVp8aGaSp5S9H77aW jhK5Dyri/01WdyIS185Tt+o1zc4fe0zVwO731TVSu8Z6gZOgahwf/HoyH6QCGFk4YWG4 RndYjkfUO5A19HHK5T0GQDD8Ki/+GoxTYfbhZYsFaqOezBGFFpM6jSNb2I9KtFkQN8vl i1lOfIECdR4Qqh36wWDl+C6CzcdwuspMkALLARzxW2UAz/uZiPk+PE1YBL7DATY6bEVp Y7T8Bs1TO/wztUMEg6HPHa2V6nNwdecnfvOp/k/p0ixX7/8z1NDNDI8Y+nMpWSa9emv3 0sug== 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=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si19501069pgj.493.2019.01.23.08.32.40; Wed, 23 Jan 2019 08:32:55 -0800 (PST) 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=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726829AbfAWQbH (ORCPT + 99 others); Wed, 23 Jan 2019 11:31:07 -0500 Received: from 8bytes.org ([81.169.241.247]:59242 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbfAWQax (ORCPT ); Wed, 23 Jan 2019 11:30:53 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id C807B450; Wed, 23 Jan 2019 17:30:51 +0100 (CET) From: Joerg Roedel To: "Michael S . Tsirkin" , Jason Wang , Konrad Rzeszutek Wilk , Christoph Hellwig Cc: Jens Axboe , virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, jfehlig@suse.com, jon.grimm@amd.com, brijesh.singh@amd.com, joro@8bytes.org, jroedel@suse.de Subject: [PATCH 4/5] virtio: Introduce virtio_max_dma_size() Date: Wed, 23 Jan 2019 17:30:48 +0100 Message-Id: <20190123163049.24863-5-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190123163049.24863-1-joro@8bytes.org> References: <20190123163049.24863-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel This function returns the maximum segment size for a single dma transaction of a virtio device. The possible limit comes from the SWIOTLB implementation in the Linux kernel, that has an upper limit of (currently) 256kb of contiguous memory it can map. Other DMA-API implementations might also have limits. Use the new dma_max_mapping_size() function to determine the maximum mapping size when DMA-API is in use for virtio. Signed-off-by: Joerg Roedel --- drivers/virtio/virtio_ring.c | 10 ++++++++++ include/linux/virtio.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index cd7e755484e3..9ca3fe6af9fa 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -266,6 +266,16 @@ static bool vring_use_dma_api(struct virtio_device *vdev) return false; } +size_t virtio_max_dma_size(struct virtio_device *vdev) +{ + size_t max_segment_size = SIZE_MAX; + + if (vring_use_dma_api(vdev)) + max_segment_size = dma_max_mapping_size(&vdev->dev); + + return max_segment_size; +} + static void *vring_alloc_queue(struct virtio_device *vdev, size_t size, dma_addr_t *dma_handle, gfp_t flag) { diff --git a/include/linux/virtio.h b/include/linux/virtio.h index fa1b5da2804e..673fe3ef3607 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -157,6 +157,8 @@ int virtio_device_freeze(struct virtio_device *dev); int virtio_device_restore(struct virtio_device *dev); #endif +size_t virtio_max_dma_size(struct virtio_device *vdev); + #define virtio_device_for_each_vq(vdev, vq) \ list_for_each_entry(vq, &vdev->vqs, list) -- 2.17.1