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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 94CD4C43603 for ; Wed, 11 Dec 2019 15:21:01 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 264B42465B for ; Wed, 11 Dec 2019 15:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 264B42465B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id AEFD04AEB2; Wed, 11 Dec 2019 10:20:59 -0500 (EST) 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 7PQqsmZHWUea; Wed, 11 Dec 2019 10:20:58 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A2FA34ACEE; Wed, 11 Dec 2019 10:20:58 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id AC8EE4ACEE for ; Wed, 11 Dec 2019 10:20:56 -0500 (EST) 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 yO9TW5q+xtLZ for ; Wed, 11 Dec 2019 10:20:55 -0500 (EST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 743184AC84 for ; Wed, 11 Dec 2019 10:20:55 -0500 (EST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CCBB730E; Wed, 11 Dec 2019 07:20:54 -0800 (PST) Received: from [10.1.197.1] (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6E3D3F52E; Wed, 11 Dec 2019 07:20:53 -0800 (PST) Subject: Re: [PATCH v2 1/3] arm64: cpufeature: Extract capped fields To: Andrew Murray , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland References: <20191210120146.2942-1-andrew.murray@arm.com> <20191210120146.2942-2-andrew.murray@arm.com> From: Suzuki Kuruppassery Poulose Message-ID: Date: Wed, 11 Dec 2019 15:20:52 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191210120146.2942-2-andrew.murray@arm.com> Content-Language: en-US Cc: 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Andrew, On 10/12/2019 12:01, Andrew Murray wrote: > When emulating ID registers there is often a need to cap the version > bits of a feature such that the guest will not use features that do > not yet exist. > > Let's add a helper that extracts a field and caps the version to a > given value. > > Signed-off-by: Andrew Murray > --- > arch/arm64/include/asm/cpufeature.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 4261d55e8506..19f051ec1610 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -447,6 +447,21 @@ cpuid_feature_extract_unsigned_field(u64 features, int field) > return cpuid_feature_extract_unsigned_field_width(features, field, 4); > } > > +static inline u64 __attribute_const__ > +cpuid_feature_cap_signed_field_width(u64 features, int field, int width, > + s64 cap) > +{ > + s64 val = cpuid_feature_extract_signed_field_width(features, field, > + width); > + > + if (val > cap) { > + features &= ~GENMASK_ULL(field + width - 1, field); > + features |= cap << field; Please could we make sure that the "cap" is masked to "width" bits. Otherwise looks good to me. Suzuki _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm