From mboxrd@z Thu Jan 1 00:00:00 1970 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 05823C433EF for ; Fri, 24 Jun 2022 17:37:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B311E8E0241; Fri, 24 Jun 2022 13:37:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A94198E020E; Fri, 24 Jun 2022 13:37:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AF7E8E0241; Fri, 24 Jun 2022 13:37:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6403E8E020E for ; Fri, 24 Jun 2022 13:37:15 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3C7B760BA6 for ; Fri, 24 Jun 2022 17:37:15 +0000 (UTC) X-FDA: 79613835630.16.4525EED Received: from mail-vk1-f201.google.com (mail-vk1-f201.google.com [209.85.221.201]) by imf18.hostedemail.com (Postfix) with ESMTP id CF53A1C0096 for ; Fri, 24 Jun 2022 17:37:14 +0000 (UTC) Received: by mail-vk1-f201.google.com with SMTP id l19-20020ac5c353000000b0036c1d249b61so910934vkk.12 for ; Fri, 24 Jun 2022 10:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=t5KTYrM6ct0JWom4isvAtP154HT/fkrm8rvSO1JL/WI=; b=M7hxU1278b0Lh3tABv6L9l9qZ4Alxa0YOqUCt2BED4X975N8JVezOpIosUzb1pRlq1 SX94qvz3QX67rX7o3GZ8S0leLb7FFHhNK9SdbX2Rb4HmWbI4dwX/Y22ct/UwPlrwOYgo BEGkS4HWHIzpNKTgxCJfh6kCkdYmxrPG3Nl2ni6y2MM4kjfXPF2tIOcXuallnel4T3/F /EtqJ7IGlIBOBHTK/RDkilRjqZ1ZMgNfsJXOMiaLWaQMYD1+JF22Fefkl8MXbu5xw4Co KYFTD830ASsGDKWn3Fb3Id7J7wa0mQKCv+6AwRNyDerpkb98fQtJVbUhtnQtE3T/QsCS 4F8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=t5KTYrM6ct0JWom4isvAtP154HT/fkrm8rvSO1JL/WI=; b=DnOeHtWsiwA7seiax8mHTYvAfwluTw+sLOmo+0NaYwTlrvKIpN1stqLccW36exdbSv fy9/r5XJAWP0Q8br8HPwZHdECk601pY5+xfJwKdAyIqF6i19BsmCqhLGUCuPC55Kwar2 eiKBpqied6B/PJ/J6aoOJ4PBpaHgX98vxtG9YU1FdA4QuHeymVPmIT4YtqkYuyFSNmMv vMtfQ9mNT6ChDY0lNhQel9KVXWJrJo1VMjrPoYXsC72gIlGQJwDgPeCZLGfC015+FM9v Es4TofQEEdLEIi9JUtGpy5C15M7FPHwBSRwgmyFlCJOkIc+wHw345vKptuwLMhSHyFwS b5eA== X-Gm-Message-State: AJIora+02pkYwLoc67+8PluoRrmhnhAydKLYGLe1EkJbRsBqbRRoVesX spQrG8PqOZPql2jvKNNpEhlmqMNp0sagNQ6o X-Google-Smtp-Source: AGRyM1s3Rhw53YqM2sURrEy49E22RRF/1tHTOyTtY+rHKd8zIb/K3DKzbqQUo9FnKORpPjSO3ZnTjnoOojVZvhpT X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6102:3ec8:b0:335:d67e:7535 with SMTP id n8-20020a0561023ec800b00335d67e7535mr71521vsv.47.1656092234176; Fri, 24 Jun 2022 10:37:14 -0700 (PDT) Date: Fri, 24 Jun 2022 17:36:33 +0000 In-Reply-To: <20220624173656.2033256-1-jthoughton@google.com> Message-Id: <20220624173656.2033256-4-jthoughton@google.com> Mime-Version: 1.0 References: <20220624173656.2033256-1-jthoughton@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [RFC PATCH 03/26] hugetlb: add make_huge_pte_with_shift From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Jue Wang , Manish Mishra , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656092234; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t5KTYrM6ct0JWom4isvAtP154HT/fkrm8rvSO1JL/WI=; b=aLcRqw9xrzXaHBmEnpgehTcgvnvO+AwhtQfxP2PYPN44cgl0KSe4110gmYNyawonhARv8q R/eTkIE8PBfsZPkG9mtlY7ZiNZR+r0bUUhx4qZScsnfXSmw2mhICGaof5LDD/Rbt8UV0Rw gPVCF1uNOQt2DMs84vTk49kn79RBxHQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=M7hxU127; spf=pass (imf18.hostedemail.com: domain of 3Sva1YgoKCCsQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com designates 209.85.221.201 as permitted sender) smtp.mailfrom=3Sva1YgoKCCsQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656092234; a=rsa-sha256; cv=none; b=vqArc7n1766+Drgu0Cv8f2MN3FnJNoSxE3QsAj1/R7/iJ46gdOGbjgZMT3luQIRY++Xu/5 p+/NffMXL4qhSIo29tfQgUdOrZDCmmJsu+XsNYFGzXWmYkq8kAGqrAt5EJzyopTEecE132 U1CnfWP3Ydq11LzwD2JH3Q85eMkc6Ps= Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=M7hxU127; spf=pass (imf18.hostedemail.com: domain of 3Sva1YgoKCCsQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com designates 209.85.221.201 as permitted sender) smtp.mailfrom=3Sva1YgoKCCsQaOVbNOaVUNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: ebwgpjmdu79o4rz1ge4rk8se8g6bmkc6 X-Rspamd-Queue-Id: CF53A1C0096 X-HE-Tag: 1656092234-509218 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: This allows us to make huge PTEs at shifts other than the hstate shift, which will be necessary for high-granularity mappings. Signed-off-by: James Houghton --- mm/hugetlb.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5df838d86f32..0eec34edf3b2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4686,23 +4686,30 @@ const struct vm_operations_struct hugetlb_vm_ops = { .pagesize = hugetlb_vm_op_pagesize, }; +static pte_t make_huge_pte_with_shift(struct vm_area_struct *vma, + struct page *page, int writable, + int shift) +{ + bool huge = shift > PAGE_SHIFT; + pte_t entry = huge ? mk_huge_pte(page, vma->vm_page_prot) + : mk_pte(page, vma->vm_page_prot); + + if (writable) + entry = huge ? huge_pte_mkwrite(entry) : pte_mkwrite(entry); + else + entry = huge ? huge_pte_wrprotect(entry) : pte_wrprotect(entry); + pte_mkyoung(entry); + if (huge) + entry = arch_make_huge_pte(entry, shift, vma->vm_flags); + return entry; +} + static pte_t make_huge_pte(struct vm_area_struct *vma, struct page *page, - int writable) + int writable) { - pte_t entry; unsigned int shift = huge_page_shift(hstate_vma(vma)); - if (writable) { - entry = huge_pte_mkwrite(huge_pte_mkdirty(mk_huge_pte(page, - vma->vm_page_prot))); - } else { - entry = huge_pte_wrprotect(mk_huge_pte(page, - vma->vm_page_prot)); - } - entry = pte_mkyoung(entry); - entry = arch_make_huge_pte(entry, shift, vma->vm_flags); - - return entry; + return make_huge_pte_with_shift(vma, page, writable, shift); } static void set_huge_ptep_writable(struct vm_area_struct *vma, -- 2.37.0.rc0.161.g10f37bed90-goog