Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864891rwb; Fri, 19 Aug 2022 10:39:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lsyL72Ma6Nh9DVjt7Wjj2qvufCe3f3/D/pveKA1n+S02x/6nYSAUbZwUu/86m3GhWXr7C X-Received: by 2002:a05:6402:518b:b0:43e:70be:97cd with SMTP id q11-20020a056402518b00b0043e70be97cdmr7025265edd.388.1660930797216; Fri, 19 Aug 2022 10:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930797; cv=none; d=google.com; s=arc-20160816; b=DGon1wypJ7+ELLJ/qW2cMNZtU3cG4eaTh+Hudlicakki5mAAUcMPC+Wekf9pk5l9Of I5W1htDHuc5Q45//U7+CydZ1MKxUXf4iIywQXKh6jtO/X4NloxqJwXc1HtRMDCI8pMoQ XIzvhspMy5UGNSokBEA8XVmLx7s+akahY9kfJ6z7EmSDTxAgvnDfWqEPzW7B694Gj/ej KluzSZBA4Cwp0lHZkTSTq0oyRXCpUWOpsIFOR7GW4p65GqZjWmneRBsfVE2wduzVBb1U ccGi9/S3VDgLB5RrPgtx+T7hks985rZjtdhO1jPXwI2gH+nYCpha0rdSfxkXQOeirE5l zYrg== 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=SZDCs8dhaJEyFCSH/IMX3wLwgGl4Sbyav3zT2nfqA68=; b=s2AhT1x3lRGJvt20EnBUpgIq6oLqJgavbP715jv0SwKoaNnUqWN0ZhSrH2umz6j8LH 4orUpkE3CPyoZGs1b/7213orDXcSyiDEBz75nQcB7xVejWl1QU8AqwlV5pptkTv4iyhV ypyB7YRoefL+vXd0Y6yLeiy4eDVaXhCxALDKSGYhFAGeoxT0tDVO1YPA2B5T/R2ZTOSy mD1TBue1wu5eikmO+u89zixLc+5J1Ax21qOd662ORD8O5nmGtqS8IWBHRkN6/ti+eHBt EGZKydyyO4IgZrUi3qjzusBt+u/VqTwxtwfVLgyO3uTc14owiVF76XZeZrW7T/D6Kfzo TZgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FzVZiOGt; 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 h13-20020a056402280d00b0042e0b28922asi3802374ede.7.2022.08.19.10.39.31; Fri, 19 Aug 2022 10:39:57 -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=FzVZiOGt; 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 S1353305AbiHSQfF (ORCPT + 99 others); Fri, 19 Aug 2022 12:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353482AbiHSQbq (ORCPT ); Fri, 19 Aug 2022 12:31:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F18A11DF79; Fri, 19 Aug 2022 09:06:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A9EC1617F2; Fri, 19 Aug 2022 16:05:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3992C433C1; Fri, 19 Aug 2022 16:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925131; bh=ZxhMVr49eMNwslMvCFUqsr9mcAHtbfXm7urEzpKHVlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzVZiOGt9Fy+zM7uksxaqmWgAMYmNgn/KQPGpBT7i34ahzYrqFtaiNGUWCvwDmnzV jDIAMxu1r+gVcKJz5pJVMXaU4GI8U+dozqNG4ihA0chyXjGMrkd2TxmVDz9JfD7ovv T5vj02G9kS71h/UKrjN2jZeLmVL34C6FE20tAKjs= 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.10 376/545] selftests/livepatch: better synchronize test_klp_callbacks_busy Date: Fri, 19 Aug 2022 17:42:26 +0200 Message-Id: <20220819153846.236093717@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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(+) --- 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, "bloc 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( 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