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 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 EE3B5ECAA24 for ; Thu, 25 Aug 2022 16:50:11 +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: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=+gUXLuaJgD4MZHfaAqUa/BXAbY0dEomyH9k17RsrXUM=; b=brqXkC1+2lWjSw NrAwZ4R38Qbl9LLnsx4L0DLDUgj/sVgRXKSsFG+y/54iYeY4GClHVPwbQX4ZT2SaJuOkZObvLZAWj C+d2F5X+P4GLjleHSJIl/YSH7r6hbjEvQc2RmcmARaGX1H6BRQSmcNN0VJTJm97y5M8VOBgUXMDMa 0i+aukjuX6p7Lhov35cJv72BwuTYKcGthQEAYHJqwi6YAJi4mLKEWOt3Iq1am8hl9ROWadE9Gc0Ql NuCsa3R409/dH0J2nEqv1BAF6qtQRm1xb8LtDxsB+D5h4C8kQj73DH9uQnlMrN40rfahjBfRNQTBb RocnOgwtXOBwXbmRoZOw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRG2P-00GPhH-Aw; Thu, 25 Aug 2022 16:49:01 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRG2L-00GPYH-W2 for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 16:48:59 +0000 Date: Thu, 25 Aug 2022 09:48:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1661446128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O55Usr66A7V9l1jjtJXC2418I7L6XcDR17b2fP/LeV8=; b=RWt+g44/T7Kp2wGu4/ODtzLHwl5J2VponJSj4snIACnF6961LlO6/FqMTLLeKZ5i8pXgkP JG8COFmBFhlxryApELZ0rw/dQ6SuiPVpUC7IfxETtgmTJDjF1vSd0nKQewgAW/dAmNKuE+ 7TQYRvTi2ZFt8n5VqZ3BjO/D5fLTYZQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Reiji Watanabe Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Andrew Jones , Paolo Bonzini , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 1/9] KVM: arm64: selftests: Add helpers to extract a field of an ID register Message-ID: References: <20220825050846.3418868-1-reijiw@google.com> <20220825050846.3418868-2-reijiw@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220825050846.3418868-2-reijiw@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220825_094858_496432_71E1C2C6 X-CRM114-Status: GOOD ( 17.24 ) 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 Hi Reiji, On Wed, Aug 24, 2022 at 10:08:38PM -0700, Reiji Watanabe wrote: > Introduce helpers to extract a field of an ID register. > Subsequent patches will use those helpers. > > Signed-off-by: Reiji Watanabe > --- > .../selftests/kvm/include/aarch64/processor.h | 2 ++ > .../testing/selftests/kvm/lib/aarch64/processor.c | 15 +++++++++++++++ > 2 files changed, 17 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > index a8124f9dd68a..a9b4b4e0e592 100644 > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > @@ -193,4 +193,6 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, > > uint32_t guest_get_vcpuid(void); > > +int cpuid_get_sfield(uint64_t val, int field_shift); > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift); > #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 6f5551368944..0b2ad46e7ff5 100644 > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > @@ -528,3 +528,18 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, > [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) > : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); > } > + > +/* Helpers to get a signed/unsigned feature field from ID register value */ > +int cpuid_get_sfield(uint64_t val, int field_shift) > +{ > + int width = 4; > + > + return (int64_t)(val << (64 - width - field_shift)) >> (64 - width); > +} I don't believe this helper is ever used. > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift) > +{ > + int width = 4; > + > + return (uint64_t)(val << (64 - width - field_shift)) >> (64 - width); > +} I would recommend not open-coding this and instead make use of ARM64_FEATURE_MASK(). You could pull in linux/bitfield.h to tools, or do something like this: #define ARM64_FEATURE_GET(ftr, val) \ ((ARM64_FEATURE_MASK(ftr) & val) >> ftr##_SHIFT) Slight preference for FIELD_{GET,SET}() as it matches the field extraction in the kernel as well. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel