From patchwork Tue Nov 23 21:01:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12693503 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 C6B00C433FE for ; Tue, 23 Nov 2021 21:03:30 +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=aBMjgZP2vFRx0KxgiA63C7Kauek9UK59lOPpo/YAWy4=; b=aLbkgSk2/yn4EhID/PMpOL2cVY 0at4FVKrb8vBBUIIm6BjhmguGzER4jMCmWc2NXq+IadejD0ThcpqsuslbjJ1ckkHp3KHvw16Gj97i 5Ap6Qznf/iefwFosRs0s0kQbcgum0V6rDD4zuBx+CyvaBSv7Ba62aD3eu6SF4yWN/s9VSr7UVtsrw YfIUaVm3T+bDvbzUn2NTT1gooRW7GlLXEUWt3NXadxla/Gj0vEbqpCtLJSMxu+KbW1MTjtw3mlVFZ CJtvMfldVXhuEMnYJTXuqd8qH6XHzZ1ut4alKnmGpKkg1k7MX5fojuf063ngTFixNnT682K9VYial T9MAzv0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcvK-003SpJ-4g; Tue, 23 Nov 2021 21:01:54 +0000 Received: from mail-il1-x149.google.com ([2607:f8b0:4864:20::149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcul-003Sj9-Lw for linux-arm-kernel@lists.infradead.org; Tue, 23 Nov 2021 21:01:21 +0000 Received: by mail-il1-x149.google.com with SMTP id d8-20020a928748000000b0027585828bc3so229968ilm.7 for ; Tue, 23 Nov 2021 13:01:18 -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=3r/HSQlSMaGqGuO6qlyByqylj4w37aYh03CWLKihWyE=; b=I8o6vjAywpa6ruSUYX/8rdQEeBmRUvrZry6knOs03Fgu95sSJgIAGoEOAm5r52PDyM OPUu6j2D962rPDVnZCg/PcPaiRpKDm27kqyLUztlCTLwup2hcjFYHG7RZ4r4CJHzjpjo 47XmcQns0NFxIW4y+Tam+CSpz0of/dHbWg06/kEztW/6TQd9Jtg184l9TrwZiJG22i8G Ya24YTmfCQKVw8J7RVMbFS7QOLYgstBAxVflKJRtxOBJKbsWMs2c3RD6WxijeZUXsOTA k0aYjkpMBXtBcwytCiuXiX9UvwE4imWn/KbfC7lMdFNzMHklDMH/bAN/hYO5xQ3AAg4g 2e2g== 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=3r/HSQlSMaGqGuO6qlyByqylj4w37aYh03CWLKihWyE=; b=6A/Nu0xzCtHu2t9HkFnsfKqD7UzygDdJ8/Nj6+BuD6o/0rgs89No9NjUgEae/0Lu3s KtrQLjNutDd7HlNsU4fDK/LBa5HN+mfMgDXWPqn1bLA8XG61oZKUc2QyLwCKiOI9mEEm SLltaxoBzMINlogFnM556e/KvI63TRRA2E6IE6ON9oEgcvSoXRSAaGOvxCtS3taX458C SoH5m0qTb5pjK3cH2PdYvvjkA/C0IJji6lyZXiyZcoPrVEeTTdbWO90xY+r9mRyQ317W cvT4NYFwOg8yktcM98E7ROzKarAH2lfzt+HU/X92N8dBZKsHtCnriGaAYxfrYjoLoViR iyFw== X-Gm-Message-State: AOAM531qEc9CpHhiH3VjheH49b59LqbEHK6xT+0FwwDzD5bIzUDbFIvT 8VnHGmIhKUzNuo2BtpapO4GbZiJfCrw= X-Google-Smtp-Source: ABdhPJyC0nmrb9p3Fph5PiHQgzCf4XqAVV9qwdGI+BZkjpGMX0GXawApszVLVF40+DN93mTIiNXihq0S8Bg= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:2146:: with SMTP id d6mr7996051ilv.45.1637701278015; Tue, 23 Nov 2021 13:01:18 -0800 (PST) Date: Tue, 23 Nov 2021 21:01:05 +0000 In-Reply-To: <20211123210109.1605642-1-oupton@google.com> Message-Id: <20211123210109.1605642-3-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 2/6] KVM: arm64: Stash OSLSR_EL1 in the cpu context 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_130119_746533_D90E06AB X-CRM114-Status: GOOD ( 14.73 ) 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 An upcoming change to KVM will context switch the OS Lock status between guest/host. Add OSLSR_EL1 to the cpu context and handle guest reads using the stored value. Wire up a custom handler for writes from userspace and prevent any of the invariant bits from changing. Reviewed-by: Reiji Watanabe Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/sys_regs.c | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 2a5f7f38006f..53fc8a6eaf1c 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -172,8 +172,10 @@ enum vcpu_sysreg { PAR_EL1, /* Physical Address Register */ MDSCR_EL1, /* Monitor Debug System Control Register */ MDCCINT_EL1, /* Monitor Debug Comms Channel Interrupt Enable Reg */ + OSLSR_EL1, /* OS Lock Status Register */ DISR_EL1, /* Deferred Interrupt Status Register */ + /* Performance Monitors Registers */ PMCR_EL0, /* Control Register */ PMSELR_EL0, /* Event Counter Selection Register */ diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 11b4212c2036..7bf350b3d9cd 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -291,12 +291,28 @@ static bool trap_oslsr_el1(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - if (p->is_write) { + if (p->is_write) return write_to_read_only(vcpu, p, r); - } else { - p->regval = (1 << 3); - return true; - } + + p->regval = __vcpu_sys_reg(vcpu, r->reg); + return true; +} + +static int set_oslsr_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, + const struct kvm_one_reg *reg, void __user *uaddr) +{ + u64 id = sys_reg_to_index(rd); + u64 val; + int err; + + err = reg_from_user(&val, uaddr, id); + if (err) + return err; + + if (val != rd->val) + return -EINVAL; + + return 0; } static bool trap_dbgauthstatus_el1(struct kvm_vcpu *vcpu, @@ -1448,7 +1464,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_MDRAR_EL1), trap_raz_wi }, { SYS_DESC(SYS_OSLAR_EL1), trap_raz_wi }, - { SYS_DESC(SYS_OSLSR_EL1), trap_oslsr_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 }, { SYS_DESC(SYS_DBGPRCR_EL1), trap_raz_wi }, { SYS_DESC(SYS_DBGCLAIMSET_EL1), trap_raz_wi }, @@ -1923,7 +1940,7 @@ static const struct sys_reg_desc cp14_regs[] = { { Op1( 0), CRn( 1), CRm( 0), Op2( 4), trap_raz_wi }, DBGBXVR(1), /* DBGOSLSR */ - { Op1( 0), CRn( 1), CRm( 1), Op2( 4), trap_oslsr_el1 }, + { Op1( 0), CRn( 1), CRm( 1), Op2( 4), trap_oslsr_el1, NULL, OSLSR_EL1 }, DBGBXVR(2), DBGBXVR(3), /* DBGOSDLR */