From patchwork Thu Mar 16 13:53:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jon Medhurst (Tixy)" X-Patchwork-Id: 9628229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 39E6760244 for ; Thu, 16 Mar 2017 13:54:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2835027D13 for ; Thu, 16 Mar 2017 13:54:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CF5828599; Thu, 16 Mar 2017 13:54:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 867E527D13 for ; Thu, 16 Mar 2017 13:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=bWi8f2b2EgoIlYQGf6o6xRIKtCeu9KuZ1aYgtxx/s9E=; b=oGx mErNMlY2Nqh7/ADsU2szAsMDNAuj2FHNFFtjdU7nXoNBxBgmZ1LGrgFQwGgRlsHSiowH+eA7xS01S cigbZ20ueSQ3Yhi43JSqpG170uBBf7oUZy1l6rGTZBk5+bpHVIvMONHZpHHUMntKEXqTP4TpWyn5i 1UJkS3sshZYWt/qfN1+kolknmG+zWffdNrSTG0KtzBxU3sLcRXWuLhKddJ66KDUHr5T1usp1amHlK u2EMCByZF3VVYaYFCmuSdzFbcurR0GvI079Uh0Si0vbouZloj6QmqD9AiOiopOSIsDROOJyEHp7Tn 5dSAsItWXRRd2cpR/HJ940AuwfyBSiA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1coVrI-00066V-8X; Thu, 16 Mar 2017 13:54:28 +0000 Received: from smarthost03c.mail.zen.net.uk ([212.23.1.22]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1coVrD-0005tm-P2 for linux-arm-kernel@lists.infradead.org; Thu, 16 Mar 2017 13:54:26 +0000 Received: from [82.69.122.217] (helo=plug1) by smarthost03c.mail.zen.net.uk with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1coVqr-0004il-5W; Thu, 16 Mar 2017 13:54:01 +0000 Received: from linaro1 ([192.168.2.110] helo=linaro2.home) by plug1 with esmtp (Exim 4.80) (envelope-from ) id 1coVqp-0000yV-Uz; Thu, 16 Mar 2017 13:53:59 +0000 Received: from tixy by linaro2.home with local (Exim 4.88) (envelope-from ) id 1coVqp-000610-TT; Thu, 16 Mar 2017 13:53:59 +0000 From: Jon Medhurst To: Russell King Subject: [PATCH] arm: kprobes: Align stack to 8-bytes in test code Date: Thu, 16 Mar 2017 13:53:59 +0000 Message-Id: <20170316135359.23019-1-tixy@linaro.org> X-Mailer: git-send-email 2.11.0 X-Originating-smarthost03c-IP: [82.69.122.217] Feedback-ID: 82.69.122.217 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170316_065423_970532_51A2B672 X-CRM114-Status: GOOD ( 11.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wang Nan , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP kprobes test cases need to have a stack that is aligned to an 8-byte boundary because they call other functions (and the ARM ABI mandates that alignment) and because test cases include 64-bit accesses to the stack. Unfortunately, GCC doesn't ensure this alignment for inline assembler and for the code in question seems to always misalign it by pushing just the LR register onto the stack. We therefore need to explicitly perform stack alignment at the start of each test case. Without this fix, some test cases will generate alignment faults on systems where alignment is enforced. Even if the kernel is configured to handle these faults in software, triggering them is ugly. It also exposes limitations in the fault handling code which doesn't cope with writes to the stack. E.g. when handling this instruction strd r6, [sp, #-64]! the fault handling code will write to a stack location below the SP value at the point the fault occurred, which coincides with where the exception handler has pushed the saved register context. This results in corruption of those registers. Signed-off-by: Jon Medhurst --- I'm assuming the fact the alignment exception handler doesn't cope with instructions that push things to the stack isn't a problem that we need to be concerned about, given that compiler generated code and handwitten assembler shouldn't trigger this unless it's buggy? Russell, this is the last of several issues [1] [2] I found when testing Masami Hiramatsu's kprobe changes [3]. That is a total of 4 kprobes patches and 3 fixes around code patching. Assuming these are acceptable I can create a branch and a pull request, or feed them into the patch tracker, let me know. [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/494365.html [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/494370.html [3] https://lkml.org/lkml/2017/2/14/709 arch/arm/probes/kprobes/test-core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/arm/probes/kprobes/test-core.c b/arch/arm/probes/kprobes/test-core.c index c893726aa52d..1c98a87786ca 100644 --- a/arch/arm/probes/kprobes/test-core.c +++ b/arch/arm/probes/kprobes/test-core.c @@ -977,7 +977,10 @@ static void coverage_end(void) void __naked __kprobes_test_case_start(void) { __asm__ __volatile__ ( - "stmdb sp!, {r4-r11} \n\t" + "mov r2, sp \n\t" + "bic r3, r2, #7 \n\t" + "mov sp, r3 \n\t" + "stmdb sp!, {r2-r11} \n\t" "sub sp, sp, #"__stringify(TEST_MEMORY_SIZE)"\n\t" "bic r0, lr, #1 @ r0 = inline data \n\t" "mov r1, sp \n\t" @@ -997,7 +1000,8 @@ void __naked __kprobes_test_case_end_32(void) "movne pc, r0 \n\t" "mov r0, r4 \n\t" "add sp, sp, #"__stringify(TEST_MEMORY_SIZE)"\n\t" - "ldmia sp!, {r4-r11} \n\t" + "ldmia sp!, {r2-r11} \n\t" + "mov sp, r2 \n\t" "mov pc, r0 \n\t" ); } @@ -1013,7 +1017,8 @@ void __naked __kprobes_test_case_end_16(void) "bxne r0 \n\t" "mov r0, r4 \n\t" "add sp, sp, #"__stringify(TEST_MEMORY_SIZE)"\n\t" - "ldmia sp!, {r4-r11} \n\t" + "ldmia sp!, {r2-r11} \n\t" + "mov sp, r2 \n\t" "bx r0 \n\t" ); }