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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E4B7C4332F for ; Wed, 20 Apr 2022 08:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376629AbiDTIJV (ORCPT ); Wed, 20 Apr 2022 04:09:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376630AbiDTIJR (ORCPT ); Wed, 20 Apr 2022 04:09:17 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF0FE23 for ; Wed, 20 Apr 2022 01:06:31 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id n11so839924qvl.0 for ; Wed, 20 Apr 2022 01:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=Erq3+piETQp5RWzwuFjK9X3j+PcBZrBcFwHVVHWoNkc5BLWhm6a6xeNm8TCZz2SOL8 f5Db0959Jq5aYJtp62b5f3klqBty+15MCTFgQzNSRZFsRH7sSum1c9xYV9cJkvWcQrXn lTLPc0WNET0R6aBwyHs/6kHn+AJ+AHByzu4tXlVvhInBxtkYVVb9QZcSiYlPCI7XLmFw 6kkMedNi4WCOvlFG9LzxCwYng8kuqoTzqJj3JbT/EW7K5UXkuiXGhwwe8G7I3xgcZYLs XSnCh97TCEtwi+0c0rDQ3NM5FUGwg8QqMKG/QtBB8EosVzAot/QMT+/pVVNGavnZ0MmA sHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=wi39RtefvFoHJF7pHVKHDFeedwUw6IfskKq/tzJqVjLubpDcFceoM4CUyrS8x8K0+U B7rZdZc+YnREaP7fP1rLZ4G3DYGNfE8aj93srMG5u3rFIBOWs5dvi2lUQG1XXuNfUXI2 Y4P625y/mGVtbilQNJ+1aMDhEsewoKSmuz2dfU5pMFfPFCVTG2cR9/e/NxnVxFCnIsBR EMFOmcMMz4GVFe7RYMEdGOmw+Wod5S/l/KxKJEOFpxryE5IExRY4mefD3Zr/hNu1hCfw R6td1FukpNpvxKIRd3tu1eTBbppGb9th7AnQJRPlaMXlQoQS3y+y3Rb4kpCsm3v7qioC HDcg== X-Gm-Message-State: AOAM531TUbHtUkMOTfAJoF0ZvBYqraG8laKN7SsHn8deb7W6hYnyaBat XJq52V4ySVlhqicAZ9ZKajODTA== X-Google-Smtp-Source: ABdhPJwAhnapy/3QfM8gMgmTzWAzita1u/CrFffinAcEwTa3eqdvUFvcrn3uzoKu1buIbLYYEdt1Vw== X-Received: by 2002:ad4:5b8f:0:b0:446:646a:a508 with SMTP id 15-20020ad45b8f000000b00446646aa508mr8529527qvp.113.1650441990983; Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id p3-20020a05620a15e300b0069e5b556f75sm1128265qkm.5.2022.04.20.01.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Date: Wed, 20 Apr 2022 09:06:02 +0100 From: Jean-Philippe Brucker To: Nicolin Chen Cc: jgg@ziepe.ca, will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, jacob.jun.pan@linux.intel.com, baolu.lu@linux.intel.com, fenghua.yu@intel.com, rikard.falkeborn@gmail.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Message-ID: References: <20220419210158.21320-1-nicolinc@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220419210158.21320-1-nicolinc@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 19, 2022 at 02:01:58PM -0700, Nicolin Chen wrote: > The arm_smmu_mm_invalidate_range function is designed to be called > by mm core for Shared Virtual Addressing purpose between IOMMU and > CPU MMU. However, the ways of two subsystems defining their "end" > addresses are slightly different. IOMMU defines its "end" address > using the last address of an address range, while mm core defines > that using the following address of an address range: > > include/linux/mm_types.h: > unsigned long vm_end; > /* The first byte after our end address ... > > This mismatch resulted in an incorrect calculation for size so it > failed to be page-size aligned. Further, it caused a dead loop at > "while (iova < end)" check in __arm_smmu_tlb_inv_range function. > > This patch fixes the issue by doing the calculation correctly. > > Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops") > Cc: stable@vger.kernel.org > Signed-off-by: Nicolin Chen Thanks for the fix, I guess we didn't catch this earlier because our test platforms didn't support range invalidation, so __arm_smmu_tlb_inv_range() would always use PAGE_SIZE as increment. Reviewed-by: Jean-Philippe Brucker > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > index 22ddd05bbdcd..c623dae1e115 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > @@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, > { > struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); > struct arm_smmu_domain *smmu_domain = smmu_mn->domain; > - size_t size = end - start + 1; > + size_t size; > + > + /* > + * The mm_types defines vm_end as the first byte after the end address, > + * different from IOMMU subsystem using the last address of an address > + * range. So do a simple translation here by calculating size correctly. > + */ > + size = end - start; > > if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) > arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, > -- > 2.17.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 Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2CC1C433EF for ; Wed, 20 Apr 2022 08:06:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 4B1DB41979; Wed, 20 Apr 2022 08:06:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FASzGbtLUr6D; Wed, 20 Apr 2022 08:06:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id C34AF4193B; Wed, 20 Apr 2022 08:06:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 98CB4C002F; Wed, 20 Apr 2022 08:06:34 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 110ACC002C for ; Wed, 20 Apr 2022 08:06:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E3CD04093B for ; Wed, 20 Apr 2022 08:06:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=linaro.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 7tfuueLg6M7b for ; Wed, 20 Apr 2022 08:06:32 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1348D404D5 for ; Wed, 20 Apr 2022 08:06:31 +0000 (UTC) Received: by mail-qv1-xf35.google.com with SMTP id h13so818908qvr.2 for ; Wed, 20 Apr 2022 01:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=Erq3+piETQp5RWzwuFjK9X3j+PcBZrBcFwHVVHWoNkc5BLWhm6a6xeNm8TCZz2SOL8 f5Db0959Jq5aYJtp62b5f3klqBty+15MCTFgQzNSRZFsRH7sSum1c9xYV9cJkvWcQrXn lTLPc0WNET0R6aBwyHs/6kHn+AJ+AHByzu4tXlVvhInBxtkYVVb9QZcSiYlPCI7XLmFw 6kkMedNi4WCOvlFG9LzxCwYng8kuqoTzqJj3JbT/EW7K5UXkuiXGhwwe8G7I3xgcZYLs XSnCh97TCEtwi+0c0rDQ3NM5FUGwg8QqMKG/QtBB8EosVzAot/QMT+/pVVNGavnZ0MmA sHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=J4xwD3K02D1qZdESP0aifzqVLqyCseIDnNzVsqc/1a9J+DTF5YaIiRNKsElFB+GTn0 TEoaNpq9t0b7ZJDe7Q3DjUDnDfd3PoBMm8kS5MmLJPOdAgqNwNeCaA4TGVtfeYGJ+Pk7 6LKsugoHNXNjrZWiq9x76sf7twoeEOZFRdR4qgdfPAIs24b6yZO6MIhW1J/SreyZgCVr vkLLSJ2kS5Df+GrXEHfSd/sj5+SDt1E5yVtHS709Jo4LzlnfRGKAvi6eUrBs6Ji2ITOe 63rzyNw4fkVs3WOXi86CAUDAAe+cfkmm4mlTgXQMiwwcfPpCWMPQh8bwpWmZfsuRXJpV ZoPQ== X-Gm-Message-State: AOAM531xRrKroULbSYsCDDInY0v8RJzKgJO04ffKDOCUom35shr/7TZV lp38toEuzBdgXzpbYSRD3CttqA== X-Google-Smtp-Source: ABdhPJwAhnapy/3QfM8gMgmTzWAzita1u/CrFffinAcEwTa3eqdvUFvcrn3uzoKu1buIbLYYEdt1Vw== X-Received: by 2002:ad4:5b8f:0:b0:446:646a:a508 with SMTP id 15-20020ad45b8f000000b00446646aa508mr8529527qvp.113.1650441990983; Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id p3-20020a05620a15e300b0069e5b556f75sm1128265qkm.5.2022.04.20.01.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Date: Wed, 20 Apr 2022 09:06:02 +0100 From: Jean-Philippe Brucker To: Nicolin Chen Subject: Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Message-ID: References: <20220419210158.21320-1-nicolinc@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220419210158.21320-1-nicolinc@nvidia.com> Cc: fenghua.yu@intel.com, robin.murphy@arm.com, linux-kernel@vger.kernel.org, rikard.falkeborn@gmail.com, jgg@ziepe.ca, iommu@lists.linux-foundation.org, stable@vger.kernel.org, will@kernel.org, linux-arm-kernel@lists.infradead.org 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" On Tue, Apr 19, 2022 at 02:01:58PM -0700, Nicolin Chen wrote: > The arm_smmu_mm_invalidate_range function is designed to be called > by mm core for Shared Virtual Addressing purpose between IOMMU and > CPU MMU. However, the ways of two subsystems defining their "end" > addresses are slightly different. IOMMU defines its "end" address > using the last address of an address range, while mm core defines > that using the following address of an address range: > > include/linux/mm_types.h: > unsigned long vm_end; > /* The first byte after our end address ... > > This mismatch resulted in an incorrect calculation for size so it > failed to be page-size aligned. Further, it caused a dead loop at > "while (iova < end)" check in __arm_smmu_tlb_inv_range function. > > This patch fixes the issue by doing the calculation correctly. > > Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops") > Cc: stable@vger.kernel.org > Signed-off-by: Nicolin Chen Thanks for the fix, I guess we didn't catch this earlier because our test platforms didn't support range invalidation, so __arm_smmu_tlb_inv_range() would always use PAGE_SIZE as increment. Reviewed-by: Jean-Philippe Brucker > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > index 22ddd05bbdcd..c623dae1e115 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > @@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, > { > struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); > struct arm_smmu_domain *smmu_domain = smmu_mn->domain; > - size_t size = end - start + 1; > + size_t size; > + > + /* > + * The mm_types defines vm_end as the first byte after the end address, > + * different from IOMMU subsystem using the last address of an address > + * range. So do a simple translation here by calculating size correctly. > + */ > + size = end - start; > > if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) > arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, > -- > 2.17.1 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E731C433EF for ; Wed, 20 Apr 2022 08:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sQW76cxft47yGSqsGQDgcV15go9AVJ2PFkrEWYBqdSI=; b=glbj5OiSbk+48X gX5AEPRC4pesxi5qVRF6Gu1m8ToroqpnCj+8Npde0pT0NAbMAnjKHkar7mfkkUdbsOtaRlF+mBBNh LCMuEi3mX28UyDYELguWImK8bMmoEpbQxorhA95MHPslxJ7YCmlD8hUrnH/cVla7zf9eW1jHGDhzr HwnAa+u3NqOqfzBZds5fPNm5CVD3v1zTxZ1eOs8C1hjA//2BW6RIlcj3UwX7i4DMijSEbBvF1Mo71 1yJ4Q1qIWukQO5iZ/OyEhaWvly0vvHh00Tl2IDDQ+ikL6iXB5DHEA+WNSMGXtWVDq5KWb+5/ngynJ 6WDZ6iDkM9RKEByGh0KQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nh5MG-007zHx-Kw; Wed, 20 Apr 2022 08:06:41 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nh5MB-007zFo-My for linux-arm-kernel@lists.infradead.org; Wed, 20 Apr 2022 08:06:37 +0000 Received: by mail-qv1-xf34.google.com with SMTP id dw17so794929qvb.9 for ; Wed, 20 Apr 2022 01:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=Erq3+piETQp5RWzwuFjK9X3j+PcBZrBcFwHVVHWoNkc5BLWhm6a6xeNm8TCZz2SOL8 f5Db0959Jq5aYJtp62b5f3klqBty+15MCTFgQzNSRZFsRH7sSum1c9xYV9cJkvWcQrXn lTLPc0WNET0R6aBwyHs/6kHn+AJ+AHByzu4tXlVvhInBxtkYVVb9QZcSiYlPCI7XLmFw 6kkMedNi4WCOvlFG9LzxCwYng8kuqoTzqJj3JbT/EW7K5UXkuiXGhwwe8G7I3xgcZYLs XSnCh97TCEtwi+0c0rDQ3NM5FUGwg8QqMKG/QtBB8EosVzAot/QMT+/pVVNGavnZ0MmA sHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=F0zmSg9xQd1DHzMpiuM84w9dmmbdQ6gU0u22uG4V/JdBpeTNPUlWmWu8st9BhG1IKZ 79R0De/iZd9AoiJN+hdXTNzS40km7m6yptE9p2VJDF4zLmvlSRm2zqTRBgHodef3sJQv itr2SnDVhePTulyptgX+MnYneHD1FUJg1k5rxYwZEUC3Nro5PxgaxjTUB0I36gmAPcxb rkB+6KbXcQwQWD8qbqP/HOZcn37/BvVqY181yGHMJiB6TPmZS/gbedlTgXn73uYbtIC4 8fhJrg76dJ90Ur3qlH/hfmDHCLPxgbOCMm0lqVGnlIpJecVG5UKHcL6cmRUx3h42qpxu gOrw== X-Gm-Message-State: AOAM532vjG69zfaVjtAuLCq0yVDxS1XaNWeYWM6n5L8xaHQDU8PpG4ik tBULCNl74UCwlOqyEtKcJtRTmg== X-Google-Smtp-Source: ABdhPJwAhnapy/3QfM8gMgmTzWAzita1u/CrFffinAcEwTa3eqdvUFvcrn3uzoKu1buIbLYYEdt1Vw== X-Received: by 2002:ad4:5b8f:0:b0:446:646a:a508 with SMTP id 15-20020ad45b8f000000b00446646aa508mr8529527qvp.113.1650441990983; Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id p3-20020a05620a15e300b0069e5b556f75sm1128265qkm.5.2022.04.20.01.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 01:06:30 -0700 (PDT) Date: Wed, 20 Apr 2022 09:06:02 +0100 From: Jean-Philippe Brucker To: Nicolin Chen Cc: jgg@ziepe.ca, will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, jacob.jun.pan@linux.intel.com, baolu.lu@linux.intel.com, fenghua.yu@intel.com, rikard.falkeborn@gmail.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Message-ID: References: <20220419210158.21320-1-nicolinc@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220419210158.21320-1-nicolinc@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220420_010635_806897_389E34EF X-CRM114-Status: GOOD ( 26.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Apr 19, 2022 at 02:01:58PM -0700, Nicolin Chen wrote: > The arm_smmu_mm_invalidate_range function is designed to be called > by mm core for Shared Virtual Addressing purpose between IOMMU and > CPU MMU. However, the ways of two subsystems defining their "end" > addresses are slightly different. IOMMU defines its "end" address > using the last address of an address range, while mm core defines > that using the following address of an address range: > > include/linux/mm_types.h: > unsigned long vm_end; > /* The first byte after our end address ... > > This mismatch resulted in an incorrect calculation for size so it > failed to be page-size aligned. Further, it caused a dead loop at > "while (iova < end)" check in __arm_smmu_tlb_inv_range function. > > This patch fixes the issue by doing the calculation correctly. > > Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops") > Cc: stable@vger.kernel.org > Signed-off-by: Nicolin Chen Thanks for the fix, I guess we didn't catch this earlier because our test platforms didn't support range invalidation, so __arm_smmu_tlb_inv_range() would always use PAGE_SIZE as increment. Reviewed-by: Jean-Philippe Brucker > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > index 22ddd05bbdcd..c623dae1e115 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > @@ -183,7 +183,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, > { > struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); > struct arm_smmu_domain *smmu_domain = smmu_mn->domain; > - size_t size = end - start + 1; > + size_t size; > + > + /* > + * The mm_types defines vm_end as the first byte after the end address, > + * different from IOMMU subsystem using the last address of an address > + * range. So do a simple translation here by calculating size correctly. > + */ > + size = end - start; > > if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) > arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel