From patchwork Thu Aug 31 17:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13371757 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 80AFEC83F37 for ; Thu, 31 Aug 2023 17:46:27 +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:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Ll30KCg+Oq1388PsHBEzDI8sJXJQRFdfXdSiFnsFku4=; b=uUh A0rL9bQ+IReovJBuh7hFbTeTAkY8GArOm3zdbEb4YV1aUX5XSPWa8nOjX5qDgcwYpqVRr8egWZGE2 N8SqvSwmbJUdTd1TiQhgTWIFiyYRk3V+B+Ki9mfc/yDUxmIc433A8ayW0MO+26ionhX5SIiDXb5in mSPIimJMt4vOWmDOQpqirpXubFlJdrujqjFk07TcuWr6nKzo8EDuimKbnrmz7HXoZ2XdCkD6fN6hU hDzJSz/yxbJHN0qd1upTWfHzaEDH8k+tg6zmXZ/vqgX+VHhwrfGCTJdYdkWSFz46BJvRhSay4IoYF HNxZ3m/wNmxbQeWNW0x7s9h0bgxLZsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbljw-00Fedu-2Q; Thu, 31 Aug 2023 17:45:56 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qbljs-00FecL-0C for linux-arm-kernel@lists.infradead.org; Thu, 31 Aug 2023 17:45:53 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58e49935630so18895767b3.0 for ; Thu, 31 Aug 2023 10:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503946; x=1694108746; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3TyP311oLDB7f/wd/rHD433Vsh3NwjwEGZRdFg/vh88=; b=XdLo8IkBQpheba7pZ+69vmik6w6a1XM0lJwqJ1Bd1ON0X8OareOq3CBntJ3KR/z/Ow WihhhO6lkRJlU5kqh17qyy9494/1o6ODLQp4Z/Cp5Q+7IaYnTwt1xohq+aYDT1y5Yf8P xgV3D3Iyfg/XA0nPehlNwSCkLq8BM+IMWsJQvgW3TFRUzjl3/1xbI2YCB4H+V+r67Il6 rlAKYmtTBhHiFgLM6sFSV6TlR/AL525qcud1PamdYtL44PNMMMuGl5lzuG7A25izIHoT DYcLjeeJ8z/8JrjjiwWadFVg3VRA1GYcx9/zfmMxDcg0vQ1TjGjAdMD9jRMf6lL+nSAD xcDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503946; x=1694108746; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3TyP311oLDB7f/wd/rHD433Vsh3NwjwEGZRdFg/vh88=; b=ewuL1LH4zGLFDgzuTTsh91IfqTCZ/0ha55C2LTZU9Uxpj/9DWM4ETuNRtZOmz5Fg0f Kw+Da0UhkPNCV9HoGUtyoKY9tQniLLP8og5r/wOnezNsu//gvKmmvBgzZMWiDIMVDouw jnk9VuONr+hD7t9UFr9GeKE+yFG7bMjnBexq7UXv3tIuFAIfV/dVSC8A5ZQHX/V725zj BRI9FgAEHsAIEux4PN6cHjysUET5dGRoehYD/uf0JyA+zgiOKTcEFCnb48hsWNsMdYMG x4Dh8DhVKHgR/yeOPpwCJFx8llYvStZIewSZB09klXVVPzuJlOuOcJ/LYPCysYbdV+dC gMgg== X-Gm-Message-State: AOJu0YwzbPGEcnkmh6TWjcW2CObrcnN2F8qsAk3ODg1vFGeZIkU1fi0h nztEejU1nG3XMXE2TkNiPFQ9JldXPPgg X-Google-Smtp-Source: AGHT+IGeekO0hDtnwCjLBcmgCPi6ukecPYF3K58dIbVBSkohSTIzFB3+CH2tmjGZTdJgAfpEPn5fhJtLWBLG X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a05:690c:e1a:b0:586:e91a:46c2 with SMTP id cp26-20020a05690c0e1a00b00586e91a46c2mr11312ywb.4.1693503946561; Thu, 31 Aug 2023 10:45:46 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:29 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230831174536.103472-1-mshavit@google.com> Subject: [PATCH v7 0/9] Refactor the SMMU's CD table ownership From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230831_104552_096733_1DF1DBE2 X-CRM114-Status: GOOD ( 19.96 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi all, This series refactors stage 1 domains so that they describe a single CD entry. These entries are now inserted into a CD table that is owned by the arm_smmu_master instead of the domain. This is conceptually cleaner and unblocks other features, such as attaching domains with PASID (for unmanaged/dma domains). This patch series was originally part of a larger patch series that implemented the set_dev_pasid callback for non-SVA domains but is now split into a distinct series. This patch series is also available on gerrit with Jean's SMMU test engine patches cherry-picked on top for testing: https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/24742/15 Thanks, Michael Shavit Changes in v7: - Change the amr_smmu_write_ctx_desc_devices helper introduced to arm_smmu_update_ctx_desc_devices to distinguish from the case where a potentially new CD entry is written to. Add a comment to clarify that it is assumed that the operation can't fail and that it's therefore safe not to handle the return. In contrast, the case where a new CD entry is written-to does not use the helper and does have to handle failure. - Update commit message to be more clear about locking purpose. - Drop "Skip cd sync if CD table isn't active" commit, and remove related comment in the "Move CD table to arm_smmu_master patch. - And some minor cosmetic changes based on v6 feedback. - Link to v6: https://lore.kernel.org/all/20230816131925.2521220-1-mshavit@google.com/ Changes in v6: - Undo removal of s1fmt and renaming of s1cdmax - Unwind the loop in amr_smmu_write_ctx_desc_devices to NULL out the CD entries we succesfully wrote on failure. - Add a comment clarifying the different usages of amr_smmu_write_ctx_desc_devices - Grab the asid lock while writing the RID CD to prevent a race with SVA. - Add the device to the devices list before writing the CD to the table and installing the CD table. - Link to v5: https://lore.kernel.org/all/20230808171446.2187795-1-mshavit@google.com/ Changes in v5: - Clear the 0th CD entry when the domain is detached. Not clearing it caused a bug in arm_smmu_write_ctx_desc which doesn't expect the entry to already be set. - Added commit to clean-up now unused master parameter in arm_smmu_domain_finalise - Link to v4: https://lore.kernel.org/all/20230802163328.2623773-1-mshavit@google.com/ Changes in v4: - Added comment about the cd_table's dependency on the iommu core's group mutex. - Narrowed the range of code for which the domain's init_mutex is held on attach since it now only protects the arm_smmu_domain_finalise call. - Link to v3: https://lore.kernel.org/all/20230801183845.4026101-1-mshavit@google.com/ Changes in v3: - Add a helper to write a CD to all masters that a domain is attached to. - Fixed an issue where an arm_smmu_write_ctx_desc error return wasn't correctly handled by its caller. - Link to v2: https://lore.kernel.org/all/20230731104833.800114-1-mshavit@google.com/ Changes in v2: - Allocate CD table when it's first needed instead of on probe. - Minor changes - Added commit to rename remaining usages of cdcfg to cd_table - Link to v1: https://lore.kernel.org/all/20230727182647.4106140-1-mshavit@google.com/#r Changes in v1: - Replace s1_cfg with arm_smmu_ctx_desc_cfg representing the CD table - Assume that the CD table is owned by the SMMU master for most operations. This is forward-compatible with the nested patch series as these operations wouldn't be called when the installed CD table comes from nested domains. - Split off as a distinct patch series from https://lore.kernel.org/all/20230621063825.268890-1-mshavit@google.com/ Michael Shavit (9): iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg iommu/arm-smmu-v3: Replace s1_cfg with cdtab_cfg iommu/arm-smmu-v3: Encapsulate ctx_desc_cfg init in alloc_cd_tables iommu/arm-smmu-v3: move stall_enabled to the cd table iommu/arm-smmu-v3: Refactor write_ctx_desc iommu/arm-smmu-v3: Move CD table to arm_smmu_master iommu/arm-smmu-v3: Cleanup arm_smmu_domain_finalise iommu/arm-smmu-v3: Update comment about STE liveness iommu/arm-smmu-v3: Rename cdcfg to cd_table .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 41 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 251 +++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 17 +- 3 files changed, 166 insertions(+), 143 deletions(-) base-commit: 6eaae198076080886b9e7d57f4ae06fa782f90ef Tested-by: Nicolin Chen