From patchwork Tue Nov 2 09:46:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12598265 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E7FCC433EF for ; Tue, 2 Nov 2021 09:48:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6C05260C4B for ; Tue, 2 Nov 2021 09:48:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C05260C4B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=/fnQYkVS7408xEexW3Qq9SrrEuYGwsU5wIRx3s45ChQ=; b=0wbv/+B/tNQ+yv+NcOGMS6GHTE mH7yI8439f5O3pDr3TuqiyWXy4eQHaCBBTsNDc/JXg2i2SuT21fL6SFIFCZfCK8XC4u8Z74py4Q92 E4MmcTF7uPRMV/zvfGzGTD7WFXVQkkN+SFnopxfoXw3TqvX5OvQyrzhgt7g12I3P/B5gySRrBkjyo YegoMGxNvM7iwZrWiEc3auBqcq/hz7nXn8B6lVmfkPJegfrY86N4ehwbmA3OAce/kkAzT/mxSyFO2 J8fl0zYA96CxNDRqdyR3BtZ8QgUkcdm0Psv0WVUhKELIbicmmIgelWwjbHJWynAQ/QKMaEIo59aqz qMa8N7LA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhqO8-0018vp-5w; Tue, 02 Nov 2021 09:47:28 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhqNj-0018mK-Pg for linux-arm-kernel@lists.infradead.org; Tue, 02 Nov 2021 09:47:05 +0000 Received: by mail-io1-xd49.google.com with SMTP id k5-20020a0566022a4500b005e1c84e667dso986325iov.16 for ; Tue, 02 Nov 2021 02:47:02 -0700 (PDT) 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=DbmokXu45N05i00rjRKFS9Aukc67vZn4OjwqX1uC/YU=; b=EdDi9FOXMCGHRhU016qAQn/ZmuBFvVQyBV401phw9A0mM29D7FCBkKrqoRN+ddaDKu WMNSZyuCDNWevO/SP5n9ML9GzsOq3KJVi026ObUqHeQqAO6uvqeRwYkUUMyOGQWHiYA2 tnvJWSLvjtmZY8JFr6NQakWEW4/5U9vJZL8Lqm47kV26cjyA2ANUqH8OMBybG6CG908N x0okPVWvlaqCs8jLleOKU+LoC7nP19scolOl5HFZ8y+ukdy5eVk5p2toXh3eLSrG2BBJ +fwB5JpZB8U6m0jYd/lt9RgHDohbN545YLjTCvSuLn+ccimIQxFvgF0GnE25PMzP3z+b oMng== 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=DbmokXu45N05i00rjRKFS9Aukc67vZn4OjwqX1uC/YU=; b=B0qcnquMb2P59RzY+p0oVOrDBFU6kp+sDfl6/q2VgMC2zXP4rVJONPuREhNQ2YLkZ+ C4M3zQ+suBkuVq8U2K+DXCwO9Ysyjjs52NHaPrGDSypG7vrHPNi2RTaKQzX1baunJpxs hLFgrV/Ka2lOqV6UWA4+wgQhWTfus8nygh7pgxAU79sgaxDLZUACbzm+wYC08LJZqG+5 FP4XCWqxzhLNm5g4ulsYUVFBdiEmVpkzns8pv9HX68fhKpmehXkU1GbaYVKPbzKK3O7e fCtyNtSxVA+/Z6kk3QmqtiPz4v7frpw7+B39Q99LAC+6M8rEiyMuyPdDjhm0dBja/Yrn Rrow== X-Gm-Message-State: AOAM532NAFZPvYnI1TjafeiWxVAVHWVVpja89XcG5v83jPg5kNpNBU1v t9QxrHsPsOq0mL/qej0N/CnU6W/KFK8= X-Google-Smtp-Source: ABdhPJyDtijBd6vvihLRehY/zlMTHVriiJWyurunjgvekkIvbB0W9BlpBBhTD9Sttnoy8lUPFahbqXpiX6c= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a02:a884:: with SMTP id l4mr26257855jam.44.1635846421777; Tue, 02 Nov 2021 02:47:01 -0700 (PDT) Date: Tue, 2 Nov 2021 09:46:47 +0000 In-Reply-To: <20211102094651.2071532-1-oupton@google.com> Message-Id: <20211102094651.2071532-3-oupton@google.com> Mime-Version: 1.0 References: <20211102094651.2071532-1-oupton@google.com> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 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-20211102_024703_860699_A1775009 X-CRM114-Status: GOOD ( 14.82 ) 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. Signed-off-by: Oliver Upton Reviewed-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/sys_regs.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index f8be56d5342b..c98f65c4a1f7 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -172,6 +172,7 @@ enum vcpu_sysreg { MDSCR_EL1, /* Monitor Debug System Control Register */ MDCCINT_EL1, /* Monitor Debug Comms Channel Interrupt Enable Reg */ DISR_EL1, /* Deferred Interrupt Status Register */ + OSLSR_EL1, /* OS Lock Status Register */ /* Performance Monitors Registers */ PMCR_EL0, /* Control Register */ diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 17fa6ddf5405..0326b3df0736 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, @@ -1441,7 +1457,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 }, @@ -1916,7 +1933,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 */