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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 D7C1DC43460 for ; Thu, 22 Apr 2021 15:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5671613F5 for ; Thu, 22 Apr 2021 15:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237898AbhDVPMZ (ORCPT ); Thu, 22 Apr 2021 11:12:25 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:40234 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236975AbhDVPMX (ORCPT ); Thu, 22 Apr 2021 11:12:23 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lZaza-0004D1-SE; Thu, 22 Apr 2021 15:11:46 +0000 Subject: Re: [PATCH][next] KVM: x86: simplify zero'ing of entry->ebx To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , kvm@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210422141129.250525-1-colin.king@canonical.com> From: Colin Ian King Message-ID: Date: Thu, 22 Apr 2021 16:11:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/04/2021 16:07, Sean Christopherson wrote: > On Thu, Apr 22, 2021, Colin King wrote: >> From: Colin Ian King >> >> Currently entry->ebx is being zero'd by masking itself with zero. >> Simplify this by just assigning zero, cleans up static analysis >> warning. >> >> Addresses-Coverity: ("Bitwise-and with zero") >> Signed-off-by: Colin Ian King >> --- >> arch/x86/kvm/cpuid.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >> index 57744a5d1bc2..9bcc2ff4b232 100644 >> --- a/arch/x86/kvm/cpuid.c >> +++ b/arch/x86/kvm/cpuid.c >> @@ -851,7 +851,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) >> entry->eax &= SGX_ATTR_DEBUG | SGX_ATTR_MODE64BIT | >> SGX_ATTR_PROVISIONKEY | SGX_ATTR_EINITTOKENKEY | >> SGX_ATTR_KSS; >> - entry->ebx &= 0; >> + entry->ebx = 0; > > I 100% understand the code is funky, but using &= is intentional. ebx:eax holds > a 64-bit value that is a effectively a set of feature flags. While the upper > 32 bits are extremely unlikely to be used any time soon, if a feature comes > along then the correct behavior would be: > > entry->ebx &= SGX_ATTR_FANCY_NEW_FEATURE; > > While directly setting entry->ebx would be incorrect. The idea is to set up a > future developer for success so that they don't forget to add the "&". > > TL;DR: I'd prefer to keep this as is, even though it's rather ridiculous. OK, makes sense. Thanks for explaining. > >> break; >> /* Intel PT */ >> case 0x14: >> -- >> 2.30.2 >>