From patchwork Sat Sep 17 01:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12978937 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 62755ECAAA1 for ; Sat, 17 Sep 2022 01:07:32 +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:Message-ID: Mime-Version: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=eyOVzfHzHzyFOzyswKXqbv3WGBLSWBO9KjpALUgaBfc=; b=t3v 30JMbI96C+vlTs6TAaNcDHoZmHMIW/TpvmuZF/Nx1fa3Op2eENvoI1qV6UHb+5LYRbz1xdtLkAkVz WmonfDVISxLbGUgUQe2ncdH7G8C8Vem5xG80t8Y08bphGaVEyRw7FfnQcWqYyA4luiNmt04yFzBem RM4LsUQbbl5U8mTOLBrOnNkKt2i5ZEJHEMwQa6D5UP9kvz7GLhzvKZpmSOiCWE2DRdT2OC/jl5vZk jU0Y8/pYFDsU3jBBTXHs/jSO1BH/89tBrnvxWVTbQP/56+OWX8WGddv27X641CFGzD8la4QzUqfj3 bwnmMLimDqztuPtrisZVfNnn8bEIuHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oZMHk-001CQ3-SQ; Sat, 17 Sep 2022 01:06:21 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oZMHh-001CJo-Dz for linux-arm-kernel@lists.infradead.org; Sat, 17 Sep 2022 01:06:19 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3451e7b0234so205256927b3.23 for ; Fri, 16 Sep 2022 18:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=FPmIZ20vcTUeBFUMKdaLzmUVq8vMch7/heQIwOJWf6I=; b=tAFTWGiHh8oW2k7UJWEM5Y3bG6bkwLfnpOBuOdCuxk+rZNbmhhM1l8IU4cBn4WFKrb f+bB///QmF1d/7+xnOluIe6aNNzsU/lygE9MKZ4u5pHcwCw01d1aCJb/eoO1IAQizUT1 6U32afXpbaY8kj719kzrUygp/nfRYIjZ49AaIQimpwnLpBydSoAhrYNGHWF7BDK+beNY 3wc+w1VqMEwZgog2px86mTYdBFIMt91uyhZLoqfnUawrlKGjR6xLgPAUPmuK2glEmm3u zEij4qYIZUMQyO+6hI7HsBWaQ/MSXHMgD1vc6NGkoxA3wz4TLKzIJUoeMbADXFusTCs1 u5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=FPmIZ20vcTUeBFUMKdaLzmUVq8vMch7/heQIwOJWf6I=; b=ZUA8uxL5+p/ere5R5uPCTDOcaQFc5ghzNwiJtfkO6RHLnXauHpwokTPysvZliae5fY cvlOuYDsOyKUCpiaqDDdkOcT6f2KDHfZOK1PTgyCPYhrN4gO0Ur30GZYOfbnV7N/v7OJ ynR8ht6ArW5fOQZn0JoCMMCVDKWKNejEkxyOLjLGIZVfTO1u/4UH3sdixFEv2QQeYAM8 Exr0Gzk/qVv+yotI/RBesUxIwWMW8FjMHBYxEzw1tQQnzCUcwuc4P7Tz7RLQnSMW55Ik iSA9kZ23qgcsdyr6oq95yrcsWn7LBPniMnGm6JtqaHz+dDLZKP+YMdLNr8fTG67TGSSY QHIw== X-Gm-Message-State: ACrzQf0abeJBSYUG1V8ty7yaPYjRzT2I7HdgV1zy9T+3YG4RKGK9v8t0 iUid0qon/QPpLFxQsJJOebA2puwv5l4= X-Google-Smtp-Source: AMsMyM7+y1N9+gTgvFSbs1C1oHCJr2OfSIB0qnRQXA92Ps+jtzT3rtMrAlli+ZateJjndneNoW56QwXzWzI= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:8c07:0:b0:6af:ef09:be31 with SMTP id k7-20020a258c07000000b006afef09be31mr6435316ybl.285.1663376770905; Fri, 16 Sep 2022 18:06:10 -0700 (PDT) Date: Fri, 16 Sep 2022 18:05:56 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog Message-ID: <20220917010600.532642-1-reijiw@google.com> Subject: [PATCH v2 0/4] KVM: arm64: Fix bugs of single-step execution enabled by userspace From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220916_180617_522222_C9C55008 X-CRM114-Status: GOOD ( 13.01 ) 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 This series fixes two bugs of single-step execution enabled by userspace, and add a test case for KVM_GUESTDBG_SINGLESTEP to the debug-exception test to verify the single-step behavior. Patch 1 fixes a bug that KVM might unintentionally change PSTATE.SS for the guest when single-step execution is enabled for the vCPU by userspace. Patch 2 fixes a bug that KVM could erroneously perform an extra single step (without returning to userspace) due to setting PSTATE.SS to 1 on every guest entry, when single-step execution is enabled for the vCPU by userspace. Patch 3-4 adds a test for KVM_GUESTDBG_SINGLESTEP to the debug-exception test to verify the single-step behavior. The series is based on 6.0-rc5. v2: - Change kvm_handle_guest_debug() to use switch/case statement [Marc] - Clear PSTATE.SS on guest entry if the Software step state at the last guest exit was "Active-pending" to make DBG_SS_ACTIVE_PENDING and PSTATE.SS consistent [Marc] - Add a fix to preserve PSTATE.SS for the guest. v1: https://lore.kernel.org/all/20220909044636.1997755-1-reijiw@google.com/ Reiji Watanabe (4): KVM: arm64: Preserve PSTATE.SS for the guest while single-step is enabled KVM: arm64: Clear PSTATE.SS when the Software Step state was Active-pending KVM: arm64: selftests: Refactor debug-exceptions to make it amenable to new test cases KVM: arm64: selftests: Add a test case for KVM_GUESTDBG_SINGLESTEP arch/arm64/include/asm/kvm_host.h | 4 + arch/arm64/kvm/debug.c | 34 +++- arch/arm64/kvm/guest.c | 1 + arch/arm64/kvm/handle_exit.c | 8 +- .../selftests/kvm/aarch64/debug-exceptions.c | 149 +++++++++++++++++- 5 files changed, 190 insertions(+), 6 deletions(-) base-commit: 80e78fcce86de0288793a0ef0f6acf37656ee4cf