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 04E71C432BE for ; Wed, 1 Sep 2021 23:48:25 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 6159761026 for ; Wed, 1 Sep 2021 23:48:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6159761026 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 CD5244B121; Wed, 1 Sep 2021 19:48:23 -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 RZ67Aes00N6U; Wed, 1 Sep 2021 19:48:19 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id EB3CB4B12F; Wed, 1 Sep 2021 19:48:19 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 18E754B12F for ; Wed, 1 Sep 2021 19:48:18 -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 GtBStdY+vgYJ for ; Wed, 1 Sep 2021 19:48:17 -0400 (EDT) Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 0F0464B121 for ; Wed, 1 Sep 2021 19:48:17 -0400 (EDT) Received: by mail-io1-f52.google.com with SMTP id q3so212685iot.3 for ; Wed, 01 Sep 2021 16:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=vLoV3R33YLTSXudj2GKqaz2xUKTo/hFMiYfsqG/Fz3dT8teBjlT7VODVk8heJfB0JT fUNhKoXkyn3UsIiwKTRMDEWo7nEJ4NVJX7SWhXurBTzziGFf2ls9a6cn6gBuqs85JPhL Rp6yb0/UPwD/9pIrcSxGX8Qao0EVoBbvygNditKUMfFrRMOS/rlbZX4YK+8UgVFlPyC7 ItJyQLXmGmJlVEtJZvW6h8rYhkecCGKg9JxHNAqiRr4ylYCbedpzjIyn1ijclBeZ8/g2 TSIs0i6xJo5sWN0UDJfjSFrTC/sFJ9wOkdQftASbkiEMOoRPLXLrGgaw4on2KvuSb7nI PX0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=pcgaaVvvcUrhJuCEqo3juzPffmKIyCuTlaG3fJtsIoQGqP6L/B1EyMjl7101sSLE90 WAevG/Ow1O3hDYtRQu06My0YzETXeAJBSDo+x0QmZGQ8r8gzNuvwxdi3Z7W+cu6I+JBP fir/B9Pi+Ew4oa+xaP4dddWbi6NCyd+6Bjx0xcg2BpZijXxh1AbPcK3TGUsdiZ2FhJeQ xvWkLMTlNXZTlJN56IXMTFpTZN84WMESiv4SqQVWWZL5PZtdbZKp9HdB5aFbUTfUSuG7 nDDEpIbKQzFGgHIF/iRSPxyq/hxYWBpiYuw8gl5xvaZVWoJzVetTlFuhlVeduLpdAW7S /00Q== X-Gm-Message-State: AOAM532StPVjRAJZAIbeY31QjukZSKPB8mYJiRNu010j1sOjry7qGACV vndhMabrW+HghGfkUNFP9YJYEw== X-Google-Smtp-Source: ABdhPJz6cpuNWJjH26XrDJUo+kRNx4ojf/ksC3gj1/vmgDdieL8PaiWXNPxQsuZSqgO4P3XxcpmNHA== X-Received: by 2002:a02:cc53:: with SMTP id i19mr379146jaq.124.1630540096213; Wed, 01 Sep 2021 16:48:16 -0700 (PDT) Received: from google.com (194.225.68.34.bc.googleusercontent.com. [34.68.225.194]) by smtp.gmail.com with ESMTPSA id k21sm38569ioh.38.2021.09.01.16.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 16:48:15 -0700 (PDT) Date: Wed, 1 Sep 2021 23:48:12 +0000 From: Oliver Upton To: Raghavendra Rao Ananta Subject: Re: [PATCH v3 07/12] KVM: arm64: selftests: Add support to get the vcpuid from MPIDR_EL1 Message-ID: References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-8-rananta@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210901211412.4171835-8-rananta@google.com> Cc: kvm@vger.kernel.org, Will Deacon , Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, Marc Zyngier , 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 Wed, Sep 01, 2021 at 09:14:07PM +0000, Raghavendra Rao Ananta wrote: > At times, such as when in the interrupt handler, the guest wants to > get the vCPU-id that it's running on. As a result, introduce > get_vcpuid() that parses the MPIDR_EL1 and returns the vcpuid to the > requested caller. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../selftests/kvm/include/aarch64/processor.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > index c35bb7b8e870..8b372cd427da 100644 > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > @@ -251,4 +251,23 @@ static inline void local_irq_disable(void) > asm volatile("msr daifset, #3" : : : "memory"); > } > > +#define MPIDR_LEVEL_BITS 8 > +#define MPIDR_LEVEL_SHIFT(level) (MPIDR_LEVEL_BITS * level) > +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) > +#define MPIDR_AFFINITY_LEVEL(mpidr, level) \ > + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) > + > +static inline uint32_t get_vcpuid(void) > +{ > + uint32_t vcpuid = 0; > + uint64_t mpidr = read_sysreg(mpidr_el1); > + > + /* KVM limits only 16 vCPUs at level 0 */ > + vcpuid = mpidr & 0x0f; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 1) << 4; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 2) << 12; > + > + return vcpuid; > +} Are we guaranteed that KVM will always compose vCPU IDs the same way? I do not believe this is guaranteed ABI. For the base case, you could pass the vCPU ID as an arg to the guest function. I do agree that finding the vCPU ID is a bit more challenging in an interrupt context. Maybe use a ucall to ask userspace? But of course, every test implements its own run loop, so its yet another case that tests need to handle. Or, you could allocate an array at runtime of length KVM_CAP_MAX_VCPUS (use the KVM_CHECK_EXTENSION ioctl to get the value). Once all vCPUs are instantiated, iterate over them from userspace to populate the {MPIDR, VCPU_ID} map. You'd need to guarantee that callers initialize the vGIC *after* adding vCPUs to the guest. -- Thanks, Oliver > #endif /* SELFTEST_KVM_PROCESSOR_H */ > -- > 2.33.0.153.gba50c8fa24-goog > _______________________________________________ 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 39620C432BE for ; Wed, 1 Sep 2021 23:50:48 +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 EA73F6023E for ; Wed, 1 Sep 2021 23:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA73F6023E 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pSyfn0N18TWaxMHY3ZmaD9nQG3h53qiOmbISrT/++bs=; b=uVUxsxHtLbRnLk hLR79wnaCxSNi5Zjm9j7BQfhu9yc/+KpJWfMIEbY+ApwgMdog4daWN58vVLvNCJeHsrsYA25BWhvM HAmxC3JSImRRwHb4W+Ur499PP9goa8tLtqluZe3GX+TDAxW9CU7DNL83e+kqiIhGxBdGw4LA3s8qv +7JTilxSrNkLh0w0AfXLQukUUcuV5ShfIqkVPVvvfYo2GSU8aJ1aGR9d2LXw2oSEpU68g9lE1COS5 vo1O6A5ZUBzBa5okQ1i9ajlOrdDfaI3Ohy8/jHRPk+ACJb785EJS9nlKjM+DaDG1/6QaX2GXVLpst IrhauTAl8p9SWcjGViYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLZxs-007tsI-So; Wed, 01 Sep 2021 23:48:21 +0000 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mLZxp-007tra-GL for linux-arm-kernel@lists.infradead.org; Wed, 01 Sep 2021 23:48:18 +0000 Received: by mail-io1-xd2b.google.com with SMTP id z1so198421ioh.7 for ; Wed, 01 Sep 2021 16:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=vLoV3R33YLTSXudj2GKqaz2xUKTo/hFMiYfsqG/Fz3dT8teBjlT7VODVk8heJfB0JT fUNhKoXkyn3UsIiwKTRMDEWo7nEJ4NVJX7SWhXurBTzziGFf2ls9a6cn6gBuqs85JPhL Rp6yb0/UPwD/9pIrcSxGX8Qao0EVoBbvygNditKUMfFrRMOS/rlbZX4YK+8UgVFlPyC7 ItJyQLXmGmJlVEtJZvW6h8rYhkecCGKg9JxHNAqiRr4ylYCbedpzjIyn1ijclBeZ8/g2 TSIs0i6xJo5sWN0UDJfjSFrTC/sFJ9wOkdQftASbkiEMOoRPLXLrGgaw4on2KvuSb7nI PX0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=mpziie+0g9fCi1Bg4Ly0MjrqVn+C2STg+AE/OK1mVTYF6Z69FcYnv1bhR8HE7EtBm2 RSTxToJiAa4AVNoFL+NZqXYR/MzbeB0mPVCs6oOfs2CtQGorPMaMEhKYPJt2O5yBDUlz XgO6JnUDS0+GI0BB6FQXDSMn5VMM122u6a40lDS2vOhk8VXvBzdRpRidebgvghgBD3+6 doRN0dHS08OhyOmGK25hkGF9CS6C3lxcJr+HCKtnOd3yjpUB63Zoq4AzlucSYBRyGy0z OLvnn/vPRrJ8Q51gZyxzRkPWHETgPik6pqbkuCwUj9+3ypRvPsEGJ6x/uXdN5TMnCA2g Qmrw== X-Gm-Message-State: AOAM530A1c7uJ1tGx/A1vTG99ro69tv0KoJ5EaDc9AkzgdVecKnEa3aI Fvop8Fp06UwaRkuy1XlavaeX/w== X-Google-Smtp-Source: ABdhPJz6cpuNWJjH26XrDJUo+kRNx4ojf/ksC3gj1/vmgDdieL8PaiWXNPxQsuZSqgO4P3XxcpmNHA== X-Received: by 2002:a02:cc53:: with SMTP id i19mr379146jaq.124.1630540096213; Wed, 01 Sep 2021 16:48:16 -0700 (PDT) Received: from google.com (194.225.68.34.bc.googleusercontent.com. [34.68.225.194]) by smtp.gmail.com with ESMTPSA id k21sm38569ioh.38.2021.09.01.16.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 16:48:15 -0700 (PDT) Date: Wed, 1 Sep 2021 23:48:12 +0000 From: Oliver Upton To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , 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 Subject: Re: [PATCH v3 07/12] KVM: arm64: selftests: Add support to get the vcpuid from MPIDR_EL1 Message-ID: References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-8-rananta@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210901211412.4171835-8-rananta@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210901_164817_613198_CCCBAADD X-CRM114-Status: GOOD ( 24.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: , 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 Wed, Sep 01, 2021 at 09:14:07PM +0000, Raghavendra Rao Ananta wrote: > At times, such as when in the interrupt handler, the guest wants to > get the vCPU-id that it's running on. As a result, introduce > get_vcpuid() that parses the MPIDR_EL1 and returns the vcpuid to the > requested caller. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../selftests/kvm/include/aarch64/processor.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > index c35bb7b8e870..8b372cd427da 100644 > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > @@ -251,4 +251,23 @@ static inline void local_irq_disable(void) > asm volatile("msr daifset, #3" : : : "memory"); > } > > +#define MPIDR_LEVEL_BITS 8 > +#define MPIDR_LEVEL_SHIFT(level) (MPIDR_LEVEL_BITS * level) > +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) > +#define MPIDR_AFFINITY_LEVEL(mpidr, level) \ > + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) > + > +static inline uint32_t get_vcpuid(void) > +{ > + uint32_t vcpuid = 0; > + uint64_t mpidr = read_sysreg(mpidr_el1); > + > + /* KVM limits only 16 vCPUs at level 0 */ > + vcpuid = mpidr & 0x0f; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 1) << 4; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 2) << 12; > + > + return vcpuid; > +} Are we guaranteed that KVM will always compose vCPU IDs the same way? I do not believe this is guaranteed ABI. For the base case, you could pass the vCPU ID as an arg to the guest function. I do agree that finding the vCPU ID is a bit more challenging in an interrupt context. Maybe use a ucall to ask userspace? But of course, every test implements its own run loop, so its yet another case that tests need to handle. Or, you could allocate an array at runtime of length KVM_CAP_MAX_VCPUS (use the KVM_CHECK_EXTENSION ioctl to get the value). Once all vCPUs are instantiated, iterate over them from userspace to populate the {MPIDR, VCPU_ID} map. You'd need to guarantee that callers initialize the vGIC *after* adding vCPUs to the guest. -- Thanks, Oliver > #endif /* SELFTEST_KVM_PROCESSOR_H */ > -- > 2.33.0.153.gba50c8fa24-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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=ham 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 249DAC432BE for ; Wed, 1 Sep 2021 23:48:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAAD261026 for ; Wed, 1 Sep 2021 23:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbhIAXtQ (ORCPT ); Wed, 1 Sep 2021 19:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242593AbhIAXtO (ORCPT ); Wed, 1 Sep 2021 19:49:14 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 337EFC061575 for ; Wed, 1 Sep 2021 16:48:17 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id b7so211891iob.4 for ; Wed, 01 Sep 2021 16:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=vLoV3R33YLTSXudj2GKqaz2xUKTo/hFMiYfsqG/Fz3dT8teBjlT7VODVk8heJfB0JT fUNhKoXkyn3UsIiwKTRMDEWo7nEJ4NVJX7SWhXurBTzziGFf2ls9a6cn6gBuqs85JPhL Rp6yb0/UPwD/9pIrcSxGX8Qao0EVoBbvygNditKUMfFrRMOS/rlbZX4YK+8UgVFlPyC7 ItJyQLXmGmJlVEtJZvW6h8rYhkecCGKg9JxHNAqiRr4ylYCbedpzjIyn1ijclBeZ8/g2 TSIs0i6xJo5sWN0UDJfjSFrTC/sFJ9wOkdQftASbkiEMOoRPLXLrGgaw4on2KvuSb7nI PX0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7QLaqmuMdndaoDUoQKfj9TVz0nnnEHxweKe5hvBPXD0=; b=OZuMx6nys9vl+kfBgFEzWQ0L069QXe2iPz4u5+QL63GZYeTt9yc3hyEMKzezrgT0ub oJ16jyB/q7WElZI6OfcSFF+x1p0wKvHVH2VQx1BL44PVTYkwQBjdhkJcGKgGh7UfDFS/ ZSFIW4fjcXgwqeusvnd+MpcEyL89kO5jCOs2TKeV6/4hvgBLDnJUIZbobqZjZiaS+c36 jjM2DGTrC42nhmCtvxe0BHh2dhDtbfXk2X2Q9Hxgpx0v4wPOS/HI5ULAvAo2HzXAbvvj FeYyINI0mYH4R2xkIXJ+1vvT4Or1p7zBlSqbTRNziOSU+NeSzQPgRtZNo7RLD9aPSw0n UmYg== X-Gm-Message-State: AOAM532bbYGQQsaZPQKs1A8mk+7LDHKJep+Hwa+tkfm7+mgOzk8Hsxzl lq33fYE/Zc/jxwdLLAJsWqvnBg== X-Google-Smtp-Source: ABdhPJz6cpuNWJjH26XrDJUo+kRNx4ojf/ksC3gj1/vmgDdieL8PaiWXNPxQsuZSqgO4P3XxcpmNHA== X-Received: by 2002:a02:cc53:: with SMTP id i19mr379146jaq.124.1630540096213; Wed, 01 Sep 2021 16:48:16 -0700 (PDT) Received: from google.com (194.225.68.34.bc.googleusercontent.com. [34.68.225.194]) by smtp.gmail.com with ESMTPSA id k21sm38569ioh.38.2021.09.01.16.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 16:48:15 -0700 (PDT) Date: Wed, 1 Sep 2021 23:48:12 +0000 From: Oliver Upton To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , 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 Subject: Re: [PATCH v3 07/12] KVM: arm64: selftests: Add support to get the vcpuid from MPIDR_EL1 Message-ID: References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-8-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210901211412.4171835-8-rananta@google.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Sep 01, 2021 at 09:14:07PM +0000, Raghavendra Rao Ananta wrote: > At times, such as when in the interrupt handler, the guest wants to > get the vCPU-id that it's running on. As a result, introduce > get_vcpuid() that parses the MPIDR_EL1 and returns the vcpuid to the > requested caller. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../selftests/kvm/include/aarch64/processor.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > index c35bb7b8e870..8b372cd427da 100644 > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > @@ -251,4 +251,23 @@ static inline void local_irq_disable(void) > asm volatile("msr daifset, #3" : : : "memory"); > } > > +#define MPIDR_LEVEL_BITS 8 > +#define MPIDR_LEVEL_SHIFT(level) (MPIDR_LEVEL_BITS * level) > +#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1) > +#define MPIDR_AFFINITY_LEVEL(mpidr, level) \ > + ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) > + > +static inline uint32_t get_vcpuid(void) > +{ > + uint32_t vcpuid = 0; > + uint64_t mpidr = read_sysreg(mpidr_el1); > + > + /* KVM limits only 16 vCPUs at level 0 */ > + vcpuid = mpidr & 0x0f; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 1) << 4; > + vcpuid |= MPIDR_AFFINITY_LEVEL(mpidr, 2) << 12; > + > + return vcpuid; > +} Are we guaranteed that KVM will always compose vCPU IDs the same way? I do not believe this is guaranteed ABI. For the base case, you could pass the vCPU ID as an arg to the guest function. I do agree that finding the vCPU ID is a bit more challenging in an interrupt context. Maybe use a ucall to ask userspace? But of course, every test implements its own run loop, so its yet another case that tests need to handle. Or, you could allocate an array at runtime of length KVM_CAP_MAX_VCPUS (use the KVM_CHECK_EXTENSION ioctl to get the value). Once all vCPUs are instantiated, iterate over them from userspace to populate the {MPIDR, VCPU_ID} map. You'd need to guarantee that callers initialize the vGIC *after* adding vCPUs to the guest. -- Thanks, Oliver > #endif /* SELFTEST_KVM_PROCESSOR_H */ > -- > 2.33.0.153.gba50c8fa24-goog >