From patchwork Thu Feb 3 17:41:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12734480 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 98436C433F5 for ; Thu, 3 Feb 2022 17:43:53 +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=8Ke1g6HvyF/Jk1VaCd1/Vc+DBadWZwgtskOR7N18pL0=; b=sA4 dxUlMXzVXn896XAEOfmqzqbfBECJDDpBdev57ZRQEaW0N/n5TtM+6/GEit/qF5iOPPwmnOTCdes7A u7TJOS/pHUPRigxT80dr178t0Lk3dpE3VB9pjgosg4+ZzDQEj73ZVl4BUvjd8hGWX2m1q8pLyuQUV 5niiJAU8Q/OPQCEGQ5pdtaHAMJWUkiMXrrssqAheIpv3sH7fH6H1MpKIQFJY8Bm+PfthTtlkBQiID IFscMuioE6HWZ8yFvNRfKNEB2iCztgoehl63w+VeaeZGFbGrp83Yj13Uv0/8rzIQRwdklHwdvti8k I1GV8nfY7BXAby19BU2NiRSjsvOs1hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFg7g-002IJa-8N; Thu, 03 Feb 2022 17:42:22 +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 1nFg7Q-002IEr-Th for linux-arm-kernel@lists.infradead.org; Thu, 03 Feb 2022 17:42:06 +0000 Received: by mail-il1-x149.google.com with SMTP id t18-20020a92ca92000000b002b952c60bfbso2143993ilo.15 for ; Thu, 03 Feb 2022 09:42:03 -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=wtbaMJAcQnUO9qTorbz70eUVIMRxM9RIgak6LcFUBbE=; b=iWNSw66HK3xFVyVWo/nsSDvNahYyh+8iHQJGXCfl3MJyq2KHy6SMvZSRDHo7jjcsa6 aT/A4CoJClWOCyEsZ47ZyfOsfXa3mo2Zhq3huMk2v7GZ4Gbbd61Yr1kmKtsZ6G8rtpHp 9GhIdFPv67wk8HcMhQMhIXwyFx8eIq5z5rajhIq70WXQFf3Y0XVPvFPY44cFKQVm1Iz8 /mEUwV2WwvfAsZKWlqtuBOZstP64tAw4+ra1wS5tfyeKHuTxxMkhb3O7Uvwa7fP0N+xg KMOxGB7rNY9eiz1+5dM25v5H9+y2stts4LjSN1YbGzmUAcyuAWCsKZ2d1Ot39Df9oQEf I5Bg== 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=wtbaMJAcQnUO9qTorbz70eUVIMRxM9RIgak6LcFUBbE=; b=WvJebtLF+ULWlBIpWImuJ4cAMRKMea/z/NxGSw8O3ALOONMu5g73RA25Dwtp8tGzJ8 zaY6JC1IA4KcmiSw6tO8qQvimry+F/CQ9H/LgOzQVahOTfIrXXKkbXa+sZe6eYAS7Cgp LbMkjSIkZ/vjnfGU33HHR+gyROpjh80HO+iJkdYY847UVeGkpk7nU7DFf00K1xXBGtQw B4KVQipSYTQjFElTYdf/S2/yM2rxpFVKSxtSvULPmhM+fp1JrDHdLA4B4S2OP5ORDjAY PXmS6LEQFAJwUaDc3GTV5Rf3/iycgpLx4vBzmDMIXp7U8KS+TLD8SSTy1KbSj01I59KX WjTA== X-Gm-Message-State: AOAM533oQcMVdCMHJCT3EE7+VfQg8diFX7XgNTZG3G/H/Fpua1/QovhE aS59itBmU+xBZfGbetCnNUlgLYRdhNc= X-Google-Smtp-Source: ABdhPJyjGwifMCspxAbvAxARlfmTo1KqwjLTOFFoUnnZSSU36ffXdntHhtr3u0pDpdD2d1Wz/BXGRIOMtWM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a02:83c1:: with SMTP id j1mr18511925jah.185.1643910122833; Thu, 03 Feb 2022 09:42:02 -0800 (PST) Date: Thu, 3 Feb 2022 17:41:53 +0000 Message-Id: <20220203174159.2887882-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v5 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 , Mark Rutland , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220203_094205_000035_F21D37B6 X-CRM114-Status: GOOD ( 15.36 ) 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. With this series a new register is exposed to userspace: OSLSR_EL1. Since the register was not exposed to userspace before, changes to register mutability do not have ABI breakage implications. This series applies cleanly to 5.17-rc2. 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 | 5 ++ arch/arm64/include/asm/sysreg.h | 8 ++ 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, 149 insertions(+), 23 deletions(-)