Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4562927rwb; Sat, 10 Dec 2022 10:31:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5W0G8hvOn2nMwLX3yQXVdjSZTdyZLh/l7qq9QqcmB3eCR1cvwi1LdVvxmiUT1LqgH3vvtM X-Received: by 2002:a17:90a:7483:b0:219:b1f3:2401 with SMTP id p3-20020a17090a748300b00219b1f32401mr10085692pjk.13.1670697090482; Sat, 10 Dec 2022 10:31:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670697090; cv=none; d=google.com; s=arc-20160816; b=JM0aZrKX5yydiW7zb3xRoeo1rOHhD/FKy4TR8ntJryopG35NNNvjkhpuSttEX23c7V 56F5jwzP11apjUG3c+HveH+PtsZWuGR2WDOm3tZixGnQ0BVnT3Lc67qneYKhQIzxjaZI TtfAzpH2cmeEbwAhZfNc2i7qcLPqITYo/8Qmw0AILUNQlPIzK6C7NZlZ9P8H+CEhbyvq 0YbW11cet+y5GLrriEotTLhRQy4ppF6gvgfZbziTJGvpCmkm1MP1xdDovk9BrUZYr+bt WVQ3FfWzmwgZwaE3ugqcVO1gkqrwNX5oZErwvQNuzVlZXk7PLioQeiwqkltOqbDnEncp 0yeQ== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=84thTfAbEFwdWhnbC99EGYAV74Pe0ymxZyX7gV4u3jQ=; b=lMbQWXpvLEqqRGh0k3jUbOHuhbqKsP6E5Ag6nieflzvnAsg8bPDxgK+Cze6qiR+Ye3 jNLDfu3AujIulPCHlfi8fg8b9KtTFsSi6znmP+S0+cqLCr0JAdgfNVIGov2cKuvtTWAY X47YJm08pJ7jEhsIbJ4ZZt2cMChUHZ+4CrWKzWa08z8tOztSs33/45ZZ9+uh4nWAb//R clffEEToG6rXY944SUUfqZNDbI5yHbk1vP0XaG7SsuAXFXJv12lissfLwGJcuIcSz7yZ ZuCV55CYESyzCkv/JHz3e7cCUCaomJlZk4ZSgm23ZNwnrGjzSLO25asTu9OY3D5Ed/oC umqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fQfI5Osu; 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 w5-20020a17090a8a0500b00219b3307f5fsi5142725pjn.45.2022.12.10.10.31.21; Sat, 10 Dec 2022 10:31:30 -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=fQfI5Osu; 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 S229784AbiLJRr7 (ORCPT + 74 others); Sat, 10 Dec 2022 12:47:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiLJRr5 (ORCPT ); Sat, 10 Dec 2022 12:47:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E11634C for ; Sat, 10 Dec 2022 09:47:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id CF519B80884 for ; Sat, 10 Dec 2022 17:47:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F4F9C433D2; Sat, 10 Dec 2022 17:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670694473; bh=eGEHQ/VAOok5w7QGZwJySepr/dzmtnSDc+W5FmrQevg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=fQfI5OsuPa7u19qb3TYtkYtgfula+Ktq0+C+CP1fOfg3NCaCcfcesikGTVcsZQQPu B1mT48cIlRnQi59LltjG/3ibHsC1v9Beszv5Bad+t47i7Vd8onIuJUoPJ7Caxls6jq ck8Pun446A/bK/e6ZUs5OIio4JQ64+KXD0rGdPctvpKU0ExFYOkdJ+16icuxIjrQvY 8g4qDbxmI7+gwxEWYhbVmXb9L208G70RyNLejGRXrpBSDKUmcrXab9a7nqEKeY/Sab BrusZjtj4RHOnK9dGchGE4+FJv/cCpTSdjQ4REqMUWFE2jva9dQIM2L4yl6a+hWGZD g/uRln229tl4A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 2FD795C05C0; Sat, 10 Dec 2022 09:47:53 -0800 (PST) Date: Sat, 10 Dec 2022 09:47:53 -0800 From: "Paul E. McKenney" To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, Masami Hiramatsu , Andrew Morton , Karol Herbst , Pekka Paalanen , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov Subject: Re: [for-next][PATCH 13/25] x86/mm/kmmio: Use rcu_read_lock_sched_notrace() Message-ID: <20221210174753.GD4001@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20221210135750.425719934@goodmis.org> <20221210135825.241167123@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221210135825.241167123@goodmis.org> X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 Sat, Dec 10, 2022 at 08:58:03AM -0500, Steven Rostedt wrote: > From: Steven Rostedt > > The mmiotrace tracer is "special". The purpose is to help reverse engineer > binary drivers by removing the memory allocated by the driver and when the > driver goes to access it, a fault occurs, the mmiotracer will record what > the driver was doing and then do the work on its behalf by single stepping > through the process. > > But to achieve this ability, it must do some special things. One is to > take the rcu_read_lock() when the fault occurs, and then release it in the > breakpoint that is single stepping. This makes lockdep unhappy, as it > changes the state of RCU from within an exception that is not contained in > that exception, and we get a nasty splat from lockdep. > > Instead, switch to rcu_read_lock_sched_notrace() as the RCU sched variant > has the same grace period as normal RCU. This is basically the same as > rcu_read_lock() but does not make lockdep complain about it. > > Note, the preempt_disable() is still needed as it uses preempt_enable_no_resched(). > > Link: https://lore.kernel.org/linux-trace-kernel/20221209134144.04f33626@gandalf.local.home > > Cc: Masami Hiramatsu > Cc: Andrew Morton > Cc: Karol Herbst > Cc: Pekka Paalanen > Cc: Dave Hansen > Cc: Andy Lutomirski > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "Paul E. McKenney" > Signed-off-by: Steven Rostedt (Google) Executable code can be the best form of comment. ;-) This does mess with preempt_count() redundantly, but the overhead from that should be way down in the noise. Acked-by: Paul E. McKenney > --- > arch/x86/mm/kmmio.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/mm/kmmio.c b/arch/x86/mm/kmmio.c > index edb486450158..853c49877c16 100644 > --- a/arch/x86/mm/kmmio.c > +++ b/arch/x86/mm/kmmio.c > @@ -254,7 +254,7 @@ int kmmio_handler(struct pt_regs *regs, unsigned long addr) > * again. > */ > preempt_disable(); > - rcu_read_lock(); > + rcu_read_lock_sched_notrace(); > > faultpage = get_kmmio_fault_page(page_base); > if (!faultpage) { > @@ -323,7 +323,7 @@ int kmmio_handler(struct pt_regs *regs, unsigned long addr) > return 1; /* fault handled */ > > no_kmmio: > - rcu_read_unlock(); > + rcu_read_unlock_sched_notrace(); > preempt_enable_no_resched(); > return ret; > } > @@ -363,7 +363,7 @@ static int post_kmmio_handler(unsigned long condition, struct pt_regs *regs) > /* These were acquired in kmmio_handler(). */ > ctx->active--; > BUG_ON(ctx->active); > - rcu_read_unlock(); > + rcu_read_unlock_sched_notrace(); > preempt_enable_no_resched(); > > /* > -- > 2.35.1 > >