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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 48069C282DD for ; Thu, 9 Jan 2020 14:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23E902067D for ; Thu, 9 Jan 2020 14:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731558AbgAIONx convert rfc822-to-8bit (ORCPT ); Thu, 9 Jan 2020 09:13:53 -0500 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:48156 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729642AbgAIONw (ORCPT ); Thu, 9 Jan 2020 09:13:52 -0500 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-175-aevZXyfFPaql_ZCdCCrlLw-1; Thu, 09 Jan 2020 14:13:49 +0000 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 9 Jan 2020 14:13:48 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Thu, 9 Jan 2020 14:13:48 +0000 From: David Laight To: 'Sean Christopherson' , Paolo Bonzini CC: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] KVM: x86/mmu: Fix a benign Bitwise vs. Logical OR mixup Thread-Topic: [PATCH] KVM: x86/mmu: Fix a benign Bitwise vs. Logical OR mixup Thread-Index: AQHVxbk8+XHUyW1VS0SOYvyU0+7JlafiXjig Date: Thu, 9 Jan 2020 14:13:48 +0000 Message-ID: References: <20200108001859.25254-1-sean.j.christopherson@intel.com> In-Reply-To: <20200108001859.25254-1-sean.j.christopherson@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-MC-Unique: aevZXyfFPaql_ZCdCCrlLw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson > Sent: 08 January 2020 00:19 > > Use a Logical OR in __is_rsvd_bits_set() to combine the two reserved bit > checks, which are obviously intended to be logical statements. Switching > to a Logical OR is functionally a nop, but allows the compiler to better > optimize the checks. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/mmu/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 7269130ea5e2..72e845709027 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3970,7 +3970,7 @@ __is_rsvd_bits_set(struct rsvd_bits_validate *rsvd_check, u64 pte, int level) > { > int bit7 = (pte >> 7) & 1, low6 = pte & 0x3f; > > - return (pte & rsvd_check->rsvd_bits_mask[bit7][level-1]) | > + return (pte & rsvd_check->rsvd_bits_mask[bit7][level-1]) || > ((rsvd_check->bad_mt_xwr & (1ull << low6)) != 0); Are you sure this isn't deliberate? The best code almost certainly comes from also removing the '!= 0'. You also don't want to convert the expression result to zero. So: return (pte & rsvd_check->rsvd_bits_mask[bit7][level-1]) | (rsvd_check->bad_mt_xwr & (1ull << low6)); The code then doesn't have any branches to get mispredicted. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)