From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AD8B3D64 for ; Mon, 27 Jan 2025 14:31:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737988310; cv=none; b=e3wCMf6h1urGgFh3fiI0ZzmfSg5rqonookWa+tpTi7p7CnVIV66Q3/vbEPhlcmBswhXu/w0vPIEfli/3gq/ATt2qvnXM3vi30BtSFe2w7jiz2UaRrEfg0euPPbNmwUwpDRx3dr4nZfoqDXKW8H1a3ivsFc2PNfRzRI8fYERtmPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737988310; c=relaxed/simple; bh=gq72t9xQ1bRKGj2BkovtB7txTTMx9dWXs5C4LIi9EKs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P359kcgkHxy2pEr66UUNA6p2mWBH3pcBsdk3KJmpo3iAxF17n789Zm9fm/igP4TVLT9oIghEtzSOuR+WR8Qokr+y/HONo7dZjACCYNqm3RNj0NOgT2mMmAbQH5O5IeJk1yNqIkpg9j8zfoefOoil/IumBipMdrWaF7VKvFLRV3o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=OjVNVzvr; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="OjVNVzvr" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5d7e3f1fc01so9289093a12.2 for ; Mon, 27 Jan 2025 06:31:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1737988305; x=1738593105; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mDb/GhQ4TlZtuUyEoyGF/CoAJCWNs5bGdIyaITH584I=; b=OjVNVzvrvN62Cr7G75DxGlTmgxviCmCT1rhC8qcSjC6hq8jAFtCV+v1YemJVd/FWu9 WijKurfFG18pAKzaJki7qTUVm1eyEXMpTsoCWideVFK+yNe08jatYvAdMOn7sVsu8LqU meogfX4+XcO4gTzEjD5dk54U26ghM9rIGZODsgO0tCaCoId32JRD+mYVacuk81n4xlNz RllGXkkUlTTWaedT7oAOo2qgeowvs6KdB/ISaGfgQu0uL93+LVUoj2KBKRASb7HlogVX 7mbYh0A41Bv8dQXFp42jEa0QNHpLQlzO5tvDw45xsl4tvCVS5VzC6kT3WwZVLEWoDDoY tx7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737988305; x=1738593105; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mDb/GhQ4TlZtuUyEoyGF/CoAJCWNs5bGdIyaITH584I=; b=a/LAVrErPBIl86n55n5TEJ1SI6m3RKUumA/DQ6LdDUVFpVINP82spkYa//TPOWYp9T w9DmDVlLG4LzaZL4jGG0M7SoHfHYNzOejQJyG7pDHPZLQyL21ilaVzmhIiDH2wkK2Jx1 ERU9d5l13ljrmATYYLmLgJ3U1KUjce7XKsG6tXGGE+z8HNay/TitcAkfwfHQwC01Gwo9 cnQxbcsZe49YMfYXP5DrwhPvuskyK7wB2nnXy2kLCRQKb+lCr/dY40lehps1KmQlYjov qbnMjnX7qV+rg+9jT9WFr0gwEFMqD55Xtj2BzrQsUWhwjvn19sO0maZdfUwxmsNvy/83 MKoA== X-Forwarded-Encrypted: i=1; AJvYcCVm8yQ+eHpdcctL8M0afVJEptFxTOWdAUe6sG3uxYtR/VGESeNSyYg3zu+44HZHV8Peb3xR3wJn22mk8TA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj1dGgFId6loLCVOYi8PieGaKx3ijsqNIK9EQq0BHTCQkGum5d LBaiOTo3u82RdtlhexIl0vgApG0eq8j9AjKIc7c9RndvKo4BOmTx/xiX5XH+uFtpljEFfkc7DRG S X-Gm-Gg: ASbGncs4ogCh3vLOEYenncv7br3Bd+V4qJSXv8N5IrAbuDgk5AZTuj9IRgJw24UZyaV 7Fcl1+N5kKiW5CyoUXEx463PK1pdSWzVVdxVJrsP2W4lIH0AN5D+T0Z7hO94Yjc0oTgK3SolbzH F0qYsOnVFNObzdyUteWiGv6fSuNitRTG4SBTiyE9ohiOiInglzep0OEf3CihrmdjmAqM7MYKMie muUEr2DsbRVyml1Y42llUrQBuWrALHSNg2JX4LZ69Ac8ut+IEnpvweQNOY5KzY56OyubXiY10aP 4Dxgh4c= X-Google-Smtp-Source: AGHT+IF3FIfxHgix2nKnF4oKJTIQTzZMDdI9qEwZ3cBcqN7MFxvnaUWUjb+g2+qDHnbVCbzqkWWCUQ== X-Received: by 2002:a05:6402:2347:b0:5cf:43c1:6ba7 with SMTP id 4fb4d7f45d1cf-5db7db1d549mr40567520a12.30.1737988303643; Mon, 27 Jan 2025 06:31:43 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc1863ae2csm5628667a12.43.2025.01.27.06.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 06:31:43 -0800 (PST) Date: Mon, 27 Jan 2025 15:31:41 +0100 From: Petr Mladek To: Yafang Shao Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, joe.lawrence@redhat.com, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/2] livepatch: Implement livepatch hybrid mode Message-ID: References: <20250127063526.76687-1-laoar.shao@gmail.com> <20250127063526.76687-3-laoar.shao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250127063526.76687-3-laoar.shao@gmail.com> On Mon 2025-01-27 14:35:26, Yafang Shao wrote: > The atomic replace livepatch mechanism was introduced to handle scenarios > where we want to unload a specific livepatch without unloading others. > However, its current implementation has significant shortcomings, making > it less than ideal in practice. Below are the key downsides: [...] > In the hybrid mode: > > - Specific livepatches can be marked as "non-replaceable" to ensure they > remain active and unaffected during replacements. > > - Other livepatches can be marked as "replaceable," allowing targeted > replacements of only those patches. > > This selective approach would reduce unnecessary transitions, lower the > risk of temporary patch loss, and mitigate performance issues during > livepatch replacement. > > --- a/kernel/livepatch/core.c > +++ b/kernel/livepatch/core.c > @@ -658,6 +658,8 @@ static int klp_add_nops(struct klp_patch *patch) > klp_for_each_object(old_patch, old_obj) { > int err; > > + if (!old_patch->replaceable) > + continue; This is one example where things might get very complicated. The same function might be livepatched by more livepatches, see ops->func_stack. For example, let's have funcA and three livepatches: a + lp1: .replace = false, .non-replace = true, .func = { .old_name = "funcA", .new_func = lp1_funcA, }, { } + lp2: .replace = false, .non-replace = false, .func = { .old_name = "funcA", .new_func = lp2_funcA, },{ .old_name = "funcB", .new_func = lp2_funcB, }, { } + lp3: .replace = true, .non-replace = false, .func = { .old_name = "funcB", .new_func = lp3_funcB, }, { } Now, apply lp1: + funcA() gets redirected to lp1_funcA() Then, apply lp2 + funcA() gets redirected to lp2_funcA() Finally, apply lp3: + The proposed code would add "nop()" for funcA() because it exists in lp2 and does not exist in lp3. + funcA() will get redirected to the original code because of the nop() during transition + nop() will get removed in klp_complete_transition() and funcA() will get suddenly redirected to lp1_funcA() because it will still be on ops->func_stack even after the "nop" and lp2_funcA() gets removed. => The entire system will start using another funcA implementation at some random time => this would violate the consistency model The proper solution might be tricky: 1. We would need to detect this situation and do _not_ add the "nop" for lp3 and funcA(). 2. We would need a more complicate code for handling the task states. klp_update_patch_state() sets task->patch_state using the global "klp_target_state". But in the above example, when enabling lp3: + funcA would need to get transitioned _backward_: KLP_TRANSITION_PATCHED -> KLP_TRANSITION_UNPATCHED , so that it goes on ops->func_stack: lp2_funcA -> lp1->funcA while: + funcA would need to get transitioned forward: KLP_TRANSITION_UNPATCHED -> KLP_TRANSITION_PATCHED , so that it goes on ops->func_stack: lp2_funcB -> lp3->funcB => the hybrid mode would complicate the life for both livepatch creators/maintainers and kernel code developers/maintainers. I am afraid that this complexity is not acceptable if there are better solutions for the original problem. > err = klp_add_object_nops(patch, old_obj); > if (err) > return err; I am sorry but I am quite strongly against this approach! Best Regards, Petr