From patchwork Mon Sep 14 13:26:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 53555 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id CCE8122B17 for ; Mon, 14 Sep 2015 13:26:53 +0000 (UTC) Received: by lbbmp1 with SMTP id mp1sf45599181lbb.2 for ; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=j0XQuoiB3XSzMXO7BAEtQxFsec6k11TZQG4ylXovPao=; b=TqhmFHf7S/3JlxyJKirdZaEvW9x5mWeEGO35L0Qwjz1w8Y56/9osxekSI92BSZGzHh TdhLg/1WhnI2SEQsbEj6ulkT+d/UNANFxiprwaGqlmCuHBA2SmdsX2SPheKgk5mufUK5 Iv0ZhDEwgis+rVN2O/UldQlAkLSYCKULyy30VIGo2fI/2rrCLLFl7zgUqG2FVUjvl0lA PHJxScj6shgCKfJSGCSoOEfYWePpfxjYAuulwCuD1WFx2rF4z1H0rHqFmfkf5p0VF8f3 ZAQhVs8dq+qMspzVUqDuUaKzHDbBOTs8g6G0SEvZGjz+CEESdTnRENDN6fNnXqfiPtx7 yxUg== X-Gm-Message-State: ALoCoQljBzKN7sAStB46ybgzHK3qVT6lUPwrY6c3m4ISzqLTM7de0l4a5UrJL3K+ZCzZyX6X4xsx X-Received: by 10.180.210.71 with SMTP id ms7mr2550882wic.4.1442237212755; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.74 with SMTP id i10ls585636lah.48.gmail; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) X-Received: by 10.112.154.106 with SMTP id vn10mr13837411lbb.38.1442237212582; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id t5si9718880lbb.35.2015.09.14.06.26.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbmp1 with SMTP id mp1so67323807lbb.1 for ; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) X-Received: by 10.152.37.135 with SMTP id y7mr11951621laj.106.1442237212484; Mon, 14 Sep 2015 06:26:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1200393lbq; Mon, 14 Sep 2015 06:26:51 -0700 (PDT) X-Received: by 10.194.202.137 with SMTP id ki9mr27262521wjc.16.1442237211726; Mon, 14 Sep 2015 06:26:51 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id mb10si17132770wic.100.2015.09.14.06.26.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by wiclk2 with SMTP id lk2so133044544wic.1 for ; Mon, 14 Sep 2015 06:26:51 -0700 (PDT) X-Received: by 10.180.92.138 with SMTP id cm10mr25444734wib.33.1442237211072; Mon, 14 Sep 2015 06:26:51 -0700 (PDT) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by smtp.gmail.com with ESMTPSA id ht5sm14415869wib.10.2015.09.14.06.26.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:26:50 -0700 (PDT) From: Daniel Thompson To: linux-arm-kernel@lists.infradead.org Cc: Daniel Thompson , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal , Marc Zyngier , Andrew Thoelke , Dave Martin Subject: [RFC PATCH v2 3/7] arm64: alternative: Apply alternatives early in boot process Date: Mon, 14 Sep 2015 14:26:17 +0100 Message-Id: <1442237181-17064-4-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442237181-17064-1-git-send-email-daniel.thompson@linaro.org> References: <1442237181-17064-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently alternatives are applied very late in the boot process (and a long time after we enable scheduling). Some alternative sequences, such as those that alter the way CPU context is stored, must be applied much earlier in the boot sequence. Introduce apply_alternatives_early() to allow some alternatives to be applied immediately after we detect the CPU features of the boot CPU. Currently apply_alternatives_all() is not optimized and will re-patch code that has already been updated. This is harmless but could be removed by adding extra flags to the alternatives store. Signed-off-by: Daniel Thompson --- arch/arm64/include/asm/alternative.h | 1 + arch/arm64/kernel/alternative.c | 15 +++++++++++++++ arch/arm64/kernel/setup.c | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/arch/arm64/include/asm/alternative.h b/arch/arm64/include/asm/alternative.h index d56ec0715157..f9dad1b7c651 100644 --- a/arch/arm64/include/asm/alternative.h +++ b/arch/arm64/include/asm/alternative.h @@ -17,6 +17,7 @@ struct alt_instr { u8 alt_len; /* size of new instruction(s), <= orig_len */ }; +void __init apply_alternatives_early(void); void __init apply_alternatives_all(void); void apply_alternatives(void *start, size_t length); void free_alternatives_memory(void); diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index ab9db0e9818c..59989a4bed7c 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -117,6 +117,21 @@ static void __apply_alternatives(void *alt_region) } /* + * This is called very early in the boot process (directly after we run + * a feature detect on the boot CPU). No need to worry about other CPUs + * here. + */ +void apply_alternatives_early(void) +{ + struct alt_region region = { + .begin = __alt_instructions, + .end = __alt_instructions_end, + }; + + __apply_alternatives(®ion); +} + +/* * We might be patching the stop_machine state machine, so implement a * really simple polling protocol here. */ diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 6bab21f84a9f..0cddc5ff8089 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -211,6 +211,13 @@ static void __init setup_processor(void) cpuinfo_store_boot_cpu(); /* + * We now know enough about the boot CPU to apply the + * alternatives that cannot wait until interrupt handling + * and/or scheduling is enabled. + */ + apply_alternatives_early(); + + /* * Check for sane CTR_EL0.CWG value. */ cwg = cache_type_cwg();