From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20A64224B0C for ; Thu, 29 May 2025 13:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748526974; cv=none; b=Vd6sTAK50ypb9B445DyhOfflGWVw9o+F0wQOSDw92iBj+9tB/B2nTAds2QDYEv+D+ytP6T702VFSxD0HSDXfG4gjfhcXli3alWHs3xHEBxPsJm+XS+oU+UWpJHt8+pT8p7Rnw2sxa0ZKe6iHvqYOKt2dzX1HwTOrQJK3zGsvvm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748526974; c=relaxed/simple; bh=j5Q3sX/YIUtqn5PpjjmEJ4Hp4cwg9WJvwuLWZ/prHJU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X3/HSuOR+NomupPtBBNfFx+3Av8d0/2sxEkdX/lE7jJjxO1t1MAlvOsHb6eyvpAXSQKuLPIX3i5sOStbZyBVlAxhuLqQt8ncP/eJZXpvOmsYRj5t6PDucOfI7g+IhQtAvItHtw2GXRCp6d/6oZS26tN+h24YXSOLDu4Dsximozc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JwsR4iLN; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JwsR4iLN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1748526973; x=1780062973; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=j5Q3sX/YIUtqn5PpjjmEJ4Hp4cwg9WJvwuLWZ/prHJU=; b=JwsR4iLNRDOWbHwKbN8hqTPX2IN/eSoqwOr0QZApk10JcM9nCoP5UtKk ObqE+WDf+vSW7sNHz0M9IgPo9SkJlhaq+WnPFrA+VOhknbl/DxO9FijjH 3ukDi3AdbiTL4GuTZR5bn1zLdv2zztz71BGFrDUPwpredWQp779chxHtP Osb8KXMtXs6YzFE0NKP3vkqxF0yhj3zDbp+5sbng+yLAmloWso0Z6FYtm pvyM0VAxve5hgGvA41ccoljCLkXSoYuIz5rCH8d+je/A/VISiU+JDAPr3 GPcCh/tmSPBFy1gUVYiA+N5Zj7F3YS8pMnKpHWvqnAxX7p9il+jt9AIEg w==; X-CSE-ConnectionGUID: /OU70Hr0TAat+ZwLXNWjyQ== X-CSE-MsgGUID: 8rg0N5GJQQWZ+tSunMxWjQ== X-IronPort-AV: E=McAfee;i="6700,10204,11448"; a="50288808" X-IronPort-AV: E=Sophos;i="6.16,193,1744095600"; d="scan'208";a="50288808" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2025 06:56:12 -0700 X-CSE-ConnectionGUID: WfM2R1bkRsiM46zXzFf9rQ== X-CSE-MsgGUID: o7pY8hpvTJWORXYYkEUdoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,193,1744095600"; d="scan'208";a="148854885" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orviesa005.jf.intel.com with ESMTP; 29 May 2025 06:56:10 -0700 Date: Thu, 29 May 2025 21:49:51 +0800 From: Xu Yilun To: Jason Gunthorpe Cc: "Aneesh Kumar K.V" , Shameer Kolothum , Alexey Kardashevskiy , Dan Williams , linux-coco@lists.linux.dev, linux-pci@vger.kernel.org, gregkh@linuxfoundation.org, lukas@wunner.de, suzuki.poulose@arm.com, sameo@rivosinc.com, zhiw@nvidia.com Subject: Re: [PATCH v3 12/13] PCI/TSM: support TDI related operations for host TSM driver Message-ID: References: <1bcf37cd-0fc4-40fa-bcd1-e499619943bd@amd.com> <20250527130610.GN61950@nvidia.com> <20250527144516.GO61950@nvidia.com> <20250528164225.GS61950@nvidia.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250528164225.GS61950@nvidia.com> On Wed, May 28, 2025 at 01:42:25PM -0300, Jason Gunthorpe wrote: > On Wed, May 28, 2025 at 05:47:19PM +0530, Aneesh Kumar K.V wrote: > > > +#if IS_ENABLED(CONFIG_KVM) > > +#include > > + > > +static void viommu_get_kvm_safe(struct iommufd_viommu *viommu, struct kvm *kvm) > > +{ > > + void (*put_fn)(struct kvm *kvm); > > + bool (*get_fn)(struct kvm *kvm); > > + bool ret; > > + > > + if (!kvm) > > + return; > > + > > + put_fn = symbol_get(kvm_put_kvm); > > + if (WARN_ON(!put_fn)) > > + return; > > + > > + get_fn = symbol_get(kvm_get_kvm_safe); > > + if (WARN_ON(!get_fn)) { > > + symbol_put(kvm_put_kvm); > > + return; > > + } > > + > > + ret = get_fn(kvm); > > + symbol_put(kvm_get_kvm_safe); > > + if (!ret) { > > + symbol_put(kvm_put_kvm); > > + return; > > + } > > + > > + viommu->put_kvm = put_fn; > > + viommu->kvm = kvm; > > +} > > Shameer was working on something like this too > > I would probably split just the viommu kvm stuff into one patch so you > two can share it. > > > @@ -68,10 +121,32 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd) > > */ > > viommu->iommu_dev = __iommu_get_iommu_dev(idev->dev); > > > > + /* get the kvm details if specified. */ > > + if (cmd->kvm_vm_fd) { > > Pedantically a 0 fd is still valid, you should add a flag to indicate > if the KVM is being supplied. Did I miss something? Shameer's patch passed in struct kvm* through iommufd_device_bind() then to viommu, and has your Reviewed-by. I'm a little confused... https://lore.kernel.org/all/20250319232848.GD126678@ziepe.ca/ Thanks, Yilun