Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4822442ybl; Wed, 22 Jan 2020 05:24:44 -0800 (PST) X-Google-Smtp-Source: APXvYqz04aF73zClmLMGv0EeJKY5Y4XjkJsiahxIof+cQ+KfmNaVFeKnXeKygnIY1INUi98/QWJx X-Received: by 2002:a05:6830:154c:: with SMTP id l12mr7206782otp.275.1579699484147; Wed, 22 Jan 2020 05:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699484; cv=none; d=google.com; s=arc-20160816; b=ezIW/FO3Iq6XSGa4L2vKMTOPRsAYSX64v8fc6wqkH2SWwqZVtiAozoWqkpa6U85g9+ FWta0AM7MHbcznl6cepRY3FpKGUleS5J9IbDt8ive+/ebi4ID6OItVysWQ9zRA4irB8N S5wBP1eqGstKkTQco7FIu57uaDTNO7/NOmkk88tmFsLWRgHRqlyLmP8iUd3KdoEwxOXM Fv05bry14+0w472QBHJncMEMjSDQE0o8MBgi8+M1dAEL1bZdNIoRug7OLDVRRFe/FzTV O7OqV/F3aTLnxFJrtF8cOO9sSmNwILjfcmXCZnUZ2pRyIhURh4+oqXiAMffbvcXIcXr+ mBZA== 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=wwzfuhmtJpq62DcUk4MoHxIbkBmki+MrNYO1XgVzC7w=; b=aBJbeIyHe2V/nAp68Bkd5vfg+aKWpMsWF+m9vTVvko5OVXsVk08v0cF0it/9DWJJkA sAFQEyY8j/Ky689jRmrPzmVdAb/ofNRTf5rDsjshTVg0ZQdgpWfBiNbrsQ81i0Sdpcos NRKh0GXuOyzKIlEUjIHoNUdk9ezvlKWv6hcWRNDVCf5FYrBvTHVwENcldHP4v9RdMdNR X1W3JChu4X1eCRbxXjBiEwDufWvpw1v8M3GbLgHMwqEQdFJ42rtBfivqgyuuYAx+fUfW CWuaZwkLTnbmogVgNjyOLxL5+Ui0XkYmhGe4owvHVgzjvS7HnAL6DHztwU35xHM4NRRZ u+DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ajVoK6n8; 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 v67si22313182oia.26.2020.01.22.05.24.32; Wed, 22 Jan 2020 05:24:44 -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=ajVoK6n8; 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 S1730538AbgAVNWX (ORCPT + 99 others); Wed, 22 Jan 2020 08:22:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:39874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729992AbgAVNWU (ORCPT ); Wed, 22 Jan 2020 08:22:20 -0500 Received: from localhost (unknown [84.241.205.26]) (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 D145B24688; Wed, 22 Jan 2020 13:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699339; bh=l8E9WhQUYdRFLvGLz94bVCMxZ6KMHAl9UrG+udAtBWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ajVoK6n8gGZI6FN+7AFZCCWPAYkXuNtaxovb68ZEV5Gj0xNws99jHOCCYIiuVNyha fO+E+uXwx/VRToDX8G8kZT9KOPhBxrWUao7dmMqi6j3/Z8zj7TCFl2SY0R9ood1Dso n0qkx+quMIU0sHdeJxF78S8Adp2u5AxC5fdkdeJg= 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 5.4 078/222] mm/shmem.c: thp, shmem: fix conflict of above-47bit hint address and PMD alignment Date: Wed, 22 Jan 2020 10:27:44 +0100 Message-Id: <20200122092839.299021330@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@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 @@ -2106,9 +2106,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) { @@ -2142,7 +2143,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)