Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3886726ybh; Tue, 17 Mar 2020 08:20:46 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtdxIc/bu/4yvxBzQ7K6ddhHbYKLkjgBP9LZG5kMMwZndhED030rU5npdlkMr/dYTxO4UKP X-Received: by 2002:a05:6830:1249:: with SMTP id s9mr4038880otp.359.1584458446521; Tue, 17 Mar 2020 08:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584458446; cv=none; d=google.com; s=arc-20160816; b=x4OqRaQAgmUZHRNSVLlGwtq0KU3Yr0JDH4dlmOyFsQcS1mxIfs33YR6fCrpAtVjYvU QDF5/Uk96jzQcRb+cWoXvk3s/8opEA38BssS7kxePid5CCe9Wdi/LXXBpUE7kwy2f/HS zJiOAB/PvHmCO0dqALSkU7MpA3/UZQu+hyCQWQRBfmLDCdzPN2R7YGDo/Kz6Mi9yFLwa 7QcC3EwlooXP+MA45QS6nqPzfbEHROdHlCzBfSK/TA3AgO6FyhkwiAObRh4WaIEE0hHU t/kF7pNFNR1MutL6zJeMgNi0USwVwDsmSq4brw+pMQXWfc+lzzCpbbsKACOJkHSpnpUq L/IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=znCKAMcnXuWUezmSMkSqk2ggeUtOVec4rV/5fvcGNnI=; b=w81nXjAmcTetDidx/iXWBQMqp3lrkfyN4B1z9fp1Ncpe8n9CFtc05p8osJW67BOhdO VvpekFQROjgECl85XaYyngNW2/tx3mLSz6LtCteW6R9VGeXMzWyFQ3WUrxgaXCsWW6Bl 6+HVt22nk0WkvRmdYorZ7uub0HPH4QcfF7wVqfpVogs7tGGEz8UqnJROJ4+NGVj15t4v 5k5vc+6CFPLnWoNtPSp9YEjNILyujwhoHyhmxpkVnTeLvVRZF1OjjR51jeVE1W8ogSCb hvkLhkDEBwBGl0JRMoJgePwQOQROOwMpSG57tRbKZRwn8E3iBPCuzDtntvhEG1t+KCK+ /TsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LUy+Ookc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si2344035ots.192.2020.03.17.08.20.30; Tue, 17 Mar 2020 08:20:46 -0700 (PDT) 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=@kernel.org header.s=default header.b=LUy+Ookc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbgCQPSU (ORCPT + 99 others); Tue, 17 Mar 2020 11:18:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:51230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbgCQPST (ORCPT ); Tue, 17 Mar 2020 11:18:19 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD79C20714; Tue, 17 Mar 2020 15:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584458299; bh=kPqFh2OC+QYr6S9udTfHPUyXCCUZbCYYP+w4Ykyo5ac=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LUy+OokcgDni5hFal9vNvB6rC6CWzLecLAR9f1XopbpdGlLV9X07U3BWT4J1Jyptv +BJnDAuiik5lDTDZCkqpU0RGXJefbmywJuUAg/a8wyiePh7LnOVpvESitpBYCV7A+e 2DBa1Y8EAPamXkr2ZdZUIVFv/dQQwZOAdMfsZp2Y= Date: Tue, 17 Mar 2020 15:18:14 +0000 From: Will Deacon To: Mark Brown Cc: Mark Rutland , Hongbo Yao , linux-kernel@vger.kernel.org, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Subject: Re: [RFC PATCH] arm64: fix the missing ktpi= cmdline check in arm64_kernel_unmapped_at_el0() Message-ID: <20200317151813.GA16579@willie-the-truck> References: <20200317114708.109283-1-yaohongbo@huawei.com> <20200317121050.GH8831@lakrids.cambridge.arm.com> <20200317124323.GA16200@willie-the-truck> <20200317135719.GH3971@sirena.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200317135719.GH3971@sirena.org.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 17, 2020 at 01:57:19PM +0000, Mark Brown wrote: > On Tue, Mar 17, 2020 at 12:43:24PM +0000, Will Deacon wrote: > > On Tue, Mar 17, 2020 at 12:10:51PM +0000, Mark Rutland wrote: > > > On Tue, Mar 17, 2020 at 07:47:08PM +0800, Hongbo Yao wrote: > > > > > Kpti cannot be disabled from the kernel cmdline after the commit > > > > 09e3c22a("arm64: Use a variable to store non-global mappings decision"). > > > > > Bring back the missing check of kpti= command-line option to fix the > > > > case where the SPE driver complains the missing "kpti-off" even it has > > > > already been set. > > > > > - return arm64_use_ng_mappings; > > > > + return arm64_use_ng_mappings && > > > > + cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); > > > > } > > > This probably isn't the right fix, since this will mean that early mappings > > will be global and we'll have to go through the painful page-table rewrite > > logic when the cap gets enabled for KASLR-enabled kernels. > > Aren't we looking for a rewrite from non-global to global here (disable > KPTI where we would otherwise have it), which we don't currently have > code for? What I mean is that cpus_have_const_cap() will be false initially, so we'll put down global mappings early on because PTE_MAYBE_NG will be 0, which means that we'll have to invoke the rewriting code if we then realise we want non-global mappings after the caps are finalised. > > Maybe a better bodge is something like: > > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > index 0b6715625cf6..ad10f55b7bb9 100644 > > --- a/arch/arm64/kernel/cpufeature.c > > +++ b/arch/arm64/kernel/cpufeature.c > > @@ -1085,6 +1085,8 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > > if (!__kpti_forced) { > > str = "KASLR"; > > __kpti_forced = 1; > > + } else if (__kpti_forced < 0) { > > + arm64_use_ng_mappings = false; > > } > > } > > That is probably a good idea but I think that runs too late to affect > the early mappings, they're done based on kaslr_requires_kpti() well > before we start secondaries. My first pass not having paged everything > back in yet is that there needs to be command line parsing in > kaslr_requires_kpti() but as things stand the command line isn't > actually ready then... Yeah, and I think you probably run into chicken and egg problems mapping the thing. With the change above, it's true that /some/ mappings will still be nG if you pass kpti=off, but I was hoping that didn't really matter :) What was the behaviour prior to your patch? If it used to work without any nG mappings, then I suppose we should try to restore that behaviour. Will