Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp324860imm; Thu, 31 May 2018 00:44:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLZp8R2Nl3dOdwYrhvz39nMPOD8wgHTcGFQubdGBvFrGxLKysrtEMgHxgry7R99PhuqFMBC X-Received: by 2002:a17:902:aa98:: with SMTP id d24-v6mr5940664plr.185.1527752692847; Thu, 31 May 2018 00:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527752692; cv=none; d=google.com; s=arc-20160816; b=G/ScOR75+Di0TRdVuGk5rvyMgBBX/DQTl3AB2KMpXfQe41N7F1vU2BwiNKvewAIOae isAqc1FetAubxDsZ9egjKlJKFIpE5cz9KwUyR/4OW87wEd3DqLYcIWeHs5IQ6xoIl5hl 7oYZpzj8dXL1tYuQMN6wNb+pLSGECIqXnd5EywzoP/Fw0/WG0ihIzL6Gl7m22yCpn7EH 3xcqMNuZDKWPQAaIyiMui9/xHBsiWq2QU9PM3aaf7rchAxGdiftZSg6FIygpzA7buszW npAHSJdoIRCx4RL3W2ighV9otAfccmFY4pQdesYwde+L+PopVCk33orc73lOsEy/voXW JOiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=1PZeytOcFaKnwy8ctkTb2JoXAWZC/oy12fQ+bA3bY+M=; b=WUwdUjMdEleBTdrrqHKDbFW47kMaSi3lXKJCn1KzVZnayO0IgUzuN9GX3s1qAVdIF5 g9ANwNNsq2iFZweJw+vPN+DXZKkI4blX+w8L29QkYCqN4SH2/BxIyY2uCUdBtN1/89wg 0f924U65fcRCptQMATyO58m7twUocSqHmRtjAtvKXvyHyqIkRFh3uERtnWPzGBj75TNs 7fRT7l108GirpId2FfSM85KF27cE3QZdwE6B5IvByn4of3HSY5DHno0dvTlmKL+4qyli x63cUN5OXRSxtrae1UYSZHHBKO4/fjWKITDQRJfR696KyzO3rPu7qY7Pr7QDX/ngwUUc pWTQ== 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 v69-v6si36576598pfd.341.2018.05.31.00.44.39; Thu, 31 May 2018 00:44:52 -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 S1754120AbeEaHnz (ORCPT + 99 others); Thu, 31 May 2018 03:43:55 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:49010 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754076AbeEaHnq (ORCPT ); Thu, 31 May 2018 03:43:46 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D0D58D03BD0C; Thu, 31 May 2018 15:43:42 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 15:43:34 +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 4/7] iommu/amd: make sure TLB to be flushed before IOVA freed Date: Thu, 31 May 2018 15:42:46 +0800 Message-ID: <1527752569-18020-5-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> References: <1527752569-18020-1-git-send-email-thunder.leizhen@huawei.com> 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 Although the mapping has already been removed in the page table, it maybe still exist in TLB. Suppose the freed IOVAs is reused by others before the flush operation completed, the new user can not correctly access to its meomory. Signed-off-by: Zhen Lei --- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 8fb8c73..93aa389 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2402,9 +2402,9 @@ static void __unmap_single(struct dma_ops_domain *dma_dom, } if (amd_iommu_unmap_flush) { - dma_ops_free_iova(dma_dom, dma_addr, pages); domain_flush_tlb(&dma_dom->domain); domain_flush_complete(&dma_dom->domain); + dma_ops_free_iova(dma_dom, dma_addr, pages); } else { pages = __roundup_pow_of_two(pages); queue_iova(&dma_dom->iovad, dma_addr >> PAGE_SHIFT, pages, 0); -- 1.8.3