From patchwork Tue Dec 14 17:28: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: 12696096 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 501C3C433EF for ; Tue, 14 Dec 2021 17:29:48 +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:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=00j00wfpGptf7MoF8qX1jDwxVh2aX8DKfFYB1+ejtVo=; b=jdv K/7xVU0yEn4iszztYWMiZPPHAjCL6d1nRyj10GgOhxl8mt0iwRq3031wXayWbNBdnJRPtrWkDoIwT Mz8waPKgWcxfJQqXFDQRUpostoVKgSI+YWf0sCj+goU1Zht1Ypvu8GZiKINj0W9WQELfifLmZ+alb 4J/xa38k8L0kEYVVpcR1zw/fXip8o1RmoP8UWf9VNXc+a5LWIdUb73WKwAh9y7m06jIdtL9qbr/G1 a0SP2qR98HToPz+Pkwg/fsEfeFm3mT6jJ6R9WqeHBba8GKQ0DFSMg9BF4nTIoybDrTPTGbdj62zDD afMaWKk9++2B8VynjkJ+/kqnuqimbcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxBbC-00F6Vl-Rl; Tue, 14 Dec 2021 17:28:23 +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 1mxBb8-00F6UR-U4 for linux-arm-kernel@lists.infradead.org; Tue, 14 Dec 2021 17:28:20 +0000 Received: by mail-io1-xd4a.google.com with SMTP id s199-20020a6b2cd0000000b005ed3e776ad0so18291682ios.18 for ; Tue, 14 Dec 2021 09:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=zk8b273QnCh6EBKHsBLZCwm7phsH1qXNNxAFMztBRMQ=; b=Z1p6iB38u4qCLN3DR6XCPMSeigD1Z90OlOv79x1GPPrkP/Zle4CFrX7F1AkqkyLyv7 pTfAm2sxx5KBGsVYl56DkuvF8sus9B08ph5GevUidg2bCb2erwD34UEBUPgQOLv2mcgR ttlLQ+aDL8Y+RBNggNyu2CUQAdU88fB6nPfi8d7KDMjMMZQ8uVCn5U/6ZJr8yehKvQq0 YK4s3ktTyMmfdGY1232w6DsMQ2PcXxxJkoJxHs+J6kv9Z3xtxkjSTBPdaELbVMwVRRj6 Vpp1uDVLDs+pDeM0HqOS9PL1A9Jajy0DfNyDpiCp0whq9oBBQx135HKMKyhmTo12gaXb NmRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=zk8b273QnCh6EBKHsBLZCwm7phsH1qXNNxAFMztBRMQ=; b=tQPm8xKD2JwBWPmCr4eBoT4RDzpS3WgXKDimdKmbw7nlxZHy2gRj2LzK5NCPHMX5Sr mwP05l9Xca1WOufVurzIglKu89bTOXvfPSF65MczLbB0Ynk9tOBk5PYNf+bFR5YwEtr9 WIffAb953xlT5R1HuxaVpiE64Oa0XtPIdTWkQy8qWIRyzsIwGruOrolP3lS04iSxms4k u75Fv8RXtkJqLXjnmwbxlhkX2YuW3iRO+U5ajVH70Lz7uZb11EZ/KR46oRm3dUOtDduH 4ipWDoPmmjHeZqLkqUwAQn3msuelVJRRHvPYOrQvnDpBLBE+Qhb4mYDrDwKGjKlziM06 PUEg== X-Gm-Message-State: AOAM5300bGby8JUWzPYDn04vGRZrGff5Z4K4yZDCneBKJlMkf0PxUOUR N+1KsWhs3uWtBpiiuEzwOaGKpgxjYIg= X-Google-Smtp-Source: ABdhPJwm2kW1tWIdTafhk7By1Qz8hjfZFCojXCQPPWKGX9iyHrDuiA02tnU4jkY+2HaL5PjwP1IH8HpANww= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a92:8747:: with SMTP id d7mr4479540ilm.203.1639502896974; Tue, 14 Dec 2021 09:28:16 -0800 (PST) Date: Tue, 14 Dec 2021 17:28:06 +0000 Message-Id: <20211214172812.2894560-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [PATCH v4 0/6] KVM: arm64: Emulate the OS Lock 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-20211214_092819_010910_EBEBDBD6 X-CRM114-Status: GOOD ( 14.44 ) 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 KVM does not implement the debug architecture to the letter of the specification. One such issue is the fact that KVM treats the OS Lock as RAZ/WI, rather than emulating its behavior on hardware. This series adds emulation support for the OS Lock to KVM. Emulation is warranted as the OS Lock affects debug exceptions taken from all ELs, and is not limited to only the context of the guest. The 1st patch is a correctness fix for the OSLSR register, ensuring the trap handler actually is written to suggest WO behavior. Note that the changed code should never be reached on a correct implementation, as hardware should generate the undef, not KVM. The 2nd patch adds the necessary context to track guest values of the OS Lock bit and exposes the value to userspace for the sake of migration. The 3rd patch makes the OSLK bit writable in OSLAR_EL1 (from the guest) and OSLSR_EL1 (from userspace), but does nothing with its value. The 4th patch actually implements the OS Lock behavior, disabling all debug exceptions (except breakpoint instructions) from the perspective of the guest. This is done by disabling MDE and SS in MDSCR_EL1. The 5th patch asserts that OSLSR_EL1 is exposed by KVM to userspace through the KVM_GET_REG_LIST ioctl. Lastly, the 6th patch asserts that no debug exceptions are routed to the guest when the OSLK bit is set. This series applies cleanly to 5.16-rc4. Tested on an Ampere Altra machine with the included selftests patches. Oliver Upton (6): KVM: arm64: Correctly treat writes to OSLSR_EL1 as undefined KVM: arm64: Stash OSLSR_EL1 in the cpu context KVM: arm64: Allow guest to set the OSLK bit KVM: arm64: Emulate the OS Lock selftests: KVM: Add OSLSR_EL1 to the list of blessed regs selftests: KVM: Test OS lock behavior arch/arm64/include/asm/kvm_host.h | 6 ++ arch/arm64/include/asm/sysreg.h | 9 +++ arch/arm64/kvm/debug.c | 26 ++++++- arch/arm64/kvm/sys_regs.c | 74 ++++++++++++++----- .../selftests/kvm/aarch64/debug-exceptions.c | 58 ++++++++++++++- .../selftests/kvm/aarch64/get-reg-list.c | 1 + 6 files changed, 151 insertions(+), 23 deletions(-)