Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2582675imm; Fri, 20 Jul 2018 00:55:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd1WWThzwDzz35V9uXo0jbDgklHL64x1YCXEzWyu7uCugSJRcrgn+395toKjAq6GruHlfTH X-Received: by 2002:a63:951e:: with SMTP id p30-v6mr1062789pgd.318.1532073358712; Fri, 20 Jul 2018 00:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532073358; cv=none; d=google.com; s=arc-20160816; b=Q6AlSk5pA5+lx8RWOj5qx+lv2mR7mEzl2dAtouklrJdIskUwXFQsV+F+orzuGPVBN7 tXv+EMrfbaSrvSolD5oTY0QyBE+Vghi8TTYbTnWStY7NXKrAidyBCihpiFH7sDdF50yd rIPtw7mr/2Fb2QrkJpjX73CXrVZKtNKA2B/gdVsr4ZASvWeOUR9HG8cz5q/Zq2IlKJfj pNo+vYPhkKFjO7tEithsL6sx/EO6ZUaittdDN33aK79kkfve78M+WtPWFMI+3blyGLuU m9MuZaNWs6nFBn2onK+Spd72GrTMkb2YcpjieG28gKswZ5q50frnYC5KWuS4f/2GP8OU 13bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=oAN6trz2IhsdIjzlVlbmg2q6MIgeblkWsmAneV3zPQM=; b=k8H+WpGKyKjDlT113TiVZmXUCAOc+ahTMI/P63GW8K+yATyekKK1JgQASljErtoo+e jwgmOu2JB5mxjg7dPo+FIjGnsVDICJm6VDVM6KNOeC33KGeY2FPqB42dASxAcdCYmwGo QrOmLBiG7P5nuBwnt2Bn/kRauTytDQUotm3kj2a3VYzB8yAD30C4gebjHYCxu8sHdJlm qr83TRg6umJMVtj/RluNhnAEreuiq/oAdeg5Bu8DRKX5yqhW31Y4nGEFofsQzyVTQvW9 n90V1LOoH9bNJPXwJVxcNjHlGi7bt8mlG6tGaggUUvCRZ2eT7r1eoxHZ2BGpKbW9nXuS 49yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=bKG+U0BI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o189-v6si1241629pga.577.2018.07.20.00.55.43; Fri, 20 Jul 2018 00:55:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=bKG+U0BI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727733AbeGTIlT (ORCPT + 99 others); Fri, 20 Jul 2018 04:41:19 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:37416 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727202AbeGTIlT (ORCPT ); Fri, 20 Jul 2018 04:41:19 -0400 Received: by mail-io0-f195.google.com with SMTP id z19-v6so9248307ioh.4 for ; Fri, 20 Jul 2018 00:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=oAN6trz2IhsdIjzlVlbmg2q6MIgeblkWsmAneV3zPQM=; b=bKG+U0BICI1Iaa+tBiMWTY7u3NZ1azlhOG+Bm6HNrdL/pzwSc7jpJdhgkDD7JoLW02 vDnRayqJqxQ1tPtsePuGJUApqxYrNuPD1IwwMDKI2m2q4rDpYM5rb4NVOBaSpS+ToDEZ ivXV+jpGnJ/AKrAuicv9bBqfVhvjjmYQFYdNBqn7vDUZSQuMa9ACZ1KYITqIRX8VTsih A3A+8zYnAwnqQAj9tw19jGtoBtduosx80pAXhhF74VpSZfvRg6qniGPQKraPRLT6VCb/ Rtwli+9DF00qZ1rDa8LGUuFMumteydswn5y/HvYRaRe3zxIV/BDJ1jn/7C8g9TTMDLWv 9AqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=oAN6trz2IhsdIjzlVlbmg2q6MIgeblkWsmAneV3zPQM=; b=UY70YihHGkqM+yulPQd9Vlt28+J7+2gtRHy3a1b5mtJddxSyRvzfk1DPQ1t4FSSKw6 blVELBKcLt8P1rwpCIggmCuqGsPkRPbbspWYwWyGTaKkb7EjDC7zuKcup6srotxoJpCq QTonek1NxS/l9A/B8tSzaim1vGLSQax9dgwhp25WF2VgcGadbuNRQWVZFrAmIn9lxoj8 UMlb+DDbeV+NX1SoAxeZVxy7eokmPK1uolqwIXKMf4Kuw7t/wV3UzCqxAjCELU6g5bMG hyeUatagIbUrr4lPB53cwGaSH6PB2kaiRoUXMqbINQA9njWWdfSu0T7OxUs+4GLcFXRY a44g== X-Gm-Message-State: AOUpUlHOVWVFCLVJr+9rK6fakHI8ishtjJe5nVQLnMvb59mjvl2BM3UH BcmQEAiQqdKoqSxocQzfMI7FiWpwTc795LHCZ6gdrw== X-Received: by 2002:a6b:1e52:: with SMTP id e79-v6mr742753ioe.110.1532073257512; Fri, 20 Jul 2018 00:54:17 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:bb58:0:0:0:0:0 with HTTP; Fri, 20 Jul 2018 00:54:16 -0700 (PDT) In-Reply-To: <20180719163208.5xvrafugpcbhh7kj@linux-8ccs> References: <20180716122125.175792-1-maco@android.com> <20180716122125.175792-3-maco@android.com> <20180719163208.5xvrafugpcbhh7kj@linux-8ccs> From: Martijn Coenen Date: Fri, 20 Jul 2018 09:54:16 +0200 Message-ID: Subject: Re: [PATCH 2/6] module: add support for symbol namespaces. To: Jessica Yu Cc: LKML , Masahiro Yamada , Michal Marek , Geert Uytterhoeven , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "the arch/x86 maintainers" , Alan Stern , Greg Kroah-Hartman , Oliver Neukum , Arnd Bergmann , Stephen Boyd , Philippe Ombredanne , Kate Stewart , Sam Ravnborg , linux-kbuild@vger.kernel.org, linux-m68k , USB list , USB Storage list , linux-scsi@vger.kernel.org, Linux-Arch , Martijn Coenen , Sandeep Patil , Iliyan Malchev , Joel Fernandes Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jessica, On Thu, Jul 19, 2018 at 6:32 PM, Jessica Yu wrote: > First, thanks a lot for the patchset. This is definitely something that > will help distros as well to declutter the exported symbol space and > provide a more cleanly defined kernel interface. Thanks, that's good to hear! > Hm, I'm wondering if we could avoid all this extra module-ns-dependency > checking work if we just put the import stuff as a modinfo tag, like > have MODULE_IMPORT_NS() insert an "import:" tag like we already do for > module parameters, author, license, aliases, etc. Then we'd have that > information pretty much from the start of load_module() and we don't > need to wait for relocations to be applied to __knsimport. Then you > could do the namespace checking right at resolve_symbol() instead of > going through the extra step of building a dependency list to be > verified later. I believe I did consider modinfo when I started with this a while back, but don't recall right now why I didn't decide to use it; perhaps it was the lack of support for multiple identical tags. Since both modpost and the module loader have access to them, I don't see why it wouldn't work, and indeed I suspect it would make the module loader a bit simpler. I'll rework this and see what it looks like. Thanks, Martijn > > Also, this would get rid of the extra __knsimport section, the extra > ns_dependencies field in struct module, and all those helper functions that > manage it. In addition, having the modinfo tag may potentially help with > debugging as we have the namespace imports clearly listed if we don't have > the source code for a module. We'd probably need to modify get_modinfo() to > handle multiple import: tags though. Luis [1] had written some code a while > ago to handle multiple (of the same) modinfo tags. > > Thoughts on this? > > Thanks, > > Jessica > > [1] https://lkml.kernel.org/r/20171130023605.29568-3-mcgrof@kernel.org > > >> getname: >> /* We must make copy under the lock if we failed to get ref. */ >> strncpy(ownername, module_name(owner), MODULE_NAME_LEN); >> @@ -3061,6 +3118,11 @@ static int find_module_sections(struct module *mod, >> struct load_info *info) >> sizeof(*mod->gpl_syms), >> &mod->num_gpl_syms); >> mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); >> + >> + mod->ns_imports = section_objs(info, "__knsimport", >> + sizeof(*mod->ns_imports), >> + &mod->num_ns_imports); >> + >> mod->gpl_future_syms = section_objs(info, >> "__ksymtab_gpl_future", >> sizeof(*mod->gpl_future_syms), >> @@ -3381,6 +3443,19 @@ static int post_relocation(struct module *mod, >> const struct load_info *info) >> return module_finalize(info->hdr, info->sechdrs, mod); >> } >> >> +static void verify_namespace_dependencies(struct module *mod) >> +{ >> + struct module_ns_dep *ns_dep; >> + >> + list_for_each_entry(ns_dep, &mod->ns_dependencies, ns_dep) { >> + if (!module_imports_ns(mod, ns_dep->namespace)) { >> + pr_warn("%s: module uses symbols from namespace >> %s," >> + " but does not import it.\n", >> + mod->name, ns_dep->namespace); >> + } >> + } >> +} >> + >> /* Is this module of this name done loading? No locks held. */ >> static bool finished_loading(const char *name) >> { >> @@ -3682,6 +3757,8 @@ static int load_module(struct load_info *info, const >> char __user *uargs, >> if (err) >> goto free_module; >> >> + INIT_LIST_HEAD(&mod->ns_dependencies); >> + >> #ifdef CONFIG_MODULE_SIG >> mod->sig_ok = info->sig_ok; >> if (!mod->sig_ok) { >> @@ -3730,6 +3807,8 @@ static int load_module(struct load_info *info, const >> char __user *uargs, >> if (err < 0) >> goto free_modinfo; >> >> + verify_namespace_dependencies(mod); >> + >> flush_module_icache(mod); >> >> /* Now copy in args */ >> -- >> 2.18.0.203.gfac676dfb9-goog >> >