Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id E06B410E012 for ; Fri, 1 Apr 2022 20:12:32 +0000 (UTC) Date: Fri, 01 Apr 2022 13:12:19 -0700 Message-ID: <87ilrsh8bg.wl-ashutosh.dixit@intel.com> From: "Dixit, Ashutosh" To: Daniele Ceraolo Spurio In-Reply-To: <20220401182229.3308644-2-daniele.ceraolospurio@intel.com> References: <20220401182229.3308644-1-daniele.ceraolospurio@intel.com> <20220401182229.3308644-2-daniele.ceraolospurio@intel.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Subject: Re: [igt-dev] [PATCH i-g-t v2 1/2] lib/igt_kmod: Wait for a kmod to finish its probe before unloding it. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: On Fri, 01 Apr 2022 11:22:28 -0700, Daniele Ceraolo Spurio wrote: > > Modprobing i915 can result in other dependent modules being loaded > automatically as a follow up. This means that by the time the i915 > load function returns these modules may still be going through their > init, so if we try to immediately unload i915 again we will fail with > an -EBUSY. To avoid this, if the module load is still in progress, wait > for it to complete before unloading. > > v2: move the wait to igt_kmod_unload_r (Ashutosh) Reviewed-by: Ashutosh Dixit > Signed-off-by: Daniele Ceraolo Spurio > Cc: Ashutosh Dixit > --- > lib/igt_kmod.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c > index cf7a3b22..0e3ca9b3 100644 > --- a/lib/igt_kmod.c > +++ b/lib/igt_kmod.c > @@ -143,6 +143,12 @@ out: > return ret; > } > > +static bool > +igt_kmod_is_loading(struct kmod_module *kmod) > +{ > + return kmod_module_get_initstate(kmod) == KMOD_MODULE_COMING; > +} > + > static int modprobe(struct kmod_module *kmod, const char *options) > { > unsigned int flags; > @@ -261,6 +267,17 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) > if (err < 0) > return err; > > + if (igt_kmod_is_loading(kmod)) { > + const char *mod_name = kmod_module_get_name(kmod); > + igt_debug("%s still initializing\n", mod_name); > + err = igt_wait(!igt_kmod_is_loading(kmod), 10000, 100); > + if (err < 0) { > + igt_debug("%s failed to complete init within the timeout\n", > + mod_name); > + return err; > + } > + } > + > return kmod_module_remove_module(kmod, flags); > } > > -- > 2.25.1 >