From patchwork Wed Apr 1 21:22:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 11469553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7646B1392 for ; Wed, 1 Apr 2020 21:23:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CEFA20787 for ; Wed, 1 Apr 2020 21:23:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pgWU7I13" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732385AbgDAVXD (ORCPT ); Wed, 1 Apr 2020 17:23:03 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54111 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732357AbgDAVXD (ORCPT ); Wed, 1 Apr 2020 17:23:03 -0400 Received: by mail-wm1-f67.google.com with SMTP id d77so1279808wmd.3 for ; Wed, 01 Apr 2020 14:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:references:to:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=2zzLWXdpfOIS+Gm0CyRwUQB1dpscFF97orsW709AfXQ=; b=pgWU7I13VYFpWy0hU5EGJUAlnhosUXGehPoDUyaJWZMaOW1mqyWWF1fpBDDabFk/yt vrgilr7iAPfDHGhGsW54CCkemBIRbmcQKsPM4aKOKYlpYKsr/gCN8SGXWq8xYRtRAM/w 6zhizQdZoh1ZUHr6Hkzoqpa/10yEu+ytopKJk8qJltjWhqaEQGkClCt3YEAyKvFANQL/ nXh3osoz2wYCM7fuUtyGuy055ry0kFHpltFSZNDtPGZMy0Filh5GtIxn2L4LQrP0We60 IzOnDukKntplYa6ObXS36gvE1KYYOFLjD4sVql5U7z9TdeThn0Pm7O688T6t5B+rVoCH d8NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:to:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=2zzLWXdpfOIS+Gm0CyRwUQB1dpscFF97orsW709AfXQ=; b=gLRNTAbqqj1zAFzoVSv6YFvWznaDyYrzFPnfYdReArFxaSPRYoaqcyKbyr+MB7VXYi gYXuiXRlAPF7TPNXtcMx8FSnp4imGc73rraInqS/QTM0EQCQANZQCCNhUjccBsS7shR/ rJPDQnX0A+2jXdcn1DqZ4Q1rnvte+S0fep3kfl7x96y9vcLWqGG3uMwhLeunVVDHpMKB 2U36nlXfYtbSHXyZ6mrl1MsDDrSPllhdvlOcSKo11F4TO5oDDe1N9iy0NhGfAnXkHlFU WjPlia6w9W7tpxcRFnhpfFzMoInJr6PH/n7oM9mChjEvTFcc5gIanq3SMqGIhTuxKonm uykw== X-Gm-Message-State: AGi0PuZHjMMzeoOVNFDSyoeqE8dviNYLxAB4qHEofYZGIDWN52vz6sEO suMrK7Y9ttdCWpu3DuumjxJ2QOiW X-Google-Smtp-Source: APiQypJv3KYtF33Q7hLcsuJkQC1FDZfuV6QAhPOJlP+e/lhPELEvDPuZ/9txhQwQ6iVBsLVdMQB1+g== X-Received: by 2002:a1c:82:: with SMTP id 124mr317531wma.63.1585776179283; Wed, 01 Apr 2020 14:22:59 -0700 (PDT) Received: from ?IPv6:2003:ea:8f29:6000:3878:c820:d9e6:1e25? (p200300EA8F2960003878C820D9E61E25.dip0.t-ipconnect.de. [2003:ea:8f29:6000:3878:c820:d9e6:1e25]) by smtp.googlemail.com with ESMTPSA id y4sm4320067wrl.40.2020.04.01.14.22.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Apr 2020 14:22:58 -0700 (PDT) Subject: Fwd: RFC: Handle hard module dependencies that are not symbol-based (r8169 + realtek) References: To: linux-modules@vger.kernel.org From: Heiner Kallweit X-Forwarded-Message-Id: Message-ID: <92546e9f-db6e-ccc0-147d-f3692984d620@gmail.com> Date: Wed, 1 Apr 2020 23:22:53 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: Mistakenly sent it to linux-module instead of linux-modules. -------- Forwarded Message -------- Subject: RFC: Handle hard module dependencies that are not symbol-based (r8169 + realtek) Date: Wed, 1 Apr 2020 23:20:20 +0200 From: Heiner Kallweit To: Lucas De Marchi , Jessica Yu CC: Linux Kernel Mailing List , linux-module@vger.kernel.org, netdev@vger.kernel.org Currently we have no way to express a hard dependency that is not a symbol-based dependency (symbol defined in module A is used in module B). Use case: Network driver ND uses callbacks in the dedicated PHY driver DP for the integrated PHY (namely read_page() and write_page() in struct phy_driver). If DP can't be loaded (e.g. because ND is in initramfs but DP is not), then phylib will use the generic PHY driver GP. GP doesn't implement certain callbacks that are needed by ND, therefore ND's probe has to bail out with an error once it detects that DP is not loaded. We have this problem with driver r8169 having such a dependency on PHY driver realtek. Some distributions have tools for configuring initramfs that consider hard dependencies based on depmod output. Means so far somebody can add r8169.ko to initramfs, and neither human being nor machine will have an idea that realtek.ko needs to be added too. Attached patch set (two patches for kmod, one for the kernel) allows to express this hard dependency of ND from DP. depmod will read this dependency information and treat it like a symbol-based dependency. As a result tools e.g. populating initramfs can consider the dependency and place DP in initramfs if ND is in initramfs. On my system the patch set does the trick when adding following line to r8169_main.c: MODULE_HARDDEP("realtek"); I'm interested in your opinion on the patches, and whether you maybe have a better idea how to solve the problem. Heiner From 290e7dee9f6043d677f08dc06e612e13ee0d2d83 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Tue, 31 Mar 2020 23:02:47 +0200 Subject: [PATCH 1/2] depmod: add helper mod_add_dep_unique Create new helper mod_add_dep_unique(), next patch in this series will also make use of it. Signed-off-by: Heiner Kallweit --- tools/depmod.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index 875e314..5419d4d 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -907,23 +907,35 @@ static void mod_free(struct mod *mod) free(mod); } -static int mod_add_dependency(struct mod *mod, struct symbol *sym) +static int mod_add_dep_unique(struct mod *mod, struct mod *dep) { int err; - DBG("%s depends on %s %s\n", mod->path, sym->name, - sym->owner != NULL ? sym->owner->path : "(unknown)"); - - if (sym->owner == NULL) + if (dep == NULL) return 0; - err = array_append_unique(&mod->deps, sym->owner); + err = array_append_unique(&mod->deps, dep); if (err == -EEXIST) return 0; if (err < 0) return err; - sym->owner->users++; + dep->users++; + + return 1; +} + +static int mod_add_dependency(struct mod *mod, struct symbol *sym) +{ + int err; + + DBG("%s depends on %s %s\n", mod->path, sym->name, + sym->owner != NULL ? sym->owner->path : "(unknown)"); + + err = mod_add_dep_unique(mod, sym->owner); + if (err <= 0) + return err; + SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); return 0; }