From patchwork Thu Jul 18 10:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13736389 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 C20D8C3DA49 for ; Thu, 18 Jul 2024 10:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E365A6B0093; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBFCE6B0095; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9ACC6B0096; Thu, 18 Jul 2024 06:59:21 -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 9523D6B0093 for ; Thu, 18 Jul 2024 06:59:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 50FBF81A79 for ; Thu, 18 Jul 2024 10:59:21 +0000 (UTC) X-FDA: 82352576922.19.E6D115A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf27.hostedemail.com (Postfix) with ESMTP id 1E14B40011 for ; Thu, 18 Jul 2024 10:59:18 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; spf=pass (imf27.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=1721300327; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=46vmLB0EUKvE0Szz/Y9LRAPq+BL5pW24AOybndqXxdmqSLlN0oItT2fqJ+KhpOflFZXp95 7OEEltGUjw9H7cQxR4LvExKj4qqWlBd+CBSNu1345bKKm0Sr2DMClcCTXsceDheSVphi+p w2ZNzMjKQtOdn0whSVscCZ5HePnK9TQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=UnjJIEr7; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NbhZQkeV; spf=pass (imf27.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=1721300327; a=rsa-sha256; cv=none; b=MH5VHN8UAUR9OuS/CB5d2Xu+iRhi7QCcfoCgA6gNlKkJO9tOC05ZFlyPd4AjC7vUIJjDm9 zpsdThu8Rhd+WSU1jRcqZ6otwPsowQ0bsVkIghZ8oq9/ZKYh59AzpFdBm67wpBRb7iIww2 3MupqXqUOp9pjMU8ZzrhzihH6x4c1Ro= Received: from imap1.dmz-prg2.suse.org (unknown [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 DA05D21AF6; Thu, 18 Jul 2024 10:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=UnjJIEr7+U+Yrn6jxxs3zgpZTb5TccLLns7pS78W/SYDCVTvs4A7gnL3OmtFUjvDi1S2wU lNxFD702yo/uvM2yCjGBBMeMjSk0NyaHmii5DSTOLypLmsSxCbVG6983rKJSa3ckiYTTvC 0z7Kh0Lm2g4IgLHNZtfEMCAtXyxpfYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=NbhZQkeVeCNXG/5vzvKd+hQQ5SapWr4Znt38EgWYmc+HQiaV0WXSpR3JdMor0elYCnFmiy jXbfPE4afZn32cBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=UnjJIEr7+U+Yrn6jxxs3zgpZTb5TccLLns7pS78W/SYDCVTvs4A7gnL3OmtFUjvDi1S2wU lNxFD702yo/uvM2yCjGBBMeMjSk0NyaHmii5DSTOLypLmsSxCbVG6983rKJSa3ckiYTTvC 0z7Kh0Lm2g4IgLHNZtfEMCAtXyxpfYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1721300357; 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=S3eV4tzn99V5QCNtsrHXIAbjIOXiUl0vRGMsjIKRQw0=; b=NbhZQkeVeCNXG/5vzvKd+hQQ5SapWr4Znt38EgWYmc+HQiaV0WXSpR3JdMor0elYCnFmiy jXbfPE4afZn32cBg== 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 D5364137EB; Thu, 18 Jul 2024 10:59:16 +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 UEFJL4T1mGbnVAAAD6G6ig (envelope-from ); Thu, 18 Jul 2024 10:59:16 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [PATCH 4/9] arch/sparc: Teach arch_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Thu, 18 Jul 2024 12:58:58 +0200 Message-ID: <20240718105903.19617-5-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240718105903.19617-1-osalvador@suse.de> References: <20240718105903.19617-1-osalvador@suse.de> MIME-Version: 1.0 X-Stat-Signature: g67oypw8bb3xsgi4f1cfxa5xw6tszbx5 X-Rspam-User: X-Rsp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vdXeCThxA7frX3DiL3CY4qYXuufMQE2MDHGEZrMmYBTzvJ/CdhnC82WrAiIlem05ktkbhj1J/oNq+cEUiKtp2OWGmGoRdOEJleJMjvlueRfT0Hbx3AquC6e23WBzEs1Dk1c7HmWEEca5lahKLi94mjntr3gmH+lZgKreSRzsKLL8tUo89YY8dAzovcYrExm0yYrPAIO3L9YImLyzxtq9dtEPsgKTh8a/pLqiftFJuQm1Kvnub46wzMi9ClywBw== 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: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach arch_get_unmapped_area{_topdown} to handle those. sparc specific hugetlb function does not set info.align_offset, and does not care about adjusting the align_mask for MAP_SHARED cases, so the same here for compability. Signed-off-by: Oscar Salvador --- arch/sparc/kernel/sys_sparc_32.c | 16 ++++++++++---- arch/sparc/kernel/sys_sparc_64.c | 36 +++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 08a19727795c..fc33ac48ed28 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c @@ -42,12 +42,16 @@ SYSCALL_DEFINE0(getpagesize) unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -62,9 +66,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = addr; info.high_limit = TASK_SIZE; - info.align_mask = (flags & MAP_SHARED) ? - (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + if (!file_hugepage) { + info.align_mask = (flags & MAP_SHARED) ? + (PAGE_MASK & (SHMLBA - 1)) : 0; + info.align_offset = pgoff << PAGE_SHIFT; + } else { + info.align_mask = huge_page_mask_align(filp); + } return vm_unmapped_area(&info); } diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index d9c3b34ca744..81d8f5467dd8 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -87,6 +87,16 @@ static inline unsigned long COLOR_ALIGN(unsigned long addr, return base + off; } +static unsigned long get_align_mask(struct file *filp, unsigned long flags) +{ + if (filp && is_file_hugepages(filp)) + return huge_page_mask_align(filp); + if (filp || (flags & MAP_SHARED)) + return PAGE_MASK & (SHMLBA - 1); + + return 0; +} + unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct mm_struct *mm = current->mm; @@ -94,12 +104,16 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi unsigned long task_size = TASK_SIZE; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false; + + if (filp && is_file_hugepages(filp)) + file_hugepage = true; if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -111,7 +125,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; if (addr) { @@ -129,8 +143,9 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi info.length = len; info.low_limit = TASK_UNMAPPED_BASE; info.high_limit = min(task_size, VA_EXCLUDE_START); - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) { @@ -154,15 +169,19 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, unsigned long addr = addr0; int do_color_align; struct vm_unmapped_area_info info = {}; + bool file_hugepage = false /* This should only ever run for 32-bit processes. */ BUG_ON(!test_thread_flag(TIF_32BIT)); + if (filp && is_file_hugepages(filp)) + file_hugepage = true; + if (flags & MAP_FIXED) { /* We do not accept a shared mapping if it would violate * cache aliasing constraints. */ - if ((flags & MAP_SHARED) && + if (!file_hugepage && (flags & MAP_SHARED) && ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) return -EINVAL; return addr; @@ -172,7 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return -ENOMEM; do_color_align = 0; - if (filp || (flags & MAP_SHARED)) + if ((filp || (flags & MAP_SHARED)) && !file_hugepage) do_color_align = 1; /* requesting a specific address */ @@ -192,8 +211,9 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = mm->mmap_base; - info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; + info.align_mask = get_align_mask(filp, flags); + if (!file_hugepage) + info.align_offset = pgoff << PAGE_SHIFT; addr = vm_unmapped_area(&info); /*