From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 6EC834D90D7 for ; Mon, 11 May 2026 21:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778535684; cv=none; b=KEUsGW3ihmLwrVYVjLUYArYa/nt+qWo/zJ5PqhqEaCH2Tan3Q95gC3CFe9BgE4Tx80IpVcQ75io7nMkDyOZprvbV2eQ4wXb1wO90Zjvobs6NL7CZthDgO0KmSg/I8N+JAcSeuCrF6zagkBfe6lTM3njRHLPULMI5GjkCos1y93g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778535684; c=relaxed/simple; bh=/e3f6zy8+2O3SOV431n7I0SZEJjZUbJQmkF91G952Sk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B9xIFzenbSjii5+RJPHjfqO2wBJExZe4X9aDd3X/8uPW04sIwCmAr6oVQqwdWVnhGj53fMB+gGIqYiAxkREdD2ypLqFHHP4hbPIYUOJ3v4lnteabqNSHxXU9huUG47Gydc5Cz3orkXiZLiTUl1qzXyITpcDkjwaS98BRpzf5hKs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rzmbnNSm; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rzmbnNSm" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so2755ad.0 for ; Mon, 11 May 2026 14:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778535683; x=1779140483; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=s41dmpYUKpt1K9Yzx8SN6t8VShmt2QtfJ1wxqCwyx+E=; b=rzmbnNSmOWwpbUSedN3yPzv3qEczuKqa5r2SYB1KOFaRbI5XwacF/E4N6iFJ//2Lm1 51TpwIrlIgWRQZZz0AfPzvFeKPP3depppG/ykQxWQZVyh3q2tN14C+kwt9zYzvgLO//I ldSl3yFSI5OEuVs+i+DhJ/C08Vqx8I2rXGKWI6QZKR16fQLShsKNyCQ7scaWa6j8X8E2 tAGbjxrx2hQnFDraK+kg3wK7u+MVUB5uSaAiMm696DYtqlQZQ7kAw6ViqxkXnmm9fj/A qcHYD2tjaMU0CKkw4GWjQsCEjhsx5FrwPNsMwW4P+vodIzbbUVbyutDP0BKMBbpUMnZV vZEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778535683; x=1779140483; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s41dmpYUKpt1K9Yzx8SN6t8VShmt2QtfJ1wxqCwyx+E=; b=TdLqhoZuRqqwy/b+Aqq7BWUSIcrRhHXRUkJBzObzLN8t52Cw4FR9adIyY8ln0PFOAU 2P1WkXBNbmTSHNIQSc9YXadrmMPcEnyfATpXrzm4U2+sn3BdBsUplWvPKKVhyk0fqnyA sbPkiH+6CuSNSrB7XGAMiMRdNoEjnz7s0AmJc4P0aw5S+2jWza1bQHuHZvjKZFu4ku7n rW5obDz5mkdAEzh23wX7IO0EHh94Ay4osgUKwe4Jji2B/qpgr5NPJPHhxSfzUqHdTuir t/aOIsie9crb/IsHaANeHudJyjQbEGLn7IpIQ5yUG2QnH1c+4j1CuNyQuIr/758PX38x eVvQ== X-Forwarded-Encrypted: i=1; AFNElJ8Oao34j3z33VoOKEPCLQaPAZM228sZrZezY8yaExr/d3cw8jL01tBGQ4VKEhCvdldaX9TVv23lMi6MG7Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzbfAsfvumMF3x7NUvwfU8hsMhEc42DI5mrITPNr7tPnENWplgU 2hYtSF1XMM9dv5W0+SgkWOX58cc91QXpUSoBKSW9n8BeGIr+y3xhh8U/xdkXjd+Jcw== X-Gm-Gg: Acq92OFfYqF3wT8WCAhBZioubvYrfKGtSv+eupKVDUSBzufLynzlvk/X1j0tEPkHYSd RuFgF6DFE5p+gEvg9wPQYvQ4+sEk249GpjLFvsgdFglto2BOtsZBCpjAZz9qzT+CwAT69R6Ji+/ GPPoheTaAKeY+1J/UTrYQcBsi/11/S6r8fYAqEvAfKU0UUKCEoMLUhFc3LnO6KlpMLAL0FVXdSw MubsHhRR/yvO3TCI/7sfSxAF+quceMRbjCAUeqBJRWHt/CEO62OxKD6+U+i+YusBJQhtBHpqD5m lqvMUTxGcS757QxYfObmwy2AhAaFtq0vwNMMn+5Y15J8oDnn3cxVMvSlaYTuKJk37Nancz8Pxug bWK7MCvOaYfwuA6S5AiZDNwqwizCDzaj2APyAvJNWsNvrBMvzu5krcC4G4OpLaV0KkG+kZ0UpTs Pui/Z5ftx0v8HA7kvbv4KIbs5lO/ush2WV5HoelkIp+vxMAyJvpLLfYx/ZGQf0hFvEJwwbGQ== X-Received: by 2002:a17:903:190:b0:2ba:dfa:328d with SMTP id d9443c01a7336-2bd01294a6bmr914625ad.1.1778535682176; Mon, 11 May 2026 14:41:22 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d63b952bsm8644567a91.9.2026.05.11.14.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 14:41:21 -0700 (PDT) Date: Mon, 11 May 2026 21:41:18 +0000 From: Samiullah Khawaja To: David Matlack Cc: Aex Williamson , Shuah Khan , Alex Mastro , Raghavendra Rao Ananta , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] vfio: selftests: Add support of creating multiple iommus from iommufd Message-ID: References: <20260505221518.619123-1-skhawaja@google.com> <20260505221518.619123-2-skhawaja@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: On Mon, May 11, 2026 at 08:59:53PM +0000, David Matlack wrote: >On 2026-05-11 08:21 PM, Samiullah Khawaja wrote: >> On Fri, May 08, 2026 at 06:17:19PM +0000, David Matlack wrote: >> > On 2026-05-05 10:14 PM, Samiullah Khawaja wrote: > >> > @@ -478,11 +483,7 @@ struct iommu *iommufd_iommu_init(int iommufd, u32 dev_id, u32 flags) >> > struct iommu *iommu; >> > >> > iommu = iommu_alloc("iommufd"); >> > - >> > - iommu->iommufd = dup(iommufd); >> > - VFIO_ASSERT_GT(iommu->iommufd, 0); >> > - >> > - iommu->ioas_id = iommufd_ioas_alloc(iommu->iommufd); >> > + iommufd_init(iommu, dup(iommufd)); >> > >> > if (flags & IOMMUFD_IOMMU_INIT_CREATE_PT) >> > iommu->hwpt_id = iommufd_hwpt_alloc(iommu, dev_id); >> > >> > > + >> > > + if (flags & IOMMUFD_IOMMU_INIT_CREATE_PT) >> > > + iommu->hwpt_id = iommufd_hwpt_alloc(iommu, dev_id); >> > >> > Does this need to be part of iommufd_iommu_init()? Maybe it would be >> > better to expose a separate helper to allocate a HWPT for a given struct >> > iommu *. >> >> Hmm.. that is interesting.. I think we can have following immediate >> possibilities when creating a struct iommu (there will be more down the >> road, but can be handled in similar way): >> >> - create using struct iommu with a new IOAS. >> - create using struct iommu with existing IOAS but new HWPT. >> - create using struct iommu with new IOAS and new HWPT. >> >> I think I should probably add following flags: >> >> IOMMUFD_IOMMU_INIT_CREATE_IOPT (IO Page Table) or _PT >> IOMMUFD_IOMMU_INIT_CREATE_IOAS (IO address Space) or _AS >> >> At least one of those should be required when creating new struct iommu >> from an existing one. WDYT? > >I don't love the idea of passing in flags to control the logic, >especially since not every combination of flags is valid. And also tests >would be required to pass in dev_id even if it's not needed (first >possibility in your list). Agreed. > >Maybe add explicit helpers for each case? > >/*** static (private) helpers ***/ > >static u32 iommufd_hwpt_alloc(struct iommu *iommu, u32 dev_id) >{ > struct iommu_hwpt_alloc args = { > .size = sizeof(args), > .pt_id = iommu->ioas_id, > .dev_id = dev_id, > }; > > VFIO_ASSERT_EQ(iommu->hwpt_id, 0); > ioctl_assert(iommu->iommufd, IOMMU_HWPT_ALLOC, &args); > > iommu->hwpt_id = args.out_hwpt_id; >} > >static struct iommu *iommufd_new(int iommufd, u32 ioas_id) >{ > struct iommu *new; > > new = iommu_alloc("iommufd"); > > new->iommufd = dup(iommufd); > VFIO_ASSERT_GT(new->iommufd, 0); > > new->ioas_id = ioas_id; > > return new; >} > >/*** Public API for tests ***/ > >struct iommu *iommufd_new_ioas(struct iommu *cur) >{ > return iommufd_new(cur->iommufd, iommufd_ioas_alloc(cur->iommufd)); >} > >struct iommu *iommufd_new_hwpt(struct iommu *cur, u32 dev_id) >{ > struct iommu *new = iommufd_new(cur->iommufd, cur->ioas_id); > > iommufd_hwpt_alloc(new, dev_id); > return new; >} > >struct iommu *iommufd_new_ioas_hwpt(struct iommu *cur, u32 dev_id) >{ > struct iommu *new = iommufd_new_ioas(cur); > > iommufd_hwpt_alloc(new, dev_id); > return new; >} This looks great. I will update in next revision.