From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 12774C63798 for ; Fri, 20 Nov 2020 20:30:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 901832223F for ; Fri, 20 Nov 2020 20:30:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 901832223F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A834A6B0071; Fri, 20 Nov 2020 15:30:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A61FA6B0072; Fri, 20 Nov 2020 15:30:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE606B0075; Fri, 20 Nov 2020 15:30:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 50B916B0071 for ; Fri, 20 Nov 2020 15:30:08 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F31A5181AEF23 for ; Fri, 20 Nov 2020 20:30:07 +0000 (UTC) X-FDA: 77505938496.08.cakes78_5811df82734e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id CFE321819E624 for ; Fri, 20 Nov 2020 20:30:07 +0000 (UTC) X-HE-Tag: cakes78_5811df82734e X-Filterd-Recvd-Size: 4350 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 20:30:06 +0000 (UTC) IronPort-SDR: HlZku7NPWKrMAS2ww7lJkyZavKYTwkfmLvfTUzassY83iinINPYLwn14M4rA5hwATnAb8QBsUL Vh/Mii10dlKQ== X-IronPort-AV: E=McAfee;i="6000,8403,9811"; a="171702880" X-IronPort-AV: E=Sophos;i="5.78,357,1599548400"; d="scan'208";a="171702880" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 12:30:04 -0800 IronPort-SDR: gJ6W2CFNMwn1RagqoGLH/KeqmBi6Dhzx2j/5cSBj3ZQTj3v8ZsjxGeTStmhQgZKVVm4KAoPcnN T/CopTEyg3wQ== X-IronPort-AV: E=Sophos;i="5.78,357,1599548400"; d="scan'208";a="342163319" Received: from rpedgeco-mobl.amr.corp.intel.com (HELO localhost.intel.com) ([10.209.105.214]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 12:30:04 -0800 From: Rick Edgecombe To: akpm@linux-foundation.org, jeyu@kernel.org, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, luto@kernel.org, dave.hansen@linux.intel.com, peterz@infradead.org, x86@kernel.org, rppt@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dan.j.williams@intel.com Cc: elena.reshetova@intel.com, ira.weiny@intel.com, Rick Edgecombe Subject: [PATCH RFC 08/10] jump_label: Handle module writable address Date: Fri, 20 Nov 2020 12:24:24 -0800 Message-Id: <20201120202426.18009-9-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201120202426.18009-1-rick.p.edgecombe@intel.com> References: <20201120202426.18009-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Since modules can have a separate writable address during loading, do the nop application at the writable address. As long as info is on hand about if the operations is happening during a module load, don't do a full text_poke() when writing data to a writable address. Signed-off-by: Rick Edgecombe --- arch/x86/kernel/jump_label.c | 18 ++++++++++++++++-- kernel/jump_label.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 5ba8477c2cb7..7a50148a63dd 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -63,6 +63,18 @@ static inline void __jump_label_transform(struct jump_= entry *entry, int init) { const void *opcode =3D __jump_label_set_jump_code(entry, type, init); + unsigned long addr =3D jump_entry_code(entry); + struct module *mod =3D __module_address(addr); + bool mod_writable =3D false; + + if (mod) { + struct perm_allocation *alloc =3D module_get_allocation(mod, addr); + + if (perm_is_writable(alloc)) { + addr =3D perm_writable_addr(alloc, addr); + mod_writable =3D true; + } + } =20 /* * As long as only a single processor is running and the code is still @@ -74,9 +86,11 @@ static inline void __jump_label_transform(struct jump_= entry *entry, * At the time the change is being done, just ignore whether we * are doing nop -> jump or jump -> nop transition, and assume * always nop being the 'currently valid' instruction + * + * If this is a module being loaded, text_poke_early can also be used. */ - if (init || system_state =3D=3D SYSTEM_BOOTING) { - text_poke_early((void *)jump_entry_code(entry), opcode, + if (init || system_state =3D=3D SYSTEM_BOOTING || mod_writable) { + text_poke_early((void *)addr, opcode, JUMP_LABEL_NOP_SIZE); return; } diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 015ef903ce8c..3919e78fce12 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -595,7 +595,7 @@ static void __jump_label_mod_update(struct static_key= *key) */ void jump_label_apply_nops(struct module *mod) { - struct jump_entry *iter_start =3D mod->jump_entries; + struct jump_entry *iter_start =3D module_adjust_writable_addr(mod->jump= _entries); struct jump_entry *iter_stop =3D iter_start + mod->num_jump_entries; struct jump_entry *iter; =20 --=20 2.20.1