Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5099608rdb; Tue, 12 Dec 2023 20:56:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEemX36ehDESz8ZLCPt6cjzRPFPQv11fLYSeBSbX2k4gmaamMpAMRJIxCQ54rsYUAp5N8kc X-Received: by 2002:a05:6a00:990:b0:6cd:d53c:f5ea with SMTP id u16-20020a056a00099000b006cdd53cf5eamr9269335pfg.6.1702443397672; Tue, 12 Dec 2023 20:56:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702443397; cv=none; d=google.com; s=arc-20160816; b=V7jUqOoRBJiQ4rAZzn8p9L6CpgLIq34XiShNuqGNdP8tMHyfiKtk7HTzuUJHBP+FLH 9OmMjWNE8f23FX0wWNRpocwTz66v7IZWNpY41vRj1yyQQWTX57uwbPZI6vR76wMawO3j yxPUGwTD1oXDjMDe9LtiI6xrkN3TtG6SB2vnfcHuw4YQq1dXrHm0wcSHKOGsrlg/57K0 i+ssiHgU/JT7pbgik90QZAY/EdIAfi6CnbiKarVRS0s2Js+PBIHTxrcGaz+ElhGSB5Lb F0DBVpChgaZ+ZZI9J9rFRmP4oS31RUSzQ7Xx34Q1QAhqBDwZp05bvnFu2r1KPMzPcXup FJLg== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=+076ulzt2Z9dOb2ZujODBEh5/UTgbcvBuZRAGj1YAyw=; fh=So85UxWXUBEI7ya3RJ3N9YvQLhx3tJ/Vjk8U3aV+iC0=; b=rY5m/rkwNaDg7Rny6N+hDzJ3XkMNbN6vJEdD5lIk3rS3E8O8PefjFs2dIm38fK76Gt vkz/oWvpchDh3eXv9Mrf2YaBl8R58gqWk846TBbdOJ0/WkbirW09iW6j7CnRkagH9G0Z 1xocKwNUct3Xe+fa1anyTSPwrAsO2e7Vuu93urhhPSAZWMdlsxzlE4OOJlkZvCpHcEoV QNaL1QAovW1neAUmknXLNABUbUWeljgUmR/4ghpMIpjvFQG/EuXevL042Ru8a4Qai7w3 tu1sEMcMU3I9O5X1GQnR98+q/kxtxqM2jzj7bu08yPbOgcC+QSRQj0uVGVjgSJVO3unW 5vRA== 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:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b6-20020a056a000cc600b006ce1127888asi9125034pfv.10.2023.12.12.20.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 20:56:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 44EEC804755A; Tue, 12 Dec 2023 20:56:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378466AbjLME4W (ORCPT + 99 others); Tue, 12 Dec 2023 23:56:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232803AbjLME4U (ORCPT ); Tue, 12 Dec 2023 23:56:20 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 40F929A; Tue, 12 Dec 2023 20:56:26 -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 F41A9C15; Tue, 12 Dec 2023 20:57:11 -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 905483F5A1; Tue, 12 Dec 2023 20:56:19 -0800 (PST) Message-ID: <26ab1190-f437-477b-b09c-6522a1d3fe1d@arm.com> Date: Wed, 13 Dec 2023 10:26:16 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V15 5/8] KVM: arm64: nvhe: Disable branch generation in nVHE guests Content-Language: en-US From: Anshuman Khandual 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-6-anshuman.khandual@arm.com> <86ttoybbp4.wl-maz@kernel.org> In-Reply-To: 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 20:56:35 -0800 (PST) On 12/11/23 11:30, Anshuman Khandual wrote: > On 12/4/23 14:12, Marc Zyngier wrote: >> On Fri, 01 Dec 2023 05:39:03 +0000, >> Anshuman Khandual wrote: >>> Disable the BRBE before we enter the guest, saving the status and enable it >>> back once we get out of the guest. This is just to avoid capturing records >>> in the guest kernel/userspace, which would be confusing the samples. >> Why does it have to be limited to non-VHE? What protects host EL0 >> records from guest's EL0 execution when the host is VHE? > In a scenario when running the host in VHE mode > > - The host might have enabled branch records for host EL0 through BRBCR_EL2.E0HBRE > indirectly via accessing BRBCR_EL1.E0BRE > > - But after the guest switches in on the cpu - BRBCR_EL2.E0HBRE will still remain > set and enable branch records in guest EL0 as well because BRBCR_EL1.E0BRE will > not have any effect when EL2 is implemented and HCR_EL2.TGE == 1. The guest EL0 > execution branch records will find their way into branch records being captured > for host EL0 > > You are right. The host EL0 branch records too need to be protected from guest EL0 > execution. A similar BRBCR_EL1 save/restore mechanism is needed for VHE as well ? Looking at this again, seems like host EL0 records will be protected from guest EL0 execution as HCR_EL2.TGE toggles when th guest switches in thus enforcing BRBCR_EL1.E0BRE (which is clear) requirement for capturing guest EL0 branch records. arch/arm64/kvm/hyp/vhe/tlb.c __tlb_switch_to_guest() { .... val = read_sysreg(hcr_el2); val &= ~HCR_TGE; write_sysreg(val, hcr_el2); isb(); } HCR_TGE comes back via HCR_HOST_VHE_FLAGS when the host switches back in. __tlb_switch_to_host() { write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); isb(); .... }