Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7337838imu; Thu, 31 Jan 2019 08:34:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN5AUAt+mw19Q2P0vSogHOG6nzdC2LEroIybxUFefv7GSg9dxXn6IkNghdTseySmr1XWLvjz X-Received: by 2002:a17:902:9a02:: with SMTP id v2mr36189972plp.180.1548952476142; Thu, 31 Jan 2019 08:34:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548952476; cv=none; d=google.com; s=arc-20160816; b=r6tUlkxVMgnl4WrXe7LMo8VKRfpYpOUY/MzVIOw/vuQLF1XdY7FqtYLbQBsagHlhdN NzzgqsdH+zORvq2kxFJGllYoYWANQmll81/HO4H8BPbYR5fYf9JCGxNJG7l2CWed8Wrd Jaw3XqigzS5ChsO/OUR3FZwxj5g/ONkcmpap4SczY4YRcLu4evo/TIbQUgaFVt4AIraa vvye1yfvlw677JhIhjKoLzknCpCsNpoY0beoey7Zt3pHWSYtBiB1jX/ncR4lNw++RAqm VRow3Q2USgSbmqk1/MKeKT6RSjIBaHVKaONC86WrkuWDt6WqE/QwT6iIEUFjQwGez3Dz ZW7Q== 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=qYJHb96Fwwaldw4WFfAxx2yNvcz/EU+NzLA/Q6jCbBs=; b=tSClNOGO73us2rDHALQbnHGKn/suQtjBB3dq8ZhNzzNLgeW+keKGamp+sX7E6O2J7w auO0dya6zXGovpBtwPiP8/70HE4SPhk53Yh80hbdUp4rZP9VbQAdpw1hHDm03PmBXAy4 a2sKPPjgJQ5nthE678wTG9qVnQm9UkLqk/4kH2w8uU14R/iP7yphIAfrmac4lrU1pR/e d+3kCIEdZzjn1wv26xrcCZfjpYMlnurBZpf2PdzDZScoYSiX7NCXU181iOU6vLQ6a4mt WCGjUGSorI9/mRaYvSrO5c4omtqQiF3IjMJlQ8W6+ZthkDSyxxsXHf2M8adjv8b2KGrT QAww== 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 u123si4576674pgb.516.2019.01.31.08.34.19; Thu, 31 Jan 2019 08:34:36 -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 S2388555AbfAaQeJ (ORCPT + 99 others); Thu, 31 Jan 2019 11:34:09 -0500 Received: from 8bytes.org ([81.169.241.247]:36382 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388485AbfAaQeH (ORCPT ); Thu, 31 Jan 2019 11:34:07 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 48B64292; Thu, 31 Jan 2019 17:34:05 +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, Thomas.Lendacky@amd.com Subject: [PATCH 4/5] virtio: Introduce virtio_max_dma_size() Date: Thu, 31 Jan 2019 17:34:02 +0100 Message-Id: <20190131163403.11363-5-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190131163403.11363-1-joro@8bytes.org> References: <20190131163403.11363-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. Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Christoph Hellwig Signed-off-by: Joerg Roedel --- drivers/virtio/virtio_ring.c | 11 +++++++++++ include/linux/virtio.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index cd7e755484e3..8a31c6862b2b 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -266,6 +266,17 @@ 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; +} +EXPORT_SYMBOL_GPL(virtio_max_dma_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