From patchwork Tue Nov 23 21:01:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12693504 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 82F7EC4332F for ; Tue, 23 Nov 2021 21:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DrWpf2T3DcL8yjxTBbh43cFhFBBRzX2ossUQUsXGhTc=; b=d/49m4N5p7jz/0QYOXhVXHohDQ ZFxw06V0wDF4V+FwLTMHrcI+u+tbyLGEwXVmktUkjaCJqvKNjyDqIF+1BpsQawzza1UTQ5D+9f6g4 8ezGf+Br8ocbdYJeOBVrPx0PW3M543mjPQREUa2dkCdcWMlFcJ49z8ZU2DuIOFTPnwPLhLp93OATL 8XO0vBtRyFf17y6IxtRIjlZgHAQ3Vm3h9h14XOT6VpX5pR7y9cjL6fr0Oiozemdl625C6SXwQDeCW 5Z/U6/Zj5yVnxspsv9UfeX0dubxJ/mKMovCss1oFjJOUd0UTyI6hHbC3D9mJILqc4Bnh95pvrM3bT IqpLVtdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcvV-003Sr3-LM; Tue, 23 Nov 2021 21:02:05 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcum-003SjB-DR for linux-arm-kernel@lists.infradead.org; Tue, 23 Nov 2021 21:01:22 +0000 Received: by mail-io1-xd4a.google.com with SMTP id s8-20020a056602168800b005e96bba1363so124918iow.21 for ; Tue, 23 Nov 2021 13:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wUzCexKaXqQ03XsQOxjv7f8NBY5L7dr1LK/AA5KCKVI=; b=N4kxRBI3igPLyUbZrW9s5rSGAXFsVGDjEkCFd9S+Fu240fBqY/L3uIz5prx5b2504I xoIsnrDsGp07KyyGNprN/lfLAM14jDxOLpHRqjHROeX8RRsjRPQrJewYTylZFWxCrMbI a/f93jbLyjLGyhg+sUlFDys1hfrLng401WPE/5RD8mC1vAfB9mncSxkWOX6xCz2hlea/ 7hRGO8HmnqyNq0Qp6E0zu+DCDXoFiZZ4shk2+BOX8y3uKGs9cZuNbxGOTR4p1ZkSzpTc mUEcs0RIG85ola8ud0G50BxCF2gQnO1c8XAo8q0OvDlf8PPzxGGtYTrnYrgVv54AKos4 xNxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wUzCexKaXqQ03XsQOxjv7f8NBY5L7dr1LK/AA5KCKVI=; b=49kO4iRofKLQVlbK0epl4fN4RWAtJFWvfLzoRlu0N2T+3yTSxioYfkIPUaxpt+wvX7 dveo9Nb64flWeEHAPNNeHjFIKPPDIxd78K5UpQBGEBzn8S1TWuHwCk3LA0I24TyA5Oca fTnPddGxFOc24OPAz7N9S7SbCHZa2S853JzavpCm5NB2NdJ7v9D7Cvx+I4MGH+0+56q0 9o9K36fNeGR9qe/WYUiKDTgF842vc7tv9JQVPWx2hfLUTsbPnaFqTCrO+l+STzv4b0eU 5rL0dFp+nOihrGPAr4IoXzKg0TfieZU1wR2mCU6ER8nH/JOQdPIPS80fL+wBoOWSOD+t EsXw== X-Gm-Message-State: AOAM530xaaBptqFH3fOH/M3mzN6nkEQ7ztNmkpSMcAguecOklS1NRGeZ KyBbY5lvl4MZ9vTkgcWjmHIHif9Cndo= X-Google-Smtp-Source: ABdhPJxZ6Ef2pIjtj2QD9UsUAaVMm2FHgIlxHqaMG62gt2+RpOlDZ5Kr4E2rZUU8AHbYJ32aB6DYa499PJ4= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6638:224d:: with SMTP id m13mr9947094jas.86.1637701279128; Tue, 23 Nov 2021 13:01:19 -0800 (PST) Date: Tue, 23 Nov 2021 21:01:06 +0000 In-Reply-To: <20211123210109.1605642-1-oupton@google.com> Message-Id: <20211123210109.1605642-4-oupton@google.com> Mime-Version: 1.0 References: <20211123210109.1605642-1-oupton@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3 3/6] KVM: arm64: Allow guest to set the OSLK bit From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Peter Shier , Ricardo Koller , Reiji Watanabe , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211123_130120_481035_E7F75D01 X-CRM114-Status: GOOD ( 15.66 ) 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 Allow writes to OSLAR and forward the OSLK bit to OSLSR. Do nothing with the value for now. Reviewed-by: Reiji Watanabe Signed-off-by: Oliver Upton --- arch/arm64/include/asm/sysreg.h | 6 ++++++ arch/arm64/kvm/sys_regs.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 16b3f1a1d468..9fad61a82047 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -129,7 +129,13 @@ #define SYS_DBGWCRn_EL1(n) sys_reg(2, 0, 0, n, 7) #define SYS_MDRAR_EL1 sys_reg(2, 0, 1, 0, 0) #define SYS_OSLAR_EL1 sys_reg(2, 0, 1, 0, 4) + +#define SYS_OSLAR_OSLK BIT(0) + #define SYS_OSLSR_EL1 sys_reg(2, 0, 1, 1, 4) + +#define SYS_OSLSR_OSLK BIT(1) + #define SYS_OSDLR_EL1 sys_reg(2, 0, 1, 3, 4) #define SYS_DBGPRCR_EL1 sys_reg(2, 0, 1, 4, 4) #define SYS_DBGCLAIMSET_EL1 sys_reg(2, 0, 7, 8, 6) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 7bf350b3d9cd..5dbdb45d6d44 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -44,6 +44,10 @@ * 64bit interface. */ +static int reg_from_user(u64 *val, const void __user *uaddr, u64 id); +static int reg_to_user(void __user *uaddr, const u64 *val, u64 id); +static u64 sys_reg_to_index(const struct sys_reg_desc *reg); + static bool read_from_write_only(struct kvm_vcpu *vcpu, struct sys_reg_params *params, const struct sys_reg_desc *r) @@ -287,6 +291,24 @@ static bool trap_loregion(struct kvm_vcpu *vcpu, return trap_raz_wi(vcpu, p, r); } +static bool trap_oslar_el1(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + u64 oslsr; + + if (!p->is_write) + return read_from_write_only(vcpu, p, r); + + /* Forward the OSLK bit to OSLSR */ + oslsr = __vcpu_sys_reg(vcpu, OSLSR_EL1) & ~SYS_OSLSR_OSLK; + if (p->regval & SYS_OSLAR_OSLK) + oslsr |= SYS_OSLSR_OSLK; + + __vcpu_sys_reg(vcpu, OSLSR_EL1) = oslsr; + return true; +} + static bool trap_oslsr_el1(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -309,9 +331,10 @@ static int set_oslsr_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, if (err) return err; - if (val != rd->val) + if ((val & ~SYS_OSLSR_OSLK) != rd->val) return -EINVAL; + __vcpu_sys_reg(vcpu, rd->reg) = val; return 0; } @@ -1180,10 +1203,6 @@ static bool access_raz_id_reg(struct kvm_vcpu *vcpu, return __access_id_reg(vcpu, p, r, true); } -static int reg_from_user(u64 *val, const void __user *uaddr, u64 id); -static int reg_to_user(void __user *uaddr, const u64 *val, u64 id); -static u64 sys_reg_to_index(const struct sys_reg_desc *reg); - /* Visibility overrides for SVE-specific control registers */ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) @@ -1463,7 +1482,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { DBG_BCR_BVR_WCR_WVR_EL1(15), { SYS_DESC(SYS_MDRAR_EL1), trap_raz_wi }, - { SYS_DESC(SYS_OSLAR_EL1), trap_raz_wi }, + { SYS_DESC(SYS_OSLAR_EL1), trap_oslar_el1 }, { SYS_DESC(SYS_OSLSR_EL1), trap_oslsr_el1, reset_val, OSLSR_EL1, 0x00000008, .set_user = set_oslsr_el1, }, { SYS_DESC(SYS_OSDLR_EL1), trap_raz_wi }, @@ -1937,7 +1956,7 @@ static const struct sys_reg_desc cp14_regs[] = { DBGBXVR(0), /* DBGOSLAR */ - { Op1( 0), CRn( 1), CRm( 0), Op2( 4), trap_raz_wi }, + { Op1( 0), CRn( 1), CRm( 0), Op2( 4), trap_oslar_el1 }, DBGBXVR(1), /* DBGOSLSR */ { Op1( 0), CRn( 1), CRm( 1), Op2( 4), trap_oslsr_el1, NULL, OSLSR_EL1 },