Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4634251ybl; Wed, 22 Jan 2020 01:42:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxcCz+Jq4uu2LrKzWoSjbHOOkU4FmZVlJ2FSaSxUNuDTlKc+fOztDFm+nDAuSsepxB5227q X-Received: by 2002:aca:a9c5:: with SMTP id s188mr6285648oie.154.1579686136445; Wed, 22 Jan 2020 01:42:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579686136; cv=none; d=google.com; s=arc-20160816; b=FT1Qv/+LAMDj0y9eEgdzWNMkMkLkm70DtCiljRs74CwJn6WTIqFtjC4Ro+0cjvmH0V NbLI52wKqHtYMVveF48qLU7UG4PVwiGYMX64eerA1csPlWI5F/k0kp/nHwqGY9ty0pIa 9jsNW7V7lfeQAuYDGU53g3dVRIjh2vkmDlpOoqoYeILUxXqhLBovX3iRZWo1s5POW5oO z2toOqLEdLJPbzdiZR2jNxKw8fSvPeNY25efqKyZP2iQ63hN9Xo3vu02DkRbIvxOI3KT lbHLjGRuLANGsetsf1Pn1hI3/aXKuT3KKztFzKL+8/v+gXAnzAUmnoDqfLVuIBL45lys AquA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sQn82M5HvjxND3lhQL6NtxT9aCwlaYYIsj0q7DqX86Y=; b=BwzvzxDmYze/MypP/OencAiCTrHd5u8UTh639FkvQFKVIeVhcG3zSlgQUiuwd/v+qX cue1Yk8n1p1rs1vM+wRvBKVUZ3v5b8lyTPJiMctzt3Y/8U1eu3HffokXb+B2qzdnVx1t Yp2rNDzmLMf8VnkEhD5kKPntveDZYgezVY/Kh0XYa8YFVnaGbDEOtjBI8CTRYqTob85g p9EUs6mA2VUeuaI/ZQbWMR4+RvNExQ2uVN9sCkz3NbC3b2m+K00ViiDPgEv/URipSnws q7lJzPQyw9yPBC2X3YNUg8ujldp0M1+JG1tCDvmN1yoHs/duPfw8UuwBnn1VlPIVVNNw awfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EIefOkZa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si20289528oix.197.2020.01.22.01.42.04; Wed, 22 Jan 2020 01:42:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EIefOkZa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732391AbgAVJkN (ORCPT + 99 others); Wed, 22 Jan 2020 04:40:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:58752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732879AbgAVJkK (ORCPT ); Wed, 22 Jan 2020 04:40:10 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F1AE524686; Wed, 22 Jan 2020 09:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579686009; bh=6peGELComVwPJobIqCDWWvnmKmDPtlCrb3OFIpVkbPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EIefOkZaC+qqRYB4NLF94tbvQWbpLbCnS1PUZW/V6y2TZgovw/b15oKggxNE8GbJp 9zrAwtth7mVwSIc9IQAWPkuUQUGIf9dV9r98/lRfFmwZW8MEHj2ojXDW6FatrRiWXi 2fjyIkM42bfDdbEZ1puKjX5elTXh9DtIPqZvyX1g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kirill A. Shutemov" , "Willhalm, Thomas" , Dan Williams , "Bruggeman, Otto G" , "Aneesh Kumar K . V" , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 26/65] mm/shmem.c: thp, shmem: fix conflict of above-47bit hint address and PMD alignment Date: Wed, 22 Jan 2020 10:29:11 +0100 Message-Id: <20200122092754.541271857@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092750.976732974@linuxfoundation.org> References: <20200122092750.976732974@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kirill A. Shutemov commit 991589974d9c9ecb24ee3799ec8c415c730598a2 upstream. Shmem/tmpfs tries to provide THP-friendly mappings if huge pages are enabled. But it doesn't work well with above-47bit hint address. Normally, the kernel doesn't create userspace mappings above 47-bit, even if the machine allows this (such as with 5-level paging on x86-64). Not all user space is ready to handle wide addresses. It's known that at least some JIT compilers use higher bits in pointers to encode their information. Userspace can ask for allocation from full address space by specifying hint address (with or without MAP_FIXED) above 47-bits. If the application doesn't need a particular address, but wants to allocate from whole address space it can specify -1 as a hint address. Unfortunately, this trick breaks THP alignment in shmem/tmp: shmem_get_unmapped_area() would not try to allocate PMD-aligned area if *any* hint address specified. This can be fixed by requesting the aligned area if the we failed to allocated at user-specified hint address. The request with inflated length will also take the user-specified hint address. This way we will not lose an allocation request from the full address space. [kirill@shutemov.name: fold in a fixup] Link: http://lkml.kernel.org/r/20191223231309.t6bh5hkbmokihpfu@box Link: http://lkml.kernel.org/r/20191220142548.7118-3-kirill.shutemov@linux.intel.com Fixes: b569bab78d8d ("x86/mm: Prepare to expose larger address space to userspace") Signed-off-by: Kirill A. Shutemov Cc: "Willhalm, Thomas" Cc: Dan Williams Cc: "Bruggeman, Otto G" Cc: "Aneesh Kumar K . V" Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/shmem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2052,9 +2052,10 @@ unsigned long shmem_get_unmapped_area(st /* * Our priority is to support MAP_SHARED mapped hugely; * and support MAP_PRIVATE mapped hugely too, until it is COWed. - * But if caller specified an address hint, respect that as before. + * But if caller specified an address hint and we allocated area there + * successfully, respect that as before. */ - if (uaddr) + if (uaddr == addr) return addr; if (shmem_huge != SHMEM_HUGE_FORCE) { @@ -2088,7 +2089,7 @@ unsigned long shmem_get_unmapped_area(st if (inflated_len < len) return addr; - inflated_addr = get_area(NULL, 0, inflated_len, 0, flags); + inflated_addr = get_area(NULL, uaddr, inflated_len, 0, flags); if (IS_ERR_VALUE(inflated_addr)) return addr; if (inflated_addr & ~PAGE_MASK)