Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5990836rwp; Mon, 17 Jul 2023 12:55:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRUHmUnOgw2jh/fFiOdeyBqPDxtPqwBsHOoR7q2Z2s+iX9ePH/SZU1NwlxQByw11987kPo X-Received: by 2002:a17:906:8a78:b0:991:d2a8:658a with SMTP id hy24-20020a1709068a7800b00991d2a8658amr11552890ejc.34.1689623713338; Mon, 17 Jul 2023 12:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689623713; cv=none; d=google.com; s=arc-20160816; b=kQm7HTiDva4MXkJBvgxPtFf54q1N7saZPofoqvntY6Shy7C9KWCEX+S6u2bjNymQ+m jEFJL43dV8OLndARdS6pGaeS4S0PWMNxS/yvZgUJljv9TAn0W7eTevslRg4tUYytvQSL EPDmUFP5pGz0UROIQP/L6uGLvkL+m3ezh1/m0TwQnh+olRXF2hTWvJmauex4O9Dod6Nv iIpYmJ1c/MbFubDyDNuLKjHjBvxZdVgiJu/9qqoSh+pV3mk8kMfWMyfO+hVWNpIsH+6z KvhVYbr0au096Bnj+/cDbn5bn/lHVWM09vZv4Ed+DFnau2kBgHCw7L+no6v9jmSjHCiT NEjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+cytCEsh6gzundo6i/C5zNkgfffdz6tPbcyoKNbIHfk=; fh=BR/fONzGW3sKmUS525jnTRALfcRPvNYRQVS3/Baqt9w=; b=XyJQhicbXu/hQoNnYkZKpHOK1b2PeI8suphR6gqnKEITy1LETHELUBX0jMxU+TRsoq XzvsLoc6/9cwdueXxJLb8ln8g7WpbRt9HctBXgT9QbtrMSMacb44uAfPW+whdvmpdmjv FWM70nUDxqbMpRTEkv/lMxQWUfGGRmiB+Pe/EQbZSPdxiOR0YyvZjLBNyQMTMbcpg5wc Fqi/1ychBNXCwc3EKPTzqT8ay8yX7rOl616yP8EcXryHlJkk4X8pyp4va9Na0Jhi2YGn c6+x3lXDUdWGHuGD+obtTpw5qq24DW4Lkhvzm2NJ36yCBgeiFeByouAfOIwDZoHxeAWg 5Qbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ujy8hekg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gf1-20020a170906e20100b009931f44c716si90032ejb.219.2023.07.17.12.54.48; Mon, 17 Jul 2023 12:55:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ujy8hekg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231138AbjGQTO4 (ORCPT + 99 others); Mon, 17 Jul 2023 15:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjGQTOy (ORCPT ); Mon, 17 Jul 2023 15:14:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D30131B5; Mon, 17 Jul 2023 12:14:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6F60A6121D; Mon, 17 Jul 2023 19:14:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4496C433C7; Mon, 17 Jul 2023 19:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689621288; bh=OsEawghtwBT7iv0WttprK9jGHSbrsVJ0XtLmVa+47/0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Ujy8hekg6gGk+ORsAunzZjMH1evFq4VFlhQ1JqC+2nc/JTFmOfQnH8NnX2ri1e40c XCem618cdbTu7xyYob4gbLyo1Cf5tZ4PCm2KOU3ZWhS0RgDGw8syDe4HggMFUzIl7p AuKDXGshC/7qciwLpXQuBC7z+bLjbg3TvTufZSbpqOg1+p7eaxE4+EUJObPXZSsL77 ofL3CNNWRuQvcBEXNQYUAMd6bM2mXZkNeAf2xXcU23gJgl+19yel0MoTd71siVWRd9 YwSV7YwYKok/FnO7FkUFpsyaoSXQOLgfrhYXZgbZZJs0I/VInIEFdSolplXCkS/7gy u2POxeRliOLDw== Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-1b049163c93so2795368fac.3; Mon, 17 Jul 2023 12:14:48 -0700 (PDT) X-Gm-Message-State: ABy/qLa7wvD5gCCBNtaLsqcoX/M7IaT5IMEpcI/KKc9LxqanPb1bpb4D rGdZWskD6XxXTx6kny//VAlTj+UKr8HSk2Bdy1g= X-Received: by 2002:a05:6870:2197:b0:195:f0bb:959e with SMTP id l23-20020a056870219700b00195f0bb959emr13676591oae.50.1689621288074; Mon, 17 Jul 2023 12:14:48 -0700 (PDT) MIME-Version: 1.0 References: <20230714143002.GL9196@kitsune.suse.cz> <20230714151042.GN9196@kitsune.suse.cz> In-Reply-To: <20230714151042.GN9196@kitsune.suse.cz> From: Masahiro Yamada Date: Tue, 18 Jul 2023 04:14:11 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] depmod: Handle installing modules under a prefix To: =?UTF-8?Q?Michal_Such=C3=A1nek?= Cc: Nicolas Schier , linux-modules@vger.kernel.org, Takashi Iwai , Lucas De Marchi , =?UTF-8?B?TWljaGFsIEtvdXRu77+9?= , Jiri Slaby , Jan Engelhardt , Nathan Chancellor , Nick Desaulniers , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 15, 2023 at 12:10=E2=80=AFAM Michal Such=C3=A1nek wrote: > > On Fri, Jul 14, 2023 at 04:54:49PM +0200, Nicolas Schier wrote: > > On Fri, Jul 14, 2023 at 04:30:02PM +0200, Michal Such=EF=BF=BDnek wrote= : > > > Hello, > > > > > > On Fri, Jul 14, 2023 at 04:05:10PM +0200, Nicolas Schier wrote: > > > > On Fri, Jul 14, 2023 at 02:21:08PM +0200 Michal Suchanek wrote: > > > > > Some distributions aim at not shipping any files in / outside of = usr. > > > > > > > > For me, preventing negation often makes things easier, e.g.: "... a= im at > > > > shipping files only below /usr". > > > > > > > > > > > > > > The path under which kernel modules are installed is hardcoded to= /lib > > > > > which conflicts with this goal. > > > > > > > > > > When kmod provides the config command, use it to determine the co= rrect > > > > > module installation prefix. > > > > > > > > > > This is a prefix under which the modules are searched by kmod on = the > > > > > system, and is separate from the temporary staging location alrea= dy > > > > > supported by INSTALL_MOD_PATH. > > > > > > > > > > With kmod that does not provide the config command empty prefix i= s used > > > > > as before. > > > > > > > > > > Signed-off-by: Michal Suchanek > > > > > --- > > > > > v2: Avoid error on systems with kmod that does not support config > > > > > command > > > > > v3: More verbose commit message > > > > > --- > > > > > Makefile | 4 +++- > > > > > scripts/depmod.sh | 8 ++++---- > > > > > 2 files changed, 7 insertions(+), 5 deletions(-) > > > > > > > > > > diff --git a/Makefile b/Makefile > > > > > index 47690c28456a..b1fea135bdec 100644 > > > > > --- a/Makefile > > > > > +++ b/Makefile > > > > > @@ -1165,7 +1165,9 @@ export INSTALL_DTBS_PATH ?=3D $(INSTALL_PAT= H)/dtbs/$(KERNELRELEASE) > > > > > # makefile but the argument can be passed to make if needed. > > > > > # > > > > > > > > > > -MODLIB =3D $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) > > > > > +export KERNEL_MODULE_PREFIX :=3D $(shell kmod config &> /dev/nul= l && kmod config | jq -r .module_prefix) > > > > > > > > All other calls of `jq` that I could find are located at tools/; as= this here > > > > is evaluated on each invocation, this should probably be documented= in > > > > Documentation/process/changes.rst? > > > > > > > > (Absence of `jq` will cause error messages, even with CONFIG_MODULE= S=3Dn.) > > > > > > That's a good point. > > > > > > > > > > > > + > > > > > +MODLIB =3D $(INSTALL_MOD_PATH)$(KERNEL_MODULE_PREFIX)/lib/module= s/$(KERNELRELEASE) > > > > > export MODLIB > > > > > > > > > > PHONY +=3D prepare0 > > > > > diff --git a/scripts/depmod.sh b/scripts/depmod.sh > > > > > index 3643b4f896ed..88ac79056153 100755 > > > > > --- a/scripts/depmod.sh > > > > > +++ b/scripts/depmod.sh > > > > > @@ -27,16 +27,16 @@ fi > > > > > # numbers, so we cheat with a symlink here > > > > > depmod_hack_needed=3Dtrue > > > > > tmp_dir=3D$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) > > > > > -mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" > > > > > +mkdir -p "$tmp_dir$KERNEL_MODULE_PREFIX/lib/modules/$KERNELRELEA= SE" > > > > > if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then > > > > > - if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.d= ep" -o \ > > > > > - -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.d= ep.bin"; then > > > > > + if test -e "$tmp_dir$KERNEL_MODULE_PREFIX/lib/modules/$KE= RNELRELEASE/modules.dep" -o \ > > > > > + -e "$tmp_dir$KERNEL_MODULE_PREFIX/lib/modules/$KE= RNELRELEASE/modules.dep.bin"; then > > > > > depmod_hack_needed=3Dfalse > > > > > fi > > > > > fi > > > > > > > > I'd like to come back to the statement from Masahiro: Is the check = above, > > > > against some very old versions of depmod [1], the only reason for t= his patch? > > > > > > > > If we could remove that, would > > > > > > > > make INSTALL_MOD_PATH=3D"$(kmod config | jq -r .module_prefix)"= modules_install > > > > > > > > be sufficient? > > > > > > No, the INSTALL_MOD_PATH is passed as the -b argument to depmod while > > > the newly added part is not because it's integral part of where the > > > modules are installed on the system, and not the staging area path. > > > > Ah, thanks. So just for my understanding, could this be a (non-gentle) > > alternative version of your patch, w/o modifying top-level Makefile? > > > > diff --git a/scripts/depmod.sh b/scripts/depmod.sh > > index 3643b4f896ed..72c819de0669 100755 > > --- a/scripts/depmod.sh > > +++ b/scripts/depmod.sh > > @@ -1,4 +1,4 @@ > > -#!/bin/sh > > +#!/bin/bash > > # SPDX-License-Identifier: GPL-2.0 > > # > > # A depmod wrapper used by the toplevel Makefile > > @@ -23,6 +23,8 @@ if [ -z $(command -v $DEPMOD) ]; then > > exit 0 > > fi > > > > +kmod_version=3D$(( $(kmod --version | sed -rne 's/^kmod version ([0-9]= +).*$/\1/p') )) > > + > > # older versions of depmod require the version string to start with th= ree > > # numbers, so we cheat with a symlink here > > depmod_hack_needed=3Dtrue > > @@ -35,6 +37,13 @@ if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/nul= l; then > > fi > > fi > > rm -rf "$tmp_dir" > > + > > +if [ "${kmod_version}" -gt 32 ]; then > > + kmod_prefix=3D"$(kmod config | jq -r .module_prefix)" > > + INSTALL_MOD_PATH=3D"${INSTALL_MOD_PATH#${kmod_prefix}" > > + depmod_hack_needed=3Dfalse > > +fi > > + > > if $depmod_hack_needed; then > > symlink=3D"$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" > > ln -s "$KERNELRELEASE" "$symlink" > > > > (untested, and assuming that kmod module prefix is in kmod >=3D 32) > > It can be detected by running the 'kmod config' command first and > ignoring the output when it fails which the above patch already did. > The version check does not sound very reliable. > > > Or are I am still missing something? > > MODLIB still needs to include the extra prefix so that files are > installed in the correct location. And that's defined in the toplevel > Makefile. > > Thanks > > Michal As Documentation/kbuild/kbuild.rst mentions, you can override MODLIB. Kbuild already provides the maximum flexibility. $ make modules_install \ INSTALL_MOD_PATH=3D/path/to/whatever/staging/dir \ MODLIB=3D/path/to/whatever/real/install/destination --=20 Best Regards Masahiro Yamada