From patchwork Thu Oct 29 17:49:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 7520111 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C2867BEEA4 for ; Thu, 29 Oct 2015 17:50:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EAF72206F0 for ; Thu, 29 Oct 2015 17:50:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFEE72061D for ; Thu, 29 Oct 2015 17:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757910AbbJ2RuH (ORCPT ); Thu, 29 Oct 2015 13:50:07 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:37832 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752215AbbJ2RuF (ORCPT ); Thu, 29 Oct 2015 13:50:05 -0400 Received: by wmff134 with SMTP id f134so29432346wmf.0 for ; Thu, 29 Oct 2015 10:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=l9fCgen4O+UlLsnjybdBTkJUZXfkowK3huhSXo7sKYM=; b=UoZO/Xvw8ltc7i0XM00yHaB5lFftNrS1jJjjs8GkWSQwejVeiMSFKsL+lqh5RayHdP Wx1oL3gDh70eUmbCINC2bppw7xeAYPsJKS+eHarnXbZvzkTH0Ajug3zNcdAmQfRkI9it qGNopY40X0Ii/jRWK6uYUROvQ0lQJVr5TjbOsNvrbiqzgtPNjmABrVKMiNbYPTIxo31f TkQmfPbOvqLcOLwUh7VcfNbEqQ+sE9TdyHV4abM0IgTIx1943WQfnDJT4ng5dGS2Uaw1 ZQI6blh0ynKrUV1UAK4xLJw8IkL9YVqEgIWC0R5EebJERvCBc9iwi3ncVA9Ll3HVKHIW Re7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=l9fCgen4O+UlLsnjybdBTkJUZXfkowK3huhSXo7sKYM=; b=d1+poaaDjbIf78Op5gRHT32lxW4kkdDAOcVjVuQR5wQ1U/bqZMQZZRSAN0TeK+maHB MVY/MX+FEDL1krNQ5Ll7gL4mwWGPKE0uzgnWsOyr3X6E8m9i+OnyY0SFzUBk86qWJO2Z +CfXYnqt4TKOWYmpNGnQ/i5g6kV1dbsGJ0nADlFbWGSqb9/UXUvZdElSQG6CBdCt9U8N vA3wBmaGVIkZBMeDMhf2xX7N688qdp3q3yFD3LfvVKaS13NAbRvmGKyyUWepbCmYGTdZ vOZamTrDmEjIifJ4v1aWnf3/NFQhv6mLh6PAe5Xt+n7IBue4OMJ600/B72cWZb58ZHYL 8sYg== X-Gm-Message-State: ALoCoQmIBr7xJUGWVWiOHp28eVTaW6+ttT/+2x3uX8Xk97FXaBfkuZFJxLEWO9fUnLkQpdPAKFDZ X-Received: by 10.28.174.139 with SMTP id x133mr8847895wme.100.1446141003852; Thu, 29 Oct 2015 10:50:03 -0700 (PDT) Received: from new-host-3.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id m143sm4629776wmb.1.2015.10.29.10.50.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Oct 2015 10:50:03 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, will.deacon@arm.com Cc: suravee.suthikulpanit@amd.com, christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2] vfio/type1: handle case where IOMMU does not support PAGE_SIZE size Date: Thu, 29 Oct 2015 17:49:42 +0000 Message-Id: <1446140982-4059-1-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current vfio_pgsize_bitmap code hides the supported IOMMU page sizes smaller than PAGE_SIZE. As a result, in case the IOMMU does not support PAGE_SIZE page, the alignment check on map/unmap is done with larger page sizes, if any. This can fail although mapping could be done with pages smaller than PAGE_SIZE. This patch modifies vfio_pgsize_bitmap implementation so that, in case the IOMMU supports page sizes smaller than PAGE_SIZE we pretend PAGE_SIZE is supported and hide sub-PAGE_SIZE sizes. That way the user will be able to map/unmap buffers whose size/ start address is aligned with PAGE_SIZE. Pinning code uses that granularity while iommu driver can use the sub-PAGE_SIZE size to map the buffer. Signed-off-by: Eric Auger Signed-off-by: Alex Williamson Acked-by: Will Deacon --- This was tested on AMD Seattle with 64kB page host. ARM MMU 401 currently expose 4kB, 2MB and 1GB page support. With a 64kB page host, the map/unmap check is done against 2MB. Some alignment check fail so VFIO_IOMMU_MAP_DMA fail while we could map using 4kB IOMMU page size. v1 -> v2: - correct PAGE_HOST type in comment and commit msg - Add Will's R-b RFC -> PATCH v1: - move all modifications in vfio_pgsize_bitmap following Alex' suggestion to expose a fake PAGE_SIZE support - restore WARN_ON's --- drivers/vfio/vfio_iommu_type1.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 57d8c37..59d47cb 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -403,13 +403,26 @@ static void vfio_remove_dma(struct vfio_iommu *iommu, struct vfio_dma *dma) static unsigned long vfio_pgsize_bitmap(struct vfio_iommu *iommu) { struct vfio_domain *domain; - unsigned long bitmap = PAGE_MASK; + unsigned long bitmap = ULONG_MAX; mutex_lock(&iommu->lock); list_for_each_entry(domain, &iommu->domain_list, next) bitmap &= domain->domain->ops->pgsize_bitmap; mutex_unlock(&iommu->lock); + /* + * In case the IOMMU supports page sizes smaller than PAGE_SIZE + * we pretend PAGE_SIZE is supported and hide sub-PAGE_SIZE sizes. + * That way the user will be able to map/unmap buffers whose size/ + * start address is aligned with PAGE_SIZE. Pinning code uses that + * granularity while iommu driver can use the sub-PAGE_SIZE size + * to map the buffer. + */ + if (bitmap & ~PAGE_MASK) { + bitmap &= PAGE_MASK; + bitmap |= PAGE_SIZE; + } + return bitmap; }