Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp638039rdb; Sat, 19 Aug 2023 17:36:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQTTRaYEp14lYOQNKwiuzZSuDKUvIyjgQRbwjLoIdd8dH9uF6fvrKP9rTn+Gz25gZPSOAo X-Received: by 2002:a05:6870:3307:b0:1ba:3ff0:493c with SMTP id x7-20020a056870330700b001ba3ff0493cmr4719677oae.19.1692491809564; Sat, 19 Aug 2023 17:36:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1692491809; cv=pass; d=google.com; s=arc-20160816; b=mApgB++aHHwPSOrf2n491YbqLhG9Yc40ySlvQjG4Ti1P2WDOCs75qhQmenaVB784h3 CW8uZ/kOaBe+8xL4TGfO45BaZ6FNyudGt9Jy19mbIcdyKfQWbLyPrCG5jUjJx95Jwsy6 Ej/spf4G2DtVxBhB6A41cY67oWo9xdvr0kd8HwOrXij1o0CR5ENIh8YPJoLl2cth2/Q2 t0DtCUauiQkybgdFsosYJyr+dpuLYGJXXJ7z/bfu8ZRpwCLt/BIs/2LoRw5zi+WR5bn9 ssr2DcK/egUvQxU4oz6pK3FkoaoxTa8bdBr/7ptyxLTzz9enZVmP6/XxV3TAAOg7ZRjv DG6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to :content-transfer-encoding:content-disposition:references:message-id :subject:cc:to:from:date:dkim-signature; bh=ctGlO12/XsLAROApewDezfgeJWnXtNvS9rA5cqH3/Bk=; fh=XBKcGT+MYdg+72glTH2lvfzoxhCeGNZzi9nUWQ+JkDA=; b=A+pNt8rL38uCwJnUBXo+iIFYDSTVA9DVcX3OPGtUpIfz3G6bfhiVXVpYVNPhL2NqXy qiAuyhLmqazj7VCDw4s2nkTngrJSN3646UiplGbqOo3ByIfWubEwva0f38ZDzY7EfbYl jRvUCOeC8u61zJ5HSxZLh41s6TzFCRlsUQVh6t2fUY0HZFv9qI36Y90z03MH5LC0sW+2 v9tJaULUXOq6rW3LjR9k+c7swxzJojwbiwC4Vi6DDllNwlpleH3u6w+oeeo/5Mj0k0lw mLK3dCulWJ3iEbltii4pg+2FPHyr+3qf1H4nvozqrDW4xZUuYFiUebiLMKBEdjU7wLDa NMVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=ElhT15AX; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ca5-20020a17090af30500b00268b5d65afcsi5916613pjb.58.2023.08.19.17.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 17:36:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=ElhT15AX; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5F96D178BD6; Sat, 19 Aug 2023 11:13:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236780AbjHOMba (ORCPT + 99 others); Tue, 15 Aug 2023 08:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231941AbjHOMa6 (ORCPT ); Tue, 15 Aug 2023 08:30:58 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2068.outbound.protection.outlook.com [40.107.92.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5801173F for ; Tue, 15 Aug 2023 05:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dMDa4FYWbGHIteQiSwXcF+EcySWwtraSqpnNDE0Mflr79/2vAuLHncqjJ/KwMaiKgJdp/NAo2MXlfHr/BUCQyC0ZntTWRfHF0gximETATgID0Z648MCTcrHuGNhA1cVOK132RY5E6SyD1Wq3ZIP6EWWp30MmzVGPiD61RVnTk3ssdGxYRU5A10TJoGQPUIBYcbL6J7kaEjF3E8yz0kgLqQD0a2Ecpra54NBG5lIg3lWOfrj4hu9Lv1PDhX8k+3BFu5JYl00mO6pFiBl30tvPLJzE2lzASenaD2wpmd3ntyjREFHr1ZYBomwxirM2OMzsx8qV/z7pOdd94r2+FpWUqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ctGlO12/XsLAROApewDezfgeJWnXtNvS9rA5cqH3/Bk=; b=ZndnXR0Vp3p0JZgYAk/AcEyewSpubwYW7+8eG53BY3kdPdAbMoJcx2HBu82/j1jx0XdB5hBeNHqmST8ZZ1TzBe4so4xMnCvk64F5Tl5D1oTsnMoJcZ/TbtMnaQf+sD8hWIhzUw4xMLUrRxPbJ/RlDbDduFAtOBZN0Uete/Y5eFMLnI1EjQ7UgADIEvFM98uJmedNS8/cpsZxDKaN7LvcmOMdjyqyKcDvNL3qDi95Il2ysOekOo4ia+WVQ2X3jjEaiJ9GS1oYQmKPkGY21OhbwoVsm2gaoYgwCA2dwJ9MERnR8Fnlo7+h5LlHyxBrITn0RWYA3erBlBWTk5RkfIwDcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ctGlO12/XsLAROApewDezfgeJWnXtNvS9rA5cqH3/Bk=; b=ElhT15AXHvj+d/ZrXmsWqeiAoLaE/uYslXiLjdQduWCoQArNNwVJeGVJ/qd583YLO25qMb2NpnDbhQ/5HOmi4366VPJI4Q97u7EYEiedHtLzELPhhwjuQ3pJEt0XEXv8KVbr/hKxwiVe5G7+TqRVULW+xHEZsdFBatH7MX70/uRfCgsQzBN/nQytr94NXSMu9suiFsPe02AyDYEgBJW3FNLRl5FzxVO8H7p1mUcdAX+46kSyRMdjE6B8l3NI3Lf3rAbozMFlnsE4BZMmvYzeEevcCgcOGGoxXzr22XjRGPB+VIxk91GAj2TagXTTphFoxc7OzAv872v6tMCL1xjNjQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Tue, 15 Aug 2023 12:30:52 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6678.025; Tue, 15 Aug 2023 12:30:52 +0000 Date: Tue, 15 Aug 2023 09:30:50 -0300 From: Jason Gunthorpe To: Michael Shavit Cc: Will Deacon , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, robin.murphy@arm.com, nicolinc@nvidia.com, jean-philippe@linaro.org Subject: Re: [PATCH v5 5/9] iommu/arm-smmu-v3: Refactor write_ctx_desc Message-ID: References: <20230808171446.2187795-1-mshavit@google.com> <20230809011204.v5.5.I219054a6cf538df5bb22f4ada2d9933155d6058c@changeid> <20230809134959.GB4226@willie-the-truck> <20230810144051.GD5795@willie-the-truck> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: CH0PR13CA0041.namprd13.prod.outlook.com (2603:10b6:610:b2::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SA0PR12MB4430:EE_ X-MS-Office365-Filtering-Correlation-Id: 1800da34-cf70-44b6-50f7-08db9d8b76ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lEE+LzEBY9iGIIi0Dkd52+FV2bqTk2xKr370nEhoNgmEoWsVujn+A86NBeQnKcUMugD8MpOvhVF6AIpa5BPeuVvEztTdGvNfnJJHAgSm0Mr4nQxoIKEhr/3hH0ud2DFKO8Ux/jTtKPbDN94HZqGd2Ee/hyJKuX8RbDshfCPewJdyjtK2YX4dO7HRjaj1zBXdaHyHCpo0zmL8HCQFE5kFnigLRHBOmvd9YWIiN3Z9+/MQ1vGsL6PSI4HLfvlDRRhPzsdPg80Dvnjd37jmtGYBSP9cqo+ooNdcEt6fCgdmIz+DarwUfBwpDM7L2jp9OQyCm/FLKA8rImc/m5pf7CcUmSKE3e/KvERHYHQ6Tc6Mn+xbEimaYDaZyO8Jh9kcGeUz77dWulUxH26kR2qpDA5ap0uMtpfrn2U3c5jVzMJGtk9UVxWCSH6sSZ60gvIP4pExwKph7QkafLjjwcTD48s7i+N5jmIU1Z1AJ2sS2fNSEJtivTgavNemAfYTO0qmctDds0c0kHwWC3XMmqzGun65Un4tjNN01wvvKErMXAPslBrC/+4+k28CLrl6DJEFbucD9LazklsVqUwMEp6sZ95wAN+oJ5EikuFpIyxKSndwXJI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(366004)(376002)(136003)(39860400002)(396003)(451199024)(1800799009)(186009)(478600001)(6486002)(38100700002)(86362001)(36756003)(2616005)(6506007)(66476007)(66556008)(66946007)(6916009)(316002)(5660300002)(41300700001)(26005)(53546011)(83380400001)(6512007)(4326008)(2906002)(8676002)(8936002)(67856001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VytnNmZyaWFacjdwQjNkdW02ZGd0a215WGJFZ01kc200VjNES1RqbnQrNWIw?= =?utf-8?B?MVU0U3VNU2E2ek52bk1FSU5zc2ZEdmNpbVZzcVZ5L21kVXhpdFlkd0p0MGFT?= =?utf-8?B?RE9rS08yUWdyNGQ1RUprbXpjWVUwVDR6MTQ3dkxWUHI0ZFZDbWF0QkpPMVN6?= =?utf-8?B?YzVuaWFEZjZPcDIrQThORmFzeFJiSjVBNnFvVUVGVXp4UVBkWHd6bVZwK3Jr?= =?utf-8?B?TGpWbDZScURibmxDb3d5RWF0aGhvRnV1aVFLTTZLVWtaK2xyd3lCY3MzWkdT?= =?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NUTU5TUFkSUZVbkFZU08vUkFQTUpwa1d3QmtUZmMzTU1PWlhR?= =?utf-8?Q?BhwQmo0HOPLT/75cmstZa106T?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1800da34-cf70-44b6-50f7-08db9d8b76ad X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2023 12:30:52.1639 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PTiIqpyChUYOr13fm3Ih1mGpxT+GU7mKp6Rp9Qf1I54Oq+oyQLPkiGVhuSBMd2jx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4430 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=no 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 Tue, Aug 15, 2023 at 08:03:40PM +0800, Michael Shavit wrote: > On Tue, Aug 15, 2023 at 7:38 PM Jason Gunthorpe wrote: > > > > On Tue, Aug 15, 2023 at 01:20:04PM +0800, Michael Shavit wrote: > > > On Thu, Aug 10, 2023 at 11:39 PM Jason Gunthorpe wrote: > > > > > > > > Actually, I don't think this even works as nothing on the PASID path > > > > adds to the list that arm_smmu_write_ctx_desc_devices() iterates over ?? > > > > > > > > Then the remaining two calls: > > > > > > > > arm_smmu_share_asid(struct mm_struct *mm, u16 asid) > > > > arm_smmu_write_ctx_desc_devices(smmu_domain, 0, cd); > > > > > > > > This is OK only if the sketchy assumption that the CD > > > > we extracted for a conflicting ASID is not asigned to a PASID. > > > > > > > > static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) > > > > arm_smmu_write_ctx_desc_devices(smmu_domain, mm->pasid, &quiet_cd); > > > > > > > > This doesn't work because we didn't add the master to the list > > > > during __arm_smmu_sva_bind and this path is expressly working > > > > on the PASID binds, not the RID binds. > > > > > > Actually it is working on the RID attached domain (as returned by > > > iommu_get_domain_for_dev() at sva_bind time) not the SVA domain > > > here... > > > > That can't be right, the purpose of that call and arm_smmu_mm_release is to > > disable the PASID that is about the UAF the mm's page table. > > > > Jason > > For the sake of this message, let's call "primary domain" whatever RID > domain was attached to a master at the time set_dev_pasid() was called > on that master. That RID domain is locked in while SVA is enabled and > cannot be detached. > > The arm-smmu-v3-sva.c implementation creates a mapping between an SVA > domain and this primary domain (through the sva domain's mm). In > arm_smmu_mm_release, the primary domain is looked up and > arm_smmu_write_ctx_desc() is called on all masters that this domain is > attached to. My question is still the same - how does arm_smmu_mm_release update the Contex descriptor table entry for the *PASID* The RID on PASID 0 hasn't change and doesn't need updating. Jason