Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3202548pxk; Mon, 21 Sep 2020 07:46:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr0bk8/xBle2/jDqAlMwNKOMur1fDWKB3tq9utIhaAfbfL1aFvNUMRKqvbdG7WqjDu+kkj X-Received: by 2002:a17:906:9604:: with SMTP id s4mr51885977ejx.182.1600699599703; Mon, 21 Sep 2020 07:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600699599; cv=none; d=google.com; s=arc-20160816; b=nDeJ3Et2pUObQWFYGpJOqmtg23x8cOfXGEnpmcsfAcV4NdgiUhlJ1Z9lYW6+U2ATg8 REcPecicAOksu2hjYGh92IloVLJo+1zJZBIKaq2atSAbrHDVlHKg6+JLZUizW7KVOUca yJT7Vg3AEnmhc+BJoG9CrUgRIfP8lBWVGJIeRYUn7uaFfUBnuU+/+EpbLDQK5XyrV/Uf rkuAFT+FTxPBB6yzyCYPeQY1gAw6DncoXHWvUjyVs8WtNbyUMJKkh2KHjnb7sU12w2mU rjSchrbZzrYCYQFHA1Mj33jDU+xPWiK4+EWHFeDav2zjOZrpi5WN+mkDevSFK53DtVEO B+Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sQEBEJDBifGk3tJdDbe+fvW/T4J0VUcdvhY6JITEot8=; b=KzqYpbq3X8xljMHyzblugXeQ0fbRZtjHiCz08G0n9g8zN6sHd+fVvECJqyGzZ2l6KB hfCtwiK52akNNlZ8KZAzEKXzLZF7fS2EpVJt2d92zo7BwdBeCF4ijQgX7lo2qWmZs9MB HmqK5g9fV1DkkO9X4gmVhoLTYqCZYaOBWNHZboHBWLHY3tz/PiC2rofiVFs03zO+JOcm 419F+mYvgWxyKPo/nGumk8NZKxXIhv1cAk6je2rkL1rb3ikoiy8xxSZmesp6KwQWMG48 iXmTCNerUzIHIqY6gATOz15ZiJzaY4B44+y7r3EDRmZkRj7moxe1RaZshjt0kA8hP4+E ny3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BwkNdHhx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw15si8330377edb.299.2020.09.21.07.46.16; Mon, 21 Sep 2020 07:46:39 -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; dkim=pass header.i=@kernel.org header.s=default header.b=BwkNdHhx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728015AbgIUOlS (ORCPT + 99 others); Mon, 21 Sep 2020 10:41:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:50014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727369AbgIUOlD (ORCPT ); Mon, 21 Sep 2020 10:41:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B0E12389F; Mon, 21 Sep 2020 14:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600699262; bh=GmXUaK7KDx5Au+pQK6GEf2o0wJ5SeLpezqoStuF2LQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BwkNdHhxkr5j4jtYNcAuvzg4sZpIyXh25+lu64E9VlrtxKs++sLFxz8Wwg4JquP7R PqhbvUk5vkQsU7ZPDov3gH17HxGO1Tu0GPOBNFaMw9Dq7fvYS9/zw97T0WMcR/eKvG HVDnHUpvxJkZwNZ7Sw6+3XR/Auo8fszwdloWVLyU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Palmer Dabbelt , Guo Ren , Sasha Levin , linux-riscv@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 06/15] RISC-V: Take text_mutex in ftrace_init_nop() Date: Mon, 21 Sep 2020 10:40:45 -0400 Message-Id: <20200921144054.2135602-6-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921144054.2135602-1-sashal@kernel.org> References: <20200921144054.2135602-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Palmer Dabbelt [ Upstream commit 66d18dbda8469a944dfec6c49d26d5946efba218 ] Without this we get lockdep failures. They're spurious failures as SMP isn't up when ftrace_init_nop() is called. As far as I can tell the easiest fix is to just take the lock, which also seems like the safest fix. Signed-off-by: Palmer Dabbelt Acked-by: Guo Ren Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/include/asm/ftrace.h | 7 +++++++ arch/riscv/kernel/ftrace.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index c6dcc5291f972..02fbc175142e2 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -63,4 +63,11 @@ do { \ * Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here. */ #define MCOUNT_INSN_SIZE 8 + +#ifndef __ASSEMBLY__ +struct dyn_ftrace; +int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); +#define ftrace_init_nop ftrace_init_nop +#endif + #endif diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index c40fdcdeb950a..291c579e12457 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -88,6 +88,25 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, return __ftrace_modify_call(rec->ip, addr, false); } + +/* + * This is called early on, and isn't wrapped by + * ftrace_arch_code_modify_{prepare,post_process}() and therefor doesn't hold + * text_mutex, which triggers a lockdep failure. SMP isn't running so we could + * just directly poke the text, but it's simpler to just take the lock + * ourselves. + */ +int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec) +{ + int out; + + ftrace_arch_code_modify_prepare(); + out = ftrace_make_nop(mod, rec, MCOUNT_ADDR); + ftrace_arch_code_modify_post_process(); + + return out; +} + int ftrace_update_ftrace_func(ftrace_func_t func) { int ret = __ftrace_modify_call((unsigned long)&ftrace_call, -- 2.25.1