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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham 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 8A9B9C433E1 for ; Mon, 22 Mar 2021 17:41:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ECF36199F for ; Mon, 22 Mar 2021 17:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbhCVRlS (ORCPT ); Mon, 22 Mar 2021 13:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231750AbhCVRkq (ORCPT ); Mon, 22 Mar 2021 13:40:46 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF9FC061574 for ; Mon, 22 Mar 2021 10:40:44 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id k8so18037478wrc.3 for ; Mon, 22 Mar 2021 10:40:44 -0700 (PDT) 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=iqx4aHW7FNF4wyHYPNIxseKctlq/hpv2wK6Dm4zP9Tm/R4vtJuDBdYLnpsXx7vRvl5 29DRkgQ0flZpLqhEWVQF+YDhsqwjyVHk9Kvze/AiJZjbPlu7s/j/P21LjcE8WT6+FCA/ T6MzgN0XxviMCYwiIIlm3Xms3t6SW+FWzrAAz6WmTD9+buffDPXNPy3XgjT/T/6LNnww dz4ze9nLU2jgndXpnCn+7uJTD7KOzUP1Qg+DZxaOCa1GkylEgeUItff0Oip8TwrR6hix VKsxwdpQila6uZCigkSXOny68RWCrG0mlOb9U8kdycED+PLzsttKS1heAJ78rtygNuDT gOAQ== 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=sl0L9ti4l8a3g/ZhyY9UT7WvXFM2U88wsacCsQqJteHYJzLQ55jG1HjJUr209Xzm7c TAKXjvngVyNStasAnGEHPlr2mzXTQPgtcMEPi9FHdRd4rvbq3dyb0UdHYc2YoD9bcDZh /FIu6u6UTnc0tRAlfPFGyz97p0ZRTKmiMnfOdiQ6i8yqVBDN5ilaKMq8PAM9JLbeZ17y ltSo3yeiiuhrAVoX7sEiQFvNQoMvym9vKZsnybXiXNe2T16kVEVtkOgOfekNWzbC2UgG u4NHa8Fmr+Iy9NroVeuRUSz/oMFh55+uXFk2XWg0TyEViUF5BsOZysff0aipm6KlvlQp MYew== X-Gm-Message-State: AOAM533tcC8wxi21+AGS8JnZPoC6d96cwv3mPA4UYpxZPXzrzq6e9kYF 0PpdQQghPdSahCYp2qE4Kad2Iw== X-Google-Smtp-Source: ABdhPJwlW8Sko8nIrzPZMUnI95OPH4WRWyOCvQ0v+YlPw7MwCNpZVFd7Scuq1pqSBTH9xLCYIArLHQ== X-Received: by 2002:adf:f0c1:: with SMTP id x1mr656464wro.7.1616434843381; Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Received: from google.com (230.69.233.35.bc.googleusercontent.com. [35.233.69.230]) by smtp.gmail.com with ESMTPSA id b131sm105865wmb.34.2021.03.22.10.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Date: Mon, 22 Mar 2021 17:40:40 +0000 From: Quentin Perret To: Marc Zyngier Cc: catalin.marinas@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com Subject: Re: [PATCH 2/3] KVM: arm64: Generate final CTR_EL0 value when running in Protected mode Message-ID: References: <20210322164828.800662-1-maz@kernel.org> <20210322164828.800662-3-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210322164828.800662-3-maz@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Marc, On Monday 22 Mar 2021 at 16:48:27 (+0000), Marc Zyngier wrote: > In protected mode, late CPUs are not allowed to boot (enforced by > the PSCI relay). We can thus specialise the read_ctr macro to > always return a pre-computed, sanitised value. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/assembler.h | 9 +++++++++ > arch/arm64/kernel/image-vars.h | 1 + > arch/arm64/kvm/va_layout.c | 7 +++++++ > 3 files changed, 17 insertions(+) > > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h > index fb651c1f26e9..1a4cee7eb3c9 100644 > --- a/arch/arm64/include/asm/assembler.h > +++ b/arch/arm64/include/asm/assembler.h > @@ -270,12 +270,21 @@ alternative_endif > * provide the system wide safe value from arm64_ftr_reg_ctrel0.sys_val > */ > .macro read_ctr, reg > +#ifndef __KVM_NVHE_HYPERVISOR__ > alternative_if_not ARM64_MISMATCHED_CACHE_TYPE > mrs \reg, ctr_el0 // read CTR > nop > alternative_else > ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL > alternative_endif > +#else > +alternative_cb kvm_compute_final_ctr_el0 > + movz \reg, #0 > + movk \reg, #0, lsl #16 > + movk \reg, #0, lsl #32 > + movk \reg, #0, lsl #48 > +alternative_cb_end > +#endif > .endm So, FWIW, if we wanted to make _this_ macro BUG in non-protected mode (and drop patch 01), I think we could do something like: alternative_cb kvm_compute_final_ctr_el0 movz \reg, #0 ASM_BUG() nop nop alternative_cb_end and then make kvm_compute_final_ctr_el0() check that we're in protected mode before patching. That would be marginally better as that would cover _all_ users of read_ctr and not just __flush_dcache_area, but that first movz is a bit yuck (but necessary to keep generate_mov_q() happy I think?), so I'll leave the decision to you. No objection from me for the current implementation, and if you decide to go with it: Reviewed-by: Quentin Perret Thanks, Quentin 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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 6AC5CC433C1 for ; Mon, 22 Mar 2021 17:40:49 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id CA8436188B for ; Mon, 22 Mar 2021 17:40:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA8436188B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 17C804B30D; Mon, 22 Mar 2021 13:40:48 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wMMqBvWfXDeL; Mon, 22 Mar 2021 13:40:46 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 4C5454B352; Mon, 22 Mar 2021 13:40:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 84A914B2CA for ; Mon, 22 Mar 2021 13:40:45 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21BElWfNtxdw for ; Mon, 22 Mar 2021 13:40:44 -0400 (EDT) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 80F624B2AA for ; Mon, 22 Mar 2021 13:40:44 -0400 (EDT) Received: by mail-wr1-f50.google.com with SMTP id j18so18047532wra.2 for ; Mon, 22 Mar 2021 10:40:44 -0700 (PDT) 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=iqx4aHW7FNF4wyHYPNIxseKctlq/hpv2wK6Dm4zP9Tm/R4vtJuDBdYLnpsXx7vRvl5 29DRkgQ0flZpLqhEWVQF+YDhsqwjyVHk9Kvze/AiJZjbPlu7s/j/P21LjcE8WT6+FCA/ T6MzgN0XxviMCYwiIIlm3Xms3t6SW+FWzrAAz6WmTD9+buffDPXNPy3XgjT/T/6LNnww dz4ze9nLU2jgndXpnCn+7uJTD7KOzUP1Qg+DZxaOCa1GkylEgeUItff0Oip8TwrR6hix VKsxwdpQila6uZCigkSXOny68RWCrG0mlOb9U8kdycED+PLzsttKS1heAJ78rtygNuDT gOAQ== 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=GgKcVQAiuX1k2u2693cXYEBorn0vOXvK2+sdttNZ0ZDOVMWKlxNgy8PevUsiENAKZS mCmwiwfdfqzmMEkrziqMDlkyJsAdfm7OzZa6gAH3/AxtWDKHQNRsoe7URiLPzIUxVyp3 SznTHTIhHqnHaEHto37ukTaLQ9aK5HMOiksM1SFeq4BUfNE0wNHzyq4zKjMLohvyiSaQ UZdGywkN+mwdc2FfjBVNJTVQW3mD8Tqs+gjxm0i7S60ew4RQslTWLIQk/nBr8canBnk+ w8bTKhPY/JYHJgmeRo48gbUmrxed5OCsLKfWW+GzgGM91S0V923zWuqhYY33owQsNN6x xbug== X-Gm-Message-State: AOAM5317UEkCxQ1owX/QheFomENW5/JjgkmW/YJ0qFaKQyXz68AsJQxN AqBQE1Txs/z93nPTjkxd5KnZ4w== X-Google-Smtp-Source: ABdhPJwlW8Sko8nIrzPZMUnI95OPH4WRWyOCvQ0v+YlPw7MwCNpZVFd7Scuq1pqSBTH9xLCYIArLHQ== X-Received: by 2002:adf:f0c1:: with SMTP id x1mr656464wro.7.1616434843381; Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Received: from google.com (230.69.233.35.bc.googleusercontent.com. [35.233.69.230]) by smtp.gmail.com with ESMTPSA id b131sm105865wmb.34.2021.03.22.10.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Date: Mon, 22 Mar 2021 17:40:40 +0000 From: Quentin Perret To: Marc Zyngier Subject: Re: [PATCH 2/3] KVM: arm64: Generate final CTR_EL0 value when running in Protected mode Message-ID: References: <20210322164828.800662-1-maz@kernel.org> <20210322164828.800662-3-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210322164828.800662-3-maz@kernel.org> Cc: android-kvm@google.com, catalin.marinas@arm.com, mate.toth-pal@arm.com, tabba@google.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, seanjc@google.com, kernel-team@android.com, kvmarm@lists.cs.columbia.edu X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hey Marc, On Monday 22 Mar 2021 at 16:48:27 (+0000), Marc Zyngier wrote: > In protected mode, late CPUs are not allowed to boot (enforced by > the PSCI relay). We can thus specialise the read_ctr macro to > always return a pre-computed, sanitised value. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/assembler.h | 9 +++++++++ > arch/arm64/kernel/image-vars.h | 1 + > arch/arm64/kvm/va_layout.c | 7 +++++++ > 3 files changed, 17 insertions(+) > > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h > index fb651c1f26e9..1a4cee7eb3c9 100644 > --- a/arch/arm64/include/asm/assembler.h > +++ b/arch/arm64/include/asm/assembler.h > @@ -270,12 +270,21 @@ alternative_endif > * provide the system wide safe value from arm64_ftr_reg_ctrel0.sys_val > */ > .macro read_ctr, reg > +#ifndef __KVM_NVHE_HYPERVISOR__ > alternative_if_not ARM64_MISMATCHED_CACHE_TYPE > mrs \reg, ctr_el0 // read CTR > nop > alternative_else > ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL > alternative_endif > +#else > +alternative_cb kvm_compute_final_ctr_el0 > + movz \reg, #0 > + movk \reg, #0, lsl #16 > + movk \reg, #0, lsl #32 > + movk \reg, #0, lsl #48 > +alternative_cb_end > +#endif > .endm So, FWIW, if we wanted to make _this_ macro BUG in non-protected mode (and drop patch 01), I think we could do something like: alternative_cb kvm_compute_final_ctr_el0 movz \reg, #0 ASM_BUG() nop nop alternative_cb_end and then make kvm_compute_final_ctr_el0() check that we're in protected mode before patching. That would be marginally better as that would cover _all_ users of read_ctr and not just __flush_dcache_area, but that first movz is a bit yuck (but necessary to keep generate_mov_q() happy I think?), so I'll leave the decision to you. No objection from me for the current implementation, and if you decide to go with it: Reviewed-by: Quentin Perret Thanks, Quentin _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 3C16CC433DB for ; Mon, 22 Mar 2021 17:42:40 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 BC6D96198E for ; Mon, 22 Mar 2021 17:42:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC6D96198E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc: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=M7qEpSw7KA/PXdrMQKwfhdACfm+TO1uY2yAAiPhjlXw=; b=l6YgFL9UFto1XwkX8Z3EAL4Od 2ZWnVylahaODVrh4EDc4klipRnIeubhnb8jdFHQMWGCtjbW+6Ta4mTw2mk8uofhut6kgGZ+kcF5Qd lYHQ0XTbHQVINbRn6ayIcu32RfGEcEpC7KCkC81MtQkP7fPNu3cp4eLYGa49FEJJxHXVHrJRCbVKL s4ovuqfDk6fPZq8SHD41GQb4JX6jOqaPTuNHJtQSo+cPJFdamYzNE5EO+Lp4pdhWcIWPNT5thbJmd CCNyMVXE/y7KI1H04iIgzMdSdVrlGlT6wWJ1cfprPwQZQJ2YV5MyHm94MploeydXDc8H8fwqLh1H3 CLINAfpgQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lOOXp-00CB1o-5f; Mon, 22 Mar 2021 17:40:49 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lOOXk-00CB1N-9q for linux-arm-kernel@lists.infradead.org; Mon, 22 Mar 2021 17:40:47 +0000 Received: by mail-wr1-x429.google.com with SMTP id z2so18058281wrl.5 for ; Mon, 22 Mar 2021 10:40:43 -0700 (PDT) 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=iqx4aHW7FNF4wyHYPNIxseKctlq/hpv2wK6Dm4zP9Tm/R4vtJuDBdYLnpsXx7vRvl5 29DRkgQ0flZpLqhEWVQF+YDhsqwjyVHk9Kvze/AiJZjbPlu7s/j/P21LjcE8WT6+FCA/ T6MzgN0XxviMCYwiIIlm3Xms3t6SW+FWzrAAz6WmTD9+buffDPXNPy3XgjT/T/6LNnww dz4ze9nLU2jgndXpnCn+7uJTD7KOzUP1Qg+DZxaOCa1GkylEgeUItff0Oip8TwrR6hix VKsxwdpQila6uZCigkSXOny68RWCrG0mlOb9U8kdycED+PLzsttKS1heAJ78rtygNuDT gOAQ== 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=+fO8q0q5J+d7OtGdbjb3cUlxaHCNevc3CNJXbnhrioc=; b=YT+Eb2luC5CzMsZbo96P01v27xTf3pbJKI/G2GTHmiM2nZ1HOjaf0biIqKFu15SviC kKWWYOTFzz/nD8AMoAI537ysA7LqVPs+gGqNHkktiDXqbj0SbxYE12JdXpQQccBHTRIE BI40EKYQPSk3vKX+AnAAJ11z6ZYS7I1URuHKdKrJCQAqUH0Yo5mrdT5gzRwy448ylKiv 4H1FJWpcJscGNHFJJYvx5BG1mfzPsL6mYQVRSp6MQDur/6Se41DZGwm5yh3wcOT6mMrI c5gwgGbk3a8MHNc20Xp5mW5VTqWCILLo7M0bkm2sZ0SuE50tnKJU41iBAuGlgEBKFsoK e2mg== X-Gm-Message-State: AOAM5323+d7KsI5Rgm3oZWtzWt60D9P8B62WOEXZv5kMb5MAfPyCG1yx 0FrGzzvtoa6Fw6w3xza/8Z7E4A== X-Google-Smtp-Source: ABdhPJwlW8Sko8nIrzPZMUnI95OPH4WRWyOCvQ0v+YlPw7MwCNpZVFd7Scuq1pqSBTH9xLCYIArLHQ== X-Received: by 2002:adf:f0c1:: with SMTP id x1mr656464wro.7.1616434843381; Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Received: from google.com (230.69.233.35.bc.googleusercontent.com. [35.233.69.230]) by smtp.gmail.com with ESMTPSA id b131sm105865wmb.34.2021.03.22.10.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 10:40:43 -0700 (PDT) Date: Mon, 22 Mar 2021 17:40:40 +0000 From: Quentin Perret To: Marc Zyngier Cc: catalin.marinas@arm.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com Subject: Re: [PATCH 2/3] KVM: arm64: Generate final CTR_EL0 value when running in Protected mode Message-ID: References: <20210322164828.800662-1-maz@kernel.org> <20210322164828.800662-3-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210322164828.800662-3-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210322_174045_215841_E102DA60 X-CRM114-Status: GOOD ( 17.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Hey Marc, On Monday 22 Mar 2021 at 16:48:27 (+0000), Marc Zyngier wrote: > In protected mode, late CPUs are not allowed to boot (enforced by > the PSCI relay). We can thus specialise the read_ctr macro to > always return a pre-computed, sanitised value. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/assembler.h | 9 +++++++++ > arch/arm64/kernel/image-vars.h | 1 + > arch/arm64/kvm/va_layout.c | 7 +++++++ > 3 files changed, 17 insertions(+) > > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h > index fb651c1f26e9..1a4cee7eb3c9 100644 > --- a/arch/arm64/include/asm/assembler.h > +++ b/arch/arm64/include/asm/assembler.h > @@ -270,12 +270,21 @@ alternative_endif > * provide the system wide safe value from arm64_ftr_reg_ctrel0.sys_val > */ > .macro read_ctr, reg > +#ifndef __KVM_NVHE_HYPERVISOR__ > alternative_if_not ARM64_MISMATCHED_CACHE_TYPE > mrs \reg, ctr_el0 // read CTR > nop > alternative_else > ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL > alternative_endif > +#else > +alternative_cb kvm_compute_final_ctr_el0 > + movz \reg, #0 > + movk \reg, #0, lsl #16 > + movk \reg, #0, lsl #32 > + movk \reg, #0, lsl #48 > +alternative_cb_end > +#endif > .endm So, FWIW, if we wanted to make _this_ macro BUG in non-protected mode (and drop patch 01), I think we could do something like: alternative_cb kvm_compute_final_ctr_el0 movz \reg, #0 ASM_BUG() nop nop alternative_cb_end and then make kvm_compute_final_ctr_el0() check that we're in protected mode before patching. That would be marginally better as that would cover _all_ users of read_ctr and not just __flush_dcache_area, but that first movz is a bit yuck (but necessary to keep generate_mov_q() happy I think?), so I'll leave the decision to you. No objection from me for the current implementation, and if you decide to go with it: Reviewed-by: Quentin Perret Thanks, Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel