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 B8348C4828F for ; Thu, 8 Feb 2024 16:26:24 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iJ+i/0GA1IbSoMWXMZ/bDsHZFv5deJEtvhPxTElysSA=; b=qLHe+0dmRNuFCu LF0dToKN/3OhQA+PVaKGk93D6/UygNZq9ydHOT5xtKH+7SDPXcxOuETamFL9g+trbNeZR8studW9d oUtV4JeBMr8wKWuyQuwVBSTD52Om8RI07VnMqsT0fiuzV2jefG4j8leN74ttNXrmVT0ttgCFTC2kl 3q/DUJLnKTt5dVsq8NcdyUcJJIlmchWUL+JInzW/GeFyvG5GgJlpPbkPhnLOTTmXdP0h18ItHqqRx sHFhMg7ICiQAncLPlM6/K5KN7mX+YvKMwSJnoM+dMiWZvDjY+nrDPsSRBvWgu0Ms4U/Kih+4Rmm6m gjZBkghQhTAobdV5TyPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7E3-0000000EJ2a-26it; Thu, 08 Feb 2024 16:26:11 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rY7E0-0000000EJ1h-411J for linux-arm-kernel@lists.infradead.org; Thu, 08 Feb 2024 16:26:10 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-214ca209184so1251964fac.1 for ; Thu, 08 Feb 2024 08:26:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1707409567; x=1708014367; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uEuGXrzdCmYr9ISXm9wok5krFRzGj/Nfq5pKtnmjTpE=; b=jAtZ73U6mrOiw3vIByY0VEUkztwrk+Awek95nUdrahXisJBjwRba7v1AECtnLlQ1BX ibEybKoUI9ofSnqOuRT9M+EamdJPll+uOec3eLG3bJlKwL01vxffLkWONYt5nbFtndoF Oojja/EzCDQW8uX4VLI7TBtCLk20oPwVwn2PzhC+AF/hBzY52GF0bOHNaIcJ9bKRd3S6 6nmdkYLcboQYcWlKunphIGew/CD7yRJNjJyZTuWZnLmRf74jieLM8vvTQ0KEYHIaVJDU 8RSEJOpMHe68V6i/nmL4JHC4fV1pfJUMyWYXSZkqQSzLX1FgiCFN8WPK10GcG6eaztfI IMxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707409567; x=1708014367; 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 :message-id:reply-to; bh=uEuGXrzdCmYr9ISXm9wok5krFRzGj/Nfq5pKtnmjTpE=; b=tgCrwdO2EJleSslvndYUKQnIPin1qhEIGo2X0UXc5jyfehXMa4lKv0nfVVNg49QSXV SE91wdoxE0qTxm4Ok2vkLNRLdTTzRdpmRloNiPnS9DNijxgCYjqQNQHRxUH4rwyeEr0d W1Zn0+LE8UASa+vgObwbJUKXsh3hPsG6hJMXjJPBxHY1wv6bmi+LBouvRRK+1Qahiqv0 EEAB0OVzqDQ2sHqfPhJZ620ZNYsrEvKx3yuPPtB1ZnZ4Nlh1wetfymz4uSDIprncA6KN jPdhUFUujrLxu1jUlFUMCKwpLQ+Buj9h7oEvalHF1zP9BNmy3kzG2XEko9zZz3RABGjK Myfw== X-Forwarded-Encrypted: i=1; AJvYcCUH/s76VpSe8rucTHYlHXTWxSTRFLW+bWcTbet8PwWKQmRUsElrzSAtUM0wnzDxLSwAFMcneUWv4MATWFChTa6hPfyJFUuXBsnm9n+6TFRsrxonHN0= X-Gm-Message-State: AOJu0YxUbP9vRVKZUGDXsZ22+7oRkRfqFZGfTyAjk+W/DiB/Q2li5dxY hfQkAINcOzUXz1CAyD5fjCCN1/JJ82Z44gWryayA4YbyGcruVhxsgBDb2kWkVY0= X-Google-Smtp-Source: AGHT+IHEcGaBNtRLEgrLbFu1sCv+GngpUjS6FT8VFiEziEh9X9S5+cHNVzY6D4c3XKvRcB+Nite3dg== X-Received: by 2002:a05:6871:4009:b0:219:f2a3:d8ad with SMTP id kx9-20020a056871400900b00219f2a3d8admr2877587oab.42.1707409567035; Thu, 08 Feb 2024 08:26:07 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVpw2zU29fHt7MX61F7ZAet9NJsnC7/j5ovgqUH+vgWFOdJEoCDEN4Cm6/zORgxNNVNzeUjK62Qqfek2NqlAhKhdzZexbVc86AO72THL72VPkYSpzl6907QFQsG86oQfsZUH/c6NVbI9nuNtfGLUtPJTVCG+4pYvu+cy1qckYHnPwG/5IdLAxQ8JK6BnnWadYO/4BxGzMCyu8F/RTFP2I1gWRY/zfr+cFEzBg2MBGpG9R+Eh6dAkr6Tm2ZHhrzEDC0GuFeJ/WmPqrKOOeHRB1YTx+2Kgy9yKa4U3X+5RFS0SFPXMQV5ieWUV0sOqmYQlyqbl/ha1MQt2/bQxNoaFEA6vVxS3/Eh4ACoE92Gd3TSvVjmrtmnKDAf1dH2LIfudbc3WtQtSrGexx2IaVfKoXwZ0iw/0joFCLo= Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id h40-20020a056870172800b002199d8f9e2esm791993oae.19.2024.02.08.08.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 08:26:06 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rY7Dx-00F3Fa-PH; Thu, 08 Feb 2024 12:26:05 -0400 Date: Thu, 8 Feb 2024 12:26:05 -0400 From: Jason Gunthorpe To: Shameerali Kolothum Thodi Cc: "kvmarm@lists.linux.dev" , "iommu@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , Linuxarm , "kevin.tian@intel.com" , "alex.williamson@redhat.com" , "maz@kernel.org" , "oliver.upton@linux.dev" , "will@kernel.org" , "robin.murphy@arm.com" , "jean-philippe@linaro.org" , Jonathan Cameron Subject: Re: [RFC PATCH v2 6/7] iommu/arm-smmu-v3: Use KVM VMID for s2 stage Message-ID: <20240208162605.GU31743@ziepe.ca> References: <20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com> <20240208151837.35068-7-shameerali.kolothum.thodi@huawei.com> <20240208155915.GR31743@ziepe.ca> <8bfca4c5bfe7424691efdae0f686ece4@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8bfca4c5bfe7424691efdae0f686ece4@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_082609_019571_9F716503 X-CRM114-Status: GOOD ( 19.85 ) 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: , 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 On Thu, Feb 08, 2024 at 04:14:07PM +0000, Shameerali Kolothum Thodi wrote: > > > #include > > > @@ -2399,9 +2400,13 @@ int arm_smmu_domain_alloc_id(struct > > arm_smmu_device *smmu, > > > } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2) { > > > int vmid; > > > > > > - /* Reserve VMID 0 for stage-2 bypass STEs */ > > > - vmid = ida_alloc_range(&smmu->vmid_map, 1, > > > - (1 << smmu->vmid_bits) - 1, GFP_KERNEL); > > > + if (smmu_domain->kvm) { > > > + vmid = kvm_pinned_vmid_get(smmu_domain->kvm); > > > + } else { > > > + /* Reserve VMID 0 for stage-2 bypass STEs */ > > > + vmid = ida_alloc_range(&smmu->vmid_map, 1, > > > + (1 << smmu->vmid_bits) - 1, > > GFP_KERNEL); > > > + } > > > > We cannot allow the two different STEs to be programmed with the same > > VMID but different translations, so somehow the two allocators have to > > work together. > > My idea was, we only set smmu_domain->kvm in the nested parent case > and that means SMMUv3 supports both S1 & S2. So all the non-nested domains > are using S1. Okay, that is what I was thinking to get to. The logic needs to reflect this directly though: /* * There can only be one allocator for VMIDs active at once. If BTM is * turned on then KVM's allocator always supplies the VMID, and the * VMID is matched by CPU invalidation of the KVM S2. Right now there * is no API to get an unused VMID from KVM so this also means BTM systems * cannot support S2 without an associated KVM. */ if ((smmu->feature & ARM_SMMU_FEAT_BTM)) { if (!smmu_domain->kvm) vmid = -EOPNOTSUPP; else vmid = kvm_pinned_vmid_get(smmu_domain->kvm); } else { /* Reserve VMID 0 for stage-2 bypass STEs */ vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1, GFP_KERNEL); } (and matching change to the free side) > This is what I was trying to do. But not sure we have systems out there where > only S2 is supported and that may require a private VMID without KVM. iommufd can ask for a nesting parent without supplying a KVM fd, which would cause vmid aliasing between the two allocators. That needs to be blocked as above Jason _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel