Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751803AbdLLOcq (ORCPT ); Tue, 12 Dec 2017 09:32:46 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:33528 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750731AbdLLOco (ORCPT ); Tue, 12 Dec 2017 09:32:44 -0500 X-Google-Smtp-Source: ACJfBouhae1PRAQPB7AWJYdoCJNbpHPZSN4ec4ds0FmLLR6wBVT51YQ0SHh2XSxC/kq+Qbd38BRrz3jR9FzRfKMItPE= MIME-Version: 1.0 In-Reply-To: <20171212140418.56xld2lxja5rywp7@gmail.com> References: <20171127075139.4928-1-kherbst@redhat.com> <20171212134952.2hok6754245qshv3@hirez.programming.kicks-ass.net> <20171212140418.56xld2lxja5rywp7@gmail.com> From: Karol Herbst Date: Tue, 12 Dec 2017 15:32:42 +0100 Message-ID: Subject: Re: [tip:x86/urgent] x86/mm/kmmio: Fix mmiotrace for page unaligned addresses To: Ingo Molnar Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Pekka Paalanen , Lyude Paul , Steven Rostedt , Thomas Gleixner , torvalds@linux-foundation.org, hpa@zytor.com, linux-tip-commits@vger.kernel.org, Karol Herbst Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2306 Lines: 58 Hi Peter, the basic idea is to detect if a driver accesses a memory region mapped through ioremap. This is super usefull for reverse engineering closed source drivers like the Nvidia GPU driver. So here is what it does: 1. on ioremap the entire memory region mapped is registered in the mmiotracer and marked as not presen, which basically leads to page faults on acces 2. mmiotrace is the registered page fault handler for those pages and while handling the page (which basically means marking them as presen, because they were never missing in the first place) it parses the current instruction to detect if it was a read or write and writes relevant information into a file. This includes address accessed, value read/written, type of instruction 3. after single stepping, the page is marked as not present again 4. on unmap time, mmiotrace unregisteres those regions and marks them as present this is more or less the basic idea. And to answer your question how it is not completely broken: I don't know. It works for us (more or less, we can't parse repeat instructions as one example what does not work) and if we come across issues we try to fix them on the way. Anyway, this is a super useful tool to record and debug what a driver is doing with hardware and helps tracking down a lot of this, especially for Nouveau. I hope that helps. On Tue, Dec 12, 2017 at 3:04 PM, Ingo Molnar wrote: > > * Peter Zijlstra wrote: > >> On Tue, Dec 12, 2017 at 02:55:30AM -0800, tip-bot for Karol Herbst wrote: >> > Commit-ID: 6d60ce384d1d5ca32b595244db4077a419acc687 >> > Gitweb: https://git.kernel.org/tip/6d60ce384d1d5ca32b595244db4077a419acc687 >> > Author: Karol Herbst >> > AuthorDate: Mon, 27 Nov 2017 08:51:39 +0100 >> > Committer: Ingo Molnar >> > CommitDate: Mon, 11 Dec 2017 15:35:18 +0100 >> > >> > x86/mm/kmmio: Fix mmiotrace for page unaligned addresses >> >> OK, let me hijack this thread since apparently people use and care about >> mmiotrace. >> >> I was recently auditing the x86 tlb flushing and ran across this >> 'thing'. Can someone please explain to me how this is supposed to work >> and how its not completely broken? > > (I have Cc:-ed other gents as well.) > > Thanks, > > Ingo