Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp864204rwn; Thu, 8 Sep 2022 09:46:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XKOd6A1XIiBmj9VvSetT7HHqg9DD3KxkDRl4KJ8v2alwEGUHME8pQZfNzeQaV49q69hqr X-Received: by 2002:a2e:958c:0:b0:26b:de19:ca51 with SMTP id w12-20020a2e958c000000b0026bde19ca51mr526350ljh.449.1662655594851; Thu, 08 Sep 2022 09:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662655594; cv=none; d=google.com; s=arc-20160816; b=pcZag535dlirWMdZ7Sm6WLIPfdCPSq3uzGwuZ3c6eCqmXEZvor2bLKv9q5EhocgUfM cHr8yNcpvAqV9JyjHEEevL+NZN9Geq2obVkeosAlw2W4ZxmKmMMBYsxtr8Hn1W6sgmvd zf89BzN1FDvCOlU6tYmsRgrccK8LigA45Cl3ji+e7+SNi/MRP1uNq0jwsVe1c+qqC84y DbwDJ5gpBnbtsgo2wyHvlI99K3SEyhKlWbu9JLpC+ljKfdw6B55sXCu0Hz+zd+T4tXTW d7n/PyKnVHpHWlg1K07KDgo4FN3h/3ltFJEvfYf3Vrp6txA9+gx97Ll/XUqMCfuLRi8B cW7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dpvUUBmrVBJXdXzTGjJjQlhI+WRTTf8cffEB6shyZ4E=; b=wEB6G8IP8kdJy1Q+5li030dSWDG4FzW36fKArqdsuuuuc48g892cgU0W9tygvSJ4zQ S/2GVAlvDWW7KrLX7alYKeDhnai12De4Me9XSqL+dKUDG3ttySTwJQZJgg6OocP3wnJn NOK1TGih3KaRrH3O2R7rUNy7YA4c0wSIkezob4q47a5j58lZu5veWqYe7aqH/md6cwo4 d050WLKcGKkqinhND6hGhQbBnbNQb7fZupo/lY+Sq74rI1kGer67I+Gh8Yk6lHR+9qWz Prri67IkgUAN6gCgCx8oKW3vrTsOLpehKFaql+AQ789aNYzGXoOGElOWdEfmr8+kY7of gywA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T0Ych89K; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u23-20020a05651c131700b0026bdbb6ddeesi780361lja.314.2022.09.08.09.46.05; Thu, 08 Sep 2022 09:46:34 -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; dkim=pass header.i=@linaro.org header.s=google header.b=T0Ych89K; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231424AbiIHQZm (ORCPT + 99 others); Thu, 8 Sep 2022 12:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbiIHQZj (ORCPT ); Thu, 8 Sep 2022 12:25:39 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B5DF88DD0 for ; Thu, 8 Sep 2022 09:25:38 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id t7so22002010wrm.10 for ; Thu, 08 Sep 2022 09:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=dpvUUBmrVBJXdXzTGjJjQlhI+WRTTf8cffEB6shyZ4E=; b=T0Ych89KMD5a2BAiaAlBK4ZBCijC8Z91doILrAPNvwn9BJo7ejCp64NSQwp7fjTwt3 2fV0SHmJVtKdkIpy8+k0pcn1ItjtRqaYR99HoHpkwNUkvDaJvg9cFnUopcCUprV2EeSV 4fpYZyqJZVbF8BSkoyyPEAJxTCF7Jn4qF0HLoMrUHXd4/vghiFW3+HPxED6lP5EhfN2k W5q2N9MzOWlINfCXFVKksy1vuS7OPcPROonLgw/P04iXTgr5Gt8JQUe7KpdBeq7UHMsW VO0p8fUZKzUG4itNhw98hWnqReawCckwg4BXk/EYFIbVZJVLw7j5AGAYnOtO37e8JYBH pKoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=dpvUUBmrVBJXdXzTGjJjQlhI+WRTTf8cffEB6shyZ4E=; b=DcUEe0IXi8ftySCmKSJFpgEkdtCto8HaOCCcp1zFjyKSwp7y2DgbMoMVWc0+f0h8ab rXIowAd3P5L0F3oMwvNq3WmIrAydvhoX5lADYSSD8eKBgsKDWmgZBPoJX7ji2FO9dCpm X6iJs9xgmTIffQi0S66uKujzdQhjhriaF1vNZgwRnW8PPYDVvQsnmhsXY3hR+WatWUSd p5NioNNN2jNYLa8yvrPxMpN9xEg+FgczFRI80z0yihLrgiQqLROy5r6TcPRKe5iTL37f kJsTLeu6T31KW34BAyUSiYLnsrAuCn+IIigSDCzUYAa6hYcBrlwh3INH1NxvROE84kZV pKDA== X-Gm-Message-State: ACgBeo293riCZK4HQPDT6QanKUw/DRK+Xtz4o9QRSwZRSxq9K9en1daM Up4cUD+susdyzCMLeNIVE+ps3Q== X-Received: by 2002:a5d:5887:0:b0:220:81c9:8ab7 with SMTP id n7-20020a5d5887000000b0022081c98ab7mr5606176wrf.702.1662654336709; Thu, 08 Sep 2022 09:25:36 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id e13-20020a05600c4e4d00b003a60f0f34b7sm3102445wmq.40.2022.09.08.09.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 09:25:35 -0700 (PDT) Date: Thu, 8 Sep 2022 17:25:32 +0100 From: Jean-Philippe Brucker To: Jason Gunthorpe Cc: Baolu Lu , Joerg Roedel , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v13 09/13] iommu/sva: Refactoring iommu_sva_bind/unbind_device() Message-ID: References: <20220906124458.46461-1-baolu.lu@linux.intel.com> <20220906124458.46461-10-baolu.lu@linux.intel.com> <682d8922-200d-8c89-7142-83e7b3754b8d@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Sep 07, 2022 at 02:33:11PM -0300, Jason Gunthorpe wrote: > On Wed, Sep 07, 2022 at 10:54:54AM +0100, Jean-Philippe Brucker wrote: > > > Is iommu_domain still going to represent both a device context (whole > > PASID table) and individual address spaces, or are you planning to move > > away from that? What happens when a driver does: > > > > d1 = iommu_domain_alloc() > > iommu_attach_device(d1) > > d2 = iommu_sva_bind_device() > > iommu_detach_device(d1) > > > > Does detach > > (a) only disable the non-PASID address space? > > (b) disable everything? > > (c) fail because the driver didn't unbind first? > > I think it must be (a), considering how everything is defined and the > needs for vIOMMU emulation. Yes (a) is probably better. The SMMU driver currently implements (c) to ensure that you can't switch device driver without unbinding everything first, and we should keep that check somewhere > > If it is any other option then we have a problem of what to do if the > guest VM asks to change the page table associated with the RID while a > PASID is attached. > > > I'm asking because the SMMU driver is still using smmu_domain to represent > > all address spaces + the non-PASID one, and using the same type > > "iommu_domain" for the new object makes things unreadable. I think > > internally we'll want to use distinct variable names, something like > > "domain" and "address_space". If (a) is not the direction you're going, > > then it may be worth renaming the API as well. > > > > I'm also not sure why set_dev_pasid() is a domain_ops of the SVA domain, > > but acts on the parent domain which contains the PASID table. Shouldn't it > > be an IOMMU op like remove_dev_pasid(), or on the parent domain? > > There is no "parent domain" > > PASID or RID+PASID are completely equal concepts for binding. > > If you are thinking "parent domain" because SMMU is storing the PASID > table in the RID's iommu_domain, then I think that is a misplacement > in the SMMU driver... > > The PASID table belongs in the iommu driver's per-group data > structure. The iommu domain should only have the actual IOPTEs. > > Otherwise everything blows up if you attach an iommu_domain to two > RIDs - the API demands that every RID gets its own PASID mapping, even > if the RID shares iommu_domains. We do not have an API to share PASID > tables. Well, we still do since SMMU implements it. Changing the API is fine, but someone will need to rework the SMMU driver to align with the new meaning of iommu_domain. I can take a stab if no one volunteers but probably not before next year. Thanks, Jean > > Thus the PASID table is NOT part of the iommu_domain. > > The exception will be for nested translation where we will have a > special ARM iommu_domain that contains the PASID table in userspace > memory. When this domain is attached it will logically claim the RID > and every PASID and thus disable the PASID API for that RID. > > Remember also that an UNMANAGED iommu_domain should be attachable to > many PASID's and RID's concurrently. > > Jason