From patchwork Wed Nov 8 02:26:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13449528 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 712E5C4332F for ; Wed, 8 Nov 2023 02:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbjKHC1U (ORCPT ); Tue, 7 Nov 2023 21:27:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjKHC1T (ORCPT ); Tue, 7 Nov 2023 21:27:19 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C5F181 for ; Tue, 7 Nov 2023 18:27:17 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81e9981ff4so6469855276.3 for ; Tue, 07 Nov 2023 18:27:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699410437; x=1700015237; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dHBKDxSX6sFdE8FPheIQIj/jS3pVY6NCDTnh174u1ns=; b=Mvbz1nb065Anmbikm7daaqWVTzheA4ephiWXwl4Zac/i2NScQ8T0B+/hk1KTlNu0Ti K+fU3oPsQxmOJFVBDJGXIyqPmvFsj+eJ6ysMi22WI3amFuEiRQfvfClMaCSyBFbkOBOT SYDQe3ztJnpQbBj6W33j6JIyQliro8Kpy+cLVw2uBDlEmYb5pCro/1sKoStrI12Ygft6 hgAJFDmaE2XVvR+uWVLfJOfBN+Aw15KmQaq0lElGQ6UfY/FzyUPq0uy24tRYXcSA1wpL sW9km68FQyLBq+xx1wqXVSxnGOeL92zDoltUWARgo59EbQzgR3LXl3Rsdnn/XTvdOLvL NMDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699410437; x=1700015237; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dHBKDxSX6sFdE8FPheIQIj/jS3pVY6NCDTnh174u1ns=; b=JmP/aPynbWfISc2lCRqx4o/WWSrl7Q6v6pRBKq5hH7ouCb5Bf4lfw9+pqh/XSofA9k CtD0HA+wJ2XDNf2b9j3CpksKbXaEHzVBJZNFdx+FOLGaTDsdtGWIrzrqSkToL3GP1SSp Oj90T3sh0KIRp6wcOOIjaDmXjZ9D1tCyCdR698Yb28eILSIZFH2I+cQNkf5o5SPkhUVr BDJwR/FOIfH3ZDGDHcb6Fhu1th/AqR4Xlw8OGSTkfvl3pYWoUVryVbummErdh1BRYH/0 qr0xZo1wS7yubq/GRe92MAuZe7w2C1el5sQL7ojtTwGZlnse01r35WiZWNpy2tpyGQ+A CUyg== X-Gm-Message-State: AOJu0Yz4m//ZAI0AClcz9MDGbOsDV7lXtyN1tvChpTXeCmiqxYsxgObh tpMsbZpu7hrlWnfQ1Lqqkzt1vIKSxoJ8 X-Google-Smtp-Source: AGHT+IEd4YppkzLvzHVgzMv4K4Im8NsnUDvSn1GF/un6K4zJP32gBGMx9TOWWIz9Zty7GbdwjtzDJGqCCcKy X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:6902:701:b0:d9a:6007:223a with SMTP id k1-20020a056902070100b00d9a6007223amr9307ybt.8.1699410436773; Tue, 07 Nov 2023 18:27:16 -0800 (PST) Date: Wed, 8 Nov 2023 02:26:22 +0000 In-Reply-To: <20231108022651.645950-2-mmaurer@google.com> Mime-Version: 1.0 References: <20231108022651.645950-2-mmaurer@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231108022651.645950-3-mmaurer@google.com> Subject: [PATCH 1/3] kconfig: Extend expr_depends_symbol to recurse From: Matthew Maurer To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Matthew Maurer , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Adds optional recursion support to expr_depends_symbol. If recurse is set to true, it will recurse through other defined symbols' dependencies to determine if the expression hard-depends on the provided argument through an multi-step dependency. Signed-off-by: Matthew Maurer --- scripts/kconfig/expr.c | 22 ++++++++++++++++------ scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index 81ebf8108ca7..9d517b897378 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -876,25 +876,35 @@ int expr_contains_symbol(struct expr *dep, struct symbol *sym) return 0; } -bool expr_depends_symbol(struct expr *dep, struct symbol *sym) +static bool sym_depends_symbol(struct symbol *hay, struct symbol *needle, bool recurse) { + if (!hay) + return false; + if (hay == needle) + return true; + if (recurse) + return expr_depends_symbol(hay->dir_dep.expr, needle, recurse); + return false; +} + +bool expr_depends_symbol(struct expr *dep, struct symbol *sym, bool recurse) { if (!dep) return false; switch (dep->type) { case E_AND: - return expr_depends_symbol(dep->left.expr, sym) || - expr_depends_symbol(dep->right.expr, sym); + return expr_depends_symbol(dep->left.expr, sym, recurse) || + expr_depends_symbol(dep->right.expr, sym, recurse); case E_SYMBOL: - return dep->left.sym == sym; + return sym_depends_symbol(dep->left.sym, sym, recurse); case E_EQUAL: - if (dep->left.sym == sym) { + if (sym_depends_symbol(dep->left.sym, sym, recurse)) { if (dep->right.sym == &symbol_yes || dep->right.sym == &symbol_mod) return true; } break; case E_UNEQUAL: - if (dep->left.sym == sym) { + if (sym_depends_symbol(dep->left.sym, sym, recurse)) { if (dep->right.sym == &symbol_no) return true; } diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 4a9a23b1b7e1..edfe3046d050 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -299,7 +299,7 @@ struct expr *expr_trans_bool(struct expr *e); struct expr *expr_eliminate_dups(struct expr *e); struct expr *expr_transform(struct expr *e); int expr_contains_symbol(struct expr *dep, struct symbol *sym); -bool expr_depends_symbol(struct expr *dep, struct symbol *sym); +bool expr_depends_symbol(struct expr *dep, struct symbol *sym, bool recurse); struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym); void expr_fprint(struct expr *e, FILE *out); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 61c442d84aef..d5898cd6aeb8 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -443,7 +443,7 @@ void menu_finalize(struct menu *parent) if (!expr_contains_symbol(dep, sym)) /* No dependency, quit */ break; - if (expr_depends_symbol(dep, sym)) + if (expr_depends_symbol(dep, sym, false)) /* Absolute dependency, put in submenu */ goto next; From patchwork Wed Nov 8 02:26:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13449529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 339D4C4332F for ; Wed, 8 Nov 2023 02:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234154AbjKHC1o (ORCPT ); Tue, 7 Nov 2023 21:27:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjKHC1n (ORCPT ); Tue, 7 Nov 2023 21:27:43 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C77F10FB for ; Tue, 7 Nov 2023 18:27:41 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da07b5e6f75so296635276.0 for ; Tue, 07 Nov 2023 18:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699410460; x=1700015260; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fjSw5yMl7Zaa3WfnbuzU7Ubg5vKwHRFX37791b+j1Dg=; b=o7CsKyGSxOpTDdFkIJwH71y9b4XkH/VOQPKrVtsHv2drdvXm1PTy695u3fblFpByx9 CMLSzvQVLHBTTOTF6Bg8vmDIbDsjMR37C/Qt6UoLxYtHH3baTDPTCQvxIFMTjlmNJBdF Uf3gnK+BM4WIV0XZLGtzueMffaf9H6CJkGteFaKGT5Cvn4Bsk5KwlDkWNEiISvJSvv7l EjIAwrT9Z6fwOvyXEybIjEO5qWTRE9eXsKsdhXXfol+8r/EuPSKorf2oV1OH2eKn2B7S UMbaBc32en/35JH4feYpoiLFhIDxHQq4k4qJZNIw1zx+/wkQT4G1i5MsU0KsWEtFTT/S ax6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699410460; x=1700015260; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fjSw5yMl7Zaa3WfnbuzU7Ubg5vKwHRFX37791b+j1Dg=; b=W3HWI9x/oNNRqV3RMqgZXH1hrNoM+PHBQ+zHCY5NbKpCAnMaud6BqZGhjIv4JlQPRA BgjT8lkbKO12FXK/80QOHNeltt5jwwIP4BoNI3MbclmAlR+seo5++IZQYYpsNw7J4CBg shUlqeLJnEjxNpU4id7W19WyhJ2dS1WgzkrrOiaGSg0APZwqFPeX3hQIvWrz3UJdhIHS jdlTk9Zfhn6WZjSQFrULsKFri9kLgoiXeC/oo/7x+STQMxtmCze8ElF8cGJvmiy4DejK yteJLniyfQGcOz+D6vM89nfRmIWMZErVduIFzuLFUP41NLHwBobeHdjBcvM6Y8eBGwWe Talg== X-Gm-Message-State: AOJu0Yx0e+B0LI0twRVXWroVBTnwTHE9p7HboET4SDIWm9PfZHaZPDaz PnkJ5IG1rAXJV5iDDmZ0E3mzucz1XxUc X-Google-Smtp-Source: AGHT+IHldxiMAIxZ5HAkJMuR1XTXLNZhYZ7h25Ivz/3x1GBY7LjNMDFpllxOewqbgHrqtaVX0ZmrznabXIJi X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a25:5d1:0:b0:d9c:f811:eb9e with SMTP id 200-20020a2505d1000000b00d9cf811eb9emr10751ybf.4.1699410460764; Tue, 07 Nov 2023 18:27:40 -0800 (PST) Date: Wed, 8 Nov 2023 02:26:24 +0000 In-Reply-To: <20231108022651.645950-2-mmaurer@google.com> Mime-Version: 1.0 References: <20231108022651.645950-2-mmaurer@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231108022651.645950-5-mmaurer@google.com> Subject: [PATCH 2/3] kconfig: Add special rust_modules config option From: Matthew Maurer To: Masahiro Yamada , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho Cc: linux-kbuild@vger.kernel.org, Matthew Maurer , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Adds support for the rust_modules kconfig type, which works similarly to modules, but for restricting or allowing the use of modules which directly depend on Rust. Signed-off-by: Matthew Maurer --- scripts/kconfig/confdata.c | 3 +++ scripts/kconfig/expr.h | 1 + scripts/kconfig/lexer.l | 1 + scripts/kconfig/lkc.h | 1 + scripts/kconfig/menu.c | 7 +++++-- scripts/kconfig/parser.y | 12 ++++++++++++ scripts/kconfig/symbol.c | 31 +++++++++++++++++++++++++++++-- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 4a6811d77d18..f5e2dcb56e1c 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -549,10 +549,12 @@ int conf_read(const char *name) if (conf_read_simple(name, S_DEF_USER)) { sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); return 1; } sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); for_all_symbols(i, sym) { sym_calc_value(sym); @@ -1090,6 +1092,7 @@ static int conf_touch_deps(void) conf_read_simple(name, S_DEF_AUTO); sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); for_all_symbols(i, sym) { sym_calc_value(sym); diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index edfe3046d050..6b576fbc330e 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -283,6 +283,7 @@ struct file *lookup_file(const char *name); extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; +extern struct symbol *modules_rust_sym; extern int cdebug; struct expr *expr_alloc_symbol(struct symbol *sym); struct expr *expr_alloc_one(enum expr_type type, struct expr *ce); diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index cc386e443683..d6c7fd11f07e 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -114,6 +114,7 @@ n [A-Za-z0-9_-] "optional" return T_OPTIONAL; "prompt" return T_PROMPT; "range" return T_RANGE; +"rust_modules" return T_MODULES_RUST; "select" return T_SELECT; "source" return T_SOURCE; "string" return T_STRING; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 471a59acecec..ea97ff25909e 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -108,6 +108,7 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help); /* symbol.c */ void sym_clear_all_valid(void); struct symbol *sym_choice_default(struct symbol *sym); +bool sym_depends_rust(struct symbol *sym); struct property *sym_get_range_prop(struct symbol *sym); const char *sym_get_string_default(struct symbol *sym); struct symbol *sym_check_deps(struct symbol *sym); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index d5898cd6aeb8..10a115f3a450 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -96,8 +96,11 @@ static struct expr *rewrite_m(struct expr *e) break; case E_SYMBOL: /* change 'm' into 'm' && MODULES */ - if (e->left.sym == &symbol_mod) - return expr_alloc_and(e, expr_alloc_symbol(modules_sym)); + if (e->left.sym == &symbol_mod) { + if (sym_depends_rust(e->left.sym)) + e = expr_alloc_and(e, expr_alloc_symbol(modules_rust_sym)); + e = expr_alloc_and(e, expr_alloc_symbol(modules_sym)); + } break; default: break; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 2af7ce4e1531..37d9e390f545 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -68,6 +68,7 @@ struct menu *current_menu, *current_entry; %token T_MENU %token T_MENUCONFIG %token T_MODULES +%token T_MODULES_RUST %token T_ON %token T_OPEN_PAREN %token T_OPTIONAL @@ -224,6 +225,15 @@ config_option: T_MODULES T_EOL modules_sym = current_entry->sym; }; +config_option: T_MODULES_RUST T_EOL +{ + if (modules_rust_sym) + zconf_error("symbol '%s' redefines option 'rust_modules' already defined by symbol '%s'", + current_entry->sym->name, modules_rust_sym->name); + modules_rust_sym = current_entry->sym; +}; + + /* choice entry */ choice: T_CHOICE word_opt T_EOL @@ -495,6 +505,8 @@ void conf_parse(const char *name) exit(1); if (!modules_sym) modules_sym = sym_find( "n" ); + if (!modules_rust_sym) + modules_rust_sym = sym_find( "n" ); if (!menu_has_prompt(&rootmenu)) { current_entry = &rootmenu; diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 0572330bf8a7..d48fbde936d1 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -38,6 +38,18 @@ static struct symbol symbol_empty = { struct symbol *modules_sym; static tristate modules_val; +struct symbol *modules_rust_sym; +static tristate modules_rust_val; + +bool sym_depends_rust(struct symbol *sym) +{ + static struct symbol *rust_sym; + + if (!rust_sym) + rust_sym = sym_find("RUST"); + return expr_depends_symbol(sym->dir_dep.expr, rust_sym, true); +} + enum symbol_type sym_get_type(struct symbol *sym) { enum symbol_type type = sym->type; @@ -47,6 +59,8 @@ enum symbol_type sym_get_type(struct symbol *sym) type = S_BOOLEAN; else if (modules_val == no) type = S_BOOLEAN; + else if ((modules_rust_val == no) && sym_depends_rust(sym)) + type = S_BOOLEAN; } return type; } @@ -443,6 +457,10 @@ void sym_calc_value(struct symbol *sym) sym_set_all_changed(); modules_val = modules_sym->curr.tri; } + if (modules_rust_sym == sym) { + sym_set_all_changed(); + modules_rust_val = modules_rust_sym->curr.tri; + } } if (sym_is_choice(sym)) { @@ -474,6 +492,7 @@ void sym_clear_all_valid(void) sym->flags &= ~SYMBOL_VALID; conf_set_changed(true); sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); } bool sym_tristate_within_range(struct symbol *sym, tristate val) @@ -704,6 +723,7 @@ const char *sym_get_string_default(struct symbol *sym) sym_calc_visibility(sym); sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); val = symbol_no.curr.tri; str = symbol_empty.curr.val; @@ -734,9 +754,12 @@ const char *sym_get_string_default(struct symbol *sym) val = EXPR_OR(val, sym->rev_dep.tri); /* transpose mod to yes if modules are not enabled */ - if (val == mod) - if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no) + if ((val == mod) && !sym_is_choice_value(sym)) { + if (modules_sym->curr.tri == no) + val = yes; + if ((modules_rust_sym->curr.tri == no) && sym_depends_rust(sym)) val = yes; + } /* transpose mod to yes if type is bool */ if (sym->type == S_BOOLEAN && val == mod) @@ -778,7 +801,11 @@ const char *sym_get_string_value(struct symbol *sym) return "n"; case mod: sym_calc_value(modules_sym); + sym_calc_value(modules_rust_sym); + if (sym_depends_rust(sym)) + return (modules_rust_sym->curr.tri == no) ? "n" : "m"; return (modules_sym->curr.tri == no) ? "n" : "m"; + case yes: return "y"; } From patchwork Wed Nov 8 02:26:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13449530 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F5FFC4332F for ; Wed, 8 Nov 2023 02:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbjKHC16 (ORCPT ); Tue, 7 Nov 2023 21:27:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjKHC15 (ORCPT ); Tue, 7 Nov 2023 21:27:57 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4FE8181 for ; Tue, 7 Nov 2023 18:27:54 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb79eb417so6474500276.2 for ; Tue, 07 Nov 2023 18:27:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699410474; x=1700015274; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=j+pXCzJsltO32Q6Q6QKytaM4r4O4ehr4GGX/b31TdaA=; b=sCmUhvrNpDzPvwfh8RXHn+9yWDq50A6xSMsWdxAJI7IiczvMBtv0jmW5ILjOzLbW5P Gw1dXMLJmyeUFBF23SORgYdvH8k2tg6IF7fr0oZk7oB2oADwupiVqg4ZwreU4UCCZpi3 vw3hkSdyklMFS+h21jiab7GCp5cuft82X8W+PJ3Th6GrhXKDi4T8nQe0+ESwGZurE6Ep kwX14C40DYRgu/QC28UQktSn7MiWKJETWqVyYRNNqJhXUcWAUCIVZ76vK8UoXwtVOSuQ pZ+FOy5DYKvDKTkakDE0wAfrwiIceAro0CGzULyIuDi4R4YeuXIJ3ixTsSoT+3Bmq/te CdUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699410474; x=1700015274; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j+pXCzJsltO32Q6Q6QKytaM4r4O4ehr4GGX/b31TdaA=; b=aXVKfd9bp1YyAU5NViOQGQiwWxCpUQtKF6wJInaSZQleyYKYQdR2NCKr1Qq9sOnhnd qR7jPziJqX7Bxp807XaB+CAfcIEWJuMvIfjPeXmX3/Xi6+VnFzyzsDRwBgx1LR8kQb2Q MhZnAwW205scA04Pwcu7qGDjCJsEdsi5QVbQFdxMMNvwfx17dEjOPka7KOXTmKcnX5i7 sxcgiciOefMcjm9FCbFFMFpqD/CIxAGRY/DV3nt8i1LV5bCYPP7Nzke3p+p4wdKHGp8C rImtX04KQ/rLsR7+k9xElgzMrCgOeEn0wwCzFLlTnjHP/52BWpj6RrcmARitizqifLJ1 Ud7g== X-Gm-Message-State: AOJu0YxjyafnERdxKNtU2zH/RyNg4oz3k5aMnC659HyVMLjiqSYWY4PY KX+raxkvbNYvh6/HSw+albOME8X2S960 X-Google-Smtp-Source: AGHT+IEStJ9CSqrdAUJC0EXXJkXE33qO2K7wb06zQcU3w37tWljEEI+W9gKdDO6RYrRaincap25EZASrHFME X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:6902:102:b0:da3:723b:b2a4 with SMTP id o2-20020a056902010200b00da3723bb2a4mr8048ybh.7.1699410474120; Tue, 07 Nov 2023 18:27:54 -0800 (PST) Date: Wed, 8 Nov 2023 02:26:25 +0000 In-Reply-To: <20231108022651.645950-2-mmaurer@google.com> Mime-Version: 1.0 References: <20231108022651.645950-2-mmaurer@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231108022651.645950-6-mmaurer@google.com> Subject: [PATCH 3/3] rust: Require RUST_MODULES for module support From: Matthew Maurer To: Masahiro Yamada , Luis Chamberlain , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Andrew Morton , "Masami Hiramatsu (Google)" , "Paul E. McKenney" , John Ogness , Randy Dunlap , Matthew Maurer , Zhen Lei , Nhat Pham , Greg Kroah-Hartman , " =?utf-8?q?Marc_Aur=C3=A8?= =?utf-8?q?le_La_France?= " Cc: linux-kbuild@vger.kernel.org, Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Alice Ryhl , Nick Desaulniers , linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Currently, we don't support MODVERSIONS for Rust symbols. For users that want to use Rust in the kernel but for whom MODVERSIONS is required, this allows the use of built-in Rust code even with MODVERSIONS enabled. It may additionally allow code-size reduction by avoiding exporting symbols that won't be used without Rust modules. Signed-off-by: Matthew Maurer --- init/Kconfig | 21 +++++++++++++++++---- kernel/module/Kconfig | 1 + rust/exports.c | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 9ffb103fc927..6912dbbee3f1 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1885,7 +1885,6 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE @@ -1896,13 +1895,27 @@ config RUST This allows other Rust-related options, like drivers written in Rust, to be selected. - It is also required to be able to load external kernel modules - written in Rust. - See Documentation/rust/ for more information. If unsure, say N. +config RUST_MODULES + bool "Rust Module Support" + depends on RUST + depends on MODULES + rust_modules + help + Enables support for Rust Modules in the kernel. + + This is required to load external kernel modules written in Rust. + + The two primary reasons to consider disabling this are: + * Allow MODVERSIONS support + * Allow additional code to be optimized out by the compiler if you + know that you'll only be using built-in Rust code. + + If unsure, say Y. + config RUSTC_VERSION_TEXT string depends on RUST diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index 0ea1b2970a23..a76128887618 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -158,6 +158,7 @@ config MODULE_UNLOAD_TAINT_TRACKING shown. If unsure, say N. config MODVERSIONS + depends on !RUST_MODULES bool "Module versioning support" help Usually, you have to use modules compiled with your kernel. diff --git a/rust/exports.c b/rust/exports.c index 83e2a7070cae..96b706048ed4 100644 --- a/rust/exports.c +++ b/rust/exports.c @@ -13,7 +13,11 @@ #include +#ifdef CONFIG_RUST_MODULES #define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym) +#else +#define EXPORT_SYMBOL_RUST_GPL(sym) +#endif #include "exports_core_generated.h" #include "exports_alloc_generated.h"