From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13E9AC433DB for ; Wed, 3 Feb 2021 15:55:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98F2B64F8C for ; Wed, 3 Feb 2021 15:55:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98F2B64F8C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DfBam6ZKZh7xfyz5gDX7P7Zw4q6foS3mr4yo4Knt4ME=; b=UY6cPbh/TQPTpZtWpqOyHi7Ip 2NiJSr8fS+eUUU4MGU+OynMMk0ndgvCpV5U5Zfr5KP3Zn0q0i8SZBo86ecEwTFlQbdMJPMa3TF1w/ mnc+r3DJmG6pAvfp/kx/cyFVT3t6SRfwMAE70Qp94f+zWhrPclyRRe4FKD9NGQIaB80LPHtbQSTWy wUXDaOeFqZv6gWyzRcDmnV67Sq3ozlxjF7qYXQi4vXXRPJzkWrd95UzCr1EmElg2YSbleKQ6jVSjH 6m5lSIHhG3GRZ7OFR7Tz7s5rfHk7boHM/ZCxAUptRYxGU1KI+LkuD8Pmn6rOZ3LjLRZ7EeWbu6QNV aKD8Gb07w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7KTl-00067v-7T; Wed, 03 Feb 2021 15:54:05 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7KTi-00067R-Ga for linux-arm-kernel@lists.infradead.org; Wed, 03 Feb 2021 15:54:03 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 71DCF64F55; Wed, 3 Feb 2021 15:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612367641; bh=LboLHM+6kIOh+gRaFnxe+9BKVjr4IMqy2/wdrtr8YPM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dIc9iPjjDgDhe3A+EVOFewT1KzjihGTkkVlbtTGWiLbdsiMbRFH0KhRIz9uZyia+f z93MgcrhCcxUQW725BBor3g+fQMct+Ns9J1l1dOY9ipYK+E8rvrYvuhuS4lbKQEKXz WEizc349XENeMZw90ZJej3JfWzD40pwKEhEIxmqrWpnvxCJYqeAVs4TCp3+k5ogpIy skemPMst7d2Z+O6clupBCwPXsNNZQcPWpVXw1b05kHptOzLsL+sX8ygfoWZupSUnWB HzwOwX9AGaub0Ao697Dy1MzA7k1CBwREMIdS5S0wFhurodwQNLbhTBjQvZ1yuNqGFr ufDHaSbamHi0w== Date: Wed, 3 Feb 2021 15:53:54 +0000 From: Will Deacon To: Quentin Perret Subject: Re: [RFC PATCH v2 21/26] KVM: arm64: Refactor kvm_arm_setup_stage2() Message-ID: <20210203155354.GE18974@willie-the-truck> References: <20210108121524.656872-1-qperret@google.com> <20210108121524.656872-22-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210108121524.656872-22-qperret@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210203_105402_727086_2CBDD7B0 X-CRM114-Status: GOOD ( 23.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, kernel-team@android.com, Suzuki K Poulose , android-kvm@google.com, Catalin Marinas , Fuad Tabba , linux-kernel@vger.kernel.org, Rob Herring , James Morse , linux-arm-kernel@lists.infradead.org, Marc Zyngier , David Brazdil , Frank Rowand , kvmarm@lists.cs.columbia.edu, Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jan 08, 2021 at 12:15:19PM +0000, Quentin Perret wrote: > In order to re-use some of the stage 2 setup at EL2, factor parts of > kvm_arm_setup_stage2() out into static inline functions. > > No functional change intended. > > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_mmu.h | 48 ++++++++++++++++++++++++++++++++ > arch/arm64/kvm/reset.c | 42 +++------------------------- > 2 files changed, 52 insertions(+), 38 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h > index 662f0415344e..83b4c5cf4768 100644 > --- a/arch/arm64/include/asm/kvm_mmu.h > +++ b/arch/arm64/include/asm/kvm_mmu.h > @@ -280,6 +280,54 @@ static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa, > return ret; > } > > +static inline u64 kvm_get_parange(u64 mmfr0) > +{ > + u64 parange = cpuid_feature_extract_unsigned_field(mmfr0, > + ID_AA64MMFR0_PARANGE_SHIFT); > + if (parange > ID_AA64MMFR0_PARANGE_MAX) > + parange = ID_AA64MMFR0_PARANGE_MAX; > + > + return parange; > +} > + > +/* > + * The VTCR value is common across all the physical CPUs on the system. > + * We use system wide sanitised values to fill in different fields, > + * except for Hardware Management of Access Flags. HA Flag is set > + * unconditionally on all CPUs, as it is safe to run with or without > + * the feature and the bit is RES0 on CPUs that don't support it. > + */ > +static inline u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift) > +{ > + u64 vtcr = VTCR_EL2_FLAGS; > + u8 lvls; > + > + vtcr |= kvm_get_parange(mmfr0) << VTCR_EL2_PS_SHIFT; > + vtcr |= VTCR_EL2_T0SZ(phys_shift); > + /* > + * Use a minimum 2 level page table to prevent splitting > + * host PMD huge pages at stage2. > + */ > + lvls = stage2_pgtable_levels(phys_shift); > + if (lvls < 2) > + lvls = 2; > + vtcr |= VTCR_EL2_LVLS_TO_SL0(lvls); > + > + /* > + * Enable the Hardware Access Flag management, unconditionally > + * on all CPUs. The features is RES0 on CPUs without the support > + * and must be ignored by the CPUs. > + */ > + vtcr |= VTCR_EL2_HA; > + > + /* Set the vmid bits */ > + vtcr |= (get_vmid_bits(mmfr1) == 16) ? > + VTCR_EL2_VS_16BIT : > + VTCR_EL2_VS_8BIT; > + > + return vtcr; > +} Although I think this is functionally fine, I think it's unusual to see large "static inline" functions like this in shared header files. One alternative approach would be to follow the example of kernel/locking/qspinlock_paravirt.h, where the header is guarded in such a way that is only ever included by kernel/locking/qspinlock.c and therefore doesn't need the "inline" at all. That separation really helps, I think. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel