Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp832900imu; Mon, 5 Nov 2018 09:24:54 -0800 (PST) X-Google-Smtp-Source: AJdET5c4WvWXLU1UcO9if41sAUnDmuSacHYJXPXNDWUhtxLiVFjMYY+9g4+l/82y9tj2gGTHSXOI X-Received: by 2002:a62:888c:: with SMTP id l134-v6mr22832869pfd.198.1541438694639; Mon, 05 Nov 2018 09:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541438694; cv=none; d=google.com; s=arc-20160816; b=JRBAKZuX1s44j6MdLCtQIdUKg9ZHfvyTqIMBFLcXgLbiwi7oouzKaLLs9BQnAI9ZNu J5z6Y8VQyEVqv/n2H9YurvboL8Ey2mUmBpmSR3N+0o/2j0wOL6tONqaOFxhd/Jw41zTD QfXG5zlnUwhGyvhjVg2JL0G23ZcgLKYEmrQgHuEGSvFodZTll2BLPfuaFn13d5MiH53d p+azaD8C/HiL1Wu9NpyQiMgpd/3qGg10Sfbb4L6OxwSl5fm/R70milIbTjdyTzZzScFh R+OKb5TokoEyPmqIpjagJDXONqUPvRSjyxF7kmSLRa8nsvpzMht6395zw2m30q4jOaBr uYww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=k1INU1pnFYgrBmHlY0ecbAtkdCLQ8Gp82wEYXROI4I0=; b=Ozp3Lbu1XIiAiGxBuIwLaojb6rDgo9Eqn8Dox/0KWyi4Qedubio00G+hFGZN3nK55P mjULDgZSPygx0qHyY7T6VMSxkLe7DsTP4Oe1z8sqTtyy/9S6Z8qVKzBRjRWZ6aJPOQd3 ezOXqdmuKgphFzdj4cJ4OA8/MyRhMtEyx69IR7reZH36UxKKjWfKOYFz2ShHfTMHw+DC 6UgJcv4TIIKGJBhX9jCZIbFXX74Yp50rKOoUsvHM3mgJjNNVvOJZlhoEsfM8+I0qEjj/ zI/8e+qI/BdAGcbDjYbyLG3gA4TlXnTDVFwBXd+genVWQfgHbeX89ozatHtmrLtjNazv /HqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fSFPy3SG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5-v6si36327031ple.258.2018.11.05.09.24.37; Mon, 05 Nov 2018 09:24:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fSFPy3SG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729996AbeKFCnR (ORCPT + 99 others); Mon, 5 Nov 2018 21:43:17 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46135 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729748AbeKFCnR (ORCPT ); Mon, 5 Nov 2018 21:43:17 -0500 Received: by mail-pg1-f195.google.com with SMTP id w7so4503487pgp.13 for ; Mon, 05 Nov 2018 09:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=k1INU1pnFYgrBmHlY0ecbAtkdCLQ8Gp82wEYXROI4I0=; b=fSFPy3SG2q503zzs20lVIJnDKUbz1uSNNufMhYSULBvfrvtilyQ4ug5bZN0/b/7pSy EE9trnBOYDFhQMX0G5al41Zjga9qoF3eMm6B22JmVoqULcGGsBIUx5ZRRfzwxY3B8j1a cYh9kwrFkqi3//I0J9QLKGPfIrs3jcRTMt4G7Ov0xUdmNoaeHy7jHL1ZwYYO92qukkp1 DEIflX9WO5Jt0ENB6nGrlxaNxwRorGseEcwrvF1UwjWdd7MXwBUMwVqH51is9Xjtc/Ah EFDafAzBJw3pGNxWTc8hgLEHS/0Bv7Y/+p49PrttcOrWbsrtgb2WYSpgMKTLtv8HGzoM Sz4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=k1INU1pnFYgrBmHlY0ecbAtkdCLQ8Gp82wEYXROI4I0=; b=PvkwXy4XKsojR0QLFY9aI8i0umOGXs2WGfIIuX+ydSzf/2397JxO2z3l45hRyVRnsQ JkWmMfT8qZQO/yfpWGNL4KCtiT2/G1dYpYi9DDslMPHMY+DTfD3ccs2cBzRKQGeX9auR XsJnQ5Vixe6mtk8XkdT9iX7v3QeRdWFHoU0q/pLOEJ0vLy8zC+j3QIO7Y7RG4xAz7i7q l38FUHSXrE0UIaTBgYaYRca2Pmm/ivsbCywEio1zTKN/TJPWZFr8m5XBNRaBjYX5uFUT QufgIFUs1twOBgMiJsqHM8Lo6FLE4Q8TGWf5ILfxCWj/X9NxPqe57VXe1Gu/fuMB8RGR zDOw== X-Gm-Message-State: AGRZ1gKmisM0DZEcvcNjb4w/aP7MF6YinI26An7X+4xuo++nvUeFGeXq +ec+F/apdKIlRrIhRjkr8Dt/KQ== X-Received: by 2002:a63:f515:: with SMTP id w21mr1838276pgh.220.1541438555760; Mon, 05 Nov 2018 09:22:35 -0800 (PST) Received: from ?IPv6:2600:1010:b022:50cc:40e8:641b:7bb4:fb59? ([2600:1010:b022:50cc:40e8:641b:7bb4:fb59]) by smtp.gmail.com with ESMTPSA id m17-v6sm12715744pfi.102.2018.11.05.09.22.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 09:22:34 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v3 2/7] x86/jump_label: Use text_poke_early() during early_init From: Andy Lutomirski X-Mailer: iPhone Mail (16A404) In-Reply-To: <20181105140925.GD22467@hirez.programming.kicks-ass.net> Date: Mon, 5 Nov 2018 09:22:32 -0800 Cc: Nadav Amit , Ingo Molnar , linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Andy Lutomirski , Kees Cook , Dave Hansen , Masami Hiramatsu Content-Transfer-Encoding: quoted-printable Message-Id: References: <20181102232946.98461-1-namit@vmware.com> <20181102232946.98461-3-namit@vmware.com> <20181105140925.GD22467@hirez.programming.kicks-ass.net> To: Peter Zijlstra Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Nov 5, 2018, at 6:09 AM, Peter Zijlstra wrote: >=20 >> On Fri, Nov 02, 2018 at 04:29:41PM -0700, Nadav Amit wrote: >> diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c >> index aac0c1f7e354..367c1d0c20a3 100644 >> --- a/arch/x86/kernel/jump_label.c >> +++ b/arch/x86/kernel/jump_label.c >> @@ -52,7 +52,13 @@ static void __ref __jump_label_transform(struct jump_e= ntry *entry, >> jmp.offset =3D jump_entry_target(entry) - >> (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); >>=20 >> - if (early_boot_irqs_disabled) >> + /* >> + * As long as we are in early boot, we can use text_poke_early(), wh= ich >> + * is more efficient: the memory was still not marked as read-only (= it >> + * is only marked after poking_init()). This also prevents us from u= sing >> + * text_poke() before poking_init() is called. >> + */ >> + if (!early_boot_done) >> poker =3D text_poke_early; >>=20 >> if (type =3D=3D JUMP_LABEL_JMP) { >=20 > It took me a while to untangle init/maze^H^Hin.c... but I think this > is all we need: >=20 > diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c > index aac0c1f7e354..ed5fe274a7d8 100644 > --- a/arch/x86/kernel/jump_label.c > +++ b/arch/x86/kernel/jump_label.c > @@ -52,7 +52,12 @@ static void __ref __jump_label_transform(struct jump_en= try *entry, > jmp.offset =3D jump_entry_target(entry) - > (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); >=20 > - if (early_boot_irqs_disabled) > + /* > + * As long as we're UP and not yet marked RO, we can use > + * text_poke_early; SYSTEM_BOOTING guarantees both, as we switch to > + * SYSTEM_SCHEDULING before going either. > + */ > + if (system_state =3D=3D SYSTEM_BOOTING) > poker =3D text_poke_early; >=20 > if (type =3D=3D JUMP_LABEL_JMP) { Can we move this logic into text_poke() and get rid of text_poke_early()? FWIW, alternative patching was, at some point, a significant fraction of tot= al boot time in some cases. This was probably mostly due to unnecessary sync= _core() calls. Although I think this was reported on a VM, and sync_core() u= sed to be *extremely* expensive on a VM, but that=E2=80=99s fixed now, and i= t even got backported, I think. (Hmm. Maybe we can also make jump label patching work in early boot, too!)=