From patchwork Fri Oct 18 17:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13842092 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 8C08CD3DEA0 for ; Fri, 18 Oct 2024 17:31:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17F806B00A7; Fri, 18 Oct 2024 13:31:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 131466B00A8; Fri, 18 Oct 2024 13:31:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F110D6B00A9; Fri, 18 Oct 2024 13:31:15 -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 CB5FD6B00A7 for ; Fri, 18 Oct 2024 13:31:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1E925A08D8 for ; Fri, 18 Oct 2024 17:30:53 +0000 (UTC) X-FDA: 82687413648.08.6FAB082 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 3565F20014 for ; Fri, 18 Oct 2024 17:31:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZeQMro5J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272512; 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=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=NjhgmZaCRMIYEe7lWAG2WPTF3CU3H+SU9+Wvpji3vXsMV2F6ShoYTBmaaJBo0xWa284hBb b0RSmNiXRE5yPNfqxxTVybPz+yrXLIHgsQwwXJDGOZRzwS+znGkLqayuko+0RkclvqwiK/ 7DlNmXAbzJUrM6WJY827/21kwO5MHVg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272512; a=rsa-sha256; cv=none; b=tk6GJKUMD83ZMF6Urs//KIMZLDXTcJwIonwN7LyB5jtcSb71T1vfMr19vDyTLDFyCkuDnw bVjnfH7JHPb2t73qRxPCU2yW7ET+vrjLlq0YhlydCVsVufJIUCwvz8ZfgoWOeXTjh2DFTN jRK6aRfNN0CO0tGd6ZBjIlWf2opD8Nk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZeQMro5J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71e7086c231so1828704b3a.0 for ; Fri, 18 Oct 2024 10:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272672; x=1729877472; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=ZeQMro5J8hstSYDafwns0kvxSg7pFaxUoh7pZYd5e/OcYZ8kDjhs64pmdOFqr7LHNI lj09R0Xe+2oGe/9LCeYAfXhOrSglnqMfWlMnpbQ07ht4gHWhdf//X6IHpb8hPdd/J7yj 5KQDp0BjLhmYvwSlwUA6PxsB2G47AcPgGoT1uy0+CU/VvjzbPipcYrsh2Ge6rLLBcfbB IveuvF3n/OuvhjZz6Tw3rtmjfmvCuHzttbKIFXUk6ueHcDkLMR7Q801sJHSA9/cVqRKV tV7tbjLXJkR748I4zOgUue5HL3Z4fyoLgc17yjK2Va9ty/mQqLC5GF43vNNsVn9prw8U STGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272672; x=1729877472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=NvLG8h3QnsoPPXuzJgh6PkS9GIFSPQ1n/nVUIFB13iX9XUp7mA0i9Gt0F4SOIOlYKq V/fYW0GL4aOQA99lvtC9oNkN21e1qNF5d+X3t+sSaAXhyAl89wY61V058tc/RSk3bwRm MovPx3OLlGlCVUTdjDCk08HBVR4iDPFa9u3yCuEHAyPmek8SzBxvBZnN6KLMJrgZ9nva kulzDhVjK1L50EHUWODh2HVXdXpMyT2Y160ehGsYtZvn8ZAX7545tewvzV8vnk2yUtIV oRAc7R+LCvLIXJqNOpD5zVbrAm7GgyYj1byE3mMduZ6YVomm90bU/ttVXeog2rJvbu2P 6nXw== X-Forwarded-Encrypted: i=1; AJvYcCUqo8z6W3pdmXst1VXYAFsu7LLB9Ro2xPHoGxbk54y7GLi+GHDDDeuTx3HeDuqb1xoHx4LN5cll3g==@kvack.org X-Gm-Message-State: AOJu0Yy21S4apUNWlTLz7KUWN6e1za2pEZ+foK68dW7UMf4pWysBMKRD QcCqRvBqmmd+R7S7HE2+qz8Kvmi8wMB4DRoZKp85BepAafPmnwqI X-Google-Smtp-Source: AGHT+IGCcfcvV3hhkWCRVZ4L4+07qgofxPBOFcgBhHnT233XbATfjI7cFHkLMcuk8gJsatcgaCUiZQ== X-Received: by 2002:a05:6a20:43a0:b0:1d9:a90:8879 with SMTP id adf61e73a8af0-1d92c502994mr4770966637.21.1729272672394; Fri, 18 Oct 2024 10:31:12 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea3311f51sm1725242b3a.36.2024.10.18.10.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31:11 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [PATCH v3 10/12] book3s64/radix: Refactoring common kfence related functions Date: Fri, 18 Oct 2024 22:59:51 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3565F20014 X-Stat-Signature: q8di3tusfbotcbusytfb4x9szs8eotmf X-Rspam-User: X-HE-Tag: 1729272668-292308 X-HE-Meta: U2FsdGVkX18Rq/Y8ihXfEbfjSQeOdAu14ioHDyxct5EeyvgU0GSpSzx2XgQ8npJQwKZ9T+dxDdB5c30nDUDbG5WWGuSjj8/lXJGNS7n7DRkaQXtGtu5xsHX6QuFZIYFXDqklSfnD8ZvYgGpg/Mc9XNMvkp289u067elxr+7MEgKXaSDF1lcNNlrfvmYKhJ1pN/A4s8DZ7MKDaw6EhWuJkfPTtFoPxKF3tJjwgBqrGQ1nlk/LjO83vZwqvTw0R2fvy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m@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Both radix and hash on book3s requires to detect if kfence early init is enabled or not. Hash needs to disable kfence if early init is not enabled because with kfence the linear map is mapped using PAGE_SIZE rather than 16M mapping. We don't support multiple page sizes for slb entry used for kernel linear map in book3s64. This patch refactors out the common functions required to detect kfence early init is enabled or not. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/kfence.h | 8 ++++++-- arch/powerpc/mm/book3s64/pgtable.c | 13 +++++++++++++ arch/powerpc/mm/book3s64/radix_pgtable.c | 12 ------------ arch/powerpc/mm/init-common.c | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/kfence.h b/arch/powerpc/include/asm/kfence.h index fab124ada1c7..1f7cab58ab2c 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -15,7 +15,7 @@ #define ARCH_FUNC_PREFIX "." #endif -#ifdef CONFIG_KFENCE +extern bool kfence_early_init; extern bool kfence_disabled; static inline void disable_kfence(void) @@ -27,7 +27,11 @@ static inline bool arch_kfence_init_pool(void) { return !kfence_disabled; } -#endif + +static inline bool kfence_early_init_enabled(void) +{ + return IS_ENABLED(CONFIG_KFENCE) && kfence_early_init; +} #ifdef CONFIG_PPC64 static inline bool kfence_protect_page(unsigned long addr, bool protect) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c index f4d8d3c40e5c..1563a8c28feb 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -37,6 +37,19 @@ EXPORT_SYMBOL(__pmd_frag_nr); unsigned long __pmd_frag_size_shift; EXPORT_SYMBOL(__pmd_frag_size_shift); +#ifdef CONFIG_KFENCE +extern bool kfence_early_init; +static int __init parse_kfence_early_init(char *arg) +{ + int val; + + if (get_option(&arg, &val)) + kfence_early_init = !!val; + return 0; +} +early_param("kfence.sample_interval", parse_kfence_early_init); +#endif + #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * This is called when relaxing access to a hugepage. It's also called in the page diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c index b0d927009af8..311e2112d782 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -363,18 +363,6 @@ static int __meminit create_physical_mapping(unsigned long start, } #ifdef CONFIG_KFENCE -static bool __ro_after_init kfence_early_init = !!CONFIG_KFENCE_SAMPLE_INTERVAL; - -static int __init parse_kfence_early_init(char *arg) -{ - int val; - - if (get_option(&arg, &val)) - kfence_early_init = !!val; - return 0; -} -early_param("kfence.sample_interval", parse_kfence_early_init); - static inline phys_addr_t alloc_kfence_pool(void) { phys_addr_t kfence_pool; diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c index 2978fcbe307e..745097554bea 100644 --- a/arch/powerpc/mm/init-common.c +++ b/arch/powerpc/mm/init-common.c @@ -33,6 +33,7 @@ bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP); bool disable_kuap = !IS_ENABLED(CONFIG_PPC_KUAP); #ifdef CONFIG_KFENCE bool __ro_after_init kfence_disabled; +bool __ro_after_init kfence_early_init = !!CONFIG_KFENCE_SAMPLE_INTERVAL; #endif static int __init parse_nosmep(char *p)