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 D8BDFC6FD1C for ; Fri, 24 Mar 2023 15:46:52 +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=vDMWm/yOMLHWsYEkNAgFlVovr5SEHdQk/+Ka/J0p6NM=; b=BEf3wGG/BIxCjx lIWO0hR3zfJgPTyYrVSoZTeTG+7Gc8kok6EvDs+7lwDuhninOK6UCpmjHRTr0dVXGYbwVFDIx9AJH TPd+/ZMlxc2f8ypSrMFbFMzUQXetElr3eBDbtVFlxtpUHKseaOp7X+cxX6qE0dJppdoOGGDF1Tl/s rA6Tn/v90sZbv2g5wnQuyF/B2iz3b7rGoFB64tAd9B9QgYScqHo0dDCeqSRsFP+8avtsiigbOKn8C ZIMB80bUJFKCllCdzzzaournW4pQogpy4HMYPhCShSK9o6/H3zIEe1nzUrW84caAIh35BAFPDeBvH Xr3Z/yZJXy0OVOVqD4cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfjbM-004tIC-2Z; Fri, 24 Mar 2023 15:45:12 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfjbJ-004tH8-2B for linux-arm-kernel@lists.infradead.org; Fri, 24 Mar 2023 15:45:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679672708; 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=vRC1/VdP8QTnH2Qzmn0A62aZq5RTC7SBPX5Sc2dfmw4=; b=XzfDziRlFKwHYkO5IazNc7xWS9NbRtZBeuqzGotEFOgGcNEYtZOJYkASiPob2HRGJoH/R9 8ENduMHisMpUPPtTXUSkgHgT5rSEl/iTjnHJJFIl2koxnPPNWtrLShk1RrmDypmldUoBZ+ 7u3zFBox6yPCrVXsJdmWuJHICh5WOik= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-HOJkJNgpMLeqjcNYhBXpzQ-1; Fri, 24 Mar 2023 11:45:04 -0400 X-MC-Unique: HOJkJNgpMLeqjcNYhBXpzQ-1 Received: by mail-qk1-f200.google.com with SMTP id 203-20020a370ad4000000b00746981f8f4bso968827qkk.13 for ; Fri, 24 Mar 2023 08:45:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679672704; 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=vRC1/VdP8QTnH2Qzmn0A62aZq5RTC7SBPX5Sc2dfmw4=; b=a3SCte5NFy2lm7aXkArWlo7KGtBTmjDr1qZMitAnTs3wZBz244W2xy0m5gCpmiKci+ B4JqjmgVpEmJ4bRr65NSjDiNJVq7p9EUymBnq3i/dnKc2pbY2xb07noJn7EiL/1s0Ey4 4ya7OIMagu0wTI09iyLbKgm/bey4TsRE8/5l1MuSdZ7cMom4FewUbP3srpELuZbs3bpT tvzzFjZSZZvJxRXPh7CQOl/PdzADE05VcVWkTu+Cu61/c+Zgzcd3fJOysoOi2+qvCCZN lF6NQvIgFvgubmmNs3upo+YetAjfqgCswDG3goD8NoKnEJ+ZghzwtrNa5TdWAWdbu28s fMvA== X-Gm-Message-State: AO0yUKU5IDx5yofpSTg0CL6xT0gJadC8htolt6q9kyqBWcimYvFoMfAa lO4O5+o67KloKKITo5kxsL8/nZfjB7nQGIcdCMpUuNUivk2bo7NCcHAc9Hcm7sPasEq3EqH9z2j mXok4fok66Y2WHvaGYeyDqREU6pPtsnsG1go= X-Received: by 2002:a05:622a:1a98:b0:3dc:a4e5:aef0 with SMTP id s24-20020a05622a1a9800b003dca4e5aef0mr5984978qtc.9.1679672703947; Fri, 24 Mar 2023 08:45:03 -0700 (PDT) X-Google-Smtp-Source: AKy350YoDFgTJsdfo1CEzGHeBcuvWj1BI5zKHFdIUbVT2L0Ym7GunFU5QXEIokCQtmR0rSAjY4mzZg== X-Received: by 2002:a05:622a:1a98:b0:3dc:a4e5:aef0 with SMTP id s24-20020a05622a1a9800b003dca4e5aef0mr5984944qtc.9.1679672703630; Fri, 24 Mar 2023 08:45:03 -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 m124-20020a375882000000b0073b8745fd39sm14290433qkb.110.2023.03.24.08.45.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Mar 2023 08:45:02 -0700 (PDT) Message-ID: Date: Fri, 24 Mar 2023 16:44:58 +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 12/14] iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED type of allocations 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: From: Eric Auger In-Reply-To: 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_084509_799277_19E8508C X-CRM114-Status: GOOD ( 23.98 ) 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: > Add domain allocation support for IOMMU_DOMAIN_NESTED type. This includes > the "finalise" part to log in the user space Stream Table Entry info. Please explain the domain ops specialization. > > Co-developed-by: Eric Auger > Signed-off-by: Eric Auger > Signed-off-by: Nicolin Chen > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 38 +++++++++++++++++++-- > 1 file changed, 36 insertions(+), 2 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 5ff74edfbd68..1f318b5e0921 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -2214,6 +2214,19 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, > return 0; > } > > + if (domain->type == IOMMU_DOMAIN_NESTED) { > + if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1) || > + !(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) { > + dev_dbg(smmu->dev, "does not implement two stages\n"); > + return -EINVAL; > + } > + smmu_domain->stage = ARM_SMMU_DOMAIN_S1; > + smmu_domain->s1_cfg.s1fmt = user_cfg->s1fmt; > + smmu_domain->s1_cfg.s1cdmax = user_cfg->s1cdmax; > + smmu_domain->s1_cfg.cdcfg.cdtab_dma = user_cfg->s1ctxptr; > + return 0; > + } > + > if (user_cfg_s2 && !(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) > return -EINVAL; > if (user_cfg_s2) > @@ -2863,6 +2876,11 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) > arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); > } > > +static const struct iommu_domain_ops arm_smmu_nested_domain_ops = { > + .attach_dev = arm_smmu_attach_dev, > + .free = arm_smmu_domain_free, > +}; > + > static struct iommu_domain * > __arm_smmu_domain_alloc(unsigned type, > struct arm_smmu_domain *s2, > @@ -2877,11 +2895,15 @@ __arm_smmu_domain_alloc(unsigned type, > return arm_smmu_sva_domain_alloc(); > > if (type != IOMMU_DOMAIN_UNMANAGED && > + type != IOMMU_DOMAIN_NESTED && > type != IOMMU_DOMAIN_DMA && > type != IOMMU_DOMAIN_DMA_FQ && > type != IOMMU_DOMAIN_IDENTITY) > return NULL; > > + if (s2 && s2->stage != ARM_SMMU_DOMAIN_S2) > + return NULL; > + > /* > * Allocate the domain and initialise some of its data structures. > * We can't really finalise the domain unless a master is given. > @@ -2889,10 +2911,14 @@ __arm_smmu_domain_alloc(unsigned type, > smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); > if (!smmu_domain) > return NULL; > + smmu_domain->s2 = s2; > domain = &smmu_domain->domain; > > domain->type = type; > - domain->ops = arm_smmu_ops.default_domain_ops; > + if (s2) > + domain->ops = &arm_smmu_nested_domain_ops; > + else > + domain->ops = arm_smmu_ops.default_domain_ops; > > mutex_init(&smmu_domain->init_mutex); > INIT_LIST_HEAD(&smmu_domain->devices); > @@ -2923,8 +2949,16 @@ arm_smmu_domain_alloc_user(struct device *dev, struct iommu_domain *parent, > 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; > + struct arm_smmu_domain *s2 = NULL; > + > + if (parent) { > + if (parent->ops != arm_smmu_ops.default_domain_ops) > + return NULL; > + type = IOMMU_DOMAIN_NESTED; > + s2 = to_smmu_domain(parent); > + } Please can you explain the (use) case where !parent. This creates an unmanaged S1? Thanks Eric > > - return __arm_smmu_domain_alloc(type, NULL, master, user_cfg); > + return __arm_smmu_domain_alloc(type, s2, master, user_cfg); > } > > static struct iommu_ops arm_smmu_ops = { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel