From patchwork Fri Jul 28 05:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13331189 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A7D1C05052 for ; Fri, 28 Jul 2023 04:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C865D6B0075; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0E2E6B0078; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A877C6B007B; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 970116B0075 for ; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 49312B138F for ; Fri, 28 Jul 2023 04:48:34 +0000 (UTC) X-FDA: 81059789748.21.CE778AE Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id C423FA0008 for ; Fri, 28 Jul 2023 04:48:30 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690519711; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NjF9mahCAmrdY7IQdEpL1zgetsdP4wZLFMpIN91y3YY=; b=17VWvWePTX8VwWzTaxa6mh30bxD7h6suHLzxk6FabVeESoDsCVblvYhkHgZ+p2y9kg/W23 b0ioYdttZTHHRjmanNcwCaZ+HxD9cuOaPl/+lHyAfqoQVVTKERSKbzpRbGdc/rXydBal8m /LPqWowaWvBYrlNwwJLeX895JdsdenA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690519711; a=rsa-sha256; cv=none; b=amYS+iUKy2o7kDrUjzI6WXTlcYGmXClV0syKwucicvHYmaL1yoJEyE2YZx6k+yS/Jo/Qdc Wr5Kkh2nt0VFeizOm2zWldCzPsfWPCCZf+xkF39EdLbRiOicDAoxfOksUfYVlcQRtevJ7r Ab0GKNEcJ1jTubEvW4BYz/JRGS/OJy8= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RBw9G6bpfz1GDKc; Fri, 28 Jul 2023 12:47:30 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:48:25 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , =?utf-8?q?Christian_G=C3=B6ttsche?= , David Hildenbrand , Felix Kuehling , Alex Deucher , , , , , , , , , , Kefeng Wang Subject: [PATCH v3 1/4] mm: factor out VMA stack and heap checks Date: Fri, 28 Jul 2023 13:00:40 +0800 Message-ID: <20230728050043.59880-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728050043.59880-1-wangkefeng.wang@huawei.com> References: <20230728050043.59880-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 dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: C423FA0008 X-Rspam-User: X-Stat-Signature: tzf4mbo9c48fzo8zetmicdoczggw1hzd X-Rspamd-Server: rspam01 X-HE-Tag: 1690519710-862722 X-HE-Meta: U2FsdGVkX19QPfgL4CFeVqzG9qo6PPJRdFk9Mh7kpcjQlDbfpwyojVdnbLBuqsSacknsnBAezqLcJnDygcXoYoIfC8OG0YgoAf3Sm2gjTleUCi3VCCSfkQm4frm8RBKRUHVI9OH04pAehmuQ8hdgHGuD2oMS2rYdUagHj5prLRLP0yozpoavBzSzqvAwLhxPuhqhGDP+AGRkzZFmtIz5wOqz2A0O/K4fm53bcp0gmGYR6oqwWMV2f35hDCiVHjwW3xFNaN/dntMvctIGnGPjMQ9Dw37OzQT7yz1+sUPkeNxRRDwGinjD7YZhir0iQfSkVmqmeZoaK/vcOkwW6u4DusweRCrLWhaszYIWyE6BqFMd3ux3TrJqcqOaeaELliqQzpQI5qFcdP5OwVOAD8ufloz4cxMajQZ/zXF/sEIiJAstR4/oBRAYKwNZUrajbum4HcAUzJqpcKV/P54jQnhUVMVl3cdyHShIbCavLzcauz8X7RlgJ03su/Ob2SUWpb1H7jKLJKa6NY5jzRQniaWaGPHZkxdccbnIcCT083lehuoUG7FoSZOlbuU/yxxIUvI62TL+FBsIfNPqkQfHLrLj7/ZLfbWmr6qXOnO3TWXQ54rPpE6j8maXfu7MY/ibDaLe3XYAXeuSrDpBMfpI9I78qn6TpSIMdCA9UXKGRXGdjq/sUrtDHQ4S4dROhmqbEQDCQuvBlDCcY2qB4JBdkJQ7rkUXH3j/Hq2EpfAWUiZ3ql8dsoL02frNWVw8dcNZvPF/qV0EQUmh3eYl4ItjoyE8QIauhIjdXikGb+I44F9OwAOvcLwnrTwoDTGHO3m5gK/cGZTCjZDGiAwifBavJWL7srrBAf5hyUM/EANQUHf7tUzhITpDMtnQfY15BCuXm+dzoApqI0gdoX2zVB7zEV6taXUvKSp1Iyj+rXkQ3PjkFYD7PqMCcuv6OwiQeG0o701MiwZHVZKVhVYpsdM/ODI TQKJ2j8Z Cl+OIG+QxvHqwgrwElqT2Szr4fCFEXZWDRamPihQs5a1im8qwPE5f6Bizrb1GaJJw7EKZ6mSvcYBexB4rs55m9cVnoM5nKA0zmO/3NxAyH/dF5S8yOLwQ/in1DpJb1YwaKIhBmyktNrR8tv10AmlVm9IB0ixWYbR3ILi+dZ+SuZeP88h0XKu8l+5Hq7T4q+eDGVj4DeRcdN9e7xvUXZBuOAw37Wa4LvegArh4uVpODpxbiP6cTR8hkt99vMR8K87bFQZWfFVLcxHz7lMWxuJCLKoSFLv83KA/vqpwxs1svybungt11Rs96b3IWA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: David Hildenbrand Signed-off-by: Kefeng Wang --- fs/proc/task_mmu.c | 24 ++++-------------------- fs/proc/task_nommu.c | 15 +-------------- include/linux/mm.h | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2b434b3fa2ec..3f063201b1ec 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; } @@ -1975,9 +1959,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 acaef8d106f0..2fbc6c631764 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -866,6 +866,31 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma) return !vma->vm_ops; } +/* + * Indicate if the VMA is a heap for the given task; for + * /proc/PID/maps that is the heap of the main task. + */ +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 Fri Jul 28 05:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13331187 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0488C41513 for ; Fri, 28 Jul 2023 04:48:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D1D36B0074; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35B736B0075; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 188466B0078; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 060F06B0074 for ; Fri, 28 Jul 2023 00:48:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BFA58160414 for ; Fri, 28 Jul 2023 04:48:33 +0000 (UTC) X-FDA: 81059789706.22.518BC35 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf17.hostedemail.com (Postfix) with ESMTP id 7773C40009 for ; Fri, 28 Jul 2023 04:48:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690519711; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TD9L4lC/bWfizvKwNSfd2+Bp+MhdORLoRxAYAh2SyGE=; b=0I/mGFtE7MXCxQlOLImR++QRCIP/cdM7Z10bHGbSmi3Z0nz5ae1usm2I82UmB3j8TAUeic hIR2c1TqiuLz93nPNL2OV+CKcH5d6EWvRBIA7KhTM0uGGW6IdJkZ6sRVAFOKIA1tY2cY0u MAiW76A29o8zlJcIa2da3C8jzklGNt4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690519711; a=rsa-sha256; cv=none; b=IHD/fvT7qjtQpTItllEItbw8yYPrVAsUpmPbYhHUOhyKdgLkIT1JPS+nyRr7tdulMESISk AO66iouV2nb0aMOo9V9hhxBToP/WJ9F80hzX/CCYlhGZK2QmIajmpMSgR04V0T1Q1ZXrwj /uvzGaCj4fS5if0Ts8D17USd9bk5WT8= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RBw9H5nhFz1GDJX; Fri, 28 Jul 2023 12:47:31 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:48:26 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , =?utf-8?q?Christian_G=C3=B6ttsche?= , David Hildenbrand , Felix Kuehling , Alex Deucher , , , , , , , , , , Kefeng Wang Subject: [PATCH v3 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Date: Fri, 28 Jul 2023 13:00:41 +0800 Message-ID: <20230728050043.59880-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728050043.59880-1-wangkefeng.wang@huawei.com> References: <20230728050043.59880-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 dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7773C40009 X-Stat-Signature: o41frfsp3hwms1mwnspdfzuis9cta6xg X-HE-Tag: 1690519709-600925 X-HE-Meta: U2FsdGVkX1/oUbr3w1OIysm/kLXKD9keS6nMH3iMCkHsg3Dva4uUIb6Pvv9nuWn6VFj4phfoYFav1Pd1fmeIltqla/GFXeEJCpHlFvlHMsZ9MJ6US+g4N2QKNURn7jbDyIpzsUQA8teFXV7rLWCmk2/mIMCj5oNzpDndS3Jl9lvKNeTIAfPOty4+Hq5LTAPjgqj+RB/NdStlTrCo//hvJvJj8zCZbsgbAfmGPapbWkIgMoohwaRBSIyqI0mF9f/U/Cc84ZrEnlvgiI6i9wyZOIBry0E4imYJPtZucayih4kaulp7jYhstu6kwkb+/Fs6LkB/++TntB/8EvRX3TSbBHZZD2FFHMPZlWOG4JSU7EZtnjrxiqInktlAW9XCENPubdarnApQl8WpARXXmxUTrlXjLHIupK4Pcb8EaORbr3fzi47lA4d/Q7ukzdSfyM7zcKp8SFc90Ze7of0BnA+XLQlyyGorcuoRNO3GuFSqqlMix/xQFos/eSlbHR7ulNE4051shQgQD+x11BS4r1iwG0VOMQc6TeLUAK0jk3asy84KncUXquAjtyyg6s8P0hk0Ho2rwzWB/STPUsBkQ7+jJVuiG3/m4/YPfIkomwys8GPD2Xv5XcMI+81rZ1mKIP9GyhgHpaJyy4NxOqMdr/uECp/Jutx6CGo5GehbEM7xDDPdGU9Vr4EmhvhmOsk69CF7H4xz6knNbYwPSQ4UTiJrrcvi8XSPTuKXHWvwoviE4w9n73TAw0tw3I8khB6xV1MpB/BDcipA2u/SkTZnfKiSIHMhQMbqflbtBZyRJ6Z99zTAG2h22L9dUPvjhSTXs10ruJbCZBtaaqUWACF4gjGWtEp9cpATWo0su0toGlcTzq1M1rgPOGvyCifCxZ7pX58lve6o28ohhGd7uPXpT8WElWsofj+S7xRxAvNFYiBbuEKWKDfoDcgH2fJFu/uqkNFs8oNcQq0naY/O4zizjXh S4ANi+Rc RtRbz9lKCKktY2Bi5d5tMNC3sVFNNY2UhJ1tIFRA8ma81F54I1nxXQbW8wvKxKsMhognqW4ZQqit/T9Jnsh7NsTdzwImE64Aihhnt4DuIxqzNTHvawczIgmIUEDfDnN756XogJrsiwk/iQfwsp9xrqScV6vi2smTDGNQZKLwJVmp+uIoEJB1sI3jgRNZywm1eXpqvlzQeaYw/iR+GPsmL62FLYjNpw4US1zNFnUroLeeL7e+k4um2tacub83zbJopXxLt+wLBNmPhGmk967hpwVPcaXWxVx1ryUjsYTRX1rVwmh5J3bQ6AlgT6gY0H7HlchYLscGYLgRIYqlGiurqRW9jrA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the helpers to simplify code. Cc: Felix Kuehling Cc: Alex Deucher Cc: "Christian König" Cc: "Pan, Xinhui" Cc: David Airlie Cc: Daniel Vetter Reviewed-by: David Hildenbrand Reviewed-by: Felix Kuehling Signed-off-by: Kefeng Wang --- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c index 01c7de2d6e19..308384dbc502 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -2624,10 +2624,7 @@ svm_range_get_range_boundaries(struct kfd_process *p, int64_t addr, return -EFAULT; } - *is_heap_stack = (vma->vm_start <= vma->vm_mm->brk && - vma->vm_end >= vma->vm_mm->start_brk) || - (vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack); + *is_heap_stack = vma_is_initial_heap(vma) || vma_is_initial_stack(vma); start_limit = max(vma->vm_start >> PAGE_SHIFT, (unsigned long)ALIGN_DOWN(addr, 2UL << 8)); From patchwork Fri Jul 28 05:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13331190 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3A43C001DE for ; Fri, 28 Jul 2023 04:48:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AB946B007B; Fri, 28 Jul 2023 00:48:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 334B26B007D; Fri, 28 Jul 2023 00:48:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D6C16B007E; Fri, 28 Jul 2023 00:48:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0B8186B007B for ; Fri, 28 Jul 2023 00:48:38 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C6910407CE for ; Fri, 28 Jul 2023 04:48:37 +0000 (UTC) X-FDA: 81059789874.30.D7288AB Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf19.hostedemail.com (Postfix) with ESMTP id 180DE1A001C for ; Fri, 28 Jul 2023 04:48:34 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690519716; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VciDaF1eQZ1bIKh/QSRmkEMR+WzJ3A1u3Y3GbRGEwLc=; b=DNMdv7W+WdcknI6mARatBjIIk1J/Qtmc9/eZ4c9epUQ13iRzARzzhdUOMnh5BIAl4izmyn ngjyjG9ah1NTzZGa1ReZl3eDqg2cS8cYsOqjDxbEgFl+aR2JuytWPWOibg9sQminRMfJdT /yDURQtilR3kDsllCzsPVsW9bYXgx3o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690519716; a=rsa-sha256; cv=none; b=bEbrQhOF5zYyQ25fR37JeYf64dpKNsWUfYi2YwWyL318dMMKCdJ5BjeHvCcwiaNYPzs/9Q vEfRNUInRMYcbsmQd0bxqX1N1feKl+tHoBw+BzvwCiX2LEetvPFPMci6M5JIULfmtclJLs chrgCaeSpaZrygkuxSsJfQS5GNfQ3/U= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RBw9J50qQz1GDKB; Fri, 28 Jul 2023 12:47:32 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:48:26 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , =?utf-8?q?Christian_G=C3=B6ttsche?= , David Hildenbrand , Felix Kuehling , Alex Deucher , , , , , , , , , , Kefeng Wang Subject: [PATCH v3 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap() Date: Fri, 28 Jul 2023 13:00:42 +0800 Message-ID: <20230728050043.59880-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728050043.59880-1-wangkefeng.wang@huawei.com> References: <20230728050043.59880-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 dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 180DE1A001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: okkcykxaktgdjbi7d9kiw969arpkq1o9 X-HE-Tag: 1690519714-46504 X-HE-Meta: U2FsdGVkX1/Fbmmg1tubVsipS/BEa5vjqy1elMqsR2D1hWV4vlZlGDIfA6swQIlo3eNZ0S3WHR5N9P1I4dvJtHrR3hzhEHA80s2j9uJPLkzfxMhCp3DRdJE8zGL3WJvUYKRM7j9GYX+BOBCYNGovanBM5CnQGd/B1G+DYYNicaWTePDMsO+vjL3fWVBV40F+HFAXbse5NDKzSVGcqyhpvY2z7P50D04ZQFKUO3QfEvEWL3buYkDs3BpGBZQxwLItk/r72FOxEIsvpLnC2GOrnf7mcQK81Fm1tjHlXI5KIR2h/NVFZvcDAQ10cZeLUnoYHW2LykdpZuhzELoMpKWoVQzeyB5m+PbfIL3zJwbyaXsxo259pMU8nbZQp88bzpco3w2l++X8tDOXfUaztGRy0a9J9wvHhleoSzSfVnnLV/XNjK/DgeS/UFRiuQwmdzHEp8MR53tq/C0cP6Cpi6JHEhO625+1Kt9GqLFfsw07DE88+HU/EmpxgbrzUnVRbmY2NdzebFmi6zoI/+Ky381jN5gmj1wWtFp4f8BOxdGio1BsWgaUhJOC8QmeF5A0a1PRzS+5ERdi8xfNtdxCnysQtJeQb7wwkV785wef6dARrQUEn9L37NOZnBpdkukR+CNubOQW5ZtYbUuNfmhl1BbFcBZV2NFsn9nOfK49aagJ9v/M+5vksknUir0m/4epxBIdk8zmOyor92JT2ss3q0RE4pi9EZe7RphS5DmOiGgLLuz4aZeJKsr4Ik19p8jIql3i8/NkTxozACpujgYJZXfkk3GFPW6B5JJmHp0x4pRJQEZOrQjCB7zlTTtijHtQg4OAh/I5NpvQxcJhYDT3aV6r9RX/NqhgD/tsNsK3x5ZUcRurdsgNm54WTNih21+4TmVUyT7RUXABPPg9++yOeXEhvDAoEbkoOHK1Z95C/ldaqFgVtkTaRcu0BIQAv65zNjZbLt7IB9LZ9jWP8aTj0O4 sk2HtCMf 56osvoq6XmZg8mMIvnUJMvtPzflefPBObC5z//Hbgd+hixhIJ/K34v86Xx6JzCNxXNlCcFEU4EpGZdyQa6a/i+HyC7m0Qwm/gRAC9pc0Puzh8D4RTaE1LlgXQXE6Le6Avic5BOizMtuBzADwx07QEWT0+QX/48xmOwJu2P9wdRYM142gXjCbPGXJ2/YSvvXMbxpdLsSul7uOPeOOvBxSk6+iN9ra6qH24vaxVqCA4aKLHhYSmRRciuyvnHDpBtVaAA9KO/wBy+RAQIFQfrAP+9rPHVXzP8KkkwbDrhJGCqLmymeBrTdFMYbIfTwQfL3KY0YmtqiDC6BWsoMSrQ7ywVmHIse1HicyhwQRXoG0VOCaF9dYoy3TBjSmj5gTXC5ts6vA4jJKUftiO0ZYHVS0fGgMymezz35SokoTT+iP9gSoalOE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the helpers to simplify code. Cc: Paul Moore Cc: Stephen Smalley Cc: Eric Paris Acked-by: Paul Moore Reviewed-by: David Hildenbrand Signed-off-by: Kefeng Wang --- security/selinux/hooks.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index c87b79a29fad..ac582c046c51 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3800,13 +3800,10 @@ static int selinux_file_mprotect(struct vm_area_struct *vma, if (default_noexec && (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { int rc = 0; - if (vma->vm_start >= vma->vm_mm->start_brk && - vma->vm_end <= vma->vm_mm->brk) { + if (vma_is_initial_heap(vma)) { rc = avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__EXECHEAP, NULL); - } else if (!vma->vm_file && - ((vma->vm_start <= vma->vm_mm->start_stack && - vma->vm_end >= vma->vm_mm->start_stack) || + } else if (!vma->vm_file && (vma_is_initial_stack(vma) || vma_is_stack_for_current(vma))) { rc = avc_has_perm(sid, sid, SECCLASS_PROCESS, PROCESS__EXECSTACK, NULL); From patchwork Fri Jul 28 05:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13331188 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC0A2C001DF for ; Fri, 28 Jul 2023 04:48:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D492D6B0078; Fri, 28 Jul 2023 00:48:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CAAA46B007B; Fri, 28 Jul 2023 00:48:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A12426B007D; Fri, 28 Jul 2023 00:48:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8EEC96B0078 for ; Fri, 28 Jul 2023 00:48:35 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C33C8058B for ; Fri, 28 Jul 2023 04:48:35 +0000 (UTC) X-FDA: 81059789790.17.254CF64 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf06.hostedemail.com (Postfix) with ESMTP id ECC86180004 for ; Fri, 28 Jul 2023 04:48:32 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690519713; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D/rLs7gASsjHAy2ZfI3q4nMacggGm1PsNeI9gnyVH3Y=; b=enVqalb9vRAZ+cofPrwBkJOeamOi4hZ0zCaN3Ee+kAc57s4TJnkz6cJS0MqLVucLYcpFss N1gVHk88psLZeLTE/NVLBOHjqs3Wk/rgp54HWE+nnAteU71w6/eIiX1/wDw+rOkoM8MyF3 itbhJrgWP6z8VWbVBlWrV6TUuWcxcj4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690519713; a=rsa-sha256; cv=none; b=RTc6pLJuwYhq0PyaRJdeXeSKQkHQh/Fe3z2lB4sdZAkXL79qz4fH4mt+XGH7NOriC0Vmv+ kzcz3Fng2pTAFtc1Xs6LIWkReSXSc6FhZ4qZAO8y8+4c3WweBJSVNVxPl0QYoZdBN0WwCG ISPG17dCi5hl46ZCiOG5CHBYYGf2Q2k= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RBw6T19T8zNm4t; Fri, 28 Jul 2023 12:45:05 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 12:48:27 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , =?utf-8?q?Christian_G=C3=B6ttsche?= , David Hildenbrand , Felix Kuehling , Alex Deucher , , , , , , , , , , Kefeng Wang Subject: [PATCH v3 4/4] perf/core: use vma_is_initial_stack() and vma_is_initial_heap() Date: Fri, 28 Jul 2023 13:00:43 +0800 Message-ID: <20230728050043.59880-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728050043.59880-1-wangkefeng.wang@huawei.com> References: <20230728050043.59880-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 dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: ECC86180004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 96tkwuauie89jseamo7phkbs8zsz6hxz X-HE-Tag: 1690519712-218862 X-HE-Meta: U2FsdGVkX1/qi5GZ7Y0A6wfwKAirqN78EyAGiR29zByQlQtw6akdWtUu4+0DlvOU2n0yd0eEsTSFjjtTdH1eClZ+Wt07OEfQYmO2y1x6uhUw/0UZ6gWleqzFndSmzP8HoE7uAd5mPLyfUjYiDaH0jExHjXEtAPrz/I/1qx99qUCyf/ZlZN5JyUgn8WDjA6X8xtZYsdNbUWLg/Zhf+uWD5H4eV7+HixOVc6VAgOiPcE96ZpFkC0hd8gZxQopk9Z+ta8nMwhfOeDSPDN6qpM/XeUYnh/OwyXN97FeHKLWLHGEKd7JtnXEt2CmyQoDZtd3Xd+6KFEIVFruXTXLf3ur1/6hPXFkZwhOtRQw9bVn/RLTYavT2wbDLzESwwT27e/FP3ZbvvM9Lb1vw24qwTDn1lyYtP5oq/OV/nGMpz8oTrItBd1tcBFyYgViqbVZAldJHm7kCuhLG97tDMnFyKDkWtnDL456noNZStsNENLYoTocFIyA/rL2UBYsn9UvaiO49rcFQM1SP6DlBGuMKbBu87iJkUAx1dJrUxDJFoGHaUnUKPLkb3Jt8nwgl/cvd967D/+5FGEvICDC61S3MHXiR+Chew47pNvU0Dwj8K82wHwovyFa1LQBh3M/4v8slhBTc9/WNdVQ1wtV8KzLy11ldDfPLvT1YhUrL4ZO+wTF+62m2IzpB9ST7t52awBg90/UezspMt/DafkgKqvF0WaQMRSOFnnwdguLbvFUCG5cLC7w0LfVWqO9UFjsMp7Qz4ggtVsgOKtGVQdQyN9NtfG24MO9fCd4L/L1lpbtinHrdA5qYx5cREAI6Xr7tlvXK7uANwpDCnxlBBPxyZ//nVxtDOw48K7xWvns0VNmrgeEJG5yRSLo0jO+vnbuKjowBVpPWMcTOGn7MB3R2PANv+NtMvyhM1M7mmEpIbLDTya6QJu+a8lX4t//2BS5mJwRLNf+2Iu56s/ETbKc1eyZwyvO mJr7Zdo9 4HGzYr1Ko9cF3zNJ4ubz1x1S1Rg/8dcLV4JYATCZ2AHyV8nuMbofO4wRhBP+1LUx/2Tax/ClE0s+38zq+5TyfXCLbLKo+KFISYY41zqX9DX2KDbdGrVY/DEJAGT4A82KgEEp708RPdoGqTKvND9a7zAw13bXa/pQm5/YCkzdC/pHcm0Z2I9G4dofKagAK+rfLfSLnCXD7kFKdIrnZT5Fi0zQjz8sX7OxGpbBsef4+DLeCAjJdkTg1U8fZaFfJkjzOFYxZWpxuzLbryiY3+QdTxd9gEZvW9672SAFyyuErD089rmZ6jDYPIy7oV91MT4ehR5kWwS0S96PfRfHchFVvA/pVgfewhgNuUgmorjLFBlTa7QR7/6/cilmHYeuny7KwOPdjQuoFsxQrv0ob35NYBTm9Sw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the helpers to simplify code, also kill unneeded goto cpy_name. Cc: Peter Zijlstra Cc: Arnaldo Carvalho de Melo Reviewed-by: David Hildenbrand Signed-off-by: Kefeng Wang --- kernel/events/core.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index f84e2640ea2f..b36d0823ff33 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8631,7 +8631,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) unsigned int size; char tmp[16]; char *buf = NULL; - char *name; + char *name = NULL; if (vma->vm_flags & VM_READ) prot |= PROT_READ; @@ -8678,29 +8678,18 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) goto got_name; } else { - if (vma->vm_ops && vma->vm_ops->name) { + if (vma->vm_ops && vma->vm_ops->name) name = (char *) vma->vm_ops->name(vma); - if (name) - goto cpy_name; + if (!name) + name = (char *)arch_vma_name(vma); + if (!name) { + if (vma_is_initial_heap(vma)) + name = "[heap]"; + else if (vma_is_initial_stack(vma)) + name = "[stack]"; + else + name = "//anon"; } - - 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 (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: