From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 506CE382F04 for ; Mon, 23 Mar 2026 22:18:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774304328; cv=none; b=W26XGKnDeDORwIxWTEIQnkiagz3im7hUbLBp00nF2wOeQbHgr3oGSeGaQyGxZnfh0zFzfd8bXCn2QOkEs8+oojxtZjZAimTaKII+iDvyzQNnV4VFNG7JbAAijcgnMV162Ny3A/t2PY965XCrF/2hua2ZZc3yRXi7Tr8jLBfcqhg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774304328; c=relaxed/simple; bh=m0Oct6L5BwAfzAqfEGPIqu2tZ0EzzUznTUJO7ip40R8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IP27SnRv9iY7Dqo779fmVjPP0KQ5iYdZMyBsOMsqVidhs3bgMMUky/KYMCu3v48VksAsYaEnMy0XEXk6RelT1TduCp2N0VCjoxX1v0Z5DbjOHaSHU51gY9wn69uXol8esYExtLhYD3D1q5ct2z9lsdTqKAU3V8dcKxnjTKkySaA= 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=ZHYQW4fM; arc=none smtp.client-ip=209.85.214.178 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="ZHYQW4fM" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2aeab6ff148so15645ad.1 for ; Mon, 23 Mar 2026 15:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774304326; x=1774909126; 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=SUjy+2x1i7Xfs6bwVX9ul43lO5ojBIL9kKYDxuqVt+4=; b=ZHYQW4fMx7e9sf7I8Q7ol2g8tZUWmkH42eK1Eluadpvim9EpOc7/jO6ph9E5GM4g3Q GVZvKn2cR0inSypdV5cuzZWoFqhEYyUt/06AeSIuso2Ae6VjEtNHbp2r0RiTV+g2xuJb MqP6Mcgl51uaTKmYK8Gs2PtJ4oOnSv+wbtkKyIRDbOhIbFEuLJ0jd65gCnrbEIPhaaZk ZG2aAbwfKOdC7idHZW3XRnSu8uDgoDmRjzuwFJkKyNt/ED5/cvyZy6bTvwvDopP3GqIi pN3PUVMQQVhbALDfQrr95hGJjZKYfSBrAuOnC5Izl/k22AJbG+l/t8nxJX+VEIwBCv1c TK6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774304326; x=1774909126; 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=SUjy+2x1i7Xfs6bwVX9ul43lO5ojBIL9kKYDxuqVt+4=; b=FtSxwl9QTUgCe5IEi0vX25n+tJBH7J3fOFOVY/Ic/eBvsWiQFmDxcBYuBoW5mDDvnV oEXTFK8jz/I/4EZKmF5k4t25U5dc1lXQlUAgdihDdt0V6nVjX9h0SQM6QHx2Ml/CRyhC JkbZ5penoVd5lwdX2GX8ceNJJS8QnRA/6dNrdtP+GBBtVf1W/UGjc5/FQRtscm9oNczw h/1DTOHmcCxBJVMBiiaXbpUS0nt1cGsfJ7OW6RTFC7Se8NCOtRdy2/Bq3XCYUW86w/R5 dQXg5Catl2n6B1YI36f7YHJmqmlC7W7hBcsoBkS4ay69nS+/SyO3mJg0X2JP6SZfsDu7 uCQQ== X-Forwarded-Encrypted: i=1; AJvYcCV/N9+B4pDm0I/klRSW2s0JJydj6yTlpMjwu1TutuYTTCfNv9/dt9O63e84n0sO7Z8mqCjoeJMloMypD64=@vger.kernel.org X-Gm-Message-State: AOJu0YzSDegTvr9//qPPX5XrvCAShr8FnwVZq0Oda8qSbL6v2MZCCbLb Lq50LupMp7WK/Yfc95U5mMbairFdrtMP05FnTs3RK1TrODu96UBt9N9HasyXfOuiFA== X-Gm-Gg: ATEYQzzgfaINbnAnt8jw9LVOD66kL6GucJF6tOEMt0OK1e08skQOJ/mOxxvY8xHTZAu fLKk5/Wu9RkGGBRsYF8udY6Ngh6nWn6bH0XEUYM3vNDU22PSglM62lauOsrcamfSmo5tVifDh1m Em/KbCMUI5ug9E3mHCNuKnpOne8UarEaEH5CjqjFev9PsKPoWoo2iVwHghlVd4nKTEK+YFg708j 0jAgGwwCYzE6mZZrgLCi+7dC+JPjCOckci+DdlMxWHYkGmsetxf+GFHovxewZwgyQpJJPSgG2pH n7DI/cEQgl6FxQIxHELlWTkSQU8VjoZAvSwJJWfmuNkzc/M85LSZvF9aWbn2R4wxKm7MWlqpcUu ZrvRU6txpMvz9FxrKSxy6T3hd9cw5G8VZbNFRNtwnQ+56Zwf9m71GxtLe8Ksl81bjAObdeSNNz2 u7xaNEcnx91vPwBYKZH0sfNu837fZUBINHs/QcAhrrKXi+GK4Kbrt21hi0dyKr X-Received: by 2002:a17:902:f68d:b0:2ae:4808:bd99 with SMTP id d9443c01a7336-2b0a53e730fmr1188815ad.2.1774304324944; Mon, 23 Mar 2026 15:18:44 -0700 (PDT) Received: from google.com (176.13.105.34.bc.googleusercontent.com. [34.105.13.176]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c0175e234sm131271a91.1.2026.03.23.15.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 15:18:44 -0700 (PDT) Date: Mon, 23 Mar 2026 15:18:39 -0700 From: Vipin Sharma To: Samiullah Khawaja Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Pranjal Shrivastava , YiFei Zhu Subject: Re: [PATCH 14/14] iommufd/selftest: Add test to verify iommufd preservation Message-ID: <20260323212009.GC2571566.vipinsh@google.com> References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-15-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 Content-Disposition: inline In-Reply-To: <20260203220948.2176157-15-skhawaja@google.com> On Tue, Feb 03, 2026 at 10:09:48PM +0000, Samiullah Khawaja wrote: > Test iommufd preservation by setting up an iommufd and vfio cdev and > preserve it across live update. Test takes VFIO cdev path of a device > bound to vfio-pci driver and binds it to an iommufd being preserved. It > also preserves the vfio cdev so the iommufd state associated with it is > also preserved. > > The restore path is tested by restoring the preserved vfio cdev only. > Test tries to finish the session without restoring iommufd and confirms > that it fails. May be alos add more details that VFIO bind will also fail, it will return EPERM due to ... > diff --git a/tools/testing/selftests/iommu/Makefile b/tools/testing/selftests/iommu/Makefile > +$(TEST_GEN_PROGS_EXTENDED): %: %.o $(LIBLIVEUPDATE_O) > + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_O) $(LDLIBS) -static -o $@ Why static? User can pass static flag through EXTRA_CFLAGS. > diff --git a/tools/testing/selftests/iommu/iommufd_liveupdate.c b/tools/testing/selftests/iommu/iommufd_liveupdate.c > + > +#define ksft_assert(condition) \ > + do { if (!(condition)) \ > + ksft_exit_fail_msg("Failed: %s at %s %d: %s\n", \ > + #condition, __FILE__, __LINE__, strerror(errno)); } while (0) Please add indentation to the code. > + > +int setup_cdev(const char *vfio_cdev_path) Nit: s/setup_cdev/open_cdev Since you are using open_iommufd() name below, this will make it consistent as there not setup here apart from opening. > +int setup_iommufd(int iommufd, int memfd, int cdev_fd, int hwpt_token) > + bind.iommufd = iommufd; > + ret = ioctl(cdev_fd, VFIO_DEVICE_BIND_IOMMUFD, &bind); > + ksft_assert(!ret); > + > + ret = ioctl(iommufd, IOMMU_IOAS_ALLOC, &alloc_data); > + ksft_assert(!ret); > + > + hwpt_alloc.dev_id = bind.out_devid; > + hwpt_alloc.pt_id = alloc_data.out_ioas_id; > + ret = ioctl(iommufd, IOMMU_HWPT_ALLOC, &hwpt_alloc); > + ksft_assert(!ret); > + > + attach_data.pt_id = hwpt_alloc.out_hwpt_id; > + ret = ioctl(cdev_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data); > + ksft_assert(!ret); > + > + map_file.ioas_id = alloc_data.out_ioas_id; > + ret = ioctl(iommufd, IOMMU_IOAS_MAP_FILE, &map_file); > + ksft_assert(!ret); > + > + set_preserve.hwpt_id = attach_data.pt_id; > + ret = ioctl(iommufd, IOMMU_HWPT_LU_SET_PRESERVE, &set_preserve); > + ksft_assert(!ret); > + > + return ret; > +} iommufd_utils.h has functions defined for iommufd ioctls. I think we should use those functions here and if related to iommufd are not present we should add there. > +int main(int argc, char *argv[]) > +{ > + int iommufd, cdev_fd, memfd, luo, session, ret; > + const int token = 0x123456; > + const int cdev_token = 0x654321; > + const int hwpt_token = 0x789012; > + const int memfd_token = 0x890123; > + > + if (argc < 2) { > + printf("Usage: ./iommufd_liveupdate \n"); > + return 1; > + } > + > + luo = luo_open_device(); > + ksft_assert(luo > 0); > + > + session = luo_retrieve_session(luo, "iommufd-test"); > + if (session == -ENOENT) { > + session = luo_create_session(luo, "iommufd-test"); > + > + iommufd = open_iommufd(); > + memfd = create_sealed_memfd(SZ_1M); > + cdev_fd = setup_cdev(argv[1]); > + > + ret = setup_iommufd(iommufd, memfd, cdev_fd, hwpt_token); > + ksft_assert(!ret); > + > + /* Cannot preserve cdev without iommufd */ > + ret = luo_session_preserve_fd(session, cdev_fd, cdev_token); > + ksft_assert(ret); > + > + /* Cannot preserve iommufd without preserving memfd. */ > + ret = luo_session_preserve_fd(session, iommufd, token); > + ksft_assert(ret); > + > + ret = luo_session_preserve_fd(session, memfd, memfd_token); > + ksft_assert(!ret); > + > + ret = luo_session_preserve_fd(session, iommufd, token); > + ksft_assert(!ret); > + > + ret = luo_session_preserve_fd(session, cdev_fd, cdev_token); > + ksft_assert(!ret); > + All of these ksft_assert are hurting my eyes:) I like the approach in VFIO where library APIs does validation and test code only check actual things needed. Should we at least create a common function to combine both luo_session_preserve() and ksft_assert()?