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: 20721 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f198.google.com (mail-gg0-f198.google.com [209.85.161.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 18EEE25E05 for ; Tue, 1 Oct 2013 15:59:42 +0000 (UTC) Received: by mail-gg0-f198.google.com with SMTP id j1sf2388894ggn.1 for ; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=EtVlPUT7WMKwPUK850ixXfvt8NjZ77/15s3To7olEu8=; b=SBDcVye3tmG+TjYUDX9WEUiVAJocooVKLuRrfIdrSD9XcXOIiVb9ymeIIX915i/69C aXstDURvRuBVs93qxpAyLbKAz5b3g/Er5LLYvCjyCQl4aiJak87noubEiGDps1WwQ8Rv LRk1SgpqLQmpWjF8VrON5AHYK3apFoIJ8gO9to6F05LQPzFfTHnIrht51nYx3MZntI0t NKdNkUAOFK+X3KYURDbe6s2PiGo1oelbuyG5rKAsmaXAee/Pt7v08eJe7fUmNoP+P2cR s6ld72gwSrf2F0AQ623R5Kz8UiUVsZ58jXLRwc9t8/pWVwANw86CYMRbkZ7+LJ0FtBKT 2wiw== X-Received: by 10.236.176.1 with SMTP id a1mr9690501yhm.10.1380643181838; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.29.129 with SMTP id k1ls113264qeh.75.gmail; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) X-Received: by 10.52.230.35 with SMTP id sv3mr1224038vdc.27.1380643181564; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id tj1si1460652vdc.105.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id ij15so4904943vcb.2 for ; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) X-Gm-Message-State: ALoCoQkmE/Qozblc5dE4Vf3CzLR5pTOeTOA/jgH4HTBy58Bkj10KxW5OpiBccbtnQDxBDxbqSjbf X-Received: by 10.52.230.202 with SMTP id ta10mr446555vdc.41.1380643181466; Tue, 01 Oct 2013 08:59:41 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp28274vcz; Tue, 1 Oct 2013 08:59:40 -0700 (PDT) X-Received: by 10.68.4.232 with SMTP id n8mr30615502pbn.9.1380643180395; Tue, 01 Oct 2013 08:59:40 -0700 (PDT) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id iv2si5324052pac.177.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 08:59:40 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of sandeepa.prabhu@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id g10so7429868pdj.16 for ; Tue, 01 Oct 2013 08:59:40 -0700 (PDT) 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 Cc: deepak.saxena@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, tixy@linaro.org, linaro-kernel@lists.linaro.org, patches@linaro.org, Sandeepa Prabhu 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sandeepa.prabhu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 */