Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp131673rwb; Fri, 4 Aug 2023 10:09:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0UmOc76qSc/pHh6O11VYqlhDE7iKO+sYU/yVMRdFAWgRSY047+aqacfaLYF50hqeEL4U6 X-Received: by 2002:a17:907:761a:b0:99b:4525:e06c with SMTP id jx26-20020a170907761a00b0099b4525e06cmr1868357ejc.55.1691168958986; Fri, 04 Aug 2023 10:09:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691168958; cv=none; d=google.com; s=arc-20160816; b=E4T/U+fcds4BL5bQTqWFaU9c3PbnCdDzyaJIHNBh4k68xIO7Vf7Xq1EB91XfZzrJT5 kCx18XCGGODwobBfMIZsZX9RNrJGb59uxYKXuQyFlBJhdiwmPilbPim3+AtCR92J7gTs PdZ60jVCO/dttz1I9K4IgsLae2+4WWW0Wf8rVoXeqWO7NT8pW0LdGdH+Myji22EKkKnT WqrmuLzSh0B4rALI8tG/+KC/+CTcHHPK5zkcE6U/nQE3m0BNVW7beaTM9Rzf4izkFs6J jRP/B2v103qRCur1TDnaQ16bdvBk+L5EfJPZk+O2IlLVU/KXpqtoEMhSvlQChcIKLiPp xtag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bnKbiqH8LKwiJiiQgimKnz1aCWM8izZnfbEjKet8pNc=; fh=lBGyDxvK+WZgTBJAyNUhIi/2CoX6SP86zzzRNjU6F0c=; b=HmirV+c27Qw6hK+5qAaqhcsK8sUmsxBGekBOXnEhS2mY9/5kY7Xlp9Iu/+ErRkq7Fr An3jrU/8+ajy5OSkR8SRGBEREZTJAGtI/fpZLlW+WzYDEq2D54WnUQwAxIhrxOfE/cm6 ISdNKvt/X+i6BiYUIu7Csz7gdJeg7gdwJL8zhLMxEEgj1SByDZSiDV28rhyFdGPkRRgm MT4sZEu/JbBiFczHI4PYu80MJcycPXWwi4HmE6Ve8+aQ/VTS7Smb16+CdhpAx+X9M/Nu 7FclkxTjL3GMeM1q6v/kTrVrqjVTZufr1FCckwooE2bgFWiYiwCmT8VkrtNCEosn+JAY qmXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o1xWFrqk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a1709067e0700b00992a096678fsi696520ejr.813.2023.08.04.10.08.40; Fri, 04 Aug 2023 10:09:18 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o1xWFrqk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbjHDQwk (ORCPT + 99 others); Fri, 4 Aug 2023 12:52:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjHDQwi (ORCPT ); Fri, 4 Aug 2023 12:52:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41E24C10 for ; Fri, 4 Aug 2023 09:52:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0723862096 for ; Fri, 4 Aug 2023 16:52:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AAC4C433C7; Fri, 4 Aug 2023 16:52:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691167951; bh=buMAlpQhDwKnRxmVi9Eejmudb/fRIJ7cOINBfet7OBo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o1xWFrqk5qmn3Nzc4P26s8n6svP0A4OStmcEsxPCguXYSNNb9HR7w0bIJ4IR6ed1/ vKhcg4lD0ik0tFxu7dBNyIOitabSek3LdA2x4zlKGbQMY0jX3/QvaoRE09byYit4Q2 7Ogpyzkf9N1y/XVbEr4cEyBfY1mwZkzUNZ3+r/HM2SlpdOXw/9HsmYQdmKqFoyvHUu uKmuTORldBvlWPvecdNG+ZNXacZkBNbPpXM7GTNb25KW0ky+gpgClTesNHqgkw2ADQ bGl06V1+xy9Xcn9xxyNMQHJjcnTngFC6C7slin/1ZgmprMuXbbj2BpWFUSSMBJAEP1 nN7nhV0lJOVCg== Date: Fri, 4 Aug 2023 17:52:25 +0100 From: Will Deacon To: zhurui Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Robin Murphy , Joerg Roedel , Lu Baolu , Jason Gunthorpe , Yicong Yang , Tomas Krcka , Jean-Philippe Brucker , Nicolin Chen Subject: Re: [PATCH v2 1/1] iommu/arm-smmu-v3: Fix error case of range command Message-ID: <20230804165225.GF30679@willie-the-truck> References: <1690784482-30028-1-git-send-email-wangwudi@hisilicon.com> <20230801085504.GA26130@willie-the-truck> <27c895b8-1fb0-be88-8bc3-878d754684c8@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 Fri, Aug 04, 2023 at 05:31:20PM +0800, zhurui wrote: > When tg != 0 but ttl, scale, num all 0 in a range tlbi command, it > is reserved and will cause the CERROR_ILL error. This case means > that the size to be invalidated is only one page size, and the > range invalidation is meaningless here. So we set tg to 0 in this > case to do an non-range invalidation instead. > > Cc: Will Deacon > Cc: Robin Murphy > Cc: Joerg Roedel > Cc: Lu Baolu > Cc: Jason Gunthorpe > Cc: Yicong Yang > Cc: Tomas Krcka > Cc: Jean-Philippe Brucker > Cc: Nicolin Chen > Cc: Rui Zhu > > Signed-off-by: Rui Zhu > --- > ChangeLog: > v1-->v2: > 1. Change from "Revert" to modify the problematic case > > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 9b0dc3505601..5e56c7e85819 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -1895,9 +1895,6 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, > /* Get the leaf page size */ > tg = __ffs(smmu_domain->domain.pgsize_bitmap); > > - /* Convert page size of 12,14,16 (log2) to 1,2,3 */ > - cmd->tlbi.tg = (tg - 10) / 2; > - > /* > * Determine what level the granule is at. For non-leaf, io-pgtable > * assumes .tlb_flush_walk can invalidate multiple levels at once, > @@ -1930,6 +1927,12 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, > num = (num_pages >> scale) & CMDQ_TLBI_RANGE_NUM_MAX; > cmd->tlbi.num = num - 1; > > + /* Prevent error caused by one page tlbi with leaf 0 */ > + if (scale == 0 && num == 1 && cmd->tlbi.leaf == 0) > + cmd->tlbi.tg = 0; This should only be true for the last iteration, right (i.e. when num_pages == 1)? In which case, I'd prefer to leave the old code as-is and just add: /* Single-page leaf invalidation requires a TG field of 0 */ if (num_pages == 1 && !cmd->tlbi.leaf) cmd->tlbi.tg = 0; here. Will