From patchwork Tue Oct 15 01:33:34 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: 13835657 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 90C4ECFC501 for ; Tue, 15 Oct 2024 01:34:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FEA96B00A5; Mon, 14 Oct 2024 21:34:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AE8B6B00A6; Mon, 14 Oct 2024 21:34:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 027D26B00A7; Mon, 14 Oct 2024 21:34:43 -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 D6B966B00A5 for ; Mon, 14 Oct 2024 21:34:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6192A40A82 for ; Tue, 15 Oct 2024 01:34:38 +0000 (UTC) X-FDA: 82674116994.19.6437BD9 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf17.hostedemail.com (Postfix) with ESMTP id 390B14000B for ; Tue, 15 Oct 2024 01:34:36 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Te5D2mGN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.177 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=1728955924; 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=vbK+DyWhNFTOskVhv1fyi/tJ2PP4Ej6g6TRuPbyIjZc=; b=icFmqOA6xUtwVc6IEEe1Crx4GWoLmbKZrXq1yBkYMQWKJk/inJk+RBD/UdbE+d0tSjdVe+ OItWub4fHG4lHpUMZVIVyvUB+FrAOn1cvnIFnYsM1MP+21ERvihiaIJqnJ4mgd3Tjf73rQ a9lI396qWtbGG2dQtwr2XLPMDY6h+hU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728955924; a=rsa-sha256; cv=none; b=l8o85z/ch9XZPBRUE8TPH9PTKKJJfhcDAj1YGvST0fZK1a1nlfxBJpi3TXQ09tShAkkPIb +gZn50eHxeoEYBQ1+KTdp4HMKRKzvdZcSbZ7QAmnAxtfHXO4yzUdww5iIk5KXJk9N3i5Hm est+Hg9aRr71+y0/pMcUudIw71WZJrs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Te5D2mGN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-71e483c83dbso2992843b3a.3 for ; Mon, 14 Oct 2024 18:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956080; x=1729560880; 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=vbK+DyWhNFTOskVhv1fyi/tJ2PP4Ej6g6TRuPbyIjZc=; b=Te5D2mGNhJVt8+jzMMyhf5aLZtC4lpD4i6vcysjBXZTlHbVTxvsIWbJOAAAy3CQ81B eswnrR6oZFwFmuLoV7vfQkYmkscqvQ9aUMnqfscqEAJxYOr8Kx5vFoGc2dWgiqhBsdGz jhxW6GFW+k5qYv6buxdsvkLhaHQwGL06cM55VR7fNcjL5C8ylfc/VbbU564P/dQeM8gN S14g3FskYy9x8tBL9KF4X64yt4iOv0oMkxQDhoom+iiU81A4foPxvpFBTV4l+lT4CeWw SwudoT+pUodMBiN4LkzZk7o7VsuvZ771iEctaOpfIB/W5x6uOlwmEhotKuWX/JcXcnHh tb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956080; x=1729560880; 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=vbK+DyWhNFTOskVhv1fyi/tJ2PP4Ej6g6TRuPbyIjZc=; b=u/FlR8cYGPeeXn67KA835TJGUIqs7dXzNxMJCuEFx1rNcogQGGqPKI+mIQX/QvPQKm KojBI85s86+7XNmdjUhenw5oUQNVmCa/uNBGP5kkWpmaIbJffgHMnVu7ujr+7TLpwvUv p2Ex5tHv15XtoPJbau+z6R3KVsfRlu6DXIu1AQple9oEiPnBh5x3IUOHq4VVIvFtns+J fbEW1+NxMauqC+QY5pbw2pwdwNPPAxwsy3D6nHmScIjDdXsPjpMwLMUCsDzTkQUzRo0E DG9sveIl1tneRVKSzdVlfPR338+x6f0hhQP8HYXZPBRJeR+AlIvdo9TkpFglvtHsyPZL 7Ijg== X-Forwarded-Encrypted: i=1; AJvYcCVhJL/QbNWqZhX4fk2sjQszX/2oLQoPnyM9JxUuU5bJixypZvFEOUN3Ah9q3hHoVEwS3cvJs4u9wQ==@kvack.org X-Gm-Message-State: AOJu0YzDaKyXRRb8p6vDKqnpqms0c8+0evBd1hmf9AYDKYzfq8zAK1IQ BkVTdncZ48QBq6oy6ON55um9j4JFLDE9dOTQ7N3VKUMnYcAyr6xb X-Google-Smtp-Source: AGHT+IHF1r2QtlGKVN6HtXXxcFg+k0gYJd/nSgLWyKs83ZTBLQXCdo//6FQThWun5q5jEjrAv0//bA== X-Received: by 2002:a05:6a00:189d:b0:71e:768b:700a with SMTP id d2e1a72fcca58-71e768b7107mr1328450b3a.23.1728956080395; Mon, 14 Oct 2024 18:34:40 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:39 -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: [RFC RESEND v2 11/13] book3s64/radix: Refactoring common kfence related functions Date: Tue, 15 Oct 2024 07:03:34 +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: 390B14000B X-Stat-Signature: obcr9xebeejm77tcmfi31jfst1esois7 X-Rspam-User: X-HE-Tag: 1728956076-870721 X-HE-Meta: U2FsdGVkX1/jHwclXIrSWyisuiUFpuccXad/qLrrz4c2FjAJx9maB2074KqH9J4ORuCOjQABiMWT0czoTUZtQveSKXMTkRj4kFQi1xPFb/kuCFj3JgJ4MtcSjgnEzUUv+Kvjnms1ba3K0wpMp0kmgJdzZyuUOqXHjKfSu9KIK6++bklP0HH3SBNNZ9D+InSPNRDPjXOhmVuSBS9Bp4LPMZFnCtRdjQrddsSHGVNmXTOfDC4GogTBHA16i42gmsXIu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-linux-mm@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 5a4a75369043..374542528080 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)