From patchwork Tue Oct 1 15:57:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeepa Prabhu X-Patchwork-Id: 2970771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BE8DF9F245 for ; Tue, 1 Oct 2013 16:00:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60DB8203FD for ; Tue, 1 Oct 2013 16:00:47 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E44492041C for ; Tue, 1 Oct 2013 16:00:45 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VR2NC-0004h6-8z; Tue, 01 Oct 2013 16:00:30 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VR2N3-0005jC-EC; Tue, 01 Oct 2013 16:00:21 +0000 Received: from mail-pd0-f170.google.com ([209.85.192.170]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VR2Mj-0005cr-DU for linux-arm-kernel@lists.infradead.org; Tue, 01 Oct 2013 16:00:02 +0000 Received: by mail-pd0-f170.google.com with SMTP id x10so7480734pdj.29 for ; Tue, 01 Oct 2013 08:59:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EtVlPUT7WMKwPUK850ixXfvt8NjZ77/15s3To7olEu8=; b=OU3tk2Hh8KvxxD11hiRT3jmYPqZdcuXnw0uXpGB9imqrxG3EsDdv8KHw3UvKhmS95t gsQ5j6NOngcQH5KNZPOnMT2COeHlEs8vFr7/KyvVCiKoQG30tEa/SjqUcPEqv0n1VAi5 NZ5SS2LQZj6+//Bi4LYDeFvMH5USYMpSyNvdIF5HgbjeK9X0RUwxkdGOJlYoNtUQdUAi orsX7yg3NAaoLoCJECWXRBmXMYCOCN0Q6oJUY5nMC5rr54crT6C8USuMfwhgBUsAC+TC z2bVzd0wsSWu4shXfkJFzCjtwcpnECD+GZxuvZkpKuzGbF9G/R2I7owk93gCWKikakkp /UPA== X-Gm-Message-State: ALoCoQmyFJnd//i6uxWw1VrbuR+aiIiYFCvOHG49XSWNdyoyDECO1OJKSvRGcQMHwqNKjCGebkyV X-Received: by 10.68.11.103 with SMTP id p7mr29867925pbb.84.1380643179977; Tue, 01 Oct 2013 08:59:39 -0700 (PDT) Received: from linaro-workstation.ban.broadcom.com ([202.122.18.226]) by mx.google.com with ESMTPSA id nj9sm7593660pbc.13.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:39 -0700 (PDT) From: Sandeepa Prabhu To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RFC v1 2/5] arm64: Kernel code patching support Date: Tue, 1 Oct 2013 21:27:57 +0530 Message-Id: <1380643080-8984-3-git-send-email-sandeepa.prabhu@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380643080-8984-1-git-send-email-sandeepa.prabhu@linaro.org> References: <1380643080-8984-1-git-send-email-sandeepa.prabhu@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131001_120001_739554_F0185DC2 X-CRM114-Status: GOOD ( 13.32 ) X-Spam-Score: -1.9 (-) Cc: tixy@linaro.org, deepak.saxena@linaro.org, linaro-kernel@lists.linaro.org, patches@linaro.org, Sandeepa Prabhu , catalin.marinas@arm.com, will.deacon@arm.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement API for kernel code section. These API supports modifying kernel text section, one instruction at a time. This functionality will be used in kprobes handlers to place/replace software breakpoints, kprobe breakpoints cannot be placed inside these handlers so will be added under __kprobes section. Signed-off-by: Sandeepa Prabhu --- arch/arm64/kernel/patch.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/patch.h | 20 ++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 arch/arm64/kernel/patch.c create mode 100644 arch/arm64/kernel/patch.h diff --git a/arch/arm64/kernel/patch.c b/arch/arm64/kernel/patch.c new file mode 100644 index 0000000..880742d --- /dev/null +++ b/arch/arm64/kernel/patch.c @@ -0,0 +1,58 @@ +/* + * arch/arm64/kernel/patch.c + * + * Copyright (C) 2013 Linaro Limited. + * Based on arch/arm/kernel/patch.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ +#include +#include +#include +#include + +#include "patch.h" + +struct patch { + void *addr; + unsigned int insn; +}; + +/* Patching kernel text -AArch64 mode */ +void __kprobes __patch_text(void *addr, unsigned int insn) +{ + int size = sizeof(u32); + + /* AArch64 32-bit alignment check */ + if ((unsigned long)addr % size) + return; + + /* little-endian mode: does it work for big-endian mode? */ + *(u32 *) addr = insn; + + flush_icache_range((uintptr_t) (addr), (uintptr_t) (addr) + size); +} + +static int __kprobes patch_text_stop_machine(void *data) +{ + struct patch *patch = data; + + __patch_text(patch->addr, patch->insn); + return 0; +} + +void __kprobes patch_text(void *addr, unsigned int insn) +{ + struct patch patch = { + .addr = addr, + .insn = insn, + }; + stop_machine(patch_text_stop_machine, &patch, cpu_online_mask); +} diff --git a/arch/arm64/kernel/patch.h b/arch/arm64/kernel/patch.h new file mode 100644 index 0000000..e9d5e75 --- /dev/null +++ b/arch/arm64/kernel/patch.h @@ -0,0 +1,20 @@ +/* + * arch/arm/kernel/patch.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#ifndef _AARCH64_KERNEL_PATCH_H +#define _AARCH64_KERNEL_PATCH_H + +void patch_text(void *addr, unsigned int insn); +void __patch_text(void *addr, unsigned int insn); + +#endif /* _AARCH64_KERNEL_PATCH_H */