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 B95ABC4743F for ; Tue, 8 Jun 2021 01:55:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B14F261168 for ; Tue, 8 Jun 2021 01:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbhFHB51 (ORCPT ); Mon, 7 Jun 2021 21:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbhFHB5T (ORCPT ); Mon, 7 Jun 2021 21:57:19 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0457FC06178B for ; Mon, 7 Jun 2021 18:55:27 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id z26so14494106pfj.5 for ; Mon, 07 Jun 2021 18:55:27 -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=PVlNy6GFZskXwhmJM3/KpQE5O4kPgimeLb6iehn44jE=; b=rtJTHteosGHqvGerLxDOacK+OAEMS78keadnAtsslhFWaQd76IG1I30qATHXr3U1+O u3Pcn1u1ZaZRTEe+TJKtRGrJsu6jCGVCIaVNvZwLnv+haxMJUIcv4V7FcTwSWlQWKaKn aA0hbuDVmbkf2rTc/lUjXn3S3OncimcpFr4HfORnYrLWfc1K+Uot7v/FN8M94eahUWmD qmAvOgQ6/N2w8+Mx6URrug9t+oTsSGpkjqJGShkmyVJCZjEEW7vu1eHcJL8gTPC8b2Qm 79m+BHGTzTBpdNAbBzIXch0lgWWTlWIoWCgZcFZuIkRbKHuhsEnuJfpovzQZ+NPg29Bc hHVg== 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=PVlNy6GFZskXwhmJM3/KpQE5O4kPgimeLb6iehn44jE=; b=RB05NyoMHcW8bNneDtjoDn6CHUpUIZKVdvlNDNXpC8300xUqoXFPMH0eHMQagHJijl fvzoXY7qMRjEXY/M8BelnWdVCNw6BpnPAFiMTHuc15J7wrKO0sQCjEHg2FpBwZB7dFZ2 7CUl4Dqr1ChZOpkgU08hbNji59SbwOiPiYba1ZYTzLzmwbZ2eOcgEUloxwmXEssbHFEi Lk6jchUauLURqzESan2caPhlIcMexG9BJlUBz6j+eCBe1WvEN5Gde55pJTXWr0UltzVI uE0e63V/zvfswNdnkqxbUEt9ltYV6Sb7VkMlplTC0fdhK4N7BEv7crHw3HvkwCTQyAzZ VFFQ== X-Gm-Message-State: AOAM531HSFCL42KvSzLVq/cw5WhNqDiF8rewApiGKNL2ng4nsdnSKdZi gqpDC8dVCNvkAd29ovKbPzk= X-Google-Smtp-Source: ABdhPJxVT8efeIufgkaSCDKk6eZ4gB5/q4jKeVg4vhx+g85q5sdx4JTMRcU359SIEQBq5lXjHMHE/g== X-Received: by 2002:a05:6a00:26d8:b029:2ea:1101:8acf with SMTP id p24-20020a056a0026d8b02902ea11018acfmr19317888pfw.67.1623117324738; Mon, 07 Jun 2021 18:55:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 18:55:24 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Joerg Roedel Cc: Robin Murphy , Will Deacon , Jiajun Cao , Lu Baolu , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/6] iommu: Improve iommu_iotlb_gather helpers Date: Mon, 7 Jun 2021 11:25:38 -0700 Message-Id: <20210607182541.119756-4-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: Robin Murphy The Mediatek driver is not the only one which might want a basic address-based gathering behaviour, so although it's arguably simple enough to open-code, let's factor it out for the sake of cleanliness. Let's also take this opportunity to document the intent of these helpers for clarity. 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: Robin Murphy --- Changes from Robin's version: * Added iommu_iotlb_gather_add_range() stub !CONFIG_IOMMU_API * Use iommu_iotlb_gather_add_range() in iommu_iotlb_gather_add_page() --- drivers/iommu/mtk_iommu.c | 5 +---- include/linux/iommu.h | 43 ++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e06b8a0e2b56..0af4a91ac7da 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -523,10 +523,7 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, struct mtk_iommu_domain *dom = to_mtk_domain(domain); unsigned long end = iova + size - 1; - if (gather->start > iova) - gather->start = iova; - if (gather->end < end) - gather->end = end; + iommu_iotlb_gather_add_range(gather, iova, size); return dom->iop->unmap(dom->iop, iova, size, gather); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..f254c62f3720 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -497,6 +497,38 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, iommu_iotlb_gather_init(iotlb_gather); } +/** + * iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation + * @gather: TLB gather data + * @iova: start of page to invalidate + * @size: size of page to invalidate + * + * Helper for IOMMU drivers to build arbitrarily-sized invalidation commands + * where only the address range matters, and simply minimising intermediate + * syncs is preferred. + */ +static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ + unsigned long end = iova + size - 1; + + if (gather->start > iova) + gather->start = iova; + if (gather->end < end) + gather->end = end; +} + +/** + * iommu_iotlb_gather_add_page - Gather for page-based TLB invalidation + * @domain: IOMMU domain to be invalidated + * @gather: TLB gather data + * @iova: start of page to invalidate + * @size: size of page to invalidate + * + * Helper for IOMMU drivers to build invalidation commands based on individual + * pages, or with page size/table level hints which cannot be gathered if they + * differ. + */ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size) @@ -515,11 +547,7 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, gather->pgsize = size; } - if (gather->end < end) - gather->end = end; - - if (gather->start > start) - gather->start = start; + iommu_iotlb_gather_add_range(gather, iova, size); } /* PCI device grouping function */ @@ -702,6 +730,11 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, { } +static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ +} + static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { return 0; -- 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 592B4C47082 for ; Tue, 8 Jun 2021 01:55:33 +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 1F4F561278 for ; Tue, 8 Jun 2021 01:55:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F4F561278 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 247D0608A6; Tue, 8 Jun 2021 01:55:32 +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 5fgREZguUKvx; Tue, 8 Jun 2021 01:55:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id D892D608B5; Tue, 8 Jun 2021 01:55:27 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7EC6BC0022; Tue, 8 Jun 2021 01:55:27 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 116F6C0001 for ; Tue, 8 Jun 2021 01:55:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E1D6D83A91 for ; Tue, 8 Jun 2021 01:55:25 +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 4eZk8lCIPsx2 for ; Tue, 8 Jun 2021 01:55:25 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by smtp1.osuosl.org (Postfix) with ESMTPS id 617B883A8F for ; Tue, 8 Jun 2021 01:55:25 +0000 (UTC) Received: by mail-pg1-x530.google.com with SMTP id 6so15275461pgk.5 for ; Mon, 07 Jun 2021 18:55:25 -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=PVlNy6GFZskXwhmJM3/KpQE5O4kPgimeLb6iehn44jE=; b=rtJTHteosGHqvGerLxDOacK+OAEMS78keadnAtsslhFWaQd76IG1I30qATHXr3U1+O u3Pcn1u1ZaZRTEe+TJKtRGrJsu6jCGVCIaVNvZwLnv+haxMJUIcv4V7FcTwSWlQWKaKn aA0hbuDVmbkf2rTc/lUjXn3S3OncimcpFr4HfORnYrLWfc1K+Uot7v/FN8M94eahUWmD qmAvOgQ6/N2w8+Mx6URrug9t+oTsSGpkjqJGShkmyVJCZjEEW7vu1eHcJL8gTPC8b2Qm 79m+BHGTzTBpdNAbBzIXch0lgWWTlWIoWCgZcFZuIkRbKHuhsEnuJfpovzQZ+NPg29Bc hHVg== 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=PVlNy6GFZskXwhmJM3/KpQE5O4kPgimeLb6iehn44jE=; b=SxvD7fl2Ssq34G31E/E0Rd+ZNt83wlRh9g63bTReDGpMwQrriKZncHwmWPxWA6HknE MrDGpSctAxhBmlBgJVpUXSKrwawKSxLtqpTn0kXGjS+G24hZcN+0akh4lknUKKE6F6Di DqdL2mODdmkDoFlpX8r0DTHUXS+icJ9mI39dvSM4HrCCpBSsn8I80iDI38jbZRD+ChLX tcc2N79Z7PbFJ4lUxUZ4iaZ3b4uZjk2AokMAFqaD+aWzv6YKJmeG3PXPXffucz55exjN cQc7o2yE7ZOmSHNDNTYl18j/YERRcNqdEYfwYiKeQ9FMxqmIaGyeypeinGvpbPe1yV+l AKNA== X-Gm-Message-State: AOAM532cLNTC0fDfUXClm0obri12duEDr1lsntEbAlyyw2LcQ16ZgmpG rEOtXj1T+U/i5vGYNEfG9/Y= X-Google-Smtp-Source: ABdhPJxVT8efeIufgkaSCDKk6eZ4gB5/q4jKeVg4vhx+g85q5sdx4JTMRcU359SIEQBq5lXjHMHE/g== X-Received: by 2002:a05:6a00:26d8:b029:2ea:1101:8acf with SMTP id p24-20020a056a0026d8b02902ea11018acfmr19317888pfw.67.1623117324738; Mon, 07 Jun 2021 18:55:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 18:55:24 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: Joerg Roedel Subject: [PATCH v3 3/6] iommu: Improve iommu_iotlb_gather helpers Date: Mon, 7 Jun 2021 11:25:38 -0700 Message-Id: <20210607182541.119756-4-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, 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: Robin Murphy The Mediatek driver is not the only one which might want a basic address-based gathering behaviour, so although it's arguably simple enough to open-code, let's factor it out for the sake of cleanliness. Let's also take this opportunity to document the intent of these helpers for clarity. 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: Robin Murphy --- Changes from Robin's version: * Added iommu_iotlb_gather_add_range() stub !CONFIG_IOMMU_API * Use iommu_iotlb_gather_add_range() in iommu_iotlb_gather_add_page() --- drivers/iommu/mtk_iommu.c | 5 +---- include/linux/iommu.h | 43 ++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e06b8a0e2b56..0af4a91ac7da 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -523,10 +523,7 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, struct mtk_iommu_domain *dom = to_mtk_domain(domain); unsigned long end = iova + size - 1; - if (gather->start > iova) - gather->start = iova; - if (gather->end < end) - gather->end = end; + iommu_iotlb_gather_add_range(gather, iova, size); return dom->iop->unmap(dom->iop, iova, size, gather); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 32d448050bf7..f254c62f3720 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -497,6 +497,38 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, iommu_iotlb_gather_init(iotlb_gather); } +/** + * iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation + * @gather: TLB gather data + * @iova: start of page to invalidate + * @size: size of page to invalidate + * + * Helper for IOMMU drivers to build arbitrarily-sized invalidation commands + * where only the address range matters, and simply minimising intermediate + * syncs is preferred. + */ +static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ + unsigned long end = iova + size - 1; + + if (gather->start > iova) + gather->start = iova; + if (gather->end < end) + gather->end = end; +} + +/** + * iommu_iotlb_gather_add_page - Gather for page-based TLB invalidation + * @domain: IOMMU domain to be invalidated + * @gather: TLB gather data + * @iova: start of page to invalidate + * @size: size of page to invalidate + * + * Helper for IOMMU drivers to build invalidation commands based on individual + * pages, or with page size/table level hints which cannot be gathered if they + * differ. + */ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size) @@ -515,11 +547,7 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, gather->pgsize = size; } - if (gather->end < end) - gather->end = end; - - if (gather->start > start) - gather->start = start; + iommu_iotlb_gather_add_range(gather, iova, size); } /* PCI device grouping function */ @@ -702,6 +730,11 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, { } +static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ +} + static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) { return 0; -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu