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 7E3E4C001DF for ; Fri, 4 Aug 2023 16:52:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbjHDQwn (ORCPT ); Fri, 4 Aug 2023 12:52:43 -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) 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