Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp813968pxb; Fri, 22 Apr 2022 11:44:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkCkGwDyEs5fSm3cOy8lVcQYXV14FmeAbevtVUVlGBSlCmghQPX8d7fDw2B19gNWtDZf7D X-Received: by 2002:a17:90b:4b42:b0:1d2:c218:5bb5 with SMTP id mi2-20020a17090b4b4200b001d2c2185bb5mr17843469pjb.7.1650653045736; Fri, 22 Apr 2022 11:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650653045; cv=none; d=google.com; s=arc-20160816; b=iZtVwobVdMDmX65Vehf3mwpRP07oLZmenTwwEiy6pp+d1+Ui+2OEQejgdJez1aE81j rDGBuGYYuS5rUZGi9M7FeAfQslKWVi4wmQSCu8q3dwRtFi517m/y+WZcU/Ilp8yUYyVd mSOSwVh2eQ+9IqNZJ67TkHerrMEO5f+mUA3bDiUgoq3p1BWpD8XjlmZvkouH1x1hrcoo povck6m613bN4WQt9jF7QD0X5m6TCD6UoQZaf8CRPph9fTlUmfdo0VBYi9hszFoFBba/ NZVFW+wCKMPTFSQtiIGJU9TOJY936C45wST4X6FSN04qkpksyT8ljzlQrILTW0y6IWPV 88xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+eE3WMmFBHt9qFLIivrenNFjT6R/u5U6XLtVu6wSVa4=; b=nrmbZYqRZ+zKsvtflet7LIQ5s2Xw4+pC30eGnaeVTzqZPLruIhD7lfx/eDrIFRQ/xL WT/64NNe0pyMmKoKxDEcI9ch8+9w2mSu0dIelIYL9fClD13+mDafZ82ysLerABaZF1Wh Ki0X0dIQlVOv+ZDenk/gzAnHoEaTcc3Z/IqcBxECFYOKVcTMxn4BFj0Fsvoap1X8Hifr Ya5xeXYmrtudngO7QfgEUt3E85+SYY51+bqmsfKdFtoO9pnLoVf/MJ6j/kkKbW3V4Qom 5Dmf7m4vW8KC+JFJtgh8ekJP/SsVERybSnita2t2gKEpVrrv3yHa6Gvs9HlztpslA0Ys WVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Erq3+piE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c70-20020a633549000000b003a9eb7f65b0si9637393pga.439.2022.04.22.11.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:44:05 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Erq3+piE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54D1C165EFE; Fri, 22 Apr 2022 11:12:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376627AbiDTIJU (ORCPT + 99 others); Wed, 20 Apr 2022 04:09:20 -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-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> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 >