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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D0F1D2F7D8 for ; Thu, 17 Oct 2024 00:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ieleEVTPWn9Zh92ysgfXoFMSmClM+5NchpTLWKRdSEM=; b=AOtUGo5vqD6/yFt4oW3UBA/NJx Q5tDrDIDWD0gl2xST7xzAUjDsJCU3w9D26wf8dsF616x/ONnzD6I64nlcOcFv4v/USgnrgWirpj24 sJ3oB19T+GvZqq6uQKRZITBzQpGwa2trHy9RvzBcMCNaZCiMVmz5rFeVgiD5PSrH3zB5h5ogjm+T7 VJIrQLnttZHZvL/YyvQQnn8MMFNCz60LXu6EKZaaGLIgohrFPK7X8m8z2Z7M4z7f87QzUHbdFPWYI DyyKrnPucR+N5IzJc5ZJZybrvdYkltl+XrE9aSaAsc2/vAJY1S4+6sdRDGispc6hKSvr5oM9NtRwC Iv5h2zKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1EN7-0000000DKuK-3O4j; Thu, 17 Oct 2024 00:28:09 +0000 Received: from out-180.mta1.migadu.com ([95.215.58.180]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1E64-0000000DHrb-0nKD for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 00:10:33 +0000 Date: Wed, 16 Oct 2024 17:10:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729123826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ieleEVTPWn9Zh92ysgfXoFMSmClM+5NchpTLWKRdSEM=; b=bF46m3KLhianGDXXLx8rsBwd6lfkgfNp3rCw5OTV71Hxht7cUl6QBeIPXuOudNzUG0wUCd 1SbGrYG/phNu6azS7ciM0dR39LmKpPvipqM7svTeHtylH/hTCpEVLZrXRxMedleIOGyeTD uwV3Sf9uXK8h8y2uj/pnY/5IZLQ4E/A= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Joey Gouly Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, anshuman.khandual@arm.com, james.morse@arm.com, Marc Zyngier , Suzuki K Poulose , Zenghui Yu , Jing Zhang , Shameerali Kolothum Thodi , Catalin Marinas , Will Deacon Subject: Re: [PATCH v5 4/7] KVM: arm64: Fix missing traps of guest accesses to the MPAM registers Message-ID: References: <20241015133923.3910916-1-joey.gouly@arm.com> <20241015133923.3910916-5-joey.gouly@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241015133923.3910916-5-joey.gouly@arm.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_171032_459672_FB05DDE6 X-CRM114-Status: GOOD ( 12.75 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Joey, On Tue, Oct 15, 2024 at 02:39:20PM +0100, Joey Gouly wrote: > +static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu) > +{ > + u64 r = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1; > + > + if (!cpus_support_mpam()) > + return; > + > + /* trap guest access to MPAMIDR_EL1 */ > + if (mpam_cpus_have_mpam_hcr()) { > + write_sysreg_s(MPAMHCR_EL2_TRAP_MPAMIDR_EL1, SYS_MPAMHCR_EL2); > + } else { > + /* From v1.1 TIDR can trap MPAMIDR, set it unconditionally */ > + r |= MPAM2_EL2_TIDR; > + } > + > + write_sysreg_s(r, SYS_MPAM2_EL2); > +} > + > +static inline void __deactivate_traps_mpam(void) > +{ > + if (!cpus_support_mpam()) > + return; > + > + write_sysreg_s(0, SYS_MPAM2_EL2); > + > + if (mpam_cpus_have_mpam_hcr()) > + write_sysreg_s(MPAMHCR_HOST_FLAGS, SYS_MPAMHCR_EL2); > +} TBH, I think our trap configuration should *not* be conditioned on CONFIG_ARM64_MPAM. Otherwise we're silently allowing the guest to change things under the nose of KVM/host kernel, assuming an unkind firmware that left the EL2 trap configuration in a permissive state. WDYT about detecting the feature && enforcing traps regardless of the Kconfig? -- Thanks, Oliver