From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FDBDC433FE for ; Fri, 18 Nov 2022 01:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240902AbiKRBlP (ORCPT ); Thu, 17 Nov 2022 20:41:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234794AbiKRBlK (ORCPT ); Thu, 17 Nov 2022 20:41:10 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD87B50 for ; Thu, 17 Nov 2022 17:41:07 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NCztn5Y6gzJnfJ; Fri, 18 Nov 2022 09:37:53 +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.31; Fri, 18 Nov 2022 09:41:03 +0800 Message-ID: Date: Fri, 18 Nov 2022 09:41:03 +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 v4 2/8] riscv/kprobe: Allocate detour buffer from module area To: Steven Rostedt , Chen Guokai CC: , , , , , , , Peter Zijlstra , Linus Torvalds References: <20221106100316.2803176-1-chenguokai17@mails.ucas.ac.cn> <20221106100316.2803176-3-chenguokai17@mails.ucas.ac.cn> <20221116202521.6c528955@gandalf.local.home> From: "liaochang (A)" In-Reply-To: <20221116202521.6c528955@gandalf.local.home> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/11/17 9:25, Steven Rostedt 写道: > On Sun, 6 Nov 2022 18:03:10 +0800 > Chen Guokai wrote: > >> @@ -84,6 +85,30 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) >> } >> >> #ifdef CONFIG_MMU >> +#if defined(CONFIG_OPTPROBES) && defined(CONFIG_64BIT) >> +void *alloc_optinsn_page(void) >> +{ >> + void *page; >> + >> + page = __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, >> + MODULES_END, GFP_KERNEL, >> + PAGE_KERNEL, 0, NUMA_NO_NODE, >> + __builtin_return_address(0)); >> + if (!page) >> + return NULL; >> + >> + set_vm_flush_reset_perms(page); >> + /* >> + * First make the page read-only, and only then make it executable to >> + * prevent it from being W+X in between. >> + */ >> + set_memory_ro((unsigned long)page, 1); >> + set_memory_x((unsigned long)page, 1); > > FYI, the above combination is going to be going away: > > https://lore.kernel.org/all/Y10OyLCLAAS6rsZv@hirez.programming.kicks-ass.net/ Thanks for reminding, i will use this API in next revision. > -- Steve > > >> + >> + return page; >> +} >> +#endif >> + > -- BR, Liao, Chang