Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3717700pxj; Mon, 7 Jun 2021 18:58:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww4YaguMY7D5+I+nAgMni6YPrtu/wn3flQnlNkVKEY5XiIejiFg9ff8+l5Rv65/Rw/HCUn X-Received: by 2002:aa7:dc4c:: with SMTP id g12mr23444712edu.258.1623117539781; Mon, 07 Jun 2021 18:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623117539; cv=none; d=google.com; s=arc-20160816; b=RS7pIfjKOjHSysCRwnYTsQTn3bltz+D8LmzcKPpotlF9hBBRPzFdEEUV4uUnOywPR7 Dy0aMonjCWovw+kDdde/DkuejM59Ra3MT4eqZ0ZMSvhpZVn+pRY2oUpmk+g3G8hRSBOD Hm5Cq/MiGLPt/JzlBb8AJO+M8ZYjcreELNVvYuzTr49yxPSsDqDoz5C97192lqV0IZ7V RS+ynf+h64c1VSGd82H/7eBSOgyfHL+b76TGqWo5BVcZyTmCC6B1+pLX1JynfDbMmqOW d+w0A0w+pRRuNo6McZ3mTBpSmcuJRLLXs/8PF9J5ebn1rdJHuMUnTVR3ByR3k0a7F2ZY vq0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a5Q03kPB9N31Dxz5JpgFwNRhEHR7Ck7FkWGxbrLez1o=; b=O5UuhID+TSQ/2qE7vzNmdq7j1zAWw0P6xjEFgv7qF+Tb7Fa4nmNIVnht24WWN7OWyz zfNLvx0ilKhrltQLgPWT0L6T26RZk49tXAjEG2Jao5P9ViLIAFbp1zWMF63cXc4/pofp qy44ZojTKerILgQKJvO6/1Qq32F90LBhWFQZlu/IxFZBa2HpY/+opNvsGPmG57f7QNjB Bfh30hH8whQWl55fbWbdDhlp59o7WOISDi14LT1tJc9Ok3lb2qgc6KwumtveqQgoc+/f /skNHYzJiZrjnvyYYH0H7Tl57tYoeCB104O5GRcCEIfMM6iwW0RX9B7+RpuaTtT4oP3A InmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MmLsD0VY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si14058511ejl.661.2021.06.07.18.58.35; Mon, 07 Jun 2021 18:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MmLsD0VY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231543AbhFHB6S (ORCPT + 99 others); Mon, 7 Jun 2021 21:58:18 -0400 Received: from mail-pf1-f171.google.com ([209.85.210.171]:37856 "EHLO mail-pf1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231542AbhFHB6S (ORCPT ); Mon, 7 Jun 2021 21:58:18 -0400 Received: by mail-pf1-f171.google.com with SMTP id y15so14493961pfl.4 for ; Mon, 07 Jun 2021 18:56:26 -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=a5Q03kPB9N31Dxz5JpgFwNRhEHR7Ck7FkWGxbrLez1o=; b=MmLsD0VYye5jr8qllapIW+sULNF1AqgI9y2nx0BegR+bTMbQ2Hfsv+TVMqg8Eqfnbl mfq0nXiK0HKYzuDVdn0d6/aC4iMXJF8oZ/YQhRuhW/KJS7zvmnNKKP9Z1Xpp7NsdRmBY lFxqMbHPN55xVsBkDq/mWF0RQxk73S43HBdlnln22aD8EJQbR0eEzqhV2atNiUNlSWMW H0gyaW/LvxoWJM1RK8db7LbeOpjHrQAXDbqQKdqYfX5AbNexcyKTrsupYfM9OAUtO1C9 VzxRKtyZvoXDM/aaoHk3lbldaavnmLEQXO2Td98VDXOni+4LmNP/zZgCpTYIV7hwm/mT iJ7A== 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=a5Q03kPB9N31Dxz5JpgFwNRhEHR7Ck7FkWGxbrLez1o=; b=XPWUOCyumufGYbVBIQkK/aCJsIy43LEVNoYXzbTa/wonrEEUGvc7EwjMECr6p6e9kZ IEMW86fuooD1yHJ/EVLK62bPd1CJsBBq2uYXlli4s3qnrXFJE8UKOSMVkze26j6WINYP DCk98ckJwVMziwyszM+geRu1XaZdyAwKEEuYegoTqCsyEc1Xfjh8FxqvT8kQGPIIGDYS mg7up+9NBER+hBzSEZz7RBCVGSJ4RKUu6F6YsD+74W9A7u+3OkZUjTdctsMN+ufBmGlr RFX9OtPHtCQsDTRvWibdreGIKJqSfWIbbPQB4r4U+YHHdiidbcSZmkQ7+4qYFksTWloc twsQ== X-Gm-Message-State: AOAM532GF+OQ7lwzslIpo1gabnSwBtfM4I099Boiqb91MA3RPmooMOhY 9ubizjSYiDoDsOv+zOY6os4ASvDUXjPuxw== X-Received: by 2002:aa7:8114:0:b029:2e9:c437:1121 with SMTP id b20-20020aa781140000b02902e9c4371121mr19464441pfi.7.1623117326092; Mon, 07 Jun 2021 18:55:26 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 18:55:25 -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 4/6] iommu: Factor iommu_iotlb_gather_is_disjoint() out Date: Mon, 7 Jun 2021 11:25:39 -0700 Message-Id: <20210607182541.119756-5-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 Refactor iommu_iotlb_gather_add_page() and factor out the logic that detects whether IOTLB gather range and a new range are disjoint. To be used by the next patch that implements different gathering logic for AMD. 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 --- include/linux/iommu.h | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index f254c62f3720..b5a2bfc68fb0 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -497,6 +497,28 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, iommu_iotlb_gather_init(iotlb_gather); } +/** + * iommu_iotlb_gather_is_disjoint - Checks whether a new range is disjoint + * + * @gather: TLB gather data + * @iova: start of page to invalidate + * @size: size of page to invalidate + * + * Helper for IOMMU drivers to check whether a new range is and the gathered + * range are disjoint. For many IOMMUs, flushing the IOMMU in this case is + * better than merging the two, which might lead to unnecessary invalidations. + */ +static inline +bool iommu_iotlb_gather_is_disjoint(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ + unsigned long start = iova, end = start + size - 1; + + return gather->end != 0 && + (end + 1 < gather->start || start > gather->end + 1); +} + + /** * iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation * @gather: TLB gather data @@ -533,20 +555,16 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, struct iommu_iotlb_gather *gather, unsigned long iova, size_t size) { - unsigned long start = iova, end = start + size - 1; - /* * If the new page is disjoint from the current range or is mapped at * a different granularity, then sync the TLB so that the gather * structure can be rewritten. */ - if (gather->pgsize != size || - end + 1 < gather->start || start > gather->end + 1) { - if (gather->pgsize) - iommu_iotlb_sync(domain, gather); - gather->pgsize = size; - } + if ((gather->pgsize && gather->pgsize != size) || + iommu_iotlb_gather_is_disjoint(gather, iova, size)) + iommu_iotlb_sync(domain, gather); + gather->pgsize = size; iommu_iotlb_gather_add_range(gather, iova, size); } @@ -730,6 +748,13 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, { } +static inline +bool iommu_iotlb_gather_is_disjoint(struct iommu_iotlb_gather *gather, + unsigned long iova, size_t size) +{ + return false; +} + static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather, unsigned long iova, size_t size) { -- 2.25.1