From patchwork Tue Sep 14 22:31:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12495063 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.1 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, 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 092EFC433EF for ; Tue, 14 Sep 2021 22:53:22 +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 C6D9D61155 for ; Tue, 14 Sep 2021 22:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C6D9D61155 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=sHrgPxkQl6qk86zNZvcTO+H2CtvUv3HHGU38Sz7Ozlk=; b=ueKMDyYO16ZmPd4VEOxf5kcmAf F1WS09/rERk1zD2MFkH+FRGGO5MooMsl9UfVy+1XacBwt+PW5ZY/7OZdfFgHgvWxGajE3nSBD8T/D COPGdFhOBG5fA6QmMDSY1SwuN6lRbZv8NSLCOAKjjM6OQCGQeHJWSSChme1Jl7mM1xkHhmPoFkxNX R5H4REwB51MMoM+RHCDWpyFB+GQf/tkQugjwbOyVwX5HA9Th4FMQa4wCFHi1+Az6IkfGNCcLlrzYD z7Od7TDUATU6mjeihn/IlXmWJBP+8GRvQecHqdrfKg2K3G7eUtlPxRDVLUY34nfcsK3d62bSqIS/6 HdexmdJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQHGt-007Wus-Kr; Tue, 14 Sep 2021 22:51:24 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQGxu-007PHF-9T for linux-arm-kernel@lists.infradead.org; Tue, 14 Sep 2021 22:31:47 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j4-20020a258b84000000b005a203c5e066so870338ybl.19 for ; Tue, 14 Sep 2021 15:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BW7fBGcKsdrR8mke56V7bzU7gD9WyqlXvKOO1bey3dM=; b=KKrMidevVqRU8tnCf4HU4OhnmV4gTubXrbIfa7ytYE6gg6NnqwIA73O/SeJOdKPaFS +aF6f8SR1NWh9ctn4JkR57SOSgLADPbjUTJXnTPMlWXteaQen7oI9433NcrMbrU9+6Vx IfOmq44ELPlXjNG5vZ8UGDbY8XrQNygpDmddOehD8XpaTdhS5CBvPXhFs97WUdE3mdlx +rlcewue0YSfqo1HwOKvI4mzWUA4vf5jcotMRA3l3ydvvLj8mozJhget75ThKDippFOI QQYqdf3SRHPJwf8tlda7NBau1BdAqms2EsS0QX+etXuBOJJaFOw6OK7Ykj4paUtyEafI le9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BW7fBGcKsdrR8mke56V7bzU7gD9WyqlXvKOO1bey3dM=; b=rd4PBsjPNfOHvyWQDDcIsij7MpRJejPf+MDrd3n6qmozNklglaI0C2tvTuEalw+cYU wPDAQiRri3V7rhjSHsBTbGvdD4YC58sjZGNdB2M+zK9sjiz47vUZl+iw2PGVYDfyqyNw YiRQpvUbHVJyR646OiOjjIk/aD4G2IIDwR2z01McCZUkYDfUVdwnbz8UTXmFJNBmE7OQ UdJyb77pWPuJ5I6WULzUmJBmQuvqCGy7lLvPm7LgJNA8dUXNMh0pHs97go0+QsNP3Lp0 lX1qp8TKj+i4BBRFLTVF9NJm26hVo/9iVeyMeEuTsIpU8iap93CYwPrWwHTiYyCvXPJl gS0w== X-Gm-Message-State: AOAM530G1muhRqHO4qDG4xvZtXt0Rc+advOEnBr58Ez+ny+dvWy3ctkc fZZG8uVyHbwkSeci0044CKv1T81s3qP6 X-Google-Smtp-Source: ABdhPJzPcqUzTM5tBKbzTFIOabctvphrNK79S1QDbS3uHmuEww5wKnVoFnhwbSzNggFM60aX3Wsu6DKNYmnL X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a25:5607:: with SMTP id k7mr2077562ybb.378.1631658704625; Tue, 14 Sep 2021 15:31:44 -0700 (PDT) Date: Tue, 14 Sep 2021 22:31:09 +0000 In-Reply-To: <20210914223114.435273-1-rananta@google.com> Message-Id: <20210914223114.435273-11-rananta@google.com> Mime-Version: 1.0 References: <20210914223114.435273-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v7 10/15] KVM: arm64: selftests: Add guest support to get the vcpuid From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210914_153146_389177_E56FEC77 X-CRM114-Status: GOOD ( 11.10 ) 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 At times, such as when in the interrupt handler, the guest wants to get the vcpuid that it's running on to pull the per-cpu private data. As a result, introduce guest_get_vcpuid() that returns the vcpuid of the calling vcpu. The interface is architecture independent, but defined only for arm64 as of now. Suggested-by: Reiji Watanabe Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Ricardo Koller Reviewed-by: Reiji Watanabe Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/include/kvm_util.h | 2 ++ tools/testing/selftests/kvm/lib/aarch64/processor.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 010b59b13917..bcf05f5381ed 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -400,4 +400,6 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc); int vm_get_stats_fd(struct kvm_vm *vm); int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid); +uint32_t guest_get_vcpuid(void); + #endif /* SELFTEST_KVM_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 34f6bd47661f..b4eeeafd2a70 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -277,6 +277,7 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_vcpu_init set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TCR_EL1), tcr_el1); set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_MAIR_EL1), DEFAULT_MAIR_EL1); set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TTBR0_EL1), vm->pgd); + set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TPIDR_EL1), vcpuid); } void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) @@ -426,3 +427,8 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector, assert(vector < VECTOR_NUM); handlers->exception_handlers[vector][0] = handler; } + +uint32_t guest_get_vcpuid(void) +{ + return read_sysreg(tpidr_el1); +}