Received: by 2002:ab2:7104:0:b0:1f7:f6c3:9cb1 with SMTP id z4csp43264lql; Tue, 7 May 2024 09:17:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWM76LnW1KLJbqzhFFJhHu8SuRGKJM+u8C/0CgDlhan4mfU1OEOfjjxsdihlYHvrZoHjgv9PzbzWiY2tiOa6rYIWcm6Vsl9SZIO889aUQ== X-Google-Smtp-Source: AGHT+IH5dQ2hip6XY1GkJI8mp0/zZQWtAu6RWCyhAEWy8tRndfG9QN+KKDYpfrGwI0AfxLJrUH1H X-Received: by 2002:a05:6a00:2d04:b0:6ed:41f4:1886 with SMTP id d2e1a72fcca58-6f49bd8a073mr366771b3a.8.1715098637281; Tue, 07 May 2024 09:17:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715098637; cv=pass; d=google.com; s=arc-20160816; b=T3a2kC21X1Hc34alMXpb9mnUecjP+n+1Cb9XBfbF0jxxc1OLkSIxz3cCWM0JaBtB9Q RBlNBZrPmSftmzaqTN62l7p3UO2PkrsyMFChsS4w6nUIwMP6TXORYTNrc1cN/LdPEI2X nugcG3drhCxlvif3iXf3gVlTWLp8GUj2JVVNS5k/ZJBQ5G0+tvGQBX2xAV64OBeSgqH8 lo4k4Z/bXQBXPJrcC34ZZn/Hl/Up/jytol2t9EhzBcVnjRVHHC6T0EA7kVOZWI4zxT9t /XC/R0cqL9+QF1aAIHKRNsnxxDST5BBaV0cS7GsmFjTvWabNH0F9CGqiXcObGWK5weuw 3L7w== 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=MdwrYxvKykWEvU1ciSRbQbFvSgqU+2A+2xiS1iPvfJQ=; fh=EHgCAGTeW6QtqIlMWvx851rKU3aIiN9/qc9K/AV56cM=; b=y7ngCOM8r+sC+jUuNh7ErtexWGXGzylroEfB/oiX59FskQanzC5D5HDGMQz+kM7TVq 3RsVchVOAlltJ9hUjfdbvWK83DC9vECl4FwtVLAlc4Mue8Milmo76UspbeZiLcDt1gHE Q4Un5GMIUX9wnqelmpPvnpO6RMcbK2QwooI2ewAvyAQkl/pxyYyF30Iy/eJr2R9ccv8S cmbk+1A5fy5LpbiyPhDw6cZRgtBZ8cxmu1x4xn+MgFHP/qXDbe0I2AbzA9yOmUIkZiUS AbAaX+/2DqmtbxdKrWOUBK3ZxqU9Xa94NXm2923BN0KxvOhpkCxWDtzlLXtfHT5Phtos PjLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=D9O+KEzz; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-171724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l129-20020a633e87000000b00613ba02961dsi8497542pga.606.2024.05.07.09.17.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 09:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171724-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=@sifive.com header.s=google header.b=D9O+KEzz; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-171724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 D54B6B22D2A for ; Tue, 7 May 2024 15:52:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1701165FDA; Tue, 7 May 2024 15:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="D9O+KEzz" Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 682B2155A55 for ; Tue, 7 May 2024 15:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715097148; cv=none; b=er9vMLnB4BFIImNjv3Pp4TIYo+7+CJ/JmDQCLy3EAtoFup/uaOgEoigOSf546EgqQFzktB828NzShNObDQ74EQTTIPc677HwJoYr2BipquXIc9gg/bNKxVAtbvjBK3xsMNXSBKWUg8oUPYgNPYXmRTKZNGLCYllKeWYsmBC8CrU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715097148; c=relaxed/simple; bh=1Rv56/oBFuyRJwYgTZCyvFrjtKjGcVyqzKsoClMQ1k0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OrfFLIs9CCP00HwrhJTMyfJXd4qI4REKRIwCzRRNq/q8huawmt63ky4wUhndt7kJJbw3gSYte0C+NKw7SIMjfxRiRbysMaaqtMEvJSdLqhen6khuYeX93o/o+nIZQBGwjdYsPyMpZF5TnsWaRqdu0bk0+DT3K24zHQ86n15ZH58= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=D9O+KEzz; arc=none smtp.client-ip=209.85.166.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7e1835a9339so20558239f.1 for ; Tue, 07 May 2024 08:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715097146; x=1715701946; 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=MdwrYxvKykWEvU1ciSRbQbFvSgqU+2A+2xiS1iPvfJQ=; b=D9O+KEzzVVmVQHUbR5HU6mdo0t7mCbBTNdJi0ZEchfD/TX6uWe2UEgE6ro7+YjuQcA T8iIxlX+7Qh/3crxvEoSSyyRzDqT269gbkEiZP4mSsW32/pDSR4uigEQebxm/g2Oeicq DWxHralEairhoiyPIZ0+NfcisYCQdIi5vDqMI64wcX3UfOHJ11P3Z/7XvJjqDLY7sjQD +I51Wxop1uGfo64e3NUXrXsBbMsECyF6SVj8Yo2dwJL02ETGpcCOBnOULhHt+M+pER0Q awRvsQNgeGP7oeVo+bVCYfsZt4im48A6F4zLfOb1kjbz9QJ3qS9Vh8ARhdd+fNUu+l4E uUeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715097146; x=1715701946; 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=MdwrYxvKykWEvU1ciSRbQbFvSgqU+2A+2xiS1iPvfJQ=; b=mdjefqpqW6UocLOG4wBa5fw7okkQtNR75NiPlHsqYR6Sq4LT6w4CdNjwToz3TXFToI BQCABkTNL/8myhMWDGTmIvmqpCZMj0H+5l2+eoGxKj86Qykid2ywdby+IJOVUP4l418m nps/h2WcWUJrrFUbnfdEMZaxbNVQQyJxpZSK1qpF/3i5xIqNj3OqgtdjTm8vtMOTDwC0 xd6Rzp+hurI54JFFXzlThT/l8C6lSub4vk7XCCgHUED13Wj89G7XCIP9mRGebXAF5bdB Xb4DrvFCD4E0Nw7jEXjaG9lTRZZic+tsSy5RlauXf+Qs2I1syUOWKXcy8Gk5uy+W49oA XIag== X-Forwarded-Encrypted: i=1; AJvYcCVLVMcSS/fEWC9gt8Sua5rukLMnm//ieTOcwjWCOM4qL2BbE/cTWv4swk9EAV7hiih0GlFeQhfDiZ2sKM7WodgkPaKtGYdrFLw1fAFB X-Gm-Message-State: AOJu0YxqECCfgtSELd+Fza9+zBx4B8kOwZfC8/j5Q+x7QdF7RdroO0Z8 N3CAyXZz+3E55IXkl/Lw9XJqul5jdC7QroUIrBIf7d/ygZGRaaQiDMXY9dMKnqVxlzchbluTA6D 1o5ly5NRNxrQw7IsuzdPxl+MIaSiMkCpV8r0SWg== X-Received: by 2002:a5e:db42:0:b0:7de:c47d:a740 with SMTP id ca18e2360f4ac-7e18f722d8amr13408539f.8.1715097146605; Tue, 07 May 2024 08:52:26 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240507142600.23844-1-zong.li@sifive.com> <20240507142600.23844-4-zong.li@sifive.com> <20240507151516.GK901876@ziepe.ca> In-Reply-To: <20240507151516.GK901876@ziepe.ca> From: Zong Li Date: Tue, 7 May 2024 23:52:15 +0800 Message-ID: Subject: Re: [PATCH RFC RESEND 3/6] iommu/riscv: support GSCID To: Jason Gunthorpe Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, tjeznach@rivosinc.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, kevin.tian@intel.com, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2024 at 11:15=E2=80=AFPM Jason Gunthorpe wrot= e: > > On Tue, May 07, 2024 at 10:25:57PM +0800, Zong Li wrote: > > @@ -919,29 +924,43 @@ static void riscv_iommu_iotlb_inval(struct riscv_= iommu_domain *domain, > > rcu_read_lock(); > > > > prev =3D NULL; > > - list_for_each_entry_rcu(bond, &domain->bonds, list) { > > - iommu =3D dev_to_iommu(bond->dev); > > > > - /* > > - * IOTLB invalidation request can be safely omitted if al= ready sent > > - * to the IOMMU for the same PSCID, and with domain->bond= s list > > - * arranged based on the device's IOMMU, it's sufficient = to check > > - * last device the invalidation was sent to. > > - */ > > - if (iommu =3D=3D prev) > > - continue; > > - > > - riscv_iommu_cmd_inval_vma(&cmd); > > - riscv_iommu_cmd_inval_set_pscid(&cmd, domain->pscid); > > - if (len && len >=3D RISCV_IOMMU_IOTLB_INVAL_LIMIT) { > > - for (iova =3D start; iova < end; iova +=3D PAGE_S= IZE) { > > - riscv_iommu_cmd_inval_set_addr(&cmd, iova= ); > > + /* > > + * Host domain needs to flush entries in stage-2 for MSI mapping. > > + * However, device is bound to s1 domain instead of s2 domain. > > + * We need to flush mapping without looping devices of s2 domain > > + */ > > + if (domain->gscid) { > > + riscv_iommu_cmd_inval_gvma(&cmd); > > + riscv_iommu_cmd_inval_set_gscid(&cmd, domain->gscid); > > + riscv_iommu_cmd_send(iommu, &cmd, 0); > > + riscv_iommu_cmd_iofence(&cmd); > > + riscv_iommu_cmd_send(iommu, &cmd, RISCV_IOMMU_QUEUE_TIMEO= UT); > > Is iommu null here? Where did it come from? > > This looks wrong too. The "bonds" list is sort of misnamed, it is > really a list of invalidation instructions. If you need a special > invalidation instruction for this case then you should allocate a > memory and add it to the bond list when the attach is done. > > Invalidation should simply iterate over the bond list and do the > instructions it contains, always. I messed up this piece of code while cleaning it. I will fix it in the next version. However, after your tips, it seems to me that we should allocate a new bond entry in the s2 domain's list. This is because the original bond entry becomes detached from the s2 domain and is attached to the s1 domain when the device passes through to the guest, if we don't create a new bond in s2 domain, then the list in s2 domain would lose it. Let me modify the implementation here. Thanks. > > > static void riscv_iommu_iodir_update(struct riscv_iommu_device *iommu, > > - struct device *dev, u64 fsc, u64 ta) > > + struct device *dev, u64 fsc, u64 ta,= u64 iohgatp) > > I think you should make a struct to represent the dc entry. > > Jason