Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12948547rwl; Wed, 4 Jan 2023 01:00:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwBEL8IJpWamdLQkRs+uuV8+Qzm5QukGrwDJK0B93OrMk4KmNZ6BK0wKjxhYCIlsSaG9xQ X-Received: by 2002:a05:6a20:1d60:b0:af:adfe:e20d with SMTP id cs32-20020a056a201d6000b000afadfee20dmr52373353pzb.23.1672822829206; Wed, 04 Jan 2023 01:00:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672822829; cv=none; d=google.com; s=arc-20160816; b=E/HtBXhHhwUouGv7f4lmqSolLLloh2mv/Ksj1N83fY8OsL3i2ejNN6/VzV85Ec3FSw N0yhEm1BnFLNOwsn82aelF4/QCSni/K7qMpGs17eTLeZ6X2u2O2bGym7Fyngw2bXevJK vwuTrVGvRjes2QNpcflelU0b41HaqtPboYfBdZ/dk9xqk3JQZdBdm2/gXyvMMgZxkwgX jg9Hg5vLQFnruKS5RI6I+l7+Jt0M/OyvoeRXaU86w5Rg5Do5ENVoAKgRVty0IXJLpc34 qQPl5LQm4iTkP6KGfnsI8yH4cWlPVm8Ors1bNrRuUYZE6rkzwyuZ8lkqqT+8sV8SwaJw AMDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=MccSa+v32RHtqj8FZYl6CaTEJ8IUex4dXfdQFmum3sc=; b=lM2DV2uysh4+AXBqkKtdrwqTR04K/XRZSC65HdYASxr7nnSP6cwTsLH7/lVQAZp9Wb ZkUdqnB8piozKSFXCZqJU06qj8/C95Y3lOYVWwDMjdm1ZKQEz93PXcw7mnZ7qMZeKIgC 89hnxEkFCjCMgSsGIoWVDBFdquppO8OC+IFHycBUH4zBpXI0DSsDJ5invxoTwdgLSC0l L5pj91V6qp+azokbiQMgpCCYOGz13iaHjI6PcaGHRMxe8ky1Rdg+HOvaMzwYQIQRiQzK L2g33amD+3eCZ3rGwtKBPhwQXozl2LPm4YZLbp3n+PumJJP+LUVprP/I24EZtw8qWOWY 3lrQ== 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 x23-20020a170902b41700b00188f663e2d7si32164637plr.421.2023.01.04.01.00.21; Wed, 04 Jan 2023 01:00:29 -0800 (PST) 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 S234099AbjADIer (ORCPT + 57 others); Wed, 4 Jan 2023 03:34:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbjADIem (ORCPT ); Wed, 4 Jan 2023 03:34:42 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FC6F1A222 for ; Wed, 4 Jan 2023 00:34:38 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Nn2tH1RsPz16MML; Wed, 4 Jan 2023 16:33:11 +0800 (CST) Received: from [10.67.110.108] (10.67.110.108) 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.34; Wed, 4 Jan 2023 16:34:36 +0800 Message-ID: <9dacbd7a-6dc5-099c-d427-b20bfa22aabd@huawei.com> Date: Wed, 4 Jan 2023 16:34:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v5 3/9] riscv/kprobe: Prepare the skeleton to prepare optimized kprobe To: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Chen Guokai , , , , , , CC: , References: <20221224114315.850130-1-chenguokai17@mails.ucas.ac.cn> <20221224114315.850130-4-chenguokai17@mails.ucas.ac.cn> <87v8lovmoa.fsf@all.your.base.are.belong.to.us> From: "liaochang (A)" In-Reply-To: <87v8lovmoa.fsf@all.your.base.are.belong.to.us> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] 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=-7.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 在 2023/1/3 2:03, Björn Töpel 写道: > Chen Guokai writes: > >> From: Liao Chang > >> arch/riscv/kernel/probes/opt.c | 107 ++++++++++++++++++++++++++++++++- >> >> diff --git a/arch/riscv/kernel/probes/opt.c b/arch/riscv/kernel/probes/opt.c >> index 56c8a227c857..a4271e6033ba 100644 >> --- a/arch/riscv/kernel/probes/opt.c >> +++ b/arch/riscv/kernel/probes/opt.c > >> @@ -24,7 +72,64 @@ int arch_check_optimized_kprobe(struct optimized_kprobe *op) >> int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, >> struct kprobe *orig) >> { >> - return 0; >> + long rel; >> + int rd, ra, ret; >> + kprobe_opcode_t *code = NULL, *slot = NULL; >> + >> + if (!can_optimize((unsigned long)orig->addr, op)) >> + return -EILSEQ; >> + >> + code = kzalloc(MAX_OPTINSN_SIZE, GFP_KERNEL); >> + slot = get_optinsn_slot(); >> + if (!code || !slot) { >> + ret = -ENOMEM; >> + goto on_error; >> + } >> + >> + /* >> + * Verify if the address gap is within 4GB range, because this uses >> + * a auipc+jalr pair. > > Try to be consistent. You're mixing "AUIPC/JALR" with "auipc+jalr". OK,i will use AUIPC/JALR in all commit messages and comments of this series. > >> + */ >> + rel = (unsigned long)slot - (unsigned long)orig->addr; >> + if (!in_auipc_jalr_range(rel)) { >> + /* >> + * Different from x86, we free code buf directly instead >> of > > Reword for readers that are not familiar with x86. OK, BTW, i think the code following tag on_error is fairly self-explanatoty, perhaps this comment is no need anymore. > > > Björn -- BR, Liao, Chang