Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2478587pxb; Mon, 18 Jan 2021 20:35:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzh6WvN1OFuH/ou6ghtZ86LKDuIqanypFJ7SE9BqP5WQZiwaFOhF1xk9Z0Hr3MJ8ns2g/ha X-Received: by 2002:a17:906:b08f:: with SMTP id x15mr1854865ejy.36.1611030923154; Mon, 18 Jan 2021 20:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611030923; cv=none; d=google.com; s=arc-20160816; b=JDuvozCZz75pT9aCCttiCNgQxhYfVn2KALsi6b+0Ytg42hFaXFU6+yimkgQVap4aOw V38wRbL2GCFJgv0DimEknTMO6/LIDXB2vZg/YSKNHWe/Uj9hfhttu6FTWzN1An2WGQbB 9lCNc81K01YeTETVQsAi6d/PijfROKFz/LzGgpGNvdwg9VHbxR7fT8yTjLlT/byOLCVG cWS51kxGjGlHqGcxPfd5MEnwWr6Ghld7sXAZ8LFbfVYsENjKlIPx3w+ev4xuwvfLzNWo I/+tagZd9HPBk+TCnx29XNBOK1jYgDU1Lo0OCJxio+S+vBClJhfu1Pp8Ks9wqJChCfc5 b/Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XW5nfZgpoFkc4MpoG+G2l89kBAOPYjtlcQxlsdxxH1M=; b=NHlc8p5vX/8gEm3YMJk6XtK98G5ONzm0FlM+x0/l2ZYIAgOGbwcOsA6CCkketFMtHO 1oXHyvGeZOOQkZ0uMeyekl6l+nPsr/H/hCI/TIA0uxRag6hSMmyELd4epkWpB3Sgp+Ol fWsW3QeAI3hUpSesZV2hVVbiVlUtDgCiQGW4lnTFzctrDfEuHCEJNtjd1CU5A0lXGgrU BEVwtAlWuBehpwOaGffFAvpiQI5pA7x91iOiNykW9b7dBnRbaKXi83C0g9n0PwPePf8y euPyYWbwi84AIaXRxgBJc7Mik1yyAbt8T5WT4eLUrHB6GoqhhuPJjxFdYN22kTOrIiph ixwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=r5Ai3uTZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si7664552ejf.621.2021.01.18.20.34.25; Mon, 18 Jan 2021 20:35:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=r5Ai3uTZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393008AbhAROsG (ORCPT + 99 others); Mon, 18 Jan 2021 09:48:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405260AbhAROrU (ORCPT ); Mon, 18 Jan 2021 09:47:20 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 729C9C061573 for ; Mon, 18 Jan 2021 06:46:40 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id v15so13060865wrx.4 for ; Mon, 18 Jan 2021 06:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XW5nfZgpoFkc4MpoG+G2l89kBAOPYjtlcQxlsdxxH1M=; b=r5Ai3uTZhku8aQJq9tizY3Yw68CMO7+HZYlNZhw8fTCzOvdRkrOudtY5rQmIi7ikxw t/CMV2AQ9R0fhx+/EvVBN/6PDz/r4J2cG9IL2uZpAWBgipgNXe/RSD30BPRfX1cqGdmQ wTPgdP7O+Yvj5qq/deZOtP16MzHNx9iUgC5vqf5VX6yOOMbgkLbGSqrIq8oeMYZcsUqJ sR+Ko4lPjPXDEpm/0EzgFnLOW5wuLfd4s0Jkbgm6/SEK36hxDfgs2q54TNs24GvqNDMA HxuSr9PrZaaDkTrO73wzvKh2WXoyVHOnojEXP/U9RA+lfRA63YwQjmDPV62/ZjAdU9Dn 4MeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XW5nfZgpoFkc4MpoG+G2l89kBAOPYjtlcQxlsdxxH1M=; b=oKnsGSrzQ9o2M4UxGE9J3eZ2xRyq5TKVIcRmFsNqVVPHLyM2tqQLs3I7V26H4kWXPs QFOSgqqR5KMdvgQk+1OHwRKYkpzHB6+IT7abdq3SABRMqEen6xKkEVIrKGadjp0uvlvx oYwfDnfeZ/+rJVBzIDzM/OvZHlwOyt1HmqQZxN1ggc/L5DElyHOCTEjv/tLtKl1a3QuL YFIFraX+eA6GbCi70+/QVaKnaSUvM0qyASWRhoLo6UB1rEm+GMK6hLaSjUD7WrPVf2EY pewiTQcOpJaMKMorv7hYmqgcNQBw910WBYjxoLCmrddKUH2HsBkO2E25M0VpuJUIvl3I 1QPQ== X-Gm-Message-State: AOAM530OZfhMKWdt2MJS4HDFmwxOWxdueA76w17naXqb+gNbSBE4ZHaj Z6Dl1noa09uU7+KS7Rj8bEWOi4JRkmMzfg== X-Received: by 2002:adf:e84f:: with SMTP id d15mr26439606wrn.245.1610981199072; Mon, 18 Jan 2021 06:46:39 -0800 (PST) Received: from google.com ([2a01:4b00:8523:2d03:3d4d:985d:87b7:4d55]) by smtp.gmail.com with ESMTPSA id g194sm27599927wme.39.2021.01.18.06.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 06:46:38 -0800 (PST) Date: Mon, 18 Jan 2021 14:46:36 +0000 From: David Brazdil To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Alexandru Elisei , Ard Biesheuvel , Jing Zhang , Ajay Patil , Prasad Sodagudi , Srinivas Ramana , James Morse , Julien Thierry , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH v4 18/21] arm64: Move "nokaslr" over to the early cpufeature infrastructure Message-ID: <20210118144636.kysdvnmcdm7it5zp@google.com> References: <20210118094533.2874082-1-maz@kernel.org> <20210118094533.2874082-19-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210118094533.2874082-19-maz@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 09:45:30AM +0000, Marc Zyngier wrote: > Given that the early cpufeature infrastructure has borrowed quite > a lot of code from the kaslr implementation, let's reimplement > the matching of the "nokaslr" option with it. > > Signed-off-by: Marc Zyngier Acked-by: David Brazdil > --- > arch/arm64/kernel/idreg-override.c | 17 ++++++++++++++ > arch/arm64/kernel/kaslr.c | 37 +++--------------------------- > 2 files changed, 20 insertions(+), 34 deletions(-) > > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c > index 1db54878b2c4..143fe7b8e3ce 100644 > --- a/arch/arm64/kernel/idreg-override.c > +++ b/arch/arm64/kernel/idreg-override.c > @@ -33,8 +33,24 @@ static const struct reg_desc mmfr1 __initdata = { > }, > }; > > +extern u64 kaslr_feature_val; > +extern u64 kaslr_feature_mask; > + > +static const struct reg_desc kaslr __initdata = { > + .name = "kaslr", > +#ifdef CONFIG_RANDOMIZE_BASE > + .val = &kaslr_feature_val, > + .mask = &kaslr_feature_mask, > +#endif > + .fields = { > + { "disabled", 0 }, > + {} > + }, > +}; > + > static const struct reg_desc * const regs[] __initdata = { > &mmfr1, > + &kaslr, > }; > > static const struct { > @@ -43,6 +59,7 @@ static const struct { > } aliases[] __initdata = { > { "kvm-arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, > { "kvm-arm.mode=protected", "id_aa64mmfr1.vh=0" }, > + { "nokaslr", "kaslr.disabled=1" }, > }; > > static int __init find_field(const char *cmdline, const struct reg_desc *reg, > diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c > index 5fc86e7d01a1..dcc4a5aadbe2 100644 > --- a/arch/arm64/kernel/kaslr.c > +++ b/arch/arm64/kernel/kaslr.c > @@ -51,39 +51,8 @@ static __init u64 get_kaslr_seed(void *fdt) > return ret; > } > > -static __init bool cmdline_contains_nokaslr(const u8 *cmdline) > -{ > - const u8 *str; > - > - str = strstr(cmdline, "nokaslr"); > - return str == cmdline || (str > cmdline && *(str - 1) == ' '); > -} > - > -static __init bool is_kaslr_disabled_cmdline(void *fdt) > -{ > - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { > - int node; > - const u8 *prop; > - > - node = fdt_path_offset(fdt, "/chosen"); > - if (node < 0) > - goto out; > - > - prop = fdt_getprop(fdt, node, "bootargs", NULL); > - if (!prop) > - goto out; > - > - if (cmdline_contains_nokaslr(prop)) > - return true; > - > - if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) > - goto out; > - > - return false; > - } > -out: > - return cmdline_contains_nokaslr(CONFIG_CMDLINE); > -} > +u64 kaslr_feature_val __initdata; > +u64 kaslr_feature_mask __initdata; > > /* > * This routine will be executed with the kernel mapped at its default virtual > @@ -126,7 +95,7 @@ u64 __init kaslr_early_init(void) > * Check if 'nokaslr' appears on the command line, and > * return 0 if that is the case. > */ > - if (is_kaslr_disabled_cmdline(fdt)) { > + if (kaslr_feature_val & kaslr_feature_mask & 0xf) { nit: Isn't the 0xf redundant here? You don't re-mask for VH either. > kaslr_status = KASLR_DISABLED_CMDLINE; > return 0; > } > -- > 2.29.2 >