Received: by 10.223.176.5 with SMTP id f5csp1759886wra; Thu, 8 Feb 2018 03:03:35 -0800 (PST) X-Google-Smtp-Source: AH8x225XS9+Z+oa0cYayH6kYrWmM7GIKwWLUXpF1rb2pBkzOD0+N3WPOCxesTLssbjjovWEaDbV3 X-Received: by 10.99.42.14 with SMTP id q14mr209337pgq.183.1518087815024; Thu, 08 Feb 2018 03:03:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518087814; cv=none; d=google.com; s=arc-20160816; b=0LV1BSvbSlW3QSWy6KKYf2e76Cu4rDmoqkRhOxFG15rjr0n0is/mtYq2fxY8e+zsZk 92V8eosr/Lzg1S63cJBCsunV94OV2H/cYChT5GfqXDowHilb9IN1imVQjkO4EbWEqMgw UVfTScr9WVJN+/8JMCR0ynKQetc/3/vfgovGejYAAfXb/27I87cg64uXfF65+oPvT8Kf 3jCH5Qm8bC9nZn8oFpeKSb8HofWkd3iN/y1KnoOIwowPtcxr/SIS9K4RQBtl5qIuW5B8 6R42Pz1ETzaMynUHycaSjK6ZtGiahA9U3M6dyA1kGHoaO5zrWFWTTbPKxjEWV/QiqKph j9Ew== 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:arc-authentication-results; bh=gcPRm00rVdAPfMFj0eZUtFyZBBzuESKoDHoFrVrNu0o=; b=JuhYvEvHNl/SyxPsyE0abcJ93bDr9MD6Q+BSBVtV2N9b4Ma4Lo4iL3OBI2HRHw9OsC kwHI0cmvTttZH7K0a+GGB59sLXwWNyGz0mT6J1it9uzZ1DjrfcZww23ZhSRTOf2klCM2 4DQlVdlyiboafYGUX1+nnVznrESAHdkghvLTXrO6hP4DD0lZISJ14Ykx/N1SIOUqGha2 Br2HaMNzzZ1CNF2Ky/UgBiGZqlUkd1a+iOuCqDdMNm3qxcBCHKb+R9r5lvFsasgY6AFw yq3hpWOJ540/N+b8kojrtEIVryr/JFpQH7LqKWNjVE0UUnVTYBXKL5c7akx/+o4Q+4Tx Ib6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KbLRWa+h; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si998186pgq.776.2018.02.08.03.03.21; Thu, 08 Feb 2018 03:03:34 -0800 (PST) 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=@linaro.org header.s=google header.b=KbLRWa+h; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752210AbeBHLAt (ORCPT + 99 others); Thu, 8 Feb 2018 06:00:49 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39884 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbeBHLAp (ORCPT ); Thu, 8 Feb 2018 06:00:45 -0500 Received: by mail-wm0-f67.google.com with SMTP id b21so9100088wme.4 for ; Thu, 08 Feb 2018 03:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gcPRm00rVdAPfMFj0eZUtFyZBBzuESKoDHoFrVrNu0o=; b=KbLRWa+hO4Qwfiw5cers/FszG6Sm7nP/bOZ8jTxPO+IuwzuzYxsdZja5GC2RNlscUN alWmkolHkq6llvGSjH5qDJxMZaaSUZbk6QSQg35JNwpbEi20CQoNoyBLAVUBSdqw4hFi GluY4IWm0zKH0nhtdqw7JdOG9vf++COSefiKU= 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:user-agent; bh=gcPRm00rVdAPfMFj0eZUtFyZBBzuESKoDHoFrVrNu0o=; b=dw6yWRPTGPG3okFDhWTUSIoh7EkijsWalZE+BtA5vcPRSPKgt7NL/JlFHDtfVwFjNj nVSN21S2K8y05+4Yfu6GxQRftwurgB8l0cSl8vFkhqzAbKgWhIXld0flItqitRbV/3Ye 39HrBrjT3doep6cUdiwegpLugQRegJIv8xhXjlBj36aITQ1jus09b2ghk5n7/WN/VrWm qpW0E3kB3TDSc0EqMR7zHB2cN4RUKj7J9tDGqR/FwejXJNG9q64EMlN7VAqMVDYVmeGU xANVyZ5whzJnTS5Gk05vzr12BH6pNVF1D76yHL/HE/iNz/zwckVSqY9uK9gUaFLPh3px Wwsg== X-Gm-Message-State: APf1xPDEaPg1TA91wSrYR62C+JHH6XpUwqbnfG22D8mLgberuFetbifo ltz2y2i8klI1S2MXNsuqXwv6gg== X-Received: by 10.80.142.172 with SMTP id w41mr946928edw.275.1518087644175; Thu, 08 Feb 2018 03:00:44 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a5sm2828970eda.56.2018.02.08.03.00.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 03:00:43 -0800 (PST) Date: Thu, 8 Feb 2018 12:00:42 +0100 From: Christoffer Dall To: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, linux-kernel@vger.kernel.org, kristina.martsenko@arm.com, peter.maydell@linaro.org, pbonzini@redhat.com, rkrcmar@redhat.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, catalin.marinas@arm.com Subject: Re: [PATCH v1 05/16] arm64: Helper for parange to PASize Message-ID: <20180208110042.GH29286@cbox> References: <20180109190414.4017-1-suzuki.poulose@arm.com> <20180109190414.4017-6-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180109190414.4017-6-suzuki.poulose@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 09, 2018 at 07:04:00PM +0000, Suzuki K Poulose wrote: > Add a helper to convert ID_AA64MMFR0_EL1:PARange to they physical *the* > size shift. Limit the size to the maximum supported by the kernel. Is this just a cleanup or are we actually going to need this feature in the subsequent patches? That would be nice to motivate in the commit letter. > > Cc: Mark Rutland > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Marc Zyngier > Signed-off-by: Suzuki K Poulose > --- > arch/arm64/include/asm/cpufeature.h | 16 ++++++++++++++++ > arch/arm64/kvm/hyp/s2-setup.c | 28 +++++----------------------- > 2 files changed, 21 insertions(+), 23 deletions(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index ac67cfc2585a..0564e14616eb 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -304,6 +304,22 @@ static inline u64 read_zcr_features(void) > return zcr; > } > > +static inline u32 id_aa64mmfr0_parange_to_phys_shift(int parange) > +{ > + switch (parange) { > + case 0: return 32; > + case 1: return 36; > + case 2: return 40; > + case 3: return 42; > + case 4: return 44; > + > + default: What is the case we want to cater for with making parange == 5 the default for unrecognized values? (I have a feeling that default label comes from making the compiler happy about potentially uninitialized values once upon a time before a lot of refactoring happened here.) > + case 5: return 48; > +#ifdef CONFIG_ARM64_PA_BITS_52 > + case 6: return 52; > +#endif > + } > +} > #endif /* __ASSEMBLY__ */ > > #endif > diff --git a/arch/arm64/kvm/hyp/s2-setup.c b/arch/arm64/kvm/hyp/s2-setup.c > index 603e1ee83e89..b1129c83c531 100644 > --- a/arch/arm64/kvm/hyp/s2-setup.c > +++ b/arch/arm64/kvm/hyp/s2-setup.c > @@ -19,11 +19,13 @@ > #include > #include > #include > +#include > > u32 __hyp_text __init_stage2_translation(void) > { > u64 val = VTCR_EL2_FLAGS; > u64 parange; > + u32 phys_shift; > u64 tmp; > > /* > @@ -37,27 +39,7 @@ u32 __hyp_text __init_stage2_translation(void) > val |= parange << 16; > > /* Compute the actual PARange... */ > - switch (parange) { > - case 0: > - parange = 32; > - break; > - case 1: > - parange = 36; > - break; > - case 2: > - parange = 40; > - break; > - case 3: > - parange = 42; > - break; > - case 4: > - parange = 44; > - break; > - case 5: > - default: > - parange = 48; > - break; > - } > + phys_shift = id_aa64mmfr0_parange_to_phys_shift(parange); > > /* > * ... and clamp it to 40 bits, unless we have some braindead > @@ -65,7 +47,7 @@ u32 __hyp_text __init_stage2_translation(void) > * return that value for the rest of the kernel to decide what > * to do. > */ > - val |= 64 - (parange > 40 ? 40 : parange); > + val |= 64 - (phys_shift > 40 ? 40 : phys_shift); > > /* > * Check the availability of Hardware Access Flag / Dirty Bit > @@ -86,5 +68,5 @@ u32 __hyp_text __init_stage2_translation(void) > > write_sysreg(val, vtcr_el2); > > - return parange; > + return phys_shift; > } > -- > 2.13.6 > Could you fold this change into the commit as well: diff --git a/arch/arm64/kvm/hyp/s2-setup.c b/arch/arm64/kvm/hyp/s2-setup.c index 603e1ee83e89..eea2fbd68b8a 100644 --- a/arch/arm64/kvm/hyp/s2-setup.c +++ b/arch/arm64/kvm/hyp/s2-setup.c @@ -29,7 +29,8 @@ u32 __hyp_text __init_stage2_translation(void) /* * Read the PARange bits from ID_AA64MMFR0_EL1 and set the PS * bits in VTCR_EL2. Amusingly, the PARange is 4 bits, while - * PS is only 3. Fortunately, bit 19 is RES0 in VTCR_EL2... + * PS is only 3. Fortunately, only three bits is actually used to + * enode the supported PARange values. */ parange = read_sysreg(id_aa64mmfr0_el1) & 7; if (parange > ID_AA64MMFR0_PARANGE_MAX) Thanks, -Christoffer