From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876791; cv=none; d=zohomail.com; s=zohoarc; b=hZIXwyzw3+7EJTAJIaaW1Tm9rLzPhcAvxBldwgblwAiwNoM2tZC1fRI8Jpt34b8/2fuiTW6qmsiyPy5GY8P7Ffe8PgBTCnYYCrwi/cH18vDQimgqy1flxOUkxVX5MHvu6u19xnW9bWWMdaDUTr1JvbWPkYztnkXnFYOSg+kyU3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876791; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c9DI6AAsVfYANdpqWn77PRtU8xlVrgWkxwckQG3CZwA=; b=hmaDX/MDR6T254eHDJlZ/JV9eIxcUfFZD/pyFto5vsfWOFpwkcZzXQnQXXVQLnEWbIkCESbnqLk2N1Jn2P0tWx41K6iXqveIM8A5XX2ksa+ue8j3gOUAIDAc+ouO4mXEH9vwUAo8i52reloCmlelHTtgxbbgKGjG6eg1G4h8aSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876791268827.2625992449192; Wed, 8 Feb 2023 09:19:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo6d-0003XN-18; Wed, 08 Feb 2023 12:19:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6Z-0003X5-2K for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:19:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6X-0000Kp-7E for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:19:34 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-448-rhIuwYMEPACHqi1pwCFzgA-1; Wed, 08 Feb 2023 12:19:30 -0500 Received: by mail-ed1-f69.google.com with SMTP id bo27-20020a0564020b3b00b004a6c2f6a226so12561461edb.15 for ; Wed, 08 Feb 2023 09:19:29 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id q26-20020a170906a09a00b007aece68483csm8556368ejy.193.2023.02.08.09.19.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c9DI6AAsVfYANdpqWn77PRtU8xlVrgWkxwckQG3CZwA=; b=A/c2CWBV97uGkJvn4fj5Co4C9m7qqkG1ML+eV/Rz5PV5ZhULNSMOOp8x7BNK6x31ZJnWZp vMnbszbm/V9QKQa4M8a5T0YQwT0oX/b6kzO4BgEW9s9zeQudAeaKxkwjfkYARTVnuH4UJ/ ZKQPds5yJEaSJBLCJHuUP/hGf0E26cE= X-MC-Unique: rhIuwYMEPACHqi1pwCFzgA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c9DI6AAsVfYANdpqWn77PRtU8xlVrgWkxwckQG3CZwA=; b=lUthNm7w4lQ/mqoHX6iA6VL/sOUBIEHCySLdr5yomjVd0QW+DPFyajA0qUe+MV8Por r7HHmpZH+b89Hs7TRpBOuu0ju1soz4nFXeyFZblFRatfSh9Nhv7YhGPCDO4YZUMMeUoV yBFcI8UxPm/HDGjnoA6nD6vi396d3+9NS5Fhd2JymC14+LC+7vckn6Umyo6gnn5udmmv IA0jJMB+PfeYjfyRbS1U4UCQN46ZwCfgnfMgnGb0+QQBJNUF6mG5+JRG2iBDC6yXc6dt jQrF3uxfQiUin8X+wrKDnR6zI1Ak0FsexAwYYHgDqIJ8TdZ3mZLYn92vrwLrBhcAxzRS a4FQ== X-Gm-Message-State: AO0yUKWtyFZnrfd3wDqg7odrgq5C0wNX5Ks8JYVa6Y5wtfBZNhQDOtef P9DX2oq6jupcP/LLy4j568hBA3qxlxyMMYWXCJb3awIcvYQjQbzcseTGkYOeBchrVDksBPEK7vb SDfkpKvCXk0X573AwWpMam58HQe6WiN7w4i9s1BwMuSMZ1+U2n2ageq4hZxMKRxCihTBpfW3W X-Received: by 2002:a50:c316:0:b0:4aa:b38d:772f with SMTP id a22-20020a50c316000000b004aab38d772fmr8459774edb.31.1675876768437; Wed, 08 Feb 2023 09:19:28 -0800 (PST) X-Google-Smtp-Source: AK7set8LdYt41NED4pVuLecDO6Xr3QKtnCMETBt5VREAwFXC5QJeBuGoMGp2+eE/ABNffzcCx97tGg== X-Received: by 2002:a50:c316:0:b0:4aa:b38d:772f with SMTP id a22-20020a50c316000000b004aab38d772fmr8459751edb.31.1675876768045; Wed, 08 Feb 2023 09:19:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/11] build: make meson-buildoptions.sh stable Date: Wed, 8 Feb 2023 18:19:12 +0100 Message-Id: <20230208171922.95048-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876792170100001 Content-Type: text/plain; charset="utf-8" The library directory can change depending on the multilib setup of the hos= t. It would be even better to detect it in configure with the same algorithm that Meson uses, but the important thing to avoid confusing developers is to have identical contents of scripts/meson-buildoptions.sh, independent of the distro and architecture on which it was created. So, for now just give a custom default value to libdir. Signed-off-by: Paolo Bonzini --- scripts/meson-buildoptions.py | 7 +++++-- scripts/meson-buildoptions.sh | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/meson-buildoptions.py b/scripts/meson-buildoptions.py index 3e2b4785388f..a04dcc70a5b7 100755 --- a/scripts/meson-buildoptions.py +++ b/scripts/meson-buildoptions.py @@ -61,7 +61,10 @@ =20 # Convert the default value of an option to the string used in # the help message -def value_to_help(value): +def get_help(opt): + if opt["name"] =3D=3D "libdir": + return 'system default' + value =3D opt["value"] if isinstance(value, list): return ",".join(value) if isinstance(value, bool): @@ -88,7 +91,7 @@ def sh_print(line=3D""): def help_line(left, opt, indent, long): right =3D f'{opt["description"]}' if long: - value =3D value_to_help(opt["value"]) + value =3D get_help(opt) if value !=3D "auto" and value !=3D "": right +=3D f" [{value}]" if "choices" in opt and long: diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 0f71e92dcba6..d663c9cadfbe 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -49,7 +49,7 @@ meson_options_help() { printf "%s\n" ' --includedir=3DVALUE Header file directory [inclu= de]' printf "%s\n" ' --interp-prefix=3DVALUE where to find shared librari= es etc., use %M for' printf "%s\n" ' cpu name [/usr/gnemul/qemu-%M]' - printf "%s\n" ' --libdir=3DVALUE Library directory [lib64]' + printf "%s\n" ' --libdir=3DVALUE Library directory [system de= fault]' printf "%s\n" ' --libexecdir=3DVALUE Library executable directory= [libexec]' printf "%s\n" ' --localedir=3DVALUE Locale data directory [share= /locale]' printf "%s\n" ' --localstatedir=3DVALUE Localstate data directory [/= var/local]' --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876887; cv=none; d=zohomail.com; s=zohoarc; b=Rh0KwKzlObRY4e6ADxWy0h6p8BOb+w3cZjsNhb0JZA8JldsNy1lQ5y7V1fSnCi+WH+YMt2zQGQs0Q3lx6VSyzvQ4+TCUUdAvjyPcKV7CHoJqgYzgXfwHdBdruvcEwuQ52vgnXMOnWXx10pIhZXcphCwrSi04iy5Jq5d3jjAKEOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876887; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3+vL4OFtafgQgZupdNxcfjPLno/cd7zOHkTcPOHnfyg=; b=ji9ftb3InSkp9I3BUOEq/jBMVnx+5OnC7p9GTluLD1npPINFhAH8pVbzkB+e2W2fc7V5Q0L2dJQcHipJTuNcP2w93AfXMy4JmD9mFv87ndUnr7c+qj2myBD18m7gD/mDcIjL2Lp5sGplhZanFQMrogd93WlveC7bO4lTVpncpSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876887984802.9348537405638; Wed, 8 Feb 2023 09:21:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7W-0005VE-GW; Wed, 08 Feb 2023 12:20:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo7V-0005Rt-6q for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo7T-0001du-4R for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:32 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-641-N_y0A9f9OL6Uoah6VUEP5g-1; Wed, 08 Feb 2023 12:19:50 -0500 Received: by mail-ej1-f69.google.com with SMTP id xh12-20020a170906da8c00b007413144e87fso13618692ejb.14 for ; Wed, 08 Feb 2023 09:19:43 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id bn18-20020a170906c0d200b0087f68a2681bsm8593567ejb.96.2023.02.08.09.19.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3+vL4OFtafgQgZupdNxcfjPLno/cd7zOHkTcPOHnfyg=; b=QsiBZ1cWAlTc9bIL0X94QsNEaGNDUb9cIFJJzkZ/N/rO0Rjd/wb+mfwc3JHfJo/S8u1Wkz fCoFyGVbYhFri8kDTAkw5wjIAmPcLbHcBySnYp6vji8V7OT8aw+FO1Ww5WnUsjPTQ1a9qG 2aoP/9hQSWyuI+I6QoF0po/CA9dKTA0= X-MC-Unique: N_y0A9f9OL6Uoah6VUEP5g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+vL4OFtafgQgZupdNxcfjPLno/cd7zOHkTcPOHnfyg=; b=y+m9ADwr3Kw5K6anyRmZXxYlkhHNQYPw7wfcq++k9Nsg9vMtGaa4RmEBpwVzpykjZN kfXyLFFW/T80oCFj79DmiS4RarSRMQYwszw6Ovdl2Mr+t9BfbW7B3cn8+mg9PfAdH7hw uVifnxVj12yGUhFAuSZpDBpUbDXt53hkIXH3pzyMz3HItulUcHq1NRLizl7uVxDtu2u8 BWeh8CiRFjBL6C3pcS4GZms4XrqynBuEcBDM6FPqAG5V0Lej01FvMci5lrzvnrNB/iRK c6hOiQHzWlkB/GYEf7YXMz8DhuQ6fx95jA8hpsMIUYB0je96CZ7hIHbMS4SZfPkoYHQt Gi4A== X-Gm-Message-State: AO0yUKV5SCvOtFuBUHgKAZmr60HmrsA345/3cXMdwvG5dunYDV1mK7kU 8zQdOCxkWzGiqRrVwQoWCmHDS2pmo1IOFEoBHbK06VoY3TcVfRm1A1/sM9iIgJw+cu1iOHQneN6 0pgRZ2EhlVoDjs+bAWYqJZqKO4NOPe57TlIbkGnnFlwiq/OeJHsl6Zwip+g+d8pxFp7X9Il/E X-Received: by 2002:a17:906:e0c9:b0:88a:1ea9:a5ea with SMTP id gl9-20020a170906e0c900b0088a1ea9a5eamr8250709ejb.65.1675876770798; Wed, 08 Feb 2023 09:19:30 -0800 (PST) X-Google-Smtp-Source: AK7set+Yj9yQmTM7V4YHfVARujIyBTHZt56S5+GmZMv2tuaECNMujeijuZdVhPE6mg3Rqqbjg22hWg== X-Received: by 2002:a17:906:e0c9:b0:88a:1ea9:a5ea with SMTP id gl9-20020a170906e0c900b0088a1ea9a5eamr8250690ejb.65.1675876770457; Wed, 08 Feb 2023 09:19:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/11] remove unnecessary extern "C" blocks Date: Wed, 8 Feb 2023 18:19:13 +0100 Message-Id: <20230208171922.95048-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876888687100001 Content-Type: text/plain; charset="utf-8" A handful of header files in QEMU are wrapped with extern "C" blocks. These are not necessary: there are C++ source files anymore in QEMU, and even where there were some, they did not include most of these files anyway. Remove them for consistency. Signed-off-by: Paolo Bonzini --- include/disas/dis-asm.h | 8 -------- include/qemu/bswap.h | 8 -------- include/qemu/envlist.h | 8 -------- include/qemu/rcu.h | 8 -------- include/qemu/rcu_queue.h | 8 -------- include/qemu/uri.h | 7 ------- 6 files changed, 47 deletions(-) diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h index 64247ecb11f4..32cda9ef14c5 100644 --- a/include/disas/dis-asm.h +++ b/include/disas/dis-asm.h @@ -11,10 +11,6 @@ =20 #include "qemu/bswap.h" =20 -#ifdef __cplusplus -extern "C" { -#endif - typedef void *PTR; typedef uint64_t bfd_vma; typedef int64_t bfd_signed_vma; @@ -506,8 +502,4 @@ static inline bfd_vma bfd_getb16(const bfd_byte *addr) =20 typedef bool bfd_boolean; =20 -#ifdef __cplusplus -} -#endif - #endif /* DISAS_DIS_ASM_H */ diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 3cbe52246b81..b1650daedf9c 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -1,10 +1,6 @@ #ifndef BSWAP_H #define BSWAP_H =20 -#ifdef __cplusplus -extern "C" { -#endif - #undef bswap16 #define bswap16(_x) __builtin_bswap16(_x) #undef bswap32 @@ -395,8 +391,4 @@ DO_STN_LDN_P(be) #undef le_bswaps #undef be_bswaps =20 -#ifdef __cplusplus -} -#endif - #endif /* BSWAP_H */ diff --git a/include/qemu/envlist.h b/include/qemu/envlist.h index b9addcc11f7d..6006dfae44c3 100644 --- a/include/qemu/envlist.h +++ b/include/qemu/envlist.h @@ -1,10 +1,6 @@ #ifndef ENVLIST_H #define ENVLIST_H =20 -#ifdef __cplusplus -extern "C" { -#endif - typedef struct envlist envlist_t; =20 envlist_t *envlist_create(void); @@ -15,8 +11,4 @@ int envlist_parse_set(envlist_t *, const char *); int envlist_parse_unset(envlist_t *, const char *); char **envlist_to_environ(const envlist_t *, size_t *); =20 -#ifdef __cplusplus -} -#endif - #endif /* ENVLIST_H */ diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index b063c6fde81d..313fc414bc2a 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -31,10 +31,6 @@ #include "qemu/sys_membarrier.h" #include "qemu/coroutine-tls.h" =20 -#ifdef __cplusplus -extern "C" { -#endif - /* * Important ! * @@ -196,8 +192,4 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_aut= o_unlock) void rcu_add_force_rcu_notifier(Notifier *n); void rcu_remove_force_rcu_notifier(Notifier *n); =20 -#ifdef __cplusplus -} -#endif - #endif /* QEMU_RCU_H */ diff --git a/include/qemu/rcu_queue.h b/include/qemu/rcu_queue.h index 0e53ddd5305e..4e6298d47307 100644 --- a/include/qemu/rcu_queue.h +++ b/include/qemu/rcu_queue.h @@ -28,11 +28,6 @@ #include "qemu/queue.h" #include "qemu/atomic.h" =20 -#ifdef __cplusplus -extern "C" { -#endif - - /* * List access methods. */ @@ -311,7 +306,4 @@ extern "C" { (var) && ((next) =3D qatomic_rcu_read(&(var)->field.sle_next), 1)= ; \ (var) =3D (next)) =20 -#ifdef __cplusplus -} -#endif #endif /* QEMU_RCU_QUEUE_H */ diff --git a/include/qemu/uri.h b/include/qemu/uri.h index d201c61260de..db5218c39ec0 100644 --- a/include/qemu/uri.h +++ b/include/qemu/uri.h @@ -53,10 +53,6 @@ #ifndef QEMU_URI_H #define QEMU_URI_H =20 -#ifdef __cplusplus -extern "C" { -#endif - /** * URI: * @@ -105,7 +101,4 @@ struct QueryParams *query_params_new (int init_alloc); extern QueryParams *query_params_parse (const char *query); extern void query_params_free (QueryParams *ps); =20 -#ifdef __cplusplus -} -#endif #endif /* QEMU_URI_H */ --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876930; cv=none; d=zohomail.com; s=zohoarc; b=lJEDilhOrETjrO1QkwQTImtIAt9lEixa/0UFDSxcTVMKlIuFJmKw57WOovZgrZuRme9E/Eruw44Vtm+TXyq1828/O17to3MSfLVyVLq7QtLRgBU6WC1rKUytOFGHkrz/qD3RaC4sb2FT0AIHA91Xa81BUqZMic2V3Ml1swo10Ic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876930; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SPg0YieviKIWcimw6lMQluCiclXWxrWfPNu19kNHRP8=; b=SXw8N9BK488FvtDpI+3p+Du/X1U+92QQSpwmjMpWWINGWae41SQF3AXlrSmr7Vu/iybJgcn+OgiFalV5gwaZIxiyjoMZT1MTBoCccP7kZU5awDmYaTacoTp3H6nY0fYzO7nkdYRiCJSrbaKi0NI96nfxt9qzi+sUYUKINbCztxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876930340406.2654878660014; Wed, 8 Feb 2023 09:22:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo71-0003dO-9c; Wed, 08 Feb 2023 12:20:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6n-0003an-O8 for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:19:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6m-0000bg-28 for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:19:49 -0500 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-620-POww_ki9Oj-g_jOVj5R3NQ-1; Wed, 08 Feb 2023 12:19:42 -0500 Received: by mail-ed1-f72.google.com with SMTP id p36-20020a056402502400b004aab6614de9so6257432eda.6 for ; Wed, 08 Feb 2023 09:19:39 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id sb1-20020a170906edc100b008888f4120d4sm8431183ejb.129.2023.02.08.09.19.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SPg0YieviKIWcimw6lMQluCiclXWxrWfPNu19kNHRP8=; b=MjCCCQEieFy+VnT1klqxNL0F+fedjvAOMFOQHMxJ+cogk6fJc0XzjN5KvhdMaSrG5BKjcQ p7jZupXgjgiwePd+5URSNPxhtqoGwGUsIaXNGV3Q+ihVQCRzln0cTbf0ykxyfoHCWbkmQD ZdGLB+mzO+d7fUS79UCeChXzzGoIZ5c= X-MC-Unique: POww_ki9Oj-g_jOVj5R3NQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SPg0YieviKIWcimw6lMQluCiclXWxrWfPNu19kNHRP8=; b=eY2lW1Y6OI+HpQwC8A780N790ixyhlFh0NI/+XTYBalHMRfFoH1Mfk3PoJ+dC0y2Zs tyTF7c5sMq90GDiS8d/Hcnqrlg4l8aDxaS/XT4uu2VnbClQuXE4RTfKg5nzxTjacWP/b vmyk7Cz/akCPnO56ausNvFt9Jnb1iAakTcVZdX2uz23u9gRybtrEVP9j2CZpsUVfsKrT UOW4jNXUnpNyhEd/p7zeosHbkXIMQQj3rUq/SfxsnslTtKA3NrThSFPvrj6ookOzh6Zc gytxs8AfbD4jrdoY8/oF3619JQf33iK6aPkgKp+IznjYyanbe4UmmoVHm+FOm2vDdyCX c2vw== X-Gm-Message-State: AO0yUKUmYteXVzreQdOQjuWlV18++/EYM1oX7/AIRKl8EJYogpSbp4OG k+eqSoGDq2n4UEJUlU9QjAgzMEqI9hbkf5D7SQ/0jXDMlmrg5m1ndWo8n56YCuPMlVudamqi8bE bLqAl3hFXX/yxSh3X3fa1uOnUkHY/GcIaZ6LUOTP1x7eUenM8x0BHP5Gzpd6Qp/lTTX5ebPbE X-Received: by 2002:a17:907:6e17:b0:8af:2af5:1191 with SMTP id sd23-20020a1709076e1700b008af2af51191mr617863ejc.18.1675876778216; Wed, 08 Feb 2023 09:19:38 -0800 (PST) X-Google-Smtp-Source: AK7set/r9MnG71111f8UeZllNRGXNnr2OJ8hwf63t+M+M07XIuX0eM3r4ackKkmLXhKbNcii3xE87Q== X-Received: by 2002:a17:907:6e17:b0:8af:2af5:1191 with SMTP id sd23-20020a1709076e1700b008af2af51191mr617838ejc.18.1675876777927; Wed, 08 Feb 2023 09:19:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/11] block/iscsi: fix double-free on BUSY or similar statuses Date: Wed, 8 Feb 2023 18:19:14 +0100 Message-Id: <20230208171922.95048-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876930891100001 Content-Type: text/plain; charset="utf-8" Commit 8c460269aa77 ("iscsi: base all handling of check condition on scsi_sense_to_errno", 2019-07-15) removed a "goto out" so that the same coroutine is re-entered twice; once from iscsi_co_generic_cb, once from the timer callback iscsi_retry_timer_expired. This can cause a crash. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1378 Reported-by: Grzegorz Zdanowski Signed-off-by: Paolo Bonzini --- block/iscsi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/iscsi.c b/block/iscsi.c index b3e10f40b649..3aacd0709f93 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -269,6 +269,7 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, timer_mod(&iTask->retry_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + retry_t= ime); iTask->do_retry =3D 1; + return; } else if (status =3D=3D SCSI_STATUS_CHECK_CONDITION) { int error =3D iscsi_translate_sense(&task->sense); if (error =3D=3D EAGAIN) { --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876891; cv=none; d=zohomail.com; s=zohoarc; b=ZzWHh9xBmZwjSjZAI2bHAsrP426aVH24RFG8nTLT0Y6Yj+t5+9KCXSbhQ5UZEA0z8yAAFeWlDgPlfl2EXfFbuO1mZCBMkFtfkiUIww1T/n0fsYnaU0f9DEnunoHc/qTNn1VBMznHT6pDRpmF4zpLMmavv3QCadwQu06kGlY/KMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876891; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7kPbqxOjC1Fp1Du88sVlCoM09v1WlV98R9rPPhknYA0=; b=g3fH0fqYrnRv9FU8qlVlQUg1WUlc2OoT2qP1FSsiqY1wwJL2Ge2pDNVD4QVLLO3r+e07CNbqiDMHAVLfEQIpWZgkW/oXufXI+9yGJCVLDBHFBKgrLii5dPB6vc5Xsw0dGF3UG2o92kEOJDTGrhlMBZCSmDnPQ0P47qqj3Mo1fjY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876891765416.883070282261; Wed, 8 Feb 2023 09:21:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7H-0004GB-1C; Wed, 08 Feb 2023 12:20:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6y-0003go-LP for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6w-0000o6-VD for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:00 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-198-H0vBsFrnPUKGrD8yh-Zpsw-1; Wed, 08 Feb 2023 12:19:43 -0500 Received: by mail-ej1-f72.google.com with SMTP id ge13-20020a170907908d00b008aac038968aso2392250ejb.21 for ; Wed, 08 Feb 2023 09:19:42 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id q26-20020a170906a09a00b007aece68483csm8556592ejy.193.2023.02.08.09.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7kPbqxOjC1Fp1Du88sVlCoM09v1WlV98R9rPPhknYA0=; b=RyyRcjfSYnv//NCi4YDlyokQcrmvkoBhF2hfy0sHnynH0toOhmDDg10p4SxnaN7EQ7jSGE qm54AQAUF3KaUAokv8RzvgYrxnczSEVMG9wXkSE4/Aype2GowsfToi39QLHfdm+F9/VJjB OFpTeK6Eq1o5+e2QzOWX79DcZNmdztg= X-MC-Unique: H0vBsFrnPUKGrD8yh-Zpsw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7kPbqxOjC1Fp1Du88sVlCoM09v1WlV98R9rPPhknYA0=; b=ZdD/TQUngxiYw5M86LwlC3QsqJfCBlNFdd7OcqqWEjDCk0Pf7ClqaO1pseTN5BU/TE EYkKeMp2y2HVm2ggyJ3T4D4KplAF5qg4dJC3QvoBYHAAH/L4RKegNpDNwcOFERynGq3v nHACbVyHBcofx9Lprcm73Vjy8LpOrd86Bn407N6VUZW7nmGVfShZo5xGPEvrNjLg1rMf NtMatLZ3xS1RJiDy/oBRticHupRLUSTNk/ZGfhcIj9AvceEBCzrAzbj+FXjgCXU7/98O yM3l3fjA5fEFfx83Xtiggk58jq0WISvoZI7NR/YHt0e12BuwMJ4Rn5nF0Yw+GbsouVeI sTQA== X-Gm-Message-State: AO0yUKVwZODrgmJo15EOK8g9ZYXvQsl41VM30K9l8z3h0UGOqqVxvgrY SWsxJd8HU3fY8pmVtj8yo8uDBIvi2VIXKjdtkzxYc3D6DqciAkrXSe2XUyaDfDHrhCnmVTSqFkn 5k/j7APhss6Aka8E3UtZ5R2fPbvyM7lbzJNzCcK6JdxCJxctUzxBW6IRggsm4cgXiLbVVnQ6N X-Received: by 2002:a17:906:1182:b0:878:605b:ffef with SMTP id n2-20020a170906118200b00878605bffefmr8993653eja.55.1675876780846; Wed, 08 Feb 2023 09:19:40 -0800 (PST) X-Google-Smtp-Source: AK7set/KBb2MrW0r5967WSLGWz1Gh+xdGj89XHQi/O7o5CPalBYg4dmyREs/n3/ivzIAiK+e1zrmbw== X-Received: by 2002:a17:906:1182:b0:878:605b:ffef with SMTP id n2-20020a170906118200b00878605bffefmr8993630eja.55.1675876780465; Wed, 08 Feb 2023 09:19:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Thomas Huth Subject: [PULL 04/11] vl: catch [accel] entry without accelerator Date: Wed, 8 Feb 2023 18:19:15 +0100 Message-Id: <20230208171922.95048-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876892708100007 Content-Type: text/plain; charset="utf-8" Avoid a SIGSEGV and return an error instead. Reported-by: Thomas Huth Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1439 Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index b2ee3fee3f06..06c9c931565e 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2204,14 +2204,18 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) int ret; bool qtest_with_kvm; =20 + if (!acc) { + error_setg(&error_fatal, QERR_MISSING_PARAMETER, "accel"); + goto bad; + } + qtest_with_kvm =3D g_str_equal(acc, "kvm") && qtest_chrdev !=3D NULL; =20 if (!ac) { - *p_init_failed =3D true; if (!qtest_with_kvm) { error_report("invalid accelerator %s", acc); } - return 0; + goto bad; } accel =3D ACCEL(object_new_with_class(OBJECT_CLASS(ac))); object_apply_compat_props(OBJECT(accel)); @@ -2221,14 +2225,17 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) =20 ret =3D accel_init_machine(accel, current_machine); if (ret < 0) { - *p_init_failed =3D true; if (!qtest_with_kvm || ret !=3D -ENOENT) { error_report("failed to initialize %s: %s", acc, strerror(-ret= )); } - return 0; + goto bad; } =20 return 1; + +bad: + *p_init_failed =3D true; + return 0; } =20 static void configure_accelerators(const char *progname) --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876821; cv=none; d=zohomail.com; s=zohoarc; b=bSnTwZl4Qdv3tK4WZuh40K4pRXQPXnarQJ3dRL3NvlT8llnYRNR/m/QE3x04EnGczrXNkWxef9kaVK7MJ1nYu+1nxvBfhvgZ7iOX4ZSKRf3xFICMmWgQlh+1pb49JJgzPV4hEotQ1wcay30Yqnoysr+Pl/tl/c3kStOmCNurI/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876821; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3jKWUVNkgNe/yvskNRzJo8AnQAUPutISJ0+zSYfHtwc=; b=BG5ucfOuGDrD0friRU/oTHF3jI3G10Xae3YetaN0TwZ76KjXPtRtGTdKU8I6Y5ZgtkwTLbB7Hbz9mHoZsr/KI8KpCzHG6bkqHV3549kt1K9AifC7NVJy0ybXqyZlVpHgh025IaZGvuwsZMruSP0MnxQejSJ5y/o1tEgq4eJSRrE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876821174452.6299647466824; Wed, 8 Feb 2023 09:20:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7D-0003wB-W6; Wed, 08 Feb 2023 12:20:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6z-0003gu-V8 for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6y-0000q8-B9 for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:01 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-168-8tAzswdQPXu3PUM8yj8agw-1; Wed, 08 Feb 2023 12:19:48 -0500 Received: by mail-ed1-f70.google.com with SMTP id eo7-20020a056402530700b004aab4319cedso6369375edb.2 for ; Wed, 08 Feb 2023 09:19:45 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id c19-20020a17090603d300b0088519b9206bsm8493272eja.130.2023.02.08.09.19.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3jKWUVNkgNe/yvskNRzJo8AnQAUPutISJ0+zSYfHtwc=; b=KtOlOeFLKyf1xWrbFsMTBkf2CxJUcDRz1lfXAA7SD1O+rdmZpLok5rc2eEwrj0uT4rOtTk CXuumJf+wpmMM1anqBedftEqYfSsQ69Zqq8mGiAGiakZ52BBeM4ce1TcRlvtQTFQCr0wsW JOQw9Q+5q1/jqkLw5icgLYR/8QPQlb4= X-MC-Unique: 8tAzswdQPXu3PUM8yj8agw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3jKWUVNkgNe/yvskNRzJo8AnQAUPutISJ0+zSYfHtwc=; b=5F3xZCo32XHcS6329cXDMeRxdZubci3cPPRPJ5XXzuTmS9VI5F0/lpwWXtl/lSht2K ubngrqBxd577pxKYh73Qnn6fUOKOfiaEmbd1SnEoN3y3vDkH/hgMSThkjyNNARWeBbCT FXBd1VHiZjkfqUQDApo47VzoWhG612l12WT068rW/3VnJycIHJ5+wXnTD3d58zp++GRX 4TvL11rnzH85B4k0tcky1lO5BQgjwpFddUNfSMf00sXvID9uHzwLRKyEFjdBLav3mW2n F0+bA3HJNQMbexpAe94libMNDM5WaqEBPLE9h5u2kkHUDtdsOGuLEHgu8GsFBgXduZda c87A== X-Gm-Message-State: AO0yUKXG2sg6/GTTvzPESmHiwcY75iHvksg80H1Nddy/P+kNicy0semm zYdOn0wT4JPz9RIy8MtIDE1coL3RqvIe0TZgC5CVB2+MZCAzJ5HPEhuDsy64w/+LE/nV8hjDJuT nUzx/NUHR0ACqPWc/ZWXUjTORXwPdw3pKA+xGn3b8kSlshklxksTsyRfx5pH/wq7iNWvECHmn X-Received: by 2002:a17:907:3f91:b0:8ae:bb1d:45e4 with SMTP id hr17-20020a1709073f9100b008aebb1d45e4mr2463168ejc.26.1675876783539; Wed, 08 Feb 2023 09:19:43 -0800 (PST) X-Google-Smtp-Source: AK7set/lZdcduHeXdEceUbMEE9MmDz1pQ6P8PLDIU4L9QBWpm/Ux3C+KEi1nE4yr/RoTj92DNngkNQ== X-Received: by 2002:a17:907:3f91:b0:8ae:bb1d:45e4 with SMTP id hr17-20020a1709073f9100b008aebb1d45e4mr2463151ejc.26.1675876783165; Wed, 08 Feb 2023 09:19:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/11] libqtest: split qtest_spawn_qemu function Date: Wed, 8 Feb 2023 18:19:16 +0100 Message-Id: <20230208171922.95048-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876822248100003 Content-Type: text/plain; charset="utf-8" In order to create a function that allows testing of invalid command lines, extract the parts of qtest_init_without_qmp_handshake that do not require any successful set up of sockets. Signed-off-by: Paolo Bonzini --- tests/qtest/libqtest.c | 103 ++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index d658222a191d..4e1f4fb91c55 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -360,60 +360,25 @@ static pid_t qtest_create_process(char *cmd) } #endif /* _WIN32 */ =20 -QTestState *qtest_init_without_qmp_handshake(const char *extra_args) +static QTestState *G_GNUC_PRINTF(1, 2) qtest_spawn_qemu(const char *fmt, .= ..) { - QTestState *s; - int sock, qmpsock, i; - gchar *socket_path; - gchar *qmp_socket_path; - gchar *command; - const char *qemu_binary =3D qtest_qemu_binary(); + va_list ap; + QTestState *s =3D g_new0(QTestState, 1); const char *trace =3D g_getenv("QTEST_TRACE"); g_autofree char *tracearg =3D trace ? g_strdup_printf("-trace %s ", trace) : g_strdup(""); + g_autoptr(GString) command =3D g_string_new(""); =20 - s =3D g_new(QTestState, 1); - - socket_path =3D g_strdup_printf("%s/qtest-%d.sock", - g_get_tmp_dir(), getpid()); - qmp_socket_path =3D g_strdup_printf("%s/qtest-%d.qmp", - g_get_tmp_dir(), getpid()); - - /* It's possible that if an earlier test run crashed it might - * have left a stale unix socket lying around. Delete any - * stale old socket to avoid spurious test failures with - * tests/libqtest.c:70:init_socket: assertion failed (ret !=3D -1): (-= 1 !=3D -1) - */ - unlink(socket_path); - unlink(qmp_socket_path); - - socket_init(); - sock =3D init_socket(socket_path); - qmpsock =3D init_socket(qmp_socket_path); - - qtest_client_set_rx_handler(s, qtest_client_socket_recv_line); - qtest_client_set_tx_handler(s, qtest_client_socket_send); + va_start(ap, fmt); + g_string_append_printf(command, CMD_EXEC "%s %s", + qtest_qemu_binary(), tracearg); + g_string_append_vprintf(command, fmt, ap); + va_end(ap); =20 qtest_add_abrt_handler(kill_qemu_hook_func, s); =20 - command =3D g_strdup_printf(CMD_EXEC "%s %s" - "-qtest unix:%s " - "-qtest-log %s " - "-chardev socket,path=3D%s,id=3Dchar0 " - "-mon chardev=3Dchar0,mode=3Dcontrol " - "-display none " - "%s" - " -accel qtest", - qemu_binary, tracearg, socket_path, - getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL, - qmp_socket_path, - extra_args ?: ""); + g_test_message("starting QEMU: %s", command->str); =20 - g_test_message("starting QEMU: %s", command); - - s->pending_events =3D NULL; - s->wstatus =3D 0; - s->expected_status =3D 0; #ifndef _WIN32 s->qemu_pid =3D fork(); if (s->qemu_pid =3D=3D 0) { @@ -434,14 +399,56 @@ QTestState *qtest_init_without_qmp_handshake(const ch= ar *extra_args) if (!g_setenv("QEMU_AUDIO_DRV", "none", true)) { exit(1); } - execlp("/bin/sh", "sh", "-c", command, NULL); + execlp("/bin/sh", "sh", "-c", command->str, NULL); exit(1); } #else - s->qemu_pid =3D qtest_create_process(command); + s->qemu_pid =3D qtest_create_process(command->str); #endif /* _WIN32 */ =20 - g_free(command); + return s; +} + +QTestState *qtest_init_without_qmp_handshake(const char *extra_args) +{ + QTestState *s; + int sock, qmpsock, i; + gchar *socket_path; + gchar *qmp_socket_path; + + socket_path =3D g_strdup_printf("%s/qtest-%d.sock", + g_get_tmp_dir(), getpid()); + qmp_socket_path =3D g_strdup_printf("%s/qtest-%d.qmp", + g_get_tmp_dir(), getpid()); + + /* + * It's possible that if an earlier test run crashed it might + * have left a stale unix socket lying around. Delete any + * stale old socket to avoid spurious test failures with + * tests/libqtest.c:70:init_socket: assertion failed (ret !=3D -1): (-= 1 !=3D -1) + */ + unlink(socket_path); + unlink(qmp_socket_path); + + socket_init(); + sock =3D init_socket(socket_path); + qmpsock =3D init_socket(qmp_socket_path); + + s =3D qtest_spawn_qemu("-qtest unix:%s " + "-qtest-log %s " + "-chardev socket,path=3D%s,id=3Dchar0 " + "-mon chardev=3Dchar0,mode=3Dcontrol " + "-display none " + "%s" + " -accel qtest", + socket_path, + getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL, + qmp_socket_path, + extra_args ?: ""); + + qtest_client_set_rx_handler(s, qtest_client_socket_recv_line); + qtest_client_set_tx_handler(s, qtest_client_socket_send); + s->fd =3D socket_accept(sock); if (s->fd >=3D 0) { s->qmp_fd =3D socket_accept(qmpsock); --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876837; cv=none; d=zohomail.com; s=zohoarc; b=GTp4MAEtmq3SkVFQVygJWEZ0WSMY4rRS18nyDP/kJm7JGLEqIVCTgwmpoXD7VPNBn7wAZjVI0TP8U0ft4wuI+2MUukiyosqhhSwLvy7auy1+DO8u4VVJrZ7ERv0YMIgiPhF0qdnpAH30b0D06MTG5ax6L7ovRSR0cAn9nSGFqis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876837; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0WVQ2SCJikMfdhu6sifF8wS8VeWU3oti7JZabc1triw=; b=GIsP7Gxfg9Kr4jw3SdKh8SzukQynbTn/WYjKwVCxKzdKS9Gvcwcs+UZGDRbaI04TX4sNZwGco1ZSzAjr0RQ9WGUlI828iasOZ4fooWhybEw9pf3GZtxCYgBfuTdh5IYPuHCz2nWgM3Ci+0aAgmR0U8DbPziKzi9rlG3r73j30xA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876836993606.4454861985213; Wed, 8 Feb 2023 09:20:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo79-0003og-By; Wed, 08 Feb 2023 12:20:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6y-0003gl-3q for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6w-0000nJ-9k for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:19:59 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-613-tserYXgsMqixeFv1WToS_g-1; Wed, 08 Feb 2023 12:19:55 -0500 Received: by mail-ed1-f70.google.com with SMTP id bo27-20020a0564020b3b00b004a6c2f6a226so12561894edb.15 for ; Wed, 08 Feb 2023 09:19:47 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id u7-20020a170906408700b0081bfc79beaesm8517609ejj.75.2023.02.08.09.19.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0WVQ2SCJikMfdhu6sifF8wS8VeWU3oti7JZabc1triw=; b=QO1/CerCD+rug1OfXcXtlGAaBdRw0Lm+fnMD9IiV7Tg5r8JdcH8nPie8UNOvJsC9w1xVZY qvVnzOoCAHvliyA8hH7dyJmyJz1Sno8HUIKDSJyL88juc/TwdVe2p+Ya7C+oYt7hMqJZRw l6vQqI+sDRT+r1t00i3vge1zLgxVtvI= X-MC-Unique: tserYXgsMqixeFv1WToS_g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0WVQ2SCJikMfdhu6sifF8wS8VeWU3oti7JZabc1triw=; b=jAl4e6Pn1dRmnbJwT8oXmZJBl6LTkyvWHyzD+gHZCrr7UmXWLPJignLts5nj60ZytS EmVZOrr/8StY2BZ9YZxQFeuHtU8QPr5J/l7Dz5mfuxTok4v64C9vBpytfb+E3hSNjjSB Efgb9GC3NI7AATHftac/Mq6TfRfWB0DYS9UijYnqHZG98Lf2xF+2EMIbqfnZ1B2Cpxpu 6CZsUIAgOvZOaum0VUgntJE4GSFQtiNzhD6t6Mym8IQufZm+5zrQak10irx+6TqHxt3K bVV4dee+U9D/BHC7IL8/Shrn4eFZRCIZK/k8K0jADWd+D1tkNvFVHZNKogfNi2SCz4h/ u3nw== X-Gm-Message-State: AO0yUKX/3h41HIoZXXvzAcGE46/YzAwlTIMH2ZMMsPa9abMeDq9dkJ8r 7G7V48+iKNHXAhDnNDbf6siXOqnsBq190d0WS+PTev63PnystP8w0NhXPE6c9XcIEcrcAgUEFhE sEHjYsahs3tKOKMoD0LDG17FqoxKnWGGw+hzDaNMakHJOifs2Wx8rwVBt3Sca/OFl8k+MWNNc X-Received: by 2002:a17:906:7c91:b0:88c:b4c5:4006 with SMTP id w17-20020a1709067c9100b0088cb4c54006mr9796901ejo.45.1675876785987; Wed, 08 Feb 2023 09:19:45 -0800 (PST) X-Google-Smtp-Source: AK7set8xP0pUKqRzA7LLZUJQ+HjskuJl/yz1V1nIbif0rgEuVl1PSz4bgMR3ibR3vApSPEfzvedwig== X-Received: by 2002:a17:906:7c91:b0:88c:b4c5:4006 with SMTP id w17-20020a1709067c9100b0088cb4c54006mr9796879ejo.45.1675876785630; Wed, 08 Feb 2023 09:19:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/11] libqtest: ensure waitpid() is only called once Date: Wed, 8 Feb 2023 18:19:17 +0100 Message-Id: <20230208171922.95048-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876838419100003 Content-Type: text/plain; charset="utf-8" If a test aborts after qtest_wait_qemu() is called, the SIGABRT hooks are still in place and waitpid() is called again. The second time it is called, the process does not exist anymore and the system call fails. Move the s->qemu_pid =3D -1 assignment to qtest_wait_qemu() to make it idempotent, and anyway remove the SIGABRT hook as well to avoid that qtest_check_status() is called twice. Because of the extra call, qtest_remove_abrt_handler() now has to be made idempotent as well. Signed-off-by: Paolo Bonzini --- tests/qtest/libqtest.c | 55 +++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 4e1f4fb91c55..ce5f235e25f1 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -158,6 +158,7 @@ bool qtest_probe_child(QTestState *s) CloseHandle((HANDLE)pid); #endif s->qemu_pid =3D -1; + qtest_remove_abrt_handler(s); } return false; } @@ -169,6 +170,8 @@ void qtest_set_expected_status(QTestState *s, int statu= s) =20 static void qtest_check_status(QTestState *s) { + assert (s->qemu_pid =3D=3D -1); + /* * Check whether qemu exited with expected exit status; anything else = is * fishy and should be logged with as much detail as possible. @@ -202,36 +205,40 @@ static void qtest_check_status(QTestState *s) =20 void qtest_wait_qemu(QTestState *s) { + if (s->qemu_pid !=3D -1) { #ifndef _WIN32 - pid_t pid; - uint64_t end; + pid_t pid; + uint64_t end; =20 - /* poll for a while until sending SIGKILL */ - end =3D g_get_monotonic_time() + WAITPID_TIMEOUT * G_TIME_SPAN_SECOND; + /* poll for a while until sending SIGKILL */ + end =3D g_get_monotonic_time() + WAITPID_TIMEOUT * G_TIME_SPAN_SEC= OND; =20 - do { - pid =3D waitpid(s->qemu_pid, &s->wstatus, WNOHANG); - if (pid !=3D 0) { - break; + do { + pid =3D waitpid(s->qemu_pid, &s->wstatus, WNOHANG); + if (pid !=3D 0) { + break; + } + g_usleep(100 * 1000); + } while (g_get_monotonic_time() < end); + + if (pid =3D=3D 0) { + kill(s->qemu_pid, SIGKILL); + pid =3D RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); } - g_usleep(100 * 1000); - } while (g_get_monotonic_time() < end); =20 - if (pid =3D=3D 0) { - kill(s->qemu_pid, SIGKILL); - pid =3D RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); - } - - assert(pid =3D=3D s->qemu_pid); + assert(pid =3D=3D s->qemu_pid); #else - DWORD ret; + DWORD ret; =20 - ret =3D WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); - assert(ret =3D=3D WAIT_OBJECT_0); - GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); - CloseHandle((HANDLE)s->qemu_pid); + ret =3D WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); + assert(ret =3D=3D WAIT_OBJECT_0); + GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); + CloseHandle((HANDLE)s->qemu_pid); #endif =20 + s->qemu_pid =3D -1; + qtest_remove_abrt_handler(s); + } qtest_check_status(s); } =20 @@ -245,7 +252,6 @@ void qtest_kill_qemu(QTestState *s) TerminateProcess((HANDLE)s->qemu_pid, s->expected_status); #endif qtest_wait_qemu(s); - s->qemu_pid =3D -1; return; } =20 @@ -307,6 +313,11 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *= data) void qtest_remove_abrt_handler(void *data) { GHook *hook =3D g_hook_find_data(&abrt_hooks, TRUE, data); + + if (!hook) { + return; + } + g_hook_destroy_link(&abrt_hooks, hook); =20 /* Uninstall SIGABRT handler on last instance */ --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876898; cv=none; d=zohomail.com; s=zohoarc; b=WSHogShLFmxbIe97d4JDKKzU260AoyTWWL3n2Bh9/euPxGlT14b3Z29f2nxvyG0OOIovqrXEUijfIPeFrPj9k4qmB4pjEf2H6saWspuY2wP4Rd6GdNUY8tDuQ76u5wlDO8sR89Q6j92qkm0X1xMT1dIAmFVWeqn3xaVXuzubs4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876898; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JRoAe9ECLPd8dIco7IoMD9qC7H0WOGm1xgJWWsd7V30=; b=KCX4U4eOirpat41QL5Wv6SHqWp7NMPJBV2e1AII9gLV6v0ylzJb4Bu6yFkiUYRqZwAJ9Fs1rFO9G8d/ibtoU+2BWE94Kzvp5424FU6b8IqQw6IJLuD/Ejc6cxNx9OiuxVN3b0f2wWAVCV8t+ajKydaW+J/JsPN86hhLsaED3Sk4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876898427517.9966442724032; Wed, 8 Feb 2023 09:21:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7F-00044q-D1; Wed, 08 Feb 2023 12:20:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo7C-0003sZ-Bj for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo79-0001Do-Np for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:13 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-619--QbbN_iSOfKhotgYP0AYAQ-1; Wed, 08 Feb 2023 12:19:54 -0500 Received: by mail-ed1-f69.google.com with SMTP id s3-20020a50ab03000000b0049ec3a108beso12740239edc.7 for ; Wed, 08 Feb 2023 09:19:52 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id r3-20020a50d683000000b004aabb714230sm3695347edi.35.2023.02.08.09.19.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JRoAe9ECLPd8dIco7IoMD9qC7H0WOGm1xgJWWsd7V30=; b=VHaD9b8wU6PoiOj0gRFrzrHwkvmaxbSDrc5b62M9DST36dJpKla58UQ+rZUFGrYJ10rNHh KsxWDzCMqcprqUHG5ri/0cGurKsaH2immJ+Zfea/gbulrHyFn9Ri5FFwQJyKw/Cxgdlv63 LcIvRuM5r6Ujs/f7DRyYhXWyX1b3R/0= X-MC-Unique: -QbbN_iSOfKhotgYP0AYAQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JRoAe9ECLPd8dIco7IoMD9qC7H0WOGm1xgJWWsd7V30=; b=rVz0b3AT6SBIgW5bpuKKX7rVS5JjGUmluPQWYFhMBE5GJe5rsOWjq/vjQuOQatinhN UJNKYObLvK3reLbxmfI8y1I+EbGTlb0PlpAWrxU02PtjWKf8+JhX5jUITyidpw6x4H2j qMlD8voLk0HdPftFI2/M4emnGvKzu3Bty5cpT9sfo+H7oxi4ztN8r5EYmCWcNEPIZPS2 47F6xBL0sarpa6aGWV8t9tCUG7IsjmpmuLdHCrErWx4q3BkJM/WlNS64NFNxkv3AANJ7 ASH7jiQXPNmEOr/dBS7qh57P3mx54qvRbRgdpOsgC1YvWf42jjRpzDJHjx+oDw2fFiEQ DuQw== X-Gm-Message-State: AO0yUKX+3lGlizlbbmMCEAqkDwz4Jq9d3v0LcjjEkqSw2ANzQYjznmC4 DNeJ4pakr8UqdKNgFkvUo76KDXUDJzE/276MMsVRE0T0R6Y0Cs4ViTr7QoQqxY/cUY6IPZ44H7b X/4fA9jaTPZcD+dpPpZv6+00nD1KF0KqvrH172eslQydK32KDfzfrOs63d7LkZ4K/oozSf7cp X-Received: by 2002:a50:d7cd:0:b0:4a0:af87:b3ab with SMTP id m13-20020a50d7cd000000b004a0af87b3abmr7970793edj.36.1675876788598; Wed, 08 Feb 2023 09:19:48 -0800 (PST) X-Google-Smtp-Source: AK7set/ztC8DvRzx+dQRZZSHl8UroLCyiZKC0mr8PCo1Ft8Zlpp4QUEdN+5xgZ/vz+23qcjLdCNH7g== X-Received: by 2002:a50:d7cd:0:b0:4a0:af87:b3ab with SMTP id m13-20020a50d7cd000000b004a0af87b3abmr7970774edj.36.1675876788217; Wed, 08 Feb 2023 09:19:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/11] readconfig-test: add test for accelerator configuration Date: Wed, 8 Feb 2023 18:19:18 +0100 Message-Id: <20230208171922.95048-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876900782100003 Content-Type: text/plain; charset="utf-8" Test that it does not cause a SIGSEGV, and cover a valid configuration as well. Signed-off-by: Paolo Bonzini --- tests/qtest/libqtest.c | 28 +++++++++++++++++----- tests/qtest/libqtest.h | 12 ++++++++++ tests/qtest/readconfig-test.c | 45 ++++++++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index ce5f235e25f1..4fba2bb27f06 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -420,6 +420,26 @@ static QTestState *G_GNUC_PRINTF(1, 2) qtest_spawn_qem= u(const char *fmt, ...) return s; } =20 +QTestState *G_GNUC_PRINTF(1, 0) qtest_init_bare(const char *args) +{ + QTestState *s =3D qtest_spawn_qemu("%s", args); + + /* + * Stopping QEMU for debugging is not supported on Windows. + * + * Using DebugActiveProcess() API can suspend the QEMU process, + * but gdb cannot attach to the process. Using the undocumented + * NtSuspendProcess() can suspend the QEMU process and gdb can + * attach to the process, but gdb cannot resume it. + */ +#ifndef _WIN32 + if (getenv("QTEST_STOP")) { + kill(s->qemu_pid, SIGSTOP); + } +#endif + return s; +} + QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; @@ -477,12 +497,8 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) } =20 /* - * Stopping QEMU for debugging is not supported on Windows. - * - * Using DebugActiveProcess() API can suspend the QEMU process, - * but gdb cannot attach to the process. Using the undocumented - * NtSuspendProcess() can suspend the QEMU process and gdb can - * attach to the process, but gdb cannot resume it. + * Stopping QEMU for debugging is not supported on Windows; + * see qtest_init_bare for more information. */ #ifndef _WIN32 if (getenv("QTEST_STOP")) { diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index fcf1c3c3b36f..7ca7df26a2c0 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -23,6 +23,18 @@ =20 typedef struct QTestState QTestState; =20 +/** + * qtest_init_bare: + * @extra_args: other arguments to pass to QEMU. CAUTION: these + * arguments are subject to word splitting and shell evaluation. + * + * Return a QTestState instance without automatically creating any + * sockets for QMP and qtest communication. + * + * Returns: #QTestState instance. + */ +QTestState *qtest_init_bare(const char *args); + /** * qtest_initf: * @fmt: Format for creating other arguments to pass to QEMU, formatted diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c index 9ef870643dcd..4c11883e36eb 100644 --- a/tests/qtest/readconfig-test.c +++ b/tests/qtest/readconfig-test.c @@ -19,13 +19,11 @@ #include "qapi/qmp/qstring.h" #include "qemu/units.h" =20 -static QTestState *qtest_init_with_config(const char *cfgdata) +static char *qtest_write_config(const char *cfgdata) { GError *error =3D NULL; - g_autofree char *args =3D NULL; int cfgfd =3D -1; - g_autofree char *cfgpath =3D NULL; - QTestState *qts; + char *cfgpath; ssize_t ret; =20 cfgfd =3D g_file_open_tmp("readconfig-test-XXXXXX", &cfgpath, &error); @@ -38,13 +36,14 @@ static QTestState *qtest_init_with_config(const char *c= fgdata) unlink(cfgpath); } g_assert_cmpint(ret, =3D=3D, strlen(cfgdata)); + return cfgpath; +} =20 - args =3D g_strdup_printf("-nodefaults -machine none -readconfig %s", c= fgpath); - - qts =3D qtest_init(args); - +static QTestState *qtest_init_with_config(const char *cfgdata) +{ + g_autofree char *cfgpath =3D qtest_write_config(cfgdata); + QTestState *qts =3D qtest_initf("-nodefaults -machine none -readconfig= %s", cfgpath); unlink(cfgpath); - return qts; } =20 @@ -176,6 +175,32 @@ static void test_object_rng(void) qtest_quit(qts); } =20 +static void test_valid_accel(void) +{ + const char *cfgdata =3D + "[accel]\n" + "accel =3D \"qtest\"\n"; + + QTestState *qts =3D qtest_init_with_config(cfgdata); + qtest_quit(qts); +} + +static void test_invalid_accel(void) +{ + const char *cfgdata =3D + "[accel]\n" + "foo =3D \"bar\"\n"; + + g_autofree char *cfgpath =3D qtest_write_config(cfgdata); + g_autofree char *args =3D g_strdup_printf("-nodefaults -machine none -= readconfig %s", cfgpath); + QTestState *qts =3D qtest_init_bare(args); + + qtest_set_expected_status(qts, 1); + qtest_wait_qemu(qts); + g_free(qts); + unlink(cfgpath); +} + int main(int argc, char *argv[]) { const char *arch; @@ -192,6 +217,8 @@ int main(int argc, char *argv[]) #endif =20 qtest_add_func("readconfig/object-rng", test_object_rng); + qtest_add_func("readconfig/invalid-accel", test_invalid_accel); + qtest_add_func("readconfig/valid-accel", test_valid_accel); =20 return g_test_run(); } --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876922; cv=none; d=zohomail.com; s=zohoarc; b=aLHysL+JDHsO6q5o0mXsybISzjkWpEV/CWE+c4skCV6Gk3Do9VEp0oXXgV+FGAyDbp5cPnQtkH2PO4xvZ4ZU8z8au069zyM4EiRE4h5zgBqldu2ubEC0J0w+Vn6i6LKFQzSW/jEAl9wTMaEXsf5MRh2Hz+ScPP05S18p0XlKN1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876922; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n6S8f8jSlQQI+M5AqaNQXoEME6tyNRUu5phS9LX667o=; b=i1YZ53SRTKGSxonqEJMClKbN2rnzRMaS4H9fBQD8J+fOmhKC+IbYd6dl6VQBFRrX4la1K75wx7225h8s9i0CAZhayWYMtY7WBX2aU2KbislMs3+mSrYmOYc0x1wiJ12X+EyVYX/iU+3jUScyDSKGs5BVkb/g+Tdh3aOcYW/OqPk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876922104855.4950293593993; Wed, 8 Feb 2023 09:22:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7G-00047o-13; Wed, 08 Feb 2023 12:20:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo76-0003ku-SI for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo74-00019e-R6 for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:08 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-590-SWWpO--2Nt-lnQkMpBY_ug-1; Wed, 08 Feb 2023 12:19:58 -0500 Received: by mail-ej1-f70.google.com with SMTP id wz4-20020a170906fe4400b0084c7e7eb6d0so13639978ejb.19 for ; Wed, 08 Feb 2023 09:19:53 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id de48-20020a1709069bf000b0088cf92eb0e1sm8540034ejc.150.2023.02.08.09.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n6S8f8jSlQQI+M5AqaNQXoEME6tyNRUu5phS9LX667o=; b=SwWUINfzAQAx1ntqg/qw8jDHgM6boMaKf33Gj+na0VbfmkxgqTEVFyXaHcqeRauJADkaaX kUAjUfn3lt40xFH2kKG2+cz7POFSiYi0Y+25Y/OMYIMhQMpyF8m4z1d/Yafv6z9DdXdb6U ANDESElbFVkVtXUHpCR4O6YgsVq6gf0= X-MC-Unique: SWWpO--2Nt-lnQkMpBY_ug-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n6S8f8jSlQQI+M5AqaNQXoEME6tyNRUu5phS9LX667o=; b=anARRZBDEX8BjkVwQ63cEnD5AWbFc/ZaZ8liDDfItt4c/MnWW23oNfWytrcwoqLmjd VOcB7DdWtiBykwtXtIEiOGCUB1ypVHEe90Wk0n1Jz/6Y7VpqscVVKbOVa9XpjvfeyQ9w i1q60ARr1QrjldH6AeER9vr9xFcSn7HF/CeJCdIXfcoFK3fMaQeQWUwtS4+cuM908mZR 7hCJXvT5uRx04PAj9W+BKKZxVPAqjvpcRhVZHSXoybxgHTOAxn4qcdM6corJa7gv1xKN f5qSpBsAQm1k/6YtiR4cvau08LQUDlvjaAo/GlllkMnDh4fbzNkuO1SNgexCTfxXPH2d jZ2w== X-Gm-Message-State: AO0yUKVf2JuQXkni0/4fUNkD5AIhCq1mZbfiv940Q87nyAsLZZgWvLk6 ozd647s9zvvg2+qXi6turVAiBuOSdVkRulNIvZBHYJ3KY/HplR3GZhfV2EyNwofGuw5SzZ9aIJG tKacoijhDUKcYudwQRYkJbj0Ie3vnUbcyP+s6ObOiYUetOOyznVe8l1xUazdXF3sBxGd39fmV X-Received: by 2002:a17:907:2d92:b0:8aa:9c54:a285 with SMTP id gt18-20020a1709072d9200b008aa9c54a285mr8099781ejc.12.1675876791503; Wed, 08 Feb 2023 09:19:51 -0800 (PST) X-Google-Smtp-Source: AK7set/D+/KbhvaNBuxgnpHcJ8HA5o5/VLuJb/jEtfcwzCtTmj3KCUAKxybOXOVE/cSTSt91uzeUEA== X-Received: by 2002:a17:907:2d92:b0:8aa:9c54:a285 with SMTP id gt18-20020a1709072d9200b008aa9c54a285mr8099757ejc.12.1675876791204; Wed, 08 Feb 2023 09:19:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 08/11] tests/tcg/i386: Introduce and use reg_t consistently Date: Wed, 8 Feb 2023 18:19:19 +0100 Message-Id: <20230208171922.95048-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876922857100003 From: Richard Henderson Define reg_t based on the actual register width. Define the inlines using that type. This will allow input registers to 32-bit insns to be set to 64-bit values on x86-64, which allows testing various edge cases. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20230114230542.3116013-2-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- tests/tcg/i386/test-i386-bmi2.c | 182 ++++++++++++++++---------------- 1 file changed, 93 insertions(+), 89 deletions(-) diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi= 2.c index 5fadf47510f2..3c3ef85513e1 100644 --- a/tests/tcg/i386/test-i386-bmi2.c +++ b/tests/tcg/i386/test-i386-bmi2.c @@ -3,34 +3,40 @@ #include #include =20 +#ifdef __x86_64 +typedef uint64_t reg_t; +#else +typedef uint32_t reg_t; +#endif + #define insn1q(name, arg0) = \ -static inline uint64_t name##q(uint64_t arg0) = \ +static inline reg_t name##q(reg_t arg0) = \ { = \ - uint64_t result64; = \ + reg_t result64; = \ asm volatile (#name "q %1, %0" : "=3Dr"(result64) : "rm"(arg0)); = \ return result64; = \ } =20 #define insn1l(name, arg0) = \ -static inline uint32_t name##l(uint32_t arg0) = \ +static inline reg_t name##l(reg_t arg0) = \ { = \ - uint32_t result32; = \ + reg_t result32; = \ asm volatile (#name "l %k1, %k0" : "=3Dr"(result32) : "rm"(arg0)); = \ return result32; = \ } =20 #define insn2q(name, arg0, c0, arg1, c1) = \ -static inline uint64_t name##q(uint64_t arg0, uint64_t arg1) = \ +static inline reg_t name##q(reg_t arg0, reg_t arg1) = \ { = \ - uint64_t result64; = \ + reg_t result64; = \ asm volatile (#name "q %2, %1, %0" : "=3Dr"(result64) : c0(arg0), c1= (arg1)); \ return result64; = \ } =20 #define insn2l(name, arg0, c0, arg1, c1) = \ -static inline uint32_t name##l(uint32_t arg0, uint32_t arg1) = \ +static inline reg_t name##l(reg_t arg0, reg_t arg1) = \ { = \ - uint32_t result32; = \ + reg_t result32; = \ asm volatile (#name "l %k2, %k1, %k0" : "=3Dr"(result32) : c0(arg0),= c1(arg1)); \ return result32; = \ } @@ -65,130 +71,128 @@ insn1l(blsr, src) int main(int argc, char *argv[]) { uint64_t ehlo =3D 0x202020204f4c4845ull; uint64_t mask =3D 0xa080800302020001ull; - uint32_t result32; + reg_t result; =20 #ifdef __x86_64 - uint64_t result64; - /* 64 bits */ - result64 =3D andnq(mask, ehlo); - assert(result64 =3D=3D 0x002020204d4c4844); + result =3D andnq(mask, ehlo); + assert(result =3D=3D 0x002020204d4c4844); =20 - result64 =3D pextq(ehlo, mask); - assert(result64 =3D=3D 133); + result =3D pextq(ehlo, mask); + assert(result =3D=3D 133); =20 - result64 =3D pdepq(result64, mask); - assert(result64 =3D=3D (ehlo & mask)); + result =3D pdepq(result, mask); + assert(result =3D=3D (ehlo & mask)); =20 - result64 =3D pextq(-1ull, mask); - assert(result64 =3D=3D 511); /* mask has 9 bits set */ + result =3D pextq(-1ull, mask); + assert(result =3D=3D 511); /* mask has 9 bits set */ =20 - result64 =3D pdepq(-1ull, mask); - assert(result64 =3D=3D mask); + result =3D pdepq(-1ull, mask); + assert(result =3D=3D mask); =20 - result64 =3D bextrq(mask, 0x3f00); - assert(result64 =3D=3D (mask & ~INT64_MIN)); + result =3D bextrq(mask, 0x3f00); + assert(result =3D=3D (mask & ~INT64_MIN)); =20 - result64 =3D bextrq(mask, 0x1038); - assert(result64 =3D=3D 0xa0); + result =3D bextrq(mask, 0x1038); + assert(result =3D=3D 0xa0); =20 - result64 =3D bextrq(mask, 0x10f8); - assert(result64 =3D=3D 0); + result =3D bextrq(mask, 0x10f8); + assert(result =3D=3D 0); =20 - result64 =3D blsiq(0x30); - assert(result64 =3D=3D 0x10); + result =3D blsiq(0x30); + assert(result =3D=3D 0x10); =20 - result64 =3D blsiq(0x30ull << 32); - assert(result64 =3D=3D 0x10ull << 32); + result =3D blsiq(0x30ull << 32); + assert(result =3D=3D 0x10ull << 32); =20 - result64 =3D blsmskq(0x30); - assert(result64 =3D=3D 0x1f); + result =3D blsmskq(0x30); + assert(result =3D=3D 0x1f); =20 - result64 =3D blsrq(0x30); - assert(result64 =3D=3D 0x20); + result =3D blsrq(0x30); + assert(result =3D=3D 0x20); =20 - result64 =3D blsrq(0x30ull << 32); - assert(result64 =3D=3D 0x20ull << 32); + result =3D blsrq(0x30ull << 32); + assert(result =3D=3D 0x20ull << 32); =20 - result64 =3D bzhiq(mask, 0x3f); - assert(result64 =3D=3D (mask & ~INT64_MIN)); + result =3D bzhiq(mask, 0x3f); + assert(result =3D=3D (mask & ~INT64_MIN)); =20 - result64 =3D bzhiq(mask, 0x1f); - assert(result64 =3D=3D (mask & ~(-1 << 30))); + result =3D bzhiq(mask, 0x1f); + assert(result =3D=3D (mask & ~(-1 << 30))); =20 - result64 =3D rorxq(0x2132435465768798, 8); - assert(result64 =3D=3D 0x9821324354657687); + result =3D rorxq(0x2132435465768798, 8); + assert(result =3D=3D 0x9821324354657687); =20 - result64 =3D sarxq(0xffeeddccbbaa9988, 8); - assert(result64 =3D=3D 0xffffeeddccbbaa99); + result =3D sarxq(0xffeeddccbbaa9988, 8); + assert(result =3D=3D 0xffffeeddccbbaa99); =20 - result64 =3D sarxq(0x77eeddccbbaa9988, 8 | 64); - assert(result64 =3D=3D 0x0077eeddccbbaa99); + result =3D sarxq(0x77eeddccbbaa9988, 8 | 64); + assert(result =3D=3D 0x0077eeddccbbaa99); =20 - result64 =3D shrxq(0xffeeddccbbaa9988, 8); - assert(result64 =3D=3D 0x00ffeeddccbbaa99); + result =3D shrxq(0xffeeddccbbaa9988, 8); + assert(result =3D=3D 0x00ffeeddccbbaa99); =20 - result64 =3D shrxq(0x77eeddccbbaa9988, 8 | 192); - assert(result64 =3D=3D 0x0077eeddccbbaa99); + result =3D shrxq(0x77eeddccbbaa9988, 8 | 192); + assert(result =3D=3D 0x0077eeddccbbaa99); =20 - result64 =3D shlxq(0xffeeddccbbaa9988, 8); - assert(result64 =3D=3D 0xeeddccbbaa998800); + result =3D shlxq(0xffeeddccbbaa9988, 8); + assert(result =3D=3D 0xeeddccbbaa998800); #endif =20 /* 32 bits */ - result32 =3D andnl(mask, ehlo); - assert(result32 =3D=3D 0x04d4c4844); + result =3D andnl(mask, ehlo); + assert(result =3D=3D 0x04d4c4844); =20 - result32 =3D pextl((uint32_t) ehlo, mask); - assert(result32 =3D=3D 5); + result =3D pextl((uint32_t) ehlo, mask); + assert(result =3D=3D 5); =20 - result32 =3D pdepl(result32, mask); - assert(result32 =3D=3D (uint32_t)(ehlo & mask)); + result =3D pdepl(result, mask); + assert(result =3D=3D (uint32_t)(ehlo & mask)); =20 - result32 =3D pextl(-1u, mask); - assert(result32 =3D=3D 7); /* mask has 3 bits set */ + result =3D pextl(-1u, mask); + assert(result =3D=3D 7); /* mask has 3 bits set */ =20 - result32 =3D pdepl(-1u, mask); - assert(result32 =3D=3D (uint32_t)mask); + result =3D pdepl(-1u, mask); + assert(result =3D=3D (uint32_t)mask); =20 - result32 =3D bextrl(mask, 0x1f00); - assert(result32 =3D=3D (mask & ~INT32_MIN)); + result =3D bextrl(mask, 0x1f00); + assert(result =3D=3D (mask & ~INT32_MIN)); =20 - result32 =3D bextrl(ehlo, 0x1018); - assert(result32 =3D=3D 0x4f); + result =3D bextrl(ehlo, 0x1018); + assert(result =3D=3D 0x4f); =20 - result32 =3D bextrl(mask, 0x1038); - assert(result32 =3D=3D 0); + result =3D bextrl(mask, 0x1038); + assert(result =3D=3D 0); =20 - result32 =3D blsil(0xffff); - assert(result32 =3D=3D 1); + result =3D blsil(0xffff); + assert(result =3D=3D 1); =20 - result32 =3D blsmskl(0x300); - assert(result32 =3D=3D 0x1ff); + result =3D blsmskl(0x300); + assert(result =3D=3D 0x1ff); =20 - result32 =3D blsrl(0xffc); - assert(result32 =3D=3D 0xff8); + result =3D blsrl(0xffc); + assert(result =3D=3D 0xff8); =20 - result32 =3D bzhil(mask, 0xf); - assert(result32 =3D=3D 1); + result =3D bzhil(mask, 0xf); + assert(result =3D=3D 1); =20 - result32 =3D rorxl(0x65768798, 8); - assert(result32 =3D=3D 0x98657687); + result =3D rorxl(0x65768798, 8); + assert(result =3D=3D 0x98657687); =20 - result32 =3D sarxl(0xffeeddcc, 8); - assert(result32 =3D=3D 0xffffeedd); + result =3D sarxl(0xffeeddcc, 8); + assert(result =3D=3D 0xffffeedd); =20 - result32 =3D sarxl(0x77eeddcc, 8 | 32); - assert(result32 =3D=3D 0x0077eedd); + result =3D sarxl(0x77eeddcc, 8 | 32); + assert(result =3D=3D 0x0077eedd); =20 - result32 =3D shrxl(0xffeeddcc, 8); - assert(result32 =3D=3D 0x00ffeedd); + result =3D shrxl(0xffeeddcc, 8); + assert(result =3D=3D 0x00ffeedd); =20 - result32 =3D shrxl(0x77eeddcc, 8 | 128); - assert(result32 =3D=3D 0x0077eedd); + result =3D shrxl(0x77eeddcc, 8 | 128); + assert(result =3D=3D 0x0077eedd); =20 - result32 =3D shlxl(0xffeeddcc, 8); - assert(result32 =3D=3D 0xeeddcc00); + result =3D shlxl(0xffeeddcc, 8); + assert(result =3D=3D 0xeeddcc00); =20 return 0; } --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876926; cv=none; d=zohomail.com; s=zohoarc; b=QlD60Soscdy9pRd9SMFdvddCEL9VFRkN3FqBbMCMiUrhzB3yT5btOHAz9RyhZ1WQWab0iQ4uWPlqqpOqBCejQKJp2oOMAdFSjqQ9I8ri1Zfx+UH42YVmf7Y7/OosPB1EoHeJCrMGVgP+ch8jmfIkPhBGOR/kX9lnvNzbdKseySs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876926; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ta/RvWxoi3BYi01guIZtQWyrOdtMvFMGSaAl0lHjLvE=; b=JTvM15/CbQ6zjiVU6O+7V10hEqHLrmPNtHC3aYwwy1EQztbGIrQU2Sov3bgBugnMqfJyox0SpZTU3J8AB/NfGDor2Xl8eZ/b8c3+KjZJKggm6ekVttW2Cn992EBQ7CDdyE3F0wkmlqTaRapeGjgaaEVcXE79OuDHXAQpYUv87UI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16758769264301017.7809873254517; Wed, 8 Feb 2023 09:22:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7G-0004Ad-DT; Wed, 08 Feb 2023 12:20:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo7F-00043p-5c for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo7D-0001I3-7S for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:16 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-90-CIaJfLNHPU-iX_20VSUPfQ-1; Wed, 08 Feb 2023 12:20:01 -0500 Received: by mail-ed1-f71.google.com with SMTP id s11-20020a056402520b00b004aada311135so2881941edd.9 for ; Wed, 08 Feb 2023 09:19:56 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id r16-20020a170906a21000b00883ec4c63ddsm8589732ejy.146.2023.02.08.09.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ta/RvWxoi3BYi01guIZtQWyrOdtMvFMGSaAl0lHjLvE=; b=C7doRkrObdlForz4bZfVyEW7uj4z0cPt4F1gfTxJ0pc2CkSePIKTHop1ldwJdoy0q7j9oB wKVVHk3YLHhLM2yphgrjU3nm34d6h3W8UVDt793/v2qOu58mfzeToLnid9jdzDopItgTsi u+7LOLAmuTARxfAdYshX1RQIlWidy/M= X-MC-Unique: CIaJfLNHPU-iX_20VSUPfQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ta/RvWxoi3BYi01guIZtQWyrOdtMvFMGSaAl0lHjLvE=; b=ulRYWQaiqVt0tOpgZc2CUk761vaB36cRZcUcz8i9fSLO+xIGcS2aZyk27AnkESHhlP KuvrBmd//PknLcXozqn3+5XgB+hU7Qt2XNT9EmnUWbj1U06EPyguPCk1Bz9uuEgeRyHK ZLDmVQOx+n05HygyvLLmEjUbDw1bTM9DNZrY5tu0q5Qd7s9aGo2gsHyV5Hjuzc0cySKJ x6Z4WkgGE3uKbW2Cy4w5WI5s/XNab/0qQvq4gbZAkilmunFnNSqd6EBqkeTNVDaMo4iG JeY7eJNOEykAglVHhWAD+GEzSK1HVSOTa8dD44HsqSfqvb40zc08hpGcPiYnkYI8qweq 2UXQ== X-Gm-Message-State: AO0yUKUBYDKYsZGEXAGf4h7Ds8oG5106e7bPaucQU2pYCm25HXqBuH6j gLPc+4MNxdpCgEHjceNTxLz/2UHrItIxnLOSpFMz6m4o7gpUsD18J4KMzzWfvHr1eQ2hxR6pjMm bOYXMJSrtmUw1/fu8h+FPquVZK1Z1gxq1qFlivOxUjhPgRKcTKESIiIe347S+pFedAAvezuxL X-Received: by 2002:a17:906:f52:b0:884:ab29:bd0b with SMTP id h18-20020a1709060f5200b00884ab29bd0bmr7686062ejj.69.1675876794233; Wed, 08 Feb 2023 09:19:54 -0800 (PST) X-Google-Smtp-Source: AK7set91NrImlV+C08Q4Nfansegq1e0bkRbKljnBuclyk6towsqF+Pm9+3lG7ca9dB876IkzAFp6Mw== X-Received: by 2002:a17:906:f52:b0:884:ab29:bd0b with SMTP id h18-20020a1709060f5200b00884ab29bd0bmr7686051ejj.69.1675876794037; Wed, 08 Feb 2023 09:19:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-stable@nongnu.org Subject: [PULL 09/11] target/i386: Fix BEXTR instruction Date: Wed, 8 Feb 2023 18:19:20 +0100 Message-Id: <20230208171922.95048-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876926878100001 Content-Type: text/plain; charset="utf-8" From: Richard Henderson There were two problems here: not limiting the input to operand bits, and not correctly handling large extraction length. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1372 Signed-off-by: Richard Henderson Message-Id: <20230114230542.3116013-3-richard.henderson@linaro.org> Cc: qemu-stable@nongnu.org Fixes: 1d0b926150e5 ("target/i386: move scalar 0F 38 and 0F 3A instruction = to new decoder", 2022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/emit.c.inc | 22 +++++++++++----------- tests/tcg/i386/test-i386-bmi2.c | 12 ++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 7037ff91c612..99f6ba6e19a2 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1078,30 +1078,30 @@ static void gen_ANDN(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode) static void gen_BEXTR(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) { MemOp ot =3D decode->op[0].ot; - TCGv bound, zero; + TCGv bound =3D tcg_constant_tl(ot =3D=3D MO_64 ? 63 : 31); + TCGv zero =3D tcg_constant_tl(0); + TCGv mone =3D tcg_constant_tl(-1); =20 /* * Extract START, and shift the operand. * Shifts larger than operand size get zeros. */ tcg_gen_ext8u_tl(s->A0, s->T1); + if (TARGET_LONG_BITS =3D=3D 64 && ot =3D=3D MO_32) { + tcg_gen_ext32u_tl(s->T0, s->T0); + } tcg_gen_shr_tl(s->T0, s->T0, s->A0); =20 - bound =3D tcg_constant_tl(ot =3D=3D MO_64 ? 63 : 31); - zero =3D tcg_constant_tl(0); tcg_gen_movcond_tl(TCG_COND_LEU, s->T0, s->A0, bound, s->T0, zero); =20 /* - * Extract the LEN into a mask. Lengths larger than - * operand size get all ones. + * Extract the LEN into an inverse mask. Lengths larger than + * operand size get all zeros, length 0 gets all ones. */ tcg_gen_extract_tl(s->A0, s->T1, 8, 8); - tcg_gen_movcond_tl(TCG_COND_LEU, s->A0, s->A0, bound, s->A0, bound); - - tcg_gen_movi_tl(s->T1, 1); - tcg_gen_shl_tl(s->T1, s->T1, s->A0); - tcg_gen_subi_tl(s->T1, s->T1, 1); - tcg_gen_and_tl(s->T0, s->T0, s->T1); + tcg_gen_shl_tl(s->T1, mone, s->A0); + tcg_gen_movcond_tl(TCG_COND_LEU, s->T1, s->A0, bound, s->T1, zero); + tcg_gen_andc_tl(s->T0, s->T0, s->T1); =20 gen_op_update1_cc(s); set_cc_op(s, CC_OP_LOGICB + ot); diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi= 2.c index 3c3ef85513e1..982d4abda455 100644 --- a/tests/tcg/i386/test-i386-bmi2.c +++ b/tests/tcg/i386/test-i386-bmi2.c @@ -99,6 +99,9 @@ int main(int argc, char *argv[]) { result =3D bextrq(mask, 0x10f8); assert(result =3D=3D 0); =20 + result =3D bextrq(0xfedcba9876543210ull, 0x7f00); + assert(result =3D=3D 0xfedcba9876543210ull); + result =3D blsiq(0x30); assert(result =3D=3D 0x10); =20 @@ -164,6 +167,15 @@ int main(int argc, char *argv[]) { result =3D bextrl(mask, 0x1038); assert(result =3D=3D 0); =20 + result =3D bextrl((reg_t)0x8f635a775ad3b9b4ull, 0x3018); + assert(result =3D=3D 0x5a); + + result =3D bextrl((reg_t)0xfedcba9876543210ull, 0x7f00); + assert(result =3D=3D 0x76543210u); + + result =3D bextrl(-1, 0); + assert(result =3D=3D 0); + result =3D blsil(0xffff); assert(result =3D=3D 1); =20 --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876866; cv=none; d=zohomail.com; s=zohoarc; b=nQvtSYHeg6ecNqFvxNc4nndsYaRpPri8ZRbNeKsH6Nc2PfWq5kOueHAW+fSRUTtOXA6Q5tTS6sMvigsQEQRF6qOpi70r+uKGahbz8EbjGfRR0iND1D/RtIMFPkWInCeP89usnYazhhvD+2/H0hb5cjoE53cQVEbTi4LS948LkF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876866; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eErj71CMpZpTAVb4OGeJIVbpHzfh0RDDmrrDw4l1jN4=; b=UG6j1HUvf+++5I8KDsW5YPyXDk1UW2I5vOoVK9VoFYUq0TOJeVjC4C2NXzVRw+c71emW0cwjpdyDNKez148PSxoeKMqegq2umzCuK3lHZDobg1z1TsSZ7BD62Mf/shU8V040ScNlleDyldScoJ6NhmCFroxk3jlb6RrFSUdpzjE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876866456728.4341686314481; Wed, 8 Feb 2023 09:21:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7F-00045H-Gm; Wed, 08 Feb 2023 12:20:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo71-0003hP-0N for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo6y-0000r1-Vz for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:02 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-364-c2tV45HONFG7h8r8jiecUQ-1; Wed, 08 Feb 2023 12:19:59 -0500 Received: by mail-ed1-f70.google.com with SMTP id fd23-20020a056402389700b004aaa054d189so8303165edb.11 for ; Wed, 08 Feb 2023 09:19:58 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id k7-20020a170906158700b0088385cd6166sm8578995ejd.195.2023.02.08.09.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eErj71CMpZpTAVb4OGeJIVbpHzfh0RDDmrrDw4l1jN4=; b=QbogTepW2P9mGqtVI+0N856t0odCYCApesl6StzjvxW71Z7ibBd3nADkQDrVid7GzGvdL8 V/7hNbr0yXTzn/9KIF+p6jXcV6prq7N03Wy7w3VhV+C+Er8EhpnlCSc2UDqaT7QKVSXdOC gYiahbOKYftQvJHcvemW0LhlY6IvAQU= X-MC-Unique: c2tV45HONFG7h8r8jiecUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eErj71CMpZpTAVb4OGeJIVbpHzfh0RDDmrrDw4l1jN4=; b=b9WUQrKQChdYmgRCcWPW+B61YIjZ/S7Bi1j+OQFAIhyey/Z3uG3KfBrmNMjeRR560O /UlHW7JlfX7HYBbF7X8d8cV8UAnetX+QttidgkKMUr8K/i5vot85FNs4cNbK3NKq5QuL CKJVCO8h96BIsLcCw/+DyRTcAbjCFq/b6kCFlgw7FfEgFJurhpUDZFjpAs1I/Nujbf9I mwz7Xm+RhXVl3zh4VvkNLBbzERRSaPu9wk1JmN5RGRXr2nUDb0MU26ufi/FvdZWgTZc0 I6wxppyJD/Zat4Zk8P+ZwtelMF/3YkFXYNuB3OSNRrA9Nhtu7G2/VOD+WTR/uayXwDjp nFAg== X-Gm-Message-State: AO0yUKXtaGlIsl6AA+Sr9pAJp3HMoKDIHNSDKs+TVGcga3HbtNKS0c5E eLvMHa1IZmLxEzrDuJoUWQAiYybaOOioLLPfHoUW2U/z6/gs1umZZOdC/7PFNcO0vTJreWIfKTt IlFg/6v3S4+i0XCV6xlTRefCK1I6CGie8qnY+16+B5y3O+Wom92puhR1/4lGnTG7CgLQufn8e X-Received: by 2002:a17:906:2603:b0:862:11f6:a082 with SMTP id h3-20020a170906260300b0086211f6a082mr8107916ejc.17.1675876796945; Wed, 08 Feb 2023 09:19:56 -0800 (PST) X-Google-Smtp-Source: AK7set/xRA15pD0vGoUlxjQMcLufpKErwtsjY3rrOvY1FtKlqgVZXZ49n3w2h/Vl3NB94zp++uffKw== X-Received: by 2002:a17:906:2603:b0:862:11f6:a082 with SMTP id h3-20020a170906260300b0086211f6a082mr8107901ejc.17.1675876796750; Wed, 08 Feb 2023 09:19:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-stable@nongnu.org Subject: [PULL 10/11] target/i386: Fix C flag for BLSI, BLSMSK, BLSR Date: Wed, 8 Feb 2023 18:19:21 +0100 Message-Id: <20230208171922.95048-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876868579100003 Content-Type: text/plain; charset="utf-8" From: Richard Henderson We forgot to set cc_src, which is used for computing C. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1370 Signed-off-by: Richard Henderson Message-Id: <20230114180601.2993644-1-richard.henderson@linaro.org> Cc: qemu-stable@nongnu.org Fixes: 1d0b926150e5 ("target/i386: move scalar 0F 38 and 0F 3A instruction = to new decoder", 2022-10-18) Signed-off-by: Paolo Bonzini --- target/i386/tcg/emit.c.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 99f6ba6e19a2..4d7702c106bf 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1111,6 +1111,7 @@ static void gen_BLSI(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) { MemOp ot =3D decode->op[0].ot; =20 + tcg_gen_mov_tl(cpu_cc_src, s->T0); tcg_gen_neg_tl(s->T1, s->T0); tcg_gen_and_tl(s->T0, s->T0, s->T1); tcg_gen_mov_tl(cpu_cc_dst, s->T0); @@ -1121,6 +1122,7 @@ static void gen_BLSMSK(DisasContext *s, CPUX86State *= env, X86DecodedInsn *decode { MemOp ot =3D decode->op[0].ot; =20 + tcg_gen_mov_tl(cpu_cc_src, s->T0); tcg_gen_subi_tl(s->T1, s->T0, 1); tcg_gen_xor_tl(s->T0, s->T0, s->T1); tcg_gen_mov_tl(cpu_cc_dst, s->T0); @@ -1131,6 +1133,7 @@ static void gen_BLSR(DisasContext *s, CPUX86State *en= v, X86DecodedInsn *decode) { MemOp ot =3D decode->op[0].ot; =20 + tcg_gen_mov_tl(cpu_cc_src, s->T0); tcg_gen_subi_tl(s->T1, s->T0, 1); tcg_gen_and_tl(s->T0, s->T0, s->T1); tcg_gen_mov_tl(cpu_cc_dst, s->T0); --=20 2.39.1 From nobody Mon Feb 9 03:58:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675876881; cv=none; d=zohomail.com; s=zohoarc; b=a7nu6cJNM+lWVxK1m7TggOysxjnUjijyzcUPfRCe8SYzBwyrUdwZwuKp/6hwRllxQNBWJzBmJZOOaseSCZkxrvgZ33T6I1dXgoiWxD7ykshRsbuaAh2u7qzUydf5EXU/QGVJBOJA5q2i5FXvokDcVeA3nFuW3uiXbVe/YzUGe3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675876881; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jB8iGgjchWNfETDP05maM1RKtaDKHRq7+F3cH+2o8Ho=; b=EzOluIHckyvLGBHg9RyYuE4jjYDGAJVXjai8bV1hrRl1qDzz2jTQfdoLYpuyPT1yB3MXoo6wI84UVR+ry4UpEfvs9/zrbjyYGlJ1W+z6vGqXSM8VKIuhHSYKDxxuAoAaKs1bmczy5NULE/oUZXfZpgx4g6ZcUTrok8jIVCqxQyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675876881914867.792497852471; Wed, 8 Feb 2023 09:21:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPo7F-00043N-3X; Wed, 08 Feb 2023 12:20:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo75-0003kX-5Y for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPo73-00017V-2M for qemu-devel@nongnu.org; Wed, 08 Feb 2023 12:20:06 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-94-mznrKaLQOB2GDvPoDRKHhw-1; Wed, 08 Feb 2023 12:20:03 -0500 Received: by mail-ej1-f71.google.com with SMTP id i7-20020a17090685c700b008ab19875638so1771540ejy.3 for ; Wed, 08 Feb 2023 09:20:02 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id et6-20020a056402378600b004a21263bbaasm8075143edb.49.2023.02.08.09.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 09:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675876804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jB8iGgjchWNfETDP05maM1RKtaDKHRq7+F3cH+2o8Ho=; b=Ysfm9xAC5KOtsqURGMmY2J9AGk7slaVF341u41+B2xmARtDVVpkb50bVNmIJPaL0mZRj18 Vp4xiHOSK9d8SPWs9TbcFd/D3KazqAFH3wkOVbZqf7PGNdgMwqSANGSsWsVKMzE/+kKwiO 2IBTwRh/cQbpmxpKIcmfekzOHbLKOmY= X-MC-Unique: mznrKaLQOB2GDvPoDRKHhw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jB8iGgjchWNfETDP05maM1RKtaDKHRq7+F3cH+2o8Ho=; b=GpuCmDPcznEt2JQ9HTO4vN9OrAAd4q1tEJUl27yp9TgZgKnB8QnY7HTcTcJo+xZHXK Cc6uupOxOiRnCeEi4Wi5mRIvawm2OWcxJyPJrDiJOQoBxX7uBF1rStRCZxBgOAUjw1br abH3BytACHTnKlHW+I77xRte4qok9J4YBV4HpcQbQuhsTEG7sDblHJVLkxLdS8iaHT6b eWU4ZOzMpcGqSGsvAwzWPbhHcnpC5wRNARfIJMK/gYpqSiCTrYXq1zN3mXyt2qifwaZ3 cdbtMSBT+0JXmIMkXxA+aTDXjnIiJ1JsuDDRbubQLCYWGJXGOQ8J9nBGC5+kf33y9r24 RY4Q== X-Gm-Message-State: AO0yUKVrNd0dD9o6HCjV4sNkrBqYs23tOEGj6plWPG67scoTE1Hm2Dij HsqfzAuZOuxjgjP+zPQkwOPF+4KpD6Ez/AO1R+tiYariYf8F3GuOWZSropM2H0gsUkQRVSjy/DF LdUDVbAxW2uTCY+Up7VgiZPkgKTa+blZZH/VfasFdGes2PDFlBAD1uMoSXAMbCV2Es2q2Kd2+ X-Received: by 2002:a50:f698:0:b0:49e:f062:99e6 with SMTP id d24-20020a50f698000000b0049ef06299e6mr8674309edn.28.1675876801057; Wed, 08 Feb 2023 09:20:01 -0800 (PST) X-Google-Smtp-Source: AK7set8iwLAucetKzzcQvoUit0pR7mxeRaMCW4ieFfy7q8wB3xGUBELaYU0z8n+FBkans70xvu5VCw== X-Received: by 2002:a50:f698:0:b0:49e:f062:99e6 with SMTP id d24-20020a50f698000000b0049ef06299e6mr8674289edn.28.1675876800770; Wed, 08 Feb 2023 09:20:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org Subject: [PULL 11/11] target/i386: fix ADOX followed by ADCX Date: Wed, 8 Feb 2023 18:19:22 +0100 Message-Id: <20230208171922.95048-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208171922.95048-1-pbonzini@redhat.com> References: <20230208171922.95048-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675876882692100001 Content-Type: text/plain; charset="utf-8" When ADCX is followed by ADOX or vice versa, the second instruction's carry comes from EFLAGS and the condition codes use the CC_OP_ADCOX operation. Retrieving the carry from EFLAGS is handled by this bit of gen_ADCOX: tcg_gen_extract_tl(carry_in, cpu_cc_src, ctz32(cc_op =3D=3D CC_OP_ADCX ? CC_C : CC_O), 1); Unfortunately, in this case cc_op has been overwritten by the previous "if" statement to CC_OP_ADCOX. This works by chance when the first instruction is ADCX; however, if the first instruction is ADOX, ADCX will incorrectly take its carry from OF instead of CF. Fix by moving the computation of the new cc_op at the end of the function. The included exhaustive test case fails without this patch and passes afterwards. Because ADCX/ADOX need not be invoked through the VEX prefix, this regression bisects to commit 16fc5726a6e2 ("target/i386: reimplement 0x0f 0x38, add AVX", 2022-10-18). However, the mistake happened a little earlier, when BMI instructions were rewritten using the new decoder framework. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1471 Reported-by: Paul Jolly Fixes: 1d0b926150e5 ("target/i386: move scalar 0F 38 and 0F 3A instruction = to new decoder", 2022-10-18) Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- target/i386/tcg/emit.c.inc | 20 +++++---- tests/tcg/i386/Makefile.target | 6 ++- tests/tcg/i386/test-i386-adcox.c | 75 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 tests/tcg/i386/test-i386-adcox.c diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 4d7702c106bf..0d7c6e80ae87 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1015,6 +1015,7 @@ VSIB_AVX(VPGATHERQ, vpgatherq) =20 static void gen_ADCOX(DisasContext *s, CPUX86State *env, MemOp ot, int cc_= op) { + int opposite_cc_op; TCGv carry_in =3D NULL; TCGv carry_out =3D (cc_op =3D=3D CC_OP_ADCX ? cpu_cc_dst : cpu_cc_src2= ); TCGv zero; @@ -1022,14 +1023,8 @@ static void gen_ADCOX(DisasContext *s, CPUX86State *= env, MemOp ot, int cc_op) if (cc_op =3D=3D s->cc_op || s->cc_op =3D=3D CC_OP_ADCOX) { /* Re-use the carry-out from a previous round. */ carry_in =3D carry_out; - cc_op =3D s->cc_op; - } else if (s->cc_op =3D=3D CC_OP_ADCX || s->cc_op =3D=3D CC_OP_ADOX) { - /* Merge with the carry-out from the opposite instruction. */ - cc_op =3D CC_OP_ADCOX; - } - - /* If we don't have a carry-in, get it out of EFLAGS. */ - if (!carry_in) { + } else { + /* We don't have a carry-in, get it out of EFLAGS. */ if (s->cc_op !=3D CC_OP_ADCX && s->cc_op !=3D CC_OP_ADOX) { gen_compute_eflags(s); } @@ -1053,7 +1048,14 @@ static void gen_ADCOX(DisasContext *s, CPUX86State *= env, MemOp ot, int cc_op) tcg_gen_add2_tl(s->T0, carry_out, s->T0, carry_out, s->T1, zero); break; } - set_cc_op(s, cc_op); + + opposite_cc_op =3D cc_op =3D=3D CC_OP_ADCX ? CC_OP_ADOX : CC_OP_ADCX; + if (s->cc_op =3D=3D CC_OP_ADCOX || s->cc_op =3D=3D opposite_cc_op) { + /* Merge with the carry-out from the opposite instruction. */ + set_cc_op(s, CC_OP_ADCOX); + } else { + set_cc_op(s, cc_op); + } } =20 static void gen_ADCX(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index 81831cafbce4..bafd8c2180fc 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -14,7 +14,7 @@ config-cc.mak: Makefile I386_SRCS=3D$(notdir $(wildcard $(I386_SRC)/*.c)) ALL_X86_TESTS=3D$(I386_SRCS:.c=3D) SKIP_I386_TESTS=3Dtest-i386-ssse3 test-avx test-3dnow test-mmx -X86_64_TESTS:=3D$(filter test-i386-bmi2 $(SKIP_I386_TESTS), $(ALL_X86_TEST= S)) +X86_64_TESTS:=3D$(filter test-i386-adcox test-i386-bmi2 $(SKIP_I386_TESTS)= , $(ALL_X86_TESTS)) =20 test-i386-sse-exceptions: CFLAGS +=3D -msse4.1 -mfpmath=3Dsse run-test-i386-sse-exceptions: QEMU_OPTS +=3D -cpu max @@ -28,6 +28,10 @@ test-i386-bmi2: CFLAGS=3D-O2 run-test-i386-bmi2: QEMU_OPTS +=3D -cpu max run-plugin-test-i386-bmi2-%: QEMU_OPTS +=3D -cpu max =20 +test-i386-adcox: CFLAGS=3D-O2 +run-test-i386-adcox: QEMU_OPTS +=3D -cpu max +run-plugin-test-i386-adcox-%: QEMU_OPTS +=3D -cpu max + # # hello-i386 is a barebones app # diff --git a/tests/tcg/i386/test-i386-adcox.c b/tests/tcg/i386/test-i386-ad= cox.c new file mode 100644 index 000000000000..16169efff823 --- /dev/null +++ b/tests/tcg/i386/test-i386-adcox.c @@ -0,0 +1,75 @@ +/* See if various BMI2 instructions give expected results */ +#include +#include +#include + +#define CC_C 1 +#define CC_O (1 << 11) + +#ifdef __x86_64__ +#define REG uint64_t +#else +#define REG uint32_t +#endif + +void test_adox_adcx(uint32_t in_c, uint32_t in_o, REG adcx_operand, REG ad= ox_operand) +{ + REG flags; + REG out_adcx, out_adox; + + asm("pushf; pop %0" : "=3Dr"(flags)); + flags &=3D ~(CC_C | CC_O); + flags |=3D (in_c ? CC_C : 0); + flags |=3D (in_o ? CC_O : 0); + + out_adcx =3D adcx_operand; + out_adox =3D adox_operand; + asm("push %0; popf;" + "adox %3, %2;" + "adcx %3, %1;" + "pushf; pop %0" + : "+r" (flags), "+r" (out_adcx), "+r" (out_adox) + : "r" ((REG)-1), "0" (flags), "1" (out_adcx), "2" (out_adox)); + + assert(out_adcx =3D=3D in_c + adcx_operand - 1); + assert(out_adox =3D=3D in_o + adox_operand - 1); + assert(!!(flags & CC_C) =3D=3D (in_c || adcx_operand)); + assert(!!(flags & CC_O) =3D=3D (in_o || adox_operand)); +} + +void test_adcx_adox(uint32_t in_c, uint32_t in_o, REG adcx_operand, REG ad= ox_operand) +{ + REG flags; + REG out_adcx, out_adox; + + asm("pushf; pop %0" : "=3Dr"(flags)); + flags &=3D ~(CC_C | CC_O); + flags |=3D (in_c ? CC_C : 0); + flags |=3D (in_o ? CC_O : 0); + + out_adcx =3D adcx_operand; + out_adox =3D adox_operand; + asm("push %0; popf;" + "adcx %3, %1;" + "adox %3, %2;" + "pushf; pop %0" + : "+r" (flags), "+r" (out_adcx), "+r" (out_adox) + : "r" ((REG)-1), "0" (flags), "1" (out_adcx), "2" (out_adox)); + + assert(out_adcx =3D=3D in_c + adcx_operand - 1); + assert(out_adox =3D=3D in_o + adox_operand - 1); + assert(!!(flags & CC_C) =3D=3D (in_c || adcx_operand)); + assert(!!(flags & CC_O) =3D=3D (in_o || adox_operand)); +} + +int main(int argc, char *argv[]) { + /* try all combinations of input CF, input OF, CF from op1+op2, OF fr= om op2+op1 */ + int i; + for (i =3D 0; i <=3D 15; i++) { + printf("%d\n", i); + test_adcx_adox(!!(i & 1), !!(i & 2), !!(i & 4), !!(i & 8)); + test_adox_adcx(!!(i & 1), !!(i & 2), !!(i & 4), !!(i & 8)); + } + return 0; +} + --=20 2.39.1