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: 13318465 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 ECA06C04E69 for ; Wed, 19 Jul 2023 07:40:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70823280035; Wed, 19 Jul 2023 03:40:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 691358D004B; Wed, 19 Jul 2023 03:40:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 494C9280035; Wed, 19 Jul 2023 03:40:12 -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 379458D004B for ; Wed, 19 Jul 2023 03:40:12 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0A53DA0002 for ; Wed, 19 Jul 2023 07:40:12 +0000 (UTC) X-FDA: 81027563064.24.270BAAB Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf12.hostedemail.com (Postfix) with ESMTP id 4A4E440013 for ; Wed, 19 Jul 2023 07:40:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1689752409; a=rsa-sha256; cv=none; b=dvnSPsMCK2MvHhYX1DUDWk1WdDOReyleQbwXsZdZCq1sueEv/uvHTb0v8FyhHj70e4IIMb GMTeZa3Y3KUmFkXgBtUBcFN/6UGOvX596THlqTYlAHiRwoJPYfVsnCxutpwace9BP4Rrl2 AtS9m+F7X9AbpFTHJvbeEId+8ZgNObw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1689752409; 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=MPN5dJ7jQjJof++e0GOGPjqr9j7WBPBqmO8MjvBjRlI=; b=XGOQQ3AUlN5nPOhm1u2bjspqk/qpmt+jfQ+UiqgCHdUc0fgdM/GEHXjC12Ak+VGZoLiTht HQkFFeeAJb1pjJ4Xn/6LivT322w6tRfL2NU5946auWuYC4/Q4fpkNVtXUWW4JUWbWvyyik NOVMFEPH0/aaTkcMnfKFYPlQLF/PfXo= 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4A4E440013 X-Stat-Signature: m9kk7zbpm36fqnypx914r3hgxzd1uj1q X-HE-Tag: 1689752407-288989 X-HE-Meta: U2FsdGVkX1/VCpxbu0A/orwIb4gT6cqQlqi4iBsb6hRZtk3UNZINCA800tKDk2Zb17b1KMhF0QctjTsagzOT+D/mtA2l5jxRFrN4z9jo64RW4TudsOqvdrMgUuxv/SYDk4ezTPQEaaX7plrWMKHlX3lDVZEgA/dgEGIEw1MtGxhE2K7cIJM4AdUOmr/bc+w46ILcDBt7KG2dUMSuvqaAn2JMYgYcELYHkgtJNdzIYhRlsssQTvq2wud/Mj3lGd6u/aJM2WFOVf66ClYjS9O76wR4XqEojulEqNy5O9DEKc4X8E7vO4h8XZnXjSiH8F4SW2mhL55c0l+FsFvTt74+qFx3hK+IJnbVrl2GDriumvt2Q5PflmEXrDXu0CCUB4nwWbEjIPNPGYpvH9ygG1jqKwrFWPqbul4BgBVpM+HSK55xeUbb9mhR1b7jwSfRfN9EyD716yS0xCPL/nFw5J0P+NqoGp1iATyinHEEvxFkDGXB0YzJdITrtwBJMj6bssToR1BSTEbM2P/T6DIeSQGb9HBzY7iKgSoktxvnG0jIa6owue9kLaWajf3t0OmUqYYHQcFa5XcXg/h8hniibdQW5b0a5mE/P3yIiFOxleBeHwaPno2xmlv50r/autCvnxvrNoEocJfcX7PuybcwA2YojoUw1vr9RP4hIdaL7LLN/sVJdjBRDx/Kvwd9lr6amIpfNC9z+YWzR9X6pcrvaH7vTUyRw5mXRDI0gT65FctPdkuBBUl/BZhThkpGC5dIk1NwLLrQ1gLhzYV28r5gnhyANWY9TDG/Nhjeyiq0tpx20C+aC+rxDpK9bk+bXjLGaLUxPbX9I26YHwXsaCOT3v1QXeLP4sefL6jvyA/9CWa5/JJyLkI11CPFKNXS258DfhBO3W8Y95y3gqIoyBKaxSnQyP7dFTvtQsFom9iNTBhoK8UlZXxXGxw27I7QWfYkCSP8tq+TdClLGMPQYKiE7yy GH2TqiUh hVz7aMhjJqtrW8wIsVCEYJX4cbbi0QWH9mU5BSIGl5mgCneECfXwMv2CkrpZLFPWm3dklKNw+1N4V18BWvBD1mxVbil3LNtB9RkFgAsM7zE8NLsN27VGYTVu/vni+ox9Z6/jtVDXgvEkOqAwfgVBkXBMAT5HpM73NvymWwbhmilcohL8cUV2iC906KZOJ85AzE04OkNx6qMZgsUVovDsx3IeB/uQtqly5VFlIrhOU47nC1Z8= 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 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:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13318462 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 7F956C001DC for ; Wed, 19 Jul 2023 07:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7517280034; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFDE48D0012; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97724280034; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 80D598D004B for ; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 594BD80113 for ; Wed, 19 Jul 2023 07:40:11 +0000 (UTC) X-FDA: 81027563022.02.D9C35CF Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf11.hostedemail.com (Postfix) with ESMTP id 724C440007 for ; Wed, 19 Jul 2023 07:40:08 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1689752409; 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=24vgN4qXgyyKOnmcSjRBoNWV8I6xDWypWU2tuXRGxGw=; b=VXJ2p/NMQzM11qB43Nz+ryLzTS1wpnkUt0MnPhRTXIHn7O1j/eHACDFNkSG9ZVKU7tXQPR 7Z8Pk0Q+4MRm08EQCHH8Wjoy6NjkFPUJ5hoNGLjOpIRDNmvNI8ULpftvhGW+2ZKprchIKh pBXnP2yxSAtOiK+TGzoAldxt8JCBcVQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689752409; a=rsa-sha256; cv=none; b=Nt7a7nithSFAeKix/Sz3V0Cv3QNbEnKqd1pkFyinLZnJi4/dCb6vLiWf5X2seI3VqjWc6W 8zJUlOXq6KgSkycowbS6pyGdl3CT/WUTVJ8rRoncJntFKnf+zKotoyle9beN14hbjF2s9k 5vBPrNAUsjACWrhyd43z4GAmCIAwWlM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R5SMh4XL3zLns5; Wed, 19 Jul 2023 15:37:36 +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:03 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , , , Kefeng Wang , Felix Kuehling , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter Subject: [PATCH v2 2/4] drm/amdkfd: use vma_is_initial_stack() and vma_is_initial_heap() Date: Wed, 19 Jul 2023 15:51:12 +0800 Message-ID: <20230719075127.47736-3-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-Rspamd-Queue-Id: 724C440007 X-Rspam-User: X-Stat-Signature: phou8ppkngu83k9iyddsqxopt5a9cj1k X-Rspamd-Server: rspam03 X-HE-Tag: 1689752408-194900 X-HE-Meta: U2FsdGVkX1/qLDfKVh72RPTQv/NN9YQSgjzLAfWHI8o23e+w111qh8Xeys6jhWMz7cb/Lcz3HJVsAHJdVLj90H0NtIfyN5EqD+lflVg8NLauhpt7gpzQLvp+oatQGpHILmn+32XvqH9XMbcJ7mG3K8S9ozeIkTiwwpYQwvzDdrr5GxGp5kYBmd3p+t2e+FdXtmdJ28n/QNq59x89zuOu1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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 Signed-off-by: Kefeng Wang Reviewed-by: David Hildenbrand Reviewed-by: Felix Kuehling --- 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 5ff1a5a89d96..0b7bfbd0cb66 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -2621,10 +2621,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 Wed Jul 19 07:51:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13318463 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 3DFA0C001B0 for ; Wed, 19 Jul 2023 07:40:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC0FA8D0012; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6932280036; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A130A280035; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8027B8D0012 for ; Wed, 19 Jul 2023 03:40:11 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4BC3440113 for ; Wed, 19 Jul 2023 07:40:11 +0000 (UTC) X-FDA: 81027563022.29.E7F1843 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 5E85540010 for ; Wed, 19 Jul 2023 07:40:07 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.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=1689752409; a=rsa-sha256; cv=none; b=exY0ap4yXOJGRCC9uzlKIkeIkUselYQmpxQHBPfWEGz4PTZbFph55n9K1YNr0xHwcj0K3E U19TfgORDefUzGJDCBoQVIFfooSuJvWmmXw8LfqgwiH+07OBqDSeDaoVfx+CbP21XsYibN r3egAlCMfO3/2Q9RDfxnLhIHjyVBTto= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.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=1689752409; 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=QmIT3/DIKZD9qXY85ldcQFgx/ynf1Pff2Bp+H7U63aA=; b=0B7noszxzGg/N0UE59Zz3fWTWzms1m6ajAGlaOKehUniedcbpVGJCOXxT9oFlcF11P2bu7 gK9o8lBoiJwW3J1wFf09xwXy6IkSAjzu2GFG508c52N0ch+pkwWNWjqYAe1+uB+Hv7jI12 v28ni0YJdOBx+sqBqCRJ/PZla36hbzg= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R5SPj0lfRz18LYp; 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 , Paul Moore , Stephen Smalley , Eric Paris Subject: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap() Date: Wed, 19 Jul 2023 15:51:13 +0800 Message-ID: <20230719075127.47736-4-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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5E85540010 X-Stat-Signature: 8gbo775npujp7wz9sszdcgys3bq43dby X-Rspam-User: X-HE-Tag: 1689752407-780926 X-HE-Meta: U2FsdGVkX18Go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DdsDQrJQd6rcjnCKpLYxYvGDP+nzSet2qgm1+gMWY+e8c1D4rk21WVhDBVZrPkR2+IkXYf4itbmGoxL+4pjl0FZ8jxX83UBH2znW9z3rBdPRqfNqXdiM6CWax0p8DOfsvoIE3JKiaHrNuioHU9hz8Ckylnws3xdmsyOC6q6yw+/DiL/H0mPsrMQMJv1uOS3H4ko4tShY2CTYzYhlkwUDOjPHV0kIYwWDOnFYi5nR58ZYH+so9QPAp2ROvMfBGk9/ELdfekwrnKiE23b5w3h1s8OgIE+2A5V9EfS4d1Q8xWn6M6wn6U2QFUr6Slsg== 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 Signed-off-by: Kefeng Wang Reviewed-by: David Hildenbrand --- 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 d06e350fedee..ee8575540a8e 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3762,13 +3762,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 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: 13318466 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 C7194C0729B for ; Wed, 19 Jul 2023 07:40:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38740280036; Wed, 19 Jul 2023 03:40:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30E9D8D004B; Wed, 19 Jul 2023 03:40:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C5D2280036; Wed, 19 Jul 2023 03:40:14 -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 C559E8D004B for ; Wed, 19 Jul 2023 03:40:13 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 784A8160196 for ; Wed, 19 Jul 2023 07:40:13 +0000 (UTC) X-FDA: 81027563106.19.361CEF1 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf02.hostedemail.com (Postfix) with ESMTP id 177BA80019 for ; Wed, 19 Jul 2023 07:40:10 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1689752411; 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=5cWrWwlManqrudfdOvGGdBUURxPlu26h088SbWtIKGE=; b=kZ4EfaZjCbCoD3Gk5X/ZtIbOqvFWslt31GTzrOGlWltWjiVjqqicuEWXDu/tb8eYKqdzQq KleJTsLmVCZW3PVgwEsV4Nq9yztTODnzBuUrrSl/lX5vGVTK3rY6i/Dq4f5nkAgUUr14W+ OO5qSj4RdxdbuwQGVBlLDBkAKJO1SW0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1689752411; a=rsa-sha256; cv=none; b=kX/jF7AK7MrLggGxBeSFWPcnv5GYhiZwEBvX+R8aSBCiKQ/0xPaHA4MWmU/DViFyMnGwxO Lbai69eCcgHao0As8AqfZAq4yAu+tbI/Y35Hd7tDrsPoSXIS+T2pNUxKrxqd6XrOs+bXNf x94OkPf5U1X58OTDctEAi8ML2BatcFg= 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 177BA80019 X-Stat-Signature: ccnsz1ejj39jrkbgfedpimbr74xjd6gf X-Rspam-User: X-HE-Tag: 1689752410-444394 X-HE-Meta: U2FsdGVkX1+ijOKRD1OUjHrkJL8VA3UiyNYH7IGtNxqTIEG8FpHrNVpDBYoEpODL+gEix/qlTYyixpM3b38H/0ST2Gquk8fuawRmIVprfgPHmudFcjFvSP5whZu79dFxP9rFVlssjtOVzCrN5nWa0LaRs6eZWALITaNmdUWjTIqCswR7na0Bwu9UyuKIOPID/e3CkVzbCTgqi9aftfyKqlFX7lX52ITepc1I4v1ZVfqsB8KBtyF2YXOI4cszIqQ9XN8enuHCSTdaKGeoGTm4zm9B/E5Gfjh5FVk4IgEe7BDdDfPprl0Jjv2B/qij2TIanxl8y3jm+PTXwiuK3Aj6TrPehI92Feqy2anTlgB8C40Ut9f4UmjWco8cEPSipMTjooadBZ/MR2p7PF9M7+8ACQ/cR98HTu8UtaS9mMD5+vBtx3HMXKptmlbLT0UE6KVyHUf68zmxP8AzJpCg4g8N76Vj3XsJIfw0silO6ee7+ihgywbwI9OD/jq4xCGmfHAHoDZmOgiTSSP8bMmqo80FGU10MP3BWYNUJQ3YuD78Ftp5VOebp+wutlMeScn7pbgDBs7KttukGhvpPG6qARcCrJIDQ/u52WHeY0xjxON+Cb9slxCHupgmKZQGzfGyZ5jDLlKApydkyvlzMKzWzR84bWotFAE1cz4vCkg9hqffdMoEFGtsUM+Rt/H3FdxCy1bb9eaC2juug9kT5q+zg0TFRmseS1uXIuT4QrPNVt3yblv2QJzmJ75jd9WpzRA4zYvCMmJJxAigzULjMFgp3UQ0D+7a5fPcsDTNpcJtIxi0GYghSfWDh55LZtMTgHfCqoZuMF4saTWeM7qJXRX1dOv1GJutNU+o5aINTpO9hf5qOGIt32bqWVh7y3MlZb5i3lea0/9HoehjIdVraGfhxZ3ouzfhcDXu6P2JTMvShN5AIOCjy0Pr5vCiDoRKHCDi1lMBEUguAwRF0CMXd0wi2x2 zY0kso9e MklfhvEgBhX4ibLZkN7BuaG5Peovwo+yyLYlKVkcAOrGCadlSSmSDZmKUS/zJYKW20bLkLoSEv65XC/NeqkdhHhYjSFuxk/jEGrnCxljgM3VSW6VE8CG5FnPx4pGdnFiSSJTOihArNplryrkchDWPW8NIQ03PQ3ckVNJCOpfyrhbNiS99JUyhoUwtwAFnBHZ+tGKvQSwtigLOgfiO9C2tr6grOa8mf7Guy5VdRSXly4cZWCfcFchUhoK0xEgzZ5GyMNKnXe+kPMh751HFal9Eqj7xydKt11cSHyhJwdXTXROBNkLoTmqqVNgzAQ== 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 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: