From patchwork Fri Oct 29 00:31:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12591359 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 7184CC433FE for ; Fri, 29 Oct 2021 00:34: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 343F1610CF for ; Fri, 29 Oct 2021 00:34:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 343F1610CF 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=Ziu6/XOT2uilUTtjKxM/qMkyFyzayHOrKnhXNNsOslE=; b=GXv t3GCPbnfOrgx2vZ6IVb1DMDMgpaW33oyT4PemMoTRR6z/GEBeCw/fZuxZjDi6bj1bLTQariqBZado 87sr67Fdlrx5hvKtALu1d/JbhOHybrhgbFIOyV6HI6+ObTwemFu4cGKPEoKFcfv/UHi8ImzRM6sco MnAi9zL5p7WFxPQdjOxUHvU/pT1E0QmMeLvJoAp7Xp/LUegd+AFe4fDmpUL/ZfcA/MkSvU9eWVK9F IyxOEO63HAJPQPJSjLATG+hC4rf7eqXaxLOyeoLt89rlBEYNe0axPz5S0upxul5Wgk5jfo9T80BVD nyXjXSwdjb5cP4DGPt2GgX0GPQQMs6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mgFp9-009Nly-6k; Fri, 29 Oct 2021 00:32:47 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mgFp5-009NkJ-RC for linux-arm-kernel@lists.infradead.org; Fri, 29 Oct 2021 00:32:45 +0000 Received: by mail-yb1-xb49.google.com with SMTP id h185-20020a256cc2000000b005bdce4db0easo11143343ybc.12 for ; Thu, 28 Oct 2021 17:32:41 -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=vw5IElLY3kB8cY1L2Z+7D5wanBys4JUHwDM1VncqKoI=; b=PCh1M803lS/Kd65Q8t89i5Nu8M1/0FfLF3gOxRVpd9H5ySYjaVIlKhrcBmAAZHAvHL v1TsKipc2dhUgHXNlPnV6jTdmV8k9F46xup3BxToefljw/OFIXB7jePY2Cm5XrOxHzi1 s8M6HeWExB082mLRIgrKgNPhssfGoXV53P/km8PJih9ZFR6rbrcbCAS6w32AIVYPYJgJ jkreVHIwHpBpbmFJP36xIPd7JbRl7aE/2xUzNuumQ+Q8H5dY5ooxCypcZIgwXw/K8JHp PkbLJ/g8MvaXOZdsUClyOyvB5EZXIMWrkgMJezJ2FuSquxP6Vg4Umm2GNRVIu2mPTA1R K2DQ== 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=vw5IElLY3kB8cY1L2Z+7D5wanBys4JUHwDM1VncqKoI=; b=3fgnmWriPJbgFMom9p9kQ6KyAL30qXfDuXM55f5rSAIMy72z+NNo6E3tFZbdmODuTJ POfhZHXILwWX5D4bYVHyodKXHhzVUu3zyFUNNkLAutV9g/7T+QR/Me4+j1s7Nlaf2iAt dgZkiWDLeHFMuhuSb7GZhsG3zgx8hAZndaxs9X9iUtFl0wPQMMNha9hu/ezQSy3ApHHG VMgDZhangGVzfKuMmHeJ0EGQ9d33bOTtIb+K+e8hdWB4sQ6koQkRraUhGek0LKWx30OI 7pySy/f6lrrOUDoJZBDKSmrM6GGl+FmwZ8IROuBK3YUjCghhi5IO7Im+WSSqvIP4sc8h oPBA== X-Gm-Message-State: AOAM53154eOwRA5ghSAMPAW7syfR6OCE6GkhbL4RLfiSmnAyrLERB4oj QdiOlRg0Hl7cr/tOmvvDz6WdWgCT9u8= X-Google-Smtp-Source: ABdhPJxAz30X4IhyMRe9T1OY/gwd77ukFMDfy0+meau5n4bTd35B4sOyPkxXfMVZntXji4d0V4ISRBJUilI= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a25:aac8:: with SMTP id t66mr8949989ybi.238.1635467561151; Thu, 28 Oct 2021 17:32:41 -0700 (PDT) Date: Fri, 29 Oct 2021 00:31:59 +0000 Message-Id: <20211029003202.158161-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH 0/3] KVM: arm64: Fixes for the exposed debug architecture 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-20211028_173243_929034_389C901B X-CRM114-Status: GOOD ( 13.52 ) 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 I had a conversation with Marc about some of the quirks around the debug architecture on KVM and incorporated some of his suggestions into a series here. Of course, any glaring mistakes/choices made in this series is on me :-) Anyhow: KVM's implementation of the debug architecture is a bit deviant as it stands. For one, KVM handles the OS Lock as RAZ/WI, even though the architecture mandates it. Additionally, KVM advertises more than it can actually support: FEAT_DoubleLock is exposed as implemented to the guest, though OSDLR_EL1 is handled as RAZ/WI too. Only v8.2+ revisions of the debug architecture permit implementations to omit DoubleLock. Fortunately, the delta between v8.0 and v8.2 is entirely focused on external debug, a feature that KVM does not support and likely never will. So, there isn't much of a hurdle to bump KVM's reported DebugVer to v8.2, thereby allowing KVM to omit DoubleLock from ID_AA64DFR0_EL1. Of the remaining bits of external debug visible to the guest, the only additional thing to address is the OSLAR_EL1 issue by simply context switching the host/guest values. Patch 1 changes the way KVM backs OSLSR_EL1 in the sys reg table. Instead of returning a static value from its handler, stash a copy of it in kvm_cpu_context and return that when read. Patch 2 makes the material change of allowing a guest to actually toggle the OSLK bit by redirecting writes to OSLAR_EL1.OSLK to OSLSR_EL1.OSLK. When saving context, simply stash the value of OSLSR_EL1. On resume, apply OSLSR_EL1.OSLK to OSLAR_EL1.OSLK. Finally, Patch 3 raises the KVM debug architecture to v8.2 and exposes FEAT_DoubleLock as NI to the guest. With the changes to OSLAR_EL1 in this series, KVM now does what it says on the tin. This series applies cleanly to 5.15-rc4, and was (lightly) tested by booting 5.15-rc4 as a kvmtool guest on this kernel. Oliver Upton (3): KVM: arm64: Stash OSLSR_EL1 in the cpu context KVM: arm64: Allow the guest to change the OS Lock status KVM: arm64: Raise KVM's reported debug architecture to v8.2 arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 5 +++ arch/arm64/kvm/sys_regs.c | 42 ++++++++++++++++------ 3 files changed, 37 insertions(+), 11 deletions(-)