Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5081017rdb; Tue, 12 Dec 2023 19:57:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1Onf4NVtEgeNEr7imVVfwBiRklSCDoTYM6ImHch+OU+yEaewojnnp4M0hMA8uGM2ItC+9 X-Received: by 2002:a92:c564:0:b0:35d:59a2:a322 with SMTP id b4-20020a92c564000000b0035d59a2a322mr7503639ilj.36.1702439836445; Tue, 12 Dec 2023 19:57:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702439836; cv=none; d=google.com; s=arc-20160816; b=qs302JwLkZrvZ19HHwy5Kr8KAO703Ra1yTt7wqQ/hvz35H8UwA5m5uohyA+mXvzAwK 2HDdXAPtGDd8BV60y4ZnXWkldwSMAwAT17HvbZmO5cQ/T2MW92A9/LGHDTu7hwdyi+rT 5FEEUvTCx/yt9rPwSg1noVtIgL93VYvVxLzp2h9WG+4IQc+Iy+vgX1DnXY3YeKoZF7Yk y7ggyJ+RhGXrVLWgZYaDavrRmSUbiFAJeSGBV6tVMYxU9z6+45lh1nQ614V9Df62hWlW W7qhdYWdbEKe6/caR57pazqwgl6d7pTgrRnpcTbNL/0RfuBJjZpCX1DJDQYW8JkiRWVF GDNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=9DG71ACrINRv6b0kzlgApGZWjIXssjh5guBVxrQXM00=; fh=So85UxWXUBEI7ya3RJ3N9YvQLhx3tJ/Vjk8U3aV+iC0=; b=xuV/NuEsqQrzEpU6dwNI5uDBst8TuWOWC5Gf8vLXzSVqyOR5AnWmlSz1L3nOwFAG2B Ldokna1zBI9xHYMjawL941KMQDLlJrh/yNkeAjKuJBPOtCJqoNa2NLoGKDMZD31UItNx C1+FRabSGY3rITc4P0UHZC9GHt5vcA1z+Rn87iL/pmXumUdZVOLBKFMhhNfLKnqkyBNc SotcU5/vxAa+Ff00yt4Z8hnDZ7HrAgn+fOaMANfs+1F9uMuH6q+Y5mzaSERMIV1AgijM zzBAkFnhuaSTG1mHoSNf5VvL4YKojKP3mXraTBnXbsSx1exMtRMsSurxIO6931/kJHtP gIoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ju18-20020a170903429200b001d0c1a225b3si593979plb.185.2023.12.12.19.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 19:57:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 1BB4480896A3; Tue, 12 Dec 2023 19:56:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235219AbjLMDz7 (ORCPT + 99 others); Tue, 12 Dec 2023 22:55:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235216AbjLMDz5 (ORCPT ); Tue, 12 Dec 2023 22:55:57 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1041E99; Tue, 12 Dec 2023 19:56:02 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D25A6C15; Tue, 12 Dec 2023 19:56:47 -0800 (PST) Received: from [10.162.41.8] (a077893.blr.arm.com [10.162.41.8]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEADB3F5A1; Tue, 12 Dec 2023 19:55:55 -0800 (PST) Message-ID: Date: Wed, 13 Dec 2023 09:25:52 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V15 2/8] KVM: arm64: Prevent guest accesses into BRBE system registers/instructions Content-Language: en-US To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Mark Brown , James Clark , Rob Herring , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, Oliver Upton , James Morse , kvmarm@lists.linux.dev References: <20231201053906.1261704-1-anshuman.khandual@arm.com> <20231201053906.1261704-3-anshuman.khandual@arm.com> <86v89ebcn2.wl-maz@kernel.org> From: Anshuman Khandual In-Reply-To: <86v89ebcn2.wl-maz@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 19:56:38 -0800 (PST) On 12/4/23 13:52, Marc Zyngier wrote: > On Fri, 01 Dec 2023 05:39:00 +0000, > Anshuman Khandual wrote: >> Currently BRBE feature is not supported in a guest environment. This hides >> BRBE feature availability via masking ID_AA64DFR0_EL1.BRBE field. This also >> blocks guest accesses into BRBE system registers and instructions as if the >> underlying hardware never implemented FEAT_BRBE feature. >> >> Cc: Marc Zyngier >> Cc: Oliver Upton >> Cc: James Morse >> Cc: Suzuki K Poulose >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: kvmarm@lists.linux.dev >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual >> --- >> arch/arm64/kvm/sys_regs.c | 130 ++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 130 insertions(+) >> >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index 4735e1b37fb3..42701065b3cd 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -1583,6 +1583,9 @@ static u64 read_sanitised_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, >> /* Hide SPE from guests */ >> val &= ~ID_AA64DFR0_EL1_PMSVer_MASK; >> >> + /* Hide BRBE from guests */ >> + val &= ~ID_AA64DFR0_EL1_BRBE_MASK; >> + >> return val; >> } >> >> @@ -2042,6 +2045,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { >> { SYS_DESC(SYS_DC_CISW), access_dcsw }, >> { SYS_DESC(SYS_DC_CIGSW), access_dcgsw }, >> { SYS_DESC(SYS_DC_CIGDSW), access_dcgsw }, >> + { SYS_DESC(OP_BRB_IALL), undef_access }, >> + { SYS_DESC(OP_BRB_INJ), undef_access }, >> >> DBG_BCR_BVR_WCR_WVR_EL1(0), >> DBG_BCR_BVR_WCR_WVR_EL1(1), >> @@ -2072,6 +2077,131 @@ static const struct sys_reg_desc sys_reg_descs[] = { >> { SYS_DESC(SYS_DBGCLAIMCLR_EL1), trap_raz_wi }, >> { SYS_DESC(SYS_DBGAUTHSTATUS_EL1), trap_dbgauthstatus_el1 }, >> >> + /* >> + * BRBE branch record sysreg address space is interleaved between >> + * corresponding BRBINF_EL1, BRBSRC_EL1, and BRBTGT_EL1. >> + */ >> + { SYS_DESC(SYS_BRBINF0_EL1), undef_access }, >> + { SYS_DESC(SYS_BRBSRC0_EL1), undef_access }, >> + { SYS_DESC(SYS_BRBTGT0_EL1), undef_access }, >> + { SYS_DESC(SYS_BRBINF16_EL1), undef_access }, >> + { SYS_DESC(SYS_BRBSRC16_EL1), undef_access }, >> + { SYS_DESC(SYS_BRBTGT16_EL1), undef_access }, > Surely we can do better than this wall of text. Please look at what we > do for the debug registers, and adopt a similar pattern. This should > result in one line per group of 3 registers. > > What is the plan for KVM support beyond this? We are planning to add support for simultaneous and independent branch record tracing via perf branch stack sampling inside the guest and the host. But will prevent tracing of the guest execution from the host.