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 02CCFC6FD20 for ; Fri, 24 Mar 2023 15:29:57 +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:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References: Cc:To:Subject:MIME-Version:Date:Message-ID:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qJMhppNK1Czz/KCmaE6VhmDqseO8UhMqc1vsgvmaKs8=; b=TEsmc1tTVQ2r8W g4SUhrDttj8JqTIuu9FCV8dJc0nr0y8hBMJK/H1YaglNNru7f+qwaDKS3wkfTRfczb5lrh2b8Vp5m 81wAZGpWnwfJ/Er64qgB7JprJskDYyVVYOVA5PM0xXY1C3RJVaenOB5ivwHKmvhvA5/SksS5bT9zZ iQzDolUbcxsrnNmRoLM7sSiCAW9xtzdZvMdu7PhYhAe+ydv1EmyKgUh6Flo+qsQKbeRAB+nlCICdq 87PoHK5pjjivbZMeMhmTxvbDwj7QZz58MnCicvzbLOiqX+3KeEAZ07qYHNksHFQRo8fXynLwxcKph iJIiEaQ8MflvyrDQjvfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfjLP-004r7j-0s; Fri, 24 Mar 2023 15:28:43 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfjLM-004r5e-0Y for linux-arm-kernel@lists.infradead.org; Fri, 24 Mar 2023 15:28:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679671716; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kh4apJjF008Ebwd6BpQPfSf9Xv4AqfjyXizFPG3+0WY=; b=WySlHji/dX3fDZt52TkQu3ahYs3BSjOflexD4IzNs3/f1mDcl5yk2McxrQ1wKNABH2ReL9 Ee3NFBq+98vaNCamq/iURdbpftTs35MaYDHIay07I2HwbfcRmYm6OlQdsjmhnpUWlarWZQ sHjfNiY+f3EuCZTzHCcxa1h9cTNY/Vc= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-sMeU5SHEOcqBc6B0wiB3Yg-1; Fri, 24 Mar 2023 11:28:32 -0400 X-MC-Unique: sMeU5SHEOcqBc6B0wiB3Yg-1 Received: by mail-qk1-f198.google.com with SMTP id r70-20020a374449000000b00746c31401f0so936468qka.6 for ; Fri, 24 Mar 2023 08:28:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679671711; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Kh4apJjF008Ebwd6BpQPfSf9Xv4AqfjyXizFPG3+0WY=; b=Y45M/I43vJT3y2bhN7YqIJYOIZIutljuQiSubUTT7f42q43LQSXrwhhY0QXHfiYr/J 3NfMrCHfsu8Ci3zAEspbD+g97lQZvR8IDVN8gLiEisTWgyUlnziUQrf33t2z4oWOX9bj JBw095OJuO1eAVsrvylZiQQdUktO//IrJIkCLcLJ4mGlGhyugSHFNO4BSWwoDL5wb1BP D3xxkzi5jZ5l2bQeris3rVRhXCAiJm8BAJv3BtnrgB4cbJCVWxgANV+NscHrWerwQfmZ +H3moEir36ENlba5y8PyKPw+830leCwo9oLwmbqfutuY5BleYcrUHItZjIVZ4BD4j3MU jfPw== X-Gm-Message-State: AO0yUKWQw9/4/raFvIPe1XI8U9gdXgbiTYypWifYsQcN5ylcSTVCK7Oq nO1viya8dBDqo/O8mwlM7c0bYiXwTgP31Yn+8P+L4qe+7HCv8V65u5FLtjf5HYxFP4NMetTHUyZ rKt7VN3YUpDK5wuDBu0gBrZ62h27ST7gfDCE= X-Received: by 2002:ac8:5b87:0:b0:3b9:bc8c:c214 with SMTP id a7-20020ac85b87000000b003b9bc8cc214mr15962671qta.31.1679671710906; Fri, 24 Mar 2023 08:28:30 -0700 (PDT) X-Google-Smtp-Source: AK7set/aZhTIagXr86hQGcOM0/obUyvWdZrsHbQkbzWyxnPA96NfrvjCypZ6MbXRS7MTV48Tt/mrmg== X-Received: by 2002:ac8:5b87:0:b0:3b9:bc8c:c214 with SMTP id a7-20020ac85b87000000b003b9bc8cc214mr15962640qta.31.1679671710626; Fri, 24 Mar 2023 08:28:30 -0700 (PDT) Received: from ?IPV6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id 11-20020a37060b000000b0071d0f1d01easm8220902qkg.57.2023.03.24.08.28.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Mar 2023 08:28:30 -0700 (PDT) Message-ID: <857004e1-6ab1-f825-7796-9c0b557e7cc8@redhat.com> Date: Fri, 24 Mar 2023 16:28:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v1 11/14] iommu/arm-smmu-v3: Add arm_smmu_domain_alloc_user To: Nicolin Chen , jgg@nvidia.com, robin.murphy@arm.com, will@kernel.org Cc: kevin.tian@intel.com, baolu.lu@linux.intel.com, joro@8bytes.org, shameerali.kolothum.thodi@huawei.com, jean-philippe@linaro.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <7d26e897780bdc009b11bc0c0ddc7b755a769b24.1678348754.git.nicolinc@nvidia.com> From: Eric Auger In-Reply-To: <7d26e897780bdc009b11bc0c0ddc7b755a769b24.1678348754.git.nicolinc@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230324_082840_284076_1763A5D1 X-CRM114-Status: GOOD ( 29.77 ) 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: , Reply-To: eric.auger@redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Nicolin, On 3/9/23 11:53, Nicolin Chen wrote: > The arm_smmu_domain_alloc_user callback function is used for userspace to > allocate iommu_domains, such as standalone stage-1 domain, nested stage-1 > domain, and nested stage-2 domain. The input user_data is in the type of > struct iommu_hwpt_arm_smmuv3 that contains the configurations of a nested > stage-1 or a nested stage-2 iommu_domain. A NULL user_data will just opt > in a standalone stage-1 domain allocation. > > Add a constitutive function __arm_smmu_domain_alloc to support that. > > Since ops->domain_alloc_user has a valid dev pointer, the master pointer > is available when calling __arm_smmu_domain_alloc() in this case, meaning > that arm_smmu_domain_finalise() can be done at the allocation stage. This > allows IOMMUFD to initialize the hw_pagetable for the domain. > > Signed-off-by: Nicolin Chen > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 95 ++++++++++++++------- > 1 file changed, 65 insertions(+), 30 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 2d29f7320570..5ff74edfbd68 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -2053,36 +2053,6 @@ static void *arm_smmu_hw_info(struct device *dev, u32 *length) > return info; > } > > -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) > -{ > - struct arm_smmu_domain *smmu_domain; > - > - if (type == IOMMU_DOMAIN_SVA) > - return arm_smmu_sva_domain_alloc(); > - > - if (type != IOMMU_DOMAIN_UNMANAGED && > - type != IOMMU_DOMAIN_DMA && > - type != IOMMU_DOMAIN_DMA_FQ && > - type != IOMMU_DOMAIN_IDENTITY) > - return NULL; > - > - /* > - * Allocate the domain and initialise some of its data structures. > - * We can't really do anything meaningful until we've added a > - * master. > - */ > - smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); > - if (!smmu_domain) > - return NULL; > - > - mutex_init(&smmu_domain->init_mutex); > - INIT_LIST_HEAD(&smmu_domain->devices); > - spin_lock_init(&smmu_domain->devices_lock); > - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); > - > - return &smmu_domain->domain; > -} > - > static struct iommu_domain *arm_smmu_get_unmanaged_domain(struct device *dev) > { > struct arm_smmu_master *master = dev_iommu_priv_get(dev); > @@ -2893,10 +2863,75 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) > arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); > } > > +static struct iommu_domain * > +__arm_smmu_domain_alloc(unsigned type, > + struct arm_smmu_domain *s2, > + struct arm_smmu_master *master, > + const struct iommu_hwpt_arm_smmuv3 *user_cfg) > +{ > + struct arm_smmu_domain *smmu_domain; > + struct iommu_domain *domain; > + int ret = 0; > + > + if (type == IOMMU_DOMAIN_SVA) > + return arm_smmu_sva_domain_alloc(); > + > + if (type != IOMMU_DOMAIN_UNMANAGED && > + type != IOMMU_DOMAIN_DMA && > + type != IOMMU_DOMAIN_DMA_FQ && > + type != IOMMU_DOMAIN_IDENTITY) > + return NULL; > + > + /* > + * Allocate the domain and initialise some of its data structures. > + * We can't really finalise the domain unless a master is given. > + */ > + smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); > + if (!smmu_domain) > + return NULL; > + domain = &smmu_domain->domain; > + > + domain->type = type; > + domain->ops = arm_smmu_ops.default_domain_ops; Compared to the original code, that's something new. Please can you explain why this is added in this patch? > + > + mutex_init(&smmu_domain->init_mutex); > + INIT_LIST_HEAD(&smmu_domain->devices); > + spin_lock_init(&smmu_domain->devices_lock); > + INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); > + > + if (master) { > + smmu_domain->smmu = master->smmu; > + ret = arm_smmu_domain_finalise(domain, master, user_cfg); > + if (ret) { > + kfree(smmu_domain); > + return NULL; > + } > + } > + > + return domain; > +} > + > +static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) > +{ > + return __arm_smmu_domain_alloc(type, NULL, NULL, NULL); > +} > + > +static struct iommu_domain * > +arm_smmu_domain_alloc_user(struct device *dev, struct iommu_domain *parent, > + const void *user_data) > +{ > + const struct iommu_hwpt_arm_smmuv3 *user_cfg = user_data; > + struct arm_smmu_master *master = dev_iommu_priv_get(dev); > + unsigned type = IOMMU_DOMAIN_UNMANAGED; is there any guarantee that master is non null? Don't we want to check? > + > + return __arm_smmu_domain_alloc(type, NULL, master, user_cfg); > +} > + > static struct iommu_ops arm_smmu_ops = { > .capable = arm_smmu_capable, > .hw_info = arm_smmu_hw_info, > .domain_alloc = arm_smmu_domain_alloc, > + .domain_alloc_user = arm_smmu_domain_alloc_user, > .get_unmanaged_domain = arm_smmu_get_unmanaged_domain, > .probe_device = arm_smmu_probe_device, > .release_device = arm_smmu_release_device, Thanks Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel