From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69E4B28688C for ; Wed, 19 Nov 2025 22:19:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590762; cv=none; b=obh0Jg3mQQu/BJHIU49l8xJi0SNQ/LxbA2REBCczRIEsjaYtk23uLyLSVQWAG1ts+D6FKuNAoqWewu6RTHqrZOIdF4tZ2InrpMsR31LC16Jsrlz8y0XuE9gm3BYZhkXboqNELUuzL5WPCIhsFdu4CE3ExHPXwffjUIssPiziMEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590762; c=relaxed/simple; bh=MeAH/L9J30qCwqNdMB87QZq7p2/nxJ5qIpUSuF+RrHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b/YJafojST5s8uQdGu7/6vSUA8Yu02pt6nBoVUr6k2Gl1ItC/KgcpGQfpq5TjxogcznAkvEJoEO8LouQkfCG+meOWqcgZVZLPEVvySze5EZeojhgDaiaH+xTFXVR0e/tQ6f219J9sPyz/TEesq48u/4v+twaLggFa3bvvRsenVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ejYWQbOb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=t+67ORCo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ejYWQbOb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="t+67ORCo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X0Vb/20jTWy28ubGj9MV+Ibuanb4TZxQpwWcQXJ663I=; b=ejYWQbOb4MWpprm+N03+x/SZSuyp4cZfF9v7+DUhgZ0B7Kg0HO6P6EYNQLMgGp7eKb+aD3 i33sRcpNvic8HBiCobDnLARW4rtomcv4YMRpsM/HDAbQf0PqfJP45wwshq7rAih+HIqxFx aqCdskQDZYWp8GI9wo5InG5UvEc9jEk= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-R-Ld88WnPXSQANoFtbMcyg-1; Wed, 19 Nov 2025 17:19:18 -0500 X-MC-Unique: R-Ld88WnPXSQANoFtbMcyg-1 X-Mimecast-MFC-AGG-ID: R-Ld88WnPXSQANoFtbMcyg_1763590757 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-88233d526baso8302066d6.1 for ; Wed, 19 Nov 2025 14:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590757; x=1764195557; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=X0Vb/20jTWy28ubGj9MV+Ibuanb4TZxQpwWcQXJ663I=; b=t+67ORCoQvloq0ZpCZzCXRZ1dG6L1e2Fagkc2ClXYCH6LqFrSiXeyddwaUJiXEkrSN QBBMuI6QIAEbKWRh8tDYo97qjCziBr19H4qSS3/goFj8o0NTrXE4gNyq4FGULp2ohXAH dpqFz4sgmhIlW83WAeR0/9KU8ByZG7hp7kKBBLt7Jfc9mIz1C70Z0+7QU8xGATGUUR7O LE1WLkhB6Wd5zXUMeQHlpvqZFmH15QWvT3OpVR0kzobeOz+RAJx21wNeXylo2PBHD2tE sDZE6rNidMH3c2UhSsWzIoH+Vm2Uv971b+IcHMa+2HSLhemeKiG4VeQjllUR1Hj+2LjE MYUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590757; x=1764195557; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=X0Vb/20jTWy28ubGj9MV+Ibuanb4TZxQpwWcQXJ663I=; b=f40GoguJ9nAQa5Myo/9GUTTge4TwHGS8mKCXQEL5babpgN4riqGw5uSq1S+yvl74aK /vn6SqjUWSwe34ZfUFKPYj2ANyOK4FXPSKOhbYeNt2n5jqcfCUQmL4tfO99P/UymOXWO JNr3Qgqo9D8sOjuk885lYEZPzR8DXOQ127YNt31eFCFuf3Nwkv8nYuj39ERBEIKDVTy1 2+Tsb/JepwSf0ue+Bmd5XYmgJmMrLooKmeuj1nX2o5OR5l/de6OuiKns+N4BDy4pFABc bI5wxeIMt3lBHeTXTW/8aWcYvVJVktPhUkTOOc0hA0q9hYkCTIOsoktF1yRK6z+pk+je 48qg== X-Forwarded-Encrypted: i=1; AJvYcCVWtAlG9BOBSb7fcd/5ljxaj442J1eAYiI8y0UrdG35GYBSjIeHIt89FGvQ/E9zirqIO421VrC72gV9HvM=@vger.kernel.org X-Gm-Message-State: AOJu0YwumawZf6R5kTAxJnaH5x7VT1AP7yIQQ10NKdzbEE/1p/LPGPY9 2X29qKLoUXwC48LsqWCg8L5V2YtlQME5RgCb+OuibiA3oQe3sdaO4sNlXFpBudjDi37C1LJmI6g TrLshZQK+5urWbXNPHsZzGuj6MBNlsd2MU+KFdSEUNE7b8o3vOpcmnMS2jzfI/QXFrg== X-Gm-Gg: ASbGncsHNb0XxuiDxCxLJlUiCj7tgO6xh4FXMqeTHmSBXPt/n4T030rTJmiTG4pkIZV W27jMqgWt1K2ccVL/4AfZhvI+G1/we1s8SgZ+YQ39tdush+UP2VFKBRb/plOIGZ9hlkxB573LEI hbNdkkjbwDjd/hJgFyt2NmfEdMXvJdy4tzJPevAqFEzbyWGfsg2+bkQmmAb9E3s5xhrQratRqZf CG5At6BQ5keCYdwyOIuAoo2oyb0N2ipKNvHnUiAQZWT8Zjx66R8dJpy6tP4I4jGwLCXq6o453XV fzaE5edYJ6yIR1qHe+kDLT94DPUjkqDRSin2KhyV8ea36W/d91c6IKl1JimVd3i8Ue/EKCiF3eN JZxUpWFkI6rd14A== X-Received: by 2002:a05:6214:768:b0:78e:6354:b258 with SMTP id 6a1803df08f44-8846e055f2bmr12533366d6.15.1763590757418; Wed, 19 Nov 2025 14:19:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFT94Xj7OzL6w7dHQO8Ye/Fmage53na9GJygM3mxuQHkkniYgbaAhhdRnQnnHNNrHgeJgJp7Q== X-Received: by 2002:a05:6214:768:b0:78e:6354:b258 with SMTP id 6a1803df08f44-8846e055f2bmr12532836d6.15.1763590756867; Wed, 19 Nov 2025 14:19:16 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:16 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:05 -0500 Subject: [PATCH 1/8] rust: pci: add is_virtfn(), to check for VFs 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-1-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 From: John Hubbard Add a method to check if a PCI device is a Virtual Function (VF) created through Single Root I/O Virtualization (SR-IOV). Signed-off-by: John Hubbard Reviewed-by: Alistair Popple Signed-off-by: Peter Colberg --- This patch was originally part of the series "rust: pci: expose is_virtfn() and reject VFs in nova-core" and modified as follows: - Replace true -> `true` in doc comment. - Shorten description and omit justification specific to nova-core. Link: https://lore.kernel.org/rust-for-linux/20250930220759.288528-2-jhubba= rd@nvidia.com/ --- rust/kernel/pci.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 82e128431f080fde78a06dc5c284ab12739e747e..c20b8daeb7aadbef9f6ecfc48c9= 72436efac9a08 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -409,6 +409,12 @@ pub fn resource_start(&self, bar: u32) -> Result { Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_in= to()?) }) } =20 + /// Returns `true` if this device is a Virtual Function (VF). + pub fn is_virtfn(&self) -> bool { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { (*self.as_raw()).is_virtfn() !=3D 0 } + } + /// Returns the size of the given PCI BAR resource. pub fn resource_len(&self, bar: u32) -> Result { if !Bar::index_is_valid(bar) { --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4287A30BF60 for ; Wed, 19 Nov 2025 22:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590764; cv=none; b=q8GSBoe/4XLPvEiKl368w7OHn//YCsz6iBNi/y9CeRlE0t+CwlgPiMd4r29+Dh0oOb8VohKMO9tF3HWa6X7L/NDyuWud3VonFztxIVHYT9jpySj+XGsts6eBb6cR6ORWz0zs1rk2lXTsjw/BMQKF3T+ifTxePFunu52j9yzHnws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590764; c=relaxed/simple; bh=72adYgtsLfbICwRUf51p19hvB2OaCp/Vs8bJEvAgYio=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=StFjCuE8Dj0oCW8t1V3RtG9HIwFeI+idHYzRIQpmvngozkEbk++YZBEJHEyeI3VhTj8MD625lKKeJbxEEpXR2cVk36GonJMYrTCQkS7YrDzY6IJuW0wjFXJXXIHV91WjTlpuxDb4j/rqXJaeP03Wn5UemcmsmlzUshm9Ex5ulL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dtelLWxE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rWXXan1O; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dtelLWxE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rWXXan1O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LT0/HQ7KAbR9mGXfO5hTKJsXPBMjCx5esqT8LbWmcms=; b=dtelLWxEZ/K5Hl9zMKc+7mG41QcM3TDpulrAEcf4QXLXL7xZlKiFx4kd+e2sVIBaZxvySl ufqYBa2WObWqHRUj2uIQimKKEXmw4msov7NZEsvBVS+rQCNYHv1PlxsU+L4MvUkuWkPqLQ lNDNG6KB54l6SnrMigkco+j92S2VPj4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-Jhv1tfK9OTG_a9G6mlhqAA-1; Wed, 19 Nov 2025 17:19:19 -0500 X-MC-Unique: Jhv1tfK9OTG_a9G6mlhqAA-1 X-Mimecast-MFC-AGG-ID: Jhv1tfK9OTG_a9G6mlhqAA_1763590759 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-882529130acso6462746d6.2 for ; Wed, 19 Nov 2025 14:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590759; x=1764195559; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LT0/HQ7KAbR9mGXfO5hTKJsXPBMjCx5esqT8LbWmcms=; b=rWXXan1OVrgHp0EDvSnXLv98wYes/yFE1hOVfDFnDhxRWKX/RExjGkVF3zx+D9QtOU HBDiv3R3rVFqEMoQgK7OV3OwwBGyUqUGgbaZueZW2oOhtXJyxajm6JZT+tAvaznwzjx4 /bbBExiQmba9rxf+50uDk+ijh5SyYvqqBH51zNDeq0TGYOgjAKZIOFhVTw1S6ei/tEDl redKfdtfqPdLw3Up0mazkpl0opHkDlJvE82XN6Xgr6mS0RKm3iOW2qFnPz91UaLCvY/4 JyqeWGMXOUjEe59T718FCTZ0qpkEGPu1Nkxj+sEEYyoxELIFMWc7TGf3GUgCWNQDeWPn pz/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590759; x=1764195559; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=LT0/HQ7KAbR9mGXfO5hTKJsXPBMjCx5esqT8LbWmcms=; b=kjrVDWqq3srBuPCTOSUKonBB5drlw6GjDaLfgp9RM+DEMXvaq5iFQBZw+54UzfM/r/ C1mR0DRTgI8HHAPADvfXRE+ZeFdFR9v35q/GtdXBwQRVPH9WiHhwVqR4HAXKFSNNXVRr SKEBJ4Eqjd2RmjveysXAcfsQl+HyKdRC3stvvqsY67QMYUxqBIPgnBuU1WMjK8EnbwNP fsDrplng0/JPsTfW32ansrcVk7tkM4clK0LtzSmaJ7h+OQgcMwoyotJEF9mRUkVhLjRb LprotKgDpiLfXmng4Wcyb+w8eSP05ZiSZlA3laGAXPND4MajJ0Qwp2RzIW885hYWjTRJ PMMg== X-Forwarded-Encrypted: i=1; AJvYcCWB/FFvJwOKrMBZ+YxPBO+27SIDwH2M/Gk6jB4QnLzRdt+WkDgyZzG9Kgbpko5jmBO3ROXHHPuAL4l2NdI=@vger.kernel.org X-Gm-Message-State: AOJu0YxIghqQQBiRqLb0cSUTCWdvTnvzumJp5j1Fr2rkbCyALvIL9PQt T764PwFZCTFyKL2WX/ptoThpnLAX9FNdcSlMrq8N2+MS3+SHSHM8haUsJ4bfN0UoiWv1PGAGwe1 FkDCA56o4FHw/alVCp86vNQnwYtuuAHgWuq4aDZhQzyCBHRlUCzXppSmXMzehNki+5Q== X-Gm-Gg: ASbGncs8hlAGJD1OXaolf2SYCnb2tpYvQ5QALzpYs6UEX861AUjqkQ9EadqWOeereGo ZV4OruTCL8BJi+t9SYvQIgwv8794NKsB/pj6UE19vOFW8pRMz6Hx9GnOPRqi9VtLnUh0c9bsLqx MC9+sSs/X8Uhp26MPDs15aYlXUEfA8fPrJ3A9sEEzaxaZQwOBQVo9cYWo7ouCn7tUHH9MpRaoGN WmZXeco5OuCrmeas96Zy+P5iZnetobrTg0ZyvvwlmoAgIdrCJV5sStYuEDjaN/Zks6egMItW2tA F66Md1cQDjSxRPX1qjE8Smg0iXxSjdMY/79E+ZOaiABS1OUfztyapaNzcV/IUXZARlbpxff6W1/ TY9Ds5QloShMRQA== X-Received: by 2002:a05:6214:c25:b0:882:4be6:9ad2 with SMTP id 6a1803df08f44-8847013f7c7mr2682256d6.33.1763590758934; Wed, 19 Nov 2025 14:19:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeuLwFeoT9/1jmiPiEb5rUv7hwbM9DKqLBAekr9VTFnVBnyYQBFN13GwWwKi9JFRBVUiJJoA== X-Received: by 2002:a05:6214:c25:b0:882:4be6:9ad2 with SMTP id 6a1803df08f44-8847013f7c7mr2681876d6.33.1763590758460; Wed, 19 Nov 2025 14:19:18 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:18 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:06 -0500 Subject: [PATCH 2/8] rust: pci: add is_physfn(), to check for PFs 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-2-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to check if a PCI device is a Physical Function (PF). Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index c20b8daeb7aadbef9f6ecfc48c972436efac9a08..814990d386708fe2ac652ccaa67= 4c10a6cf390cb 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -409,6 +409,12 @@ pub fn resource_start(&self, bar: u32) -> Result { Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_in= to()?) }) } =20 + /// Returns `true` if this device is a Physical Function (VF). + pub fn is_physfn(&self) -> bool { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { (*self.as_raw()).is_physfn() !=3D 0 } + } + /// Returns `true` if this device is a Virtual Function (VF). pub fn is_virtfn(&self) -> bool { // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A72DE1F8723 for ; Wed, 19 Nov 2025 22:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590765; cv=none; b=IO+xa6W/MQXViP9als2Cwcyo3QrMR2QersCP4Qjb+pfldx33xoFguZMaXRUh51E9H9PB4490p9J3tTmlC+p1O5BCRFh79TxSM8jvkCEItVvgJfKtcWU84OEA+FZ3gw8gvI/u5mRA52K8h811suo++euiv6c8N2M/+X6rjiSxCHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590765; c=relaxed/simple; bh=gUctwyZu30sn6ERuNz9kxhzBQ/dbl4j0za7C8gd+O2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J6Vkj3qRH9FEeicbKX0xU0RhNLWokJVu3Sn6V/nI1YcScyf9cUcnBHqWeNJz2JpVdMQqqrOwXLWYiAV3/kn4CtqyS48KESoMLjRtFtruc2QaRDdtL1WU63lwTZPWHE8LTCEW2X85j81GmuYxdfvwFYYwG6/E/VDcJw0Z1nG8lqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fYz1oigS; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MWKzJG7l; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fYz1oigS"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MWKzJG7l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZlM8hkUz32RUJhAJoZInUpHPPnxIuanN0JL39L4XpyI=; b=fYz1oigSHasGpXc/Th3+y2gLZY8r64IveYiT4105RWD42ktwKu9MLKZt1CrzyCHO45thmG 2eNHTkuCICmg5aCuN9g2zDEABCXU6hvJE7Y8T5L94RGqD960aiXrS+miJ4f/4dOSMliT2A zn6ThSFk80GiyZgxhjQVqpxYRA5ym/0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-KXUjcKWXNJSMlJV6t5-Jsw-1; Wed, 19 Nov 2025 17:19:21 -0500 X-MC-Unique: KXUjcKWXNJSMlJV6t5-Jsw-1 X-Mimecast-MFC-AGG-ID: KXUjcKWXNJSMlJV6t5-Jsw_1763590760 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-88044215975so8019676d6.1 for ; Wed, 19 Nov 2025 14:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590760; x=1764195560; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZlM8hkUz32RUJhAJoZInUpHPPnxIuanN0JL39L4XpyI=; b=MWKzJG7lOmzezYH0r4R4YG/OgU8nhQv9rZ9gmKWreD1Wh67cxIzdPXFbi4Zl7V8Blp WUejBYjjIVNaPmiIQwIyjfobJMVaZBViKS9QsCccjrsyBVYB4gujTCx3JyooXOXwoRIx QxcTEO//FNU6U8st8t/khZsN7kodyW2iOiRoWlkBHWfJVNG0eLdlDEa6V1/QD2jMt9Bk 9ukF8QFDQyhb9rzT396D79YqL2tHqQ6eyOcjpck/eZTCRpeUcmFSm5rCFWcekA/e0hhj fu2dAnzhlWZ64KQRyi0HC9OFEst81u0UF+H3CKt3DobM/0/UAdFUS5jApRq0LOm1ibGv behQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590760; x=1764195560; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ZlM8hkUz32RUJhAJoZInUpHPPnxIuanN0JL39L4XpyI=; b=TWmgH2PiPg1mQCLgkQ3tan22GPzahJmzT8QlENpHGbIPmxWY7Nzs1oaEYfEjH0Ulme KbAzipqY2+qpYNhzHUcdxHeDaS7FHJLryoCJvl2PodV2crOAeSyap3X9JDqBzLvaBXvg q2TV6YcBNf03FMc3LZtRiwM3NRhuvSZSvUKnwXevGXROVrZyKTMKcoEY5IWfWwV7qAhd p8z8ZaS/Whvw8Po+yjyON39IBGQ81Oox3LXi4n2ZVERg4LnE3rxDpH8YfOYd6pDnze0g 6AnA/b8Vvmhc0lCpWIY36DU+h/23S365gpHACv8maHWYJKEfGjz63maVnLaLFuXs1J2W sXmg== X-Forwarded-Encrypted: i=1; AJvYcCUMxe92qhokVkvNOnkskdxOS62NL2x5YFqvPl3yfFGEoW5MpUoyNp1dfCdLjCzXdF8vfHGykvtaUkWtH3U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6KpmDUJRgGiqKLyknQr1MexHOZOwIY+YwpyprsUB9Ok4JetiO TnzisCIC0STfBSMjvjmvrRipldB4XwnNXHosoGM9uGEdWfRDQ2L1e2GqP4iqmg15GC+SCTIpbGK E/fadAJFv3iMIrSjQWyPl1sPnanbkC9dQD0VF0dG0OEdyMFBE5L8gNEXXl03iNlghqA== X-Gm-Gg: ASbGncumEPj5WVC6WVTdnBCjtXBMb+6P+3j1g8HOFb8R9UK3chfswfcb2pEEeWL6IPL RiRuTsyoX3Gr/fSWNiWHyUFE7y5yUfRO5z4+7lwwWw6JiDVoHIvuVpVSZ3YengPwg5b9gO6w+kk MW6CejQG4yXJSLCNgrH5nGIRAByhcf51Z5Me/1Cv4cZBGWUjvIduzAPQdDhbMcyI8r8eGtFOdYJ xf/M7nFHnSx6XOfG5lO88mBOOpVKoBEF3obcdxZG0BJpi6jhdNOoka6UdZ07PN/+N67zFq2Fmb9 iKXwTDtqUwDZRPulvodH6cHrrdFbCEV92Z3oe5so5PBkWGDYZNbimIMm2RJtMY5Y2/cSV831KWf /iazV4igNQSVwzQ== X-Received: by 2002:ad4:5b83:0:b0:882:3ca2:f11f with SMTP id 6a1803df08f44-8846e03443fmr11097036d6.25.1763590760468; Wed, 19 Nov 2025 14:19:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQRDKmD0+59L+zDoLtDgwZTS1tpvNC87WX1cJ9AhOArAPTwORVd3gh8lQT/iBQwh8Q6EZBug== X-Received: by 2002:ad4:5b83:0:b0:882:3ca2:f11f with SMTP id 6a1803df08f44-8846e03443fmr11096766d6.25.1763590760029; Wed, 19 Nov 2025 14:19:20 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:19 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:07 -0500 Subject: [PATCH 3/8] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-3-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add methods to enable and disable the Single Root I/O Virtualization (SR-IOV) capability for a PCI device. The wrapped C methods take care of validating whether the device is a Physical Function (PF), whether SR-IOV is currently disabled (or enabled), and whether the number of requested VFs does not exceed the total number of supported VFs. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 814990d386708fe2ac652ccaa674c10a6cf390cb..556a01ed9bc3b1300a3340a3d23= 83e08ceacbfe5 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -454,6 +454,36 @@ pub fn set_master(&self) { // SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid = `struct pci_dev`. unsafe { bindings::pci_set_master(self.as_raw()) }; } + + /// Enable the Single Root I/O Virtualization (SR-IOV) capability for = this device, + /// where `nr_virtfn` is number of Virtual Functions (VF) to enable. + #[cfg(CONFIG_PCI_IOV)] + pub fn enable_sriov(&self, nr_virtfn: i32) -> Result { + // SAFETY: + // `self.as_raw` returns a valid pointer to a `struct pci_dev`. + // + // `pci_enable_sriov()` checks that the enable operation is valid: + // - the device is a Physical Function (PF), + // - SR-IOV is currently disabled, and + // - `nr_virtfn` does not exceed the total number of supported VFs. + let ret =3D unsafe { bindings::pci_enable_sriov(self.as_raw(), nr_= virtfn) }; + if ret !=3D 0 { + return Err(crate::error::Error::from_errno(ret)); + } + Ok(()) + } + + /// Disable the Single Root I/O Virtualization (SR-IOV) capability for= this device. + #[cfg(CONFIG_PCI_IOV)] + pub fn disable_sriov(&self) { + // SAFETY: + // `self.as_raw` returns a valid pointer to a `struct pci_dev`. + // + // `pci_disable_sriov()` checks that the disable operation is vali= d: + // - the device is a Physical Function (PF), and + // - SR-IOV is currently enabled. + unsafe { bindings::pci_disable_sriov(self.as_raw()) }; + } } =20 // SAFETY: `pci::Device` is a transparent wrapper of `struct pci_dev`. --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E4373191A2 for ; Wed, 19 Nov 2025 22:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590767; cv=none; b=rtwdN8naPMOf1xnI5EFPQZ9t8MlJcVGLv6/rneE+lwTAdf7XWPil+qfnUTZwcsa5xV11xK6jMt2VhER89HDZHplMySpuHFwkGbFvDQejF6cyJZZgCxgf57XkUGwD1/w75g6tU1CXFE8k3KM9NUbhvMN21zYierwoalI8aIwqIyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590767; c=relaxed/simple; bh=bzTncOXNg0kWII0nt+8w8axDxjNbZrgM9o9apzDdqZw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KSBw7uM3C68rrXNW+ZUlyOhTq3ZMpBtam3XdPPbC/wdPhPgWlb2P0+E8UblW0NDpppAjrdIRjGeC6Bxrc5Cyga8KmoKjok2XxedDmrxMmrGcYRWcPY94d15AdW7aS+HicTLp+quQk9Wq0jQlGrsrEkc69CPZV1dq0MuNxoRTX04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y4+JqAoL; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=AuHKdonC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y4+JqAoL"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="AuHKdonC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Sa/28IBowGRnEwfZcsKNnT8Zyd6t02o7EkUf+OoZOM=; b=Y4+JqAoL6D/LyDC0ckfdxl49xmpb+eDn52Ei6IiCQ5MJRk3fJT5pajM60M4Wul8HBTjGPi LldI/M00hlJLHtkH7+WfPSE96cEkNqOphFjkNtBY9VmfyIZt3Cn7zyWfRH70tSbSj3yt6m aZ4G/0Ux8B11CPIkxfmvclQEbLrYZno= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-2eQ3qNBUPiyqvjNFuTvKaQ-1; Wed, 19 Nov 2025 17:19:23 -0500 X-MC-Unique: 2eQ3qNBUPiyqvjNFuTvKaQ-1 X-Mimecast-MFC-AGG-ID: 2eQ3qNBUPiyqvjNFuTvKaQ_1763590762 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4ee0c1c57bcso9074301cf.2 for ; Wed, 19 Nov 2025 14:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590762; x=1764195562; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0Sa/28IBowGRnEwfZcsKNnT8Zyd6t02o7EkUf+OoZOM=; b=AuHKdonCVXl2KHWzP8/PSMJO6DCdyOsIEJFaT0UrVTJwN40bLgHy/jj2V6tZHnR2Cx xXsBfvKZzJ6ZCewansAjgRpuBe3ElS5NnfWP379kxh59tiFi30e50TXa1YUrZv/lr6Co quqjyhsghtVQJthAwrOdgkQcSUfrGhgxG/KwXPZuvsBsEfB238q9tTcPLnpXCAXX/H/j yvNClMfimuZmbju2U7q17iAZd0f16tIPjIkgOgBQkO2HbtaXQ+jtbr2STQYnYRqTqjhr VOjm85Ch5S5mOagkV2kp3ITv9mkrtBXx7KNAu7nPve1POg65OQ7+JQdcYbJN2mbXHjJZ grtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590762; x=1764195562; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=0Sa/28IBowGRnEwfZcsKNnT8Zyd6t02o7EkUf+OoZOM=; b=OU1RYXSvCy6KFn/LdKE529q2w7KvfuoP3beIQQY3uqJoxXIPVSrRzgq8ZMF5W5BUmE WM/Lsg6gpNyes1k0Kk4dswog1EJB0Mo3L4mJUHPXkXzyuJCsx/HMz2sZen7WtlOc5uSU XjkUyl6wwH9rj69xCF4MluFe1aCI0cx08VSuqK0WArzgHcN/CLGflcLYhrwpRO937v7L 4FEQVk8mXaq7k3W8VrmHDwEXTRoLp7nc0WhH7XmvEqzCSdvNgRjQC2uql3cOTyW8m24i 6N0QPiAs8Jnlc5g3bAx+G9/hPNQ6Px31HnsvuP2LeYlwGNQqMYUPveknpZS0kCHBrBdg Hptw== X-Forwarded-Encrypted: i=1; AJvYcCXDaZwhBJVt8CQ/O83stfQFCL+QT+umiDHXpFO30lc1DM3eJfzvyNbTay0PYAsI89xwcWZ4EsR/SHVfCSk=@vger.kernel.org X-Gm-Message-State: AOJu0YwIpTUHF5IBbzVAp0ia1CrYDkK/msCdYGaCps8dYBKVhyI0xHVH HYDZa7jxDmJUVGe695MCZP/pWYQmzgwLCqb1PvlLvOWQBZuWZURiXqH9z14YElBcgzkum39kpgg VcOlaDaazIj27aUtizLTvFK/KbqKJ1hK3WXaRbqErFGIPetEYYw6XCkVeZgPYUIYeCg== X-Gm-Gg: ASbGnctIG1emXsmdWe8hNT+u+KdFkGbdy9bzAKIggAdNZ0RiCDdErE1ojYvEW2r3Vqm YfhAUO9SzrMJNtuE/PsYdEddyEe1c2uq/Nr219JqqthA1Fg+MlaTaeViEAuKx2GeuS5ODupmvub hUnMBmjMCUM1XirxUhA/fAGuxvWZ4QUglCHGcnXPlEnZQN2R2nD6WqvJYVhylvEqftZNLbzZK8d 0oU+87+KTZJetF2RFvVNxzEBPJw/daJZgIzv21pZ02m9pSVHlELbtPSZ6SF+gqXkG9yT+oUotTc mbmb9VhIJDPKHUNulRZSozHw48TQE8jyKqIkGB6mjkOms1NxAEHutOGPKoV4dh9YMNfklslrOJK lTM7fGKjQ8cWHBg== X-Received: by 2002:ac8:5d4c:0:b0:4ee:1907:13ed with SMTP id d75a77b69052e-4ee49705856mr10977441cf.51.1763590762129; Wed, 19 Nov 2025 14:19:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvp/HJwXtKnotpgRtr6UAvyPlB/fAc4k6E1PSgQwkx0nIFctwGmjJxEpRk1C5rFdIJc7Go6w== X-Received: by 2002:ac8:5d4c:0:b0:4ee:1907:13ed with SMTP id d75a77b69052e-4ee49705856mr10977141cf.51.1763590761534; Wed, 19 Nov 2025 14:19:21 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:21 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:08 -0500 Subject: [PATCH 4/8] rust: pci: add num_vf(), to return number of VFs 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-4-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to return the number of Virtual Functions (VF) enabled for a Physical Function (PF). Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 556a01ed9bc3b1300a3340a3d2383e08ceacbfe5..edb2bd41c8a14c8cfc421b26cda= 4dc84f75b546d 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -421,6 +421,13 @@ pub fn is_virtfn(&self) -> bool { unsafe { (*self.as_raw()).is_virtfn() !=3D 0 } } =20 + /// Returns the number of Virtual Functions (VF) enabled for a Physica= l Function (PF). + #[cfg(CONFIG_PCI_IOV)] + pub fn num_vf(&self) -> i32 { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { bindings::pci_num_vf(self.as_raw()) } + } + /// Returns the size of the given PCI BAR resource. pub fn resource_len(&self, bar: u32) -> Result { if !Bar::index_is_valid(bar) { --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E44EC320CC2 for ; Wed, 19 Nov 2025 22:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590769; cv=none; b=O3D3VVgKFb3n8QQqSjs1LlSiFkf5aLFuAQXV0W8Z2XVaOaDS9kqR0MIBSvBswLAzH5SIE059IwQ0qbpXJoFbNhUWb+EzrWRrCKKaMlhV/COlUMD2QNnCpab+dqUppC5q6Lwm3i5+dffEf+vxjszj7MNg61z5JW5dfrTPZZ/z+IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590769; c=relaxed/simple; bh=96vzRx7vAI2mBmrVDn/9P0AmXFPaMNtBzGQHfEQkyQc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e1KwM/Ef7YemsNuFI/zXF+bqOxJiYdNRQlusqKxjmGVs8XEMuY/9RorcKdGFMtLDezuJXiBYJ/8JfzOffbr7yJti9AJbEmXsT5ZAQxcotLUB1qUtbESI/m3LsqUqhEPMS1vxc94MZ/Igo36kzy1WM9OFK3csuiw/XAwX4/GUlFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IhjRSaSW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Bli+iDJg; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IhjRSaSW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bli+iDJg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s8tI4EYN4JDf7RLWnoc2eVOO/7lGndZZgrSr2xQc/es=; b=IhjRSaSWjamIEIDgZTlE+xxRbx0fvouWbOb+04fW8530V7Z3hd4xyfaP42JqTOvIv8IxmQ VuXulG096Yrts13P10zDTGxET30rxN4jMr/qWaYRnELoIeDIlgN9FUotMgVf5k601xDmRq +cyJyiVMqZC+mD+R+1FyhIU4rQYCBac= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-rr-vFH2PNmajbkygiXPi8Q-1; Wed, 19 Nov 2025 17:19:24 -0500 X-MC-Unique: rr-vFH2PNmajbkygiXPi8Q-1 X-Mimecast-MFC-AGG-ID: rr-vFH2PNmajbkygiXPi8Q_1763590764 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-88234e4a694so11047626d6.3 for ; Wed, 19 Nov 2025 14:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590764; x=1764195564; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=s8tI4EYN4JDf7RLWnoc2eVOO/7lGndZZgrSr2xQc/es=; b=Bli+iDJgSQoOU8fxk8xpW1Lti52bOhJZuqZJqsEaI9g4YVc6eWCDTlhhOSV7KWUZ6l ZvpORWr0qi9aziLXKJ0wi3oX3UIl95islCT2kZ3xZdZPYdu89KPY6OZefdfvtYXXKHR1 WJPE5/wbE+cIReBz/X6z4mugtBt34gGOw2eR5U55chgsDNp4jp6OOU58T4nLCTb3Edee ikwuwlL18qtBsq2q47aGAhNky0xLVehA9fX7y6dapQVo3HAxt25MHBdDIAnh7HXisggh UoWN1aE/hUairWASIejlD/UYgtg6rY4l1AMmv3Rqx12V9SxoiL4U/hGJZyOHraoB2lBo EcJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590764; x=1764195564; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=s8tI4EYN4JDf7RLWnoc2eVOO/7lGndZZgrSr2xQc/es=; b=W+B0J3FqLwac9dDTHOLJ2CYEwae+b+JZaKlltOEnHBRSrIdVjRUj8o1uPEa1Uc9kdm qyKxm67/eAN/kL7PJVkj2buiSIQ2upyAJU7TIzY2wogIBNhZehceyZ0ba5ZvRQflF9s4 xv2sb0io90C6RsJXHZ876sqsgj2Cgpq+HndAXwUrYqPZl1ct1EY+0DSApC7YJPC/gchY xdb0Uy4ONAw8pgOnaW6Xrd7W/Kt4OFYn/W7oocJCSWPmMWzdGnb6LYNaM1zrGZXiogIj D2dIcmM6c00sk6cOYEK0Ay33mAZgF5Td2GyHtZxoAIOnGdgCSP009eWdZazM+Dur0is1 D7kQ== X-Forwarded-Encrypted: i=1; AJvYcCUnXVK1vU4qLhZp8L5valQJ0j8KilIrr11Kj7dDniv9otpuKQTVf97L4SNRpwZ0ibCWxe1/umsBDG6kWoE=@vger.kernel.org X-Gm-Message-State: AOJu0YzrPfKkctRUgX8QZNgLv1g/EMsuNHUN2TSnzNcVGqIxH6QMDzcD CjgwGHkzkbZ+GDyw8B/7+UHykQpyKO+yxWx0KiKZmMIQ+jF6wUqghaysEVgSO/EYawpAfpkvFHU iVOyQRo00oAUyre3iSClURkOtnEozA1Q0+cwaak7hXqkUuwHqM2DX0k4KiXgfDFGpLg== X-Gm-Gg: ASbGncuOQzMJbmM8iULk21oiWJMpZCNczmOQwdkYKkMBZUZkwTxjMrHTThZ9aApPkw6 QwtKKWHtG4tAyXB9qWGZuQXw06F+GRyeFXRSkItSbrKRZ3QLSkJwrOuoaOiafJMYkEi0GzwKakR 4f7nCDRVO1gOm20DdX5UjzmtP8KGxBgtFtNNKhaNJpiUgkMg2Ev/8URQnUsKhNIsEJBBSebW62M Ug6yXHR2yYvQayiMw1k6vDoCU2u8/REVZti366sIPceo/jpMVrP0eDvH/wVURPdt4pV+eRf5rv5 GVdWGEJwomYK1b7AhLtrtf60Smt6A2S+fwfuYPju7FKWByfIB75o4Blpn7TTkdt7odDNsJa0cC3 OywLsgeHirBVzBg== X-Received: by 2002:ad4:5aee:0:b0:880:4b32:a0fa with SMTP id 6a1803df08f44-8846e126e0fmr15483556d6.41.1763590763805; Wed, 19 Nov 2025 14:19:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBivjBhOPSe6mET8GARncZ+tJIO6qjaG8DWoG+YM0pRYYJOOFxIiTqJbhAXlSbK26RHnOI+A== X-Received: by 2002:ad4:5aee:0:b0:880:4b32:a0fa with SMTP id 6a1803df08f44-8846e126e0fmr15483256d6.41.1763590763106; Wed, 19 Nov 2025 14:19:23 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:22 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:09 -0500 Subject: [PATCH 5/8] rust: pci: add vtable attribute to pci::Driver trait 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-5-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add the #[vtable] attribute to pci::Driver trait and implementations, to prepare a subsequent patch that adds an optional bus callback sriov_configure() to enable or disable the SR-IOV capability. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 1 + samples/rust/rust_dma.rs | 1 + samples/rust/rust_driver_auxiliary.rs | 1 + samples/rust/rust_driver_pci.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index edb2bd41c8a14c8cfc421b26cda4dc84f75b546d..24dda12f6402098a1a323f3b5aa= e884201b26d89 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -275,6 +275,7 @@ macro_rules! pci_device_table { ///``` /// Drivers must implement this trait in order to get a PCI driver registe= red. Please refer to the /// `Adapter` documentation for an example. +#[vtable] pub trait Driver: Send { /// The type holding information about each device id supported by the= driver. // TODO: Use `associated_type_defaults` once stabilized: diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index f53bce2a73e3bb619372798c33bc3f13e580fdfc..96aa906984d8a40c5270bb2a7bc= f9650a41b7c9e 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -51,6 +51,7 @@ unsafe impl kernel::transmute::FromBytes for MyStruct {} [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())] ); =20 +#[vtable] impl pci::Driver for DmaSampleDriver { type IdInfo =3D (); const ID_TABLE: pci::IdTable =3D &PCI_TABLE; diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index 5761ea314f447643b8023b05ab7e92b60e6a1e17..23488fa6179fcc8c7a44df949d5= eeeb1b132bd2d 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -64,6 +64,7 @@ struct ParentDriver { [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())] ); =20 +#[vtable] impl pci::Driver for ParentDriver { type IdInfo =3D (); =20 diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci= .rs index 5823787bea8ec3e9a38ab3e4941f6c88d70e00b4..400db907e061a6a782b1cfebe9e= 5744815cc2843 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -60,6 +60,7 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result { } } =20 +#[vtable] impl pci::Driver for SampleDriver { type IdInfo =3D TestIndex; =20 --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0B2030DEAE for ; Wed, 19 Nov 2025 22:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590771; cv=none; b=e3/rOZl9glxuUpKPF4Zp5vZec3Idt2DdiAI8wwOCCHX46YJ8OFeBLHYBLPmD9626/hYytI2IINHlhQbW84ckDYetT0OdBeMxcou8jJBVBdqSi2tJ2z/k9J0ZKoe/9tjWs110jDXFAFbqF2S6gD8Fb4GoRBQc6JONAvGZB3YQU1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590771; c=relaxed/simple; bh=ePuew1JCM1Hs1e6ZIWmT70f+aea4BDiTcwCKTX9QAMU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dzdijjKNY9c2e2QfzA07yltSfmqrfOVIsvGYlprLQ88fw3mfQjJh1sEARwVvtU6xurOQrz8JeiviVNbRIxT4x+/fDwfVKRPHXWFRSSvcnVQBDdHRxz0aVKEP+IV7WPh+8lXfSvnPr2vMrafp6fSB4haZFmjb1d1T383RjCYlG1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YypFePJk; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=OoUWQt7H; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YypFePJk"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="OoUWQt7H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sRACUSt64wUiVLTpoLMSIYgwAJ0MY3voBS0pEwO7IGQ=; b=YypFePJkq/uwUBvZMzVD9DgjdhRJkuxAnMZjmlo78XbChw2Byvbo0GeYmFIPGmIVATFZ/v eMvJUviaZIs/iNcb9/EboQQlzJHsVPkKPP2jtbXj/ldgwDnoVdmOm+ZbuvCAUwdw7Xfvpm oXZ8fdowDAXHtmStxI7YmgflPI+isUw= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-9kn7GQtgOH-QZfoWEilViw-1; Wed, 19 Nov 2025 17:19:26 -0500 X-MC-Unique: 9kn7GQtgOH-QZfoWEilViw-1 X-Mimecast-MFC-AGG-ID: 9kn7GQtgOH-QZfoWEilViw_1763590765 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8b24383b680so95335285a.0 for ; Wed, 19 Nov 2025 14:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590765; x=1764195565; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sRACUSt64wUiVLTpoLMSIYgwAJ0MY3voBS0pEwO7IGQ=; b=OoUWQt7H5tRpHDkaqkcCHnEC+CcTyl6JiFC43SAu4W1Zh4rbVgN+Cqsw/736fW/OH8 F7QAZ2bn1GSYMGA0hq+4NWbMoih1ZKKaD1lErPJ9mykwO2c8JdjuDNyGPnhclKq0Kngc ipXmyXSc6KODqvGeUmoZ1QEFMq0wYSO1y9m4z8kaplpGjYEHS1E4jd7vYwoBXy9CThO7 mfH3wgBYWMS5qtPRzcwON+NSABolHhUEyl+daraz62SXHUaiPsu83tTk7Tw30WQ47/2W Vhjp2Tm+cZC5AsF7h9zrUnuFODN0WBQYWSa0wwyqGXYnwguUVY5U7Pv/NksZkYEsLRMH 95iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590765; x=1764195565; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sRACUSt64wUiVLTpoLMSIYgwAJ0MY3voBS0pEwO7IGQ=; b=Tds4a7LSDazwqYErOcavGFxXPfKuCKRyMhxQJ+9v74yF5f/GV6O0oeWiuL7uwQawO6 zmZ64DoKXKaIuVzicbIqaawcI0B8hq83f7lCZJfGwPo4MTGcxZIsYuVCi246EU8HpBG7 2M6B8zRGuzlnq8UVinRvVt1v25b5QzdpVV3Ike1Y0vWM/830cqrQJCRk5sLIVX5CDut1 ZKHvZzdIFdDKovr/DcqVSqh1UdQXz44YgRi6a9Dlp8wj1oeOGI82WEpoYAoH83k9g3+M QEOd0YZ8/Vs1h/m+Z9DhZ+TSYY3Qqi6fB2sl/yUXG/SU67Hwb1DbCMgnOdaprwebBJKD jxFw== X-Forwarded-Encrypted: i=1; AJvYcCWFXCTtHwohPJ/YMD6fPim7hd0gjiTJaigdkiqK3hbHJmLVeQb5Ts2o3S8Bwf4/MX8vvsAaAtYidJBYxBo=@vger.kernel.org X-Gm-Message-State: AOJu0YyCuOrMDbBFOvbfciaiz1RMZevqSwPnFtwENh86103CQuQRFVpJ bAJEQ3gOcNkVxpHr/93xhwfz2iVVZ4+/lkg9o9/b20GEUWY8MdakiBJ21j0tESAi/YDyBH++JkK +NXdOm+0IazgtJm+afJbKB0yh9AoOjirdbevoUq5lsxwU3aYIFMjlC0kN54k+hfyH4A== X-Gm-Gg: ASbGncuVahahJXF1t2EBQBaJ6HHhqbbpUm8nx6ZOI87/Oz0gyr8lPcgvWd17UTpJMwH B4mrdJmeKrCa7a29Dpc2Jp4oouPWX9WwpB3m7r+vD2uwl4pUGV/9oiUD6XKVexckJKoXGtVkvRQ N0JuL8ckDRdH5LgaDJHghr9n78xIxl+SPIOuSOPjr1tpDclpjFsZ1hAnR76RJVjh0hbH6hABLvT hjLi1G5mthiG4oGA9dRo1GHNafztFGchXj82LYzoQgLXk4h7X2TsBkFbJ3Wr7+9NwFIUHX9H2Ti 6xm4tdJ26seZitiBwvaxJ1Qw68E6lKefVylZQAYnW3ZeA6witIVKcZVdMwmHD3rKKhObxVjV4OW pHM63CDb8UThKrQ== X-Received: by 2002:a05:620a:c54:b0:8b2:9765:3a69 with SMTP id af79cd13be357-8b32747f96amr159065285a.68.1763590765328; Wed, 19 Nov 2025 14:19:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPsHmN0cQPL5HT5GsktthJovUEqLhZHDaj3qO7Z3zvSReIfEaHAgbYWjYECBY/fX2jHQY1EQ== X-Received: by 2002:a05:620a:c54:b0:8b2:9765:3a69 with SMTP id af79cd13be357-8b32747f96amr159058585a.68.1763590764685; Wed, 19 Nov 2025 14:19:24 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:24 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:10 -0500 Subject: [PATCH 6/8] rust: pci: add bus callback sriov_configure(), to control SR-IOV from sysfs 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-6-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add an optional bus callback sriov_configure() to pci::Driver trait, using the vtable attribute to query if the driver implements the callback. The callback is invoked when a user-space application writes the number of VFs to the sysfs file `sriov_numvfs` to enable SR-IOV, or zero to disable SR-IOV for a PCI device. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 24dda12f6402098a1a323f3b5aae884201b26d89..f9054c52a3bdff2c42273366a40= 58d943ee5fd76 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -66,6 +66,10 @@ unsafe fn register( (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).id_table =3D T::ID_TABLE.as_ptr(); + #[cfg(CONFIG_PCI_IOV)] + if T::HAS_SRIOV_CONFIGURE { + (*pdrv.get()).sriov_configure =3D Some(Self::sriov_configu= re_callback); + } } =20 // SAFETY: `pdrv` is guaranteed to be a valid `RegType`. @@ -118,6 +122,20 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci= _dev) { =20 T::unbind(pdev, data.as_ref()); } + + #[cfg(CONFIG_PCI_IOV)] + extern "C" fn sriov_configure_callback( + pdev: *mut bindings::pci_dev, + nr_virtfn: c_int, + ) -> c_int { + // SAFETY: The PCI bus only ever calls the sriov_configure callbac= k with a valid pointer to + // a `struct pci_dev`. + // + // INVARIANT: `pdev` is valid for the duration of `sriov_configure= _callback()`. + let pdev =3D unsafe { &*pdev.cast::>(= ) }; + + from_result(|| T::sriov_configure(pdev, nr_virtfn)) + } } =20 /// Declares a kernel module that exposes a single PCI driver. @@ -307,6 +325,39 @@ pub trait Driver: Send { fn unbind(dev: &Device, this: Pin<&Self>) { let _ =3D (dev, this); } + + /// Single Root I/O Virtualization (SR-IOV) configure. + /// + /// Called when a user-space application enables or disables the SR-IO= V capability for a + /// [`Device`] by writing the number of Virtual Functions (VF), `nr_vi= rtfn` or zero to the + /// sysfs file `sriov_numvfs` for this device. Implementing this callb= ack is optional. + /// + /// Upon success, this callback must return the number of VFs that wer= e enabled, or zero if + /// SR-IOV was disabled. + /// + /// See [PCI Express I/O Virtualization]. + /// + /// [PCI Express I/O Virtualization]: https://docs.kernel.org/PCI/pci-= iov-howto.html + /// + /// # Examples + /// + /// ``` + /// # use kernel::{device::Core, pci, prelude::*}; + /// #[cfg(CONFIG_PCI_IOV)] + /// fn sriov_configure(dev: &pci::Device, nr_virtfn: i32) -> Res= ult { + /// if nr_virtfn =3D=3D 0 { + /// dev.disable_sriov(); + /// } else { + /// dev.enable_sriov(nr_virtfn)?; + /// } + /// Ok(nr_virtfn) + /// } + /// ``` + #[cfg(CONFIG_PCI_IOV)] + fn sriov_configure(dev: &Device, nr_virtfn: i32) -> Resu= lt { + let _ =3D (dev, nr_virtfn); + build_error!(crate::error::VTABLE_DEFAULT_ERROR) + } } =20 /// The PCI device representation. --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD76E329381 for ; Wed, 19 Nov 2025 22:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590774; cv=none; b=eNFbOsYvl4qF8bb/UV9351aBILFhDxzgT8lI16NEayfPxcocCIBAr3G2s1XjDZQk83F1pacU9gEYQV8JPdY3yGYeDcujBfv5KVs4fuRQxPy9KE021YQIJhgYjZSy2NlNYLUpxX6zCmNG0d8C6jCvMx1IMtzzo20xeWIugWoKJ08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590774; c=relaxed/simple; bh=isBVQ57+Brz1VfxrUYneQSmfzbDfRyfWhKEYUrQf6Oc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ko6mJpy3LWaiENz0UhabG6uvsADKJEAfLqA+AoybfpqTaFXWAJt+ET6okEAcqWxz+Rq11NfNpeqeEJKGlQlrxlPOCyu1ViM0snwxs30R84+dTC9DR2Gncd7Q5tC8Q4OQPzNGJjIhJ77+jf1nMZFlRbgpjg6w+eOWFXQBGa1WtSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MMZRZqtt; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QMdubPD1; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MMZRZqtt"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QMdubPD1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8TaHEw4qfrN2YhxZsjXLb3t5RR9TWTSPbbKUt1wn06E=; b=MMZRZqttV2x7tO1K5D0HNiykivfH1TcuervJ8m5GZr+PiuWbmFNvCD0rRUVMWzxW92TlMe HwQVEV8Ld6cNFNu7PzAEgCyBsTDUQjcLYYdRRPGtZrbwkHuwOB1yNQ+21RYelCupHCpxRJ +xvs3FfC9MV8axB6lwgk4bIY+gKoKBw= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-3LydTOKqOPGdzF8-aw51nQ-1; Wed, 19 Nov 2025 17:19:28 -0500 X-MC-Unique: 3LydTOKqOPGdzF8-aw51nQ-1 X-Mimecast-MFC-AGG-ID: 3LydTOKqOPGdzF8-aw51nQ_1763590767 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-8804b9afe30so9030216d6.0 for ; Wed, 19 Nov 2025 14:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590767; x=1764195567; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8TaHEw4qfrN2YhxZsjXLb3t5RR9TWTSPbbKUt1wn06E=; b=QMdubPD1MAzVcmSYvJ3WKZpqlDeoC2bXnJZ7pYxToyCByT+VZ67873aZoEtVLwTtzw wbMnOOHyP25l1tWQrIiZOrqpr2u/OHe+u7FoMoL/UvCOat9FMqzki3Qe6iHFlFhFa+ar XwxHNgryTyqWhPt1DhCkL/KApNLRaspcmGk8QZ0qK4bXSsNEvueIbWqaaAax55YZUTUc ENfYehJLBrc6uT+1+GVOG8GMlhNj5w3sxMIonAt4JIXmru3FvJ/2yKINh0QnE/nw3DWp vt8RTYdbWggosDKvxz5PhYyKZoTUeuFnnMzYCqY1FfvzR0Ekg8/jV1KNzETjMo9yVf8B GMyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590767; x=1764195567; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=8TaHEw4qfrN2YhxZsjXLb3t5RR9TWTSPbbKUt1wn06E=; b=sVICYTg2zU068axw7Lpyvyn/FZtXElzEO8NxSi2znLzZnoPhSqDfiMevsHihv3RWpp TlQBMjuXjm8Ve/kuB0ipl5Yt1jeiHDpz8r9LSFNokbtQeQgu6ZldWMAP5JVSIf7gsIN4 nK01zEWx43OeHy/Rx5usxHHZw3hzBxH76c8tAHbrkOgXQ6Uejh+cRnM5Ud1ylpvovLLL SPS6GQ3JN8nN4zN/mgI9412s7GEPsNcNzifMjDtU7Vpdq144pRAqWg95dbslKodbhZpt GSaGvJ2RIWcg64Sbz/XyeNnlqQSM7Vjmlz6O7zH8Rwll4hAxkv2zz23L2RzL53jgHwzD uhLA== X-Forwarded-Encrypted: i=1; AJvYcCUA1/xc+NPaoGONC/BKkJEy6A/pmySjqx3W/MsoTEYc/mbSB+XEjTprpMUPOGgZdyIB7apgRkENnXRbQX0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4EfHQtUXFEqlFZ9UEZNLT1cv0ouYLWEfOQy4I2iz/lqNPq6Ho SEm7mQRBTmzo+K0WkBhh/lEH3phX7MuYQ363B4V3UGOec8fEYtPBV3e/9seZqxvBOkHgyrwcaRm w/bfktQp/OH8G4Gefs67zK0eDaL+Oal5BRdIpC9WJyokfhmAQ2iKnlpZU++XVP+nvCQ== X-Gm-Gg: ASbGnctIe/2ayIya2GBL1yvHCfxEeFzWZOtkEILKAzdKmjhMQ7WzHKsTAnZouNzaOCO MyAFVIzE2M2ASR/hwNYsuAWuoSibvnQzuFP3yzhWu+yjjdOXx58wpj/zhNKCvFO5CvhfIGE0lGR 11LONo4tgj5JAIlYYTGcGndVltORPaxTdzfObSwbQYzY1EtAnz9VuQB2R27LSHSp2WFb8ME/gXX r7N+yT60CXPi0ROEz5G++Unjp/E+DE3DA2UXfcl5K2vDWhjkS6WvAn9qJACelWNlUGR70T6h3fy XYXolyR6YJZxbl5TFSbKpEsgKtJ8vVnw+B4V3IQlUKTpvBoFoDsnblQg4/wNQGlSiaZIPg7MSMU QTwcnQbm4h7jisg== X-Received: by 2002:a05:6214:33c4:b0:880:5bff:74d6 with SMTP id 6a1803df08f44-8846e16c331mr12082806d6.51.1763590766620; Wed, 19 Nov 2025 14:19:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IG56WlPFxLZ+xUxoXWMrJpIJfnEVBJYcG8NscQK+qr9mchmkFNoMy2xH4aNIky2oxUFrfMmpw== X-Received: by 2002:a05:6214:33c4:b0:880:5bff:74d6 with SMTP id 6a1803df08f44-8846e16c331mr12082416d6.51.1763590766172; Wed, 19 Nov 2025 14:19:26 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:25 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:11 -0500 Subject: [PATCH 7/8] rust: pci: add physfn(), to return PF device for VF device 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-7-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to return the Physical Function (PF) device for a Virtual Function (VF) device in the bound device context. Unlike for a PCI driver written in C, guarantee that when a VF device is bound to a driver, the underlying PF device is bound to a driver, too. When a device with enabled VFs is unbound from a driver, invoke the sriov_configure() callback to disable SR-IOV before the unbind() callback. To ensure the guarantee is upheld, call disable_sriov() to remove all VF devices if the driver has not done so already. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index f9054c52a3bdff2c42273366a4058d943ee5fd76..d6cc5d7e7cd7a3b6e451c0ff5ae= a044b89c6774a 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -120,6 +120,19 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci= _dev) { // and stored a `Pin>`. let data =3D unsafe { pdev.as_ref().drvdata_obtain::() }; =20 + // Always disable SR-IOV before `unbind()` to guarantee that when = a VF device is bound + // to a driver, the underlying PF device is bound to a driver, too. + #[cfg(CONFIG_PCI_IOV)] + { + // First, allow the driver to gracefully disable SR-IOV by its= elf. + if T::HAS_SRIOV_CONFIGURE && pdev.num_vf() !=3D 0 { + let _ =3D T::sriov_configure(pdev, 0); + } + // Then, forcibly disable SR-IOV if the driver has not done so= already, + // to uphold the guarantee with regard to driver binding descr= ibed above. + pdev.disable_sriov(); + } + T::unbind(pdev, data.as_ref()); } =20 @@ -332,6 +345,11 @@ fn unbind(dev: &Device, this: Pin<&Self>= ) { /// [`Device`] by writing the number of Virtual Functions (VF), `nr_vi= rtfn` or zero to the /// sysfs file `sriov_numvfs` for this device. Implementing this callb= ack is optional. /// + /// Further, and unlike for a PCI driver written in C, when a PF devic= e with enabled VFs is + /// unbound from its bound [`Driver`], the `sriov_configure()` callbac= k is invoked to disable + /// SR-IOV before the `unbind()` callback. This guarantees that when a= VF device is bound to a + /// driver, the underlying PF device is bound to a driver, too. + /// /// Upon success, this callback must return the number of VFs that wer= e enabled, or zero if /// SR-IOV was disabled. /// @@ -500,6 +518,35 @@ pub fn pci_class(&self) -> Class { } } =20 +impl Device { + /// Returns the Physical Function (PF) device for a Virtual Function (= VF) device. + /// + /// # Examples + /// + /// The following example illustrates how to obtain the private driver= data of the PF device, + /// where `vf_pdev` is the VF device of reference type `&Device`= or `&Device`. + /// + /// ``` + /// let pf_pdev =3D vf_pdev.physfn()?; + /// let pf_drvdata =3D pf_pdev.as_ref().drvdata::()?; + /// ``` + #[cfg(CONFIG_PCI_IOV)] + pub fn physfn(&self) -> Result<&Device> { + if !self.is_virtfn() { + return Err(EINVAL); + } + // SAFETY: + // `self.as_raw` returns a valid pointer to a `struct pci_dev`. + // + // `physfn` is a valid pointer to a `struct pci_dev` since self.is= _virtfn() is `true`. + // + // `physfn` may be cast to a `Device` since `pci::D= river::remove()` calls + // `disable_sriov()` to remove all VF devices, which guarantees th= at the underlying + // PF device is always bound to a driver when the VF device is bou= nd to a driver. + Ok(unsafe { &*(*self.as_raw()).__bindgen_anon_1.physfn.cast() }) + } +} + impl Device { /// Enable memory resources for this device. pub fn enable_device_mem(&self) -> Result { --=20 2.51.1 From nobody Tue Dec 2 02:19:01 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 758FC28688C for ; Wed, 19 Nov 2025 22:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590775; cv=none; b=qyFpp6ChcZfpVMsJqYep/GZaWsHR8ZX65hbSsURUToGXX7TvkAu5WHm2OODfOXpSLkOHFATmB73hkJj1EcDkspHkBUsL/WydoRuYmY5KzhiEDeDpzqCW4KPcBshfk+6j2HcXwgRzZiYiTzEEXE5KLnBoc0mpCqEhfWgzGyY19rE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763590775; c=relaxed/simple; bh=D99WhKJ/ghNL6aENXqMYUdXI5q5I1XP4JOCtNjQCfz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hkr4qc+fuRSgsPDxB8tFxpb0KKlz4CQwtyFoRNt9MVpv5XhYRftK56029SHnHJ7/iKA1u7HN0rX2MYrEz9raZAIv37TE8Mk25+oCkIhUi7WjJTMi5RwO/fdjShFAcMycCALK2FvGwzZcOiYpIndoHxQ8iJ/AFBh6jYf13jN5rew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SR1aRkCH; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=CFubLoJo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SR1aRkCH"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="CFubLoJo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763590770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1vRHV6Homj57YBK4as5Vvxfa66arqOM/2yw45uMPyw=; b=SR1aRkCHRsebHJVdiZVloKFjD0quEGtufkGhbc0IuNM8Zl1F0uKr2FTLEPbwREC2Td/T8F Dozvgo1Q/xt/DcPbvH0IzCUR6wYvHwN9NANlb4YbOQDbqiS+mydPtLNL6cFjuaNZhWafi0 IIgFQnP1Z/dwF5qle23k9Sl+wEKpVSo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-INC7j8EMPeyaZO24jBSl4g-1; Wed, 19 Nov 2025 17:19:28 -0500 X-MC-Unique: INC7j8EMPeyaZO24jBSl4g-1 X-Mimecast-MFC-AGG-ID: INC7j8EMPeyaZO24jBSl4g_1763590768 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-8823a371984so5401506d6.1 for ; Wed, 19 Nov 2025 14:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763590768; x=1764195568; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=C1vRHV6Homj57YBK4as5Vvxfa66arqOM/2yw45uMPyw=; b=CFubLoJo1fnvfOUwFJHPdUyUOsH65+iipVR5y2IRzjzGjp4ILW+w3UaKTyRgpfovOT 0cAW2l5DKh/eRSZDiCZCLqLU5+jUa0iz/naA3gop0DUopN3Njc1WzQv5TtLDoQvMIGp0 fTOi5rFCl6prOhIwdghY4JVzA1iHogXoQyu18RkRiZghREQVMFHPwVR9Q09bHc/ITAQ5 1xnHXHnxqEL6d7EJFfvFdcNtvh3P4rzZ8MwD9EFLwpaQxowTm6gV3+hvIvOWhMyPZZxi e+XEXnQuytKBioT6q7pr90l0olOUwO0Epn15Iv6a4Y5YwEXd+2ZCFi/2ZKMshp5RHRZZ f8nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763590768; x=1764195568; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=C1vRHV6Homj57YBK4as5Vvxfa66arqOM/2yw45uMPyw=; b=SNaIZCu5G4mQExNDwjHLw2kMU7ExhCD13GjeK8rnMseb/xNTqx0y6J2KWUuaRgWWmD LtBkRr+1XDa6wZf5uMNx3vM3VZpp9CCSjbmUckn/Asqj3MhDL1ak1vAhastqhequjRBj SqIxjkREPd/GJGj2lu+C1dile+dOUGah5Mb6uYDy35xKHvqLNTEofmspuzF5xCFvI25U 9Fx5R+IcySnZgEx8coXj8fL0KhL6CzZ2/NykyIVs+KyiRX8Ilos3uOs1mUMtT4uB/HFL PN+9GKeUkc7mu2HrJUZSv5KSdbVGGohF082eYhjnIo/tN899nu4V22wPtYE4gmk6uffs lwjg== X-Forwarded-Encrypted: i=1; AJvYcCW3njw6WDVLR/RCKyQixEutrFjwQgAO0Z3jaG3KY5+3eEptgUq7bjwIm7zrqJz3tJgOzIflr+IUFJFh9ic=@vger.kernel.org X-Gm-Message-State: AOJu0YzUeL1PQEt153BE/nfBcjy0HmgnGqLimCmRaYDqisPqihJcUifm iXO62rxQJYSmyj2veqDvUdG3/U5Hw2WicO9sUbVUi0lt2jJInFO0/Wdlr2McA41c8tpf6ZHZfv1 Y4Xqk22Q+5U2toj0+EULs4WpiUxREpPE4JQ7XWyhhOg9ox6z+QhuhyhmI9sAG/Mu/4A== X-Gm-Gg: ASbGncvddwbYT9ArdbnXpVebf35692iLAI95eSDVyN1KjBK6uAaLo4/h9Jzvj6amChA omLsb/akYPKkX5LLCzNJ+pgu6AwTQxOouEHWLVfrr41+CcdBDbqnAFXRvMj3WOQOszUT4WZv/Q4 CkuyaXgLAk0QhRft/yJbEHRE2yoJ8NipXahJ7EGfkAp7XCiCpHdAK1LCBdmQ+ClniI7FLFSIA1v 1rR1TfhoX5bL3Bx33KwnGuO5JM5z3MFDflBzxOfTZNJWp++zGnwMlxqXPf81VooQKcvt3gTrhoy zqosp2R92yRIX4pUEg5RkHXXwpTQQXcjO95VitQl4qm47J2YFzIP7VLHRJmqla933FF9UAZvuMq l30zqjyaBzgN8iA== X-Received: by 2002:ad4:5f48:0:b0:880:854:908f with SMTP id 6a1803df08f44-8846ee4d842mr9684816d6.38.1763590768228; Wed, 19 Nov 2025 14:19:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgX6yxrFC18TElkj+HEVHEmxQ6fPmK7tD7lfiINSPtKVxeJ6AWjy050Wgsa3odgLZhl31R4w== X-Received: by 2002:ad4:5f48:0:b0:880:854:908f with SMTP id 6a1803df08f44-8846ee4d842mr9684146d6.38.1763590767686; Wed, 19 Nov 2025 14:19:27 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b141:ac00:ca1:dc8c:d6d0:7e87]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e447304sm4426866d6.4.2025.11.19.14.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 14:19:27 -0800 (PST) From: Peter Colberg Date: Wed, 19 Nov 2025 17:19:12 -0500 Subject: [PATCH 8/8] samples: rust: add SR-IOV driver sample 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251119-rust-pci-sriov-v1-8-883a94599a97@redhat.com> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> In-Reply-To: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a new SR-IOV driver sample that demonstrates how to enable and disable the Single Root I/O Virtualization capability for a PCI device. The sample may be exercised using QEMU's 82576 (igb) emulation. Link: https://www.qemu.org/docs/master/system/devices/igb.html Signed-off-by: Peter Colberg --- MAINTAINERS | 1 + samples/rust/Kconfig | 11 ++++ samples/rust/Makefile | 1 + samples/rust/rust_driver_sriov.rs | 107 ++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 120 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b71ea515240a4c5db6d932efce5183386f3a3f79..f2b00c6d9feca43443d3618da32= dce2c6ab8c569 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19945,6 +19945,7 @@ F: rust/helpers/pci.c F: rust/kernel/pci.rs F: rust/kernel/pci/ F: samples/rust/rust_driver_pci.rs +F: samples/rust/rust_driver_sriov.rs =20 PCIE BANDWIDTH CONTROLLER M: Ilpo J=C3=A4rvinen diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index b66bed5d3f36d20302bf586dfdb002d39ed9796e..b6154b6cd91f1d733f05b7529f6= 7a79fe032b50c 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -128,6 +128,17 @@ config SAMPLE_RUST_DRIVER_PLATFORM =20 If unsure, say N. =20 +config SAMPLE_RUST_DRIVER_SRIOV + tristate "SR-IOV Driver" + depends on PCI_IOV + help + This option builds the Rust SR-IOV driver sample. + + To compile this as a module, choose M here: + the module will be called rust_driver_sriov. + + If unsure, say N. + config SAMPLE_RUST_DRIVER_USB tristate "USB Driver" depends on USB =3D y && BROKEN diff --git a/samples/rust/Makefile b/samples/rust/Makefile index f65885d1d62bf406b0db13121ef3e5b09829cfbc..a4c12c1200949d0233e08a34e86= cea1ff72d0ad7 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_I2C) +=3D rust_driver_i2= c.o obj-$(CONFIG_SAMPLE_RUST_I2C_CLIENT) +=3D rust_i2c_client.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI) +=3D rust_driver_pci.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) +=3D rust_driver_platform.o +obj-$(CONFIG_SAMPLE_RUST_DRIVER_SRIOV) +=3D rust_driver_sriov.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB) +=3D rust_driver_usb.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) +=3D rust_driver_faux.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) +=3D rust_driver_auxiliary.o diff --git a/samples/rust/rust_driver_sriov.rs b/samples/rust/rust_driver_s= riov.rs new file mode 100644 index 0000000000000000000000000000000000000000..a60d58d00a2d24883ddcb7236e5= 25c448ae86b4f --- /dev/null +++ b/samples/rust/rust_driver_sriov.rs @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust SR-IOV driver sample based on QEMU's 82576 ([igb]) emulation. +//! +//! To make this driver probe, QEMU must be run with `-device igb`. +//! +//! Further, enable [vIOMMU] with interrupt remapping using, e.g., +//! +//! `-M q35,accel=3Dkvm,kernel-irqchip=3Dsplit -device intel-iommu,intrema= p=3Don,caching-mode=3Don` +//! +//! and append `intel_iommu=3Don` to the guest kernel arguments. +//! +//! [igb]: https://www.qemu.org/docs/master/system/devices/igb.html +//! [vIOMMU]: https://wiki.qemu.org/Features/VT-d + +use kernel::{device::Core, pci, prelude::*, sync::aref::ARef}; + +#[pin_data(PinnedDrop)] +struct SampleDriver { + pdev: ARef, +} + +kernel::pci_device_table!( + PCI_TABLE, + MODULE_PCI_TABLE, + ::IdInfo, + [ + // E1000_DEV_ID_82576 + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10c9), ()), + // E1000_DEV_ID_82576_VF + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10ca), ()) + ] +); + +#[vtable] +impl pci::Driver for SampleDriver { + type IdInfo =3D (); + + const ID_TABLE: pci::IdTable =3D &PCI_TABLE; + + fn probe(pdev: &pci::Device, _info: &Self::IdInfo) -> impl PinIn= it { + pin_init::pin_init_scope(move || { + dev_info!( + pdev.as_ref(), + "Probe Rust SR-IOV driver sample (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + + if pdev.is_virtfn() { + let physfn =3D pdev.physfn()?; + assert!(physfn.is_physfn()); + dev_info!( + pdev.as_ref(), + "Parent device is PF (PCI ID: {}, 0x{:x}).\n", + physfn.vendor_id(), + physfn.device_id() + ); + } + + pdev.enable_device_mem()?; + pdev.set_master(); + + Ok(try_pin_init!(Self { pdev: pdev.into() })) + }) + } + + fn sriov_configure(pdev: &pci::Device, nr_virtfn: i32) -> Result= { + assert!(pdev.is_physfn()); + + if nr_virtfn =3D=3D 0 { + dev_info!( + pdev.as_ref(), + "Disable SR-IOV (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + pdev.disable_sriov(); + } else { + dev_info!( + pdev.as_ref(), + "Enable SR-IOV (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + pdev.enable_sriov(nr_virtfn)?; + } + + assert_eq!(pdev.num_vf(), nr_virtfn); + Ok(nr_virtfn) + } +} + +#[pinned_drop] +impl PinnedDrop for SampleDriver { + fn drop(self: Pin<&mut Self>) { + dev_info!(self.pdev.as_ref(), "Remove Rust SR-IOV driver sample.\n= "); + } +} + +kernel::module_pci_driver! { + type: SampleDriver, + name: "rust_driver_sriov", + authors: ["Peter Colberg"], + description: "Rust SR-IOV driver", + license: "GPL v2", +} --=20 2.51.1