From patchwork Tue Sep 10 08:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798088 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 91677ECE564 for ; Tue, 10 Sep 2024 08:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48B568D002E; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EE868D002B; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F2958D002E; Tue, 10 Sep 2024 04:01:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F31FD8D002B for ; Tue, 10 Sep 2024 04:00:59 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B27A9A9FAD for ; Tue, 10 Sep 2024 08:00:59 +0000 (UTC) X-FDA: 82548082638.03.5B6FC3C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf18.hostedemail.com (Postfix) with ESMTP id 641CD1C0023 for ; Tue, 10 Sep 2024 08:00:57 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725955230; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=HhCZlhac2rzla2+ZQ0NRsvzWQ68fObPv6jL+S/zEeoTQkddMg91W9UIICsHk5LGEmTTl3M 6bbddV6ro2KDDMO/eE490OfkyNAR3TIj2IBsTE8X36T479I7zE8WhDtIsyzXIJU15yv42c cOuIcl5b6BE6DhXcFgFgo/s3xc0XrDU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=giYkk7zX; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=uCeWmHNi; spf=pass (imf18.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955230; a=rsa-sha256; cv=none; b=EXeHHR8CgZMCaYjgGeL+ET+VZam1+PsPuYtWgYOZSYzwskzKF4+kIH30UOyapNuIkLWxYd VDYpRUNOaTXLDhDH42blo7Rmg3BToJprJ4cbuUUKWrf74oOkSsjW9ckiRpzweHAP7SU52Y ghp9HcQiMK7EZNqs2EdE3BzKimC4TNI= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D57D421A41; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=giYkk7zXHO/VOT4TuhTNSNl4gT0+qh8Og4h40nMzbBJdkf0jxf2tIRrWuMdIcHLLJ3ihIQ 0GmSecGp3egdIS8gzGkUKxJco1eF08+P9TlvdVLnfhQa2MLPcUeju7n6vuCq7eV8VKGa/6 rl7Es7D5Cs8ORNk16yJgPHvjUsJyiPw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=uCeWmHNiOO0qicZD+hBu97YjyCz59gAOvid1pqOyFdSroieAtCXJKoYGD2jxi4WdYxl+ba 1P0uJ3A3Zi8NHpAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=giYkk7zXHO/VOT4TuhTNSNl4gT0+qh8Og4h40nMzbBJdkf0jxf2tIRrWuMdIcHLLJ3ihIQ 0GmSecGp3egdIS8gzGkUKxJco1eF08+P9TlvdVLnfhQa2MLPcUeju7n6vuCq7eV8VKGa/6 rl7Es7D5Cs8ORNk16yJgPHvjUsJyiPw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955255; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GLDltFrQL6gOEy4l6VLVTy9j8S44tPEMq7/+b46Xvkc=; b=uCeWmHNiOO0qicZD+hBu97YjyCz59gAOvid1pqOyFdSroieAtCXJKoYGD2jxi4WdYxl+ba 1P0uJ3A3Zi8NHpAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 26273132CB; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GF00Brf832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:55 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , Donet Tom , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , "Liam R . Howlett" , Oscar Salvador Subject: [PATCH v3 9/9] mm: Consolidate common checks in hugetlb_get_unmapped_area Date: Tue, 10 Sep 2024 10:00:30 +0200 Message-ID: <20240910080030.1272373-10-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910080030.1272373-1-osalvador@suse.de> References: <20240910080030.1272373-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspam-User: X-Stat-Signature: 1n9fbw3im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4 Id5iby5XkFAznyLZngz4bk+mMSHQEEjxlnHWS1BN7U3s42PSTPVPNTCWTcOGC54CTWYb7oelHnhvyyLsVztwoJbYKISojLxjIofVHRI9DjZc9wc7X83OZetQHdzlDrqOnUCCUUy1Fof7Inyalf7M8ROCQa3akIZr3z+vCMRFRtse8CIe+y7rsg3DiLhAavWLI1MTJVOJx+wN8DM0Ul8kpXh6xavGoQ5pOlGNUGpwYRNbEF9ngN4qChsQoinl7ZUD5mdTgAXy6DIv1FmUWtUb/a88927nPIzxSwLoR 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: List-Subscribe: List-Unsubscribe: prepare_hugepage_range() performs almost the same checks for all architectures that define it, with the exception of mips and loongarch that also check for overflows. The rest checks for the addr and len to be properly aligned, so we can move that to hugetlb_get_unmapped_area() and get rid of a fair amount of duplicated code. Signed-off-by: Oscar Salvador --- arch/loongarch/include/asm/hugetlb.h | 4 ---- arch/mips/include/asm/hugetlb.h | 4 ---- arch/parisc/include/asm/hugetlb.h | 15 --------------- arch/s390/include/asm/hugetlb.h | 17 ----------------- arch/sh/include/asm/hugetlb.h | 15 --------------- fs/hugetlbfs/inode.c | 8 ++++++-- include/asm-generic/hugetlb.h | 7 ------- 7 files changed, 6 insertions(+), 64 deletions(-) diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/asm/hugetlb.h index 5da32c00d483..bf41b024b6a4 100644 --- a/arch/loongarch/include/asm/hugetlb.h +++ b/arch/loongarch/include/asm/hugetlb.h @@ -18,10 +18,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h index fd69c8808554..6a63d82a8ab3 100644 --- a/arch/mips/include/asm/hugetlb.h +++ b/arch/mips/include/asm/hugetlb.h @@ -19,10 +19,6 @@ static inline int prepare_hugepage_range(struct file *file, unsigned long task_size = STACK_TOP; struct hstate *h = hstate_file(file); - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; if (len > task_size) return -ENOMEM; if (task_size - len < addr) diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h index 72daacc472a0..5b3a5429f71b 100644 --- a/arch/parisc/include/asm/hugetlb.h +++ b/arch/parisc/include/asm/hugetlb.h @@ -12,21 +12,6 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h index 37e80a32623a..6f815d4ba0ca 100644 --- a/arch/s390/include/asm/hugetlb.h +++ b/arch/s390/include/asm/hugetlb.h @@ -25,23 +25,6 @@ extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; -} - static inline void arch_clear_hugetlb_flags(struct folio *folio) { clear_bit(PG_arch_1, &folio->flags); diff --git a/arch/sh/include/asm/hugetlb.h b/arch/sh/include/asm/hugetlb.h index 75028bd568ba..4a92e6e4d627 100644 --- a/arch/sh/include/asm/hugetlb.h +++ b/arch/sh/include/asm/hugetlb.h @@ -5,21 +5,6 @@ #include #include -/* - * If the arch doesn't supply something else, assume that hugepage - * size aligned regions are ok without further preparation. - */ -#define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE -static inline int prepare_hugepage_range(struct file *file, - unsigned long addr, unsigned long len) -{ - if (len & ~HPAGE_MASK) - return -EINVAL; - if (addr & ~HPAGE_MASK) - return -EINVAL; - return 0; -} - #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index b6a619f5a85a..cd49d21e7284 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -181,8 +181,12 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (len & ~huge_page_mask(h)) return -EINVAL; - if ((flags & MAP_FIXED) && prepare_hugepage_range(file, addr, len)) - return -EINVAL; + if (flags & MAP_FIXED) { + if (addr & ~huge_page_mask(h)) + return -EINVAL; + if (prepare_hugepage_range(file, addr, len)) + return -EINVAL; + } if (addr) addr0 = ALIGN(addr, huge_page_size(h)); diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h index 67bbdafcfc22..f42133dae68e 100644 --- a/include/asm-generic/hugetlb.h +++ b/include/asm-generic/hugetlb.h @@ -123,13 +123,6 @@ static inline int huge_pte_none_mostly(pte_t pte) static inline int prepare_hugepage_range(struct file *file, unsigned long addr, unsigned long len) { - struct hstate *h = hstate_file(file); - - if (len & ~huge_page_mask(h)) - return -EINVAL; - if (addr & ~huge_page_mask(h)) - return -EINVAL; - return 0; } #endif