Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp863961pxb; Fri, 22 Apr 2022 12:56:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfo+4h2yIs1rWSCF7KL/bAd+6lRlaW8v6fqVlVEVg4ud2Ytl0563YOaPEoKUBcSCXjxbEr X-Received: by 2002:a63:4e59:0:b0:39d:69fe:eaa with SMTP id o25-20020a634e59000000b0039d69fe0eaamr5341590pgl.340.1650657416891; Fri, 22 Apr 2022 12:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650657416; cv=none; d=google.com; s=arc-20160816; b=PNT8tl9v/4alItCM4QnLKz7RoeSk3+K5TrTtSgLOCWLl0zjpMn0dQZJ/1gDdP849CP Yh96DXYK5QhTDH2XHX7TbiOpKvn/1r6+AAzVYurbz1CdFxD6ZBwNktV1j2dfZDv18HB1 V6hOa43dK6EWdSQUFsRFPZaHP8bYEN+PF354ERDxXePmsiM9r6Ej/2sX8XTNaNBO/0MK tX9HeMFpj8va/ZZ6p+gfPEtMndllAfZpVq3o8K/6i5s3w/sLlkB+hGlRDx+HDhw2vYBJ AnDVDdWziA8uW4h2FnMXYdi5z8WcHQsEExGVTdjxLqaheFJmPuu7KnQy/ilxXcFXZ4F7 czIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=bj+hs8xIkBBx6lQ2XyzXUIz9H5oE3viK6oxeQZAxlrE=; b=kdezvXzWJPy9YGXwqTYMxcm+TWKPVyZlfkPnxI3VXvKAjaZEPP5+hP7NmWVy5+NZAA TbJbC2tR+jvulLFLVoc8SFe9XdqMjUom8SbYZYDELi/avyYhGT1723GPBYw4t77wjcHq qu5SjRu+DjbrYEyUi10sjP1y12VTVjZ5yoJGi3DWgLOu3pl+D7fyWv0qyUS7Ko3IYHKk ALG8wJUIVzuTgPePeZ3WBnZhymZDxxlt5BNTv+OnMvAK1uSspRQQuICqulxm6Gz1IOzM 6HpXCIUH8VoPJTujOS9xoxe2jRXKNJ1ngtPRSl+Yg07wcmTw/P2xih1rT3/f6uj5wFAy a3Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n24-20020a637218000000b003aaa7c9281esi4597032pgc.145.2022.04.22.12.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 786B8247665; Fri, 22 Apr 2022 12:04:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357894AbiDSVI0 (ORCPT + 99 others); Tue, 19 Apr 2022 17:08:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345084AbiDSVIZ (ORCPT ); Tue, 19 Apr 2022 17:08:25 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C90C124977; Tue, 19 Apr 2022 14:05:41 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 899BF13D5; Tue, 19 Apr 2022 14:05:41 -0700 (PDT) Received: from [10.57.41.251] (unknown [10.57.41.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E939B3F766; Tue, 19 Apr 2022 14:05:38 -0700 (PDT) Message-ID: <8a43fed2-5404-26bb-243c-991369451dd8@arm.com> Date: Tue, 19 Apr 2022 22:05:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range() Content-Language: en-GB To: Nicolin Chen , jgg@ziepe.ca, will@kernel.org, joro@8bytes.org, jean-philippe@linaro.org Cc: 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 References: <20220419210158.21320-1-nicolinc@nvidia.com> From: Robin Murphy In-Reply-To: <20220419210158.21320-1-nicolinc@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 2022-04-19 22:01, 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. Reviewed-by: Robin Murphy > Fixes: 2f7e8c553e98d ("iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops") > Cc: stable@vger.kernel.org > Signed-off-by: Nicolin Chen > --- > 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,