From patchwork Thu Feb 8 11:00:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10206975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 38FC7600F6 for ; Thu, 8 Feb 2018 11:02:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F4029481 for ; Thu, 8 Feb 2018 11:02:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1933329484; Thu, 8 Feb 2018 11:02:23 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96A6E29481 for ; Thu, 8 Feb 2018 11:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752190AbeBHLAt (ORCPT ); Thu, 8 Feb 2018 06:00:49 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40584 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752175AbeBHLAp (ORCPT ); Thu, 8 Feb 2018 06:00:45 -0500 Received: by mail-wm0-f68.google.com with SMTP id v123so9099111wmd.5 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=LveF2EdnVjZTy/a25bYbtmHFokaGGXMLcJKto1jPdLRIKLMa5R3gflgFP3JbT+wxCx YEgTD11ddDN2arDjf7htmaDHCQPO/5keDIoqyqTwUhqBBe7Hj2oe1Pxyr4RrMQEBW0Hk 1SF+I442WXeFKknj1Xsmi/pOqX019v4N1Ki8rOxmf3HZ2EWWyoCMnhpVkzaSXc3B5Wem hx3fuu/IAIbnkBkCgEhC8unkfS1lTzvZ0EGRFzbKCal/0Dr6l3/MqLY5MDhJpSNRlPkC jhCw0BoN4Fg03zy291UxOSzkAZCLO1j9sBCyz0NsKZyvFJuUwtdj+MIeiRp0db/DMjMz PW9w== X-Gm-Message-State: APf1xPDYYdJi/JNeVvnytn8lD4Sgs7FHdwj8KmXpvFWfvnvv/NdMqvG1 prOuzxr/fm5aDEfB+g8IpPDo5asyz7Y= X-Google-Smtp-Source: AH8x227sZNvX3BxZ/0nszWLqKsHGJ9jJY7RqlOcl84XZbuB0H1JSfj+LkpEimYUxHL+m3I15CADeBA== 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-Disposition: inline In-Reply-To: <20180109190414.4017-6-suzuki.poulose@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: Thanks, -Christoffer 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)