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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 744A2C636C9 for ; Thu, 15 Jul 2021 20:53:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC9D860FF1 for ; Thu, 15 Jul 2021 20:53:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC9D860FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m48Mj-0008Mn-2u for qemu-devel@archiver.kernel.org; Thu, 15 Jul 2021 16:53:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m48Lb-0007X1-AE for qemu-devel@nongnu.org; Thu, 15 Jul 2021 16:52:43 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:34556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m48LZ-0005Yz-N7 for qemu-devel@nongnu.org; Thu, 15 Jul 2021 16:52:42 -0400 Received: by mail-ed1-x52f.google.com with SMTP id ec55so10075520edb.1 for ; Thu, 15 Jul 2021 13:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S+jMjj9qv4VxWA396ta3IcoAYh5PnskFQSMxJ3fw0f4=; b=TUWNYihnlIls0fFeL6dexTbqE4JqQAuzkRSbc2DUH8pqugJDTZ7XWQaBQ8z/d6hVcl bT5YkRF3RSp7/Z3QN9cVi9iPsyJsfBIkTPhBGgSwBfJ8R/28lECzapf8lPJ8/KOmWkjW Wg3lKDN0jzxbfzpN8SYDyh6Bk2N3P9MROrCFpWsl7WWZfBLhvdqtl2ZIVPvjYPUlsGxQ E0KPjm93ZCw7CtW7AeuG9Z4drtKcFsakb6/P26obWfbyP2jMCmOgo9uPOFu00a6/6vbP 2/uaWh1Q2dU+l+p/+8LBn2vyK+NIEEHFFjWqi4qCKxb6tbVp/OtP2XIHTg71MauHhoXF 7etQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=S+jMjj9qv4VxWA396ta3IcoAYh5PnskFQSMxJ3fw0f4=; b=ic9RdPHQPETKiCvwWIBLYUzUziyIRYfZhF3we2Mvkx80uoDOk/n+0FCPsnkTs+u71i d2+ADKsFBh5W7wIbF9rZqcSeEuPEdwe4pyZfD4tH60IE9B0l+3W75s3kxuP3UhQsm8kd /DMLrJ1e4Af3JCGgZ8TYQ6gHhMjn/hXVYoEdpEx968QzsozetzE1BpERM8xgeqXtcDOj 5NeJO8EsRd3XefdTauM0rfPV7n/HWemsVnPq7YTNivwg/XxRjQZIC7Zo9oF0nHu9hXWt EJQaGwJHWkryKFJr/eXGUZpTM8Mt0kyLG2o1ID16p2LbWjF2mg8me1u0x9Q7keOr+tfm C6Aw== X-Gm-Message-State: AOAM532PbdIAAKAqg9VSxX0A8H+0eLpvdfMRj3ECYbD1HY3x64wsHikU g3lZUdZbDc8Tl1qr0NI2OdFS7r7IjD2/Tm2oG0wqQA== X-Google-Smtp-Source: ABdhPJz2mtagHGX9lBAGtkbV3Y0KFvZcpSxy4NdJHVRU3VXpQYGXw5/iqaS8N4T2qcNvFLRZd8kUuC6QII8/JY0yQuw= X-Received: by 2002:aa7:d809:: with SMTP id v9mr9808210edq.146.1626382358395; Thu, 15 Jul 2021 13:52:38 -0700 (PDT) MIME-Version: 1.0 References: <20210713160957.3269017-1-ehabkost@redhat.com> <20210713160957.3269017-5-ehabkost@redhat.com> In-Reply-To: <20210713160957.3269017-5-ehabkost@redhat.com> From: Peter Maydell Date: Thu, 15 Jul 2021 21:51:58 +0100 Message-ID: Subject: Re: [PULL 04/11] i386: expand Hyper-V features during CPU feature expansion time To: Eduardo Habkost Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=peter.maydell@linaro.org; helo=mail-ed1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm-devel , "Michael S. Tsirkin" , Marcelo Tosatti , Richard Henderson , QEMU Developers , Paolo Bonzini , Vitaly Kuznetsov Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tue, 13 Jul 2021 at 17:19, Eduardo Habkost wrote: > > From: Vitaly Kuznetsov > > To make Hyper-V features appear in e.g. QMP query-cpu-model-expansion we > need to expand and set the corresponding CPUID leaves early. Modify > x86_cpu_get_supported_feature_word() to call newly intoduced Hyper-V > specific kvm_hv_get_supported_cpuid() instead of > kvm_arch_get_supported_cpuid(). We can't use kvm_arch_get_supported_cpuid() > as Hyper-V specific CPUID leaves intersect with KVM's. > > Note, early expansion will only happen when KVM supports system wide > KVM_GET_SUPPORTED_HV_CPUID ioctl (KVM_CAP_SYS_HYPERV_CPUID). > > Reviewed-by: Eduardo Habkost > Signed-off-by: Vitaly Kuznetsov > Message-Id: <20210608120817.1325125-6-vkuznets@redhat.com> > Signed-off-by: Eduardo Habkost Hi; Coverity reports an issue in this code (CID 1458243): > -static bool hyperv_expand_features(CPUState *cs, Error **errp) > +bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) > { > - X86CPU *cpu = X86_CPU(cs); > + CPUState *cs = CPU(cpu); > > if (!hyperv_enabled(cpu)) > return true; > > + /* > + * When kvm_hyperv_expand_features is called at CPU feature expansion > + * time per-CPU kvm_state is not available yet so we can only proceed > + * when KVM_CAP_SYS_HYPERV_CPUID is supported. > + */ > + if (!cs->kvm_state && > + !kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID)) > + return true; Here we check whether cs->kvm_state is NULL, but even if it is NULL we can still continue execution further through the function. Later in the function we call hv_cpuid_get_host(), which in turn can call get_supported_hv_cpuid_legacy(), which can dereference cs->kvm_state without checking it. So either the check on cs->kvm_state above is unnecessary, or we need to handle it being NULL in some way other than falling through. Side note: this change isn't in line with our coding style, which requires braces around the body of the if(). thanks -- PMM