From patchwork Wed Jul 19 07:51:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 122441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2276426vqt; Wed, 19 Jul 2023 01:06:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlGymfQuQ0NHLbY6tNXQnURRFQiFYMO0fP40i+Wlm3aMeuge7ZfYzl6mWJyYpFDKqAk+dNDh X-Received: by 2002:a17:907:90d5:b0:988:4dc:e3a3 with SMTP id gk21-20020a17090790d500b0098804dce3a3mr1406552ejb.31.1689753993889; Wed, 19 Jul 2023 01:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689753993; cv=none; d=google.com; s=arc-20160816; b=OZxMqpR7Ixqhrg1vlMLRE74z3WogD+Pc3Ku832NZiFETVjXusJy9pbh3QKmnHn2bW3 hCRap/7KEBXpgnQOuLExeTJevP1183jEh/1AtBWkTSua9lDS+ROxWC20eqvPlYQc2iXP NtWvSWHE2f6O6zytsfuYhej1AgLpeZOOehZR8yYhLiGSuhuKDrutNg30HdrRTYpzNZMS XKiWe3iYQlD98eMNK4t2IKt5yyKsGxZVEx7HUFYe6p/8gAkiyhPXfpgCC45NemACdOb2 70//ECmGeL/8z4L45oTAR2E6Ih/ldAr8xlyhr9N7GZHY8kO3bQ/EzeOhFOC/RVZe4lRP 8ytQ== 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=MPN5dJ7jQjJof++e0GOGPjqr9j7WBPBqmO8MjvBjRlI=; fh=kyKsRzMh6J2IhIpW9KkSIrCEAGtpSxp+jjyASgyRbu8=; b=pb+mH1N9ABNi2FOMs5wG8i3656svz6Ii233sexmJoo9fNEuecA20EBs1TGeJw/vwkT Ft6wYE6JsOaZSotzNTLbOQdRdzmIb+r6wjFaFXjJbrQ0mQqI02gU7oJvCiDQbsucgfLj iVgvskq1o0BH27fSoTY8B0FQBlyzxTF3KHV/VC82cbM/RsogWl5GIanZGlDrx+MzYZg2 zo3ziNoHFUntP7VXa04EzsDhGFcwxxp+NYmqmIaO5AW6rVlKqFckuh5w7HVVczrwWURK G0SOgNaM3QVW4qmV2X8o33ilyPoqn/gcK344oPLHFUwwjKPYG3F5+UQVwNgR1JF7T0Qz 4GOA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a170906b30700b009829cb69a02si2230404ejz.1034.2023.07.19.01.06.09; Wed, 19 Jul 2023 01:06:33 -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 S229732AbjGSHkR (ORCPT + 99 others); Wed, 19 Jul 2023 03:40:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjGSHkJ (ORCPT ); Wed, 19 Jul 2023 03:40:09 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60F721FF1; Wed, 19 Jul 2023 00:40:07 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R5SPg5zCWz18Ljp; Wed, 19 Jul 2023 15:39:19 +0800 (CST) 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.2507.27; Wed, 19 Jul 2023 15:40:02 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang , =?utf-8?q?Christian_G=C3=B6ttsche?= , David Hildenbrand Subject: [PATCH v2 1/4] mm: factor out VMA stack and heap checks Date: Wed, 19 Jul 2023 15:51:11 +0800 Message-ID: <20230719075127.47736-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719075127.47736-1-wangkefeng.wang@huawei.com> References: <20230719075127.47736-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771835484147508623 X-GMAIL-MSGID: 1771835484147508623 Factor out VMA stack and heap checks and name them vma_is_initial_stack() and vma_is_initial_heap() for general use. Cc: Christian Göttsche Cc: David Hildenbrand Signed-off-by: Kefeng Wang Reviewed-by: David Hildenbrand --- fs/proc/task_mmu.c | 24 ++++-------------------- fs/proc/task_nommu.c | 15 +-------------- include/linux/mm.h | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 507cd4e59d07..bf25178ae66a 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -236,21 +236,6 @@ static int do_maps_open(struct inode *inode, struct file *file, sizeof(struct proc_maps_private)); } -/* - * Indicate if the VMA is a stack for the given task; for - * /proc/PID/maps that is the stack of the main task. - */ -static int is_stack(struct vm_area_struct *vma) -{ - /* - * We make no effort to guess what a given thread considers to be - * its "stack". It's not even well-defined for programs written - * languages like Go. - */ - return vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack; -} - static void show_vma_header_prefix(struct seq_file *m, unsigned long start, unsigned long end, vm_flags_t flags, unsigned long long pgoff, @@ -327,13 +312,12 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) goto done; } - if (vma->vm_start <= mm->brk && - vma->vm_end >= mm->start_brk) { + if (vma_is_initial_heap(vma)) { name = "[heap]"; goto done; } - if (is_stack(vma)) { + if (vma_is_initial_stack(vma)) { name = "[stack]"; goto done; } @@ -1971,9 +1955,9 @@ static int show_numa_map(struct seq_file *m, void *v) if (file) { seq_puts(m, " file="); seq_file_path(m, file, "\n\t= "); - } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { + } else if (vma_is_initial_heap(vma)) { seq_puts(m, " heap"); - } else if (is_stack(vma)) { + } else if (vma_is_initial_stack(vma)) { seq_puts(m, " stack"); } diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 2c8b62265981..a8ac0dd8041e 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -121,19 +121,6 @@ unsigned long task_statm(struct mm_struct *mm, return size; } -static int is_stack(struct vm_area_struct *vma) -{ - struct mm_struct *mm = vma->vm_mm; - - /* - * We make no effort to guess what a given thread considers to be - * its "stack". It's not even well-defined for programs written - * languages like Go. - */ - return vma->vm_start <= mm->start_stack && - vma->vm_end >= mm->start_stack; -} - /* * display a single VMA to a sequenced file */ @@ -171,7 +158,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) if (file) { seq_pad(m, ' '); seq_file_path(m, file, ""); - } else if (mm && is_stack(vma)) { + } else if (mm && vma_is_initial_stack(vma)) { seq_pad(m, ' '); seq_puts(m, "[stack]"); } diff --git a/include/linux/mm.h b/include/linux/mm.h index 2dd73e4f3d8e..51f8c573db74 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -822,6 +822,27 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma) return !vma->vm_ops; } +static inline bool vma_is_initial_heap(const struct vm_area_struct *vma) +{ + return vma->vm_start <= vma->vm_mm->brk && + vma->vm_end >= vma->vm_mm->start_brk; +} + +/* + * Indicate if the VMA is a stack for the given task; for + * /proc/PID/maps that is the stack of the main task. + */ +static inline bool vma_is_initial_stack(const struct vm_area_struct *vma) +{ + /* + * We make no effort to guess what a given thread considers to be + * its "stack". It's not even well-defined for programs written + * languages like Go. + */ + return vma->vm_start <= vma->vm_mm->start_stack && + vma->vm_end >= vma->vm_mm->start_stack; +} + static inline bool vma_is_temporary_stack(struct vm_area_struct *vma) { int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP); From patchwork Wed Jul 19 07:51:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 122448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2283349vqt; Wed, 19 Jul 2023 01:22:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGv4q1ryA2xJMJys+afRjPB1CfVmueE73tQfX8sfVMhlgNIGqSJMXmGmL3/4vaQXu9Yvazq X-Received: by 2002:a2e:701a:0:b0:2b6:9ab8:9031 with SMTP id l26-20020a2e701a000000b002b69ab89031mr1247667ljc.16.1689754920003; Wed, 19 Jul 2023 01:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689754919; cv=none; d=google.com; s=arc-20160816; b=mJw3sfW5yVHjLJPK2qBcKxi22DJ2iemNkXd2gSgVzIwTlkyJitzl8XXyfRbqtVoikq r/vp+V/ZgAeHDUMcMTCb+FF3KlM19jm+EkKuDeB8JMiHRPwZB5DkR6F5jJFNGab0h0jK ja1niWdrd2vOWscg7GKVJhKSEFIN/Jh2XwWxMFJXq4FtidUFVoipI4c0MhB+JQWaGB5j fSoXVTJIblMaCVmKru4ayB7jlqSGpLKjaHZZptw9vx+vo+wbY6113LgDPJKh1uI3utUp zwfzEYFbLwM5uoGlNL1igarvrit7Z0KvJyL4y1M89QfPwTvqA7dFbyaBRipRz7FXJgdF VXsQ== 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=5cWrWwlManqrudfdOvGGdBUURxPlu26h088SbWtIKGE=; fh=N4J70hJn8skiBpfYtsw9ilEiGztepr9OGmrCWjv2bPM=; b=l4UFD/hNVqcOCahGoSx70dxbOZRe+iobUusqdcUrMuDyHHrJLKZ9St4qQOjujdQS99 KIB5qaJJL26afTOKebmMqxSJnTb8el2ZKzHOZiTDZZttKPbHs+LgsvUWB3SiTJ+AE4Kn lSjDihplu4ulcCfHfI9k7I6CXwU1jfFZCnUU+csDcsUa9xBmLgIzYk9LtZA4SYm/XG4k PICCjQ6bPb3KuxBXJYs6iWrtXTnDiYUZmBj5eBtQNfdlP67Ig2w43vgsGw3QSu3kwyrC AE7nzyYcjJ9zTXusj6NarwQjHQzZcl/oU1p6tCBXGQPzXGcoliiJixlwQiphddWDdtkg V8qw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rh7-20020a17090720e700b00987b0a5f325si2407784ejb.1043.2023.07.19.01.21.36; Wed, 19 Jul 2023 01:21:59 -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 S229673AbjGSHkU (ORCPT + 99 others); Wed, 19 Jul 2023 03:40:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjGSHkI (ORCPT ); Wed, 19 Jul 2023 03:40:08 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0CED1FC4; Wed, 19 Jul 2023 00:40:06 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R5SPj4kq2z18Lgs; Wed, 19 Jul 2023 15:39:21 +0800 (CST) 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.2507.27; Wed, 19 Jul 2023 15:40:04 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH v2 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap() Date: Wed, 19 Jul 2023 15:51:14 +0800 Message-ID: <20230719075127.47736-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719075127.47736-1-wangkefeng.wang@huawei.com> References: <20230719075127.47736-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771836455165306288 X-GMAIL-MSGID: 1771836455165306288 Use the helpers to simplify code, also kill unneeded goto cpy_name. Cc: Peter Zijlstra Cc: Arnaldo Carvalho de Melo Signed-off-by: Kefeng Wang Reviewed-by: David Hildenbrand --- kernel/events/core.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 78ae7b6f90fd..d59f6327472f 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8685,22 +8685,14 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) } name = (char *)arch_vma_name(vma); - if (name) - goto cpy_name; - - if (vma->vm_start <= vma->vm_mm->start_brk && - vma->vm_end >= vma->vm_mm->brk) { - name = "[heap]"; - goto cpy_name; + if (!name) { + if (vma_is_initial_heap(vma)) + name = "[heap]"; + else if (vma_is_initial_stack(vma)) + name = "[stack]"; + else + name = "//anon"; } - if (vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack) { - name = "[stack]"; - goto cpy_name; - } - - name = "//anon"; - goto cpy_name; } cpy_name: