Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp689074rwb; Wed, 9 Nov 2022 07:34:11 -0800 (PST) X-Google-Smtp-Source: AMsMyM4WiWanVxWTp+zbJ3BOq995oQXFLR3M5VDZNNyGjYOcL+1x6ocCR1caTMJkdC1+ouFXKbzc X-Received: by 2002:a62:1d52:0:b0:56b:f472:55e7 with SMTP id d79-20020a621d52000000b0056bf47255e7mr61795716pfd.63.1668008050956; Wed, 09 Nov 2022 07:34:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668008050; cv=none; d=google.com; s=arc-20160816; b=BXDA4aOxcYtM9NpzI1aMgn/swuq73oXtsfQW5vH5XH6WdjQFp2VaR5PWK2XDYwUShY 1dQUc+zgw+njegd8CUeL35eq7Fh7Jz9u5teEWs4t/aG5HClTGcr5HT2Em9hla667wmYA tfpOrKowgk7a0vG/tbhEfgS+WrFnlf0EKD+bL1tk8DAwoX8tNnEB7Dv+WG3tmENZi6uV XKJnIRzHKhjF7BTlNbqaNnGjAi1EHy0PKoPMTYwv3ceUW54ygspNb7msvglVPuuCIVpm Q42srNAe3vyyEDmKf5SOQ+UfrYpFRUJckH9t7vpoPZfyvneJIO+Na5aW6Sr6M8XkNrGf Y+Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RK4f1H5YPdP8JjJ/U+5vet//t/WB+7YrMTLnpKKnQlI=; b=EpVP5ZFAOLI7hMZgriTrejXEDNWLOYKpYQqZUmbNwszEtiqyDSpRp381Qdgww8uNjT q4CXZjEReGr8aK96HAACQEtdrDdPakP+1RhAQ2mf5RB0XR8U4X+MDGxewZhWg/ZGUc9R MQHxrCilFtCRKH81ds0vqTw6DGlh4mfT6Fje9SD8/e96ctK3m6iwEFX5LKbmLtdBwY7b iUS6gwSsv/PNY/L+khBl5HYmqtbNsg98coUdYDvz3s3ksTAEvSQiZvye+B7Z++DYspLR oSQQgZJDC2lKP5vEbSg/3gHfPt2/HpS91VNOwgZ9cdv15RuYRDiS/IpJoDGpztayIpLr dxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=pSfZscTy; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 33-20020a630e61000000b004610dceef13si19046428pgo.336.2022.11.09.07.33.55; Wed, 09 Nov 2022 07:34:10 -0800 (PST) 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=@suse.com header.s=susede1 header.b=pSfZscTy; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbiKIOgc (ORCPT + 93 others); Wed, 9 Nov 2022 09:36:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbiKIOga (ORCPT ); Wed, 9 Nov 2022 09:36:30 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3F4C3A2; Wed, 9 Nov 2022 06:36:28 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 43E541FAB3; Wed, 9 Nov 2022 14:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668004587; 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=RK4f1H5YPdP8JjJ/U+5vet//t/WB+7YrMTLnpKKnQlI=; b=pSfZscTy0iQa1K0Zgsw1nk2XxmOkbvROXvTvi3iv/jPP0IzG1Yfs9IqrLaoldLwOwcITXp 30t9wzNHXZIis/QBD1tdV4KB2Bult6sThZXCHj5urxUSPJuWCATVV3gtPWTCsvX8+0+KQg qH3tcuTSlbs4B8TKdk3hSNCHF6gyKrc= Received: from suse.cz (unknown [10.100.201.202]) (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 264E82C141; Wed, 9 Nov 2022 14:36:27 +0000 (UTC) Date: Wed, 9 Nov 2022 15:36:23 +0100 From: Petr Mladek To: Josh Poimboeuf Cc: Nicolai Stange , Marcos Paulo de Souza , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, jpoimboe@redhat.com, joe.lawrence@redhat.com Subject: Re: [PATCH v2 4/4] livepatch/shadow: Add garbage collection of shadow variables Message-ID: References: <20221026194122.11761-1-mpdesouza@suse.com> <20221026194122.11761-5-mpdesouza@suse.com> <20221104010327.wa256pos75dczt4x@treble> <20221108013209.eqrxs3xqtat6kksm@treble> <20221108184410.qhpxhtbfryzeh6eq@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221108184410.qhpxhtbfryzeh6eq@treble> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 On Tue 2022-11-08 10:44:10, Josh Poimboeuf wrote: > On Tue, Nov 08, 2022 at 10:14:18AM +0100, Petr Mladek wrote: > > On Mon 2022-11-07 17:32:09, Josh Poimboeuf wrote: > > > On Fri, Nov 04, 2022 at 11:25:38AM +0100, Petr Mladek wrote: > > > > > I get the feeling the latter would be easier to implement (no reference > > > > > counting; also maybe can be auto-detected with THIS_MODULE?) and harder > > > > > for the patch author to mess up (by accidentally omitting an object > > > > > which uses it). > > > > > > > > I am not sure how you mean it. I guess that you suggest to store > > > > the name of the livepatch module into the shadow variable. > > > > And use the variable only when the livepatch module is still loaded. > > > > > > Actually I was thinking the klp_patch could have references to all the > > > shadow variables (or shadow variable types?) it owns. > > > > In short, you suggest to move the array of used klp_shadow_types from > > struct klp_object to struct klp_patch. Do I get it correctly? > > Right. Though, thinking about it more, this isn't even needed. Each > klp_shadow would have a pointer to its owning module. We already have a > global hash of klp_shadows which can be iterated when the module gets > unloaded or replaced. > > Assuming atomic replace, the new patch is almost always a superset of > the old patch. We can optimize for that case. I see. But I do not agree with this assumption. The new livepatch might also remove code that caused problems. Also we allow downgrades. I mean that there is no versioning of livepatches. Older livepatches might replace new ones. We really want to support downgrades or upgrades that remove problematic code. Or upgrades that start fixing the problem a better way using another shadow variable. I personally think that registering the supported klp_shadow_types is worth the effort. It allows to do various changes a safe way. Also it should be easy to make sure that all klp_shadow_types are registered: 1. Grep might be used to find declarations in the source code. IMHO, it should work even with kPatch. 2. The klp_shadow_*() API will warn when a non-registered shadow variable is used. IMHO, this might be useful and catch some bugs on its own. Best Regards, Petr