From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 437E93D34A6 for ; Mon, 11 May 2026 23:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778543327; cv=none; b=fH6AAcbL4R8msGc8DDB0eWN7Kc3eexAGvZGBEHTOXjABKe3XVyofiCrxZS1ij176CcpD5qUG8hZ9T3PS7+5SlrwZK5osFiLllCELjQ9EFtptshuTV8q8BjpBzb5PqlCVA+OyVzon1xxnqARhbErsFxM1S9aLh4OwVUBfzpzqflU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778543327; c=relaxed/simple; bh=RghH9FcYPgVqkLV+z4skVa4m4AD6epMoNgDgpNvGU6w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jRkV671rJEmoUacPUd8lfJ2GAJ7KVG3cbcnM70QwHp5JVW9J7ANe0F/VyOwggr283ypclIXmod970BvXThUmCLX5w9j9wKKdWvui0BK5QnV7W246InK8Iv3THd19ZCXiCEM4lV8axUDAyFkicUU23pw7htJfHp9TtnQ1h2vyXSg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YInU6vj/; arc=none smtp.client-ip=209.85.215.201 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=flex--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YInU6vj/" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c827adbf00cso1127396a12.2 for ; Mon, 11 May 2026 16:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778543324; x=1779148124; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VIWZ9kq9YD08PbxmWBTSSy3QBQyaG9ngqmDEoB6yjoA=; b=YInU6vj/Isv6MOjB6KT5+4SMSgr8gkH01ejqoq8UNGugd8yYwZzAq2sSrurTN2qRHH ZwSX+PKYz+PRRiCtAo7zfsUcFeSVVTZJpKrxeAwHgwJSDXC8vxfSh2XCvDzjCduizsmG bUSsnjPZ8D6MgDXHvIevdZuxbBYadfGOCOAChAl7a3EDRg+ilajf9kWEy/TGNMkI/yk9 T2gpm0OcQ2uE99pClBzcVwg+9/2JuPUWoi8oDW8GIxgoVPd9kB0IiqRt0XdQGnLNB8Ku ejtqbqz0205A2KABNKofJd6Tp4wgvewJWU95+EwEzftRZ+rznMcQwI9WmDWY6QHKZmpT QeAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778543324; x=1779148124; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VIWZ9kq9YD08PbxmWBTSSy3QBQyaG9ngqmDEoB6yjoA=; b=Bt5CFsct1lcLtiItnxa9fBNAxfIw+Pw2zrVuLTXNGcKyy94MRrANvoCY2gl6TZzZvC zCIo9znnfJ2Z0NAwa7g7eRPBy4Ck3qWa5nywoYtJvHBJWdqYXrk2d6NkyxJdsdoCikPk F3ZBzwAAsG/wg2AwORpSJ1xmrC/Qi4pQ5l4lBzEOTV3fNy0PwpSQ4WRPia5NchRTaGbV +b5U1ON/2X8HXLuhQFb78yy1mq/jPfQ3GwtcxXWiAUFUnQDQuZjYt06LTEoUh7EEUv/I 3Zh1l9k7jiOwoFIMGjWCat2LvKZ8AnafO85uNzOoUGisuu3eYSvRo86nYMHYnzDVD4kE +XJA== X-Forwarded-Encrypted: i=1; AFNElJ/lOWkS6VV7IzppyRR3MBk5bEDTNKhRsHk+cej+n9bZZIWKN9UtsSRTG+akyRUxrRX/D/xkzyCabqYvTIY=@vger.kernel.org X-Gm-Message-State: AOJu0YyOHG4iN+mJYYTvVXYegdGw+cX5v23LPIzuwG8ykyJZ8RIeJpOS d7MK647+h+dnxi4gIhzQRZDcS0kvzc6+iMYoTZ7BYIhQJPgGpuxrPKciS7ucsz6Vc1oSEs0znPK +JwpYzUZWpA== X-Received: from pgap4.prod.google.com ([2002:a63:4204:0:b0:c6e:795e:f99a]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9149:b0:39b:87f0:758e with SMTP id adf61e73a8af0-3aad42566ccmr12931272637.8.1778543324306; Mon, 11 May 2026 16:48:44 -0700 (PDT) Date: Mon, 11 May 2026 16:48:01 -0700 In-Reply-To: <20260511234802.2280368-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260511234802.2280368-1-vipinsh@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260511234802.2280368-16-vipinsh@google.com> Subject: [PATCH v4 15/16] vfio: selftests: Verify that opening VFIO device fails during Live Update From: Vipin Sharma To: kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org Cc: ajayachandra@nvidia.com, alex@shazbot.org, amastro@fb.com, ankita@nvidia.com, apopple@nvidia.com, chrisl@kernel.org, corbet@lwn.net, dmatlack@google.com, graf@amazon.com, jacob.pan@linux.microsoft.com, jgg@nvidia.com, jgg@ziepe.ca, jrhilke@google.com, julianr@linux.ibm.com, kevin.tian@intel.com, leon@kernel.org, leonro@nvidia.com, lukas@wunner.de, michal.winiarski@intel.com, parav@nvidia.com, pasha.tatashin@soleen.com, praan@google.com, pratyush@kernel.org, rananta@google.com, rientjes@google.com, rodrigo.vivi@intel.com, rppt@kernel.org, saeedm@nvidia.com, skhan@linuxfoundation.org, skhawaja@google.com, vipinsh@google.com, vivek.kasireddy@intel.com, witu@nvidia.com, yanjun.zhu@linux.dev, yi.l.liu@intel.com Content-Type: text/plain; charset="UTF-8" From: David Matlack Verify that opening a VFIO device through its cdev file and via VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was preserved across a Live Update. When a device file is preserve across a Live Update, the file must be retrieved from /dev/liveupdate, not from VFIO directly. Signed-off-by: David Matlack Signed-off-by: Vipin Sharma --- .../vfio/vfio_pci_liveupdate_kexec_test.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c index 15b3e3af91d1..65c48196e44e 100644 --- a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c @@ -36,6 +36,42 @@ static void before_kexec(int luo_fd) daemonize_and_wait(); } +static void check_open_vfio_device_fails(void) +{ + const char *cdev_path = vfio_pci_get_cdev_path(device_bdf); + struct vfio_pci_device *device; + struct iommu *iommu; + int ret, i; + + printf("Checking open(%s) fails\n", cdev_path); + ret = open(cdev_path, O_RDWR); + VFIO_ASSERT_EQ(ret, -1); + VFIO_ASSERT_EQ(errno, EBUSY); + free((void *)cdev_path); + + for (i = 0; i < nr_iommu_modes; i++) { + if (!iommu_modes[i].container_path) + continue; + + iommu = iommu_init(iommu_modes[i].name); + + device = vfio_pci_device_alloc(device_bdf, iommu); + vfio_pci_group_setup(device); + vfio_pci_iommu_setup(device); + + printf("Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, \"%s\") fails (%s)\n", + device_bdf, iommu_modes[i].name); + + ret = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf); + VFIO_ASSERT_EQ(ret, -1); + VFIO_ASSERT_EQ(errno, EBUSY); + + close(device->group_fd); + free(device); + iommu_cleanup(iommu); + } +} + static void after_kexec(int luo_fd, int state_session_fd) { struct vfio_pci_device *device; @@ -44,6 +80,8 @@ static void after_kexec(int luo_fd, int state_session_fd) int device_fd; int stage; + check_open_vfio_device_fails(); + restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage); VFIO_ASSERT_EQ(stage, 2); -- 2.54.0.563.g4f69b47b94-goog