Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1089724ybd; Wed, 26 Jun 2019 11:01:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyF87M+PpVQnVh5byM3UPsyE8tDr0UYJBMiOhBLkEmAnRzWtzB7j6JxnLXrJ+/6YKtcD51U X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr367222pjp.103.1561572082376; Wed, 26 Jun 2019 11:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561572082; cv=none; d=google.com; s=arc-20160816; b=G+kybIM9zMzlhvSIqW/yd8U7oGobZLXKxvXHZZ10QPqiyuFrXcQwl5QvZwlKH6Uv+m Q62Q3s/JVMsEt6AIcnrLTX75UaX19w2PA1mK5a5+JQb7UdGsdhrQ8gw+371phJq5Dv42 H0eLVUMPijdygNVV++hJ0CYA46LzP3HupWB0KuGwRFg5HoB+Mhm3WUkQIyd6ERiXDMTj Yf770Ud43ORiky5FgO3807tOZtg3atV7MV0d74DXLXaenCYY7x3c2kHIAV+91uWGVahE dxQp82/uDyXHz1IWHqYrLidu0ikqKwv7bcd9RShuCTlYNtbNAPBoLQY0Y1ryIy6GGBU1 dpMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SEzYJgSY8UORp1xQL1dtZbBHggHUJcK6LZ0ETJEI5xM=; b=HSs/1iA2sNGZc1ErNnBkWvqyBS2/An6jwTm2xJgJAiEEprEuM45MzEvWeFU41u6oae mjGrOCI0MuZojHwgRAd2DpGvyPw0V93/d4D0fvVNCWt601ODoTYBHODtzONySFVKTdgw v/DFogGR8V4g8oFDWSmme8s6008LjWwJ7AlwXS58+/cB8bI6cmlEIgwmQUR4ePRy4T8j xMjkeGsgaIDCgb9Or/Kg/uwzD70v42MQJU9EtdWpZ1bYRnVqyLU/UoS6FPDyUnezhp2V QSu/DHdPXAsnCQ74zIxoN76LJaHqyzuVfj9S+suODCVQv+48r6ERthVUM4YBp/RJLA9O GAQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yjWHcRlp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si3994111plf.87.2019.06.26.11.01.06; Wed, 26 Jun 2019 11:01:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yjWHcRlp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726635AbfFZSAc (ORCPT + 99 others); Wed, 26 Jun 2019 14:00:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:51152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbfFZSAc (ORCPT ); Wed, 26 Jun 2019 14:00:32 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E2FC12177B; Wed, 26 Jun 2019 18:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561572030; bh=amZXky+dzy6w//rZtfTX48NyKxgLPjoPas3mxcVTbe4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=yjWHcRlpFsV3Ts63y+nh2Wr5JEyOiV/tm3lCQSVSJrExovUYgChIQnL3RkPEkPy// tRDUh7tJNyr68TWwrj1bgCY2qwIjsKCfUqYb45HxZltQOPAlWt/6Vm7V739Xajuanf wfGUH0ykQmRyIrO+fVMe1WlTsvKPI8heorx98kQA= Date: Wed, 26 Jun 2019 19:00:26 +0100 From: Will Deacon To: Jean-Philippe Brucker Cc: will.deacon@arm.com, joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, robin.murphy@arm.com, jacob.jun.pan@linux.intel.com, iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eric.auger@redhat.com Subject: Re: [PATCH 4/8] iommu/arm-smmu-v3: Add support for Substream IDs Message-ID: <20190626180025.g4clm6qnbbna65de@willie-the-truck> References: <20190610184714.6786-1-jean-philippe.brucker@arm.com> <20190610184714.6786-5-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190610184714.6786-5-jean-philippe.brucker@arm.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 10, 2019 at 07:47:10PM +0100, Jean-Philippe Brucker wrote: > At the moment, the SMMUv3 driver implements only one stage-1 or stage-2 > page directory per device. However SMMUv3 allows more than one address > space for some devices, by providing multiple stage-1 page directories. In > addition to the Stream ID (SID), that identifies a device, we can now have > Substream IDs (SSID) identifying an address space. In PCIe, SID is called > Requester ID (RID) and SSID is called Process Address-Space ID (PASID). > > Prepare the driver for SSID support, by adding context descriptor tables > in STEs (previously a single static context descriptor). A complete > stage-1 walk is now performed like this by the SMMU: > > Stream tables Ctx. tables Page tables > +--------+ ,------->+-------+ ,------->+-------+ > : : | : : | : : > +--------+ | +-------+ | +-------+ > SID->| STE |---' SSID->| CD |---' IOVA->| PTE |--> IPA > +--------+ +-------+ +-------+ > : : : : : : > +--------+ +-------+ +-------+ > > Implement a single level of context descriptor table for now, but as with > stream and page tables, an SSID can be split to index multiple levels of > tables. > > In all stream table entries, we set S1DSS=SSID0 mode, making translations > without an SSID use context descriptor 0. Although it would be possible by > setting S1DSS=BYPASS, we don't currently support SSID when user selects > iommu.passthrough. I don't understand your comment here: iommu.passthrough works just as it did before, right, since we set bypass in the STE config field so S1DSS is not relevant? I also notice that SSID0 causes transactions with SSID==0 to abort. Is a PASID of 0 reserved, so this doesn't matter? > @@ -1062,33 +1143,90 @@ static u64 arm_smmu_cpu_tcr_to_cd(u64 tcr) > return val; > } > > -static void arm_smmu_write_ctx_desc(struct arm_smmu_device *smmu, > - struct arm_smmu_s1_cfg *cfg) > +static int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, > + int ssid, struct arm_smmu_ctx_desc *cd) > { > u64 val; > + bool cd_live; > + struct arm_smmu_device *smmu = smmu_domain->smmu; > + __le64 *cdptr = arm_smmu_get_cd_ptr(&smmu_domain->s1_cfg, ssid); > > /* > - * We don't need to issue any invalidation here, as we'll invalidate > - * the STE when installing the new entry anyway. > + * This function handles the following cases: > + * > + * (1) Install primary CD, for normal DMA traffic (SSID = 0). > + * (2) Install a secondary CD, for SID+SSID traffic. > + * (3) Update ASID of a CD. Atomically write the first 64 bits of the > + * CD, then invalidate the old entry and mappings. > + * (4) Remove a secondary CD. > */ > - val = arm_smmu_cpu_tcr_to_cd(cfg->cd.tcr) | > + > + if (!cdptr) > + return -ENOMEM; > + > + val = le64_to_cpu(cdptr[0]); > + cd_live = !!(val & CTXDESC_CD_0_V); > + > + if (!cd) { /* (4) */ > + cdptr[0] = 0; Should we be using WRITE_ONCE here? (although I notice we don't seem to bother for STEs either...) Will