Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp762637lqd; Wed, 24 Apr 2024 16:54:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWty1L3i9Hxm2BrwSQAWVKxYPHc+yIp0XXNzyHwswHeubHbKF9RSvWTW3pdztUS4JivKvL+zWvYr0ohjklby4+JWeK/4xuJzIqz9jvKBQ== X-Google-Smtp-Source: AGHT+IFeXxc8cZ6Ln+oD5uV3u5RKPQKX1OxyjLVixVvvIFUYIqRzWWA+om+A/1hnl+KJP4kI3SNC X-Received: by 2002:a05:6214:5284:b0:6a0:9d96:abd4 with SMTP id kj4-20020a056214528400b006a09d96abd4mr1914633qvb.24.1714002863512; Wed, 24 Apr 2024 16:54:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714002863; cv=pass; d=google.com; s=arc-20160816; b=D64/4wSszUEbj0FIDwlHWgWY0IRop5+bX0+c5ggFu/SvQxgXq7DU6XCDVCt/+UlkSG Lmu44DnXULGr4e9x0OIi3EElMOrVJXu1dyTsfE9CHFhkq1cU2xHY0INyw0C0Y9gtCxfd t/ouoOnZYt1IVy84MTF6SvKbnRbMe7u5wGlrqZ0m6NFLMJ6BUvgAQ0obq1AQiIpHfM5B xyPyBbJeI6SgXLcU9II4V7Tk1Y3OKXXoDwpCI3JlEAA0i1rMEdEP9fTBrtTSpMyCrkw+ +wmKogC/zbEdBelmRSc73kLOADEle5naMd4eD1h1kWyWqDkFfvmJATkZs7Vcb9iisd5V kaHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=oZ/IIGjifE//ZRF1QGgVwJ3N+vqoEfQx7orET2JWBFc=; fh=E/Ay9+pMeFmRXI1pn+rpauAvnL5OyUAaXk413ayB3R0=; b=dTLJZBlsQB8XbHB9enV3FpLAHaLfXGtqOvDucWzYI7CZ9u1fXo3+mxh1nzn9vPpqoD lsa5kOo/MQxRN+P/84JCGsJR2vyHCCnKSYbeM+GXm1XZ7NX6Y0UX6iSmiKYU9PVO9O1l qaLDEv2rN/p92PE4jUMQ6FdNG/zlK4tjN8o5zuupEAh9l7YVMKwxD861Wcn14BIcrUHI H0vABIDfOyRPg92qPRbIgYHdbzkpYWJdkdJP/30URQNH+UFwCwcmwdnZOqVlqTdIK+S0 9vXwbV73kNFfCr63hf0lj/LD7++GcD6XtHYy7I4T4VOArx/oyc9IsJFvs0ik5lCaGQq9 uCnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=dw+Ophby; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-157861-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157861-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kj7-20020a056214528700b006a048e55a10si16184249qvb.580.2024.04.24.16.54.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:54:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157861-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=dw+Ophby; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-157861-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157861-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CD4881C21602 for ; Wed, 24 Apr 2024 23:54:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C371E16F27B; Wed, 24 Apr 2024 23:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="dw+Ophby" Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95B6616EC1E for ; Wed, 24 Apr 2024 23:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714002854; cv=none; b=suKCllb6QSEJjmarU5Nj6IGne8wVvAjqrsh28jDs7w98Dzq3Ca/+k7mli3Zsb/kWz8glkHQsn8yR1VnnwIbtjzIKKMZW3QO2NVY0emvAtZElfwvSqAIEg9BvouQugbkHFb/V8giw3BbBdesj/k43j+v4t1viZVsgAzAPuQNOX+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714002854; c=relaxed/simple; bh=+6y5EliBrhXmGNiwJV34o/LU6Lh2xWSLJP5lhHbJWD4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Lz55lFM11yNk3rSZgYjRMJauahCocUUbE/jg6aq0oRYTNrYSWNSOv/bJv5syXU4t8qFdAqtZX8TvIVd2fWC0OaP6Wq7k48/v/cxHF2wEm3suJm6c+bZWZPUA+Km2t+q3DNzWTJVBNEhHF0defynxLvQjI84eugOWAO89SN8h4sM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=dw+Ophby; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5c66b093b86so1184561a12.0 for ; Wed, 24 Apr 2024 16:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714002853; x=1714607653; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oZ/IIGjifE//ZRF1QGgVwJ3N+vqoEfQx7orET2JWBFc=; b=dw+OphbyVA0JytxzFdQanLHcLfNzhoutidNfgusx6XCniIDL41BbafbgAzuEC2Ew8d U87FQgbbjHdNqwG8U3BPlDuSNk/i/iXES5P/HyU71qABdtn7y2/ceCvp7qAaSu4HaMaA 731ru/Ip1DOE4ocse849jnU4b+rTxvYxuF00fMeWv+F651xITSmfvRkgVzumlyh78KlC DBIrK3+hJ817Oe/nVrWckhXHaBuolpBfOA4omyc4yZWyOX5poF2aetn99iTBoK3jLScy n8Ds65GyehwNiSxj9T06Vn+Oqhjjl1+juLwYhEeGmt+jopJu8mzkgwUWOULrnhA+oAWH GrnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714002853; x=1714607653; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oZ/IIGjifE//ZRF1QGgVwJ3N+vqoEfQx7orET2JWBFc=; b=SlAHlBlXQVxvPQdKeIwp3nuNCu7+c4UVaOwBfYuEqSLTRM9wz2Z99aXEeuAofG5LTI 4JFzdxguNdqtNHZ5fhtehYtp/exB1q0zgAvqzW908ZQsZ3A4XuGbCX69BelQWlIs9lq3 z6qdjkNgxtoT3qBrDudaJ4/SXla0FF1Qx72IlbHvP3EPrlZTsCz+9zUUk4iYjwQKkzap 7tXXUm4pQDHnlNkodvBYsrpglE8e72lU8IqIw7msAblEEU3/ExeuErkkRYvCIMmGVCRj LxF/+Pk0KuyV8vAaC/iLIrR0LrSmpl72wmte4KK40UGzNNh+HwyQwM30utKlhprXJaK8 726w== X-Forwarded-Encrypted: i=1; AJvYcCWEhH9nB+b/9N7dAFAme0DSSqyODBvrwWp+/jFY8x18xqg4qOQF/fQ/2V6f3CjX9GSmLmlRL2NNlB/3Ho4Idfbu1DA3npgJHRse4UeC X-Gm-Message-State: AOJu0YyTF9cD+m3EJYVdxP1VclIctbObHgns5Lx4CGyHbKw7ymsfGgjV Rmct6I68LSMiYqOS6CcCC1Kinrkdae60wTq8Hu27UX30SWEkz5GUFfFHGzy2tBeVj3u9n2jbIRI 2xo94MuVIJx7D7r2YSYPny/D0/1JifqzrEEM6Pw== X-Received: by 2002:a17:90a:b104:b0:2aa:b377:d29e with SMTP id z4-20020a17090ab10400b002aab377d29emr1768305pjq.3.1714002852883; Wed, 24 Apr 2024 16:54:12 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <301244bc3ff5da484b46d3fecc931cdad7d2806f.1713456598.git.tjeznach@rivosinc.com> <20240419125627.GD223006@ziepe.ca> <20240424233950.GJ231144@ziepe.ca> In-Reply-To: <20240424233950.GJ231144@ziepe.ca> From: Tomasz Jeznach Date: Wed, 24 Apr 2024 16:54:01 -0700 Message-ID: Subject: Re: [PATCH v2 7/7] iommu/riscv: Paging domain support To: Jason Gunthorpe Cc: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Sunil V L , Nick Kossifidis , Sebastien Boeuf , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux@rivosinc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 24, 2024 at 4:39=E2=80=AFPM Jason Gunthorpe wrot= e: > > On Wed, Apr 24, 2024 at 04:30:45PM -0700, Tomasz Jeznach wrote: > > > > @@ -46,6 +46,10 @@ MODULE_LICENSE("GPL"); > > > > #define dev_to_iommu(dev) \ > > > > container_of((dev)->iommu->iommu_dev, struct riscv_iommu_devi= ce, iommu) > > > > > > > > +/* IOMMU PSCID allocation namespace. */ > > > > +static DEFINE_IDA(riscv_iommu_pscids); > > > > +#define RISCV_IOMMU_MAX_PSCID BIT(20) > > > > + > > > > > > You may consider putting this IDA in the riscv_iommu_device() and mov= e > > > the pscid from the domain to the bond? > > > > > > > I've been considering containing IDA inside riscv_iommu_device at some > > point, but it made PCSID management more complicated. In the follow > > up patches it is desired for PSCID to be unique across all IOMMUs in > > the system (within guest's GSCID), as the protection domains might > > (and will) be shared between more than single IOMMU device. > > The PCSID isn't scoped under the GSCID? That doesn't sound very good, > it means VM's can't direct issue invalidation with their local view of > the PCSID space? > To clarify: PSCID namespace is per GSCID. However there might be more than one IOMMU in a single system sharing the same GSCID, and with e.g. SVA domains attached to more than one IOMMU. It was simpler to manage PCSID globally. PSCID management for the VM assigned GSCID will be the VM's responsibility. > > > This seems suboptimal, you probably want to copy the new design that > > > Intel is doing where you allocate "bonds" that are already > > > de-duplicated. Ie if I have 10 devices on the same iommu sharing the > > > domain the above will invalidate the PSCID 10 times. It should only b= e > > > done once. > > > > > > ie add a "bond" for the (iommu,pscid) and refcount that based on how > > > many devices are used. Then another "bond" for the ATS stuff eventual= ly. > > > > > > > Agree, not perfect to send duplicate invalidations. > > This should improve with follow up patchsets introducing of SVA > > (reusing the same, extended bond structure) and update to send IOTLB > > range invalidations. > > > > For this change I've decided to go with as simple as possible > > implementation and over-invalidate for domains with multiple devices > > attached. Hope this makes sense. > > It is fine as long as you do fix it.. > SG. I'll have a second look if it can be fixed sooner. > Jason Best, - Tomasz