Received: by 2002:ab2:7104:0:b0:1f7:f6c3:9cb1 with SMTP id z4csp4792lql; Tue, 7 May 2024 08:20:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWjR9NGhs92WXaFqIFb6xlNznHfn8O7Oz1Kj1WR+/IP2BTqam6Q0smtKFtI4Hi/3dlpwEoG8pL/327XTdas0CZ8Bf8+mfsxpkVptAAhw== X-Google-Smtp-Source: AGHT+IEMarDyuDEw9oOyYnV7/jo/aWgZtkcehQdaGngoZ+1uLTvFCmEr7AtH1TU1y4X7DmtTIxjp X-Received: by 2002:a17:907:2d88:b0:a59:cbb5:e09f with SMTP id gt8-20020a1709072d8800b00a59cbb5e09fmr4968488ejc.53.1715095218430; Tue, 07 May 2024 08:20:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715095218; cv=pass; d=google.com; s=arc-20160816; b=BBragThEN7Jir6pprKR/GZd2MNnBrtTK6tN/1ZVtXqdAcl6SahhBtwcbah6xcpxqn6 cEhQA1wJxvN2NyFXIYQ3Ak5MiA0k/EspuL1m7RlcfwehaoaH25XD8+9gd2L9r8vTJPnm PV9Pt/s7hy0CxECfKrfGBiCTIMkqA2cvyhtxda6GSzymM1DmNmpwXR8sIIO+bphV1Ox7 bgEurWrXQV7rjuo80aocN09/oItSVhKm3eIQeRosPg75ut4pe3nIexmIOblcjZ5QWc+V cwXkOuWN0o60mMeVWKQS2iVAwrVJnfeT5aTN53tq6GOXSfgNl3Vhjlpbd7fnG0SMgPkB GhZg== 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=3612MOIikzCEeo+mwv3X2VMyaMFpK5mgqqdWHRbusjg=; fh=TrI31H8Z0Pi1xq68OLn1LsT/dQaLvKKGpSwH0m8Wjco=; b=NwF7fAtbmyPmPatfFVdKy+gb4AH6uYSJJKH1cpFeWglWElL+/5G03qxjOjNWt49BBy Dxb3S4xsYaVULq63NlTSWIXEC38hUjKS41+1RuQ6sXkZV2ZHPdFPBIe4Jmjxjg17usQ4 vFfwjjV5STrbvCaMtKwHP6wBzRfF9S13ybnpdP09h1CS4UZB0CkzvYXNeU19e6rFob9G EJzhKW5a9qjGHzk2Mq9YJ8QGOFojpKikww+5Uzl+8eTDE9CvyQMwgre4q5u4iOYOeqXF aDiV89VKOJIGidqCZjh1UzPL7ZeuzA6ArCdXrXNM5LQnhG5ehLgM6eqdjwn70GF3CliU Jwrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=AZpy448d; 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-171683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dk24-20020a170906f0d800b00a59b1d21c61si3872968ejb.38.2024.05.07.08.20.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 08:20:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=AZpy448d; 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-171683-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171683-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 058FA1F22E1E for ; Tue, 7 May 2024 15:20:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 316B11635BB; Tue, 7 May 2024 15:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="AZpy448d" Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (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 C7C67161327 for ; Tue, 7 May 2024 15:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715095213; cv=none; b=JtFu5eFzn65bmyR+KJ0sKSJk/bIOu+jCfo11N8izWxpuwKElsoXKzB+rEeyK8RcOxB0NCG1VlyIgCDtveWLoJG04//OWW5xlHojjfdi9pqt6bG/NelNrwU+SIiGu3ZkaxcsZlSSJU6xoOqsCn1z/wtG5+VUWCJx01lLzV0Y3u+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715095213; c=relaxed/simple; bh=7wzzu5+Dyb2zQQ/BBHzdLsyJSaQZyO4yWyaBmCt+pjk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Qa1bnqMKTezV/nVSW+kmIiWIj14oEy5tlRgvj3IbWMh/6LqhfAvsaCBCjZ8qc5M+18a/ApsIn6BeJfgLZMxYjNDCyjI65hglhX0RbQi33SG+j/l7pifKTW5dYv+Iwbjwc4UcoYZxOtaKMCiQEoQhkw7MQw68mdSCcPk0JMt9aqg= 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=AZpy448d; arc=none smtp.client-ip=209.85.166.47 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-f47.google.com with SMTP id ca18e2360f4ac-7d9c2096c29so175748039f.0 for ; Tue, 07 May 2024 08:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715095211; x=1715700011; 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=3612MOIikzCEeo+mwv3X2VMyaMFpK5mgqqdWHRbusjg=; b=AZpy448doK/iK5AlReaECWW6bd//Oaw7EGEdbohJSOqAKh27gKenJwqvtXN9XdI0le HgIlnPjfT/Lo3TwaTZs790v7YwUThuNJMbgkFqqHWc9ByBUmQNwOmpa7HrB99UuQdKOO Cgj/mW+hrl7x4OwtpeD32neluhU/oep+HYl4ZqwZoHmNOiuNAGvI1QEbfkZRVSIzn/Jd oTPEL77Eg6Y4S8pB7Dv4Rw4GAUb1dvTAKjDckx5wu2vwClgIB9yGpZ4sYZFvX79FbVXQ eqd2PzeT6z15mK+eHoUPtFsj4U4g7f2aerz9fCdYOMwdc2i09zIovaWP1K7uavdTnGVQ bjdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715095211; x=1715700011; 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=3612MOIikzCEeo+mwv3X2VMyaMFpK5mgqqdWHRbusjg=; b=R6UjG3X95F16LvYOSPb4N9pLGnBjLuFF3bomnqmo/SPkhVpf4lqtG/mKoyMB8+mWej wIro/V4y2MWZsvPR9lPfC/8jdK74VlptyEBEKWw0e7JUHaJegtis3Txn+xfHQJ933uHY TV5G6HmvLf1k4NKBJZmK/2REWC2Ftfwl/blWKKocKWPG2zq+eBACrq9NPnElIU4BAjfg +XuzRRuDgHnetnpaVHtsfs9L4qkR/7AVVresmlQb1ivJ1UX9RLb0vol9DM22XwwwrsBz JzjhNkRIaKP+RtHWFxYGJxyw++X8dehq9k5CnGmhrpV+BYPyMcswLjq3Sgo9lyxg2gPv 6VFw== X-Forwarded-Encrypted: i=1; AJvYcCVozNFk4z9LcyotIo9dKzI9t5vuKj6Nd/AbUNkroZBGnq6B4AW8kwYYst0M7IRSXFJkGYiyptxXTOJsFzvzrsMcuWnlyC7gqzQ0N6zn X-Gm-Message-State: AOJu0YxOL4OXiymvVbGP1RRMmL7H6WCp1Fsf7ZErD/QDhrC1105Vs++Q acX7dXpNpNXY1nR7WufK8AI6ej03bsGa9RdbMa1ZB50BKydEmQRqWIQPjkVY/IwOFLRwuXdSid4 CHAvVXPm7jIt3aSpuCtSnEkO6Ib24v6bYXQR2bQ== X-Received: by 2002:a05:6602:f08:b0:7de:ac01:4224 with SMTP id hl8-20020a0566020f0800b007deac014224mr15044010iob.1.1715095210897; Tue, 07 May 2024 08:20:10 -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-5-zong.li@sifive.com> <20240507145456.GH901876@ziepe.ca> In-Reply-To: <20240507145456.GH901876@ziepe.ca> From: Zong Li Date: Tue, 7 May 2024 23:19:58 +0800 Message-ID: Subject: Re: [PATCH RFC RESEND 4/6] iommu/riscv: support nested iommu for getting iommu hardware information 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 10:54=E2=80=AFPM Jason Gunthorpe wrot= e: > > On Tue, May 07, 2024 at 10:25:58PM +0800, Zong Li wrote: > > +{ > > + struct riscv_iommu_device *iommu =3D dev_to_iommu(dev); > > + struct iommu_hw_info_riscv_iommu *info; > > + > > + if (!iommu) > > + return ERR_PTR(-ENODEV); > > This is not possible, don't include impossible checks like this. Thanks for pointing this out, I will remove it in the next version. > > > + info =3D kzalloc(sizeof(*info), GFP_KERNEL); > > + if (!info) > > + return ERR_PTR(-ENOMEM); > > + > > + info->capability =3D iommu->caps; > > + info->fctl =3D riscv_iommu_readl(iommu, RISCV_IOMMU_REG_FCTL); > > + > > + *length =3D sizeof(*info); > > + *type =3D IOMMU_HW_INFO_TYPE_RISCV_IOMMU; > > + > > + return info; > > +} > > + > > static int riscv_iommu_device_domain_type(struct device *dev) > > { > > return 0; > > @@ -1560,6 +1582,7 @@ static void riscv_iommu_release_device(struct dev= ice *dev) > > static const struct iommu_ops riscv_iommu_ops =3D { > > .pgsize_bitmap =3D SZ_4K, > > .of_xlate =3D riscv_iommu_of_xlate, > > + .hw_info =3D riscv_iommu_hw_info, > > .identity_domain =3D &riscv_iommu_identity_domain, > > .blocked_domain =3D &riscv_iommu_blocking_domain, > > .release_domain =3D &riscv_iommu_blocking_domain, > > diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.= h > > index 1dfeaa2e649e..ec9aafd7d373 100644 > > --- a/include/uapi/linux/iommufd.h > > +++ b/include/uapi/linux/iommufd.h > > @@ -475,15 +475,28 @@ struct iommu_hw_info_vtd { > > __aligned_u64 ecap_reg; > > }; > > > > +/** > > + * struct iommu_hw_info_riscv_iommu - RISCV IOMMU hardware information > > + * > > + * @capability: Value of RISC-V IOMMU capability register > > + * @fctl: Value of RISC-V IOMMU feature control register > > + */ > > Please call out explictly what spec these values come from. Let me add the description for the section that defines them. > > > +struct iommu_hw_info_riscv_iommu { > > + __aligned_u64 capability; > > + __u32 fctl; > > +}; > > Add explicit padding here Add a u32 reserve here in the next version. Thanks > > Jason