Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3124513rwb; Mon, 15 Aug 2022 18:44:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5lqmO2yAhcmnkWMnO/usZXsQTxaoc/DvmvrK3CNMz2odZ/qMh69+0hG5fO9d/ektt0tcVf X-Received: by 2002:a17:906:5a71:b0:730:aaa1:a9ec with SMTP id my49-20020a1709065a7100b00730aaa1a9ecmr11876188ejc.440.1660614258206; Mon, 15 Aug 2022 18:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614258; cv=none; d=google.com; s=arc-20160816; b=u23I8PPl8zIcsDMsBHaHGnZ0pBfdME4F7Lnhe6i54AbGLrJqfmJhoEio56/v/oJ3mJ 4FaL/VwCGsNKUJfb+2gmA2fehrvWZdaSjikb0xrdff8Azne4TjKyIq9kbhbfxJzP98b0 1uNQcljg2NI/awPSqmbWcfWGsQOVLkm62vj/O8s1IUpdryV/44HSRjelsyn8aqlgdy+v FxwS5Pcz0LQ19WT5+X3RqF/J0NhPWEjVYJFvuJNtN3rKW877+OvjJrgcVlnMytduIeFy BEct6OYjpDU4nu9AXVZUOQWL5TGniSWhQQKUloylsOojter+f9qFGuzFUH7QO7KB2GRM 7W+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bhOjpSryr7fJeXLT7oFOufFdxUvIdUPsty0UiyIgltc=; b=yfuwtJ2tSqKEkYNrNA7AFsMj3/sk0SylCA4GFJmkKSvLkTRiXJCQqxw+qkRsVgntTq Z5dM60S5Y6sPHq8O+0Q+WddsgsKtWhfIRvTqqN0dZQUZSxghDHofZA3caYomgvAMbdoR +mM8dTn0t3eeAM478XBwgWJNR71foLJgCQL7WSH9IHHBlpXaqp9+diZ0gPEIyJh46jTi HPKZSYjNy0JAeMwGyjWSaVCQ+9yLP/1Hc2Xj02ahFhceBgkNIB6hWRB2a4Yv+KwVKcEn JxO/QBXEjrcL9HtRaEMfN/RbsAYkPWZv7DL1uVo6IzZWi/briaIoSBvBBmGvC5aofFJM JIvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2HNUN8u4; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a056402274700b0043d552deb37si9625998edd.14.2022.08.15.18.43.52; Mon, 15 Aug 2022 18:44:18 -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=@linuxfoundation.org header.s=korg header.b=2HNUN8u4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344926AbiHPAjZ (ORCPT + 99 others); Mon, 15 Aug 2022 20:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345152AbiHPAh0 (ORCPT ); Mon, 15 Aug 2022 20:37:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD9DB520AF; Mon, 15 Aug 2022 13:38:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DCFEBB80EA8; Mon, 15 Aug 2022 20:38:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BA94C433D6; Mon, 15 Aug 2022 20:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595897; bh=8hDBdMDPvbcd9tHee3CoHzdJ9KzK5YiVA0P4PEbm/ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2HNUN8u4qbuKCy484ndcVNz6MyJ+4wHB5oo0oXDWp0d8OvLxY0bhHRpjDfctasqop 3WR/yDFP8cFCcK41ko8reAhLZENYb5f6f0zLXHDupRdSVUeWEDLQRue8eTYTN0/iAp kJX6kQPTR6LC1mRNdiPsU7Rq3ooHi4tI+hUIDZ3k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joe Lawrence , Petr Mladek , Sasha Levin Subject: [PATCH 5.19 0910/1157] selftests/livepatch: better synchronize test_klp_callbacks_busy Date: Mon, 15 Aug 2022 20:04:26 +0200 Message-Id: <20220815180515.861770148@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 From: Joe Lawrence [ Upstream commit 55eb9a6c8bf3e2099863118ef53e02d9f44f85a8 ] The test_klp_callbacks_busy module conditionally blocks a future livepatch transition by busy waiting inside its workqueue function, busymod_work_func(). After scheduling this work, a test livepatch is loaded, introducing the transition under test. Both events are marked in the kernel log for later verification, but there is no synchronization to ensure that busymod_work_func() logs its function entry message before subsequent selftest commands log their own messages. This can lead to a rare test failure due to unexpected ordering like: # --- expected # +++ result # @@ -1,7 +1,7 @@ # % modprobe test_klp_callbacks_busy block_transition=Y # test_klp_callbacks_busy: test_klp_callbacks_busy_init # -test_klp_callbacks_busy: busymod_work_func enter # % modprobe test_klp_callbacks_demo # +test_klp_callbacks_busy: busymod_work_func enter # livepatch: enabling patch 'test_klp_callbacks_demo' # livepatch: 'test_klp_callbacks_demo': initializing patching transition # test_klp_callbacks_demo: pre_patch_callback: vmlinux Force the module init function to wait until busymod_work_func() has started (and logged its message), before exiting to the next selftest steps. Fixes: 547840bd5ae5 ("selftests/livepatch: simplify test-klp-callbacks busy target tests") Signed-off-by: Joe Lawrence Reviewed-by: Petr Mladek Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/20220602203233.979681-1-joe.lawrence@redhat.com Signed-off-by: Sasha Levin --- lib/livepatch/test_klp_callbacks_busy.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/livepatch/test_klp_callbacks_busy.c b/lib/livepatch/test_klp_callbacks_busy.c index 7ac845f65be5..133929e0ce8f 100644 --- a/lib/livepatch/test_klp_callbacks_busy.c +++ b/lib/livepatch/test_klp_callbacks_busy.c @@ -16,10 +16,12 @@ MODULE_PARM_DESC(block_transition, "block_transition (default=false)"); static void busymod_work_func(struct work_struct *work); static DECLARE_WORK(work, busymod_work_func); +static DECLARE_COMPLETION(busymod_work_started); static void busymod_work_func(struct work_struct *work) { pr_info("%s enter\n", __func__); + complete(&busymod_work_started); while (READ_ONCE(block_transition)) { /* @@ -37,6 +39,12 @@ static int test_klp_callbacks_busy_init(void) pr_info("%s\n", __func__); schedule_work(&work); + /* + * To synchronize kernel messages, hold the init function from + * exiting until the work function's entry message has printed. + */ + wait_for_completion(&busymod_work_started); + if (!block_transition) { /* * Serialize output: print all messages from the work -- 2.35.1