From patchwork Tue Nov 2 09:46:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12598261 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 56DDAC433F5 for ; Tue, 2 Nov 2021 09:48:19 +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 211796054E for ; Tue, 2 Nov 2021 09:48:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 211796054E 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: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=FM5PBkZtc3m6sh9UWExhmQTodKHoQ5SREzh18GKj/j8=; b=Jvv eVGDnjZcU3uxrHbFBy7IJ8VQYlQZyNgwJeluXiIiRpyRKbQFWGOEXKBFosYaJ6z2nxJ3r/avkYwPq V9R0NF7g/yJzr4BJG5ArG/qEdRF88NbukOObicu38gZjlbZJU8yRLMXydVzgcPjqxtfc4M3FY8GDQ 6zK/4oVVjMsHaP5CrUn7F4sjmOxCe4XcoPpmky6+3fSHgH5Alv7G1xrtwYSSRH7HdspvZbqiaOsMq 6gMqcPKXqMccLNf4Z/DzxwGOv+FJy/5N9UAqt9Z1gniLQ77eV2NEg7Lfsze9iA2OdM2uTwqWRwfHa fcGr4CWiOCUdJw8LV9ovSYzyxMdZ18g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhqNm-0018p0-U1; Tue, 02 Nov 2021 09:47:07 +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 1mhqNj-0018m9-7z for linux-arm-kernel@lists.infradead.org; Tue, 02 Nov 2021 09:47:04 +0000 Received: by mail-il1-x149.google.com with SMTP id a5-20020a92c545000000b0026b54ead1b1so3741045ilj.13 for ; Tue, 02 Nov 2021 02:47:00 -0700 (PDT) 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=8Hd2ZUMx5ILHWyo2zM7pIHkuH4DnNmNsL76fDtWtm1s=; b=E2M0qmyqra/TlmR8sNdUNnqypFAgx2byfZsucj64HcfDQTvxD/mvhZJkXohOyHvfnv d5IB+ZGFXPR88GhGj/Ivf6QeDGp/6YurkWU2p55yIF4wdlt+JGIIU7r6G+HtZB05dFYo CGJuXlvDZLzUfyKYuMfoyq10hlYCDy/eizAOlLOxyNs7nwnVK952aeHGe/7QAwduEmge +I11gM4N4guNIyZWghqOG+A1y17uVCtQQwQhMKCIY5yU3QnKn7qPfbhZl8i+MP/Jd3Kf l3LWpUcJCZ8LPuWIkK9ibOyrEYmODpJ1s/MuMXosi0RdgDOUHSUtMAoyMKpl4/92Jzdp NXJw== 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=8Hd2ZUMx5ILHWyo2zM7pIHkuH4DnNmNsL76fDtWtm1s=; b=u8eXjAe4pfuuWAS47ird2/xkq4NiEu57cmh4BYVhrp2Yie3nCKsxoRHvyZukyvIvNy UNC6JXdvFTv9sKsRRiCqBJNDm/MAw7I0T+WHMy8uEgRJe84YVnjTnURUgvWYXsYsFLuC RUyWqZVtWxVnEqif9DVuPtHBcw24e5qQCP7w8Fj5DXefavOwXNjEVhMLB/oa356QXyt7 SN1nKmn4QJqGOI2gRwBEcizTBUmOcd8PP+VoQg3JB2Kcm7CJVN+hEF+1slZxCDezGUiQ myE4MMKxARBABajxCtl33xqc5obv7QNR6vAsJ3eKNEx8FXVbrMDUD/KoZF7+BbERUQZE LibA== X-Gm-Message-State: AOAM531S9N7+0ZuaK2f00fhrHRA9ySwfiLgUm7yMIqIgKU6ZewBmAzPI yKC68hoQ7S4OZyjkdNsIkXZsY88ctE8= X-Google-Smtp-Source: ABdhPJwp82eJZKpATb/STfJK1tEYrOYlTSbWGpyQyJFGOHuzO64TyzBAnAXrfYhajH7o5tbhGvqNlILST3A= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a02:c9c1:: with SMTP id c1mr11157225jap.0.1635846420169; Tue, 02 Nov 2021 02:47:00 -0700 (PDT) Date: Tue, 2 Nov 2021 09:46:45 +0000 Message-Id: <20211102094651.2071532-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 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-20211102_024703_330539_3B02ADC6 X-CRM114-Status: GOOD ( 17.40 ) 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 from the perspective of the guest. This is done by disabling MDE and SS in MDSCR_EL1. Since software breakpoint instructions cannot be masked by anything but the OS Lock, we emulate by trapping debug exceptions to EL2 and skipping the breakpoint. Skip this whole song and dance altogether if userspace is debugging the guest. 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.15. Tested on an Ampere Altra machine with the included selftests patches. Additionally, I single-stepped a guest using kvmtool to make sure userspace debugging is still working correctly. [v1]: http://lore.kernel.org/r/20211029003202.158161-1-oupton@google.com v1 -> v2: - Added OSLSR_EL1 to get-reg-list test - Added test cases to debug-exceptions test - Scrapped the context switching of OSLSR_EL1 - Dropped DFR0 changes, to be addressed in a later series 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 | 5 ++ arch/arm64/include/asm/sysreg.h | 6 ++ arch/arm64/kvm/debug.c | 20 ++++-- arch/arm64/kvm/handle_exit.c | 8 +++ arch/arm64/kvm/sys_regs.c | 70 ++++++++++++++----- .../selftests/kvm/aarch64/debug-exceptions.c | 58 ++++++++++++++- .../selftests/kvm/aarch64/get-reg-list.c | 1 + 7 files changed, 144 insertions(+), 24 deletions(-)