From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB937C47095 for ; Tue, 8 Jun 2021 01:56:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8BDE61168 for ; Tue, 8 Jun 2021 01:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231566AbhFHB6V (ORCPT ); Mon, 7 Jun 2021 21:58:21 -0400 Received: from mail-pf1-f182.google.com ([209.85.210.182]:35809 "EHLO mail-pf1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231542AbhFHB6U (ORCPT ); Mon, 7 Jun 2021 21:58:20 -0400 Received: by mail-pf1-f182.google.com with SMTP id h12so11666565pfe.2 for ; Mon, 07 Jun 2021 18:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PYSa5dzZqlSBhiWVVfbL3z5005cJpSnxJob3wTcfuvM=; b=Jd5F59np7OwVQO4iLQZZLy20cUm82OhVfYN3mJMZIrXP6qc9avY20mjm1C0Or+RVgB D8jUAnDWyLgze5HS1B/75OyPE1K8d6EUmdEU4BOrxfUP8MxPGnp5PAZS7SaqHSYGUFAx kefMT1zw88Y8HzyexdjUaGhbkOZMZjX7Z7gckJqNzLyalxgUrf8URyI/dI5nknCH1mKu 5jkM/9v7rkj6H45xZQqKt+YeQpa0m0Oe/YrOhkrFbruIyhUXgvMo7eoATEpd4XIb/ipD NCkQVqkdMrjOwgDG6BMhswrXq4trgof6QRXTa9BXWunfeCMfOEvidJVA7yIP7UtHzPZU FTXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PYSa5dzZqlSBhiWVVfbL3z5005cJpSnxJob3wTcfuvM=; b=AA8t+YESQhcMUjbsNjYapfgH/eBa429ZF91YfGCw95AxA7fNJZ/niHzCT39l1xjK5P 6RVt12k1N7Cp/PnoOZHZ7ET+f2xrRcuqV1vdmjO9SqEQ1k9KQ1gnZOekk+r+zRl79Yin Ig0TyL4WXcDX3ZIxLA/HzDOPANLyA+clzRR//IbP45Kny1biQPrUa5tjLqp8U67fehvV aGSyENA5884r+pf/Vxyh0WJhDlYt+nkCel4aazEWJ/jZj//gAUmY5RraqbmJM7/Is+kG 7DPU56lMWHCH4n1csYNUn9u2t3kGaMAKQHfxUdc8fPQ0hb4qYjxKRAPcp64jYYq4+sMk mJzw== X-Gm-Message-State: AOAM530g51O4RfbxEdxCUWu7YlE8fPQpM5+o+Ny2G7a137liwSvVjjpx w2N3BA1qPxacLpcyd2kn5lw= X-Google-Smtp-Source: ABdhPJyQ8lkTxIxUP+pI7+xd1dEjyqRcbeEohR06teOYio4TrTHXUm0jN2/AKARGkcYGzSnUGJH6Ew== X-Received: by 2002:a05:6a00:1893:b029:2ec:a754:570e with SMTP id x19-20020a056a001893b02902eca754570emr13709535pfh.38.1623117328716; Mon, 07 Jun 2021 18:55:28 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id s24sm9284767pfh.104.2021.06.07.18.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 18:55:28 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Joerg Roedel Cc: Nadav Amit , Will Deacon , Jiajun Cao , Robin Murphy , Lu Baolu , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/6] iommu/amd: Sync once for scatter-gather operations Date: Mon, 7 Jun 2021 11:25:41 -0700 Message-Id: <20210607182541.119756-7-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210607182541.119756-1-namit@vmware.com> References: <20210607182541.119756-1-namit@vmware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadav Amit On virtual machines, software must flush the IOTLB after each page table entry update. The iommu_map_sg() code iterates through the given scatter-gather list and invokes iommu_map() for each element in the scatter-gather list, which calls into the vendor IOMMU driver through iommu_ops callback. As the result, a single sg mapping may lead to multiple IOTLB flushes. Fix this by adding amd_iotlb_sync_map() callback and flushing at this point after all sg mappings we set. This commit is followed and inspired by commit 933fcd01e97e2 ("iommu/vt-d: Add iotlb_sync_map callback"). Cc: Joerg Roedel Cc: Will Deacon Cc: Jiajun Cao Cc: Robin Murphy Cc: Lu Baolu Cc: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Nadav Amit --- drivers/iommu/amd/iommu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 128f2e889ced..dd23566f1db8 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2027,6 +2027,16 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, return ret; } +static void amd_iommu_iotlb_sync_map(struct iommu_domain *dom, + unsigned long iova, size_t size) +{ + struct protection_domain *domain = to_pdomain(dom); + struct io_pgtable_ops *ops = &domain->iop.iop.ops; + + if (ops->map) + domain_flush_np_cache(domain, iova, size); +} + static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, phys_addr_t paddr, size_t page_size, int iommu_prot, gfp_t gfp) @@ -2045,10 +2055,8 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, if (iommu_prot & IOMMU_WRITE) prot |= IOMMU_PROT_IW; - if (ops->map) { + if (ops->map) ret = ops->map(ops, iova, paddr, page_size, prot, gfp); - domain_flush_np_cache(domain, iova, page_size); - } return ret; } @@ -2249,6 +2257,7 @@ const struct iommu_ops amd_iommu_ops = { .attach_dev = amd_iommu_attach_device, .detach_dev = amd_iommu_detach_device, .map = amd_iommu_map, + .iotlb_sync_map = amd_iommu_iotlb_sync_map, .unmap = amd_iommu_unmap, .iova_to_phys = amd_iommu_iova_to_phys, .probe_device = amd_iommu_probe_device, -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 796CCC48BD1 for ; Tue, 8 Jun 2021 01:55:38 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 344F060FEE for ; Tue, 8 Jun 2021 01:55:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 344F060FEE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1528A60899; Tue, 8 Jun 2021 01:55:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p8orb9Tpp8kB; Tue, 8 Jun 2021 01:55:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id 0A8976089C; Tue, 8 Jun 2021 01:55:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EC0FEC000E; Tue, 8 Jun 2021 01:55:33 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id B51A3C0001 for ; Tue, 8 Jun 2021 01:55:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 947D06089A for ; Tue, 8 Jun 2021 01:55:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jymVo5noepAz for ; Tue, 8 Jun 2021 01:55:31 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5C76060893 for ; Tue, 8 Jun 2021 01:55:29 +0000 (UTC) Received: by mail-pf1-x431.google.com with SMTP id k15so14500817pfp.6 for ; Mon, 07 Jun 2021 18:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PYSa5dzZqlSBhiWVVfbL3z5005cJpSnxJob3wTcfuvM=; b=Jd5F59np7OwVQO4iLQZZLy20cUm82OhVfYN3mJMZIrXP6qc9avY20mjm1C0Or+RVgB D8jUAnDWyLgze5HS1B/75OyPE1K8d6EUmdEU4BOrxfUP8MxPGnp5PAZS7SaqHSYGUFAx kefMT1zw88Y8HzyexdjUaGhbkOZMZjX7Z7gckJqNzLyalxgUrf8URyI/dI5nknCH1mKu 5jkM/9v7rkj6H45xZQqKt+YeQpa0m0Oe/YrOhkrFbruIyhUXgvMo7eoATEpd4XIb/ipD NCkQVqkdMrjOwgDG6BMhswrXq4trgof6QRXTa9BXWunfeCMfOEvidJVA7yIP7UtHzPZU FTXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PYSa5dzZqlSBhiWVVfbL3z5005cJpSnxJob3wTcfuvM=; b=PwCmI1n3QLC4MUPk3V4KTOPPRRfDdHfI1H9TgaO0J+3PsACbMoKWFGOAc2CguBj2RX oaxD9h7FwDwvpeTgBfcrKLSaDeltdVuzTNdinU3HYtSiJ7fw5dCLaLlKxTPvd2+d2xLS ZNPiDJUrLVIci/ZiRTAM/nbWic4/1cssYTvk4uAbG5VjDChHK+m4xtL2L2VXoZcXTFaK mmusAr4hLsEQcXegK8Tb0yi73sP5cpqdnvAPWrLcWjVvo9rmlPGjJ7PiBdmJGXTVb/nh Irdzi7B9sV5D9Ss45+Som67VdIdeMBn3YdGFPwYmMmzPstHb/KVvKdrusP2olFwtYQtx 52jw== X-Gm-Message-State: AOAM532/XaVsJZV8oSWECEtW08d/g/zN4UDcF96X5x+2/eD4lm6LNyPI LjYPBl82ivjEYZHuWyOjx58= X-Google-Smtp-Source: ABdhPJyQ8lkTxIxUP+pI7+xd1dEjyqRcbeEohR06teOYio4TrTHXUm0jN2/AKARGkcYGzSnUGJH6Ew== X-Received: by 2002:a05:6a00:1893:b029:2ec:a754:570e with SMTP id x19-20020a056a001893b02902eca754570emr13709535pfh.38.1623117328716; Mon, 07 Jun 2021 18:55:28 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id s24sm9284767pfh.104.2021.06.07.18.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 18:55:28 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Joerg Roedel Subject: [PATCH v3 6/6] iommu/amd: Sync once for scatter-gather operations Date: Mon, 7 Jun 2021 11:25:41 -0700 Message-Id: <20210607182541.119756-7-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210607182541.119756-1-namit@vmware.com> References: <20210607182541.119756-1-namit@vmware.com> MIME-Version: 1.0 Cc: Robin Murphy , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Nadav Amit , Jiajun Cao , Will Deacon X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" From: Nadav Amit On virtual machines, software must flush the IOTLB after each page table entry update. The iommu_map_sg() code iterates through the given scatter-gather list and invokes iommu_map() for each element in the scatter-gather list, which calls into the vendor IOMMU driver through iommu_ops callback. As the result, a single sg mapping may lead to multiple IOTLB flushes. Fix this by adding amd_iotlb_sync_map() callback and flushing at this point after all sg mappings we set. This commit is followed and inspired by commit 933fcd01e97e2 ("iommu/vt-d: Add iotlb_sync_map callback"). Cc: Joerg Roedel Cc: Will Deacon Cc: Jiajun Cao Cc: Robin Murphy Cc: Lu Baolu Cc: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Nadav Amit --- drivers/iommu/amd/iommu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 128f2e889ced..dd23566f1db8 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2027,6 +2027,16 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, return ret; } +static void amd_iommu_iotlb_sync_map(struct iommu_domain *dom, + unsigned long iova, size_t size) +{ + struct protection_domain *domain = to_pdomain(dom); + struct io_pgtable_ops *ops = &domain->iop.iop.ops; + + if (ops->map) + domain_flush_np_cache(domain, iova, size); +} + static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, phys_addr_t paddr, size_t page_size, int iommu_prot, gfp_t gfp) @@ -2045,10 +2055,8 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, if (iommu_prot & IOMMU_WRITE) prot |= IOMMU_PROT_IW; - if (ops->map) { + if (ops->map) ret = ops->map(ops, iova, paddr, page_size, prot, gfp); - domain_flush_np_cache(domain, iova, page_size); - } return ret; } @@ -2249,6 +2257,7 @@ const struct iommu_ops amd_iommu_ops = { .attach_dev = amd_iommu_attach_device, .detach_dev = amd_iommu_detach_device, .map = amd_iommu_map, + .iotlb_sync_map = amd_iommu_iotlb_sync_map, .unmap = amd_iommu_unmap, .iova_to_phys = amd_iommu_iova_to_phys, .probe_device = amd_iommu_probe_device, -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu