From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 8058139F19C for ; Mon, 6 Apr 2026 22:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775514259; cv=none; b=lyyrySCUArMv/5Yr+H1kDj2/IHVnxk+vqpoSyrSiXz82rNvRkc/341tPlG3Q7L8BARAU19HxPalPeVz7bkoIBKsXnzYNeQf+J8tlp1DGAVEuLeToQY9cMjFi0ImFFlZWVNcoX1jbtLrvlZ83FDTzTsVvps2aVDMIpej5sUeP4j8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775514259; c=relaxed/simple; bh=ewoAHirtyxvs6kNwLJTzu3Wt/BMmWqyQhBTsTu1+SDM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MnZOYlrrCOun9TqTUFgzUuSycFpZSpiPjEvC/mxzSMajEajv+MO5YAisifryN42b3YJjalHn9BmwZwJw+Z4Ic4STZ0l4MPbOkEdtZlsrj19AnbYdfcdMs96dueFFX6y6K2g4S9lwGnJdiuPU2Ai7/9vt5itCaJU5y7LLO5nQNVE= 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=D3PyK1Qg; arc=none smtp.client-ip=209.85.210.170 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="D3PyK1Qg" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-82cd70febc7so3387899b3a.2 for ; Mon, 06 Apr 2026 15:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775514251; x=1776119051; 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=LkKBfhYGIkfoZWJSvPx+TEPZBQ4oCANpmSjapN38TJg=; b=D3PyK1QgY4x5A4ESHydBbAxVJ4HPh9yncPkkSdj9uk+/QYwEVBC8rx9YZxnWD/2n55 +rpJbP2KARdopQ30CmmXniXMgT+M5oDZbFpTiVlQivIv0bhESp4T6KWnHJN9SZqqOERz wEJ/DF5CQ9esqKt+TrYSgr+3fIO7DwNlLO6uvroBmNrFvowQASaxS3Z7ZYvUQKVvkkcX WrT57AVqG96tQJDwGwkaFQ7/h7SSKemMXF/tonEGSMsKpm5yT4YQ5VV5gcTsDsQ23Ayw PXgDUpv5BEOXSWjix9Q8iJsEEmaUxqftHs1AZFuVcnBIgfh1TsirRO39IZ8D595Qr5M9 030g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775514251; x=1776119051; 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=LkKBfhYGIkfoZWJSvPx+TEPZBQ4oCANpmSjapN38TJg=; b=iGdZduMBtnGmaEBVSdBjgZP2AqWr1blC3JAYuvIHUlw0oImzieKJaD0QESoO+sdK94 LCu/fMjPmhtnnPx68tMbO7rQOslMhZIiV9RJhxEushMGEPIPRGOA/Wg+N9jWbL3o/tgb HAmFKM9R8HCcQAJJkluhVkvIN/r4eInd2rfsOb+p8+2jYyOIdvi8lg8j7KQFD6F9tu/V 0OSgtONVshD4YFXyZVvIqgvNYlpeQ9DaSwdKjxJLWOirVtd6SOTKAaByWVTVtDKLi32M bvqmZAZBYNYHvQfqCMkAhlbvHRo89WCJu1UWMj7eszUU1IOWbdKfFe9NBmA4k2qnqkCo bfnA== X-Forwarded-Encrypted: i=1; AJvYcCWVKtRG3dpOog43de6mZUyxmKIxLc0hfB7c2JBy64Cbo428ot2ZoRihL8o51qnMZ6lA2LRc+AwFErYhaMc=@vger.kernel.org X-Gm-Message-State: AOJu0YzA6yS4I9KtDP7ALnhByPBKWXx+d7hPEhHbGXWOP7jDklsSsBG7 3EA6cmWjo2fl41UJdfKyxgHYZhd2V1V967GMecQVKMcc/43j02bARPOQYBn/ltVc5A== X-Gm-Gg: AeBDievUab0CZDlWs2qsd3f8hYEZ8KCZK6jtiDXpa3ElkF/QNrgfljrKBotXrOm0yYx euLmsC4UYdkqBWapXHNfoREiT3Iis3SdTDy1MFu7q+yz6uxg80/qFE+E7Vborqck6648KN96zad RZS4ad7Q8t6I71r6X3PNSlXFPCCFpUFhLcwz7P1aOEyUFIK29IxQsV8ec0KI8Qe7bRSFCckmm4n Y0b83TYPrQWUojR3NdMEGCbDUUjcRU5f1mlDD5AWcDd4i+5weCKMOUSlNuqFIiGJ6znK7a1h5Y9 +RhPts2Vd8npbHC4/X6r5wOOuNS5MHIV3MmvPJUZT/PcINDTtImOPtTTvniDmpnLwVTVQn7HHdp upJ8tMGUric/OjneR1nxdoXPCpZqO3rzcTC3IgYjuSWct+/pgWVlv1iNnfL78TgLNnFaXK+AUX8 1BWYSGiFNcwjy53ypy+svl4Jw0oV6nCS8KUA0T8FYcv4aj06hOtTKMAJua436OLQ== X-Received: by 2002:a05:6a00:1d9e:b0:827:4372:dd15 with SMTP id d2e1a72fcca58-82d0db888d4mr14250007b3a.40.1775514250273; Mon, 06 Apr 2026 15:24:10 -0700 (PDT) Received: from google.com (239.23.105.34.bc.googleusercontent.com. [34.105.23.239]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9b76c0fsm14336712b3a.15.2026.04.06.15.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2026 15:24:09 -0700 (PDT) Date: Mon, 6 Apr 2026 22:24:05 +0000 From: David Matlack To: Raghavendra Rao Ananta Cc: Alex Williamson , Vipin Sharma , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 8/8] vfio: selftests: Add tests to validate SR-IOV UAPI Message-ID: References: <20260402173059.1018805-1-rananta@google.com> <20260402173059.1018805-9-rananta@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: <20260402173059.1018805-9-rananta@google.com> On 2026-04-02 05:30 PM, Raghavendra Rao Ananta wrote: > +/* clang-format off */ > +FIXTURE(vfio_pci_sriov_uapi_test) {}; > +/* clang-format on */ > + > +FIXTURE_SETUP(vfio_pci_sriov_uapi_test) > +{ > +} > + > +FIXTURE_TEARDOWN(vfio_pci_sriov_uapi_test) > +{ > +} Please do iommu_init() iommu_cleanup() here to reduce code duplication and as an added bonus you can drop the clang-format comments above. > +static void vf_teardown(void) > +{ > + /* Destroy the VF only when the main/parent process exits. */ > + if (getpid() != main_pid) > + return; Is this because the child processes created by test_harness_run() to run the TEST_F()s inherit the atexit() call? If so please clarify that in the comment in more detail. > + > + free(vf_bdf); > + sysfs_sriov_numvfs_set(pf_bdf, 0); > +} > + > +static void vf_setup(void) > +{ > + char *vf_driver; > + int nr_vfs; > + > + nr_vfs = sysfs_sriov_totalvfs_get(pf_bdf); > + if (nr_vfs <= 0) > + ksft_exit_skip("SR-IOV may not be supported by the PF: %s\n", pf_bdf); > + > + nr_vfs = sysfs_sriov_numvfs_get(pf_bdf); > + if (nr_vfs != 0) > + ksft_exit_skip("SR-IOV already configured for the PF: %s\n", pf_bdf); > + > + /* Create only one VF for testing */ > + sysfs_sriov_numvfs_set(pf_bdf, 1); > + > + /* > + * Setup an exit handler to destroy the VF in case of failures > + * during further setup at the end of the test run. > + */ > + main_pid = getpid(); > + VFIO_ASSERT_EQ(atexit(vf_teardown), 0); > + > + vf_bdf = sysfs_sriov_vf_bdf_get(pf_bdf, 0); > + > + /* > + * The VF inherits the driver from the PF. > + * Ensure this is 'vfio-pci' before proceeding. > + */ > + vf_driver = sysfs_driver_get(vf_bdf); > + VFIO_ASSERT_NE(vf_driver, NULL); > + VFIO_ASSERT_EQ(strcmp(vf_driver, "vfio-pci"), 0); > + free(vf_driver); > + > + printf("Created 1 VF (%s) under the PF: %s\n", vf_bdf, pf_bdf); Do we actually need atexit()? This code can go into main and we can do the VF cleanup before returning from main after test_harness_run() returns. I don't think you even need to check the VF driver. If the VF is not bound to vfio-pci then that will be caught by the test cases when they call device_init(vf_bdf, ...). That would make the logic more straightforward and get rid of the main_pid stuff too.