From patchwork Mon May 24 09:25:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12276757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DB7BC04FF3 for ; Mon, 24 May 2021 18:00:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E6CB613D2 for ; Mon, 24 May 2021 18:00:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E6CB613D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=csO/NaumGTBtms11xw1h7nDur8+SH5URcaj1wDeHejY=; b=3T71LRRfjj8In9 EHk1zzr1kNbyTpyFsVXadFpgDTzw3bjd+hZ4hARKQeFJoshJCBZfMMmbkCI6yI7F27HX0piFQDTBz uAqM0326FykvdBUaFsFc3Ia2qM+f+dhuIpUnws5uG9gZwAxxRWSxnwjZ3m2oyYMU9T3PGZY4Jj+mG i/FqdfCzF+DzOWRwdGfnfeBuko2/KmdpBRJY/uO6A9lnHdvSp+51m+PSJYcm201VosqFnlCOh9i9Q wxxd+rkFy6ThdXxqUWyOI1OpTaE4/bYb6m2SVqcmQPqtJntZ/IsppaVL+uGUgNc0/+U0BTa/yGdvj U+vnhB0my59l8pzd9UpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llEpw-001Muq-K2; Mon, 24 May 2021 17:57:58 +0000 Received: from mail-mw2nam10on2050.outbound.protection.outlook.com ([40.107.94.50] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ll6r0-000nkY-VC for linux-arm-kernel@lists.infradead.org; Mon, 24 May 2021 09:26:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjhgAeO8wwJW4KWCQ5dJcdiiM3zkqcsTMc6JFrj2uBwgYxjAOYWK/vTB5spDkU/ZDWG+0mFLWpoTkzy60NlSTuFNJxUjqWD/qzxTfEoWMx06QHNc4Q/TtqzoC7bofzvqNLyn/BMUEAs1D5+5q+NQAAcMtfysEjXIBWCW3UsJCafOGBATyzvpoanfP06qg3GqJULx+44+OISsYNGgEkxckGrwN5gb5z4i5bfRcvviAb6VxpXOYbHP2TK2X13DQWc798JjeaZeMmlGiH89vi1F3GRx5PfsaOixfxtJ3exoon3B8SxOeKWzMDn3+rOOSOrstLU9sZoOkP2dQOf4kEREcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6M0nJU/y2MKjtfSlFmSxDKO8kQQbJQf3ehgUixbHk4A=; b=ixj30kcvisQs6iMv8pQKHVnqGadRLMr94irbBwGYYkgbMlddrvUNBHrkW0AtMO0p1JzpYoGqL+xattSTGiARbZKKU24tYNiItDV6FgaJRxs/POgKl/GI07Fea0hq2B9/K/VbEuPe0NP5498V9xh9NXkwEsbGkt3w8NxL6E0T/3sJ0YgAYqWG7pWeKBpQw8Ex3YnAfm3066tThVCl7jlM/5bcWqRvg5o0vA+g2bm7R/vniBPoIH49pKXAlN97GB+5Pn1qD+sRaO4lmhLgAIEarr6KXJZUMqvkkQihwa5pdBEybs+tiuwUYSox2/du+MYzy6SPQx4/1CtQWBLhluaW8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6M0nJU/y2MKjtfSlFmSxDKO8kQQbJQf3ehgUixbHk4A=; b=bQe6+eQavRbTPBlEHoNu5EwVQTDryAlJg9MvZOs3a+mthU2FfQI+cVUTjZP3X87u5mY1YuMnWZTPzWaYKMZAEUGPyuGNclLhm8/gxL34IG/kEEMUI6DSk8UyKMSX9jK7oeEL9RxW/Xwi0/1xcNhUEGpL3t7rmn3Sc596fM3th5I= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=synaptics.com; Received: from BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) by BN9PR03MB6188.namprd03.prod.outlook.com (2603:10b6:408:101::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23; Mon, 24 May 2021 09:26:27 +0000 Received: from BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791]) by BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791%4]) with mapi id 15.20.4150.027; Mon, 24 May 2021 09:26:26 +0000 Date: Mon, 24 May 2021 17:25:29 +0800 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH 1/2] kfence: allow providing __kfence_pool in arch specific way Message-ID: <20210524172529.3d23c3e7@xhacker.debian> In-Reply-To: <20210524172433.015b3b6b@xhacker.debian> References: <20210524172433.015b3b6b@xhacker.debian> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Originating-IP: [192.147.44.204] X-ClientProxiedBy: BY5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:a03:167::46) To BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xhacker.debian (192.147.44.204) by BY5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:a03:167::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.26 via Frontend Transport; Mon, 24 May 2021 09:26:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 212b5db6-68fb-4623-cbff-08d91e96014d X-MS-TrafficTypeDiagnostic: BN9PR03MB6188: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MVcBFegMUBkO7fU0YjcOqwYno3UYFc/Jgq9KIewO2toWp82wXWMRVvR/uMP8Pj1iMYKU0RMkWhrYJTCytSnwhV2GLiBCH1FngUvinN+aKSmySXZqACsmpU9Wf3tRQ0vUGeg4u2oTLfMjBBvaqE7ktuRjGPDyOjRPuwoft2fBGgAS02o5jVhvzyhSThtkuH5xjkmqZ+6DM40YzrGosvSJjm0lbvLXLE4dtLigO7nSwRWAx40+o7lqgy5I9Cblf9DjfTVVlr44yVKpYPaqUKqasn5ns7FuuuY0JT1SqOanr2xflKTG3RvXMKU0KTV3p5H5ms3eFHGombtFZrJjbZG3FgIvU0iITX+5Leu0nC2V99Ik7kkGbDCSsAFjj+XXyO/VA4mEv6aQBan/SSmBWYugMGzt6NORGZOYXe07mlY3Rvq5sgpL4DpexV98kMTk2xCOutr6B1E83u1OkOOD5pKuacDXHH/OQmkDCjhFDIEYmpn3GBWWw0N2uCvLOMHnsW8/zRXuTVILHha85Be5vvVAyqVorZlSnX1Uqtz1FTCZ8OzYY5qal0tdhRnow2v82MZbBb5XimXVzI8lmguiitFRoLneW3LjpqvzQA35AXJ2svaOQGO0HVzi577sJXVkJjOX1Uck8KyDS1AA0jgaG0LtqiokWGvU5Ry/fkdZtguTU9k= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR03MB6058.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(39850400004)(346002)(376002)(396003)(136003)(366004)(66946007)(1076003)(316002)(66556008)(66476007)(5660300002)(478600001)(2906002)(4326008)(110136005)(7416002)(16526019)(186003)(26005)(8676002)(52116002)(7696005)(956004)(55016002)(6506007)(86362001)(83380400001)(38350700002)(9686003)(38100700002)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0qMlpUMKtnluZ2JfT5oP48G8nX2hVfICByh/N/wcuAkrhB8IuWJZgphE7ICAVjBTyXkYeTbAH3V4ntXhCqmNRFXzhne7EZeI1OG7HZaLmGsvRc6DQj92pkaoV97ynW88BRkGat2lQbAShCJB9W9w8X7IWw2oQEyjo0IDTBnFhig0fFjcW5WHSSKdmc37u8MmOoDwI4zE6pKUPxV3VFp3ybPymTvEsqX6ZF8niLJRD7d/Ak6UO+Y8T0M2yA+Jif6ZTEnNvmhLU4K304LlhKJCCIVuszl/2eKzCtAkVnoUugomO6fz4n26yXuCOBdUsCzldkwiMtUECyrUk5fRLauVBDnHbnJfvtELz7Jrjfcr0cLDjMta2GXVCRVhW8iW6qsrZD6uIdGGpUQ3kln5oQGUDXebOgwCnQ7GtZZsjPn5IJpQz/7dZ+CuBKgBj4piP4d0RmvaqLkCvTmYVTEy9xkIdmf7+8Jir8wFDsgaNTWcTz+v85KJbzxH5SlxP1yfWbZCQcFsjK/F/gFDqELm2YGSx/HlfzujmWYV52iAWVw7ozyZ5koixXzwiuBxH0JRSdhj4BCmqe2tyBxcA8maUwpxKB2Kf+WCXDXzFP2UXa+i+Uy3iX+kmpUcR8eOBx6bAD2KSh+4gval2Y54yDpMdXEJ/7+KjzjIsOOvVYmPiLcIpZAH1YVre2ir1P9JsDDWR5ynHlrr4Icgy2yCQSw++aObZO1/WLNtyL4RsoMmPkG1yFT/x9cLyiqfGvdovAvNULNmJ//kPG+Rukn3H31DUk3bwMgj/zkECvrBXTgIu/6G5u/BcF6jnWsw56QsIhc79D8MtXuFcB8CRHOoDy8OrUHYp9oliQ2A527QS/MjfxLlIYuAlRGVwQs1dp7dzHwtT3G4IxYvF7nWHfZjeo+OnoryC62qmHvUbroq83aTzX0iTmvmSyhqgj8xyeAd2RTHcH+WBiU2VAExk5pwNzbdWN39YmG+1VAWZgubfcOXaSY0gUiHCG0S8Dvtjmo3mwbIsi5dpM7N9nrjcUMWOHhyXtt62lrkG4f/J72H9sAM+5Q+Qp1pHiggMACKZSR59xll5ufa+j0Fx8aGjY+3/bJRUEyAUe0Bj0gaUdq9w54hbUxX7Ikwko3WQFM6E1FT05DO47y37FUNNrDgtveK8CHKb8rdExeIxVS9M8LxpUqjEU6mYaBUIGcDFNZyS1FWcFB3WA3v0lf5E/LmgD7y3mH0cyGcjA77FW3rmTVuKPika4tfes8x7/S9FZulgk55YiGuyPIHH1nmv0eQpIbfm+I6LY8BhAjbKBlS79+A8dHsO1mDzqZ6+JbHQLdAOGOA4PhsODAo X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 212b5db6-68fb-4623-cbff-08d91e96014d X-MS-Exchange-CrossTenant-AuthSource: BN9PR03MB6058.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2021 09:26:26.7669 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CZRkAq73ytDBjrW+o+bNwG4TB+9naOak+z8LepMTL09TGP1P8l/gY0vREYptP6xErxvf22sfleFXhzBH+wATbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR03MB6188 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_022631_100861_C6FF1998 X-CRM114-Status: GOOD ( 11.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some architectures may want to allocate the __kfence_pool differently for example, allocate the __kfence_pool earlier before paging_init(). We also delay the memset() to kfence_init_pool(). Signed-off-by: Jisheng Zhang --- mm/kfence/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index e18fbbd5d9b4..65f0210edb65 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -430,6 +430,8 @@ static bool __init kfence_init_pool(void) if (!__kfence_pool) return false; + memset(__kfence_pool, 0, KFENCE_POOL_SIZE); + if (!arch_kfence_init_pool()) goto err; @@ -645,10 +647,10 @@ static DECLARE_DELAYED_WORK(kfence_timer, toggle_allocation_gate); void __init kfence_alloc_pool(void) { - if (!kfence_sample_interval) + if (!kfence_sample_interval || __kfence_pool) return; - __kfence_pool = memblock_alloc(KFENCE_POOL_SIZE, PAGE_SIZE); + __kfence_pool = memblock_alloc_raw(KFENCE_POOL_SIZE, PAGE_SIZE); if (!__kfence_pool) pr_err("failed to allocate pool\n"); From patchwork Mon May 24 09:26:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12277047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4AE1C2B9F7 for ; Mon, 24 May 2021 22:08:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88D1761425 for ; Mon, 24 May 2021 22:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88D1761425 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yX9Lx5UljUepBXAjBOyJHBzE3FxDnWqqRDi9hcQ/R4Q=; b=Acy+RSDKOBQG+A pwRVSw6UczmXd1u1X2y/acaSUzAG/4jml5Ocol0gHE2FpJBxyLYDXNf+pHktcymPRpf5BRjiRQfe/ DSeOHJF4RUSa11Ia4co6fJ4WowWbhuIIKf1uqo34B7azQ2XtYALFN15SdAwRe8NMLSc/Mz7MiRxwB KMkuKkDhhnSm0gDKF6WneEvOsYseg+2rciTc1cV5XUq9yYGNWBPmgSsbA6z/+2rt1G4iGEWGl1e+r ZUuSbWSLd8qsWvhI8E20Jl8IMcA6UftdHiaVEYQ2Cy5O5Xy2/DtQx4GOlKcHjnpifWLtWS+Cgr2Hz H+JiGinwuQ04NKLzntYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llIhj-0022wZ-PY; Mon, 24 May 2021 22:05:46 +0000 Received: from mail-mw2nam10on2083.outbound.protection.outlook.com ([40.107.94.83] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ll6rE-000nme-Ob for linux-arm-kernel@lists.infradead.org; Mon, 24 May 2021 09:26:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nX39UVXdJCf7e9SDYY3SnExtNZTlM/qhrjJhzV9M7522IO18MokMRrWAkybuRB+siXvnhw2DPp8w+b4LmHdDKw5uoteZVEx0S6/ZgbnICghrRwM50nrluWHyPFmrHwXWwQ11GykanDAkK4fGz3N1CPqSllPjCVMH3k+4n9WMhvtIqwE/tB9Iely3Wi11/S/y9QX7e1UTMXkFEiyCGGT/RTzzI2G/IFCtz0AySYIR8LdP1p4RbooBxoZLqSmSinIhnFbDGG3gEPNi89Yhw4XhcU/HyUELiq3dIbWS4cmF640jlWOA12YV33YBTrmEQSZBhEkjmHqe3xwVAWezEN+THw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yg7gEh75KCSRWy7ZOkeyvERqafWSItL3pI+nkwcPGtA=; b=Obcq4+9dfdVzrIJAxdKjFIBC//MfcNaLKYFV3MsFUwh4qUBqTPqreroDf/7SZWwKSmN1XWQ6dZ3XTo7hKCdL+98NWn/VNkFmhjg9dLNdmDnClrnvak4rWwp37gTpUCxlLF+awljbJFiBP/fRoZfq+Y631DLBTjELHTPORUCWqiZ5UlcSP3Q1ly8DYXpFREkMVL+EDXXgkyHXJdGQcAhqQr62BlUzoH06aVU7EQMdIEyX94zimCxwPTuuFxbq921LXSr22COhnTrU+c/wK8w7LxE0eu8IuovebIgnxH48LCt61EVeW9KUhMQ+/jwty8dgNls/6VzopedEpRYbknWztQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yg7gEh75KCSRWy7ZOkeyvERqafWSItL3pI+nkwcPGtA=; b=ir50RisU0e2oiok4LitI5xh2QOGWICV0sA6kOlM8u6pFRXO2iM9puucS53IlJDckzsPnJD3/HEyzKPG+pPGFX4jfNB+RQOecoGj727SHXlFEb8/ZI4bLNN0A4mihyv9VmcgzgU/T/5ARczgpXrqn60E4DC7cDxtm0Wb6dl65Wa0= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=synaptics.com; Received: from BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) by BN9PR03MB6188.namprd03.prod.outlook.com (2603:10b6:408:101::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23; Mon, 24 May 2021 09:26:42 +0000 Received: from BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791]) by BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791%4]) with mapi id 15.20.4150.027; Mon, 24 May 2021 09:26:42 +0000 Date: Mon, 24 May 2021 17:26:06 +0800 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Andrew Morton Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH 2/2] arm64: remove page granularity limitation from KFENCE Message-ID: <20210524172606.08dac28d@xhacker.debian> In-Reply-To: <20210524172433.015b3b6b@xhacker.debian> References: <20210524172433.015b3b6b@xhacker.debian> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Originating-IP: [192.147.44.204] X-ClientProxiedBy: BY5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:a03:167::46) To BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xhacker.debian (192.147.44.204) by BY5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:a03:167::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.26 via Frontend Transport; Mon, 24 May 2021 09:26:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c197b04-eea2-480e-953a-08d91e960aa9 X-MS-TrafficTypeDiagnostic: BN9PR03MB6188: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SF+h0OIsltN1lo+OaBe4aSGbPShl4BSOCnElbhf+6MFS0zB7SkagxwLHhB80m+VRU/s3tvIaXZ2t/iqf1IIsc0M83/ebn6LDmSzzEcz7gyFbOzEK/LH4K1c3DDuzwDGY9roYuz3PG80mb+cLeuokNsHi9N70Sm8rcJcLrfzGeFctOiuYWw5JDjjKg1YVWGSWbbYz83Zytc9iGISAPaagEr9B/qP7XVhRS1Ebuu7P6fow/TMWw+AHivN9SsFN5iJPk2nO12+xJFnDNBN38oItGx/HYWKlZWaOU+PcF4bh2vxbHVDpH0+/3/dS5jl0Hx8/WYxxqLCskB1jU6iPfb7SwQGNdB2kDbwzBuAVfLB/rlODImNFOixJhV9JEcb5yCwjRgWmp9yE4y95ODtwjs4D2jhu+fQBOJbdSxTuYF4kRuNdACKff33l6szDOaKQtUSxZKNgb9xISUubSyjKX6n+4NzOIwCjIeYTe9JPWaEOo3yjECGq/DPJrptyPPODWaMQ5Z2T8AKIV1Or7sE7q343gl5Oqfe8OiAh82nPJv5TvfqFMbdBPkwgVeZs6NZbWzrfxLE9dpkVmiZVPRp7f5Ce2H2X+xa3rZvSIrQDUQDkH2OWdLRgRKD+6eRlsokn+z+xr9go9hEKFnD2YPzmmWS7fIGvYaND2t3MayNM8tN2iaY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR03MB6058.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(39850400004)(346002)(376002)(396003)(136003)(366004)(66946007)(1076003)(316002)(66556008)(66476007)(5660300002)(478600001)(2906002)(4326008)(110136005)(7416002)(16526019)(186003)(26005)(8676002)(52116002)(7696005)(956004)(55016002)(6506007)(86362001)(83380400001)(38350700002)(9686003)(38100700002)(8936002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UMRXa/8B/HR+Zj5sJLRrpbu6M9wOShn17El6lixBgoA6zyPHvz/MEfTPyLFf/bNl2f8Kjmq1meXyKJlD0gwAYx5YuoqN3ld15VpB6Ueo24uGYXsigHv6ryWXD68nawANsn7KRrCFOLU1hy9zsYPZ5bwKEr8bA0Ow97IcHa4jJrVCQEwYgY/xSOBTKkUnhr2ZXLcdFi8ohTyg5I7B8ox0jMgUVkhWO0RpO5LHeBMDUOmGdlinqP49TsglGs5s6/EhSOK8haXkrjdC7L864o5/PKcoa1H9Xp/p0OypBzEVDtFJ6/PGyZhe4ALaFgi+6cCPrhCe0sX0VFaHUtHqPI1RUL7OqQhrJVPRXDuTgFZBrFN6XOP+alHZXmtwvFw1CEfJgMSBtSFT0t+s8yXQzY3Q5DrC+M+gUJ+RbxU3moUE0yK8pcz1LcXggyCOidjHFh0kQXDAzEcXga5W/3YHvsTaLCraw6Hix36OymynSHV7MoQLkcvB7U0B8r95av8hfmJc/y0xlLPRyc+sEQFhuQaOc14z1G6SvnQ40mdNB+SFTQLDibwK28dX9wP/d0QalvNakdka9YQhx9TMDEa+oDqfoTKO4OQx9z61ng8uq5Wq+/IH2NEOujTCHQBnXPSZJdwh+cjzh8w6/s0WAUjj0eIh4BpOPP/e7vYpPhI+ZVPbD2tFhpGFXxvA44+vFt28wwCzYImUTXQGAMtRn8vbMPtSM8rytuLv8FkT+JByIIYpeGCLapuSoP6GttHZWoOrZSds/mDESVgDddNfZQ/S4FmE1iMgHuMtqFSUY+2YB1YhPfQn8c+ph2xeEIoAcfu62725115fldphKjdRDyW0d0za7QB2SWG3BHbLs63iDofBW2kYn3NBei/uOOiiFInTb/thQ1bBMJQELZyFXqVWZOeMlXYle0IAHplb7Ccvls24j0BfgMhndCHf8VGlUyINLIpC4E51GoaS4c/o7aUVVL6OhhnEYyKNx+SJYfY1D5lQIOQKKQfPh7Ca4Cjz/ljFm67nAwZXqxEeHZl91j0my8o0P1k1DTTYTPr/y+Zrzo3RnbUoF4dicH5TTegS+yGBlpJv7PyR5OrIcaM/HsxzEV3j5BCGek/55E4yNzW4Qubhi6uIVDd0P/t7mj+SyEA/x+4zpBW/NIRb042Qvx2VUiypCWywbeb8NwWUYsJLt0U0Gykr+cyr5R+TNmXX7C6ITEvjGrTNAQTMPer52aZ4dMTMPIZnJuDJ4B0JHELF1yvk5qrAbD7Pw1qVBTmPCa7YyongTgPHoKeev7pH/HSdbaBlJRzw8zHaSXzUZVOyuApJ3UJ61mf6kiHCIIaymYgCdaF5 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c197b04-eea2-480e-953a-08d91e960aa9 X-MS-Exchange-CrossTenant-AuthSource: BN9PR03MB6058.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2021 09:26:42.3445 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FE7kNrSIND2LUEkAK/e8daGnfIx3pGkUxnh9tTuwVJBHl2LtYGMWyvCvF/TmC13ugR0b4MqYopw2Heh9vVJhSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR03MB6188 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_022644_835509_A035AB77 X-CRM114-Status: GOOD ( 16.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org KFENCE requires linear map to be mapped at page granularity, so that it is possible to protect/unprotect single pages in the KFENCE pool. Currently if KFENCE is enabled, arm64 maps all pages at page granularity, it seems overkilled. In fact, we only need to map the pages in KFENCE pool itself at page granularity. We acchieve this goal by allocating KFENCE pool before paging_init() so we know the KFENCE pool address, then we take care to map the pool at page granularity during map_mem(). Signed-off-by: Jisheng Zhang --- arch/arm64/kernel/setup.c | 3 +++ arch/arm64/mm/mmu.c | 27 +++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 61845c0821d9..51c0d6e8b67b 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -345,6 +346,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) arm64_memblock_init(); + kfence_alloc_pool(); + paging_init(); acpi_table_upgrade(); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 89b66ef43a0f..12712d31a054 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -515,10 +516,16 @@ static void __init map_mem(pgd_t *pgdp) */ BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); - if (rodata_full || crash_mem_map || debug_pagealloc_enabled() || - IS_ENABLED(CONFIG_KFENCE)) + if (rodata_full || crash_mem_map || debug_pagealloc_enabled()) flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; + /* + * KFENCE requires linear map to be mapped at page granularity, so + * temporarily skip mapping for __kfence_pool in the following + * for-loop + */ + memblock_mark_nomap(__pa(__kfence_pool), KFENCE_POOL_SIZE); + /* * Take care not to create a writable alias for the * read-only text and rodata sections of the kernel image. @@ -553,6 +560,15 @@ static void __init map_mem(pgd_t *pgdp) __map_memblock(pgdp, kernel_start, kernel_end, PAGE_KERNEL, NO_CONT_MAPPINGS); memblock_clear_nomap(kernel_start, kernel_end - kernel_start); + + /* + * Map the __kfence_pool at page granularity now. + */ + __map_memblock(pgdp, __pa(__kfence_pool), + __pa(__kfence_pool + KFENCE_POOL_SIZE), + pgprot_tagged(PAGE_KERNEL), + NO_EXEC_MAPPINGS | NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); + memblock_clear_nomap(__pa(__kfence_pool), KFENCE_POOL_SIZE); } void mark_rodata_ro(void) @@ -1480,12 +1496,7 @@ int arch_add_memory(int nid, u64 start, u64 size, VM_BUG_ON(!mhp_range_allowed(start, size, true)); - /* - * KFENCE requires linear map to be mapped at page granularity, so that - * it is possible to protect/unprotect single pages in the KFENCE pool. - */ - if (rodata_full || debug_pagealloc_enabled() || - IS_ENABLED(CONFIG_KFENCE)) + if (rodata_full || debug_pagealloc_enabled()) flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start),