Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp37693lqm; Mon, 10 Jun 2024 11:56:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcCY/vRvyY1ZrihSlNWZ0VfNV4VS7qXgfluQ9W2l8bbJQR0egX0i+dZ8NFhxSPwgc8deBSGO4jymzH0VrOPPmT+itRb9eaqQUsv5Z3lg== X-Google-Smtp-Source: AGHT+IHUJQdOf8LGkMpqDQtk5NGolTG/w5fxmp6iECaumzgXlbqrK5yVb2RwhE4rXNYgzNYwXi6Q X-Received: by 2002:a05:6a00:124b:b0:705:9748:7bb7 with SMTP id d2e1a72fcca58-70597487f60mr3984302b3a.22.1718045773630; Mon, 10 Jun 2024 11:56:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718045773; cv=pass; d=google.com; s=arc-20160816; b=GTLW72BcDnX+cRP6wGFPMQtpA07tT4p/WrK6s8iwVJuC9nyhaY6u35oeJRC/oApe70 cUvHBOMjLiMxwPGIUEXSUk1jKJStgK+MvZ4bwDKVYgEsiqSC4G6xmPD1fgtUR/aBVZ0N DBuEsD4/LO6pQULYDNqIMOd/sK1goGVqJavX2Hv2ROSQmJ6R/jBeSbODjkw2Uwn3El9T WnCj13Pf3jr0FfuoeAGq9xuAOV+mXa6rMLCkP2vetW4E8Dnp+I67s3I39Ige/PVSxdhm 8jRni5iZwRRu/OtTRFqZVhUbUvVrUMdcG5ltUg+h5TuvloZwHtUqPgSAH4sPqfZl+7Hv 5gag== 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=g1zkxMfHh2XP11CPVX//08KVDgqqC8nwRqfn9/6C548=; fh=duR/Ww4OsEleqHuQQfBgHDWFH+nauoMqoL/ydtaXUz0=; b=orUsnOmqr3mmEAua/vjmmZsfCAFq2YOCiS3tDDiSQDI3lPgRnSmbZluOEIm2V6LtLN W3kj3KVP7n3/i/3hOtNZ7eDS0hp3rblv8ihuoU25on7P06kpNKVLwAkiqhz77hVHvR1/ eM9pV74QR4pMTey+rVjEm6hBBmub+zSRdKxqVdEU79fqK0C9ClrGMZDM9gXCqQgxBnoB qrHbKtMNTz4eaa+qaf9oB82XPsuxltpoYCZ2oY77NUxgtSb5IJWYaBH04Envb5DyyN/G 8u40oAwLvewKR1P95/Tcn6nUSYyZC2qAUeulyb5OEYzylpc+63BIzd1+lT7bwsKWVyUr 7qUw==; 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="yZzLfl6/"; 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-208765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208765-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70439c87b80si2847108b3a.226.2024.06.10.11.56.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 11:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="yZzLfl6/"; 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-208765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208765-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AE588B2253E for ; Mon, 10 Jun 2024 18:48:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 212B0142E7B; Mon, 10 Jun 2024 18:48:39 +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="yZzLfl6/" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 D8B7E156E4 for ; Mon, 10 Jun 2024 18:48:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718045318; cv=none; b=Sro/Ir2lHmCkxI+tuNsLcnvbbuyD6mjjlFQf/zCxit3o20YDi7uyzkMpEF/44Qou/uuZYoYTO05atpTzjKmLnN5jCShrdri57rMz/gq40Gk/fW4yvRnO5UQf5vWk0m7kWOuh5jUB/yqOd4ts4J3f55psJjGFUAywDq0VBr0m2+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718045318; c=relaxed/simple; bh=uwH3l4n/N5erM0poSH/fMhqelMaa5SHGi2i3looQLt4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qHMa2awi4Wi5edUlfKQic1WXkudKyenk7j8NPOAZpL6B2LbFIoR8Hq0V9OcuFPXEPewbZ+D/lHmgW8O0yZZRQRSHTGiLlqBTEo6A9FZB1qyP3cKvMCL6nYZRR383ehKQ/U5v1r7Gh96oQn2xWmQTtSPUVVfvFFe1jxWRNI5+Ud8= 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=yZzLfl6/; arc=none smtp.client-ip=209.85.216.41 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-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2c315b569c8so257573a91.0 for ; Mon, 10 Jun 2024 11:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1718045315; x=1718650115; 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=g1zkxMfHh2XP11CPVX//08KVDgqqC8nwRqfn9/6C548=; b=yZzLfl6/y+qfEX8AxiFpbnQ3ZbGhBNnsS+aeCwI80kJK6ByXjehqZ7FwpKfVv7vk/t 1EDrBGbJU4yWaD4kKANKXwEZI+mfCT06FSobPOy5GGq/477k8b5wyxh8ZTApu6fLVDNj D8Z6p6Oms+LcREij126JxVlITvr+8BJN2sDYuwDKpZTIyA3NuqwCDKJMj2WcWs+pqCwP 3fWKGS4s8POjvnsqC8VwA3URsd+3Su8wsxfggXgXzX1WWLkdvUvnhjJMOs8Y8QogKuin 04ZqmYjRu0soQ7Bbi8Rq04rF0M5pMxx/PJJ2lUIKPTws16Ybr9091w5ZQkiO8CzJWwTF sJYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718045315; x=1718650115; 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=g1zkxMfHh2XP11CPVX//08KVDgqqC8nwRqfn9/6C548=; b=Mp0UEW45tfeFDmDudlko1HxIMbBNF+Efhld71TQM+OnOOaebXzhLU+xGqz/Y5GUEEm 5XINMSvrHHEYbHRqcbqarVW+bHz3O8N5Qb1LWZbEuVONT0nQaixtaUqH75h1GN4ggmFq ANY5e8ox5srazv+A6XVgCCK9MY1v69tQPKKrnq3MZcubTnTjTPlXdx96/bj32wb9ZACF 4KFiKxEy4KQ20lIXG94OmDPuXd8z5Wj0sTPlkixLMw8OSX0N7EJ2tilrhuNDTrItQjBQ lLqq42NJGh/TxfU1mCgQu3okQ0lgNG7bjY0ShWFeaWhYd1jEsdTZQdiDbEW1TIxgcCU4 sxzA== X-Forwarded-Encrypted: i=1; AJvYcCWq/glTr0xZmdYOvSwZjJdRkoPqLiAJdve9jHy9kp67gqJOBjMJiQJTdRH5/3JdLAMGHI5gIrhl9e+ivsLzershRPZWShLgkMQHz+eg X-Gm-Message-State: AOJu0YwUsolI+f0YgGzL/pM1G15SwEi/BSJ5/LVmRuKHkbgwhI9CUWeZ Uitco54NnJJ+BL6nCDYy+na75vad8w6qlsn2u0EVbB6UNvlDAkS0BPz1HeZz98/ThzO7wywKHn2 FUSUrQdKqjPQNX5Wq7cfQlyOWLZWCAMv3BCqeYw== X-Received: by 2002:a17:90a:fa01:b0:2c3:792:a649 with SMTP id 98e67ed59e1d1-2c30792a75amr2976706a91.2.1718045315113; Mon, 10 Jun 2024 11:48:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240610174934.GM791043@ziepe.ca> In-Reply-To: <20240610174934.GM791043@ziepe.ca> From: Tomasz Jeznach Date: Mon, 10 Jun 2024 11:48:23 -0700 Message-ID: Subject: Re: [PATCH v6 5/7] iommu/riscv: Device directory management. To: Jason Gunthorpe Cc: Zong Li , 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, Lu Baolu , Jim Shu , Vincent Chen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 10, 2024 at 10:49=E2=80=AFAM Jason Gunthorpe wro= te: > > On Fri, May 31, 2024 at 02:25:15PM +0800, Zong Li wrote: > > > > +static void riscv_iommu_iodir_update(struct riscv_iommu_device *iomm= u, > > > + struct device *dev, u64 fsc, u64= ta) > > > +{ > > > + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); > > > + struct riscv_iommu_dc *dc; > > > + u64 tc; > > > + int i; > > > + > > > + /* Device context invalidation ignored for now. */ > > > + > > > + /* > > > + * For device context with DC_TC_PDTV =3D 0, translation attr= ibutes valid bit > > > + * is stored as DC_TC_V bit (both sharing the same location a= t BIT(0)). > > > + */ > > > + for (i =3D 0; i < fwspec->num_ids; i++) { > > > + dc =3D riscv_iommu_get_dc(iommu, fwspec->ids[i]); > > > + tc =3D READ_ONCE(dc->tc); > > > + tc |=3D ta & RISCV_IOMMU_DC_TC_V; > > > + > > > + WRITE_ONCE(dc->fsc, fsc); > > > + WRITE_ONCE(dc->ta, ta & RISCV_IOMMU_PC_TA_PSCID); > > > + /* Update device context, write TC.V as the last step= . */ > > > + dma_wmb(); > > > + WRITE_ONCE(dc->tc, tc); > > > + } > > > > Does it make sense to invalidate the DDTE after we update the DDTE in > > memory? This behavior will affect the nested IOMMU mechanism. The VMM > > has to catch the event of a DDTE update from the guest and then > > eventually go into the host IOMMU driver to configure the IOMMU > > hardware. > > Right, this is why I asked about negative caching. > > The VMMs are a prime example of negative caching, in something like > the SMMU implementation the VMM will cache the V=3D0 STE until they see > an invalidation. > > Driving the VMM shadowing/caching entirely off of the standard > invalidation mechanism is so much better than any other option. > > IMHO you should have the RISCV spec revised to allow negative caching > in any invalidated data structure to permit the typical VMM design > driven off of shadowing triggered by invalidation commands. > > Once the spec permits negative caching then the software would have to > invalidate after going V=3D0 -> V=3D1. > > Jason Allowing negative cacheing by the spec (e.g. for VMM use cases) and documenting required invalidation sequences would definitely help here. I'm hesitating adding IODIR.INVAL that is not required by the spec [1], but this is something that can be controlled by a capabilities/feature bit once added to the specification or based on VID:DID of the emulated Risc-V IOMMU. Another option to consider for VMM is to utilize the WARL property of DDTP, and provide fixed location of the single level DDTP, pointing to MMIO region, where DDTE updates will result in vmm exit / fault handler. This will likely not be as efficient as IODIR.INVAL issued for any DDTE updates. [1] https://github.com/riscv-non-isa/riscv-iommu/blob/main/src/iommu_data_s= tructures.adoc#caching-in-memory-data-structures - Tomasz