Received: by 10.213.65.68 with SMTP id h4csp3968113imn; Tue, 10 Apr 2018 07:20:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx48yA9BrGdUvQclTAVaeCS9PLKHf0ksd6nN1DHWo3Z63TrX0Vaz2mUQC/3XO7+HhgeuKzbvJ X-Received: by 10.101.75.81 with SMTP id k17mr448247pgt.335.1523370017331; Tue, 10 Apr 2018 07:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523370017; cv=none; d=google.com; s=arc-20160816; b=B2rT0rESWfyetTYek1crAsoGtKMMyE5z8254A2ot8H2YuteLrusLpTFf5wmMYDRyl4 DvKkgaRV4mHnZK0xwXuT64noo0UfqGaKoaiK7/W//+9odvcNVEH1siPQbuCSsEOMUWeY Wvqov18bBgzurtQ+itfNpe9F5XSAY1XZ+9Lm7Eb/BgUs+S4lDj4aJYCzcSpPCZ+2ZPfX tyDPHV9wiqz3m0PkmowMn0UJUU8OqtjbS7nATaal4u0HT5c1WT4T6KIOMlofl3xr3jsa nO7ki+hf8K2Mw5jlkdjjMo9Ar9IsIAJZX0W9Hgjb6hrmuz4cJYybGgigzMF0HTfDECvG RntA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-transfer-encoding :mime-version:subject:in-reply-to:message-id:to:from:date :domainkey-signature:dkim-signature:arc-authentication-results; bh=sVzgXKg1eArVeyiRWSP9LKTcGnhmWUgafsWudMCJkCs=; b=WpWA7Rn8aUU1Psc5UfIAwdTqENt6dyhHszS9Bl50zHWIPbT67o0ydrRTd2YfCovz11 EDRQdAuY1k9zuNWwT4nt6D+6pw8l64Ip1xwawSYpLmhAoO1l+suIxUWngETHIqkye40b a4LyOvNcvWhjl+pe56uBfW65fdzWanCUD3i7WDnUSkkfZ002B5EWtYU1IYOCwU5bqvON V8hw2uBJD7d1FaaJ6GEvc9OocJn+8diqmrI9GwnvvFCFdf0eUQ/9h/TDupptiIQwP5Ww n+Hw3vyOG2KUshwwTKKOEcPWxMk93eGSCqq53AuAmhsPtu0dxxhUFnBvGk6LClJz5BvG ffJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@fjellstrom.ca header.s=zoho header.b=aMkb772X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w71si1745846pgd.435.2018.04.10.07.19.40; Tue, 10 Apr 2018 07:20:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@fjellstrom.ca header.s=zoho header.b=aMkb772X; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754067AbeDJONG (ORCPT + 99 others); Tue, 10 Apr 2018 10:13:06 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21089 "EHLO sender-of-o51.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133AbeDJOND (ORCPT ); Tue, 10 Apr 2018 10:13:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1523369579; s=zoho; d=fjellstrom.ca; i=thomas@fjellstrom.ca; h=Date:From:To:Message-ID:In-Reply-To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; l=1406; bh=sVzgXKg1eArVeyiRWSP9LKTcGnhmWUgafsWudMCJkCs=; b=aMkb772XkmZ+xhvMrQSgfW2Do3u8857Oh8DUdpadss7T+G0bDiFfgkmDvP+n6uyA kL4GwUzLQaV9lN140JbgeV+xh92n1FU6Bv9T9U38KM8TBkymrDtMlH9qsvHGPZAz4Gi WYoBXwjIgCWDNeA2i8/chZgwEmDxOQwq3mj5TVsI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zoho; d=fjellstrom.ca; h=date:from:to:message-id:in-reply-to:subject:mime-version:content-type:user-agent; b=NYSA7TXodffgioZZx0JKURblIYFxcb2KiF0CoYMjetY27elET7kUIZZjsg1acAZRnOJVZh/2umSb vS7xKoMNsxnNU2pM38Og7WZJC9sVzhwLuHKycDiAmW59EODXRaGvayJ6DX2l8oLXY23yOEe0Y1Nh gmP+XU8OaD9hCvsKCro= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1523369579769786.3023750929646; Tue, 10 Apr 2018 07:12:59 -0700 (PDT) Date: Tue, 10 Apr 2018 08:12:59 -0600 From: Thomas Fjellstrom To: "linux-kernel" Message-ID: <162afe714f8.b3d0e35172666.3338804793531720120@fjellstrom.ca> In-Reply-To: Subject: Methods to intercept accesses to mmaped page from userspace, or pretend to be mmio range MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Priority: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I'm working on a little driver that wants to pretend to be a section of mmio so it can intercept accesses, or intercept accesses to a page after it's been mmaped in by a user space program. So far I haven't found a method that works. I had been trying to allocate a page, and in the fault handler try and mark the page as readonly, and attempt to check for that in the next fault but as soon as the page is accessed its just assigned now, and there's no more faults (obviously). Other methods include trying ptrace but that seems not accessible from kernel modules, and inserting a uprobe on the instruction after the current one in the fault handler so I can remark the page as readonly but that requires some "clever" platform specific code to parse instructions which I'd prefer not to have to do. I don't really care about intercepting reads, but it might be something I care about at some point. At the very least I'd like to trap all writes, do some magic and then let the access proceede (or emulate it). I looked at providing my own pci bus and device, but I'm not sure that'd actually work. For some background, I'm trying to emulate the /dev/gpiomem char device from the raspberry pi that lets userspace programs mmap in the gpio registers on the bcm283x SoC. Is there any way to do what I want to do in a kernel module? Thanks, -- Thomas Fjellstrom thomas@fjellstrom.ca