From mboxrd@z Thu Jan 1 00:00:00 1970 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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 7D947C433FE for ; Thu, 9 Sep 2021 17:04:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 660E161104 for ; Thu, 9 Sep 2021 17:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240885AbhIIRFy (ORCPT ); Thu, 9 Sep 2021 13:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234524AbhIIRFx (ORCPT ); Thu, 9 Sep 2021 13:05:53 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06C5C061575 for ; Thu, 9 Sep 2021 10:04:43 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id t19so5002518lfe.13 for ; Thu, 09 Sep 2021 10:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=sBGGF2kG+kvjABV883GUjWQBbQ2wX1NxELksiUeFov5Sj5rAv40ysH20N7VQgc/5cg DGTsfaPG76W7jKp6lCHQGpeb3qMg1jfkETHtMBdCxdXh5c2gOBgpg89a3WqziPY/83MM Ot6A5TOx+m7J0m84VaOwWv6ZwAdoTewLWePlIxQIxd7apvaH1oIskbpkSd7PwYz6oOPl JUmIjLWW1pLO63L6urfiluhdEyGC/ZeSUrpEqVBHtbdPaNCTONO5mm9fPOt/IiiZwOBJ Lld0qL0BiHZq3hUIfIXyBjAJk7u3WMKgB/VkWdPuL7XN/co3wq76VPdvD4K2hf+3X2HV lCVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=l4vHsPfk6UbDCeEqzwTQF60fTutpi8ac8k/nuE3b+uj/HbAbKL1Xb1h4xqTO0UB5bX zxBlYCO2zFqzpuRhSC6wiB/mJmMlyYL0a7PLHLOGsLv0m1U/7N4wsaSvbOD/BfM4JY5U b4INaC3P1qykPaa2ujNJv2kU5FN7ZhbonDOS8elztzVbX8Ue8x6WZd9cyRlOxbUll4mv tEdM+8u6WrlRxD+vnXknUyqSVNcyHBEeOdoCF9dB3Iu3dlj33dXy23z6CXM9cIoShvLt JYSt+CxXXJfbqAcWVl0PulcbcFcn9B5+MwmNHneROGR7FeWjl+aDqggHdQRvb6/zEPx3 OpJg== X-Gm-Message-State: AOAM530z1hkkggY56HgAHzyf13jBSGlgQbL19oJX03FzWb2yxobbZVj0 n+/I1AxL8JnxyrEL6AxwWRREAuYZ4QhM0PoVrBLXWg== X-Google-Smtp-Source: ABdhPJzgsnReiX6zBBk7VBYxWyPOlu6Rnz6b1gSn1eWpE9n3+TwnrWeVYgZ5PlPI5XB3FPGSVGVg8crba8eh2NTMT9Y= X-Received: by 2002:a05:6512:114c:: with SMTP id m12mr700974lfg.150.1631207081580; Thu, 09 Sep 2021 10:04:41 -0700 (PDT) MIME-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> <20210909013818.1191270-10-rananta@google.com> In-Reply-To: From: Oliver Upton Date: Thu, 9 Sep 2021 13:04:30 -0400 Message-ID: Subject: Re: [PATCH v4 09/18] KVM: arm64: selftests: Add guest support to get the vcpuid To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 9, 2021 at 12:59 PM Raghavendra Rao Ananta wrote: > > On Wed, Sep 8, 2021 at 10:09 PM Oliver Upton wrote: > > > > On Thu, Sep 09, 2021 at 01:38:09AM +0000, Raghavendra Rao Ananta wrote: > > > At times, such as when in the interrupt handler, the guest wants > > > to get the vcpuid that it's running on. As a result, introduce > > > get_vcpuid() that returns the vcpuid of the calling vcpu. At its > > > backend, the VMM prepares a map of vcpuid and mpidr during VM > > > initialization and exports the map to the guest for it to read. > > > > > > Signed-off-by: Raghavendra Rao Ananta > > > --- > > > .../selftests/kvm/include/aarch64/processor.h | 3 ++ > > > .../selftests/kvm/lib/aarch64/processor.c | 46 +++++++++++++++++++ > > > 2 files changed, 49 insertions(+) > > > > > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > index b6088c3c67a3..150f63101f4c 100644 > > > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > > > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > @@ -133,6 +133,7 @@ void vm_install_exception_handler(struct kvm_vm *vm, > > > int vector, handler_fn handler); > > > void vm_install_sync_handler(struct kvm_vm *vm, > > > int vector, int ec, handler_fn handler); > > > +void vm_vcpuid_map_init(struct kvm_vm *vm); > > > > > > static inline void cpu_relax(void) > > > { > > > @@ -194,4 +195,6 @@ static inline void local_irq_disable(void) > > > asm volatile("msr daifset, #3" : : : "memory"); > > > } > > > > > > +int get_vcpuid(void); > > > + > > > > I believe both of these functions could use some documentation. The > > former has implicit ordering requirements (can only be called after all > > vCPUs are created) and the latter can only be used within a guest. > > > > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > index 632b74d6b3ca..9844b62227b1 100644 > > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > @@ -13,9 +13,17 @@ > > > #include "processor.h" > > > > > > #define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN 0xac0000 > > > +#define VM_VCPUID_MAP_INVAL -1 > > > > > > static vm_vaddr_t exception_handlers; > > > > > > +struct vm_vcpuid_map { > > > + uint64_t mpidr; > > > + int vcpuid; > > > +}; > > > + > > > +static struct vm_vcpuid_map vcpuid_map[KVM_MAX_VCPUS]; > > > + > > > > Hmm. > > > > I'm not too big of a fan that the KVM_MAX_VCPUS macro is defined in the > > KVM selftests. Really, userspace should discover the limit from the > > kernel. Especially when we want to write tests that test behavior at > > KVM's limit. > > > > That being said, there are more instances of these static allocations in > > the selftests code, so you aren't to be blamed. > > > > Related: commit 074c82c8f7cf ("kvm: x86: Increase MAX_VCPUS to 1024") > > has raised this limit. > > > I'm not a fan of static allocations either, but the fact that > sync_global_to_guest() doesn't have a size argument (yet), makes me > want to take a shorter route. Anyway, if you want I can allocate it > dynamically and copy it to the guest's memory by hand, or come up with > a utility wrapper while I'm at it. > (Just wanted to make sure we are not over-engineering our needs here). No, please don't worry about it in your series. I'm just openly whining is all :-) > > > static uint64_t page_align(struct kvm_vm *vm, uint64_t v) > > > { > > > return (v + vm->page_size) & ~(vm->page_size - 1); > > > @@ -426,3 +434,41 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector, > > > assert(vector < VECTOR_NUM); > > > handlers->exception_handlers[vector][0] = handler; > > > } > > > + > > > +void vm_vcpuid_map_init(struct kvm_vm *vm) > > > +{ > > > + int i = 0; > > > + struct vcpu *vcpu; > > > + struct vm_vcpuid_map *map; > > > + > > > + list_for_each_entry(vcpu, &vm->vcpus, list) { > > > + map = &vcpuid_map[i++]; > > > + map->vcpuid = vcpu->id; > > > + get_reg(vm, vcpu->id, > > > + ARM64_SYS_KVM_REG(SYS_MPIDR_EL1), &map->mpidr); > > > + map->mpidr &= MPIDR_HWID_BITMASK; > > > + } > > > + > > > + if (i < KVM_MAX_VCPUS) > > > + vcpuid_map[i].vcpuid = VM_VCPUID_MAP_INVAL; > > > + > > > + sync_global_to_guest(vm, vcpuid_map); > > > +} > > > + > > > +int get_vcpuid(void) > > > > nit: guest_get_vcpuid() > > > Sounds nice. Since we have a lot of guest utility functions now, I'm > fancying a world where we prefix guest_ with all of them to avoid > confusion. > Sounds good to me! -- Thanks, Oliver From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 B8C42C4332F for ; Thu, 9 Sep 2021 17:04:47 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 3826F61179 for ; Thu, 9 Sep 2021 17:04:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3826F61179 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BC6AC4B15B; Thu, 9 Sep 2021 13:04:46 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iB-BtIQPuo-v; Thu, 9 Sep 2021 13:04:45 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 5CFB24B173; Thu, 9 Sep 2021 13:04:45 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7B8694B11F for ; Thu, 9 Sep 2021 13:04:44 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WZ5Psg9YtE-Y for ; Thu, 9 Sep 2021 13:04:43 -0400 (EDT) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 362D54B15B for ; Thu, 9 Sep 2021 13:04:43 -0400 (EDT) Received: by mail-lf1-f45.google.com with SMTP id t19so5002521lfe.13 for ; Thu, 09 Sep 2021 10:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=sBGGF2kG+kvjABV883GUjWQBbQ2wX1NxELksiUeFov5Sj5rAv40ysH20N7VQgc/5cg DGTsfaPG76W7jKp6lCHQGpeb3qMg1jfkETHtMBdCxdXh5c2gOBgpg89a3WqziPY/83MM Ot6A5TOx+m7J0m84VaOwWv6ZwAdoTewLWePlIxQIxd7apvaH1oIskbpkSd7PwYz6oOPl JUmIjLWW1pLO63L6urfiluhdEyGC/ZeSUrpEqVBHtbdPaNCTONO5mm9fPOt/IiiZwOBJ Lld0qL0BiHZq3hUIfIXyBjAJk7u3WMKgB/VkWdPuL7XN/co3wq76VPdvD4K2hf+3X2HV lCVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=ZgjqZEDG2NtmViQqYFBFoYhvzZjHGzjK9W4evmtgZGdHwcUYM4LiwHBNihqy7FOBpo 4Qm8NqYJqBxegVeg+y+qMBUzzc6aXgqWANOh9IFV2+6rGHtE3kpZFyMoaT0vbFUJgY0u pm7rphCbsm8sV/xwUO0t8y1hP7SIvufJQMziLYRnj4WKcskaVHDxboZQ5XgDN4gtPvEu 32n4M8N1na1UzAzsRnuEjX8is5lTotPF+PghSr/Qc2qH+YCmjKyN0IFp02ziGMnW0E9H OVk9K4YZXNzwAr2Kb2h5USZVoovlA2CG821RTXnrPq2/Sw1EbcmT8nuSv0dBGpT2d1C8 yOSA== X-Gm-Message-State: AOAM531HWXmtitqpI2l6m723A1k6BB/BM+PFFHsh8jtjvkewBALiwgVO loDee1l+bjr4iPKaI0DO8dBvv4pgj5ojklfJjHXnkQ== X-Google-Smtp-Source: ABdhPJzgsnReiX6zBBk7VBYxWyPOlu6Rnz6b1gSn1eWpE9n3+TwnrWeVYgZ5PlPI5XB3FPGSVGVg8crba8eh2NTMT9Y= X-Received: by 2002:a05:6512:114c:: with SMTP id m12mr700974lfg.150.1631207081580; Thu, 09 Sep 2021 10:04:41 -0700 (PDT) MIME-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> <20210909013818.1191270-10-rananta@google.com> In-Reply-To: From: Oliver Upton Date: Thu, 9 Sep 2021 13:04:30 -0400 Message-ID: Subject: Re: [PATCH v4 09/18] KVM: arm64: selftests: Add guest support to get the vcpuid To: Raghavendra Rao Ananta Cc: kvm@vger.kernel.org, Will Deacon , Marc Zyngier , Peter Shier , linux-kernel@vger.kernel.org, Catalin Marinas , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Thu, Sep 9, 2021 at 12:59 PM Raghavendra Rao Ananta wrote: > > On Wed, Sep 8, 2021 at 10:09 PM Oliver Upton wrote: > > > > On Thu, Sep 09, 2021 at 01:38:09AM +0000, Raghavendra Rao Ananta wrote: > > > At times, such as when in the interrupt handler, the guest wants > > > to get the vcpuid that it's running on. As a result, introduce > > > get_vcpuid() that returns the vcpuid of the calling vcpu. At its > > > backend, the VMM prepares a map of vcpuid and mpidr during VM > > > initialization and exports the map to the guest for it to read. > > > > > > Signed-off-by: Raghavendra Rao Ananta > > > --- > > > .../selftests/kvm/include/aarch64/processor.h | 3 ++ > > > .../selftests/kvm/lib/aarch64/processor.c | 46 +++++++++++++++++++ > > > 2 files changed, 49 insertions(+) > > > > > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > index b6088c3c67a3..150f63101f4c 100644 > > > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > > > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > @@ -133,6 +133,7 @@ void vm_install_exception_handler(struct kvm_vm *vm, > > > int vector, handler_fn handler); > > > void vm_install_sync_handler(struct kvm_vm *vm, > > > int vector, int ec, handler_fn handler); > > > +void vm_vcpuid_map_init(struct kvm_vm *vm); > > > > > > static inline void cpu_relax(void) > > > { > > > @@ -194,4 +195,6 @@ static inline void local_irq_disable(void) > > > asm volatile("msr daifset, #3" : : : "memory"); > > > } > > > > > > +int get_vcpuid(void); > > > + > > > > I believe both of these functions could use some documentation. The > > former has implicit ordering requirements (can only be called after all > > vCPUs are created) and the latter can only be used within a guest. > > > > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > index 632b74d6b3ca..9844b62227b1 100644 > > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > @@ -13,9 +13,17 @@ > > > #include "processor.h" > > > > > > #define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN 0xac0000 > > > +#define VM_VCPUID_MAP_INVAL -1 > > > > > > static vm_vaddr_t exception_handlers; > > > > > > +struct vm_vcpuid_map { > > > + uint64_t mpidr; > > > + int vcpuid; > > > +}; > > > + > > > +static struct vm_vcpuid_map vcpuid_map[KVM_MAX_VCPUS]; > > > + > > > > Hmm. > > > > I'm not too big of a fan that the KVM_MAX_VCPUS macro is defined in the > > KVM selftests. Really, userspace should discover the limit from the > > kernel. Especially when we want to write tests that test behavior at > > KVM's limit. > > > > That being said, there are more instances of these static allocations in > > the selftests code, so you aren't to be blamed. > > > > Related: commit 074c82c8f7cf ("kvm: x86: Increase MAX_VCPUS to 1024") > > has raised this limit. > > > I'm not a fan of static allocations either, but the fact that > sync_global_to_guest() doesn't have a size argument (yet), makes me > want to take a shorter route. Anyway, if you want I can allocate it > dynamically and copy it to the guest's memory by hand, or come up with > a utility wrapper while I'm at it. > (Just wanted to make sure we are not over-engineering our needs here). No, please don't worry about it in your series. I'm just openly whining is all :-) > > > static uint64_t page_align(struct kvm_vm *vm, uint64_t v) > > > { > > > return (v + vm->page_size) & ~(vm->page_size - 1); > > > @@ -426,3 +434,41 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector, > > > assert(vector < VECTOR_NUM); > > > handlers->exception_handlers[vector][0] = handler; > > > } > > > + > > > +void vm_vcpuid_map_init(struct kvm_vm *vm) > > > +{ > > > + int i = 0; > > > + struct vcpu *vcpu; > > > + struct vm_vcpuid_map *map; > > > + > > > + list_for_each_entry(vcpu, &vm->vcpus, list) { > > > + map = &vcpuid_map[i++]; > > > + map->vcpuid = vcpu->id; > > > + get_reg(vm, vcpu->id, > > > + ARM64_SYS_KVM_REG(SYS_MPIDR_EL1), &map->mpidr); > > > + map->mpidr &= MPIDR_HWID_BITMASK; > > > + } > > > + > > > + if (i < KVM_MAX_VCPUS) > > > + vcpuid_map[i].vcpuid = VM_VCPUID_MAP_INVAL; > > > + > > > + sync_global_to_guest(vm, vcpuid_map); > > > +} > > > + > > > +int get_vcpuid(void) > > > > nit: guest_get_vcpuid() > > > Sounds nice. Since we have a lot of guest utility functions now, I'm > fancying a world where we prefix guest_ with all of them to avoid > confusion. > Sounds good to me! -- Thanks, Oliver _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.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, URIBL_BLOCKED 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 121A5C433EF for ; Thu, 9 Sep 2021 17:06:46 +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 CA2A1604D1 for ; Thu, 9 Sep 2021 17:06:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CA2A1604D1 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:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=84QchNSdUXvJbSjeIF9Tq9yMHh8OmLoi90lKVbsaRn8=; b=coDRwitBaY0tK1 f3nVlUOD559n23p7gvKUBPZ+T/U0Wtv3gZSJpclhrGbxO3VrTxH9FqjG0HX1FFK4WaM2RkKqTEN1C r0yieXoucP/9s/STq5QesMj9KVVApLLFcEBAW/HyKo4SwF7s+dUOl8FABvwH1mi52jpCPDfSk8u/U uCkjtvjYVJ56O6YJt9mXQvil/KbbyBzbRbf7l8+mINKvqGb2yN2qkwleZlRghBkoUIIkHmEDp6wXt TFUm5litdPtZj3xl5Qx0niXd0TFtOlOmuXF5m5F+AtTwhqWW3AldaRfWr3kwJJVk2FnAbv9wOrzSf ECCw3xTP9biPNbjQUi0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mONTj-00AT6w-QQ; Thu, 09 Sep 2021 17:04:47 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mONTf-00AT6K-NR for linux-arm-kernel@lists.infradead.org; Thu, 09 Sep 2021 17:04:45 +0000 Received: by mail-lf1-x12e.google.com with SMTP id l11so5071898lfe.1 for ; Thu, 09 Sep 2021 10:04:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=sBGGF2kG+kvjABV883GUjWQBbQ2wX1NxELksiUeFov5Sj5rAv40ysH20N7VQgc/5cg DGTsfaPG76W7jKp6lCHQGpeb3qMg1jfkETHtMBdCxdXh5c2gOBgpg89a3WqziPY/83MM Ot6A5TOx+m7J0m84VaOwWv6ZwAdoTewLWePlIxQIxd7apvaH1oIskbpkSd7PwYz6oOPl JUmIjLWW1pLO63L6urfiluhdEyGC/ZeSUrpEqVBHtbdPaNCTONO5mm9fPOt/IiiZwOBJ Lld0qL0BiHZq3hUIfIXyBjAJk7u3WMKgB/VkWdPuL7XN/co3wq76VPdvD4K2hf+3X2HV lCVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ElUi2zLG+FPdz2UbE6Ray8TiRA1vza4HIfAFJ/kfzDA=; b=JFKdnoIgjI6x1Y5nRP5F9RpGogP9q6XokxeEXij9KOnbY78xBbojug8Rig8VoCbXnK 2JLmNz1y7zNAWb39D8y2744azOY3GIH4udnJja4JVaNikrgDfr2RN9YR9Ni5Quc7WVKY P1VOuNLADS0jD9860nCXKQRDRZFYLN+8E85zTe3s3DGIkCajg39E3iTzU468MwQVSh8h 5/cC3fALZXn2s72zJgUIlEChbpQKC4vACy89sgZmyWOKsSv+x4QvHRx3SSY80IdbCpC9 gT4sYo6WSACAPtM5QwkfEpQKzjKYHsi6mWmFXAiefbgH+Z89cS7rD/aMGVO6IhSBnC3r UmUw== X-Gm-Message-State: AOAM532M1Gp95AvwM/LVztD4rbXxdXkEWonbJk1AA0ATrQS0hGDcnmf3 15fF1BWS6+ZUmubTIuWYS5BZlmmDIaXb8p6I2Hl/7A== X-Google-Smtp-Source: ABdhPJzgsnReiX6zBBk7VBYxWyPOlu6Rnz6b1gSn1eWpE9n3+TwnrWeVYgZ5PlPI5XB3FPGSVGVg8crba8eh2NTMT9Y= X-Received: by 2002:a05:6512:114c:: with SMTP id m12mr700974lfg.150.1631207081580; Thu, 09 Sep 2021 10:04:41 -0700 (PDT) MIME-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> <20210909013818.1191270-10-rananta@google.com> In-Reply-To: From: Oliver Upton Date: Thu, 9 Sep 2021 13:04:30 -0400 Message-ID: Subject: Re: [PATCH v4 09/18] KVM: arm64: selftests: Add guest support to get the vcpuid To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Reiji Watanabe , Jing Zhang , 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-20210909_100443_826588_53F3B832 X-CRM114-Status: GOOD ( 36.83 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 9, 2021 at 12:59 PM Raghavendra Rao Ananta wrote: > > On Wed, Sep 8, 2021 at 10:09 PM Oliver Upton wrote: > > > > On Thu, Sep 09, 2021 at 01:38:09AM +0000, Raghavendra Rao Ananta wrote: > > > At times, such as when in the interrupt handler, the guest wants > > > to get the vcpuid that it's running on. As a result, introduce > > > get_vcpuid() that returns the vcpuid of the calling vcpu. At its > > > backend, the VMM prepares a map of vcpuid and mpidr during VM > > > initialization and exports the map to the guest for it to read. > > > > > > Signed-off-by: Raghavendra Rao Ananta > > > --- > > > .../selftests/kvm/include/aarch64/processor.h | 3 ++ > > > .../selftests/kvm/lib/aarch64/processor.c | 46 +++++++++++++++++++ > > > 2 files changed, 49 insertions(+) > > > > > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > index b6088c3c67a3..150f63101f4c 100644 > > > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > > > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > @@ -133,6 +133,7 @@ void vm_install_exception_handler(struct kvm_vm *vm, > > > int vector, handler_fn handler); > > > void vm_install_sync_handler(struct kvm_vm *vm, > > > int vector, int ec, handler_fn handler); > > > +void vm_vcpuid_map_init(struct kvm_vm *vm); > > > > > > static inline void cpu_relax(void) > > > { > > > @@ -194,4 +195,6 @@ static inline void local_irq_disable(void) > > > asm volatile("msr daifset, #3" : : : "memory"); > > > } > > > > > > +int get_vcpuid(void); > > > + > > > > I believe both of these functions could use some documentation. The > > former has implicit ordering requirements (can only be called after all > > vCPUs are created) and the latter can only be used within a guest. > > > > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > index 632b74d6b3ca..9844b62227b1 100644 > > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > @@ -13,9 +13,17 @@ > > > #include "processor.h" > > > > > > #define DEFAULT_ARM64_GUEST_STACK_VADDR_MIN 0xac0000 > > > +#define VM_VCPUID_MAP_INVAL -1 > > > > > > static vm_vaddr_t exception_handlers; > > > > > > +struct vm_vcpuid_map { > > > + uint64_t mpidr; > > > + int vcpuid; > > > +}; > > > + > > > +static struct vm_vcpuid_map vcpuid_map[KVM_MAX_VCPUS]; > > > + > > > > Hmm. > > > > I'm not too big of a fan that the KVM_MAX_VCPUS macro is defined in the > > KVM selftests. Really, userspace should discover the limit from the > > kernel. Especially when we want to write tests that test behavior at > > KVM's limit. > > > > That being said, there are more instances of these static allocations in > > the selftests code, so you aren't to be blamed. > > > > Related: commit 074c82c8f7cf ("kvm: x86: Increase MAX_VCPUS to 1024") > > has raised this limit. > > > I'm not a fan of static allocations either, but the fact that > sync_global_to_guest() doesn't have a size argument (yet), makes me > want to take a shorter route. Anyway, if you want I can allocate it > dynamically and copy it to the guest's memory by hand, or come up with > a utility wrapper while I'm at it. > (Just wanted to make sure we are not over-engineering our needs here). No, please don't worry about it in your series. I'm just openly whining is all :-) > > > static uint64_t page_align(struct kvm_vm *vm, uint64_t v) > > > { > > > return (v + vm->page_size) & ~(vm->page_size - 1); > > > @@ -426,3 +434,41 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector, > > > assert(vector < VECTOR_NUM); > > > handlers->exception_handlers[vector][0] = handler; > > > } > > > + > > > +void vm_vcpuid_map_init(struct kvm_vm *vm) > > > +{ > > > + int i = 0; > > > + struct vcpu *vcpu; > > > + struct vm_vcpuid_map *map; > > > + > > > + list_for_each_entry(vcpu, &vm->vcpus, list) { > > > + map = &vcpuid_map[i++]; > > > + map->vcpuid = vcpu->id; > > > + get_reg(vm, vcpu->id, > > > + ARM64_SYS_KVM_REG(SYS_MPIDR_EL1), &map->mpidr); > > > + map->mpidr &= MPIDR_HWID_BITMASK; > > > + } > > > + > > > + if (i < KVM_MAX_VCPUS) > > > + vcpuid_map[i].vcpuid = VM_VCPUID_MAP_INVAL; > > > + > > > + sync_global_to_guest(vm, vcpuid_map); > > > +} > > > + > > > +int get_vcpuid(void) > > > > nit: guest_get_vcpuid() > > > Sounds nice. Since we have a lot of guest utility functions now, I'm > fancying a world where we prefix guest_ with all of them to avoid > confusion. > Sounds good to me! -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel