From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D203C433EF for ; Thu, 3 Mar 2022 06:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbiCCGwR (ORCPT ); Thu, 3 Mar 2022 01:52:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbiCCGwP (ORCPT ); Thu, 3 Mar 2022 01:52:15 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E413816A590 for ; Wed, 2 Mar 2022 22:51:30 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id s11so3944481pfu.13 for ; Wed, 02 Mar 2022 22:51:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=vGPyMpAI10MU3XsGD8/28ugapGuzl32gSygdZuFaXgw=; b=yIJColnGqvEfF3gxpGrZzpxyWOXquzYrHsw7ceFq03On82nwLIBBCnVm/3e+v56jIP EEKkcwh55HyhxvrLfJ4jHN7cKEsg1KPi5rnISAIuv8l6GjBnDDYTJyZrz3gyEs+VBNFH 6LnJ57fiNZvwjgzPgfaeUlRQS8h4l7m56MPnwbpNOoxxSwROtq8sRz4hq0ThMh4LONTe Cy/n3HyIQUqIsu1EhKUqwJB3MGI1rZJPQ2btIcgTb1YOg516qdIMHOGBFkytAKS9awm4 +3OJHn7bFwqievUKBMZeXcmw8XsVhl4GCBrZxdprh1OEPN6arqHNa+OVINarcPxtftJ9 uPaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=vGPyMpAI10MU3XsGD8/28ugapGuzl32gSygdZuFaXgw=; b=fv6fMfBrBjnQLqZpHFtrTA0+qzdGT7SG4em2Q/CK/0GpLLStBInd6WR130HpesuhNx Wq8uS/k1PWdImXABCogl6kEKUg3NfXodVz0oIfTpoSUx8uIShdbjASb/yxdM06Uu8EgO 6Qu6JWHJaUgJ/T7WZQC+wakR+LsPrqtv7T+/WgUp9wIOJ0K/m+/KaHZfBF5kaJgcDeaE 98TVq5XNmKbk9zuVTnrh6e5G8+qsaLkKOC5PpeIIQci1gdaGzfFxQBNS/wyvQiwdb3uZ ziKx8xGFTExHkt9e8GHZ8wiEU9dLui29TSsPO2cCl422cvuam3ADMNkoYpL72RYbdX5U J+HA== X-Gm-Message-State: AOAM532MOJKV5cz0OsosQ0sZ7ahR/+WiZplBOK3zJhNxbUIEIS/Pfnmf qhE9cKPwUiI7ZxYgsKSBCJ/NCQ== X-Google-Smtp-Source: ABdhPJyMNs6bPxpLikwLoiCY7jFG5Q++vQC4lxr4Qp4i25BW6Zgp/1KyngyZLACjE6eZIDlpGoawIA== X-Received: by 2002:a05:6a00:150a:b0:4cc:f6a6:1bc6 with SMTP id q10-20020a056a00150a00b004ccf6a61bc6mr37154677pfu.74.1646290290328; Wed, 02 Mar 2022 22:51:30 -0800 (PST) Received: from [10.255.179.141] ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id d10-20020a63360a000000b0037947abe4bbsm1121746pga.34.2022.03.02.22.51.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Mar 2022 22:51:29 -0800 (PST) Message-ID: Date: Thu, 3 Mar 2022 14:51:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [External] Re: [PATCH] livepatch: Only block the removal of KLP_UNPATCHED forced transition patch Content-Language: en-US To: Miroslav Benes Cc: jpoimboe@redhat.com, jikos@kernel.org, pmladek@suse.com, joe.lawrence@redhat.com, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, songmuchun@bytedance.com, qirui.001@bytedance.com References: <20220301140840.29345-1-zhouchengming@bytedance.com> From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2022/3/2 5:55 下午, Miroslav Benes wrote: > Hi, > > On Tue, 1 Mar 2022, Chengming Zhou wrote: > >> module_put() is currently never called for a patch with forced flag, to block >> the removal of that patch module that might still be in use after a forced >> transition. >> >> But klp_force_transition() will flag all patches on the list to be forced, since >> commit d67a53720966 ("livepatch: Remove ordering (stacking) of the livepatches") >> has removed stack ordering of the livepatches, it will cause all other patches can't >> be unloaded after disabled even if they have completed the KLP_UNPATCHED transition. >> >> In fact, we don't need to flag a patch to forced if it's a KLP_PATCHED forced >> transition. It can still be unloaded only if it has passed through the consistency >> model in KLP_UNPATCHED transition. >> >> So this patch only set forced flag and block the removal of a KLP_UNPATCHED forced >> transition livepatch. >> >> Signed-off-by: Chengming Zhou >> --- >> kernel/livepatch/transition.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c >> index 5683ac0d2566..8b296ad9e407 100644 >> --- a/kernel/livepatch/transition.c >> +++ b/kernel/livepatch/transition.c >> @@ -641,6 +641,6 @@ void klp_force_transition(void) >> for_each_possible_cpu(cpu) >> klp_update_patch_state(idle_task(cpu)); >> >> - klp_for_each_patch(patch) >> - patch->forced = true; >> + if (klp_target_state == KLP_UNPATCHED) >> + klp_transition_patch->forced = true; > > I do not think this would interact nicely with the atomic replace feature. > If you force the transition of a patch with ->replace set to true, no > existing patch would get ->forced set with this change, which means all > patches will be removed at the end of klp_try_complete_transition(). And > that is something we want to prevent. Good point, I should check if it's an atomic replace livepatch in the else branch, in which case we have to set all existing patches to forced. Thanks. > > Miroslav