From patchwork Tue Nov 23 09:12:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12633789 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 4E0CCC433F5 for ; Tue, 23 Nov 2021 09:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1B886B0071; Tue, 23 Nov 2021 04:13:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCBEA6B0072; Tue, 23 Nov 2021 04:13:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBBC76B0073; Tue, 23 Nov 2021 04:13:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id ACFB06B0071 for ; Tue, 23 Nov 2021 04:13:17 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 56E3580D8A63 for ; Tue, 23 Nov 2021 09:13:07 +0000 (UTC) X-FDA: 78839630814.28.8E841CC Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf12.hostedemail.com (Postfix) with ESMTP id 121A410000B2 for ; Tue, 23 Nov 2021 09:13:06 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id iq11so16076638pjb.3 for ; Tue, 23 Nov 2021 01:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id; bh=IhjIetNetT6qmB9LARJqE5v76doIVBs8Q7TKsq/HG8Q=; b=AkLzGfw4+F8CJ9fF/abn/I0PrLIsdLLboA+t+s140Uugrlyzqz8q9cRu/MZ/tX+UKF 6bhvWojmP0reYDdcAKGO5+RteAxWrd/zwZ8O4dgIw045cq80plKwPiRTokHz+AUH5abh OWDRrGe5QtBkq3I2vJxqwbpCfEmApgcRNn0t/CPScotyi0POocQqtqih59xl2xEbBK/K p98VQBRm3L8JfbdWGtNAtrbYEtCY1gYPgVBD1LwB5zYCjbjAo8QaUpL5fChGERHSOIE5 dxOlIIplbWr6Tz4VO7JVm2xMQup6IATsVemElgm+0K89Np72gU4Hdi0BmKucu4mGnMCQ oN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id; bh=IhjIetNetT6qmB9LARJqE5v76doIVBs8Q7TKsq/HG8Q=; b=7r0Mp/TOd6BnL6oZDmBKr6eb88l5ni1ArL0CL6nuq9/ZUrgBfCSE1xwDWQ+aspMBOP 3+17Za2JXYAgi2HPgTa/6/L2uGcxFGSvQ46ZexHATqkL3KIQiF/a7E1mmrAatprNOeFn zYsJfJSbALFgwxGWv75PmYNlNA0S+L6UpZ7UwQSMN1HFDZgQ1TQtHDbnDVXBU5QaDWLq V7QC3uJHeMeRdxIKKOrFW1XoPSJ5i//liUBUWSWLfQlOESazopyTXKrTSRTgBd6kJnow 8oxLv5O19Hs2ii9Erhc0Dqfu1Tl2BVO6bLfQS78hssCNxFKS807NsgFbAU/49avjzCFy P4Dw== X-Gm-Message-State: AOAM532+QvQJ6b8hmIrmvmBoU3xKgqEVfQQPb1irtwZSQlIT0KU8osZV W7E/3uXHrTEi4ipX48Xcao0= X-Google-Smtp-Source: ABdhPJyo8n3nygHcG82M1fw75T5wAf5eIa+B0GHui15YxgyXgAVaxZZUMgo1hUmjftlPBrZaMCLSLA== X-Received: by 2002:a17:90a:d684:: with SMTP id x4mr1050157pju.244.1637658786119; Tue, 23 Nov 2021 01:13:06 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id ls14sm637665pjb.49.2021.11.23.01.13.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Nov 2021 01:13:05 -0800 (PST) From: Huangzhaoyang To: Ard Biesheuvel , Catalin Marinas , Will Deacon , Anshuman Khandual , Andrew Morton , Nicholas Piggin , Mike Rapoport , Pavel Tatashin , Christophe Leroy , Jonathan Marek , Zhaoyang Huang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: introduce alloc hook to apply PTE_CONT Date: Tue, 23 Nov 2021 17:12:40 +0800 Message-Id: <1637658760-5813-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 121A410000B2 X-Stat-Signature: 467neo6frpiif79g8h6pu737zt9bs7yr Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AkLzGfw4; spf=pass (imf12.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1637658786-262521 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: From: Zhaoyang Huang Since there is no PTE_CONT when rodata_full in ARM64, introducing a hook function to apply PTE_CONT on the proper page blocks. Signed-off-by: Zhaoyang Huang --- arch/arm64/include/asm/page.h | 5 +++++ arch/arm64/mm/pageattr.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index f98c91b..53cdd09 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -46,6 +46,11 @@ struct page *alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma, #include +#define HAVE_ARCH_ALLOC_PAGE +#define HAVE_ARCH_FREE_PAGE + +extern void arch_alloc_page(struct page *page, int order); +extern void arch_free_page(struct page *page, int order); #endif /* !__ASSEMBLY__ */ #define VM_DATA_DEFAULT_FLAGS (VM_DATA_FLAGS_TSK_EXEC | VM_MTE_ALLOWED) diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index a3bacd7..815a06d 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -239,3 +239,48 @@ bool kernel_page_present(struct page *page) ptep = pte_offset_kernel(pmdp, addr); return pte_valid(READ_ONCE(*ptep)); } + +void arch_alloc_page(struct page *page, int order) +{ + unsigned long addr; + unsigned long cont_pte_low_bound; + + if (!rodata_full) + return; + + addr = (u64)page_address(page); + if ((order >= 4) && (addr & ~CONT_PTE_MASK) == 0) { + order -= 4; + do { + cont_pte_low_bound = addr & CONT_PTE_MASK; + __change_memory_common(cont_pte_low_bound, + (~CONT_PTE_MASK + 1), __pgprot(PTE_CONT), __pgprot(0)); + addr = (u64)page_address(page); + page += 4; + order--; + }while (order >= 0); + } +} + +void arch_free_page(struct page *page, int order) +{ + unsigned long addr; + unsigned long cont_pte_low_bound; + + if (!rodata_full) + return; + + addr = (u64)page_address(page); + if ((order >= 4) && (addr & ~CONT_PTE_MASK) == 0) { + order -= 4; + do { + cont_pte_low_bound = addr & CONT_PTE_MASK; + __change_memory_common(cont_pte_low_bound, + (~CONT_PTE_MASK + 1), __pgprot(0), __pgprot(PTE_CONT)); + addr = (u64)page_address(page); + page += 4; + order--; + }while (order >= 0); + } +} +