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 40FCBECAA25 for ; Thu, 25 Aug 2022 16:59:39 +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=luuWH+WCoW6XgyPIoqKV8X82reOt124PLb6h+QYLYQw=; b=oXbkoyHpxrpPbM AUd6BIYLizqnVRz/ggf7FNcSHewL8kq5w1FQepi6fis9uSM8mxn+fJ5CgDFCVXJLFTldEo/HSAzyy 29Ri8r3WxjyvBgo35dp/1769JfSWtWj0mq2blQoxe8sbNK5yjKB9982aLrdXcNkLufxWKIP8/vdix 0jmwmAbrvVvVXAnQDcGIappJVd+K2UWy8QZGTma4N2GDn1AXLvTWw4G2NlOozrld5YwTvJPtPfcrl CHKIyHoALUJ8EMbwUEHRFj9w0kHzFYeFQYQSPq5KLbPgPxsKbDd42O4LNDRW6+fTvgHxPwW/agsrq XI7j4ZSv3Slp4wTitxow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRGBZ-00GYgA-07; Thu, 25 Aug 2022 16:58:29 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRGBV-00GYZg-IA for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2022 16:58:27 +0000 Date: Thu, 25 Aug 2022 09:58:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1661446701; 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=23LQr+BJhfVdQfv6GAKyN2WcdFY338AxJHz2RBNuoO0=; b=C/uCf0Lc2rScl/KZeL7T6K12Gtj0qfj9SX4MfVwAvFeXiaWQmHIFyOhv8HJqSOm4ZujbLX uYgcabc7AWWiuKfiCv2o0nSdiM208/HH9sQs89lXqq+blkCq1iAOabOfvxSJMLiPPpHfNA pHAz3AOn2NJyI9GHeCh4zAoYvcPK8sU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Ricardo Koller Cc: Reiji Watanabe , kvm@vger.kernel.org, Marc Zyngier , Andrew Jones , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, 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: 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_095825_899888_893B6E42 X-CRM114-Status: GOOD ( 25.51 ) 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, Aug 25, 2022 at 09:52:53AM -0700, Ricardo Koller wrote: > On Thu, Aug 25, 2022 at 09:48:35AM -0700, Oliver Upton wrote: > > 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. > > Was doing that with this commit: > > [PATCH v5 05/13] tools: Copy bitfield.h from the kernel sources > > Maybe you could just use it given that it's already reviewed. Oops, thanks for the reminder Ricardo! Yeah, let's go that route then. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel