From patchwork Mon Aug 16 00:12: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: 12437541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1541AC432BE for ; Mon, 16 Aug 2021 00:33:18 +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 CD5056135E for ; Mon, 16 Aug 2021 00:33:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CD5056135E 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:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CNkYrFWnDneuqtRKlWqCvX3maUEMVnHWrBDP0FlRBXE=; b=Nby/4qjgRMvAObiOKgi3MiCS3n TDSgjodJFZAOGTwG+X3FWp9oIpHSbShxQumj+px5qap99Hihoa9LTADkp4EIz3UtxgEbl8HUYKmsJ cpDbivZMWUhlKFyZiDCfgP4+bB/ULGirUpxFWqVQ/g+d00V/I7H0dHlBsvTyBMS4ekqhAlVgasHjz tiEIZ75KMLomDcS9EWLY9nMfHEZcskMDjMwHXNoP2gcM6TqeUcSklyEM58uvS4FrbU6uWlUw2EKKn gOaXTpCk2A0lD4eLYxv4+WBfmIHv0dzbCDkNXmA064uxX/5Rr9b8E3DYI07cjfa8DN5K9cNrllU0e 4vvHhrxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQWM-00FrfG-Kh; Mon, 16 Aug 2021 00:30:30 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQFR-00FlPm-VZ for linux-arm-kernel@lists.infradead.org; Mon, 16 Aug 2021 00:13:03 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id u8-20020a0cec880000b029035825559ec4so11762014qvo.22 for ; Sun, 15 Aug 2021 17:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1lYvkLvXMkZOW0Omv5DbnXGOEluFv2cT8dCWAkq6vrY=; b=ucoXmLaWopVhB4jndrMR345quHVgr2BI7iLJWrHy29tE2EOZcJZyRCkaNYoq+cCb1s nOS6S8Mo5cgsX5YvhwHLiVQNh3/pP6tRaAztg6MMwEkUJ1ZfqzukhcDfDdQS0bsR99la N6N3itdIeBBf1CxU4aoxMwyGoHsFUeqWmfTwzyXGX1ALxhANxsreVkv4GiHivCkAgMzv IBc87KPLN/5IsJt4WkC+P9dw4aVfsGiEqo3A6OIborROOWqmCBJoZTCYMX2+F0FZWQl1 2hhsiQB4JVMYGPOFoaDPb34qTUO4z2df1RFV6BjoSiz6O6JsgLNHuFsrFiFyDJFtkLch zg3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1lYvkLvXMkZOW0Omv5DbnXGOEluFv2cT8dCWAkq6vrY=; b=bqwQS1qvp4AG+k9EcbRk4Apmxcx2MjqxigTUbXACmW4R+rX7zmarATmhHYL57DB3lV nhDW7XqcmENiecO6AsgY9/JAR8seX7h+aJdVQasn9EHRBQKJ2B/QoausyDKL0eRTlaoS 5R1NyDmFxoUuLshc5egmUJyYAbgDM0JeFrF6EHaMDFMDTVj3UOWisyrzisS18Fcqkb2I WKcR7PvVjfc2izd9aSY1exuXowOnr25inpX9i06MATDW8o3T9F1XuR+hzJip1oVreVjY 3W18v9qyVJJwu5KgCjVPX2d0NF4jMps4vmgK8VGTyhN5wcQQNNi34vRHBNVl7R5N+0iK D7jA== X-Gm-Message-State: AOAM532WcAlswXHoerrMDB2GgzVYOOlMjXqlrC+QcQOR0T28a3IKpAFU /K4gwP0ciXaxRdPJUnhcbHRuXW7Pahg= X-Google-Smtp-Source: ABdhPJx2WNiG5Xm9EOAshaEpB0QvoPQw0RzciABjW2FV+0QygZ9dWPd5OcyKOs52q3Nfg8WF270Sk4LNSTM= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a0c:e609:: with SMTP id z9mr13684667qvm.37.1629072780405; Sun, 15 Aug 2021 17:13:00 -0700 (PDT) Date: Mon, 16 Aug 2021 00:12:45 +0000 In-Reply-To: <20210816001246.3067312-1-oupton@google.com> Message-Id: <20210816001246.3067312-9-oupton@google.com> Mime-Version: 1.0 References: <20210816001246.3067312-1-oupton@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH v7 8/9] selftests: KVM: Test physical counter offsetting From: Oliver Upton To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210815_171302_087941_F6AD0674 X-CRM114-Status: GOOD ( 14.78 ) 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 Test that userspace adjustment of the guest physical counter-timer results in the correct view within the guest. Cc: Andrew Jones Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones Change-Id: I8a26e88df5c5bc03740c7f980c405b4d21b28be8 --- .../selftests/kvm/include/aarch64/processor.h | 12 +++++++ .../kvm/system_counter_offset_test.c | 31 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h index 3168cdbae6ee..7f53d90e9512 100644 --- a/tools/testing/selftests/kvm/include/aarch64/processor.h +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h @@ -141,4 +141,16 @@ static inline uint64_t read_cntvct_ordered(void) return r; } +static inline uint64_t read_cntpct_ordered(void) +{ + uint64_t r; + + __asm__ __volatile__("isb\n\t" + "mrs %0, cntpct_el0\n\t" + "isb\n\t" + : "=r"(r)); + + return r; +} + #endif /* SELFTEST_KVM_PROCESSOR_H */ diff --git a/tools/testing/selftests/kvm/system_counter_offset_test.c b/tools/testing/selftests/kvm/system_counter_offset_test.c index ac933db83d03..2b8b4b84a273 100644 --- a/tools/testing/selftests/kvm/system_counter_offset_test.c +++ b/tools/testing/selftests/kvm/system_counter_offset_test.c @@ -57,6 +57,9 @@ static uint64_t host_read_guest_system_counter(struct test_case *test) enum arch_counter { VIRTUAL, + PHYSICAL, + /* offset physical, read virtual */ + PHYSICAL_READ_VIRTUAL, }; struct test_case { @@ -68,32 +71,54 @@ static struct test_case test_cases[] = { { .counter = VIRTUAL, .offset = 0 }, { .counter = VIRTUAL, .offset = 180 * NSEC_PER_SEC }, { .counter = VIRTUAL, .offset = -180 * NSEC_PER_SEC }, + { .counter = PHYSICAL, .offset = 0 }, + { .counter = PHYSICAL, .offset = 180 * NSEC_PER_SEC }, + { .counter = PHYSICAL, .offset = -180 * NSEC_PER_SEC }, + { .counter = PHYSICAL_READ_VIRTUAL, .offset = 0 }, + { .counter = PHYSICAL_READ_VIRTUAL, .offset = 180 * NSEC_PER_SEC }, + { .counter = PHYSICAL_READ_VIRTUAL, .offset = -180 * NSEC_PER_SEC }, }; static void check_preconditions(struct kvm_vm *vm) { - if (vcpu_has_reg(vm, VCPU_ID, KVM_REG_ARM_TIMER_OFFSET)) + if (vcpu_has_reg(vm, VCPU_ID, KVM_REG_ARM_TIMER_OFFSET) && + !_vcpu_has_device_attr(vm, VCPU_ID, KVM_ARM_VCPU_TIMER_CTRL, + KVM_ARM_VCPU_TIMER_PHYS_OFFSET)) return; - print_skip("KVM_REG_ARM_TIMER_OFFSET not supported; skipping test"); + print_skip("KVM_REG_ARM_TIMER_OFFSET|KVM_ARM_VCPU_TIMER_PHYS_OFFSET not supported; skipping test"); exit(KSFT_SKIP); } static void setup_system_counter(struct kvm_vm *vm, struct test_case *test) { + uint64_t cntvoff, cntpoff; struct kvm_one_reg reg = { .id = KVM_REG_ARM_TIMER_OFFSET, - .addr = (__u64)&test->offset, + .addr = (__u64)&cntvoff, }; + if (test->counter == VIRTUAL) { + cntvoff = test->offset; + cntpoff = 0; + } else { + cntvoff = 0; + cntpoff = test->offset; + } + vcpu_set_reg(vm, VCPU_ID, ®); + vcpu_access_device_attr(vm, VCPU_ID, KVM_ARM_VCPU_TIMER_CTRL, + KVM_ARM_VCPU_TIMER_PHYS_OFFSET, &cntpoff, true); } static uint64_t guest_read_system_counter(struct test_case *test) { switch (test->counter) { case VIRTUAL: + case PHYSICAL_READ_VIRTUAL: return read_cntvct_ordered(); + case PHYSICAL: + return read_cntpct_ordered(); default: GUEST_ASSERT(0); }