Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp554605imn; Thu, 28 Jul 2022 08:44:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tZWl1S0UJn2Ca+URAs1qmz26Wts4cwgM1LftwYOLDX8nM1DTrRw/CvtEYsbLw14/T1W6ZE X-Received: by 2002:a05:6402:514a:b0:43b:cb16:9fdf with SMTP id n10-20020a056402514a00b0043bcb169fdfmr28140161edd.115.1659023089058; Thu, 28 Jul 2022 08:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659023089; cv=none; d=google.com; s=arc-20160816; b=guVvNtIFosbfKWf62Vq/vIhRIZFELh0LTGtz+cTf7fTb/CT0qpK0XeWgWx1JAeHO5Y kc1RXANuSwoeUE9gYlNKFGngtRzbiUQqOfZTc5IrPDMO/mZad6OiHx/Zkf34QnM7msZs Zp7zGnnHWEUA1IbxBK7vlPvZ0RHc/xwI/Wh2ci5ZJhpfA6YQXzGTmkV4t+qNppYqef9R ScPnbw5sIsOaOCxPQQRWEvS4/ZysS487jPdSD4J9YF7vQkFCN1yAoHqEpY2ulAtQmKkr Fe27o4ora85fGL+lOuv4mgkJTMsr9JzSsP7IHHJB2lnftYO/K2eeidHGq+xOT6iXZpwX jQvg== 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=PZ1g1iDmzg1vUkpBJi42fPN29v6W/qAuH8HEq7Piwls=; b=XYzoWr/lGyvtapjW1l55Gk5Wb4uC53fiXJ/BcrOCA5Q/VIVugC7GRdb1837CDUe/77 HGHPfCQR7Enqy5SufEcZNyLr3a8sBCdlbaCnK4mA54hLZ3eyf6xRHpsLui8H0EFtczcf OKuhjnEvjZGpM/OxTU+OadH4ruCCkz4PouHAUOxVhl7qIECUtzX6tDp7OnyZImmKuzjC QZyVdKktnUKN45JBEElTy9fgYh3jeCBg6ynhisqJByc4JTmCqVYSYdokbmRKYY3WXo4V 71EOvvrRfa2bd9EcLmIqkp8cgKxg1IUKG1a97Yl5ohbbYEA46q2gE/JKFMS4Nae5Bg05 UZEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=G9nzwH5R; 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 sd13-20020a170906ce2d00b007070522a0fdsi846924ejb.835.2022.07.28.08.44.23; Thu, 28 Jul 2022 08:44:49 -0700 (PDT) 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=G9nzwH5R; 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 S231214AbiG1Phc (ORCPT + 99 others); Thu, 28 Jul 2022 11:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiG1Ph3 (ORCPT ); Thu, 28 Jul 2022 11:37:29 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 477ED5465C; Thu, 28 Jul 2022 08:37:28 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 05A3C35137; Thu, 28 Jul 2022 15:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1659022647; 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=PZ1g1iDmzg1vUkpBJi42fPN29v6W/qAuH8HEq7Piwls=; b=G9nzwH5RUiRv3tYNjRHP3cdU+Ak7QsO/RBbwasjI/2ZJfEN3zvbQzgIhQ6QS2AQEet4sCh lCfj/UETvZF+Vr6JrwGN2ndJvVj1feIoL4kc/fqtE1apgMhlgcazmYJ5U4QScu23PhKNUC DsCnK/XLGA9Vg6o9zsKdUeZdefYg3K0= Received: from suse.cz (unknown [10.100.208.146]) (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 D636E2C141; Thu, 28 Jul 2022 15:37:26 +0000 (UTC) Date: Thu, 28 Jul 2022 17:37:26 +0200 From: Petr Mladek To: Rik van Riel Cc: Josh Poimboeuf , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, kernel-team@fb.com, Jiri Kosina , Miroslav Benes , Joe Lawrence , Breno Leitao Subject: Re: [PATCH v4] livepatch: fix race between fork and KLP transition Message-ID: References: <20220720121023.043738bb@imladris.surriel.com> <20220722150106.683f3704@imladris.surriel.com> <20220725094919.52bcde19@imladris.surriel.com> <20220727001040.vlqnnb4a3um46746@treble> <20220727102437.34530586@imladris.surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220727102437.34530586@imladris.surriel.com> 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 Wed 2022-07-27 10:24:37, Rik van Riel wrote: > v4: address changelog comments by Josh (thank you) > > ---8<--- > When a KLP fails to apply, klp_reverse_transition will clear the > TIF_PATCH_PENDING flag on all tasks, except for newly created tasks > which are not on the task list yet. It actually is not true. klp_reverse_transtion() clears TIF_PATCH_FLAG only temporary when it waits until all processes leave the ftrace handler. It sets TIF_PATCH_FLAG once again for all tasks by calling klp_start_transition(). The difference is important. The WARN_ON_ONCE() in klp_complete_transition() will be printed when fork() copied TIF_PATCH_FLAG before it was set again. Anyway, the important thing is that TIF_PATCH_FLAG and task->patch_state might be incompatible because fork() copies them at different times. klp_copy_process() must make sure that they are in sync. And it must be done under tasklist_lock when the child is added to the global task list. Best Regards, Petr