From patchwork Mon Aug 2 16:15:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VuJjfKvs; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjqk6XJgz9sRK for ; Tue, 3 Aug 2021 02:18:58 +1000 (AEST) Received: from localhost ([::1]:44046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAaeW-0006os-Hh for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:18:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabV-0000xP-4K for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:40705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabS-0006pR-TL for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:48 -0400 Received: by mail-ed1-x52a.google.com with SMTP id d6so17602030edt.7 for ; Mon, 02 Aug 2021 09:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uKkyh3OYQ0mfw6Y9gyrWs6boJPfL3KQaIy+v+IFJpNM=; b=VuJjfKvsI8/T0P7XW2BhCywq/76rNm2HssiGQh9JdQr/km6lPqzrvm8/4/Id9/KbXe mV1NTHv7BSHQtjSOpOet2sWKfccgZU8ZCdmohFA9Rp0tQ+GKHOnZWT/Z1ZaI6+EmLZL/ QR2qkVeIR/9At4p72S0AscOW6gft5di1FrsAFMJJRZkkSLQ14tuHBkjv6HCpx7SuvblM 8OSLgQI67KTjUD5uy+l2i3BDHZwC3x405LC4az/1xQRtbYOabQoR+iTGdkobkk4KQnnq XhGV7QqduMzmpV/bP24TL0g/VVXVmXPuz3gBMMQLxNzYxwPFsQTAo8/cG+cSlfmbOiOZ 4+Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=uKkyh3OYQ0mfw6Y9gyrWs6boJPfL3KQaIy+v+IFJpNM=; b=dYjLEx9RqI4TdT2P/tBAe5Mnj5uY40Kdh9YCGyDnOnXs19fqQrMJYOauGGBDLcEANK AJ59pgCCOD5eIciVlKD3WERqW0IsqnapZAN8kyzDJz1EgHKF83vlbuqSoAkCWVT5sJZ8 aYdkVZ+IXc8/msOX9VmzfwzF9l3QnY9O6wgdLwmwkGy/i1c/GRorg34944IGzYMkSjws 3PJPIPIsgrityBJzzDm+eNisLzjWrddHWsrU63tNmbN7bRbg9TRQklmn6l991g17x81L nKe6gV21XrNlvnfPUoYBm5vnZg4t6V9QxT7y6U/XgFbXDHz+Xn/WE9TC2SV7w6B95IrY FaVg== X-Gm-Message-State: AOAM5337LYe3ydKB18tW2Oe6yGbe0l8kYezb9K+BTb3kJxh0ycomJ2q2 LX1Im09/ZMWMwAZ0Dlex4hfZ/VrQPPZymA== X-Google-Smtp-Source: ABdhPJyJ+tiU0SuY2TaJepC34/Iw2HFFqaX1m++MHe/YjOXV6w58kHb5rSdg8UxEfacqROIWGSQJ3Q== X-Received: by 2002:a50:d71e:: with SMTP id t30mr19977187edi.72.1627920944036; Mon, 02 Aug 2021 09:15:44 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 1/8] vl: introduce machine_merge_property Date: Mon, 2 Aug 2021 18:15:35 +0200 Message-Id: <20210802161542.381976-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It will be used to parse smp-opts config groups from configuration files. The point to note is that it does not steal a reference from the caller. This is better because this function will be called from qemu_config_foreach's callback; qemu_config_foreach does not cede its reference to the qdict to the callback, and wants to free it. To balance that extra reference, machine_parse_property_opt now needs a qobject_unref. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 4dee472c79..93aef8e747 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1534,23 +1534,36 @@ static void machine_help_func(const QDict *qdict) } } +static void +machine_merge_property(const char *propname, QDict *prop, Error **errp) +{ + QDict *opts; + + opts = qdict_new(); + /* Preserve the caller's reference to prop. */ + qobject_ref(prop); + qdict_put(opts, propname, prop); + keyval_merge(machine_opts_dict, opts, errp); + qobject_unref(opts); +} + static void machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, const char *arg, Error **errp) { - QDict *opts, *prop; + QDict *prop = NULL; bool help = false; - ERRP_GUARD(); prop = keyval_parse(arg, opts_list->implied_opt_name, &help, errp); if (help) { qemu_opts_print_help(opts_list, true); exit(0); } - opts = qdict_new(); - qdict_put(opts, propname, prop); - keyval_merge(machine_opts_dict, opts, errp); - qobject_unref(opts); + if (!prop) { + return; + } + machine_merge_property(propname, prop, errp); + qobject_unref(prop); } static const char *pid_file; From patchwork Mon Aug 2 16:15:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Imz9H59s; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjqk5T1wz9s24 for ; Tue, 3 Aug 2021 02:18:58 +1000 (AEST) Received: from localhost ([::1]:43990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAaeW-0006m0-Et for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:18:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabT-0000xG-PT for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:37563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabS-0006pY-2S for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:47 -0400 Received: by mail-ej1-x62c.google.com with SMTP id h9so16305115ejs.4 for ; Mon, 02 Aug 2021 09:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2fwd9objZBu7/3yhUZG7id8W9kbZ76Fri7jal/zJS04=; b=Imz9H59sQ212Pegl0EVDMC49YQD6RvgEVGVrT/fKciL0UNL4d8HnyEGxg0SrH+Hs60 iVNP5LnzbvTF/Qmo/MjaeR1wlwHjBoBT/12R+CTvNfoV9rpIXxzhoeVQuL8sp7kiblrI WPNHDbmiKs/ok76AJXpscKG22NJRv/I3ZDi1b4TNxS57jmVoH7P9VKaH4AtE5XXkpYYM E5CCpv4x4OLwA8w3eY1kwtXI/eFC7fQqFJPZAjmUasvxGvyi7uxycWhYFOpTbkduqtAz L+oqtKXaO8z4YUDQdsZRTHqC15ZCRD/3LAIryBAUBIFtRu6UTmlmRdlv9Dv5MZfnMFQt CB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2fwd9objZBu7/3yhUZG7id8W9kbZ76Fri7jal/zJS04=; b=EQUF9TUbErWlka1kkigcFYzNkm9qu1xlml7WNX/hKfkMZskin0Sp4VWScNFh/wjyYM 60iUvc93jntrJLG8GwRKUqv8cWIdZSMR3vwXLqXC3/VfW8WXxS6kM7JzfyUj2bBQXeQo IDtc1fRfdrT1qiuh7iD3yunVo06sscGkdmY5HbV5fyXYK0zHy7aoDplCFlF3MgpiG5cK 1n9JGhYsOAuu2kvWXoQwvebcx9hlYtlUuy9g92GmLGzk1HZgVAxUdOdjP4oTb8j7TiIQ +RF167bBWxSGhNnNQ2AOFhuJzXHNHzS2N16OL1ocg8j246HpDpxqAV+tA5H1j5pKvpx9 jWZQ== X-Gm-Message-State: AOAM530RE3eRJrHGmvXXGqShgstzNJDk5HvTS5OLSSbggvUpZv/QvfBe XiKisQoNq6LDZcOLBEdYdoP+G6tdZ9dsXw== X-Google-Smtp-Source: ABdhPJzT3G22aY29jV4KRokmhzU7K6sYH3NBSMuT0lFOcgOI3y8638t1HLr5zk/qvNPH6/IS0MwuZQ== X-Received: by 2002:a17:906:32d6:: with SMTP id k22mr15818313ejk.228.1627920944741; Mon, 02 Aug 2021 09:15:44 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 2/8] vl: stop recording -smp in QemuOpts Date: Mon, 2 Aug 2021 18:15:36 +0200 Message-Id: <20210802161542.381976-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" -readconfig is still recording SMP options in QemuOpts instead of using machine_opts_dict. This means that SMP options from -readconfig are ignored. Just stop using QemuOpts for -smp, making it return false for is_qemuopts_group. Configuration files will merge the values in machine_opts_dict using the new function machine_merge_property. At the same time, fix -mem-prealloc which looked at QemuOpts to find the number of guest CPUs, which it used as the default number of preallocation threads. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 93aef8e747..5ca11e7469 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -31,6 +31,7 @@ #include "qapi/compat-policy.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" #include "qapi/qmp/qjson.h" #include "qemu-version.h" #include "qemu/cutils.h" @@ -2166,7 +2167,8 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) static bool is_qemuopts_group(const char *group) { if (g_str_equal(group, "object") || - g_str_equal(group, "machine")) { + g_str_equal(group, "machine") || + g_str_equal(group, "smp-opts")) { return false; } return true; @@ -2186,6 +2188,8 @@ static void qemu_record_config_group(const char *group, QDict *dict, */ assert(!from_json); keyval_merge(machine_opts_dict, dict, errp); + } else if (g_str_equal(group, "smp-opts")) { + machine_merge_property("smp", dict, &error_fatal); } else { abort(); } @@ -2452,13 +2456,15 @@ static void qemu_validate_options(const QDict *machine_opts) static void qemu_process_sugar_options(void) { if (mem_prealloc) { - char *val; - - val = g_strdup_printf("%d", - (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1)); - object_register_sugar_prop("memory-backend", "prealloc-threads", val, - false); - g_free(val); + QObject *smp = qdict_get(machine_opts_dict, "smp"); + if (smp && qobject_type(smp) == QTYPE_QDICT) { + QObject *cpus = qdict_get(qobject_to(QDict, smp), "cpus"); + if (cpus && qobject_type(cpus) == QTYPE_QSTRING) { + const char *val = qstring_get_str(qobject_to(QString, cpus)); + object_register_sugar_prop("memory-backend", "prealloc-threads", + val, false); + } + } object_register_sugar_prop("memory-backend", "prealloc", "on", false); } From patchwork Mon Aug 2 16:15:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=UCMg7c/W; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjn759pWz9s24 for ; Tue, 3 Aug 2021 02:16:43 +1000 (AEST) Received: from localhost ([::1]:35554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAacL-00011V-Dj for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:16:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabV-0000xN-2n for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:35336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabS-0006qA-LL for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:48 -0400 Received: by mail-ej1-x62f.google.com with SMTP id o5so31781069ejy.2 for ; Mon, 02 Aug 2021 09:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wTjOAVjdtymwz9rd5aA6ONu5k4R7mM2ueQUxv/s95TM=; b=UCMg7c/Wa5cq/JaS0xrPZRhKaq5W79m57kOaSkn40L2pR/AlR/i7yhjd2rpzCgzl44 Az8qY0CAFl7IpZo3K9q/rellwM9RpgXY8Jn8f4AEBuHZOYvPXkgg5yEfzUHvUQ1yKObX z32KVUzefawugAL7sh+VOtF9rgSi0ZVE35JERim4Uvs2auRMUuex2PugiU2B/z7vMeQJ xCIWuAd0QssHhxza0ZCPpeN5EherRNURDvLHz7T2I8BPu9R3InHqBWb2LDl8PSDJ2nsq LxRF8QUUgOphhmQ5JU35+0dJZ9EYBql9i/A3blgaRErxJfDgINELBMycaYsYWL6XRm6B VMZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wTjOAVjdtymwz9rd5aA6ONu5k4R7mM2ueQUxv/s95TM=; b=mvU6W1ttG43Qkx82pLqmKikxzHaQihqMjF7wyQeYNmg4HJO73k8cxlmfTQunosU7um c3YeY1gymSly4rq7+YODeMr6pfOknYGupo5Kc7qs51mVBGVFIAbC0f2+x5WdsWxbhUQ4 iJx5R3FWg2E9OcKWWu9gUCUYOZVQZoS6fKCYhVktUHulNpBOwqOYwuPBzHmhLE+7A8qW 2L1i+xQLruQ3xd8OrDsukSM4HHw3ZwMLlRfR6ji0sAmNRgwiDFkUEbdkiFYs3WryAOeX o+PvQZtkBpPvm0gudU9MAQwQncRek6gDufwY34mY6QGgzttjwjnGZ0DrA8nvGcbHJRFG OD2g== X-Gm-Message-State: AOAM531YtRkGiJG3U0Q2eZWPjEGjIQCtMZtVC28cXz9vgDmtrMEFDdN4 v4f5BM1N0bFGc+LdR1clALNggxWfVKDTNg== X-Google-Smtp-Source: ABdhPJyEuNCkXq8vu1a8+7fZjUpIX+/lPvxr7PZL+X6HkBT9Lu1gQ38BQAPM3BmYlMjcPwkD/CjRlA== X-Received: by 2002:a17:906:a3d8:: with SMTP id ca24mr16565445ejb.533.1627920945372; Mon, 02 Aug 2021 09:15:45 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 3/8] coverity-model: update address_space_read/write models Date: Mon, 2 Aug 2021 18:15:37 +0200 Message-Id: <20210802161542.381976-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use void * for consistency with the actual function; provide a model for MemoryRegionCache functions and for address_space_rw. These let Coverity understand the bounds of the data that various functions read and write even at very high levels of inlining (e.g. pci_dma_read). Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 48 ++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index 2c0346ff25..e1bdf0ad84 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -45,9 +45,10 @@ typedef struct va_list_str *va_list; /* exec.c */ typedef struct AddressSpace AddressSpace; +typedef struct MemoryRegionCache MemoryRegionCache; typedef uint64_t hwaddr; typedef uint32_t MemTxResult; -typedef uint64_t MemTxAttrs; +typedef struct MemTxAttrs {} MemTxAttrs; static void __bufwrite(uint8_t *buf, ssize_t len) { @@ -67,9 +68,40 @@ static void __bufread(uint8_t *buf, ssize_t len) int last = buf[len-1]; } +MemTxResult address_space_read_cached(MemoryRegionCache *cache, hwaddr addr, + MemTxAttrs attrs, + void *buf, int len) +{ + MemTxResult result; + // TODO: investigate impact of treating reads as producing + // tainted data, with __coverity_tainted_data_argument__(buf). + __bufwrite(buf, len); + return result; +} + +MemTxResult address_space_write_cached(MemoryRegionCache *cache, hwaddr addr, + MemTxAttrs attrs, + const void *buf, int len) +{ + MemTxResult result; + __bufread(buf, len); + return result; +} + +MemTxResult address_space_rw_cached(MemoryRegionCache *cache, hwaddr addr, + MemTxAttrs attrs, + void *buf, int len, bool is_write) +{ + if (is_write) { + return address_space_write_cached(cache, addr, attrs, buf, len); + } else { + return address_space_read_cached(cache, addr, attrs, buf, len); + } +} + MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, - uint8_t *buf, int len) + void *buf, int len) { MemTxResult result; // TODO: investigate impact of treating reads as producing @@ -80,13 +112,23 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, - const uint8_t *buf, int len) + const void *buf, int len) { MemTxResult result; __bufread(buf, len); return result; } +MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + void *buf, int len, bool is_write) +{ + if (is_write) { + return address_space_write(as, addr, attrs, buf, len); + } else { + return address_space_read(as, addr, attrs, buf, len); + } +} /* Tainting */ From patchwork Mon Aug 2 16:15:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oQW17AqW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjn50z6bz9s24 for ; Tue, 3 Aug 2021 02:16:39 +1000 (AEST) Received: from localhost ([::1]:35524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAacG-000106-AD for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:16:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabV-0000xO-3D for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:35812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabT-0006qY-6s for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:48 -0400 Received: by mail-ed1-x52d.google.com with SMTP id cf5so13693960edb.2 for ; Mon, 02 Aug 2021 09:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fm2UD8Zyz4671JlxJea8LEur7xOb1KFIH/B40VUSEow=; b=oQW17AqWb4W8ZSUEh36z85BVyabfXryFcbonKMC0X0W1HNPWTvxjpSUBu8ysU3Gpvn gn1HYd2jzr+2mhCmXpJKzhUNyPf8T7DL24xudeB+//9H7IDWiEDXB9zTa4vP+PJzBtK3 RzBa3DRl7F8ZGfqXYJebcFjSFujz2qZv/ht7EJD8uxL7ycKZBqChEPxsQ5YqIFiDzvNU 0b/Ne8PZr5G0V7lX88RJBNsuV1jYfYFWh4Oj42remS6JrfSk3DEpxqYCJkZkWQqVM6Fy ee6IPu8m2Ju31bV4tI/mbbmbS0252+Lff1g2MreBeWdwmDKul1c3qEuhV0zpgBazJMt2 tXGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=fm2UD8Zyz4671JlxJea8LEur7xOb1KFIH/B40VUSEow=; b=jh/+A4L5gvTr/xbbOHDJsfePgXo88YV+YXAufaSE8m1zx/RNZ/Bha+3GEDjXsYijQa Qh14DzE2xaypCaAKiOmwAM8MLvJaelgPdKIsz8p3ICOWQG0yYJXxMR6qcN1rRdhmswSU offAg8KTUkRZbkzDS7Ss0YXwF5KNzYmPKRoOZqaJCs3MgBFNWqXguH0VdAa6tJk61yyX JBZjLPXXSxvgR5AB4880DHbHSdPHixbF2937Rz3zFQAuIOYHQKi7vW+B1t6+lugeiQ74 5R00wW19LjJ7+dMd24NZtH0LQ2gFCNCDdKga8GjksWyhy47lYOvyxuv/tHZGysLvsaBO HPMA== X-Gm-Message-State: AOAM530wm2DV0zXSGb9M/LUaW+9ialEI+zqDsKwshxsmvYo5Icx3LaJQ T+dUf7VmK3KRTsYGaQaVhc46bWiMKeI9Bg== X-Google-Smtp-Source: ABdhPJyYIbvg+AbBgP5qU7tqFt5xkl8Rj1ff9oNej7mJvDBOXNjmya8XJaisYd3MSS6+VmM0s2TTFg== X-Received: by 2002:a05:6402:34e:: with SMTP id r14mr19964640edw.6.1627920945987; Mon, 02 Aug 2021 09:15:45 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 4/8] coverity-model: make g_free a synonym of free Date: Mon, 2 Aug 2021 18:15:38 +0200 Message-Id: <20210802161542.381976-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Recently, Coverity has started complaining about using g_free() to free memory areas allocated by GLib functions not included in model.c, such as g_strfreev. This unfortunately goes against the GLib documentation, which suggests that g_malloc() should be matched with g_free() and plain malloc() with free(); since GLib 2.46 however g_malloc() is hardcoded to always use the system malloc implementation, and g_free is just "free" plus a tracepoint. Therefore, this should not cause any problem in practice. Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index e1bdf0ad84..8e64a84c5a 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -186,7 +186,7 @@ void *g_malloc_n(size_t nmemb, size_t size) sz = nmemb * size; ptr = __coverity_alloc__(sz); __coverity_mark_as_uninitialized_buffer__(ptr); - __coverity_mark_as_afm_allocated__(ptr, "g_free"); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; } @@ -200,7 +200,7 @@ void *g_malloc0_n(size_t nmemb, size_t size) sz = nmemb * size; ptr = __coverity_alloc__(sz); __coverity_writeall0__(ptr); - __coverity_mark_as_afm_allocated__(ptr, "g_free"); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; } @@ -218,14 +218,14 @@ void *g_realloc_n(void *ptr, size_t nmemb, size_t size) * model that. See Coverity's realloc() model */ __coverity_writeall__(ptr); - __coverity_mark_as_afm_allocated__(ptr, "g_free"); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; } void g_free(void *ptr) { __coverity_free__(ptr); - __coverity_mark_as_afm_freed__(ptr, "g_free"); + __coverity_mark_as_afm_freed__(ptr, AFM_free); } /* @@ -328,7 +328,7 @@ char *g_strdup(const char *s) __coverity_string_null_sink__(s); __coverity_string_size_sink__(s); dup = __coverity_alloc_nosize__(); - __coverity_mark_as_afm_allocated__(dup, "g_free"); + __coverity_mark_as_afm_allocated__(dup, AFM_free); for (i = 0; (dup[i] = s[i]); i++) ; return dup; } @@ -362,7 +362,7 @@ char *g_strdup_printf(const char *format, ...) s = __coverity_alloc_nosize__(); __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, "g_free"); + __coverity_mark_as_afm_allocated__(s, AFM_free); return s; } @@ -375,11 +375,10 @@ char *g_strdup_vprintf(const char *format, va_list ap) __coverity_string_size_sink__(format); ch = *format; - ch = *(char *)ap; s = __coverity_alloc_nosize__(); __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, "g_free"); + __coverity_mark_as_afm_allocated__(s, AFM_free); return len; } @@ -395,7 +394,7 @@ char *g_strconcat(const char *s, ...) s = __coverity_alloc_nosize__(); __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, "g_free"); + __coverity_mark_as_afm_allocated__(s, AFM_free); return s; } From patchwork Mon Aug 2 16:15:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=PIeLvCrW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjql0D9Sz9sS8 for ; Tue, 3 Aug 2021 02:18:59 +1000 (AEST) Received: from localhost ([::1]:44010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAaeW-0006mg-L6 for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:18:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabW-0000xT-Ax for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:44615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabT-0006rH-Qr for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:50 -0400 Received: by mail-ej1-x629.google.com with SMTP id yk17so24071197ejb.11 for ; Mon, 02 Aug 2021 09:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C6DiBC7Mzk28ej4iKDpfbNsQyeV69GCYbRHuydqtOrc=; b=PIeLvCrWUbHTyql+xN6V/zeh4lX3zYSMCQNg0CvcwmYDeTnJ1bENImWuUy1MoLb77p Tl4Py37otGdIBPEKd3dn8GPgxwMR6GX1rwzuAVOmVdrFNmlY0myYGzZ/SETodOALSRnA qCrtJTMsk7qi5ZQavdWBV+Q7fZeZpYlZJ/n1iG9rAxTb7wZ0+12OOlEtfhJXuyly/FUM eAY5dTqDrpIykrGRc4KUu43WdiEdAzl0I8ieeYyEP5/l8KPgpFAItYWW3WtD7LrXerrB cS62ZVlb4IpIBca5oFGzuMnOrJOOlIxEzPDSeuvc/mxLBjYGmBALQg7awME7G51shrUr Wpsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=C6DiBC7Mzk28ej4iKDpfbNsQyeV69GCYbRHuydqtOrc=; b=uXnlIARo8lTImF2l+3b8QQH1t4pffH9B0ng60XqNDwpfHijbhtRo4gaKcUGbmpOF/s eY6Qz2n92+v2zCOXnasiyqPF2imHQzFpuXzZk93KnrfTOrK5M7YNwQz7ENEcS26hL/vU KMN+ikfYrAdKSBngei2ljjKABVDi0hxPtsV9zkU3kDzxgVRBFhDQ4n2I3S6/9Hux910D CGQr5EDU5+DsguBFraSRShlDT4L/CJXBA+x1q+F5Z3w694Zd0skXq5pFnYKPeEbv++DC 8xBScZh7gO/HsisABQqxK/P7lvTs1MFV4oZAHxwa3M0/4ZrxCGPNKpatzlR2AJV7zMN2 SAhA== X-Gm-Message-State: AOAM532/6un4j1vS9RxQuLfztmMUHBPynqihQ7eLp3q2zaxn5EsBRvqu NgJHB2tu4Y4NSrXfA4e/w+yvITA6VZ/lTQ== X-Google-Smtp-Source: ABdhPJyx7roxQWvMpLne/jVYrc8VyBTJuCPieaPNTRa06G8KpWvqvOE0c3/ETEv/3q+XVfGI2mB3Mw== X-Received: by 2002:a17:907:76cd:: with SMTP id kf13mr16851024ejc.310.1627920946595; Mon, 02 Aug 2021 09:15:46 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 5/8] coverity-model: remove model for more allocation functions Date: Mon, 2 Aug 2021 18:15:39 +0200 Message-Id: <20210802161542.381976-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x629.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" These models are not needed anymore now that Coverity does not check anymore that the result is used with "g_free". Coverity understands GCC attributes and uses them to detect leaks. Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 105 +--------------------------------- 1 file changed, 1 insertion(+), 104 deletions(-) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index 8e64a84c5a..1a5f39d2ae 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -263,7 +263,7 @@ void *g_try_realloc_n(void *ptr, size_t nmemb, size_t size) return g_realloc_n(ptr, nmemb, size); } -/* Trivially derive the g_FOO() from the g_FOO_n() */ +/* Derive the g_FOO() from the g_FOO_n() */ void *g_malloc(size_t size) { @@ -295,109 +295,6 @@ void *g_try_realloc(void *ptr, size_t size) return g_try_realloc_n(ptr, 1, size); } -/* Other memory allocation functions */ - -void *g_memdup(const void *ptr, unsigned size) -{ - unsigned char *dup; - unsigned i; - - if (!ptr) { - return NULL; - } - - dup = g_malloc(size); - for (i = 0; i < size; i++) - dup[i] = ((unsigned char *)ptr)[i]; - return dup; -} - -/* - * GLib string allocation functions - */ - -char *g_strdup(const char *s) -{ - char *dup; - size_t i; - - if (!s) { - return NULL; - } - - __coverity_string_null_sink__(s); - __coverity_string_size_sink__(s); - dup = __coverity_alloc_nosize__(); - __coverity_mark_as_afm_allocated__(dup, AFM_free); - for (i = 0; (dup[i] = s[i]); i++) ; - return dup; -} - -char *g_strndup(const char *s, size_t n) -{ - char *dup; - size_t i; - - __coverity_negative_sink__(n); - - if (!s) { - return NULL; - } - - dup = g_malloc(n + 1); - for (i = 0; i < n && (dup[i] = s[i]); i++) ; - dup[i] = 0; - return dup; -} - -char *g_strdup_printf(const char *format, ...) -{ - char ch, *s; - size_t len; - - __coverity_string_null_sink__(format); - __coverity_string_size_sink__(format); - - ch = *format; - - s = __coverity_alloc_nosize__(); - __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, AFM_free); - return s; -} - -char *g_strdup_vprintf(const char *format, va_list ap) -{ - char ch, *s; - size_t len; - - __coverity_string_null_sink__(format); - __coverity_string_size_sink__(format); - - ch = *format; - - s = __coverity_alloc_nosize__(); - __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, AFM_free); - - return len; -} - -char *g_strconcat(const char *s, ...) -{ - char *s; - - /* - * Can't model: last argument must be null, the others - * null-terminated strings - */ - - s = __coverity_alloc_nosize__(); - __coverity_writeall__(s); - __coverity_mark_as_afm_allocated__(s, AFM_free); - return s; -} - /* Other glib functions */ typedef struct pollfd GPollFD; From patchwork Mon Aug 2 16:15:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sVK3JG2F; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjn62NNWz9sS8 for ; Tue, 3 Aug 2021 02:16:42 +1000 (AEST) Received: from localhost ([::1]:35520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAacK-0000zw-1P for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:16:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabW-0000xS-8q for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:42675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabU-0006rn-DM for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:50 -0400 Received: by mail-ed1-x52a.google.com with SMTP id p21so25224336edi.9 for ; Mon, 02 Aug 2021 09:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0w/cTVHey5w4upyorSaSfdFgQW9Muy6hj86ofEeuDqQ=; b=sVK3JG2FVmLMB/f2Jh1qR0u7DAJF4te5zjcieIxJYwqZBHIhWQiC5IUCK2DiGy7sls Q8bJ1P3MoOIxOpOxlKEZKAE70obzFaAB8UUxD1HDu83JJPC8Wx7dOE9bgaWdxo0tKzmX iCixOlf5zVsKQYRmr3jQINlXsJzgm4ge9ZWop5O6LPGW5mvF1K18FNro11u2jdFF+K08 a3reLkL20tZb2u8Qk06rIoKBV0bwAcaAuFL9yHu735EF2NWSb+Yl3Y076HGEXCurO2Wq HxGn0Zlt+1RkTM+ldt7NPQtCgfNqMYQ9latffJeVwYSMaU9vxGL88yV7JR4I7PXckQcv Tttg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=0w/cTVHey5w4upyorSaSfdFgQW9Muy6hj86ofEeuDqQ=; b=WA1RgOomk8p9+ukilbDGUoFYgAuOPJfnTdWaLzWB3z8cQmdWffRTisNhl4NO5ToDw3 18avcVv1MSKPyzNWsG7RjisDBXggKDeCr35lW7oGL7TYLEJDcXKkxIJ8J28n/erkcszj 1EBmf3NHe6RVyyuMwYBSwpWBTVD5kuGxlBM+CDAI4L8ioKtz+1cAwNvX9qd11uXP2gli XWxGN4KOBor+UfboEP7M72FYXLJPAthA//NNMZOG3lWehvNYn5Y392CepAPl1099p0DR ZSMjx5i3BZssmlJR59F1WBJ4zRazvtMzZ2gqCAf5x1LR0Hej6delj1yUXMmrQWoTVdjv l9Ig== X-Gm-Message-State: AOAM533oGrHfak6nxqsQBbZpDv7lh2CcMampuP3eyadX9vPLUQC7AuCx B1LtqvZrArj8KIz0s7BCFcoSB2rS7EGyaQ== X-Google-Smtp-Source: ABdhPJxMWs/CurdePUXBjuRIdIBiaDHIdqL0QBETRWF36zsLUKsQMoUyUraqdhmy0SzO0qCFTfSslw== X-Received: by 2002:a05:6402:648:: with SMTP id u8mr14097821edx.162.1627920947210; Mon, 02 Aug 2021 09:15:47 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 6/8] coverity-model: clean up the models for array allocation functions Date: Mon, 2 Aug 2021 18:15:40 +0200 Message-Id: <20210802161542.381976-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" sz is only used in one place, so replace it with nmemb * size in that one place. Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index 1a5f39d2ae..2d384bdd79 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -178,13 +178,11 @@ uint8_t replay_get_byte(void) void *g_malloc_n(size_t nmemb, size_t size) { - size_t sz; void *ptr; __coverity_negative_sink__(nmemb); __coverity_negative_sink__(size); - sz = nmemb * size; - ptr = __coverity_alloc__(sz); + ptr = __coverity_alloc__(nmemb * size); __coverity_mark_as_uninitialized_buffer__(ptr); __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; @@ -192,13 +190,11 @@ void *g_malloc_n(size_t nmemb, size_t size) void *g_malloc0_n(size_t nmemb, size_t size) { - size_t sz; void *ptr; __coverity_negative_sink__(nmemb); __coverity_negative_sink__(size); - sz = nmemb * size; - ptr = __coverity_alloc__(sz); + ptr = __coverity_alloc__(nmemb * size); __coverity_writeall0__(ptr); __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; @@ -206,13 +202,10 @@ void *g_malloc0_n(size_t nmemb, size_t size) void *g_realloc_n(void *ptr, size_t nmemb, size_t size) { - size_t sz; - __coverity_negative_sink__(nmemb); __coverity_negative_sink__(size); - sz = nmemb * size; __coverity_escape__(ptr); - ptr = __coverity_alloc__(sz); + ptr = __coverity_alloc__(nmemb * size); /* * Memory beyond the old size isn't actually initialized. Can't * model that. See Coverity's realloc() model From patchwork Mon Aug 2 16:15:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Ny6q9u9k; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjql1hb9z9sW5 for ; Tue, 3 Aug 2021 02:18:59 +1000 (AEST) Received: from localhost ([::1]:44060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAaeW-0006pJ-U6 for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:18:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabY-0000xX-UF for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:54 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:33336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabV-0006rz-A8 for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:52 -0400 Received: by mail-ed1-x536.google.com with SMTP id ec13so24709255edb.0 for ; Mon, 02 Aug 2021 09:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KB5cV0NikdfkiBGJyhuIIvWdyJWHTJa73ThUZLg8tio=; b=Ny6q9u9kjUQgbqve31/0eZbgD4LpX9oK0cMV9Fpxsca4pMt0uN2RB4PKZT4IYZwi9E A/j8xCMPNsg9BDhq8WioRGtRN1yvy/ndNrh1mB4GnheXkZItTc6DPvQPPKKF1q7Upb9J uacpjJWwsGv+hwoiRNvKfWw5rXPyqEMuUVX0oC2VHa1Vcg/AHVQvDffR6mMt1qsiyPsy 762jFEp+wBwEn6CT6xVKhr44RNcmdo7+LKhLXyRTqo+ptwNNkoZgKD6lOn9gTHZ8pTUm J1hnH9aTTztOMwMsUfn95b3E6cDf7gHXB+5xlzmOiOcoN2/w88izyzHxvoa2CatVsAl0 83nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KB5cV0NikdfkiBGJyhuIIvWdyJWHTJa73ThUZLg8tio=; b=ciXed1lVaRTs1X2LdogpZyKI/L7m0asiKsT8PBPwsrNCZ3oa3EexAVTQqF1qwTUYOz O0pUhZbfpI0or0jmoS0g9nFiapHS+eba5WQ/2OM1uG0ZjGvyJNZewNySn3Iu56BSQPjP IDPvmhTdwB4nOeSC9mPzfyRoCTSWqo1OuLVRvvNOWNdCeoJcTMggodvHwKoeLbwpk+nC eenVvurZ07XSi/r8zOsgVEet22CwPrJhVLAh//spZWr6ypmeY4oA0bdum69hSJ6oOJXw bm5Tjv86Rh4altj8WdGRNm/NpJ6C/qdaIi0UUaZ3wUCX4zCTIL5koiKrfaOhjkIUP0cL qlvw== X-Gm-Message-State: AOAM531lLFtCBUDIvwJA98IMzd5td7BKHrC+wCx7D8ra0C5pFqPDH4JS fs2NIFB30cCzJGbmoQj5dJYRI9QI3gPzHA== X-Google-Smtp-Source: ABdhPJwcGIlq2NIlm3py7vfyK5xd1htfQ/ntXilOFq834MXXQA69W7SpF3Hqyg5aZZisVlhikdVB8g== X-Received: by 2002:aa7:c799:: with SMTP id n25mr19522502eds.16.1627920947816; Mon, 02 Aug 2021 09:15:47 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 7/8] coverity-model: constrain g_malloc/g_malloc0/g_realloc as never returning NULL Date: Mon, 2 Aug 2021 18:15:41 +0200 Message-Id: <20210802161542.381976-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" g_malloc/g_malloc0/g_realloc only return NULL if the size is 0; we do not need to cover that in the model, and so far have expected __coverity_alloc__ to model a non-NULL return value. But that apparently does not work anymore, so add some extra conditionals that invoke __coverity_panic__ for NULL pointers. Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index 2d384bdd79..028f13e9e3 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -183,6 +183,9 @@ void *g_malloc_n(size_t nmemb, size_t size) __coverity_negative_sink__(nmemb); __coverity_negative_sink__(size); ptr = __coverity_alloc__(nmemb * size); + if (!ptr) { + __coverity_panic__(); + } __coverity_mark_as_uninitialized_buffer__(ptr); __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; @@ -195,6 +198,9 @@ void *g_malloc0_n(size_t nmemb, size_t size) __coverity_negative_sink__(nmemb); __coverity_negative_sink__(size); ptr = __coverity_alloc__(nmemb * size); + if (!ptr) { + __coverity_panic__(); + } __coverity_writeall0__(ptr); __coverity_mark_as_afm_allocated__(ptr, AFM_free); return ptr; @@ -206,6 +212,9 @@ void *g_realloc_n(void *ptr, size_t nmemb, size_t size) __coverity_negative_sink__(size); __coverity_escape__(ptr); ptr = __coverity_alloc__(nmemb * size); + if (!ptr) { + __coverity_panic__(); + } /* * Memory beyond the old size isn't actually initialized. Can't * model that. See Coverity's realloc() model From patchwork Mon Aug 2 16:15:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1512519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=H3bb9ZTh; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4Gdjsr0vhwz9s24 for ; Tue, 3 Aug 2021 02:20:48 +1000 (AEST) Received: from localhost ([::1]:52596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAagH-00046A-SW for incoming@patchwork.ozlabs.org; Mon, 02 Aug 2021 12:20:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAabe-0000zv-Lp for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:59 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:34807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAabY-0006ui-SD for qemu-devel@nongnu.org; Mon, 02 Aug 2021 12:15:57 -0400 Received: by mail-ej1-x62d.google.com with SMTP id cb3so9788732ejb.1 for ; Mon, 02 Aug 2021 09:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=302wxsTGGjRjbdAcJ8/o1znsZMnOFR8XXZjoCZCtdac=; b=H3bb9ZThwTEIBzz8w174X3zJgAspQXutiwblHUOleYp7DG7FxZ0CS4REn/gbVM22mk 6G17SJ9l09BbmH91sJXHn3teCYNwssqDaJXxHNL1lsbJkrjCi/KgDcj/u0Gz8KEF3TOc cNyvD6i10VDh84EbJCHDIXi6286tT0t0YvUmJ2fG2nZ10a4HIs5dTLdTep+iz2Tt2o8n L0u3Acp1lGGqn0mIZH9nxmtla4I7Qz2DRX22mnhpLRZ1vOPhrkKpDaBggMoXoaEiyL4t +hk371pSWVwEpXpWx9ImuTbnt5B61fPxMkgJ/5jtBejvEoGSMTikTEmFbFdj0y77luYQ WKpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=302wxsTGGjRjbdAcJ8/o1znsZMnOFR8XXZjoCZCtdac=; b=j/Ro82lzGbWZQSO80agEXZpEJ1DtIg2ENedGqsxjsRi+SsrncXQ7O83xCuQtItOp5Q pXTD9o3Md73lLLjy7/aSLpS/kFgcoq81cYRJCqBcx3oeJZyujlLS3Ix+nRgd33G4OGDy ixI+Hs+pTKehEs33KIUjgWWL7ZgB7I4s3FcaVI85RXxIzVapbvkWD7flSA3m5PIonVvm NC0AWa6nk+AC/aM8fmXoEqDklsjHxODUzw3BwjXIy5KYJEdKh8k0QwaoarTXIkuSSOyp hlqeHqgTD+GywFOFonfwv4fOqum5LpJEFSnwd8huIxRh2syZ8XKvLB+j10cyj6lDdVv1 HLkA== X-Gm-Message-State: AOAM531D0URkSJLS9oeDIj3EJl0Jg0PxPb1+uA/Q6EAQGg25oDggeP6k DZNJz7V9fP4SWDQHHjR5NUVOsEyQ5/1i3A== X-Google-Smtp-Source: ABdhPJzV59/YOnRZhzNU9cZKHh/QJzeDeuVPqyZ2AyXOrbBYfyBMYy33CzMph0uT+x8xb6MLRPD73Q== X-Received: by 2002:a17:906:79a:: with SMTP id l26mr3776498ejc.192.1627920948467; Mon, 02 Aug 2021 09:15:48 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id f15sm4835144ejb.125.2021.08.02.09.15.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 09:15:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 8/8] coverity-model: write models fully for non-array allocation functions Date: Mon, 2 Aug 2021 18:15:42 +0200 Message-Id: <20210802161542.381976-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210802161542.381976-1-pbonzini@redhat.com> References: <20210802161542.381976-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Coverity seems to have issues figuring out the properties of g_malloc0 and other non *_n functions. While this was "fixed" by removing the custom second argument to __coverity_mark_as_afm_allocated__, inline the code from the array-based allocation functions to avoid future issues. Signed-off-by: Paolo Bonzini --- scripts/coverity-scan/model.c | 57 +++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c index 028f13e9e3..9d4fba53d9 100644 --- a/scripts/coverity-scan/model.c +++ b/scripts/coverity-scan/model.c @@ -269,32 +269,77 @@ void *g_try_realloc_n(void *ptr, size_t nmemb, size_t size) void *g_malloc(size_t size) { - return g_malloc_n(1, size); + void *ptr; + + __coverity_negative_sink__(size); + ptr = __coverity_alloc__(size); + if (!ptr) { + __coverity_panic__(); + } + __coverity_mark_as_uninitialized_buffer__(ptr); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); + return ptr; } void *g_malloc0(size_t size) { - return g_malloc0_n(1, size); + void *ptr; + + __coverity_negative_sink__(size); + ptr = __coverity_alloc__(size); + if (!ptr) { + __coverity_panic__(); + } + __coverity_writeall0__(ptr); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); + return ptr; } void *g_realloc(void *ptr, size_t size) { - return g_realloc_n(ptr, 1, size); + __coverity_negative_sink__(size); + __coverity_escape__(ptr); + ptr = __coverity_alloc__(size); + if (!ptr) { + __coverity_panic__(); + } + /* + * Memory beyond the old size isn't actually initialized. Can't + * model that. See Coverity's realloc() model + */ + __coverity_writeall__(ptr); + __coverity_mark_as_afm_allocated__(ptr, AFM_free); + return ptr; } void *g_try_malloc(size_t size) { - return g_try_malloc_n(1, size); + int nomem; + + if (nomem) { + return NULL; + } + return g_malloc(size); } void *g_try_malloc0(size_t size) { - return g_try_malloc0_n(1, size); + int nomem; + + if (nomem) { + return NULL; + } + return g_malloc0(size); } void *g_try_realloc(void *ptr, size_t size) { - return g_try_realloc_n(ptr, 1, size); + int nomem; + + if (nomem) { + return NULL; + } + return g_realloc(ptr, size); } /* Other glib functions */