Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp324827imm; Thu, 31 May 2018 00:44:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJEyW/TrNmuUI77CvYNfdbDAfMjmgBLqug7wZqLxtT5zVsZgu+mEeMiWMAfCDuYIm931H24 X-Received: by 2002:a65:4487:: with SMTP id l7-v6mr4597373pgq.194.1527752689418; Thu, 31 May 2018 00:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527752689; cv=none; d=google.com; s=arc-20160816; b=vsRmZu+1yXYqr4L6VQpqMbaL2SOaojRJn9Yrh9gmf/hU6wgxG6FVf79JE/0PguE4SZ 9//jRddvzVdTJNL3Q0A6rQ8PE9K8EQ8+51EpDoAkmfg0qZW0utQp1bgJ8ImXaVTFPiIO BtlMgHWKEUDXh93SilXE6HYi/Bnfy6puQBHE8lYZ6siYu5Q+7S0XqKOIr4fq2ooHd3DQ k/YE8tqGDmElZuYxLEI45SLEaTSFxd2jCS2I1vJjUdQnU8u6C844LUj3BT/XblR3WgVB Xnpe1Rnw+JsnmCZ/FY1xEi2WwcLN5Q+SQiendvM2meKF125wVo/Lm8IeWTujXHbftTcp LZ2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=uyWxxxBq9wkSqKd8S305pHrOTzzWm63ErNmwapyFKjY=; b=T231/IhqA2dieoyX01qpZfln6et2h8HEjmTdIafhuPZvy7I8zFpFbIfSPNFxeVuq0v 4PxH3wteOp2Vo/pc0/3Nc6WQ+5meyd+aANYIaZpztdAQGn5IyL2y8L2A+2w2cYxlJqSC aV5NbvrKUEgM/Gwv5SaCB92qgCSfgs4Z2pr1R2SjqRXykeoP8O90QFNhiUhGbA+r2nQL orHMC+vWFTp2YAWijGjcv4Q6BLwSLlpvRYO1e2GRGnOFeyPctuNPUWPppeavZRhbzJtB Sdl71VLLcPoRLQXlSBkTfiiozdc3lNHkdf/G9KTHbpbl4eNbYvPPM/GLVzt7rJBIU/zh hznQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12-v6si35228575pll.360.2018.05.31.00.44.35; Thu, 31 May 2018 00:44:49 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754106AbeEaHnu (ORCPT + 99 others); Thu, 31 May 2018 03:43:50 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50150 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754045AbeEaHnn (ORCPT ); Thu, 31 May 2018 03:43:43 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 012161AE6168E; Thu, 31 May 2018 15:43:37 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 15:43:30 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Matthias Brugger , Rob Clark , Joerg Roedel , linux-mediatek , linux-arm-msm , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei , Hanjun Guo , Libin , Guozhu Li , "Xinwei Hu" Subject: [PATCH 0/7] add non-strict mode support for arm-smmu-v3 Date: Thu, 31 May 2018 15:42:42 +0800 Message-ID: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In common, a IOMMU unmap operation follow the below steps: 1. remove the mapping in page table of the specified iova range 2. execute tlbi command to invalid the mapping which is cached in TLB 3. wait for the above tlbi operation to be finished 4. free the IOVA resource 5. free the physical memory resource This maybe a problem when unmap is very frequently, the combination of tlbi and wait operation will consume a lot of time. A feasible method is put off tlbi and iova-free operation, when accumulating to a certain number or reaching a specified time, execute only one tlbi_all command to clean up TLB, then free the backup IOVAs. Mark as non-strict mode. But it must be noted that, although the mapping has already been removed in the page table, it maybe still exist in TLB. And the freed physical memory may also be reused for others. So a attacker can persistent access to memory based on the just freed IOVA, to obtain sensible data or corrupt memory. So the VFIO should always choose the strict mode. Some may consider put off physical memory free also, that will still follow strict mode. But for the map_sg cases, the memory allocation is not controlled by IOMMU APIs, so it is not enforceable. Fortunately, Intel and AMD have already applied the non-strict mode, and put queue_iova() operation into the common file dma-iommu.c., and my work is based on it. The difference is that arm-smmu-v3 driver will call IOMMU common APIs to unmap, but Intel and AMD IOMMU drivers are not. Below is the performance data of strict vs non-strict for NVMe device: Randomly Read IOPS: 146K(strict) vs 573K(non-strict) Randomly Write IOPS: 143K(strict) vs 513K(non-strict) Zhen Lei (7): iommu/dma: fix trival coding style mistake iommu/arm-smmu-v3: fix the implementation of flush_iotlb_all hook iommu: prepare for the non-strict mode support iommu/amd: make sure TLB to be flushed before IOVA freed iommu/dma: add support for non-strict mode iommu/io-pgtable-arm: add support for non-strict mode iommu/arm-smmu-v3: add support for non-strict mode drivers/iommu/amd_iommu.c | 2 +- drivers/iommu/arm-smmu-v3.c | 16 ++++++++++++--- drivers/iommu/arm-smmu.c | 2 +- drivers/iommu/dma-iommu.c | 41 ++++++++++++++++++++++++++++++-------- drivers/iommu/io-pgtable-arm-v7s.c | 6 +++--- drivers/iommu/io-pgtable-arm.c | 28 ++++++++++++++------------ drivers/iommu/io-pgtable.h | 2 +- drivers/iommu/ipmmu-vmsa.c | 2 +- drivers/iommu/msm_iommu.c | 2 +- drivers/iommu/mtk_iommu.c | 2 +- drivers/iommu/qcom_iommu.c | 2 +- include/linux/iommu.h | 5 +++++ 12 files changed, 76 insertions(+), 34 deletions(-) -- 1.8.3