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 488B22D0C62 for ; Thu, 20 Nov 2025 15:49:36 +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=1763653779; cv=none; b=omprPb/3rSmo58sHD3s7kLSIQFfwyUXbLtzvvEYric2B/wMDMpZbf5nLQlm3XjdIn3DC8yED3ftJHSEmkKttQO6EA92ffbs9O46n1r8eHU/4JVPhf/zk60U+xyDE4y6Iy46FOZq64LwI7slYVexZcF4R+7YTDMXX/R3M5v9DoZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763653779; c=relaxed/simple; bh=Z7khxCy0juQFD7sc2XVpGJcgIRewBFI8alTprYiEvgk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kqnoy0s0blvMVGe1EXoYoTBDMztVga5eSfg/WSm9DS1ULmHyJfMRUlJ288TnvcRDc3WnzVrPhP/mkQW0zmnI0Pp5nknWpAu/+9Ry+DZbJ33MTG4fnK8m6ysKWfhA2/kjs/2+w3KGnSB7z0W7FdYE3PU13qeU4qv3PPAt3DfUp0s= 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=aQSSgymC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=ovElWv/n; 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="aQSSgymC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="ovElWv/n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763653776; 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=91ugE35V8USHsTpLgO4hUdjEiFkkZFTQ1do7SDOhLck=; b=aQSSgymCnqqz/DY/QMXDcHrLoxY0AkUSvIFmAKHmkE+wI+7h96ngPEu+zCctjvl3h9z6xM 6JBkedloNP8RwfP7B/gYkYTJEDPLiRd/4/yd8wDJrbwETZDbc423NYoK705B0dkC8CmBQ3 hy8wNcpr8W8LGXD2bBRzAkMR20n583o= 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-347-bmK660fJNoel54ft6PKOhA-1; Thu, 20 Nov 2025 10:49:34 -0500 X-MC-Unique: bmK660fJNoel54ft6PKOhA-1 X-Mimecast-MFC-AGG-ID: bmK660fJNoel54ft6PKOhA_1763653774 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-8805c2acd64so29786106d6.3 for ; Thu, 20 Nov 2025 07:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763653774; x=1764258574; 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=91ugE35V8USHsTpLgO4hUdjEiFkkZFTQ1do7SDOhLck=; b=ovElWv/n8dnhczOqizRX4esUtAJiuOqGukPFGw96GFA5HTajt/uuIIvkNISom4jA2G 9eDnwOXNsHkL8FDJeAc4oZ7d11fwMGm7vn9Yfiyj2eCweLEy8/Z4MaH/1GqruIyDiAU+ BBc16guepRcZVx2QAhy+qAEQZrG5fU/6kMn+54AZPfaInMKz87wWJtH6M5eT9j5338t7 q+OiSVGacEoH3ELPaNCeFrokQgaxkD0h7D5Z54ciaH+Anxi2kXnwm7854TUK9JI/IaHu NQDKt9nzDYjiSz/tP3DIHXnKVvbYGVOEXLG6uRSDFjD3QTGtFMIfSxharQz/2y6EPpi+ YiLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763653774; x=1764258574; 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=91ugE35V8USHsTpLgO4hUdjEiFkkZFTQ1do7SDOhLck=; b=b4TquO/ru63ZG9t8UjOkUDds7wiev8QXFNHV73tq1lJCwzO84R5Bl6eCXig9QkNWWi Qw/DUXhFfjPTHUNV9IyGqOeHUbgkEasBSH96WlaEjPL/FFZHvRnieHMKd73sEJBEPpps SlP51OCZeQq8msV7mOxqaPlF2aNFNBbusjhwrC3508OOKSTN1NvwH+EYypxeMJy4Nr+I 8wp4VJNpjNa5EEP2rJhlfyHCtPDP9G0c/2pEduXCs5y+0O+BKt2p3yFv85Pnbr8PCvmp DZoB8RVfz5ckTHE/jtz4ffSc0f0cr4tMGjtdMxUUzDV6HhOOXuF7KXN/4mDxbgWnASUo 249A== X-Forwarded-Encrypted: i=1; AJvYcCXBtGZqV47agX5MiQMm0yXyuoPKaLMIfE3ooVyTtktVK4Y8/0nQ+WdFI/XmCYG9tiy/QsP0b/4raTkDK9s=@vger.kernel.org X-Gm-Message-State: AOJu0YzUzKqyHjjA4KOUlXHodJa9SniJCvIFZGO4iWQirEHbyCsEHHyb 5KiNk9Yo7FRh8T7vgvGfcnVMxgc0zj4q7C2CsdkKgkW8P2PCRvB+OI4+41mTio8WCRCZZFkokKQ MQCgV4DGv7Ns7TgYI7x4XsU1/2ZkiW51VfgfSZlnP/WLUbJBiV/5VjW4xa2/6hDWf9g== X-Gm-Gg: ASbGncsfudP8lj6ejoSNG0WOlM5NkOZjYdZYOyy2AqFa6T0yOc3pugHfWiuN0Fbdrde KQCsPgsuOjwrURedKNC0NCHuEo4grWkesRYfVM9NQaPZGQxFANhhAB2LZhe7L84vu1hvjC6Pr/Y ow+VnzikyI19quDZ+XLpI2yQVGY8oqA4090tvMnHqBbxorCFOyHhSLotFwANel9oL78WzeKS0Sw TqpcurKIrJPzF9eWZqS7UBRG7mcRnHbxXEn63Hq+4TiXeFTmWt6KLPD+C6eIaPGatf7owA2uHT5 BegjZeUbz6zmBZwlINvS6nlKaZOzn8weQl4pnU93FUH4vukSqumBJo6k7p2IsaBDzPBTU0o4DXj rj5tVjR4s X-Received: by 2002:a05:6214:3283:b0:87c:1fd9:da52 with SMTP id 6a1803df08f44-8847a3d973dmr11916d6.9.1763653774075; Thu, 20 Nov 2025 07:49:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZDZecDuAU2AHXM6Uqgl8MchJS3ZXsbLZQMQHbbLh7Q6dI9fcKtwuWdhAIK4pa19g+Q9VupA== X-Received: by 2002:a05:6214:3283:b0:87c:1fd9:da52 with SMTP id 6a1803df08f44-8847a3d973dmr11206d6.9.1763653773470; Thu, 20 Nov 2025 07:49:33 -0800 (PST) Received: from localhost ([2607:f2c0:b141:ac00:5cae:3da9:9913:ff7]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-8846e573909sm19710936d6.39.2025.11.20.07.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 07:49:33 -0800 (PST) Date: Thu, 20 Nov 2025 10:49:32 -0500 From: Peter Colberg To: Zhi Wang 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 , Jason Gunthorpe Subject: Re: [PATCH 8/8] samples: rust: add SR-IOV driver sample Message-ID: Mail-Followup-To: Zhi Wang , 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 , Jason Gunthorpe References: <20251119-rust-pci-sriov-v1-0-883a94599a97@redhat.com> <20251119-rust-pci-sriov-v1-8-883a94599a97@redhat.com> <20251120084132.40f72ba4.zhiw@nvidia.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: <20251120084132.40f72ba4.zhiw@nvidia.com> On Thu, Nov 20, 2025 at 08:41:32AM +0200, Zhi Wang wrote: > On Wed, 19 Nov 2025 17:19:12 -0500 > Peter Colberg wrote: > > > 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. > > > > snip > > > + > > + fn sriov_configure(pdev: &pci::Device, nr_virtfn: i32) -> > > Result { > > + assert!(pdev.is_physfn()); > > + > > + if nr_virtfn == 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)?; > > + } > > + > > IMO, it would be nice to simply demostrate how to reach the driver data > structure (struct SampleDriver) and its members (I think accessing one > dummy member in the SampleDriver is good enough, not something fancy), > which I believe quite many of the drivers need to do so and they can > take this as the kernel recommended approach instead of inventing > something new differently. :) Thanks for the suggestion. I added a `private` member to SampleDriver, similar to the rust_driver_auxiliary sample, and extended the VF-only path of probe() to demonstrate how to reach the driver data of the PF device from a VF device. Peter > > Z. > > > + 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", > > +} > > >