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 DB86A27702D for ; Wed, 7 Jan 2026 22:56:48 +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=1767826610; cv=none; b=ALJULYiNW+6CMEFHg6jMx4tRck0ubVeXKJTVeTEhl8+KnJb3IFz9mT3NHP9PSqq77mo9NQ2/+PTBdIS5YyfdI/x5MWiGmYKybwjsHd0HwHuCrY27Mft836+uL5dvgQCQ18GM7j6JkVhN0s+g5briyeXX0GRZfhWhvHdVsk8vbb0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767826610; c=relaxed/simple; bh=bEYOmVLd9MHdfQFuuqXOyhw/mjVfgExIaPCZ914sOTM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rO6jCUK8ZyJ0+cqFNIfV9rK0XPw81gnindgpbVO5V4HkMZmfNp8GOkARIIYbOz9z6On0zNLHd7MuSdpaABCe+1/jwirM4nCZE//WIzQdwl5Z7yS2JEoJSp9/OeerxKqbH0GgBj9Kc3Ku45zxx63212nmllj7+uUFo2Txv//hhZA= 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=2HYEKkFR; 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="2HYEKkFR" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2a0a95200e8so16481125ad.0 for ; Wed, 07 Jan 2026 14:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767826608; x=1768431408; 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=OJWhiDr1D/MjKYOeKl4sbtvtGhgARkJ8AAhcCNlROuw=; b=2HYEKkFRI0fMhnjAztr3aa/vbSOzJtxu9K+TlhxhkQI1TCEqsvOadXy4LtkDpZ9Kg4 DzBmPuTNT0JbVCQXXhSA9MqgwUqC14ATtBOD4evuABRXZnAGPodoXHrh1iU5V0LDBWzS 56M9BYd94l1DOeWJqaADcSTfvCDWY4WeyR3ebXCeAiFJ01E7KBiavYEjuKuaSGQqaeFK LTLY+A9AzQ79+HsBpEZ0xBatp6YJ1IJ48MDoUNwprU5kF3lKlcMGtQeu3fyuFCQ5gV+a ZJuzrAMF+nL1PZouFMQwbJqXAvmGa0PXbIbC7HE6vxu75U6Co9cwhNpJMuOqduWEpKMW +LCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767826608; x=1768431408; 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=OJWhiDr1D/MjKYOeKl4sbtvtGhgARkJ8AAhcCNlROuw=; b=DYbFZhToEO2jp8V+6y7sy2DgH8XZIQHvS9bMBpMuTEvfX07DtrSIzi0lKQ/VEbXMQL /8Ubu37JK7uf2Oq1pfRIIHJ0H+PrrguON5IH5N4DAj7/VYvei/xdxCUmpmE9WsQbDjtZ +8fvVmq62gqsV/jNtvRd31m4psh1mih0mkavXfEl5m9yLExFw//abaSF+UxgwGQ8uiYP MwT+F0XyDeOO0HY5UqF2/ggNmtZTJovyw/S9di+dQWMREfblsVWNlyyR+3KJMt4RHi53 nRgIs5rsQ9nQEGD9rAj8pJPEh0XHUIj1xPojyGDOzpi+BkJKEaQLOohGcg7DfLMb/aDP bBKQ== X-Forwarded-Encrypted: i=1; AJvYcCWk8hig0FTzWVfH6LnW6NEX2iulxOSU+Gbg7NkPKS5KBi9ctk1y9fUhrqxqCzfRnQzGvaduGfWnV+Bd0ac=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2JNRQIJALUvdqnr7NXu3nIIY35I3mdlJ6VYIZgV7BLB386RpL eWMHruN+RuNpMZcF1tWGc2gF6QoLCkPShO/IfzcWSW5IRMCjF+9oZBLy5Y/4Toz77Q== X-Gm-Gg: AY/fxX474A/5l0tNDM5iUZKcwnDngDDmFlzN0SbXrdqzLNncm+kL8zUS/ye8iPIBlbR PyI7VxiIhBAPL0UZ+5RUlMupH4axYOuA8GIYIeq3d7hHzno9kS1RaCTrXskFGZ9TETNaDwR2jk5 bFVKhxkSzqSVQ8Tt5rwzHBztchDAp92zyEqXP8+vTiJZ8TU8vc7N6Udpdy7SPnVqVxeE81S/jEE G6jE6xbF4UxolhCF8XrtvRK7meRgVpP4VLeDORb/c0SA6GF4A0EAEV5BNiiPcASJaIwZG/jKSZq PsT7n1bKtTLUg6+2Zzuvhv5/c9rE17Wjqghq4xtnJ2Og6HMEURHPgJy5WoscEg9EHSU6ItRGiA+ AzaifOkTbUMgbYaRhcmkVexpkGwanC6knJNdFDK7WO1c4Ir0zsgJ2TG0+COB0uemt9eLLbF/fKB etEAOXFYe4Ugxddsc2gsSOEFTXujDhO+vwVtj4nMsqrWbC X-Google-Smtp-Source: AGHT+IGTO1J6jb7GfhJzC/ulE53OgZ6VBQ1OD1qXgBdMMZajR7PmSbIPCZczcXxLi7aVbnzz0qLzpg== X-Received: by 2002:a17:903:41c2:b0:2a0:d149:5d0f with SMTP id d9443c01a7336-2a3ee445ba7mr34360365ad.17.1767826607972; Wed, 07 Jan 2026 14:56:47 -0800 (PST) Received: from google.com (76.9.127.34.bc.googleusercontent.com. [34.127.9.76]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3c48c15sm58685025ad.27.2026.01.07.14.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 14:56:47 -0800 (PST) Date: Wed, 7 Jan 2026 22:56:43 +0000 From: David Matlack To: Raghavendra Rao Ananta Cc: Alex Williamson , Alex Williamson , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/6] vfio: selftests: Add helper to set/override a vf_token Message-ID: References: <20251210181417.3677674-1-rananta@google.com> <20251210181417.3677674-6-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: <20251210181417.3677674-6-rananta@google.com> On 2025-12-10 06:14 PM, Raghavendra Rao Ananta wrote: > Add a helper function, vfio_device_set_vf_token(), to set or override a > vf_token. Not only at init, but a vf_token can also be set via the > VFIO_DEVICE_FEATURE ioctl, by setting the > VFIO_DEVICE_FEATURE_PCI_VF_TOKEN flag. Hence, add an API to utilize this > functionality from the test code. The subsequent commit will use this to > test the functionality of this method to set the vf_token. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../lib/include/libvfio/vfio_pci_device.h | 2 ++ > .../selftests/vfio/lib/vfio_pci_device.c | 34 +++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h > index 6186ca463ca6e..b370aa6a74d0b 100644 > --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h > +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h > @@ -129,4 +129,6 @@ void vfio_container_set_iommu(struct vfio_pci_device *device); > void vfio_pci_iommufd_cdev_open(struct vfio_pci_device *device, const char *bdf); > int __vfio_device_bind_iommufd(int device_fd, int iommufd, const char *vf_token); > > +void vfio_device_set_vf_token(int fd, const char *vf_token); > + > #endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_VFIO_PCI_DEVICE_H */ > diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > index 208da2704d9e2..7725ecc62b024 100644 > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > @@ -109,6 +109,40 @@ static void vfio_pci_irq_get(struct vfio_pci_device *device, u32 index, > ioctl_assert(device->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info); > } > > +static int vfio_device_feature_ioctl(int fd, u32 flags, void *data, > + size_t data_size) > +{ > + u8 buffer[sizeof(struct vfio_device_feature) + data_size] = {}; > + struct vfio_device_feature *feature = (void *)buffer; > + > + memcpy(feature->data, data, data_size); > + > + feature->argsz = sizeof(buffer); > + feature->flags = flags; > + > + return ioctl(fd, VFIO_DEVICE_FEATURE, feature); > +} > + > +static void vfio_device_feature_set(int fd, u16 feature, void *data, size_t data_size) > +{ > + u32 flags = VFIO_DEVICE_FEATURE_SET | feature; > + int ret; > + > + ret = vfio_device_feature_ioctl(fd, flags, data, data_size); > + VFIO_ASSERT_EQ(ret, 0, "Failed to set feature %u\n", feature); > +} > + > +void vfio_device_set_vf_token(int fd, const char *vf_token) > +{ > + uuid_t token_uuid = {0}; > + > + VFIO_ASSERT_NOT_NULL(vf_token, "vf_token is NULL"); > + VFIO_ASSERT_EQ(uuid_parse(vf_token, token_uuid), 0); > + > + vfio_device_feature_set(fd, VFIO_DEVICE_FEATURE_PCI_VF_TOKEN, > + token_uuid, sizeof(uuid_t)); > +} Would it be useful to have a variant that returns an int for negative testing? > + > static void vfio_pci_region_get(struct vfio_pci_device *device, int index, > struct vfio_region_info *info) > { > -- > 2.52.0.239.gd5f0c6e74e-goog >