Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp2259064rdb; Thu, 17 Aug 2023 16:05:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtS5Po5UhlvOB5c1ykZR+9l8ssKdr74gyKy/CDEyBzOGyJZgJ5XIMqA5F96gBPZJiOHspt X-Received: by 2002:a2e:3003:0:b0:2bb:8eea:755a with SMTP id w3-20020a2e3003000000b002bb8eea755amr443595ljw.49.1692313501115; Thu, 17 Aug 2023 16:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692313501; cv=none; d=google.com; s=arc-20160816; b=aLL56jKzsUTT4lb6Ak6Jg1YbFe+ojmsnEl0g8RznOi4afelcwhPYp24hSFj7Ol2wNm Q/9of5ex2fJEM9wznvzka5Gm8hdC1efD5NCMr+EXvYOAjYPrmQG8zrLRmI+rfhaSjPdS veQ1mUgniz9zqcPEapIZBHtVdGseowFNJQO0bmH8SneG8u78POJKAYzECoEZBdFuEX7I cuTnAhDH+2sSnlDOAU3+ufWX1wCqF6121lVKBSlL32eK5dUcfjuZjC0K5OknOTKp4+8q Qn7qb6BkE8Aez/gtSRK27GfSF8hPAgrqj1AV1l/AsVZrM/+QMEi0Pj6hO749BOOH74OY oZ+w== 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=X0Mka1IFSSZfRdCPDzSmvZDo5eqbW1Chl9qN2apCuNQ=; fh=URAbG9R359w+dyRZRLJ/MS3nCfU56ezNN7ijfMpC4P0=; b=rUmapVhARi7Qh3917sfsehVfYUqnaBoYf4BgcJU0w6GGoENnnMD9hC3cxXIbgZBy4/ BqER5wlWjdOAIHXpqG5iTgp92sjjZ5AlnnuP7p4j3f2Eo3oIK6A0M+G5KlK8i2RA39Tg 5ubLl0TOtZWTDnA/n9jUHlos+zhSUrtbj+nF2X8jiZs8whTyKaBwWeIL093sS1aW3Uhw frLb00Yfp50vzrEh6kXrncuqNOf1dQrCdaNBuPldML/XuB8eVeI1/FGPsk55BqvtpddE hAaKGyhc+M5D7Iyt9DoBYDfFcrslVMucyZf9Xjg9zXqBdzsCkpsPkeVwZAlR6QjVwIIx HUvQ== 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 i21-20020a1709064ed500b0099ccdd7770fsi368759ejv.995.2023.08.17.16.04.36; Thu, 17 Aug 2023 16:05:01 -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 S1354276AbjHQSUY (ORCPT + 99 others); Thu, 17 Aug 2023 14:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354321AbjHQSUA (ORCPT ); Thu, 17 Aug 2023 14:20:00 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF19B2D5D for ; Thu, 17 Aug 2023 11:19:58 -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 3DF0DD75; Thu, 17 Aug 2023 11:20:39 -0700 (PDT) Received: from [10.57.90.41] (unknown [10.57.90.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7ADB23F64C; Thu, 17 Aug 2023 11:19:56 -0700 (PDT) Message-ID: Date: Thu, 17 Aug 2023 19:19:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] iommu/arm-smmu-v3: Simplify stage selection logic Content-Language: en-GB To: Michael Shavit Cc: iommu@lists.linux.dev, Jason Gunthorpe , Jean-Philippe Brucker , Joerg Roedel , Lu Baolu , Nicolin Chen , Tomas Krcka , Will Deacon , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20230818000321.1.Ibca43cc8d1bcad3ac3deef5726b9745128aea634@changeid> <928822fd-642a-5ca7-7b42-dc7885f3cf51@arm.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.9 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-08-17 18:06, Michael Shavit wrote: > On Fri, Aug 18, 2023 at 12:35 AM Robin Murphy wrote: >> >> The reason it's like this is because of arm_smmu_enable_nesting(), which >> *is* the additional thing that's going on with the stage selection logic. >> >> Thanks, >> Robin. > > Right, but arm_smmu_enable_nesting isn't involved in this computation > at this point in the flow. > > arm_smmu_enable_nesting returns early if smmu_domain->smmu isn't set, > and smmu_domain->smmu is only set after arm_smmu_domain_finalise. > So at this point, smmu_domain->stage is being initialized for the > first time. If this code is responsible for handling some special > nesting case, then it's probably not working as intended. I think you may have misread that code... Anyway, the point of the logic here is that it is not "selection", it is, as the comment says, "restriction" - i.e. it is checking that the already-selected stage is actually supported, and coercing it if not. The default selection for a newly-allocated domain is always implicitly ARM_SMMU_DOMAIN_S1 (which is explicitly defined as 0 to convey that significance), but it may be set to ARM_SMMU_DOMAIN_NESTED before the first attach finalises the pagetable format. Obviously this could be clearer, especially for anyone not so familiar with all the history, but at this point I honestly don't think it's worth doing anything without completely ripping out arm_smmu_enable_nesting() as well. Jason already had a patch a while ago, and my bus rework is now also very close to the point of finally fixing iommu_domain_alloc() to be able to return working domains, such that all the "domain_finalise" bodges go away and that whole "modify the domain between allocation and attach" paradigm is no longer valid at all. By this point I'm not too fussed about breaking the current meaning of ARM_SMMU_DOMAIN_NESTED any more. But what I definitely don't want to do is have a change like this which subtly but decisively breaks it while still leaving all the now-dead code in place ;) Thanks, Robin.