Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp257639pxx; Thu, 29 Oct 2020 01:42:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC0X85t0iZIhtOjMksVL56/z+zb/KfjmxkeSKh6AURrry0yBCWJn0MGp4rmraxjryrULwL X-Received: by 2002:a17:906:a296:: with SMTP id i22mr815151ejz.288.1603960946932; Thu, 29 Oct 2020 01:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603960946; cv=none; d=google.com; s=arc-20160816; b=kcmTSAykG0mMlCPXJYnRTm+1Eh/ddDnZPMXcdCpzQITY+Kg5dPrtC8ILxFw184ylRM kxbe6lA3QjcBsGpGxflrfINV56ZS97ZNka7N4CP1Ajd5KWu9PfKA7jJyFR444K8JUHVR HTx1yxATQnqvZd6vpTxAJwLbnEniGIAHk7JZ8+MgjM6V4DqMCQL9WkIuxHF+7iMW9RUX V9Fv7/Ae/obEbLcHcdqzO0NZcdEVZHnkBA/iW1JoZiJzD7SX+VNTTYido2/SE6gIZivT 02Xlu7iYgZPXCcHInsJkjEKgeV27I7Tf6ayu0OZPb9hnn67ti7sNSatRkmxKDfB8FDq+ aUCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=m4J8mU1+FKRg6kTMu9EWHm39hY0LO6c+/HqfjjBz4B8=; b=qXeuwFq/7dNMNH1r/NgE3s/me51UbFo3BmveG7pAZnAP8qgg4DPb/mTP2ZC4Q2tUY+ O0/6HqB71xxKUTdY8stdH9Gvg1Wc6hbusyvHHJVSHZCrdMwTHJqgn7KOmuUWNIi8lZgm TWutx2CFPxcIemkae3YgxEvBbJcWUCdP46kuA6EPZhAlxJJnTE1Iz72stCwSNPB1w5eT YqKYg5tpp8ZK3i7LB7DqbxsdSSW7kWBA5InDxNBCTDO3O/6CBBQoQ/YRuzy+wWlkx+SP it1W1ZObaoeZmKP3XiSpa8P1XksfG7lBfKoc6IjCl7LwQOvd9x1JBC6swMIB/CPt4NHV M9Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y24si1327744ejw.503.2020.10.29.01.42.05; Thu, 29 Oct 2020 01:42:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731607AbgJ2A6A (ORCPT + 99 others); Wed, 28 Oct 2020 20:58:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:60532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731586AbgJ1WRd (ORCPT ); Wed, 28 Oct 2020 18:17:33 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D02E7246E7; Wed, 28 Oct 2020 11:56:14 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94) (envelope-from ) id 1kXk3p-005ZJ1-Df; Wed, 28 Oct 2020 07:56:13 -0400 Message-ID: <20201028115613.291169246@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 28 Oct 2020 07:52:50 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , live-patching@vger.kernel.org Subject: [PATCH 6/9] livepatch/ftrace: Add recursion protection to the ftrace callback References: <20201028115244.995788961@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" If a ftrace callback does not supply its own recursion protection and does not set the RECURSION_SAFE flag in its ftrace_ops, then ftrace will make a helper trampoline to do so before calling the callback instead of just calling the callback directly. The default for ftrace_ops is going to assume recursion protection unless otherwise specified. Cc: Josh Poimboeuf Cc: Jiri Kosina Cc: Miroslav Benes Cc: Petr Mladek Cc: Joe Lawrence Cc: live-patching@vger.kernel.org Signed-off-by: Steven Rostedt (VMware) --- kernel/livepatch/patch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c index b552cf2d85f8..6c0164d24bbd 100644 --- a/kernel/livepatch/patch.c +++ b/kernel/livepatch/patch.c @@ -45,9 +45,13 @@ static void notrace klp_ftrace_handler(unsigned long ip, struct klp_ops *ops; struct klp_func *func; int patch_state; + int bit; ops = container_of(fops, struct klp_ops, fops); + bit = ftrace_test_recursion_trylock(); + if (bit < 0) + return; /* * A variant of synchronize_rcu() is used to allow patching functions * where RCU is not watching, see klp_synchronize_transition(). @@ -117,6 +121,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, unlock: preempt_enable_notrace(); + ftrace_test_recursion_unlock(bit); } /* -- 2.28.0