From patchwork Thu Jan 17 00:32:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10767237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44E3D1390 for ; Thu, 17 Jan 2019 00:33:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 308F1284DA for ; Thu, 17 Jan 2019 00:33:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 217402FD2E; Thu, 17 Jan 2019 00:33:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A24742FD2C for ; Thu, 17 Jan 2019 00:33:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2BE68E0008; Wed, 16 Jan 2019 19:33:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DE3878E0005; Wed, 16 Jan 2019 19:33:39 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 922258E0008; Wed, 16 Jan 2019 19:33:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 43FF38E0003 for ; Wed, 16 Jan 2019 19:33:39 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id l9so4939356plt.7 for ; Wed, 16 Jan 2019 16:33:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=riU4AUNFoiigx578aDCwA4TwOChKMPTJViD3Oo4NuoA=; b=LVaFtSOli4d4DP2h6tLIubwDMoWlOlMr24gyUgybDB3QrkPFNt5omk5eTlPn19yZGS dqEceHesJfEyqnDtfcD6jTh6kD3iB+f0bJgcwbnvgRQfkLAXWPMwCQOzKpya4GUi1w3p n6njSKa6rMJ5JirRjRFuCUTa+ajDoERjW2IQNjA0N5dznWKnGx76dfhWAdYjJt/tE3ue i2ou7a6MPmJRbwz0YGPaUdn5aEVyJum72dsN5eT64lCO+8q15bGGjLmwvOZrVdELCMO0 SSmaLfeyCOQf+ueh/9Leayt6Zsp5OWhJCZ8iRmNpO8zlO7DBYCg+Mbhj5g2mfHYtNA3y fwCQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AJcUukcnIWMHkIgMg6/49kra0VuVEJKfxxHTA7FUc7frKDsXUgu7Bzne GY2+uxR1m0gD0nNh2zumWtE1cw7uHJyRTC5kJizN6fV/VTmiJmH2IZ2+4Z4ZbHyWqFV5AO4hTwb Hgv6MdJ5ao2bx5Gaa/eq8fyvAo7qTl1bTXqTjgJFM2eKN1SSzos6MESvswE54zZ+N2w== X-Received: by 2002:a63:f201:: with SMTP id v1mr10826836pgh.232.1547685218870; Wed, 16 Jan 2019 16:33:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN59uWM4vCbKk0LPCCcMKdVFzzM/V9n/hmNya9AbD4tn63K9pLVqvRGcFpfaAcybNb3XPd4J X-Received: by 2002:a63:f201:: with SMTP id v1mr10826767pgh.232.1547685217925; Wed, 16 Jan 2019 16:33:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685217; cv=none; d=google.com; s=arc-20160816; b=FEJsGhRVe6pbvVhXF9Way3yxMh9tTbmZl37rvc78PJbkcoigE6jd6maQOkaXQCO1uE 0Nck85wD3Yfu/zts+YB/Nh6AF7mqfDdH3L+Jg30eWoeRWLs4e1zrhlg97pbkTPg3j8eR XKtDv3lwIDlT0m1E0qD+VhPGB+mGZJSQNpGN3WO9ZednVMQ4L2e7kyWmUy2TGgEMIfGU uFZU4SzSoiuH5MQULU7GTUvXxpz5yKrmB+HADq26mByfZJ90T5jRcKUeGcMZiPIY0sCb /T3xsL+dzZ5Tb/5ti1T91SXQVmVHie1AM/3YPsd/G0UuHa3E75BXhx+/SdGwOes/+bNV Ay7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=riU4AUNFoiigx578aDCwA4TwOChKMPTJViD3Oo4NuoA=; b=Z63y16PrkqJt3GWsiXRypK7naioVkAtc/DfkRMHRR7+Ng8crKjyMyXgLL5lQn369dv Bdh4LXaK3RNsQ4MG0H3sr4bPf8lyTwhdFljlNGfmoAXIJuaW3JiEtb6mwliCebbyYkmM zcszxmBvUoRgEkOG/TkwP5/bsdzJKm2dwKRLw+AGtmU3Zz7zpZ+okRgS7W+OH14l5G5s d15sHnXnZxC5Zpl0ArkbzPd3YrZ0rT51rxQmFP5JOvgRvYhOuKIHByh3HXK8jADtxYQZ 8kyRB6+PG0/NDhQnEOYJ3jVigMZt3V96wVBSZfEASz2AGNlVwLT0MH3OkgZF9mnXN0f0 j1Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga04.intel.com (mga04.intel.com. [192.55.52.120]) by mx.google.com with ESMTPS id y10si7582915plt.406.2019.01.16.16.33.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 16:33:37 -0800 (PST) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.120 as permitted sender) client-ip=192.55.52.120; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 16:33:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="292166012" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.79]) by orsmga005.jf.intel.com with ESMTP; 16 Jan 2019 16:33:35 -0800 From: Rick Edgecombe To: Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Borislav Petkov , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com, Nadav Amit , Kees Cook , Dave Hansen , Masami Hiramatsu , Rick Edgecombe Subject: [PATCH 02/17] x86/jump_label: Use text_poke_early() during early init Date: Wed, 16 Jan 2019 16:32:44 -0800 Message-Id: <20190117003259.23141-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190117003259.23141-1-rick.p.edgecombe@intel.com> References: <20190117003259.23141-1-rick.p.edgecombe@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Nadav Amit There is no apparent reason not to use text_poke_early() while we are during early-init and we do not patch code that might be on the stack (i.e., we'll return to the middle of the patched code). This appears to be the case of jump-labels, so do so. This is required for the next patches that would set a temporary mm for patching, which is initialized after some static-keys are enabled/disabled. Cc: Andy Lutomirski Cc: Kees Cook Cc: Dave Hansen Cc: Masami Hiramatsu Cc: Peter Zijlstra Signed-off-by: Nadav Amit Signed-off-by: Rick Edgecombe --- arch/x86/kernel/jump_label.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index f99bd26bd3f1..e36cfec0f35e 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -50,7 +50,12 @@ static void __ref __jump_label_transform(struct jump_entry *entry, jmp.offset = jump_entry_target(entry) - (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); - 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 == SYSTEM_BOOTING) poker = text_poke_early; if (type == JUMP_LABEL_JMP) {