Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp321030rwb; Mon, 26 Sep 2022 19:51:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5REXSYnqnfVO1/Hx069ZlPrJA455VKqA67iZCzEsN8+OGXFOWq7NRyTTbE8vnvQcyJ6x/h X-Received: by 2002:a17:902:eb82:b0:176:c0e0:55c1 with SMTP id q2-20020a170902eb8200b00176c0e055c1mr24969659plg.168.1664247098915; Mon, 26 Sep 2022 19:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664247098; cv=none; d=google.com; s=arc-20160816; b=QlZgB+SeDs6xia1ap2psqzdNt+YlU1X/G3iO/fLot8IX2JCYnX2TVYmLNMfmmpq5Cq CfGVvZspIb7qjiG0wq0J/v0NceovzlCuXuEVXGMeFeq+elgI0eLyCOPCGPoKmf/hmYbE oqgTUVOxEzwTMJaytrHPnQO48q+Z4hiTLCcV642INZOkqcxu3+ANuOxPL8r9yg1TrKCp lrkrR8Fp9qrclELsaTjiPpPfyo7gtGgOlBMykoNcMJpEGgqpE6DT4Rn7BObk+26a3UdT 6e4Ww+KizKHDEQQTTMUBOE4wSf+gwrWJFdo4kYSJJaKnLM0oj//+C/PvSWIUuB97OU3O lYuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=6x/exLWJVeKMGnYytjy5T76eh+ojkY8OyFVoOGTMwCs=; b=m4wjsgSzmw6F7ozSGBF8nVdpfEerwj8FyGglBy4XVb47CQhWpw4mjzLE26ZGz2OQux Mih5Jgm7R5pKSU257Ef5ouhTWhmSfSQGS2VHOqc0OUy1j4WWyfqqWf7OoilyoVAGXXtO QdtMOnSxtVWXdzZGues8qMUIGMkGuC0ZrVdGl6IdMHdGLJWRugGDuWwyvwsWscj2tVCs ep6wOW+MuMBzr5EH2/r8ZBWfUpcusqPNsrW1vR8wjdGO6SbQL6Vt5eooIuYeeHLOFcli 29VE0slKHdaQTZeth9aRY9JXo2fFUKvAGnDtbIOff6GoHiuQWKAOopc/Oda2gUHvrIEh j2nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 3-20020a630f43000000b0043bed4b0253si501428pgp.116.2022.09.26.19.51.27; Mon, 26 Sep 2022 19:51:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbiI0C2o (ORCPT + 99 others); Mon, 26 Sep 2022 22:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbiI0C2X (ORCPT ); Mon, 26 Sep 2022 22:28:23 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CBA9F194; Mon, 26 Sep 2022 19:28:22 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mc3Pf02shzpTdm; Tue, 27 Sep 2022 10:25:25 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 10:28:20 +0800 From: Liao Chang To: , , , , , , , , , , CC: , , , Subject: [PATCH 1/3] riscv/kprobe: Optimize the performance of patching single-step slot Date: Tue, 27 Sep 2022 10:24:33 +0800 Message-ID: <20220927022435.129965-2-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220927022435.129965-1-liaochang1@huawei.com> References: <20220927022435.129965-1-liaochang1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Single-step slot would not be used until kprobe is enabled, that means no race condition occurs on it under SMP, hence it is safe to pacth ss slot without stopping machine. Acked-by: Masami Hiramatsu (Google) Signed-off-by: Liao Chang --- arch/riscv/kernel/probes/kprobes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index e6e950b7cf32..bc1f39b96e41 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -24,12 +24,14 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *); static void __kprobes arch_prepare_ss_slot(struct kprobe *p) { unsigned long offset = GET_INSN_LENGTH(p->opcode); + kprobe_opcode_t slot[MAX_INSN_SIZE]; p->ainsn.api.restore = (unsigned long)p->addr + offset; - patch_text(p->ainsn.api.insn, p->opcode); - patch_text((void *)((unsigned long)(p->ainsn.api.insn) + offset), - __BUG_INSN_32); + memcpy(slot, &p->opcode, offset); + *(kprobe_opcode_t *)((unsigned long)slot + offset) = __BUG_INSN_32; + patch_text_nosync(p->ainsn.api.insn, slot, + offset + GET_INSN_LENGTH(__BUG_INSN_32)); } static void __kprobes arch_prepare_simulate(struct kprobe *p) -- 2.17.1