Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp558319pxb; Thu, 15 Apr 2021 00:43:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7mdkn2PIsPV4QGLQwrMuik54ECpKClKDA+Vn9PwlX42S5aiupMqkpq8VpjMxopL1l3q85 X-Received: by 2002:a50:ec8c:: with SMTP id e12mr2526514edr.249.1618472597911; Thu, 15 Apr 2021 00:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618472597; cv=none; d=google.com; s=arc-20160816; b=UzA6JQJmJkUD/yVWp/dQvi2bJ9kg1kK6yAZODYsNOJWBfG+LvCI+n0pcO66bypkyjv Uqr0w0akNFVNKpNe5QTQsugTfJTdWazuUyc8z2gW63PJkl8TNHYjfoNbnyFD0lcg75LR S4s9e+3sqrrt6SonkqXwcYqaEz8BBwOslj0LdWe5HJihIvTrpS3XrLk7CD1ngfU3RPpR nQiqseejzgw7BhccQHsomOWMzwEm8FRSsoa5xCLycUYInaePT/YjUUEt4jlsd5P95cYl gKiculD9cTV9K9zJGHfVCgpvbG1rpWQM89AOO4slJHdnb+1YrijsoJSl4kb1n5CLXU25 F5+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xMBHOqRNLVRMS07iUqFEuZb5xzgm/L59GDWK4D2fxw4=; b=M1qd7Q3x01ehU6b0TDpKFrzvahMMCAjal0ti40OM5XvwSLRuPvVWhE1Y1D623Shper 7TT3DqbPQYp4k/ElDukz7jwxKba46HsP3MruNw+CFo7fmXTNlEqEanhEJzjkt+NwWmzk N6/+Ybs+PTFwjPjjb1AyuKpa3C68DfovNY7uoKYavyUMp8qB70odeRiIJvMBhPtph+B+ DnPwq8+1X7CXHbqFDrZWEqntbIEGFQ6bCIt2Posw50Z22rUX7lJpZXzBM6nT9W08IK/7 ETmmtGPoT5ePcfUv6+9SKRJaLKESebazCtwEofRa1veWBUh+pX9fOZ97W1k1UsyoeEid VaCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=leylOg12; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si521556ejk.72.2021.04.15.00.42.54; Thu, 15 Apr 2021 00:43:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=leylOg12; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbhDOHkP (ORCPT + 99 others); Thu, 15 Apr 2021 03:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhDOHkO (ORCPT ); Thu, 15 Apr 2021 03:40:14 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0486C061756 for ; Thu, 15 Apr 2021 00:39:51 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id c1so17771824ljd.7 for ; Thu, 15 Apr 2021 00:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xMBHOqRNLVRMS07iUqFEuZb5xzgm/L59GDWK4D2fxw4=; b=leylOg12nQE524kr0iJBrc+3WKLv4y/Hr5k7IgmS9wIeRIoKk3K3kBQZ+l1u5onlWf 7hMszo1+KSbkquXbRUDMs0h5PriyyDK0btcwTDupomKAB6Y8Ris9NqziYPOH8qt5xXxE Bo3vY6j9/lbvx0S28JJMgof1BZSn3j1xLx8q7e2JEs0I3ukRVBOTdrvjFwvU/5SZ0RyD E3ettyogrKmL23WA9z2PVGh1nLHj0wLLTLJV13LeGvvp8MXof54Ngv7h9xlqHfGiK3fv t1RAupcbqj5JhAV1oF3ZyQoqcoBWL2CyNacOtLXajyqgnMSm9Xf/KugQ8R73+oXSdwNW ycLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xMBHOqRNLVRMS07iUqFEuZb5xzgm/L59GDWK4D2fxw4=; b=Ax2Fq2hmlL2/7fSPbjGBvXT3bA4MeuASqnjmdPSP4DKq7xpd1UQxTGqNbKZg6yTF9C alQr08aLP/m9cwuyngWCDjmuc2TeTsH53p7D1xONA9fOY5uv437nmm7Koh1I3iGKOFRJ rEmKbBgkrtcA90GzKYApbxFTLgzm0EZ4trC22zGzSRR28Ixln0rxgGYFZftYw59YHIv/ W5P5Tu69lqsp5I309FCN/w/8Mxq8qPJ7p6JhLOw/q3vofW9q3zhJuenZMRsPDEGJwzlp WStBUBD/7VGXzhThsTXr9ilCItsKvhoes55a6D20agAbLbjsZx8QV1yWLY1vgPhWD4sP D13g== X-Gm-Message-State: AOAM530nKfab8cE81nWqyprMEfPGYxMttMCT0WI5DoUkgZvrAleNmyqt KytoLeQWONeY/GJ/2dG6Ob+JdWu/z3+Py9IWeBH/Tw== X-Received: by 2002:a2e:968a:: with SMTP id q10mr1048369lji.0.1618472389953; Thu, 15 Apr 2021 00:39:49 -0700 (PDT) MIME-Version: 1.0 References: <20210414184604.23473-1-ojeda@kernel.org> <20210414184604.23473-10-ojeda@kernel.org> In-Reply-To: From: Nick Desaulniers Date: Thu, 15 Apr 2021 00:39:38 -0700 Message-ID: Subject: Re: [PATCH 09/13] Samples: Rust examples To: Greg Kroah-Hartman Cc: Linus Torvalds , Miguel Ojeda , rust-for-linux@vger.kernel.org, Linux Kbuild mailing list , "open list:DOCUMENTATION" , Linux Kernel Mailing List , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 12:10 AM Greg Kroah-Hartman wrote: > > On Wed, Apr 14, 2021 at 04:24:45PM -0700, Nick Desaulniers wrote: > > On Wed, Apr 14, 2021 at 12:35 PM Linus Torvalds > > wrote: > > > > > > On Wed, Apr 14, 2021 at 11:47 AM wrote: > > > > > > > > From: Miguel Ojeda > > > > > > > > A set of Rust modules that showcase how Rust modules look like > > > > and how to use the abstracted kernel features. > > > > > > Honestly, I'd like to see a real example. This is fine for testing, > > > but I'd like to see something a bit more real, and a bit less special > > > than the Android "binder" WIP that comes a few patches later. > > > > > > Would there be some kind of real driver or something that people could > > > use as a example of a real piece of code that actually does something > > > meaningful? > > > > Are you suggesting that they "rewrite it in Rust?" :^P *ducks* > > Well, that's what they are doing here with the binder code :) I know, but imagine the meme magic if Linus said literally that! Missed opportunity. > Seriously, binder is not a "normal" driver by any means, the only way > you can squint at it and consider it a driver is that it has a char > device node that it uses to talk to userspace with. Other than that, > it's very stand-alone and does crazy things to kernel internals, which > makes it a good canidate for a rust rewrite in that it is easy to > benchmark and no one outside of one ecosystem relies on it. > > The binder code also shows that there is a bunch of "frameworks" that > need to be ported to rust to get it to work, I think the majority of the > rust code for binder is just trying to implement core kernel things like > linked lists and the like. That will need to move into the rust kernel > core eventually. > > The binder rewrite here also is missing a number of features that the > in-kernel binder code has gotten over the years, so it is not > feature-complete by any means yet, it's still a "toy example". > > > (sorry, I couldn't help myself) Perhaps it would be a good exercise to > > demonstrate some of the benefits of using Rust for driver work? > > I've been talking with the developers here about doing a "real" driver, > as the interaction between the rust code which has one set of lifetime > rules, and the driver core/model which has a different set of lifetime > rules, is going to be what shows if this actually can be done or not. > If the two can not successfully be "bridged" together, then there will > be major issues. > > Matthew points out that a nvme driver would be a good example, and I > have a few other thoughts about what would be good to start with for > some of the basics that driver authors deal with on a daily basis > (platform driver, gpio driver, pcspkr driver, /dev/zero replacement), or > that might be more suited for a "safety critical language use-case" like > the HID parser or maybe the ACPI parser (but that falls into the rewrite > category that we want to stay away from for now...) Sage advice, and it won't hurt to come back with more examples. Perhaps folks in the Rust community who have been itching to get involved in developing their favorite operating system might be interested? One technique for new language adoption I've seen at Mozilla and Google has been a moratorium that any code in needs to have a fallback in in case doesn't work out. Perhaps that would be a good policy to consider; you MAY rewrite existing drivers in Rust, but you MUST provide a C implementation or ensure one exists as fallback until further notice. That might also allay targetability concerns. > Let's see what happens here, this patchset is a great start that > provides the core "here's how to build rust in the kernel build system", > which was a non-trivial engineering effort. Hats off to them that "all" > I had to do was successfully install the proper rust compiler on my > system (not these developers fault), and then building the kernel code > here did "just work". That's a major achievement. For sure, kudos folks and thanks Greg for taking the time to try it out and provide feedback plus ideas for more interesting drivers. -- Thanks, ~Nick Desaulniers