From patchwork Mon Apr 12 09:41:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12197449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E87C6C433B4 for ; Mon, 12 Apr 2021 09:45:47 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FCD861247 for ; Mon, 12 Apr 2021 09:45:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FCD861247 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To:From:Date: 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=5zdnTdmNpzhMr0wqL98arq2laB7V7WxYWUfDaRV2/hI=; b=pyo24tLMFkd6sBXpGzA+bEFoDL DMnQAYHwg7dGfamAVvIbpO+lE3KS+PkERuifP8SngkBpdak3gxaaMWnpf4kJNtBKJEB62DfsJSKxu 8NXTAl5gjsaQWj52shdvyCG9E1oaxejWpAWoEzYcV8zQuMySjBz+ZnFXnlkfLbJPvimDHjwZbTQtq K8Y9SYHLEoL4sgRlZHMZxtjfkqHvbF7uW5QUqZtIv4SlFrlQZA0BwpHGh8IyxoDQP8A4YoLuUCuSW 44L/w75jkwDDzY5zngr9T2UjtsxIrpw/kgEW/upKc9ADgj4uwZ+7iPTgVlH1vkLFumpEHRFdstDxP J5bcH86A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lVt6l-006KZ8-BM; Mon, 12 Apr 2021 09:43:52 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVt4E-006JrB-Qn for linux-arm-kernel@desiato.infradead.org; Mon, 12 Apr 2021 09:41:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version: Content-Transfer-Encoding:Content-Type:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:In-Reply-To:References; bh=LFTmj08wrDk1R0kR8vsX9vx+ugpaQV1brUMoz77Y6J0=; b=DB8bd0JB+L1xcot6KbnAOnRN/S Y4sxUbeRxLB7mjc3q+xoLsSFauqrgM32YexIx+0KRzcKoRXKl1MN2nxDK4cjCGSw0gx2OAzb1asyB HKSlggBVodkQPqXrPrV4RXij+JUzvr5PnZkTUGvQ5h5HDkXi2MQYlRFLl/X0ktHGAJuKvdfLVDyJH 9vfMBtaOZf7jgkCuXQAe/Yp4gWRRUti0Mz2V7d3b59QMBPfT6fwmEOnOXIWN80BTG/5BSGDJ7DHEK 54+E5MwwCrcu2OBAV2hwx3B4UNDwV0rnSACZhXNLmwm9dCVduZ6rPzWk/9i5xQcmBXyiRtLyN4u9T uPqM4wjw==; Received: from mail-bn7nam10on2058.outbound.protection.outlook.com ([40.107.92.58] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVt4C-00655i-3s for linux-arm-kernel@lists.infradead.org; Mon, 12 Apr 2021 09:41:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LR1aq6bXMlMQOsZWoopyJhJrngLc/DokFcoTF1oazKw3BUu9xBI4N1s+tLufbovGOerL4kD1y2LhQGCalGKtwrXchOJxy+XVtIT23a1A3lcjxcnYFkdiSwkDBVMBy/7lYjzCpiJTAeeq1BDHYYqDEg3eRvRrtSUt+GiAlGGx6v9DCaPZBV8VRnXIPJCI8LADbtH5qUW/3jQO9mFg738pv7Rc8d61Pa0gMmL3V5ax97T3Iv+j+RFRpWJc18GAyh1wWwdU9lr3s6lffwwtx3eo54bB+Xo0h68Yphnuka2tAOd4oqutV0XFGUEkTtofBXHo6wrByJexN4KWGe53o0SFTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LFTmj08wrDk1R0kR8vsX9vx+ugpaQV1brUMoz77Y6J0=; b=MZWYyRTJI1lJWHysKOedwrQhp3ELLN15eJDV1+I49iIvNI7Lm0+x3X0CDYZgoMHfriDCXPNn3Er5R58JQOiVnXJQVuoAcnUN4VphuTEufDaf4kegHNuhCmW28SsBH/ByiQ7fFGp1igFJ7a4sM2o7DRZprZTf99cCWbncAxsTU6FTkJ2J4pIe/kVQUP8TerSPNg9Hdp6pnaTzpsHfal6ej6AQvMF7sz+spQQ+sDw60uFmRsED+gRgIsl6MT1cuY3k19K8kFJzQNWhE/eF3fusoquD3T/xk4rwKyhuhQecYiw3pr13yowSRkYI6QVoYCeSzEjwe8uxGw80ajAn9DJXQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LFTmj08wrDk1R0kR8vsX9vx+ugpaQV1brUMoz77Y6J0=; b=Iq/quSN7lja1hQOWMSeVSOwvffN8IuBdyu4jVuQmpqNlOANDK5KW0Xc9dtTdGSdM9TOf9z0qWgHfvsnvR56nGh7AeeSp8IoMIzVyIwxQb8THXhV/sGd0tikyx2I54p1UIGu2DEoVglWOSP2CKyk/2hhh3GFqu+kos45dqGKr3/U= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=synaptics.com; Received: from BY5PR03MB5345.namprd03.prod.outlook.com (2603:10b6:a03:219::16) by SJ0PR03MB5504.namprd03.prod.outlook.com (2603:10b6:a03:28a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Mon, 12 Apr 2021 09:41:09 +0000 Received: from BY5PR03MB5345.namprd03.prod.outlook.com ([fe80::8569:341f:4bc6:5b72]) by BY5PR03MB5345.namprd03.prod.outlook.com ([fe80::8569:341f:4bc6:5b72%8]) with mapi id 15.20.4020.022; Mon, 12 Apr 2021 09:41:08 +0000 Date: Mon, 12 Apr 2021 17:41:01 +0800 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Masami Hiramatsu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liao Chang Subject: [PATCH] arm64: kprobes: Restore local irqflag if kprobes is cancelled Message-ID: <20210412174101.6bfb0594@xhacker.debian> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Originating-IP: [192.147.44.204] X-ClientProxiedBy: SJ0PR03CA0123.namprd03.prod.outlook.com (2603:10b6:a03:33c::8) To BY5PR03MB5345.namprd03.prod.outlook.com (2603:10b6:a03:219::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xhacker.debian (192.147.44.204) by SJ0PR03CA0123.namprd03.prod.outlook.com (2603:10b6:a03:33c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Mon, 12 Apr 2021 09:41:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4160eb4e-26e1-4df8-53a4-08d8fd97199f X-MS-TrafficTypeDiagnostic: SJ0PR03MB5504: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Icvy4ag0JNxA74qClbTJJfyUBeJ7jtj0jVbq6BP3A4QcHvdyoWut9s5QBoB/o1furhJ/WgRSl/lPaLF1epzzPUp85np5uH1wrc9c1f/keuM3NmiSUKhUzKOC3MV79cfCwIlO/BgbiTwxlsjCR3dJOTN+Qblkx4oV2fWCXQLEpxgT821EqsSIo5vz/xd2B/I3AwEdYlZVk7DIA+FPwZni2f7J0PIeuzrEqfnItxTcpMDGIfWfQqgOmvGJpH2abavRU5wsLYoNX7EIGQHOupgKQmHdGVeT1HvhfCO4Fti0gwNPbc0wlQ4grP0UbssjB/Krnyy37cTqu0BipiLcGK9gL7jQVtQ6PIYlOiZ+dxrZ4kBm8orJLVBP3SlyrAgNYcQ7wSk8riePJKwbo73MpwiiAQ2B1nrcwqBYrXZlSS9hfbhUr01D1qrKJKH5nt0VIXOuc4kBmnVaz9jQB7EOs7bL8Hl1lhf2SMudHasOryiSm5B1nq9Wldzm6AtdVS1EmXIT9sKNT1gZ2Ru65V0NBsRuPgJWe/fr7NzzgeLzzdbFRJapSvrzAeJXqqDmXEuDKiP6SXypIXC4B9sbeRM7N1QOF4Dmcx2NVjiyGFKI3OYdttowHC+e7eMmXHjFDeS4f6TIrf0e/QKJdcyQyHRphbis1SNUpOYk7rgK54yeiS/0uys= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BY5PR03MB5345.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(366004)(39860400002)(136003)(346002)(396003)(86362001)(38100700002)(2906002)(9686003)(4326008)(7696005)(52116002)(66946007)(1076003)(956004)(38350700002)(55016002)(6666004)(316002)(478600001)(16526019)(186003)(66556008)(6506007)(83380400001)(110136005)(66476007)(26005)(8676002)(8936002)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5Tgy6j9U4AwaAZ4nouLTxFaHGQgMVVa9xzusp9IQwmutUSeKBTamOyph0aw+dZ+G08jqFoP4d0xue0Typ2a6FTnzTQJBGZpUbYUvxR2xOBTdUbanIzn7TmCKAj2nRSnifBVUvbZaLxaYvQ2cceHWi7QGDOO5dcB5Jd3sHF2ms1SIUEoYrzbPoYUTAFV7SS8CSKJ/8RkDrcF2Waue0kI+gXrYZELppTMGf6f+qv4qDOnfxoHS1OeOCEmX5Q/+2YS6thRPx8QHuZ+Q+wr1cX9tbQCg7h5iUuUFoy0ybfRn8MiemitdVTMoXi+6jgrLPjKk33JHnOl07Kt0B08gkAcNgWe7Yh1v/KC5QxalyX5RT2lkvZtp34boilwWje2gLE8l6bBa+QOKQL7lfezhlDruc9KFmxutp6XPadN2ORgLUsyjTAedO7yZlDNu41KDWnAMu93CItaGNASX+B2QqvtTHEshWF5604JyS8n9gh+6eYXtM7Ol3HsKuvVQIBI3G15ZarHVjyS/vBnovnJ1e/7azshXqRyBYtyuloGnRHTydMQk7v1rp6YY6H7I1xs4VaSu5c1xKyYESRmnzo0Qp0OpfJ9+QVOLAsJ/QzuNOT634zcEE71ZaSVPMPhXUToehxPUl1kpwoGLDo7R3Kb1kUHKVKbp5QrYFYsuJ+e40uJB/6k+U4s6IUmSyGoZqB365s98L+XRNRMXSJQ1X51YBy8/CUvpg13WHi1mcPju2lnRrJP3Cjz+YdO9apWqanfxpn8pYvgzcYm11UHSpsJ2gpKsj9qf3BUAfWkEV3niVlk9WZ8lBYA0x0PIDJDQm5yqrLjZvdqKsUCURP6x5y3RTgi+KtwBXyxkSrF+97WY1c2eiVfSHnzdNzVM9Rw4mxPF8OA1I7/AIJeBjb6j2jNUNec70BU7v5JjI7s+2PDF21TPVibnJ2TzesIIZQ+nJRamY4AKzKUOAl56P4uiw8HJVE3+EB7tIjGEM5UdapV4uUHeWyb2z6RrvTZNsbDociY26tRwHS9u7+gw7/InvetHXtEdaBaP7AdmV5LLYz+8HRbxwEcmszZ63lGdi/0IXO5JJJ8vUAKDq0W7zc0nc/ONZutGF6q0IwbE771r528lDqvkEuygxOCioC9vxux17l5RYzzwGYpc9a2WESJtTxtrhKPyl6iKvWCpc5svC4cwRpqCRpUaDkMDGHbjh/m89to6o+w9wtBFyKPMgcidsPLSE+lBWWZLX3nBbK4QWmnoj5fP9knMb0+ogoKRTrDArgHlVz/ceCyQnQsk2JAfWFFhaSdlOm+PGzDXSdPR7cEeGrUbjJK9WTHSxKqtwloOZIMMMjkT X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4160eb4e-26e1-4df8-53a4-08d8fd97199f X-MS-Exchange-CrossTenant-AuthSource: BY5PR03MB5345.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2021 09:41:08.6319 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f5vs1ROkkGGGHxQEOHI4xNo505rx6aHJaDnWpebW/JVF3TjN4mUlGQt67EO356RjU9Jq5j4kzsWu9Um8HQCEmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB5504 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210412_024112_254068_232EA74B X-CRM114-Status: GOOD ( 11.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If instruction being single stepped caused a page fault, the kprobes is cancelled to let the page fault handler continue as a normal page fault. But the local irqflags are disabled so cpu will restore pstate with DAIF masked. After pagefault is serviced, the kprobes is triggerred again, we overwrite the saved_irqflag by calling kprobes_save_local_irqflag(). NOTE, DAIF is masked in this new saved irqflag. After kprobes is serviced, the cpu pstate is retored with DAIF masked. This patch is inspired by one patch for riscv from Liao Chang. Signed-off-by: Jisheng Zhang Acked-by: Masami Hiramatsu --- arch/arm64/kernel/probes/kprobes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index 66aac2881ba8..85645b2b0c7a 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -267,10 +267,12 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) if (!instruction_pointer(regs)) BUG(); - if (kcb->kprobe_status == KPROBE_REENTER) + if (kcb->kprobe_status == KPROBE_REENTER) { restore_previous_kprobe(kcb); - else + } else { + kprobes_restore_local_irqflag(kcb, regs); reset_current_kprobe(); + } break; case KPROBE_HIT_ACTIVE: