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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B3A7C64EC4 for ; Fri, 3 Mar 2023 05:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229748AbjCCFyP (ORCPT ); Fri, 3 Mar 2023 00:54:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjCCFyN (ORCPT ); Fri, 3 Mar 2023 00:54:13 -0500 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B7D1A649 for ; Thu, 2 Mar 2023 21:54:12 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id t4so972122ybg.11 for ; Thu, 02 Mar 2023 21:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677822851; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=i3He+bv3rDW0V3ny41kX0Dr7IEw0N5ROaGJRmfThagk=; b=pkAcftF0deNqcuhVJl/YwMCK8cZxYxhDgztZRQ63faIhw1olHdb6jroHQFPQL8tuaG LSWYDVFIq+4524BJdOAk+FsJghqzuxGSF/cK/3It0uJ+fHKlBE92LW5bEV8iBQImNxBQ w94oK4JbJr0kaTDUr43tcfokMLxcNIwQ/9w1JS75ZQvq/Sy9fGFtVcf6jzJYQT72OZE2 I6j6fUxtpQtFySRfCpHer/6Rqzn5CYGCTl9vb13w3zqIF8A7A1m1rTydS+R4QWxhmdbm afVDfCSjkceYnYCfrp+3U+y7fOOpVLL9zoQTLX8PgGlpZMOyVOso1Jk8lkokxKw8dHwJ //jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677822851; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i3He+bv3rDW0V3ny41kX0Dr7IEw0N5ROaGJRmfThagk=; b=WzJLZ/DZ1fpOeMFjgI2sVB6X+wbKrdW+3TPwT1p2PCNORZ7zI6J285twehFjTj3rVz w/x6Z/CS98jkqDvOcmPIdS8IhkejX4HDHdUe6pEJrcvp1S25mxj0HdKkVheYh/vecgZs Sr0In3w/pNw8sPyNIpmV1xYteJsoxggIyPedsU/A45aegYZ9M35qpcSLwPkqBeyBfhVA iIXKk7H9ZDO5Hyoj9uW8SaydZWVuyfHmz6sIGctFyJPOEqUmdw/XZCftyxmORt+g9k0A i/+be9VhqNS6HLh6B54IIH0P4Hp9D5FPxLNvhGXCMkCYcOx5joyGjCrk0mCHFQzIYQdy cdbg== X-Gm-Message-State: AO0yUKV/uebSsQnT2q5cb4NekEozA4Om25J5EagiVm0CmeSh8iC//hb2 a5MY0cvXYGWV4BKfHMk+xvGwh7NpANTP4R3hMs1AgQ== X-Google-Smtp-Source: AK7set/mXvJo2LRKEA1VZbdhiu7bdLsHIuFQ2iyJAYVS7KdwVWMwLUeyxkyg+UgWelh+593OLpYA0fPrfVFTZnchV+A= X-Received: by 2002:a05:6902:524:b0:9f2:a18c:90ed with SMTP id y4-20020a056902052400b009f2a18c90edmr239306ybs.10.1677822851166; Thu, 02 Mar 2023 21:54:11 -0800 (PST) MIME-Version: 1.0 References: <20230301133841.18007-1-wei.w.wang@intel.com> In-Reply-To: From: Mingwei Zhang Date: Thu, 2 Mar 2023 21:53:35 -0800 Message-ID: Subject: Re: [PATCH v1] KVM: allow KVM_BUG/KVM_BUG_ON to handle 64-bit cond To: "Wang, Wei W" Cc: David Matlack , "pbonzini@redhat.com" , "Christopherson,, Sean" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 2, 2023 at 5:50=E2=80=AFPM Wang, Wei W w= rote: > > On Friday, March 3, 2023 2:12 AM, Mingwei Zhang wrote: > > > On Thursday, March 2, 2023 12:55 PM, Mingwei Zhang wrote: > > > > I don't get it. Why bothering the type if we just do this? > > > > > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > > > index 4f26b244f6d0..10455253c6ea 100644 > > > > --- a/include/linux/kvm_host.h > > > > +++ b/include/linux/kvm_host.h > > > > @@ -848,7 +848,7 @@ static inline void kvm_vm_bugged(struct kvm > > > > *kvm) > > > > > > > > #define KVM_BUG(cond, kvm, fmt...) \ > > > > ({ \ > > > > - int __ret =3D (cond); \ > > > > + int __ret =3D !!(cond); \ > > > > > > This is essentially "bool __ret". No biggie to change it this way. > > > > !! will return an int, not a boolean, but it is used as a boolean. > > What's the point of defining it as an int when actually being used as a B= oolean? > Original returning of an 'int' is a bug in this sense. Either returning a= Boolean or > the same type (length) as cond is good way to me. What's the point of using an integer? I think we need to ask the original author. But I think one of the reasons might be convenience as the return value. I am not sure if we can return a boolean in the function. But it should be fine here since it is a macro. Anyway, returning an 'int' is not a bug. The bug is the casting from 'cond' to the integer that may lose information and this is what you have captured. > > > This is consistent with the original code which _is_ returning an integ= er. > > > > > But I'm inclined to retain the original intention to have the macro > > > return the value that was passed in: > > > typeof(cond) __ret =3D (cond); > > > > hmm, I think it is appropriate to retain the original type of 'cond' > > especially since it may also involve other arithmetic operations. But I= doubt it > > will be very useful. For instance, who is going to write this code? > > > > Maybe there is, maybe not. But it doesn=E2=80=99t hurt anything to leave = the > flexibility there using typeof(cond). As said, I'm also fine to use 'bool= ret', > but probably not 'int' for no good reason. Right, maybe or maybe not. But using typeof(cond) for the variable does not always provide benefits. For instance if the 'cond' is resolved as the 8-byte type like u64, we are wasting space at runtime. We could have used a shorter type. In addition, throwing this to the compiler creates complexity and sometimes bugs since the compiler could have different behaviors. So, I prefer not having typeof(cond) for KVM_BUG(). But if you have strong opinions using typeof, go ahead. Thanks. -Mingwei