Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp41396pxb; Thu, 30 Sep 2021 00:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmCMqMq9APy0vXQ9H6qIOWP/81rHY1jkRJ2xw9XHuZBtHML+s0DraqD05hSUOXN+8Zh0VK X-Received: by 2002:aa7:da98:: with SMTP id q24mr5139768eds.236.1632985960867; Thu, 30 Sep 2021 00:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632985960; cv=none; d=google.com; s=arc-20160816; b=ruV0Vnt+066KwkSKXWSlnwOO8DmMdSHf1iIAX5B+/GSewaeOMvZj4s3WeMMWu91Yrd o9hJ0ssWsyzUzWSK8A/Bm5GZgLx3cvJElauTsw5lo/sRZK1av2uy12/gpVw9pIWo1ytS lZmRmESCvhkOOY2YkflQJPTt+muyuhcF+T7zmRqYTQXK9OrXligZLq94a4sn9rKWJBIW PDBpTAqsQ3zYoaim9oU6+eK7s80Ciqd6M2GFTRTYbG1ZSGvmkaJh9Z/0bNLrN0YOeuxX 4aEp/kQ8fJto6HlSVTDLNGyD6pepqlN3O+fGQVkrGNwZ4Vmv+9rq/Js9TiNky8dkFNTD yNYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=YOdQwtcMZYIzjqr331yK+KysqYC2SsbB/EgxzPU0vIk=; b=l1Sal6ZNkf6jeVkgOeSnAxOzPJrZ4JMRWLOm66KBYXtXrw6O0N9fmqLpfihPljSzoH /yyuLfjgYdfb1zKlO/kPw1aGwDd3g4LYTKidHl6KCw6q+jEKK6BWoZKjDYfoAaqgzaN6 MH+YY6nxsCWIl3D/ld183NOlYLwOMeA8/yVTqcTz5kkhhTTscyPkczKg07ge4iTmDJ+e ny4VLa125wFnhw1KFqUaOWj0kwdpnmh8jV7B5hgPNXJaelnaludymQHeJ79s8UOpqum/ IHTHiTgYAkRJ3rVY7wrDAaTkqRHcjm6x1SR+BHlUtpCZ3Qw7yPfHGotrCr+uRbTnqgEE 2eOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 6si2454514ejk.125.2021.09.30.00.12.17; Thu, 30 Sep 2021 00:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348703AbhI3HLe (ORCPT + 99 others); Thu, 30 Sep 2021 03:11:34 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:13861 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348529AbhI3HLE (ORCPT ); Thu, 30 Sep 2021 03:11:04 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HKkkt5J6Bz8yyF; Thu, 30 Sep 2021 15:04:38 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 30 Sep 2021 15:09:17 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 30 Sep 2021 15:09:17 +0800 From: Kefeng Wang To: , , , , , , , , , CC: , , , , , Christophe Leroy , Kefeng Wang Subject: [PATCH v4 06/11] sections: Provide internal __is_kernel() and __is_kernel_text() helper Date: Thu, 30 Sep 2021 15:11:38 +0800 Message-ID: <20210930071143.63410-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930071143.63410-1-wangkefeng.wang@huawei.com> References: <20210930071143.63410-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An internal __is_kernel() helper which only check the kernel address ranges, and an internal __is_kernel_text() helper which only check text section ranges. Signed-off-by: Kefeng Wang --- include/asm-generic/sections.h | 29 +++++++++++++++++++++++++++++ include/linux/kallsyms.h | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 811583ca8bd0..a7abeadddc7a 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -186,4 +186,33 @@ static inline bool is_kernel_inittext(unsigned long addr) addr < (unsigned long)_einittext; } +/** + * __is_kernel_text - checks if the pointer address is located in the + * .text section + * + * @addr: address to check + * + * Returns: true if the address is located in .text, false otherwise. + * Note: an internal helper, only check the range of _stext to _etext. + */ +static inline bool __is_kernel_text(unsigned long addr) +{ + return addr >= (unsigned long)_stext && + addr < (unsigned long)_etext; +} + +/** + * __is_kernel - checks if the pointer address is located in the kernel range + * + * @addr: address to check + * + * Returns: true if the address is located in the kernel range, false otherwise. + * Note: an internal helper, only check the range of _stext to _end. + */ +static inline bool __is_kernel(unsigned long addr) +{ + return addr >= (unsigned long)_stext && + addr < (unsigned long)_end; +} + #endif /* _ASM_GENERIC_SECTIONS_H_ */ diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 8a9d329c927c..5fb17dd4b6fa 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -26,14 +26,14 @@ struct module; static inline int is_kernel_text(unsigned long addr) { - if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext)) + if (__is_kernel_text(addr)) return 1; return in_gate_area_no_mm(addr); } static inline int is_kernel(unsigned long addr) { - if (addr >= (unsigned long)_stext && addr < (unsigned long)_end) + if (__is_kernel(addr)) return 1; return in_gate_area_no_mm(addr); } -- 2.26.2