From mboxrd@z Thu Jan 1 00:00:00 1970 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 A87C43B8D68 for ; Tue, 9 Dec 2025 17:59:17 +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=1765303159; cv=none; b=Da9GEl/PfKK2QsQ/i2aqe8igFEVYToQodKcigF2o/wkXmrLuRZpXeuCr4TG3ZVbXaeVUX93/KCeEQurZ9XMtjWrzsW0SWhPoM+0sCRmFATdVOn3LEulKJ8lqXHL7Euuxd36ktvll7CgXzBjn08dTb1p0DncxT/yr9vOVVg+G4ok= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765303159; c=relaxed/simple; bh=bA0wuiy1d/JjgUyW5FUV9b+iMg8924V36lmVig/owYs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fHKsCAjCKKL9xELjKl69fWcmVcyo9dyg5WeCe6VqlOilr2uFCr62nmMk0osOLQ9gFWQDk7khuQt9Ryzsa9uJmY4oDySMlaU0ZUcVTOZZP2tbcg08LD04e7i2v7b7ekz0QzvUwFbiWXMwLrxkcke9vGsYasw3OgPAHdu2kACoYeE= 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=N4xS3nke; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kBalvsA8; 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="N4xS3nke"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kBalvsA8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765303156; 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: in-reply-to:in-reply-to:references:references; bh=d40vUR++1qaOFZuFdSMGSKMwO2iDcXUS86cXZ2oik34=; b=N4xS3nkeOYxWFL363Q8T5QJ8KIrPwkwcxF2n72iN21K+HZu6NV+J0GC2+TOHQOW5CJ5NJr LpgN0GnbS3597d+kuLBNmIbnvWaKB3Il2/DnCntxWsZ14w74LY62FN4K9Rl8+TLoqNOmpA hWNuPqnFNTwP1t8nX48RghPvpUiEXm0= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-CJGp7qV2NKSYbf4lZ94WjQ-1; Tue, 09 Dec 2025 12:59:15 -0500 X-MC-Unique: CJGp7qV2NKSYbf4lZ94WjQ-1 X-Mimecast-MFC-AGG-ID: CJGp7qV2NKSYbf4lZ94WjQ_1765303155 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-8883eb7f09bso82384156d6.0 for ; Tue, 09 Dec 2025 09:59:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1765303155; x=1765907955; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=d40vUR++1qaOFZuFdSMGSKMwO2iDcXUS86cXZ2oik34=; b=kBalvsA8FDW2zVLLAmQZE/R3/buxGOiu8hX/LQUZNSeIcTUqXgooqDOIPSV/H8b8rF etXJjOl7xSj8EOgvt/0aECHClCeGZn/xGnNvkIbNHb4nZo94MV8XP2tZvOEyvJz+E5FF /0FlPOf5t+jJhE84H6NuLSEplgZKpBruQ8HJ2lWHnHyGQuhBfNHXM5BRnex2ZJFajWWQ /PeBoepYxaNo6w17pUarzYANVXZ7QhrUgS7FZK3riw//KLiBQjtKmw8af4wD28hkIjp1 +7Le+Qz0f70kW/Mny6b57+uPrToOaV52LALTQc5Y2JB3t3c2OAtXMnsIUbKTfQ5bE4LB 5QsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765303155; x=1765907955; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d40vUR++1qaOFZuFdSMGSKMwO2iDcXUS86cXZ2oik34=; b=f8CKMhLbV0kljJR4CgQo1gcfBkNQ6wwl2ii7RO77yL8aNCabCSLxqUbqPBCwvLA5P5 dM/yMGWOzuGX46N32F9nEJtJfHoWNKk3E9TH/66ONA3USfTvBy56KhYe/PPzdA32yDlO DBEHtDVbr7luVaHfARKrTd7kQd96dEwV5vYzqfrdU+DmytFZLuoqnf3aiHygpi8AM4wR UXqidsn7kmAS6MM4GsMmz2rPRF5uPqwfEGS8QfoVgaqmVdtWt7gLk9jqQZ/KWRZkcQro Dhb/sHqNuKbbswpo/8mX7nPcd1jC0+tlYk10VqMYVB/jKU8atVJj3ykN7vGH0K98qHWX nfVw== X-Forwarded-Encrypted: i=1; AJvYcCWU6kg273D9CkcrQInp8uVmjTqX15skAwF6YTlY3/xTADBT/jG03tw+M8gUFBap+sjL9sMi2hVNHEF6/lk=@vger.kernel.org X-Gm-Message-State: AOJu0YxRDFU9/q+GQMoEBcvzpxD9oCEg6D/UMYswqq2h1D1wDFDhnE/k BJ8qac51uSEqrKIFIJHGXnk2Wv8oaBfS0/w5s+jOOFEXg6NmQq4Evm2+EssJr15hlg5fWDeKc31 utR3rW7uP0/Eo9MBvdbyiPYxZdyrjfUezHb5SHJX2QNYcQUP5XAAWERJeVPsFwMJknw== X-Gm-Gg: AY/fxX4oO9Uq2bPvnomUHi7UYwQDaFc3u4C7Aj0IWzNHXKOnirUDC+8Gw3pEEHTFmkl vVKPv+qS09j02/ktJUdovmsdMRqiCb6jZcQKR4RpQBzbB92xLfJCZvTPa5byfWkLjp6Cvq2VdSc mNxAUuTh8nojXT+5Ws5hkYUbSW/jKKwqiNirqPtm4z7zwUfnqqy+lDvRcdqcndRHmvw9dyDnSdM oBUHTG6UaLAM/shE4ysOZ5GvN4fNAZedmSKeCIVfa7/LGlQ/mshEDR0sUhIdMtZAut6Mn2YA+6n 72yojKZq4AW2/9yW5us/fVmwe7CsrYSAN/2DbEF7nde6t+eF9E7KBVVfPo3ssf1Q21hvxfdaPI6 eyFxRN1Wphw== X-Received: by 2002:a05:6214:2422:b0:87f:b2d8:6020 with SMTP id 6a1803df08f44-8883dbf6cb3mr214779406d6.38.1765303154861; Tue, 09 Dec 2025 09:59:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGW59vhBVoyXlKa64sg3W6fFSnkL9S5Jg3icr+p7GG1on3Wtf7TpWh8CqQWJvDh6TJDBZ4C/Q== X-Received: by 2002:a05:6214:2422:b0:87f:b2d8:6020 with SMTP id 6a1803df08f44-8883dbf6cb3mr214778486d6.38.1765303154269; Tue, 09 Dec 2025 09:59:14 -0800 (PST) Received: from localhost ([2607:f2c0:b021:e700:1a3d:b7ef:5d4d:bee5]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-888287a5518sm127224716d6.31.2025.12.09.09.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Dec 2025 09:59:13 -0800 (PST) Date: Tue, 9 Dec 2025 12:59:13 -0500 From: Peter Colberg To: Joel Fernandes 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 , John Hubbard , Zhi Wang , Jason Gunthorpe Subject: Re: [PATCH 3/8] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability Message-ID: Mail-Followup-To: Joel Fernandes , 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 , John Hubbard , Zhi Wang , Jason Gunthorpe References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> <20251119-rust-pci-sriov-v1-3-883a94599a97@redhat.com> <20251207063355.GA213195@joelbox2> 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: <20251207063355.GA213195@joelbox2> On Sun, Dec 07, 2025 at 01:33:55AM -0500, Joel Fernandes wrote: > 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(()) > > nit: Why not use `to_result()` here? Thanks! I queued `to_result()` for v2, from an unrelated review [1]. Peter [1] https://lore.kernel.org/rust-for-linux/b8234f181d35b21a3319b95a54b21bdba11b8001.camel@redhat.com/ > > thanks, > > - Joel > > > > > + } > > + > > + /// 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()) }; > > + } > > } > > > > // SAFETY: `pci::Device` is a transparent wrapper of `struct pci_dev`. > > > > -- > > 2.51.1 > > >