From patchwork Mon Apr 22 18:57: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: 10911393 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 61BD51515 for ; Mon, 22 Apr 2019 18:58:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55CEC28759 for ; Mon, 22 Apr 2019 18:58:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49B4D28764; Mon, 22 Apr 2019 18:58:57 +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 CA3CB28759 for ; Mon, 22 Apr 2019 18:58:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 117256B0006; Mon, 22 Apr 2019 14:58:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 002CF6B026B; Mon, 22 Apr 2019 14:58:44 -0400 (EDT) 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 A5F1A6B0006; Mon, 22 Apr 2019 14:58:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 0C3C36B0006 for ; Mon, 22 Apr 2019 14:58:44 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id e14so8196988pgg.12 for ; Mon, 22 Apr 2019 11:58:44 -0700 (PDT) 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=Y4ax2hOd4Buhijx/oNSuXPhWpslJbmlh2LJYha9eHFk=; b=cOHSf8SDOjOCCn0xUf5xre6sOmrV2u06McI6rxqRJQT4/Kv1jwX4TK+AX2tbEIYgNq AEA2bYA+7TurL2d42jzIdOobsrmsEFDS5p/DGT3TOBpMqZ7kRdrzGn36e3DcbS3qUUWC aDQ/M28n7S5/K//uKmUKC5zAvQ35d+HrdqfBalSa8Dh200bRcYJ8DcNS6T+FIrdH3sRP SrMgsVa1I3n2FY4EoKLfpH3Mf/bpkGxCwB5ydb+Ll3hxmko7ZORPlum3dmSDV7kNfPZQ eg8N/XoNp3xpdnMGd23omCRSh3SGb+ZU9Z01vuO9Pz0Y8XCjbVipZCDQGoABmmB6v07B /oLA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 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: APjAAAX9HeyiyZp1hk+wkbo6QMHjgwdWW7rs/MD+PtxRTGD2WAgKFh+d pt/MYhE7ZPXMGmhdQQdAjlrAuh04M//peCIm17dzXsGyS1EY4TdJECa0uqmB9cDHf1sG+yA6OXf +iCGpEJYczR0wqSKFdxJ8AUxuhjtFzyDfEeD569NpYYAsds8dSOuAcMxsl/O5/a7mYw== X-Received: by 2002:a63:fd49:: with SMTP id m9mr20238026pgj.16.1555959523481; Mon, 22 Apr 2019 11:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhbjsUZ6D5GgJQ14xg07i4WhP6ruHS3XoNeDnaVh/2kiHf4l36uWcfoQG27DtuKsnjr3Jn X-Received: by 2002:a63:fd49:: with SMTP id m9mr20237976pgj.16.1555959522571; Mon, 22 Apr 2019 11:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555959522; cv=none; d=google.com; s=arc-20160816; b=FxQxErtYL1nhWG3UATS5FB7BKyYyYpoSqTQ+cjfFaxeU1hIyJZsl3UkZopT4j7Q7zG nQlmAwAm6qBq0QywqOwhe+UAuBVzSJ7S+p7zMKjLAQFL2N2gr0Gc+F29/nsNQYBP2Den M3kR4IBbXM04C8Nipz0gh/59QLSbhlCmhrvDxyZG4WKV/kwObwtsP6rNJDJbjhTdj10N e6glP93c+8O7KWN7qjdzTRATJE7DuzFuzjEgiiLFe+VeWp3DBtEhSklo838hclM8DodR xRwl9ZLr0IsJ1dCfws2kCG5unDR5bILNxlhHwevFFRF+SSyGkoJzZD8uXYgvSM4rOegy s9lQ== 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=Y4ax2hOd4Buhijx/oNSuXPhWpslJbmlh2LJYha9eHFk=; b=N+QAZKYaQlM86OogavV30KiFsEd5hSfD3AJ8vd2zU0yHHD3gI1AxlYlp1XVzN8XY/Q svYz1N6WJMDB6WmD6jwxHV38RAYa5ZxAhbf9xERfMRw8OMNuC0OlAQ1b6NfKtKpmCa24 Pnw0g51+AFLUQvnTBlUn8WNjxFDzoQHWu45q4qMOYJc3YVauYiMQ7xLCwk3+b9px4ILY NTbXytQ1oTeX5NGZiL4v75ZRMsfAFe3ll+FkLcpeOjmhqlgJ5rO8OAsmSXGwHx3o64j3 Y3cBF5uakPgmYuZ2Xb8Fh5amOc7n4BtAwEzQLgtu9Vi4Hv8lc4WOmvCg+tI/mjbzCUsE Hy8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id a2si12975117pgn.530.2019.04.22.11.58.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 11:58:42 -0700 (PDT) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.20 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 orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Apr 2019 11:58:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,382,1549958400"; d="scan'208";a="136417122" Received: from linksys13920.jf.intel.com (HELO rpedgeco-DESK5.jf.intel.com) ([10.54.75.11]) by orsmga008.jf.intel.com with ESMTP; 22 Apr 2019 11:58:41 -0700 From: Rick Edgecombe To: Borislav Petkov , Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , 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 v4 02/23] x86/jump_label: Use text_poke_early() during early init Date: Mon, 22 Apr 2019 11:57:44 -0700 Message-Id: <20190422185805.1169-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190422185805.1169-1-rick.p.edgecombe@intel.com> References: <20190422185805.1169-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() during early-init, since no patching of code that might be on the stack is done and only a single core is running. This is required for the next patches that would set a temporary mm for text poking, and this mm is only initialized after some static-keys are enabled/disabled. Cc: Andy Lutomirski Cc: Kees Cook Cc: Dave Hansen Cc: Masami Hiramatsu Acked-by: Peter Zijlstra (Intel) 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..e7d8c636b228 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 only a single processor is running and the code is still + * not marked as RO, text_poke_early() can be used; Checking that + * system_state is SYSTEM_BOOTING guarantees it. + */ + if (system_state == SYSTEM_BOOTING) poker = text_poke_early; if (type == JUMP_LABEL_JMP) {