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 67E32C4320E for ; Fri, 23 Jul 2021 17:02:12 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 3116560E8F for ; Fri, 23 Jul 2021 17:02:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3116560E8F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F2846405A8; Fri, 23 Jul 2021 17:02:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DCTo39bPzYCv; Fri, 23 Jul 2021 17:02:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id C04F4405A5; Fri, 23 Jul 2021 17:02:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ABC65C001A; Fri, 23 Jul 2021 17:02:10 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7B9BEC000E for ; Fri, 23 Jul 2021 17:02:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5AA2183B13 for ; Fri, 23 Jul 2021 17:02:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1RBLplN0vP98 for ; Fri, 23 Jul 2021 17:02:07 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by smtp1.osuosl.org (Postfix) with ESMTPS id DBE9583B28 for ; Fri, 23 Jul 2021 17:02:07 +0000 (UTC) Received: by mail-pj1-x1031.google.com with SMTP id u9-20020a17090a1f09b029017554809f35so9773464pja.5 for ; Fri, 23 Jul 2021 10:02:07 -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=slYU5MKZy1pznr8txKKfecz25fYTNW0V6jsxSivepmk=; b=eNqSDwzZspgyoWvb541jLbHpFMYfhzKhc+j3JuBGS+aRfE/7v+YmsqJSLKU1DKI1JS 7DmX0XKHQtdAYUJ2BkOhliZDqBENPAkOFI5s+xQ7rECm3jcibM4tNRgjmDRJ0iwDIpaP Sq+ObbeqLwddjeit86X8AFTKxjFx39qaCuNYhRaPvf/KkHyGdQB7DpFlobwELlk9rW34 rFOApBAfNnaLxSvkpUpPfyZfvoVyImhpDkt9p+wwTiB6gjTZ0u0ngP6MZSIJbNelxEld qWVDX6ESlBPso7gJsOMhrv76pRy6ChT68Xp7Nc1FyeThoQLYh5cDptCcKqUJ4M3dhtNp QV5w== 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=slYU5MKZy1pznr8txKKfecz25fYTNW0V6jsxSivepmk=; b=DIzl6uyKUvDKQgcqgFT6wKxjJowNy/tcQgiCuLZFwol/O1GE+OoUGjfvjg1cIZw5hS Utq6qGo4AQvi35TuXt3VrCy1LEKZt4TpocsdVe2gZPdJiC/p5j7Tm6CEnqywvspRp3CS amu3PPdwGz2GqeN3fqVKTbJ+hU8mwEbHw3uuwvJamthhyZGw+SlXdo3za5V6oN0yxjXO t8/389I5sZCjF1m8l0MtI3/OVutRuOyU8FfA0DocXILUtjaNIEF9Pf3xcST0Y4YRStj6 ED1RWw0E67uQ8baafeqnh+NpciXnfsrzACev2hXQv00Xj0lzb0743ssdSh9U1Z5uHCj6 T4hw== X-Gm-Message-State: AOAM531gOBtwHQoBcR/F+9U95Rz/FVdzthYzaFw+1s4Wi7r2FX3WSHTF 7G/MK/0cyfJzJX+cKJQcL3k= X-Google-Smtp-Source: ABdhPJzmDny3ny6U0xrtZ/luyrjS4pHkXAVQ+nbzP6NjpbxaTALEi/JwKIlJ8ArHJ8/6RkWsrKCUDg== X-Received: by 2002:a17:902:b188:b029:11b:1549:da31 with SMTP id s8-20020a170902b188b029011b1549da31mr4473243plr.7.1627059727165; Fri, 23 Jul 2021 10:02:07 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id d15sm33479004pfl.82.2021.07.23.10.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 10:02:06 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Joerg Roedel Subject: [PATCH v6 6/7] iommu/amd: Sync once for scatter-gather operations Date: Fri, 23 Jul 2021 02:32:08 -0700 Message-Id: <20210723093209.714328-7-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210723093209.714328-1-namit@vmware.com> References: <20210723093209.714328-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 f5d5f2124391..7846fcb1e92b 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2022,6 +2022,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) @@ -2040,10 +2050,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; } @@ -2223,6 +2231,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