Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp992120pxp; Wed, 16 Mar 2022 23:44:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIPv1rbMIYWHqH79lFDaECBiaq1nFo59bnrlOU3mbNSE5hFDAlZuO17p4lUJbmhpAMoj0F X-Received: by 2002:a65:6187:0:b0:381:54c9:8cbd with SMTP id c7-20020a656187000000b0038154c98cbdmr2527752pgv.382.1647499466821; Wed, 16 Mar 2022 23:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647499466; cv=none; d=google.com; s=arc-20160816; b=gbpRFldDIA4GADkaLtfDBtqWeA3ptyaqdxxDKgK28jg/PnZVaVhC2/PADoFs5xb0Iy OTim2fTTevO2blI9uqVuvkw6p4iaje3a4qvClidmqGjmT7onAW8kEA8Vg0CSWrS3oO/e ay9nFcS6fXfM9Hc3AiN+QnSM2/DTCh6cD3v3HKCFXYce0EabtcKIdj0t0NG0w5FWkWFK Vcmndi8pxaGYm0kydzHb3pKqewWAYoLfZwQnOfteSIyw72IDDKbpiyUcmkhidYUqz2rC BqVI+Qxxaac8jgdhv+kFCxpwalUczliPhCotDYzAemIcrQTee5uxshmcfEHnNte/3jpx ve8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature:dkim-signature; bh=sNgiXVZBv6F6wyCvndqNofHIp7IwWtdhnCB8N/Uhyx4=; b=nnU0ME2vTUN93N/rjp3YrFIG6YxCLG47A+hkaB6ij3h6DKiey1YVRw+oC9u/yh/aFf 7e2XyFHTUzF/p8q5gA1hK5OCaahalWHTB5L5bj/m6+yIncKFo8DU2mqhy4r6pWfKbf9O psmvBKSnUnzDAT8hhHv6TnnDhAmHKRGWO5HgNx8Lb8IXQKXRa32vt/wNS6Ls0i/10Iyk QIC30LnfStgiBOjeBOL9ErNXvzkE2z8hYiNEATtzhUhNtqkN1BgPGIMOvA6yRvudKv+Q 4t/t6NTuEGSkVreMIpKjeXigvyzbi6nDnWq2qQdxl7Hb69xcwjjqqdyWntNPSuAXZnYL nT1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=hothijYJ; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=PKQl+Bpg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n2-20020a1709026a8200b0015317dadaa7si3436254plk.544.2022.03.16.23.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:44:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=hothijYJ; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=PKQl+Bpg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9C972D6562; Wed, 16 Mar 2022 22:29:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345237AbiCPOtn (ORCPT + 99 others); Wed, 16 Mar 2022 10:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231273AbiCPOtm (ORCPT ); Wed, 16 Mar 2022 10:49:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A425B1A800; Wed, 16 Mar 2022 07:48:27 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 61F3C210E4; Wed, 16 Mar 2022 14:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1647442106; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sNgiXVZBv6F6wyCvndqNofHIp7IwWtdhnCB8N/Uhyx4=; b=hothijYJO1hxPRBPTWSio0H1fgSSzQ8O7tk8VGs/WEuIfRvgvnwDzVWziL+njJmzW6wyFn VATT3K4e72LwlXcRj3rW+0WbHF7s9L+fpVx64QmLSbyMLwtHUQdxspy7+5OnijG2U+hrJS i9OUAEdd5u4u2QvpIpuWOodg7TL2S18= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1647442106; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sNgiXVZBv6F6wyCvndqNofHIp7IwWtdhnCB8N/Uhyx4=; b=PKQl+BpgTe2MRagJZ4oRxzm6SS30ZxbcbTnqEeM2XrTInCRsMggLFOJzqWHHMc41bUhnSs yIjn9NvRSPch9PCA== Received: from pobox.suse.cz (pobox.suse.cz [10.100.2.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 31C92A3B87; Wed, 16 Mar 2022 14:48:25 +0000 (UTC) Date: Wed, 16 Mar 2022 15:48:25 +0100 (CET) From: Miroslav Benes To: Chengming Zhou 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 Subject: Re: [PATCH v3] livepatch: Don't block removal of patches that are safe to unload In-Reply-To: <20220312152220.88127-1-zhouchengming@bytedance.com> Message-ID: References: <20220312152220.88127-1-zhouchengming@bytedance.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sat, 12 Mar 2022, Chengming Zhou wrote: > module_put() is not called for a patch with "forced" flag. It should > block the removal of the livepatch module when the code might still > be in use after forced transition. > > klp_force_transition() currently sets "forced" flag for all patches on > the list. > > In fact, any patch can be safely unloaded when it passed through > the consistency model in KLP_UNPATCHED transition. > > By other words, the "forced" flag must be set only for livepatches s/By/In/ > that are being removed. In particular, set the "forced" flag: > > + only for klp_transition_patch when the transition to KLP_UNPATCHED > state was forced. > > + all replaced patches when the transition to KLP_PATCHED state was > forced and the patch was replacing the existing patches. > > Signed-off-by: Chengming Zhou > --- > Changes in v3: > - rewrite more clear commit message by Petr. > > Changes in v2: > - interact nicely with the atomic replace feature noted by Miroslav. > --- > kernel/livepatch/transition.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c > index 5683ac0d2566..7f25a5ae89f6 100644 > --- a/kernel/livepatch/transition.c > +++ b/kernel/livepatch/transition.c > @@ -641,6 +641,18 @@ 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; > + /* > + * Only need to set forced flag for the transition patch > + * when force transition to KLP_UNPATCHED state, but > + * have to set forced flag for all replaced patches > + * when force atomic replace transition. > + */ How about something like /* * Set forced flag for patches being removed, which is the transition * patch in KLP_UNPATCHED state or all replaced patches when forcing * the atomic replace transition. */ ? > + if (klp_target_state == KLP_UNPATCHED) > + klp_transition_patch->forced = true; > + else if (klp_transition_patch->replace) { > + klp_for_each_patch(patch) { > + if (patch != klp_transition_patch) > + patch->forced = true; > + } > + } Looks good to me. Miroslav