From patchwork Tue Nov 23 21:01:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12693502 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 3B180C433FE for ; Tue, 23 Nov 2021 21:03:25 +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=iPh0d4XZQckpU/JP/PImSEPrRLj0za5ZBWZkF1WCh5w=; b=iQ/ lwnZvHmmmptCAaohrbjDJhMVzcYi6Bnn0/wEfQOUGClDQWi2+UiD86+7ccs1bnezT6IRNIX1zBaR0 4X7hMQpTLjHlJGP6nDKUaLm85MljdqGnNcE1cw5im0IVITJ0zlkZobrKC2850PsaAOOrkGSDS/Rhh po7mslybJEH6RGSGFiV37aTgEpmgeTVLBDb/o5G9dHrnS5xLpMJLlktJTmuQnfh/i1EXDwlktPxxH uAXGkgilLvIY2fWWFH9KFT84oCpIgmiJSK3y7CbL8KbbNjHYVBOdVTAGVb9791r+EJ6fXZLPxKVFE RJTQGaOQbqOYorPahglPudf+cuOCMqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpcv9-003SoO-FK; Tue, 23 Nov 2021 21:01:43 +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 1mpcuk-003SiD-2F for linux-arm-kernel@lists.infradead.org; Tue, 23 Nov 2021 21:01:20 +0000 Received: by mail-io1-xd49.google.com with SMTP id j13-20020a0566022ccd00b005e9684c80c6so150115iow.10 for ; Tue, 23 Nov 2021 13:01:16 -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=4Jy9ZNvtLqSyNCGaQe67LiBMWweegmq5EAtgAYXEIo8=; b=C6+YVcqTvJAgK9Pcl8zQs362VGJn34iwhdZwoWTiSLIHyIQO2DA/U9jsP7Bw+gdDJn 5mPcJu8ToV4+GJTv22tFCrKLWcTpiIC5UCeUGZp9dYHBbjDP7og23OZ7gHYtceljUV37 hcj2can/fRzWsv7caiHv5f11NX8YsrzLALvI07GD031eEIQnMU1iFKBUOtmTU4CG+sxI nIkOusBb6IcF7bZLrQSIOCSG2L+wMbXDDQPfYIdTXlKgXA7jBVSc/cOwNcql8WDXLKN1 vq3PZA3BvLpGk9f30GuuFEckK0MqjOjZYjuoxSn6Uhn2ckFg3GG6oxlLPjCQ9HRb3OtD SAxA== 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=4Jy9ZNvtLqSyNCGaQe67LiBMWweegmq5EAtgAYXEIo8=; b=L65TBsHdth3h21XNN9Neat9BJiRM0NC4iJHuV7AvwMkhgcBAc38sPuZ8ZK2dhjR0gh 3bcSDnOtQlgEY0rJtuSqzlJQp2IbyVv1iQFtStWTEeOOLO/e30pJkIJZYex0ubTYqdp2 3jMZ1Y2dul97kj0yGhngLGDrz2p1lU/s6dfHByCCY5tPpIhKYqCswogD9ScG8y0maQ1O 6FKlp6pehg6/1B4GQTz/qUP0OfTmz8UHfFozhV7Syi0HhilWHGSm7gJZxNkqA1xgTFLP 6Z6Zhm7QxBdwexZJ2eabbX0FS6eKlopKrx6tbSKOEULn7cnx/dHmCB6v6fvbx6QrxOKM bmuQ== X-Gm-Message-State: AOAM532C76tro6Iiokoe9nnIPkXWf09Qu3yrwYvayjBfupOhKdzvewHN oWXv9QHBNkEZGdXDsOjrIMyMcSPmyQc= X-Google-Smtp-Source: ABdhPJwseHjr6oKumnq1kaHVtftmYAstQdQZxGpG32BJhANLhxR/L06sDCbf1VsVsCjLO3yQPf8BUbhcFVg= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6e02:1b8a:: with SMTP id h10mr7719477ili.14.1637701276051; Tue, 23 Nov 2021 13:01:16 -0800 (PST) Date: Tue, 23 Nov 2021 21:01:03 +0000 Message-Id: <20211123210109.1605642-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3 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-20211123_130118_154635_DFFAAAA7 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 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-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 | 6 ++ arch/arm64/include/asm/sysreg.h | 6 ++ arch/arm64/kvm/debug.c | 27 +++++-- arch/arm64/kvm/sys_regs.c | 70 ++++++++++++++----- .../selftests/kvm/aarch64/debug-exceptions.c | 58 ++++++++++++++- .../selftests/kvm/aarch64/get-reg-list.c | 1 + 6 files changed, 145 insertions(+), 23 deletions(-)