From patchwork Fri Dec 9 18:41:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 31908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp936488wrr; Fri, 9 Dec 2022 10:51:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf53iwAnmv/sdOehdvCvbls13suo/+1TFusSTaiLz3RPVBDHPw2/X1TW3eCZAnA6oYd6DZT6 X-Received: by 2002:a17:903:2448:b0:189:f277:3830 with SMTP id l8-20020a170903244800b00189f2773830mr10286571pls.68.1670611914448; Fri, 09 Dec 2022 10:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670611914; cv=none; d=google.com; s=arc-20160816; b=e6FrEkIPIbdmQOiG9O1NOaB3EjX7iBNKDLOhh8buH88/nn1dZt+odhG0qTYrh0lbWD q+ZmYKoB2jN4uaowV7Qpz9zWYbZK5OBqGGrlIIdBKFT5VTZc/gWOVIML/lRyfpdlHIiE PgshcIOXFDymDonEnRobh31poMDxDgDL5DhOOv8nFVaxcifV2TWwL1CJilVGcWzZ8qbR mEsrTUM4F0YbH5B8KNoKhLIbM/VPZmsmK+dq4SNFGWlyLQ5sGdm+qZpHBxIYKsj7sjKC B9k2r0efyx7ufyLLfNlILZZOelkBaWAC4Vc5TIXnX2ileEwcZmNp0FGmk3pZQggR37Qd Cklg== 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 :message-id:subject:cc:to:from:date; bh=sJZ8BgPB4i9D06tpPUdGj+H85Jjsxynf7h5SubIJ6xo=; b=saw0r79DLBK8SOw/FV+8DUE/XXO2nxnmWCgvLHYZWWU46iRuxQt2+nnpsn/lpC05If XJlu7Hwh8d+Bvs5Bkh85toM9czHolxDBivCI7QNrocvBFyW40vNHk/WnyXnaiYYGccJS VlMOp4CTDRlNk4VkoFGoH+So1P/T6RpC9seiFJBL7spty3QXEPO5FeyLnQnpMeQoLVtU icbYCyeLdDGnntBITI2ITPd7IENRCPylW7EIK6nHMHv0b+LzkWsSRNuL8jKrdTDv3V7i 5ts4w8lLSpWNwLvTj7oLyAXYtP8h+PHXF2/HppWapbql5QggWfbjQ07BV3rzPWtAhyiZ 72xQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170902c94600b00176d5b20ebesi2308493pla.355.2022.12.09.10.51.41; Fri, 09 Dec 2022 10:51:54 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbiLISlz (ORCPT + 99 others); Fri, 9 Dec 2022 13:41:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbiLISlv (ORCPT ); Fri, 9 Dec 2022 13:41:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BE98663CA; Fri, 9 Dec 2022 10:41:48 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3233062300; Fri, 9 Dec 2022 18:41:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FFE7C433D2; Fri, 9 Dec 2022 18:41:46 +0000 (UTC) Date: Fri, 9 Dec 2022 13:41:44 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Andrew Morton , Karol Herbst , Pekka Paalanen , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Paul E. McKenney" Subject: [PATCH v2] x86/mm/kmmio: Use rcu_read_lock_sched_notrace() Message-ID: <20221209134144.04f33626@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751763558926614452?= X-GMAIL-MSGID: =?utf-8?q?1751763558926614452?= 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(). Signed-off-by: Steven Rostedt (Google) --- Changes since v1: https://lore.kernel.org/linux-trace-kernel/20221206191229.813199661@goodmis.org (also called [PATCH 2/2] x86/mm/kmmio: Remove rcu_read_lock()) - Instead of simply removing rcu_read_lock() call rcu_read_lock_sched_notrace() 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(); /*