Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2025476ybc; Wed, 13 Nov 2019 07:55:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxV386KSVplnaVOVWxyAu3LUx1MfKQPbheBM0tTG62qVUUiWA9xEpY+crvQ+zFId5pTr6Bx X-Received: by 2002:a50:ed12:: with SMTP id j18mr4461976eds.172.1573660539936; Wed, 13 Nov 2019 07:55:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573660539; cv=none; d=google.com; s=arc-20160816; b=nOoL9pDDx35c9Z0rKev478TG0tJVCILD5FwY8qAa9bMk2UA05+7PJp4XjgUC+oM5yI tcQcKNt3FD2zwByMlOAqSB6dqIv4CqqGeX5ZukGXILThYTGKJdahwFVsdsql2Efpo+wt C9jGOtdoqj7Nmdqx+Bwng4s3JzirPD7NuqDMx9DBA2ViuOH47esU6Uz0/tEsXuSDEF3k j+busIBajRBYHZTgTodcXkV2JKGUB082n2T134f+V3yUrZBwgWzSgtOZaLAtpO+DW5vA ADgUWwy4lo2g34Banm4Y6EV0gePBsOG0wsg/UL39yeQmpTg1k05YmFwqCniLL6o58m5I 95SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=I49FNaB31Xym/1989jEGjQsxSSpOY1GJbdRrHOQtTFg=; b=mr9DN/w2yvKhs/WG5zYRSneQFhENV1EXTfRBrsZZYVqjrXiJWKfwKQgR5W2APrRLrP XYS18CxmyXZQoJcpeFDhhbn9tdAk/IrD68JuUft8ifH/fPpN1/BgA+2ZsoQRTqkAJJJY tIhY1UZbWnGQJ5hdq0aG1EuBquq1WinhYOhJBbIwwuCjWkFAzoLAg58LtTqdrlFMGlST b4pURAhz0bmyPRv8Atw6bJpQ0LzAx5nsCO6nEvSMnc+oHaGd2UYTQj04fRPAbIF3K5NC bbnqIQ5Qllth89W+Hyv2eED5qqWD0gibzZssQtz6nBUjoredGqN82gPtxD9ysqEfIPdt HKsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bP02yBDH; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si1857195edc.403.2019.11.13.07.55.15; Wed, 13 Nov 2019 07:55:39 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=bP02yBDH; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727531AbfKMNvR (ORCPT + 99 others); Wed, 13 Nov 2019 08:51:17 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20459 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726957AbfKMNvQ (ORCPT ); Wed, 13 Nov 2019 08:51:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573653075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I49FNaB31Xym/1989jEGjQsxSSpOY1GJbdRrHOQtTFg=; b=bP02yBDH14GS59BXMp8LtszkANtMw6qTuB6j1+QRifAgRCA2vdSvTRjU6P3HOrfGiUHrU0 +Q4SzZ0/wPH6OmpM4oRergH1tNvBf4b8fWaiaZgtM11R76AngizLjNslTYr1RcgeI/Fnyu /BOGQgXvBbAjodb2hnF6rwYHEaWriE8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-jlrzj_9NMJ-s1OhMBC6-uw-1; Wed, 13 Nov 2019 08:51:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DC91B4144; Wed, 13 Nov 2019 13:51:10 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.khw1.lab.eng.bos.redhat.com [10.16.200.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91ED84D9E1; Wed, 13 Nov 2019 13:51:09 +0000 (UTC) Subject: Re: [PATCH 1/1] kernel/module.c: wakeup processes in module_wq on module unload To: Konstantin Khorenko , Jessica Yu , Barret Rhoden Cc: Andrey Ryabinin , linux-kernel@vger.kernel.org, David Arcari , Heiko Carstens References: <20191113092950.15556-1-khorenko@virtuozzo.com> <20191113092950.15556-2-khorenko@virtuozzo.com> From: Prarit Bhargava Message-ID: <1b047b83-e6cd-9c56-9c55-a2ef6a3e16f5@redhat.com> Date: Wed, 13 Nov 2019 08:51:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20191113092950.15556-2-khorenko@virtuozzo.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: jlrzj_9NMJ-s1OhMBC6-uw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/13/19 4:29 AM, Konstantin Khorenko wrote: > Fix the race between load and unload a kernel module. >=20 > sys_delete_module() > try_stop_module() > mod->state =3D _GOING > =09=09=09=09=09add_unformed_module() > =09=09=09=09=09 old =3D find_module_all() > =09=09=09=09=09 (old->state =3D=3D _GOING =3D> > =09=09=09=09=09 wait_event_interruptible()) >=20 > =09=09=09=09=09 During pre-condition > =09=09=09=09=09 finished_loading() rets 0 > =09=09=09=09=09 schedule() > =09=09=09=09=09 (never gets waken up later) > free_module() > mod->state =3D _UNFORMED > list_del_rcu(&mod->list) > (dels mod from "modules" list) >=20 > return >=20 > The race above leads to modprobe hanging forever on loading > a module. >=20 > Error paths on loading module call wake_up_all(&module_wq) after > freeing module, so let's do the same on straight module unload. >=20 > Fixes: 6e6de3dee51a ("kernel/module.c: Only return -EEXIST > for modules that have finished loading") >=20 > Signed-off-by: Konstantin Khorenko > --- > kernel/module.c | 2 ++ > 1 file changed, 2 insertions(+) >=20 > diff --git a/kernel/module.c b/kernel/module.c > index ff2d7359a418..cb09a5f37a5f 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -1033,6 +1033,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *,= name_user, > =09strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)= ); > =20 > =09free_module(mod); > +=09/* someone could wait for the module in add_unformed_module() */ > +=09wake_up_all(&module_wq); free_module() acts on that *this* module so it makes sense to include the wake_up_all(&module_wq) call in delete_module. IIRC I did try a module loa= d & unload stress test but it looks like my testing wasn't hard enough :( In any case, Reviewed-by: Prarit Bhargava P. > =09return 0; > out: > =09mutex_unlock(&module_mutex); >=20