From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] kvm/x86 : avoid shifting signed 32-bit value by 31 bits Date: Mon, 15 Oct 2018 19:23:18 +0200 Message-ID: <08fd066f-e6c5-f82c-544f-536e9f29e6f3@redhat.com> References: <201810080904344038939@zte.com.cn> <717c02f3-bb36-33c4-a463-f5759fde30fd@zytor.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: penghao122@sina.com.cn, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, joro@8bytes.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org To: "H. Peter Anvin" , peng.hao2@zte.com.cn, richard.weiyang@gmail.com Return-path: In-Reply-To: <717c02f3-bb36-33c4-a463-f5759fde30fd@zytor.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 15/10/2018 19:16, H. Peter Anvin wrote: > On 10/7/18 6:04 PM, peng.hao2@zte.com.cn wrote: > \>>>>> >>>>>> #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) >>>>>> -#define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) >>>>>> +#define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1UL << 31) >>>> >>>>> It is reasonable to change to unsigned, while not necessary to unsigned >>>>> long? >>>> AVIC_LOGICAL_ID_ENTRY_VALID_MASK is used in function avic_ldr_write. >>>> here I think it doesn't matter if you use unsigned or unsigned long. Do you have any suggestions? >> >>> In current case, AVIC_LOGICAL_ID_ENTRY_VALID_MASK is used to calculate >>> the value of new_entry with type of u32. So the definition here is not >>> harmful. >> >>> Also, I did a quick grep and found similar definition (1 << 31) is popular >>> in the whole kernel tree. >> >>> The reason to make this change is not that strong to me. Would you >>> minding sharing more reason behind this change? >> oh, I'm just thinking logically, not more reason. > > The right way to do this would be to use the _BITUL() (or _BITULL()) macro. Even for a value from a 32-bit register? That would be _BIT, which doesn't exist. Paolo