From nobody Sun Sep 22 02:07:16 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2C5CC43334 for ; Mon, 4 Jul 2022 01:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232853AbiGDBlQ (ORCPT ); Sun, 3 Jul 2022 21:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232848AbiGDBlK (ORCPT ); Sun, 3 Jul 2022 21:41:10 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D9776388 for ; Sun, 3 Jul 2022 18:41:08 -0700 (PDT) X-UUID: c6278a1998b143c987f8fec368decef3-20220704 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.7,REQID:122888c9-8868-454d-9d76-772178075191,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:87442a2,CLOUDID:a5b64b63-0b3f-4b2c-b3a6-ed5c044366a0,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: c6278a1998b143c987f8fec368decef3-20220704 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1762774237; Mon, 04 Jul 2022 09:40:57 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Mon, 4 Jul 2022 09:40:56 +0800 Received: from mszsdtcf10.gcn.mediatek.inc (10.16.4.60) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Mon, 4 Jul 2022 09:40:55 +0800 From: Haibo Li To: Sami Tolvanen CC: , Kees Cook , Nathan Chancellor , Nick Desaulniers , Matthias Brugger , Peter Zijlstra , Masami Hiramatsu , Christophe Leroy , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Luis Chamberlain , Juergen Gross , Haibo Li , Tiezhu Yang , Aaron Tomlin , Dmitry Torokhov , , , , , Lecopzer Chen Subject: [PATCH v2 2/2] cfi: free old cfi shadow asynchronously Date: Mon, 4 Jul 2022 09:40:46 +0800 Message-ID: <20220704014046.34596-3-haibo.li@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220704014046.34596-1-haibo.li@mediatek.com> References: <20220704014046.34596-1-haibo.li@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currenly, it uses synchronize_rcu() to wait old rcu reader to go away in update_shadow.In embedded platform like ARM CA7X, load_module blocks 40~50ms in update_shadow. When there are more than one hundred kernel modules, it blocks several seconds. To accelerate load_module,change synchronize_rcu to call_rcu. Signed-off-by: Haibo Li Signed-off-by: Lecopzer Chen --- kernel/cfi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/cfi.c b/kernel/cfi.c index 6c8ae07b5835..f61439392bf8 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -43,6 +43,8 @@ typedef u16 shadow_t; struct cfi_shadow { /* Page index for the beginning of the shadow */ unsigned long base; + /* rcu to free old cfi_shadow asynchronously */ + struct rcu_head rcu; /* An array of __cfi_check locations (as indices to the shadow) */ shadow_t shadow[1]; } __packed; @@ -182,6 +184,13 @@ static void remove_module_from_shadow(struct cfi_shado= w *s, struct module *mod, } } =20 +static void free_shadow(struct rcu_head *rcu) +{ + struct cfi_shadow *old =3D container_of(rcu, struct cfi_shadow, rcu); + + vfree(old); +} + typedef void (*update_shadow_fn)(struct cfi_shadow *, struct module *, unsigned long min_addr, unsigned long max_addr); =20 @@ -211,11 +220,10 @@ static void update_shadow(struct module *mod, unsigne= d long base_addr, =20 rcu_assign_pointer(cfi_shadow, next); mutex_unlock(&shadow_update_lock); - synchronize_rcu(); =20 if (prev) { set_memory_rw((unsigned long)prev, SHADOW_PAGES); - vfree(prev); + call_rcu(&prev->rcu, free_shadow); } } =20 --=20 2.25.1