From patchwork Tue Dec 6 19:12:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 2683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3010283wrr; Tue, 6 Dec 2022 11:30:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf62SAKLpac7MD5UlTg3X1PTtCPb9Q+SlC6lAAufYB1nZL3wFI5Tybtc6d/dYs+Khwf3qVcP X-Received: by 2002:a17:90a:d598:b0:218:7734:499 with SMTP id v24-20020a17090ad59800b0021877340499mr97014258pju.2.1670355022856; Tue, 06 Dec 2022 11:30:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670355022; cv=none; d=google.com; s=arc-20160816; b=UgF1GphS63yzFADks/SjGXlj2X+6oaWB8zMdrmlyAmZcS8b/N1Zav/78FkUXnuHl/o C4avrpY1B6ugUKVRSdH6S4p22tcLY0wrCeXHgin5bX7li5gsdl7jivTjuJozt9SURusB P26sqFxynnOvKsCS87BRlks1uO0NfLKS9s1OiuqCj3xTeWWR5V+mgmKSA+mK4uplPi4i NQY23TJSwJxqLQ/k9v+xrF6+g+TqObWhPOYRIQIO+BRP7HZTlMopUYYC/DJKs6nmdY51 v9B3+wvZ75Lac/hAZLUJyCs+PfCY7+W9rkGsxrrHylPufSqmPCa9cY8zQzUpkeJEZfxX /EmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id; bh=d08iYhXATUIvfr7fOrK++KFDvVlQAQZY/4lZagmhc7c=; b=GYKfjp9L6G4B2eYWEOpY/lf+52mBXj/mSKgHLcCa/LX5TSZlejPj09OwakGhcKE3Za 1ivNPztSu5K+DlAhN7oKMzPMWsqZ3mtbtgssO6rDZucDW7+ZVTacKVn0NLCKjxvtzC7Z Puoc4eS2gonBiUXC187kKEfSrlzeJM7p5qVj6CmM9DmeVTkaRGhSv2g5lm4dN6pnux77 vy7Ym4k9/ftHfh0BwgITM3ulasSVJlL3veh/gxC2BjBTfeASFiEYH3WoiGEiFtn6hAM5 UBuQGaxqpC+TJFK/LC+FrqueTWNggBERVjAv71Zm+DTCL646rFJsixXQFUh2EdbyP98J gLZw== 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 h3-20020a170902f54300b001898c6b8ec4si5384302plf.317.2022.12.06.11.30.09; Tue, 06 Dec 2022 11:30:22 -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 S229607AbiLFTMn (ORCPT + 99 others); Tue, 6 Dec 2022 14:12:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbiLFTMf (ORCPT ); Tue, 6 Dec 2022 14:12:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FAA8211; Tue, 6 Dec 2022 11:12:33 -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 2587DB81AE1; Tue, 6 Dec 2022 19:12:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0750C433C1; Tue, 6 Dec 2022 19:12:30 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1p2dMj-0004QL-23; Tue, 06 Dec 2022 14:12:29 -0500 Message-ID: <20221206191201.217838841@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 06 Dec 2022 14:12:01 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Karol Herbst , Pekka Paalanen , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Subject: [PATCH 0/2] x86/mm/kmmio: Have mmiotracer play nice with lockdep 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?1751494188270886677?= X-GMAIL-MSGID: =?utf-8?q?1751494188270886677?= 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 it needs to grab a lock while in the breakpoint handler. This is considered an NMI state, and then lockdep warns that the lock is being held in both an NMI state (really a breakpoint handler) and also in normal context. As the breakpoint/NMI state only happens when the driver is accessing memory, there's no concern of a race condition against the setup and tear-down of mmiotracer. To make lockdep and mmiotrace work together, convert the locks used in the breakpoint handler into arch_spin_lock(). It also takes the rcu_read_lock() at the fault, and releases it in the single step breakpoint. This makes lockdep sad. Luckily, it also disables preemption when taking the rcu_read_lock() and enables it when releasing the rcu_read_lock(). As now the sched RCU variant is basically the same as the "normal" RCU variant, there's no reason to take the rcu_read_lock(), so just remove it. Steven Rostedt (2): x86/mm/kmmio: Switch to arch_spin_lock() x86/mm/kmmio: Remove rcu_read_lock() ---- arch/x86/mm/kmmio.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)