Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2766744rwb; Mon, 7 Nov 2022 18:08:48 -0800 (PST) X-Google-Smtp-Source: AMsMyM5cck90d2aO3GnWwg8SJMJfaCAinUHuRqe+yMMF2nRXkp80VhTkaUVBwif18huKUp1Imnri X-Received: by 2002:a17:90a:311:b0:214:143b:c7ab with SMTP id 17-20020a17090a031100b00214143bc7abmr36397693pje.21.1667873328405; Mon, 07 Nov 2022 18:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667873328; cv=none; d=google.com; s=arc-20160816; b=W458lxGkwpgE4AfJGIpwY9IhSnO91Rub8FZN2zSpb3CCiF4yq0kAY4pAiTh7JeA1Yz Bc1V0srAwNsgy9TAMzhRU8Ca7eetpxL/Ob96vEOkj31gWi9vOKyhyqnMy5E6nhAltHkV U6/m/Gpgqi/4MJZ8nlfa/1267QxYpdJ/KyIKy5AFRnnO2FGAORz8JepLk4M7LJ4JacH0 R/8RjC/080SHeCRifesoUTY5XilJA5bXZ5ny0WyGLikmPT9Xfj6E/Ye/5WC/Gsu4mRM4 59ut/PJfeC5qFO9JtNn00kMMkXV8moCzEHqF+rYDc2IRIXMPPb9OMwXKB/jl+kPgXTvF ATag== 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=yFHgw3YqT/n8gHNcYCNY5nfnLcviLp1Otmd7x1X9wZY=; b=bKiS4d0gbgjGFcB7AICPM6FbYP8MCY/8LbP4M6/Kk7weAyftPMstmPWAJkOt3xAgV6 OWKQMHiadFWPnSNkWTDNXmFFI0STs6pwJhWFzo2X24RMyp9DyQhPHi27Qx+/ZClWSUPE 4hUOPLZwGefJl5k82hN6M+4tUQARFIVCa5U19SsdkePxglNwYuAg/xhUtXf1Py4koQ7+ MdW1kAv097OZeKZxvGLIljHSaQpSjc+NZTboAi4TzcHp3FzLB6Ni51NRsgeek+I+zAtF FGDzyIDem0Tj3oo9ZpDZ125zDpuOZy+/5UUSPCS3HB+Ekokp/n6eSdZTgALqlnejHvKh xlvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YAIosAcx; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ng16-20020a17090b1a9000b001fe39932aa3si19662033pjb.48.2022.11.07.18.08.37; Mon, 07 Nov 2022 18:08:48 -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=@kernel.org header.s=k20201202 header.b=YAIosAcx; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233367AbiKHBdb (ORCPT + 91 others); Mon, 7 Nov 2022 20:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233350AbiKHBdO (ORCPT ); Mon, 7 Nov 2022 20:33:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EBA111A; Mon, 7 Nov 2022 17:32:12 -0800 (PST) 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 A176B61374; Tue, 8 Nov 2022 01:32:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC968C433C1; Tue, 8 Nov 2022 01:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667871131; bh=ED313/aaAI+lz49lB29Wmv20Z3nVuXhp1WXomGj7JMo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YAIosAcx5ddEnbPE5VGv5y5o955A5t4+cQY/gyHGTJb2+jU4Xgk+ldbnQy+yCjVaE 5krArbp38G8pflcWUNemKsugI8PO9LdPYSMuz/+Gd2lSj/GfKQOto9bx8iq7j+JKXa OYcGdSVe75nEOCI9UPNjwTNostb54PggF6ZUx9KclSfFXkad654d4ClVdjGkXMtnVU jAGODql/ITbX5DrOVIRUYhciEP8BAqxrg3vGFSgEgJ7yPtcxORm+uh+sQG+3doZiiN vQyXK/4Vap7NgMgsZiVAxqDFlJPezuHWO8ewYH+0ERYeRjdNRdR5QYqCBWqVhUwVYd Mazsa0qZjMX2A== Date: Mon, 7 Nov 2022 17:32:09 -0800 From: Josh Poimboeuf To: Petr Mladek 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: <20221108013209.eqrxs3xqtat6kksm@treble> References: <20221026194122.11761-1-mpdesouza@suse.com> <20221026194122.11761-5-mpdesouza@suse.com> <20221104010327.wa256pos75dczt4x@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 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 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. Instead of reference counting, the livepatch atomic replace code could just migrate any previously owned shadow variables to the new klp_patch. This of course adds the restriction that such garbage-collected shadow variables couldn't be shared across non-replace livepatches. But I wouldn't expect that to be much of a problem. Additionally, I was wondering if "which klp_patch owns which shadow variables" could be auto-detected somehow. For example: 1) add 'struct module *owner' or 'struct klp_patch *owner' to klp_shadow 2) add klp_shadow_alloc_gc() and klp_shadow_get_or_alloc_gc(), which are similar to their non-gc counterparts, with a few additional arguments: the klp module owner (THIS_MODULE for the caller); and a destructor to be used later for the garbage collection 3) When atomic replacing a patch, iterate through the klp_shadow_hash and, for each klp_shadow which previously had an owner, change it to be owned by the new patch 4) When unloading/freeing a patch, free all its associated klp_shadows (also calling destructors where applicable) I'm thinking this would be easier for the patch author, and also simpler overall. I could work up a patch. -- Josh