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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82B11C77B7C for ; Fri, 18 Aug 2023 16:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MttdvE09fsc8mmZ+/NE/cL9189PnScInfpHqMcZsZsg=; b=E15FTcbjXGdz/Z lb+hU+HJgLKCHB1KHPiLPnNWEoyMVtzJ2P3xe3Ry3l6JohvXimyJmvL+tXCgU79bE0Y9fXKrdL0xo /8GvGqPqG0irZWYcNKtzau3incEymIwSN7GI7rQsCiKzA1lJ6/Y3AR9J0uWL0A7VTaiosxoPohXqr crDYsPAH6INcWIbWAw7/M+jEaJNM4JhU6fJ54+vXcqiojTrXJgaIagxAjbMlGa6g0hONZXd6dSKYZ TCP+iaTeQNGW269EE0CiNkxyM1GrZbEozXW8sfDsAhnIS0+/oWXRjULGOyMBD7ls9OAJtuJm8oanX Iw1JwYjRZ7y79s2klSTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qX2E1-009ewB-0v; Fri, 18 Aug 2023 16:21:25 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qX2Dy-009evP-0E for linux-arm-kernel@lists.infradead.org; Fri, 18 Aug 2023 16:21:23 +0000 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 64CE761BAF; Fri, 18 Aug 2023 16:21:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A88F0C433C7; Fri, 18 Aug 2023 16:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692375680; bh=vNNA0DydvFNi8JxO1ms0ynUZolq4OWcAKa8ptRRbUcA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KxUIdHbGwA6ffzRww69NVxQyWOkcjddSpZt6hHCmMr4KnlJ357G6Vu8M5fvl6F7pK rRP7NU4vhh7g0l9rfAILxywMipNSmu7x7NB/Ulo4/ZV0a04AkIgd4HRwyyxHGXIvBy XCc/9BMralVSmfWOf+D9MdiOeLNdKxmvVYPYrwJXCXCTQ+dUU2iU21gKK3P3FIdi4K YF9EIvyolHAYCBIYgjof8H4kJU5LoAWEITPXehTy2j+FlOul2Oez88vzqUjuL4jY2z UAzhqeKR4mTT42YQtDfx0MwRbHNG7tb+Cy6JsMcGsn2EIh79ehNaaqbRvw/77j1G8r m6OVW3DLNs53A== Date: Fri, 18 Aug 2023 17:21:15 +0100 From: Will Deacon To: Robin Murphy Cc: zhurui , Nicolin Chen , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joerg Roedel , Lu Baolu , Jason Gunthorpe , Yicong Yang , Tomas Krcka , Jean-Philippe Brucker Subject: Re: [PATCH v2 1/1] iommu/arm-smmu-v3: Fix error case of range command Message-ID: <20230818162114.GB16216@willie-the-truck> References: <20230804165225.GF30679@willie-the-truck> <015b4573-9d74-451b-8028-a1050ade7019@huawei.com> <661a7bb5-99e1-de16-d860-0cd17f7a0470@arm.com> <20230808162409.GB2890@willie-the-truck> <80ead8ee-4dbe-7b3c-44f5-944073a2a39d@arm.com> <412886be-644a-5b46-9bfa-1c9a358f9a5d@huawei.com> <280d0be7-7d41-ed78-bf4b-3db6c0076e22@arm.com> <197e87cd-91a2-dce8-716c-488b379abbaf@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <197e87cd-91a2-dce8-716c-488b379abbaf@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230818_092122_192131_F867DC7D X-CRM114-Status: GOOD ( 32.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 18, 2023 at 05:19:31PM +0100, Robin Murphy wrote: > On 2023-08-09 14:48, Robin Murphy wrote: > [...] > > Does the patch below work for you? > = > Any comments on this? Just noticed this commit on a local dev branch and > realised I'd totally forgotten about it already. I'm pretty confident it > ought to be right, but then it *was* also me who missed the original bug = to > begin with... ;) I'm happy to take it if zhurui can confirm that it fixes their issue... Will (had also forgotten about this) > > ----->8----- > > Subject: [PATCH] iommu/arm-smmu-v3: Avoid constructing invalid range > > commands > > = > > Although io-pgtable's non-leaf invalidations are always for full tables, > > I missed that SVA also uses non-leaf invalidations, while being at the > > mercy of whatever range the MMU notifier throws at it. This means it > > definitely wants the previous TTL fix as well, since it also doesn't > > know exactly which leaf level(s) may need invalidating, but it can also > > give us less-aligned ranges wherein certain corners may lead to building > > an invalid command where TTL, Num and Scale are all 0. It should be fine > > to handle this by over-invalidating an extra page, since falling back to > > a non-range command opens up a whole can of errata-flavoured worms. > > = > > Fixes: 6833b8f2e199 ("iommu/arm-smmu-v3: Set TTL invalidation hint bett= er") > > Reported-by: Rui Zhu > > Signed-off-by: Robin Murphy > > --- > > =A0drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 ++++++++++----- > > =A01 file changed, 10 insertions(+), 5 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..6ccbae9b93a1 100644 > > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > > @@ -1895,18 +1895,23 @@ static void __arm_smmu_tlb_inv_range(struct > > arm_smmu_cmdq_ent *cmd, > > =A0=A0=A0=A0=A0=A0=A0=A0 /* Get the leaf page size */ > > =A0=A0=A0=A0=A0=A0=A0=A0 tg =3D __ffs(smmu_domain->domain.pgsize_bitma= p); > > = > > +=A0=A0=A0=A0=A0=A0=A0 num_pages =3D size >> tg; > > + > > =A0=A0=A0=A0=A0=A0=A0=A0 /* Convert page size of 12,14,16 (log2) to 1,= 2,3 */ > > =A0=A0=A0=A0=A0=A0=A0=A0 cmd->tlbi.tg =3D (tg - 10) / 2; > > = > > =A0=A0=A0=A0=A0=A0=A0=A0 /* > > -=A0=A0=A0=A0=A0=A0=A0=A0 * Determine what level the granule is at. For= non-leaf, > > io-pgtable > > -=A0=A0=A0=A0=A0=A0=A0=A0 * assumes .tlb_flush_walk can invalidate mult= iple levels at once, > > -=A0=A0=A0=A0=A0=A0=A0=A0 * so ignore the nominal last-level granule an= d leave TTL=3D0. > > +=A0=A0=A0=A0=A0=A0=A0=A0 * Determine what level the granule is at. For= non-leaf, both > > +=A0=A0=A0=A0=A0=A0=A0=A0 * io-pgtable and SVA pass a nominal last-leve= l granule because > > +=A0=A0=A0=A0=A0=A0=A0=A0 * they don't know what level(s) actually appl= y, so ignore that > > +=A0=A0=A0=A0=A0=A0=A0=A0 * and leave TTL=3D0. However for various erra= ta reasons we still > > +=A0=A0=A0=A0=A0=A0=A0=A0 * want to use a range command, so avoid the S= VA corner case > > +=A0=A0=A0=A0=A0=A0=A0=A0 * where both scale and num could be 0 as well. > > =A0=A0=A0=A0=A0=A0=A0=A0=A0 */ > > =A0=A0=A0=A0=A0=A0=A0=A0 if (cmd->tlbi.leaf) > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 cmd->tlbi.ttl =3D 4 - ((ilog2(gra= nule) - 3) / (tg - 3)); > > - > > -=A0=A0=A0=A0=A0=A0=A0 num_pages =3D size >> tg; > > +=A0=A0=A0=A0=A0=A0=A0 else if ((num_pages & CMDQ_TLBI_RANGE_NUM_MAX) = =3D=3D 1) > > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 num_pages++; > > =A0=A0=A0=A0 } > > = > > =A0=A0=A0=A0 cmds.num =3D 0; > > = _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel