Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp698739rdb; Sun, 3 Sep 2023 06:44:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMRXpPJiyqwJ/jPu5ESBDSLT+eGvFo7F8zuHBgh4KiC9aPK6ikFqV5QBD6ekLtT+w/Bvzb X-Received: by 2002:a05:6512:234d:b0:4fd:fd97:a77b with SMTP id p13-20020a056512234d00b004fdfd97a77bmr5558688lfu.50.1693748665675; Sun, 03 Sep 2023 06:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693748665; cv=none; d=google.com; s=arc-20160816; b=oBqIfWxKPuQVg3HWLaYIIOWBLIKR1cJa3zJIWuLVjT8jovc+zqVAdUUk2XADGihM8S VgxxopU0vYN9S91Alxgx6RyfcAxrXYgdAuMpZJ2HCJSzY3l1dpJR7YRikGvJtxqUqWf/ 5OVH/shpHjQflkITLQxQURJK7u2kEe8GBICqDAvpzcds6X+juu3Wq2/fU4LWGEJxZaST +1GevAEKncHdGl4022aekbUiOSc805Encj2J5KaYzazAakZ50mcg9PxhzNQlBmvKlt07 1WXFBak3BUV/PJobMvnL9cmrkzElb79vOaVCNjpEVwOZSygCLCEkEuHJcLM5+vMfQ+eh Fitg== 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=RWrW3IXDdS4xE/wZuQOi6zTQSFFQc/ERMEs8N5p1ObA=; fh=iCi4dBnWQb876cpEziGrcCqRXsvZuswRmKC+Mb5f+1E=; b=XJ44GFCeBjZDCHVU/wR11slx9vhmpq84Bhlm4RNASK18zzIjcgVZvAu3cYrTNBrx9W OMmGCoy7oLpMEWCXIZrpFLxTKwsn1uIjqv8pvd959xhXfOA+hQD0SkQhaJSmxKw7Sn8e 0hMmwAVt6+MW5oDK2ZMRSwhKwJKwfVHm8jFU1DbmFJdaaPVSbWjdfiTwM05iJ5/c2YD3 wIusys8pzbGgyYWAPzdnYGTTy/CI35frJglDJJdAPqmuxFNgp2IFATdQBu8iI/uul6n5 uYW8K8GzY718C4MCrn6gLYSqLR4dcrACMNincAB7Kkzhgp6kAurRoUNJb9RXW6rN46Rr rAbQ== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pg9-20020a170907204900b0098804fbcff0si4886804ejb.709.2023.09.03.06.43.56; Sun, 03 Sep 2023 06:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345089AbjIASCj (ORCPT + 99 others); Fri, 1 Sep 2023 14:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbjIASCb (ORCPT ); Fri, 1 Sep 2023 14:02:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 083E3FD for ; Fri, 1 Sep 2023 11:02:28 -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 5D2B8FEC; Fri, 1 Sep 2023 11:03:06 -0700 (PDT) Received: from [10.57.5.33] (unknown [10.57.5.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5ACC73F8A4; Fri, 1 Sep 2023 11:02:26 -0700 (PDT) Message-ID: <58fbd72b-32bc-c6da-15b2-0b8a284df60a@arm.com> Date: Fri, 1 Sep 2023 19:02:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH 1/3] iommu/io-pgtable-arm: Add nents_per_pgtable in struct io_pgtable_cfg Content-Language: en-GB To: Nicolin Chen , Will Deacon Cc: jgg@nvidia.com, joro@8bytes.org, jean-philippe@linaro.org, apopple@nvidia.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev References: <0fe68babdb3a07adf024ed471fead4e3eb7e703f.1692693557.git.nicolinc@nvidia.com> <61f9b371-7c45-26b1-ec0f-600765280c89@arm.com> <20230830214958.GA30121@willie-the-truck> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 2023-09-01 01:08, Nicolin Chen wrote: > Hi Will/Robin, > > On Thu, Aug 31, 2023 at 10:39:15AM -0700, Nicolin Chen wrote: > >> Though I have not dig enough, I assume that this worst case could >> happen to SVA too, since the IOTLB invalidation is from MMU code. >> But the same worst case might not happen to non-SVA pathway, i.e. >> TLBI ops for IO Page Table doesn't really benefit from this? >> >> With that being questioned, I got Robin's remarks that it wouldn't >> be easy to decide the arbitrary number, so we could just take the >> worst case from SVA pathway as the common threshold. >> >> Then, SVA uses the CPU page table, so perhaps we should highlight >> that SMMU sets the threshold directly reusing the MAX_TLBI_OPS of >> CPU page table rather than calculating from IO page table, though >> both of them are in the same format? > > Our test team encountered a soft lockup in this path today: > -------------------------------------------------------------------- > watchdog: BUG: soft lockup - CPU#244 stuck for 26s! That's a lot of TLBIs! > pstate: 83400009 (Nzcv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--) > pc : arm_smmu_cmdq_issue_cmdlist+0x178/0xa50 > lr : arm_smmu_cmdq_issue_cmdlist+0x150/0xa50 > sp : ffff8000d83ef290 > x29: ffff8000d83ef290 x28: 000000003b9aca00 x27: 0000000000000000 > x26: ffff8000d83ef3c0 x25: da86c0812194a0e8 x24: 0000000000000000 > x23: 0000000000000040 x22: ffff8000d83ef340 x21: ffff0000c63980c0 > x20: 0000000000000001 x19: ffff0000c6398080 x18: 0000000000000000 > x17: 0000000000000000 x16: 0000000000000000 x15: ffff3000b4a3bbb0 > x14: ffff3000b4a30888 x13: ffff3000b4a3cf60 x12: 0000000000000000 > x11: 0000000000000000 x10: 0000000000000000 x9 : ffffc08120e4d6bc > x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000048cfa > x5 : 0000000000000000 x4 : 0000000000000001 x3 : 000000000000000a > x2 : 0000000080000000 x1 : 0000000000000000 x0 : 0000000000000001 > Call trace: > arm_smmu_cmdq_issue_cmdlist+0x178/0xa50 > __arm_smmu_tlb_inv_range+0x118/0x254 > arm_smmu_tlb_inv_range_asid+0x6c/0x130 > arm_smmu_mm_invalidate_range+0xa0/0xa4 > __mmu_notifier_invalidate_range_end+0x88/0x120 > unmap_vmas+0x194/0x1e0 > unmap_region+0xb4/0x144 > do_mas_align_munmap+0x290/0x490 > do_mas_munmap+0xbc/0x124 > __vm_munmap+0xa8/0x19c > __arm64_sys_munmap+0x28/0x50 > invoke_syscall+0x78/0x11c > el0_svc_common.constprop.0+0x58/0x1c0 > do_el0_svc+0x34/0x60 > el0_svc+0x2c/0xd4 > el0t_64_sync_handler+0x114/0x140 > el0t_64_sync+0x1a4/0x1a8 > -------------------------------------------------------------------- > > > I think it is the same problem that we fixed in tlbflush.h using > MAX_TLBI_OPS. So, I plan to send a cleaner bug fix (cc stable): > -------------------------------------------------------------------- > 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 a5a63b1c947e..e3ea7d2a6308 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 > @@ -186,6 +186,9 @@ static void arm_smmu_free_shared_cd(struct arm_smmu_ctx_desc *cd) > } > } > > +/* Copid from arch/arm64/include/asm/tlbflush.h to avoid similar soft lockups */ > +#define MAX_TLBI_OPS (1 << (PAGE_SHIFT - 3)) > + > static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, > struct mm_struct *mm, > unsigned long start, unsigned long end) > @@ -201,9 +204,14 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, > */ > size = end - start; > > - if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) > - arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, > - PAGE_SIZE, false, smmu_domain); > + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) { > + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_RANGE_INV) && > + size >= MAX_TLBI_OPS * PAGE_SIZE) > + arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); > + else > + arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, > + PAGE_SIZE, false, smmu_domain); > + } > arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size); > } > -------------------------------------------------------------------- > > What do you think about it? Looks reasonable to me - I think it's the right shape to foreshadow the bigger refactoring we discussed, and I can't object to using PAGE_{SIZE,SHIFT} for the calculation when it's specifically in the context of SVA. Thanks, Robin.