From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 5A31F28FFE7 for ; Fri, 21 Nov 2025 23:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763767724; cv=none; b=lMw5uuzidwo5vKhpXiF0+6vSZ/R3VwOHCyrpaQxNjLdW2GJSKfeNFCIDW+8aMaSvflkx9D7n/V1k92ZDnLewC/6X40LzoJPW+6wL8TFTs3JkoID9Eugkl3CxetHW0bYhZsfzy0EuJ1b1m0VKaWZ1r8t5+Oj4zc4n4nvG1mW0IAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763767724; c=relaxed/simple; bh=mauH3JtypClNExnFnUryKjVThxBomgYf7WHHEjpqgb8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZEtBubE36RrsB7oG998zUkUF+yCgWNamX9CStvRSMYzioKb+WCpFG16RMJrxkacQoevwWGdPQQGN1cNLBik4hzM7Kqi+FBrgz2oj6SKVno1RsGM1xCbj697VauUY3H5H07Hr4IbZrpBhAco4WC9T1Z/DEMQbqwIJHcrT8Oq/Zsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=I3y4qwRT; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="I3y4qwRT" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8b2dcdde698so362806385a.3 for ; Fri, 21 Nov 2025 15:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1763767715; x=1764372515; 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=mPkLUeocYZ9OHUjt6MdsqZZIbrBB8fliyjymBJQ8m2U=; b=I3y4qwRTvUh9rlS5syKtf1HlC+Nyuq3zqu8WG7f8i0y+hrnFDZs6JR0puvf//dG6q9 ykpB6ZtpGK7RL9alVdrq4fNBPGIA0TVjkAhrCLG8M5hJOZA196ZtCgig4Iu6Uajf1COu zr8i79g9rXT2fjYnywpy8uqC9WrnI+SZ9iWr4i6O2jfVbgy4hyvHJPxY0ENrxbVZluhw +oynvrAaNiIqKox6J2oyslLtVnYGCS1Q05IfXzAQyzJa63bwv5Smrlh19VHnc8NowrTS PTa+rn2vh10uHiPLE9vPIPorxy36tDcvDaKF5F+NSQ18un/j8/RGSFFIK5vHcRLP44aD mekQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763767715; x=1764372515; 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=mPkLUeocYZ9OHUjt6MdsqZZIbrBB8fliyjymBJQ8m2U=; b=gcsMNqFSeqc7PBaWLjkx476H5I9m8kOvjnDhaMfIkQCzF2Pu14xBvx8cAsH3toOq8r IyBVf3FWKCEVVHlOG7SY3oeuTdimLuuCSQVDBPsEhjkyM6BgQ2HE/d/ezRUojcSi9Ec9 sq8tu/lqS10XXULp7rIQpoRb3gBmxnSnnieAy13PueYEu+fI7aOVH7pMRMv9f7NQj53k t8eIJkMJTEpcigoOAQcbf/KzsHIqZ0u0ra0fyMcQCU1UC6laCOo2Pi08bFYqgeSH3coc 5K+ZEr5tq/fjfcj3n7qlEyHDrDlZ1Ae6MMDvCFWHUYUA7SOUAS7VEvw9Aggr884pguQc OlpA== X-Forwarded-Encrypted: i=1; AJvYcCXqOekQVdozObTAcQxY/P3pg6/zrMBxpEhhwklwcjFZxdH4A8t7CdFPFHvZLiuTK3Mz0sSF52pgHdppWyU=@vger.kernel.org X-Gm-Message-State: AOJu0YzhQFLtoCpcXk4vP8EZIei1obisLABKqq1y6L3vJD+N/VPgUvJt g/lLtdIiW1rNHURFEtC4ZOxGFtDA7mGyxyWIhB8PVqWhC4buEdd6du2djXj/At94JJA= X-Gm-Gg: ASbGncuVU7BL9yVWUbhyvkZLhQkSMC2gQwfEpe8kVE8ja/2AIHiFMqLoW/cocG+60vm DaQEh7TFaisHFEFUKu7uL5LgatMv842/qmByiG6uWBCHApsOxr1uQvsrk+H5yEmVQtyQbNnENBD 8pqeu43vU52nUjMWfQRU0Spda4xSEHCMqsCn/T1ikq9ihLj94iy+P/nU48cJBLmCoHyooy36cJH irUA2NF+3YtYv1GNB/HuBvegVhZU+2mmMT8qgK6FyOWeQxY4JPwMTIFaNf24Ysiy/zoPzsqeEeG YNyc6o2qPRvxnz35scukbbfPEnq1cbZ+FCZYpGtfsXDFaR4r/Cw5BR6ftVJsrclEoVr65nUCPli qE2FtVz/ZfUhAuAiD20D3mhGMEDTJSVIMSQPrJH4JZAQNvZbv5jMy+Es7GqnCLGHmp4d45Vlj67 W5N3ISlxfoBHN696K34pMpWe/FMtQzUhgb6d6Y1TK0u/GUD5Lg7Lc17Wgj X-Google-Smtp-Source: AGHT+IGLeMtP253GHas4M+LvKhyXDfO6U6IBU1zq+lA7A93sFOfzBPQ38o7t96QuMPLUVNh7bM9LEQ== X-Received: by 2002:a05:620a:4714:b0:8b2:769b:74cd with SMTP id af79cd13be357-8b33d4846f2mr511750485a.71.1763767714795; Fri, 21 Nov 2025 15:28:34 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-47-55-120-4.dhcp-dynamic.fibreop.ns.bellaliant.net. [47.55.120.4]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b3295c1328sm451262285a.27.2025.11.21.15.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 15:28:34 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1vMaYL-00000001bZj-1HN0; Fri, 21 Nov 2025 19:28:33 -0400 Date: Fri, 21 Nov 2025 19:28:33 -0400 From: Jason Gunthorpe To: Peter Colberg Cc: Danilo Krummrich , Bjorn Helgaas , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?B?QmrDtnJu?= 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 , 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 Subject: Re: [PATCH 3/8] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability Message-ID: <20251121232833.GH233636@ziepe.ca> References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> <20251119-rust-pci-sriov-v1-3-883a94599a97@redhat.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: <20251119-rust-pci-sriov-v1-3-883a94599a97@redhat.com> On Wed, Nov 19, 2025 at 05:19:07PM -0500, Peter Colberg wrote: > 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..556a01ed9bc3b1300a3340a3d2383e08ceacbfe5 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 = unsafe { bindings::pci_enable_sriov(self.as_raw(), nr_virtfn) }; > + if ret != 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 valid: > + // - the device is a Physical Function (PF), and > + // - SR-IOV is currently enabled. > + unsafe { bindings::pci_disable_sriov(self.as_raw()) }; > + } Both these functions should only be called on bound devices - the safety statement should call it out, does the code require it? Also per my other email SRIOV should be disabled before a driver can be unbound, this patch should take care of it to not introduce an dangerous enable_sriov(). Jason