From patchwork Wed Mar 1 13:38:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 62899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3636601wrd; Wed, 1 Mar 2023 05:40:58 -0800 (PST) X-Google-Smtp-Source: AK7set8sY9BwR8Ngepd/qWK7EgP2N8c6moQOzcHmRdtTGCdmAFQ5lwVFox3jOEBkbefu9gY65go1 X-Received: by 2002:aa7:c845:0:b0:4af:69b8:52af with SMTP id g5-20020aa7c845000000b004af69b852afmr6880619edt.24.1677678058707; Wed, 01 Mar 2023 05:40:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677678058; cv=none; d=google.com; s=arc-20160816; b=QGnnGOMUYVXW4XRAVcLLGZPUhR955UsckeW76CPW19KegMZVO+zEC/2TnHigfVnfss 7/KhBHgnuOSuGo0Kjt8eTh34Z/pbjeA3IuR5TVB2U6WBYDDPuKFPqkW7uBcpljYIRYGs snNAciE/783pnn+OEnJ0Kk38L7o169J9R5l69mtJtcrR+ki0MiAuQxGaIivmRXkUI/wJ 3XCtY71eQ32TxBJ4dwIIvTSnziSDAisg4dFO2/H4j/cfLW/kYi5tY0oAuzr7/DKIg+GU zUuG02ObUDX/vdkCSrze9+CALahLizCB31GLP6Hv3XPl7/cmOeb31gkvhj1jJyYrtPtv HUww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=S2th+EEwZmf24cJmVjgHkkPOpgwxYAnAsOIFQu1AYzM=; b=rqcjWtY6PK0qcklSmplXwXExJQgyTkYCMUlqlqahm2Ydtvg/I9+JHtTMrzb0BupUVW 4hcZ77K9PRMiUZzsxnnBREWJ6CvJavYYe7V486oCX4VHZQBo2tJLjYtBejwwUTQylvWn 1H23wfAjWbGSfE5/LIMhQ3Dq6yjin+t6UDLkt62anTzBEqpapR4QMep9VXKg1Pw2rR2N oetqX86bNbY726l91QDr64pGynX0uMDRWdanT/0W4VmgcFm3mQiL2BpPcgSwbHncd+u8 ATrmMPM2ypElgDGgR9Jm5XZ92dV5xaA/C3U+L9eyWVqqMjqPwuTfRl97Lm45ikJYlfVx d8ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ADTuM2wB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a1709063fc200b008e496c408aesi4528673ejj.709.2023.03.01.05.40.35; Wed, 01 Mar 2023 05:40:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ADTuM2wB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjCANiu (ORCPT + 99 others); Wed, 1 Mar 2023 08:38:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjCANis (ORCPT ); Wed, 1 Mar 2023 08:38:48 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5BC63C3C; Wed, 1 Mar 2023 05:38:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677677926; x=1709213926; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=0ya9OVlQeRmAihszF7JDK54S+/9aNnOM4bPs8NX4tO8=; b=ADTuM2wBUAYJk7VuWVV4b5NMxEB2Hca8XfHpxB/4Ag1ncPt9RGDPCjIg NY6w3VSV9DRiwspDNa6FGnd1SSCIBZ4/n3okZIet3hVV57Q/Zi/Ra0iz8 tGaPjauRAt240MWGouQcaMOeX5YW9GZuKAN02yzJrPbL9r0XKIraYw49O eOhjLfvbnIw6+GoSUmYRR7ZpTjC/UhMGB3svzjZTsOCwOBeXkDFxwL+zW b8jFMLGN0cZ5e41qYOwtRL1xB4yyasF+hWMo6Vjp0Ayws52ttdRFqAF6c VMIerKVySwQgITl840nU0sPwioHZ2qZ0bL4Ki5wYoVExnQs+MmNb6ncYP g==; X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="334442618" X-IronPort-AV: E=Sophos;i="5.98,225,1673942400"; d="scan'208";a="334442618" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2023 05:38:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="624495674" X-IronPort-AV: E=Sophos;i="5.98,225,1673942400"; d="scan'208";a="624495674" Received: from tdx-lm.sh.intel.com ([10.239.53.27]) by orsmga003.jf.intel.com with ESMTP; 01 Mar 2023 05:38:44 -0800 From: Wei Wang To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Wang Subject: [PATCH v1] KVM: allow KVM_BUG/KVM_BUG_ON to handle 64-bit cond Date: Wed, 1 Mar 2023 21:38:41 +0800 Message-Id: <20230301133841.18007-1-wei.w.wang@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759172948000383877?= X-GMAIL-MSGID: =?utf-8?q?1759172948000383877?= Current KVM_BUG and KVM_BUG_ON assumes that 'cond' passed from callers is 32-bit as it casts 'cond' to the type of int. This will be wrong if 'cond' provided by a caller is 64-bit, e.g. an error code of 0xc0000d0300000000 will be converted to 0, which is not expected. Improves the implementation by using !!(cond) in KVM_BUG and KVM_BUG_ON. Compared to changing 'int' to 'int64_t', this has less LOCs. Fixes: 0b8f11737cff ("KVM: Add infrastructure and macro to mark VM as bugged") Signed-off-by: Wei Wang --- include/linux/kvm_host.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f06635b24bd0..d77ddf82c5c8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -881,20 +881,16 @@ static inline void kvm_vm_bugged(struct kvm *kvm) #define KVM_BUG(cond, kvm, fmt...) \ ({ \ - int __ret = (cond); \ - \ - if (WARN_ONCE(__ret && !(kvm)->vm_bugged, fmt)) \ + if (WARN_ONCE(!!cond && !(kvm)->vm_bugged, fmt)) \ kvm_vm_bugged(kvm); \ - unlikely(__ret); \ + unlikely(!!cond); \ }) #define KVM_BUG_ON(cond, kvm) \ ({ \ - int __ret = (cond); \ - \ - if (WARN_ON_ONCE(__ret && !(kvm)->vm_bugged)) \ + if (WARN_ON_ONCE(!!(cond) && !(kvm)->vm_bugged)) \ kvm_vm_bugged(kvm); \ - unlikely(__ret); \ + unlikely(!!(cond)); \ }) static inline void kvm_vcpu_srcu_read_lock(struct kvm_vcpu *vcpu)