From patchwork Thu Apr 27 21:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE983C7EE21 for ; Thu, 27 Apr 2023 21:11:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tC-0005uD-IX; Thu, 27 Apr 2023 17:10:54 -0400 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 1ps8tA-0005su-NK for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:52 -0400 Received: from esa16.hc2706-39.iphmx.com ([216.71.140.205]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8t8-0005N6-KC for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:52 -0400 X-IronPort-RemoteIP: 209.85.219.71 X-IronPort-MID: 273505165 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:4tiX7KjNxohiUjvd89uIo3zKX1613BIKZh0ujC45NGQN5FlHY01je htvCzjSMvaJZ2SgKo0kao6y8x4G68PUm4NrSAA6rS82EC8W8JqUDtmndXv9bniYRiHhoOOLz Cm8hv3odp1coqr0/0/1WlTZhSAgk/rOHvykU7Ss1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPSwP9TlK6q4mhA4gZhPasjUGL2zBH5MrpOfcldEFOlGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiM+t5qK23CulQRrukoPD8fwXG8M49m/c3Gd/ /0W3XC4YV9B0qQhA43xWTEBe811FfQuFLMqvRFTGCFcpqHLWyKE/hlgMK05FZUc8MllAnxoz PEjLjAuS0qSlvy8kJvuH4GAhux7RCXqFIYWu3Ul1C+ASPh5GNbMRKLF4dIe1zA17ixMNayGN oxJNHw1NUWGPEQn1lQ/UfrSmM+hgmn5fydwok/TqKYqi4TW5FYui+W1bYOLJ7RmQ+17w3mZh zP59l3CJUg8DI22xB2Uqi+V07qncSTTHdh6+KeD3udnhUDWymENBRk+U1y9rv+kzEmkVLpix 1c8/yMvqe0r6hXuQIakGRK/p3GAs1gXXN84//AG1TxhA5H8u26xblXohBYdNLTKaOdeqeQW6 2K0 IronPort-HdrOrdr: A9a23:l/LavKsXNq7SikfMrEYWrP9O7skDoNV00zEX/kB9WHVpmwKj5q STdZMgpGPJYVMqMk3I9urwXpVoLUmsl6KdpLNhRotKPzOWxVdAUrsSlLcKqgeIc0aOldK1l5 0QCZSWYOeRMbEQt7ec3ODXKadE/PC3tIqFv6Px9UtMcC1dQ51czm5Ce3mm+45NKDWux6BVKH NR3KR6TkKbCAwqhw2AaRg4Y9Q= X-Talos-CUID: 9a23:YdciMWN5chC8N+5DQC1t21wXB+Ycf0bbzFT1eV6pF2w5YejA X-Talos-MUID: 9a23:YHIW4Qpn89fWhdCoI3Aezx8/C8ZJspunMXsqyLM+6uCJEj0oZg7I2Q== Received: from mail-qv1-f71.google.com ([209.85.219.71]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:29 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5ef5fe13973so60531196d6.0 for ; Thu, 27 Apr 2023 14:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629828; x=1685221828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S5GA8Y1UMhuzqKrQy3ytJIXFWBXaejHanlC6dTX2Ipg=; b=Q4BOLKNFXYM9xz7kImvgEA3RG8m018gsEEiw60e8NFmlQ0yDXHTPIm8bo9j3LKftUh pWnlFeG7macRXXc8QY5bxKVzwUOLGxEC0TxjBUaUZ2E1y8GDRjwhbmWbHRNQJK4RDV0L AGR3/60+Sq3rwD+uhPZYPTLfR7qWsYZC0beoTjslIjJwj8rvzPZQabxr7h7OG1fPXMYm TbKM3xzwXXYja9We7LPBVY3+Fc9XgJNh1SLmZEXHXeF0ZAjnGxoW4nau+Awwy3rI1Owx 3K+w2TumTHeh1mDlaRI80iOxbwysrMgqyW1qC8hW1j2l6GdSqXqKuGdNFLP9HVyQm5jd pM9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629828; x=1685221828; 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=S5GA8Y1UMhuzqKrQy3ytJIXFWBXaejHanlC6dTX2Ipg=; b=J20GPBE2X6if08lMvPU6ayd9eCaBWNO/amLVYsbTTR4Xe0q4e3Ie+cHK3GGAfwfKhR B6MkyVH8KDqnWGosZgVcao8gx/cqVBQHJWSgyWy1+zeWaZCXmJ4Q9y+Kgtk4NzhJAcz2 ZXpB2wdol1H/CwE21ZrKAWTRMOA+gjjr1szOE5hg6I9b9stwVkK/DdMum/F2G29gdmll dROroy6Dm+7shIp34fJXGHQ3xnvQe0WBAxzzBoTzWTwpI2ExOsR0idQtpERwC1NKQmBJ AhGFVRhTpnG2UT1u/nuPZsjX1dVaKcwX4JFwAEfwyw1TF8kMSY0Gk7NyGvzkOcMSC3/X fQsA== X-Gm-Message-State: AC+VfDy/1JYYswP6FyuW5NEnzgFaEnED6hdS0QFYafeJSLrP/Viar9kI twYI8oODPteEWIrPf4dRBm1pOU08IcLhnc4WTdb11ku/DscG391qbLVcUWoYzNvnyrSIRZIWDA9 UsIuexbau998TgqlQVyo5Un4FUugYQb++g+pqb6ybyXE= X-Received: by 2002:a05:6214:212d:b0:5e7:f7eb:d87 with SMTP id r13-20020a056214212d00b005e7f7eb0d87mr4589029qvc.47.1682629828215; Thu, 27 Apr 2023 14:10:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Ik6U0VsaJkRAhW1VCGgiYCavtRYM7GbThgwIQ0FXZz4wj7/3BMvznECDE4EIq7G5Cpcw3+Q== X-Received: by 2002:a05:6214:212d:b0:5e7:f7eb:d87 with SMTP id r13-20020a056214212d00b005e7f7eb0d87mr4588993qvc.47.1682629827942; Thu, 27 Apr 2023 14:10:27 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id dz16-20020a05620a2b9000b0074df16f36f1sm6204726qkb.108.2023.04.27.14.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:27 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev Subject: [PATCH v10 1/8] memory: prevent dma-reentracy issues Date: Thu, 27 Apr 2023 17:10:06 -0400 Message-Id: <20230427211013.2994127-2-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.205; envelope-from=alxndr@bu.edu; helo=esa16.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add a flag to the DeviceState, when a device is engaged in PIO/MMIO/DMA. This flag is set/checked prior to calling a device's MemoryRegion handlers, and set when device code initiates DMA. The purpose of this flag is to prevent two types of DMA-based reentrancy issues: 1.) mmio -> dma -> mmio case 2.) bh -> dma write -> mmio case These issues have led to problems such as stack-exhaustion and use-after-frees. Summary of the problem from Peter Maydell: https://lore.kernel.org/qemu-devel/CAFEAcA_23vc7hE3iaM-JVA6W38LK4hJoWae5KcknhPRD5fPBZA@mail.gmail.com Resolves: https://gitlab.com/qemu-project/qemu/-/issues/62 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/540 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/541 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/556 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/557 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/827 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1282 Resolves: CVE-2023-0330 Signed-off-by: Alexander Bulekov Reviewed-by: Thomas Huth --- include/exec/memory.h | 5 +++++ include/hw/qdev-core.h | 7 +++++++ softmmu/memory.c | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 15ade918ba..e45ce6061f 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -767,6 +767,8 @@ struct MemoryRegion { bool is_iommu; RAMBlock *ram_block; Object *owner; + /* owner as TYPE_DEVICE. Used for re-entrancy checks in MR access hotpath */ + DeviceState *dev; const MemoryRegionOps *ops; void *opaque; @@ -791,6 +793,9 @@ struct MemoryRegion { unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; RamDiscardManager *rdm; /* Only for RAM */ + + /* For devices designed to perform re-entrant IO into their own IO MRs */ + bool disable_reentrancy_guard; }; struct IOMMUMemoryRegion { diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index bd50ad5ee1..7623703943 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -162,6 +162,10 @@ struct NamedClockList { QLIST_ENTRY(NamedClockList) node; }; +typedef struct { + bool engaged_in_io; +} MemReentrancyGuard; + /** * DeviceState: * @realized: Indicates whether the device has been fully constructed. @@ -194,6 +198,9 @@ struct DeviceState { int alias_required_for_version; ResettableState reset; GSList *unplug_blockers; + + /* Is the device currently in mmio/pio/dma? Used to prevent re-entrancy */ + MemReentrancyGuard mem_reentrancy_guard; }; struct DeviceListener { diff --git a/softmmu/memory.c b/softmmu/memory.c index b1a6cae6f5..fe23f0e5ce 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -542,6 +542,18 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, access_size_max = 4; } + /* Do not allow more than one simultaneous access to a device's IO Regions */ + if (mr->dev && !mr->disable_reentrancy_guard && + !mr->ram_device && !mr->ram && !mr->rom_device && !mr->readonly) { + if (mr->dev->mem_reentrancy_guard.engaged_in_io) { + warn_report("Blocked re-entrant IO on " + "MemoryRegion: %s at addr: 0x%" HWADDR_PRIX, + memory_region_name(mr), addr); + return MEMTX_ACCESS_ERROR; + } + mr->dev->mem_reentrancy_guard.engaged_in_io = true; + } + /* FIXME: support unaligned access? */ access_size = MAX(MIN(size, access_size_max), access_size_min); access_mask = MAKE_64BIT_MASK(0, access_size * 8); @@ -556,6 +568,9 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, access_mask, attrs); } } + if (mr->dev) { + mr->dev->mem_reentrancy_guard.engaged_in_io = false; + } return r; } @@ -1170,6 +1185,7 @@ static void memory_region_do_init(MemoryRegion *mr, } mr->name = g_strdup(name); mr->owner = owner; + mr->dev = (DeviceState *) object_dynamic_cast(mr->owner, TYPE_DEVICE); mr->ram_block = NULL; if (name) { From patchwork Thu Apr 27 21:10:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D81F7C77B7F for ; Thu, 27 Apr 2023 21:11:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tH-0005vU-3S; Thu, 27 Apr 2023 17:10:59 -0400 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 1ps8tE-0005v1-Pm for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:56 -0400 Received: from esa13.hc2706-39.iphmx.com ([216.71.137.83]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8tC-0005O0-Oo for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:56 -0400 X-IronPort-RemoteIP: 209.85.167.200 X-IronPort-MID: 275213208 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:QZJlTKkfDfSSZXf88vFrUAjo5gw/JERdPkR7XQ2eYbSJt1+Wr1Gzt xJLXT+EO/3eZDamedglOYXioR8HsZbcmNE2TQVorClhRS4T+ZvOCOrCEkqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvPrRC9H5qyo42tE5ANmPpingXeF/5UrJMNHTU2OByagKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0xK6aYD76vRxjnVaPpIACRYpQRw/ZwNlPjxG4 I4lWZSYEW/FN0BX8QgXe0Aw/ypWZMWq9FJbSJQWXAP6I0DuKhPRL/tS4E4eYpIcxsBHE1p3s v1ECRpRaCHZ2uWZ3+fuIgVsrpxLwMjDOYoevjRnzGicA6x+GdbMRKLF4dIe1zA17ixMNayGN oxJNHw2MkuGOUUXUrsUIMtWcOOAj33vdTFCgFiI46c7/gA/ySQrj+W3aYGPIoziqcN9t2+0+ lnX0DvDGwAVMtO/6D66wi60ibqa9c/8cMdIfFGizdZzjViOg2AeFhASfV28p/a/lwi5Qd03F qAP0i8nrKx3803yC9enB0X+r3mDsRoRHdFXFoXW9T2w90Yd2C7BbkBsc9KLQIdOWBMeLdDy6 mK0og== IronPort-HdrOrdr: A9a23:2fzk6q6BEtdGHyIilwPXwBXXdLJyesId70hD6qkRc20yTiX8ra qTdZsgpHvJYVoqKRMdcLO7Scq9qBHnm6KdiLN5VduftWHd01eAFoFt6ovkzXnMHSn39uk178 ZdWpJ/BtrxClY/t8r+7AOkFc1I+rm6GcuT9IDjJhlWPGRXQpAlxAd/BwadHAlXaWB9aqbRRK Dw2vZ6 X-Talos-CUID: 9a23:92UwyGjYnLG96EGblPy/5MjewTJuLWLZ8FHgMXSBTmc1aZfJT27KpaRLjJ87 X-Talos-MUID: 9a23:5JPmtAmbCS9h6yXSo00vdnpLHes02LWBV3oUgJoAtOmlMRNAZy+S2WE= Received: from mail-oi1-f200.google.com ([209.85.167.200]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:53 -0400 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-38c5845e8e5so6153812b6e.0 for ; Thu, 27 Apr 2023 14:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629852; x=1685221852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lp25phZ45HRqtDee0Q+1ws/xkoM4Gpnqec2ldOouCHM=; b=D1BAdHcOKXPCxaoq2nLAWDtGiXB9XlEGYzXFrNK3lBgS4yDo9cRkgXmV6/yjKyVdMj e0diDehi2nMCc6m3JQ+3HF/KgnsIhyX8tCSY8AyVRKcS7vHCXzaPP5xdeYT8ISWZLuay iMjYM+CBEo/l5YwiXTqEu+Lg9Pb8GCbuePE9BiBIC/jQO9/w+cl8TDPtQC87UbIMTyTW JOBAJCFBjVx++tHzrq287RrZk0S0zTRoQQM45YU4znx4P9C6D8WXNnkgmE3y/Hky3XLf S8P6gCJbp+El7HyCEEM0rKVibggHaq4jMBQ4rz62lGaT9d7SJfVj6Xhj9/pM981kBQR+ XDdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629852; x=1685221852; 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=lp25phZ45HRqtDee0Q+1ws/xkoM4Gpnqec2ldOouCHM=; b=Zy+EjaB32HmMNaLLV5cvoZNwc+JLSfPt6UyQR+6h2PgLMzkF08qlbqV05ji/iu7Nx6 f9p2mrbtI8H7LIR88vJ/L3dplkx5qAfIuwHozC/G/7BBGAhjgOKRLEAfze0M0tvcL/8W w4EkfQK6Xgenu0wQQmNhIGcQmihsCUtGmMqkrublxVxezvoU0Jy7P3jtTtn8EpsyBgSi 1dQmEVtzvzGtBinc2ulYEuHf/zP7OPVqysYyGKazTVeOQJwU9hozf+w4DT3Dtn1QWjO6 Y5tvbtTK8R0/irgN813K1hvWF8FDcoRsqSUEhz7cy9ruDpVmeuSGdf9MYvvC/DXVYctW VSWw== X-Gm-Message-State: AC+VfDyNakKsjwqI8JYtHPzvolEpWxCe14y/PfnEfdZaEsYot5z44aMA wbTUkYIToVDGNYWJOHE261aLbQfu1lRnOs8NQi0vqFgmVut5+tDZ9fRr7KphoUz/SpYajg9+FDz w570faZ2yOe2NDVDf9v94Dnvh0wzden2w3lJsobX+IO8= X-Received: by 2002:a05:6214:c88:b0:5f4:4e3d:2bde with SMTP id r8-20020a0562140c8800b005f44e3d2bdemr3329536qvr.48.1682629831789; Thu, 27 Apr 2023 14:10:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jb2+k0W+QOxztuMbRyAZjbakFzGUw4xXgSPdtKhPEIPchovU1lxd5ffeCdz8rSaOEXnDiHg== X-Received: by 2002:a05:6214:c88:b0:5f4:4e3d:2bde with SMTP id r8-20020a0562140c8800b005f44e3d2bdemr3329482qvr.48.1682629831455; Thu, 27 Apr 2023 14:10:31 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id j14-20020ac84c8e000000b003ef3df76ec7sm6483969qtv.93.2023.04.27.14.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:31 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev , Fam Zheng , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block I/O path) Subject: [PATCH v10 2/8] async: Add an optional reentrancy guard to the BH API Date: Thu, 27 Apr 2023 17:10:07 -0400 Message-Id: <20230427211013.2994127-3-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.137.83; envelope-from=alxndr@bu.edu; helo=esa13.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Devices can pass their MemoryReentrancyGuard (from their DeviceState), when creating new BHes. Then, the async API will toggle the guard before/after calling the BH call-back. This prevents bh->mmio reentrancy issues. Reviewed-by: Darren Kenny Signed-off-by: Alexander Bulekov --- docs/devel/multiple-iothreads.txt | 7 +++++++ include/block/aio.h | 18 ++++++++++++++++-- include/qemu/main-loop.h | 7 +++++-- tests/unit/ptimer-test-stubs.c | 3 ++- util/async.c | 18 +++++++++++++++++- util/main-loop.c | 5 +++-- util/trace-events | 1 + 7 files changed, 51 insertions(+), 8 deletions(-) diff --git a/docs/devel/multiple-iothreads.txt b/docs/devel/multiple-iothreads.txt index 343120f2ef..a3e949f6b3 100644 --- a/docs/devel/multiple-iothreads.txt +++ b/docs/devel/multiple-iothreads.txt @@ -61,6 +61,7 @@ There are several old APIs that use the main loop AioContext: * LEGACY qemu_aio_set_event_notifier() - monitor an event notifier * LEGACY timer_new_ms() - create a timer * LEGACY qemu_bh_new() - create a BH + * LEGACY qemu_bh_new_guarded() - create a BH with a device re-entrancy guard * LEGACY qemu_aio_wait() - run an event loop iteration Since they implicitly work on the main loop they cannot be used in code that @@ -72,8 +73,14 @@ Instead, use the AioContext functions directly (see include/block/aio.h): * aio_set_event_notifier() - monitor an event notifier * aio_timer_new() - create a timer * aio_bh_new() - create a BH + * aio_bh_new_guarded() - create a BH with a device re-entrancy guard * aio_poll() - run an event loop iteration +The qemu_bh_new_guarded/aio_bh_new_guarded APIs accept a "MemReentrancyGuard" +argument, which is used to check for and prevent re-entrancy problems. For +BHs associated with devices, the reentrancy-guard is contained in the +corresponding DeviceState and named "mem_reentrancy_guard". + The AioContext can be obtained from the IOThread using iothread_get_aio_context() or for the main loop using qemu_get_aio_context(). Code that takes an AioContext argument works both in IOThreads or the main diff --git a/include/block/aio.h b/include/block/aio.h index e267d918fd..89bbc536f9 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -23,6 +23,8 @@ #include "qemu/thread.h" #include "qemu/timer.h" #include "block/graph-lock.h" +#include "hw/qdev-core.h" + typedef struct BlockAIOCB BlockAIOCB; typedef void BlockCompletionFunc(void *opaque, int ret); @@ -323,9 +325,11 @@ void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, * is opaque and must be allocated prior to its use. * * @name: A human-readable identifier for debugging purposes. + * @reentrancy_guard: A guard set when entering a cb to prevent + * device-reentrancy issues */ QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, - const char *name); + const char *name, MemReentrancyGuard *reentrancy_guard); /** * aio_bh_new: Allocate a new bottom half structure @@ -334,7 +338,17 @@ QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, * string. */ #define aio_bh_new(ctx, cb, opaque) \ - aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb))) + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)), NULL) + +/** + * aio_bh_new_guarded: Allocate a new bottom half structure with a + * reentrancy_guard + * + * A convenience wrapper for aio_bh_new_full() that uses the cb as the name + * string. + */ +#define aio_bh_new_guarded(ctx, cb, opaque, guard) \ + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)), guard) /** * aio_notify: Force processing of pending events. diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index b3e54e00bc..68e70e61aa 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -387,9 +387,12 @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms); /* internal interfaces */ +#define qemu_bh_new_guarded(cb, opaque, guard) \ + qemu_bh_new_full((cb), (opaque), (stringify(cb)), guard) #define qemu_bh_new(cb, opaque) \ - qemu_bh_new_full((cb), (opaque), (stringify(cb))) -QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name); + qemu_bh_new_full((cb), (opaque), (stringify(cb)), NULL) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name, + MemReentrancyGuard *reentrancy_guard); void qemu_bh_schedule_idle(QEMUBH *bh); enum { diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c index f2bfcede93..8c9407c560 100644 --- a/tests/unit/ptimer-test-stubs.c +++ b/tests/unit/ptimer-test-stubs.c @@ -107,7 +107,8 @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask) return deadline; } -QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name, + MemReentrancyGuard *reentrancy_guard) { QEMUBH *bh = g_new(QEMUBH, 1); diff --git a/util/async.c b/util/async.c index 21016a1ac7..a9b528c370 100644 --- a/util/async.c +++ b/util/async.c @@ -65,6 +65,7 @@ struct QEMUBH { void *opaque; QSLIST_ENTRY(QEMUBH) next; unsigned flags; + MemReentrancyGuard *reentrancy_guard; }; /* Called concurrently from any thread */ @@ -137,7 +138,7 @@ void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, } QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, - const char *name) + const char *name, MemReentrancyGuard *reentrancy_guard) { QEMUBH *bh; bh = g_new(QEMUBH, 1); @@ -146,13 +147,28 @@ QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, .cb = cb, .opaque = opaque, .name = name, + .reentrancy_guard = reentrancy_guard, }; return bh; } void aio_bh_call(QEMUBH *bh) { + bool last_engaged_in_io = false; + + if (bh->reentrancy_guard) { + last_engaged_in_io = bh->reentrancy_guard->engaged_in_io; + if (bh->reentrancy_guard->engaged_in_io) { + trace_reentrant_aio(bh->ctx, bh->name); + } + bh->reentrancy_guard->engaged_in_io = true; + } + bh->cb(bh->opaque); + + if (bh->reentrancy_guard) { + bh->reentrancy_guard->engaged_in_io = last_engaged_in_io; + } } /* Multiple occurrences of aio_bh_poll cannot be called concurrently. */ diff --git a/util/main-loop.c b/util/main-loop.c index e180c85145..4d76261010 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -605,9 +605,10 @@ void main_loop_wait(int nonblocking) /* Functions to operate on the main QEMU AioContext. */ -QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name, MemReentrancyGuard *reentrancy_guard) { - return aio_bh_new_full(qemu_aio_context, cb, opaque, name); + return aio_bh_new_full(qemu_aio_context, cb, opaque, name, + reentrancy_guard); } /* diff --git a/util/trace-events b/util/trace-events index 16f78d8fe5..3f7e766683 100644 --- a/util/trace-events +++ b/util/trace-events @@ -11,6 +11,7 @@ poll_remove(void *ctx, void *node, int fd) "ctx %p node %p fd %d" # async.c aio_co_schedule(void *ctx, void *co) "ctx %p co %p" aio_co_schedule_bh_cb(void *ctx, void *co) "ctx %p co %p" +reentrant_aio(void *ctx, const char *name) "ctx %p name %s" # thread-pool.c thread_pool_submit(void *pool, void *req, void *opaque) "pool %p req %p opaque %p" From patchwork Thu Apr 27 21:10:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7007C77B61 for ; Thu, 27 Apr 2023 21:12:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8t7-0005rz-Qf; Thu, 27 Apr 2023 17:10:49 -0400 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 1ps8t2-0005rD-CE for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:45 -0400 Received: from esa1.hc2706-39.iphmx.com ([68.232.153.39]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8sz-0005K9-U4 for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:44 -0400 X-IronPort-RemoteIP: 209.85.160.197 X-IronPort-MID: 277415118 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:35Ve8ayA21Jr2pJmi/p6t+eJxCrEfRIJ4+MujC+fZmUNrF6WrkUGm DAcDW+Ea/eLNGOhfdtzYYi3p0gA656BmNAySwBuqi00HyNBpPSeOdnIdU2Y0wF+jyHgoOCLy +1EN7Es+ehtFie0Si+Fa+Sn9j8kk/nTHNIQMcacUghpXwhoVSw9vhxqnu89k+ZAjMOwRgiAo rsemeWGULOe82MyYzN8B56r8ks156yu4mxA5TTSWNgQ1LPgvyhNZH4gDfzpR5fIatE8NvK3Q e/F0Ia48gvxl/v6Ior4+lpTWhRiro/6ZGBiuFIPM0SRqkEqShgJ70oOHKF0hXG7Ktm+t4sZJ N1l7fRcQOqyV0HGsL11vxJwSkmSMUDakVNuzLfWXcG7liX7n3XQL/pGXWdqfq859r1OImxF7 cMIdA8SfEyyvrfjqF67YrEEasULKcDqOMYGpiglw2iIUrApRpfMR6iM7thdtNsyrpoWTLCOO oxAN2IpNUWfC/FMEg5/5JYWleO4gHXlWzdF7l+ZuMLb5kCJk1MtieW0aYq9ltqidZpthQWmg Tj69F/gJzcrGPyElgWb/Sf57gPItWahMG4IL5Wh+/t3xVGe2GEXIBsRU1S9vL++kEHWZj5EA 0kd+y5rtLRrsULyH4a7UBq/r3qJ+BUbXrK8DtEH1e1E8YKMiy7xO4TOZmIphAAO3CPueQEX6 w== IronPort-HdrOrdr: A9a23:ALQeOK925eQl/Y3Xz0Ruk+DhI+orL9Y04lQ7vn2ZKCYlC/Bw8v rFoB1173/JYVoqKRYdcPq7Scq9qArnhPxICOoqU4tKPjOW3VdARbsKheDfKlbbaknDH4BmpM FdmmtFZOEYz2IWsS832maF+h8boeW6zA== X-Talos-CUID: 9a23:hvnOzGMHCGvNgO5DCQ87t2w1FpscUXDW1EjAf3CnGzpYcejA X-Talos-MUID: 9a23:+DPFWQb6a0dIl+BTh2DUn3JcE51U6J+3LWY8vbUd5PaaOnkl Received: from mail-qt1-f197.google.com ([209.85.160.197]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:36 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3ef30a89abbso59844571cf.2 for ; Thu, 27 Apr 2023 14:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629835; x=1685221835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y81jYrFdHFI0h2IHDmqZGbfVAz90Pdxvxksgm9ZaytQ=; b=k+E5MGszO4U/Q+93DhK0WRb5KBoOox2CxKEZ3J6PtwAWqEa32MGSUkLfoW7iNU3xlY 45jnKJYg12pD7LSh1I0gRW+sfyYJ/M9TaUAWQET98X7645AZ03jy5lu2Smk13sg4w7kn S7rjM8xeB+Et56mdc7777OpVyx+kJkNiQnz+orJdaq86++HDD6bL3cbfV515lFX9+KBM j28OoHZk2nhLkEr4yQOCpSdAQCSG0jacSZwST4FmQ/ZlDxJSqpqa9VNdc3ysQwKQ5uCY AS3u+Ezpa3gP8ZF8o6A0Ah0fAE91uGbv2OpKAZxImPRoMzBxHk3hepRt6uVGqmDRkG4v 2VgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629835; x=1685221835; 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=y81jYrFdHFI0h2IHDmqZGbfVAz90Pdxvxksgm9ZaytQ=; b=TAB/dJGKvwaAwB33jTzVynrHPQ9jB4FrGCR7D4yfrasamIuWKDa7N8fGEytDnZG9PH yoV4vvkv/EB4fv/sDfqMBxGgQiXX1usoI696wusXxl946OQCzSM4fqTlZch33egtBtDI z+2s3Tnn/x97A0xKS1i3McoVoPxrOm2GL/hqu7eGdi2D45HBO+xDFRnq0wR68khDkI5v +GIn3cXo8+tn6Cm3mGTlZPWVp2V+pXBVxxGbIUu69JqzuwPwyIEyzT0wbxW7gad+jaKo DjG6esIl6jd08TnGLjQlELzq44bDh6oBj8thdyQult3gw5ePtQWC/WKe2v+zZqjtyZ2i /l4w== X-Gm-Message-State: AC+VfDwSRyUxBcEZBYBpl+pgZPert734/taFyuNGyJwZcBf4+/UR0miB baU4tIg0IXormU8uoonKUyi67ond1deQTalRq/HOD9FIAkgkplq1ejLM3Xk0xPG3wejznq0kRAm MbQ98VA4FHcondJgmGewNCR1qtavvu0IW4qCRcaV/DXg= X-Received: by 2002:a05:622a:5ca:b0:3ef:64d9:f0b3 with SMTP id d10-20020a05622a05ca00b003ef64d9f0b3mr4001819qtb.14.1682629835153; Thu, 27 Apr 2023 14:10:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mZNJ6S1IzpkXugvfanukXvQFph5x3I2LaxWduCjgTu22B/iObV7QHaOcQc7iKsAQz+1cuHw== X-Received: by 2002:a05:622a:5ca:b0:3ef:64d9:f0b3 with SMTP id d10-20020a05622a05ca00b003ef64d9f0b3mr4001773qtb.14.1682629834780; Thu, 27 Apr 2023 14:10:34 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id d9-20020a05620a240900b0074e24692929sm6228207qkn.106.2023.04.27.14.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:34 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev Subject: [PATCH v10 3/8] checkpatch: add qemu_bh_new/aio_bh_new checks Date: Thu, 27 Apr 2023 17:10:08 -0400 Message-Id: <20230427211013.2994127-4-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=68.232.153.39; envelope-from=alxndr@bu.edu; helo=esa1.hc2706-39.iphmx.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Advise authors to use the _guarded versions of the APIs, instead. Reviewed-by: Darren Kenny Signed-off-by: Alexander Bulekov --- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d768171dcf..eeaec436eb 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2865,6 +2865,14 @@ sub process { if ($line =~ /\bsignal\s*\(/ && !($line =~ /SIG_(?:IGN|DFL)/)) { ERROR("use sigaction to establish signal handlers; signal is not portable\n" . $herecurr); } +# recommend qemu_bh_new_guarded instead of qemu_bh_new + if ($realfile =~ /.*\/hw\/.*/ && $line =~ /\bqemu_bh_new\s*\(/) { + ERROR("use qemu_bh_new_guarded() instead of qemu_bh_new() to avoid reentrancy problems\n" . $herecurr); + } +# recommend aio_bh_new_guarded instead of aio_bh_new + if ($realfile =~ /.*\/hw\/.*/ && $line =~ /\baio_bh_new\s*\(/) { + ERROR("use aio_bh_new_guarded() instead of aio_bh_new() to avoid reentrancy problems\n" . $herecurr); + } # check for module_init(), use category-specific init macros explicitly please if ($line =~ /^module_init\s*\(/) { ERROR("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr); From patchwork Thu Apr 27 21:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39FB0C77B73 for ; Thu, 27 Apr 2023 21:11:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tR-0005yL-SZ; Thu, 27 Apr 2023 17:11:09 -0400 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 1ps8tQ-0005xo-8s for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:08 -0400 Received: from esa7.hc2706-39.iphmx.com ([216.71.137.80]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8tN-0005Pd-Bw for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:08 -0400 X-IronPort-RemoteIP: 209.85.210.199 X-IronPort-MID: 276481453 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:q2oouKJbHuXn+jFtFE+RaJclxSXFcZb7ZxGr2PjKsXjdYENShTwFn GoWWWjVOPaJYGTzL9gnb9u+9xwCucLRnNZjHQporCE8RH908vbIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkjk7xdOOn9T8kjvvgqoPUUIbsIjp2SRJvVBAvgBdin/9RqoNziJ2yDhjlV ena+qUzA3f4nW8lWo4ow/jb8kg34K6t4GhwUmEWPpingnePzxH5M7pCfcldH1OgKqFIE+izQ fr0zb3R1gs1KD90V7tJOp6iGqE7aue60Tqm0xK6aID76vR2nRHe545gXBYqhea7vB3S9zx54 I0lWZVd0m7FNIWV8AgWe0Aw/y2TocSqUVIISJSymZX78qHIT5fj69xMS2c/HtQxwMhyPmRK2 vgCJG8SZQ/W0opawJrjIgVtrsEqLc2uJI1G/385nGCfAvEhTpTOBa7N4Le03h9q3pEITauYP ZNBL2M+PXwsYDUWUrsTIJs6jOGknFH1bntVpE/9Sa8fuTeNkFwojOW2WDbTUv+lXfoJxRqZn Gft/EDgHCxHEdKV9APQpxpAgceKx0sXQrk6DbC967tmjUOewkQVDxsZU0b9puO24nNSQPpaI k0QvzIg9O08rR36CNb6WBK8rTiPuRt0t8dsLtDWITqlksL8izt1zEBdEFattPROWBcKeAEX IronPort-HdrOrdr: A9a23:GqLKKq4w/sZ09zGh0gPXwemBI+orL9Y04lQ7vn2ZESYlFfBw5P re+sjztCWEzQr5N0tQ/OxoVJPvfZq+z+8w3WByB8bHYOCOggLBRuwPgrcKqAeBJ8SKzJ8+6U 4WSdkcNDSfNzlHZZmQ2mKF+p0bsaC6GeiT9J/jJt1WPEZXg10L1XYMNu5leHcGMTWv+/ACZe ihD4N81kCdkQ9+VLXNOpEIMtKz3OEiSfrdEF07785O0njPsRq4rLH9CBSWxREYTndGxqoj63 HMl0jj6rykqOzT8G6u64Z91eUppDLN8KozOCW3sLlkFhz8zgKzIIhxUbyLuz445Ou17kwxjd XKqxA8e8xu9nLYZAiO0G3Q8hil1Cxr527pyFeej3emq9f+XigmB81Igp8cegfF6lAnoMp33M twriukX9M+N2KLoMyKj+K4Gi2DuCGP0DYfea96tQ0WbWNoAIUh5rD23ChuYdg99FGT0vFoLA BDNrCi2B8NSyLmU5nwhBgS/DR6Nk5DXytvQCA5y46o7wQ= X-Talos-CUID: 9a23:Hmis4mCcdoycV3D6EwBFs2gdOZkMSFPY83LUDEuiBTl2Q6LAHA== X-Talos-MUID: 9a23:o75ExQ90nvsmxHzsAqO4fCqQf+RH+5vyUxwMq5AtuO2dKxEtHjmXsQ3iFw== Received: from mail-pf1-f199.google.com ([209.85.210.199]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:11:01 -0400 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-63b62529864so10195072b3a.2 for ; Thu, 27 Apr 2023 14:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629860; x=1685221860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VcAcKX7/rrkQbLPugxX5FYzGcIPCu/jEZtAHpxtM8bY=; b=n7hz8eixX5V/HHe50BRBJHrZmK9bBeV0iiovV9olSpaorcQVQgRBmdduyC9e5X2k2V yoAOWatpRe2jXsLi6LoO82hQWSrpUJQyd++VYPO8gg8LV1LTyoCj1fPMoGPYEihEPP/A lhpkybzm42s9hmBaq9U+k3VWX7EPs3PNXCLDVGPc8inGPDSrZwMUJv8ZK/Ei1l333eR+ mFeiOr4JZlRw2ohNkTFtLE68qsbS9g73BGcFlH77F7zS5GXJma9/Vw8m9B7IaO2Kj/b0 utXUityUCPA1nUjxpru1CDOvpl1MMWF+w2QTaLlh+JAkBVWPqvZFYHmHCvcGxjBpGO7D ooMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629860; x=1685221860; 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=VcAcKX7/rrkQbLPugxX5FYzGcIPCu/jEZtAHpxtM8bY=; b=GgPVB6d2OQfwBgsfUCu3mEM45g4RUNXV0EwI0D7gPLovX8FdZYByCVtY0JcvNgiB57 Vgfb90lGlonNlWZoRDzybsixLUz8Q2MBbWhHgzcmPlxjdQ7qgKmxv0HNSHrNvBPyQos6 d6ri5wfa5XRw7EdBBu/A2uOc9x1u7MQBQimOXXd5h9r/yin0pJ8+W8ph4zHZq3kBwXVQ gRiv0jWyLT9aRGb+pxtIPg0pt9BqriZe9bbsIWGY4gHMLRulTMpyA8ebbqWvvfUDiuAQ SwMf6rsBHnTSQif7ntC+VMGw0AuNCKnyPacXH5U1OoYXOQDm3u9iKMFEI1qg5h5avgxV cBKw== X-Gm-Message-State: AC+VfDzf5/32rbh++8mNxjl7vpfOtV2wA2lKsx5SeGQ7W4wKeoeZ1C3u +Vns7tmKVGWTQBGby3HZeLQ4wcB3E33dExaAgdWIEPrWOyh4gilVIGMtRC1dIJMe6S7OgRgK322 7yGCZLxR2GIW0cADm2+cOjFf/nd/jK8J0F/MT/O6l4nc= X-Received: by 2002:a05:6214:2347:b0:615:29ab:e4a8 with SMTP id hu7-20020a056214234700b0061529abe4a8mr4422586qvb.31.1682629839283; Thu, 27 Apr 2023 14:10:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4laAbHzi59OplL5JKmO3ZiPSgnb9qxKrUcBhNChCQYWle0Ak0C/LKDEq5d8xbA/FOOHc7blw== X-Received: by 2002:a05:6214:2347:b0:615:29ab:e4a8 with SMTP id hu7-20020a056214234700b0061529abe4a8mr4422500qvb.31.1682629838820; Thu, 27 Apr 2023 14:10:38 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id h11-20020a0cf44b000000b005fd79831ac7sm5655053qvm.84.2023.04.27.14.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:38 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev , Paul Durrant , Stefano Stabellini , Anthony Perard , Kevin Wolf , Hanna Reitz , Amit Shah , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= , John Snow , Peter Maydell , Mark Cave-Ayland , Keith Busch , Klaus Jensen , Fam Zheng , Dmitry Fleytman , "Gonglei (Arei)" , xen-devel@lists.xenproject.org (open list:X86 Xen CPUs), qemu-block@nongnu.org (open list:virtio-blk), qemu-arm@nongnu.org (open list:i.MX31 (kzm)), qemu-ppc@nongnu.org (open list:New World (mac99)) Subject: [PATCH v10 4/8] hw: replace most qemu_bh_new calls with qemu_bh_new_guarded Date: Thu, 27 Apr 2023 17:10:09 -0400 Message-Id: <20230427211013.2994127-5-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.137.80; envelope-from=alxndr@bu.edu; helo=esa7.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This protects devices from bh->mmio reentrancy issues. Thanks: Thomas Huth for diagnosing OS X test failure. Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Reviewed-by: Paul Durrant Signed-off-by: Alexander Bulekov Reviewed-by: Thomas Huth --- hw/9pfs/xen-9p-backend.c | 5 ++++- hw/block/dataplane/virtio-blk.c | 3 ++- hw/block/dataplane/xen-block.c | 5 +++-- hw/char/virtio-serial-bus.c | 3 ++- hw/display/qxl.c | 9 ++++++--- hw/display/virtio-gpu.c | 6 ++++-- hw/ide/ahci.c | 3 ++- hw/ide/ahci_internal.h | 1 + hw/ide/core.c | 4 +++- hw/misc/imx_rngc.c | 6 ++++-- hw/misc/macio/mac_dbdma.c | 2 +- hw/net/virtio-net.c | 3 ++- hw/nvme/ctrl.c | 6 ++++-- hw/scsi/mptsas.c | 3 ++- hw/scsi/scsi-bus.c | 3 ++- hw/scsi/vmw_pvscsi.c | 3 ++- hw/usb/dev-uas.c | 3 ++- hw/usb/hcd-dwc2.c | 3 ++- hw/usb/hcd-ehci.c | 3 ++- hw/usb/hcd-uhci.c | 2 +- hw/usb/host-libusb.c | 6 ++++-- hw/usb/redirect.c | 6 ++++-- hw/usb/xen-usb.c | 3 ++- hw/virtio/virtio-balloon.c | 5 +++-- hw/virtio/virtio-crypto.c | 3 ++- 25 files changed, 66 insertions(+), 33 deletions(-) diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index 74f3a05f88..0e266c552b 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -61,6 +61,7 @@ typedef struct Xen9pfsDev { int num_rings; Xen9pfsRing *rings; + MemReentrancyGuard mem_reentrancy_guard; } Xen9pfsDev; static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev); @@ -443,7 +444,9 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev) xen_9pdev->rings[i].ring.out = xen_9pdev->rings[i].data + XEN_FLEX_RING_SIZE(ring_order); - xen_9pdev->rings[i].bh = qemu_bh_new(xen_9pfs_bh, &xen_9pdev->rings[i]); + xen_9pdev->rings[i].bh = qemu_bh_new_guarded(xen_9pfs_bh, + &xen_9pdev->rings[i], + &xen_9pdev->mem_reentrancy_guard); xen_9pdev->rings[i].out_cons = 0; xen_9pdev->rings[i].out_size = 0; xen_9pdev->rings[i].inprogress = false; diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index b28d81737e..a6202997ee 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -127,7 +127,8 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, } else { s->ctx = qemu_get_aio_context(); } - s->bh = aio_bh_new(s->ctx, notify_guest_bh, s); + s->bh = aio_bh_new_guarded(s->ctx, notify_guest_bh, s, + &DEVICE(vdev)->mem_reentrancy_guard); s->batch_notify_vqs = bitmap_new(conf->num_queues); *dataplane = s; diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 734da42ea7..d8bc39d359 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -633,8 +633,9 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice *xendev, } else { dataplane->ctx = qemu_get_aio_context(); } - dataplane->bh = aio_bh_new(dataplane->ctx, xen_block_dataplane_bh, - dataplane); + dataplane->bh = aio_bh_new_guarded(dataplane->ctx, xen_block_dataplane_bh, + dataplane, + &DEVICE(xendev)->mem_reentrancy_guard); return dataplane; } diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 7d4601cb5d..dd619f0731 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -985,7 +985,8 @@ static void virtser_port_device_realize(DeviceState *dev, Error **errp) return; } - port->bh = qemu_bh_new(flush_queued_data_bh, port); + port->bh = qemu_bh_new_guarded(flush_queued_data_bh, port, + &dev->mem_reentrancy_guard); port->elem = NULL; } diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 80ce1e9a93..f1c0eb7dfc 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -2201,11 +2201,14 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp) qemu_add_vm_change_state_handler(qxl_vm_change_state_handler, qxl); - qxl->update_irq = qemu_bh_new(qxl_update_irq_bh, qxl); + qxl->update_irq = qemu_bh_new_guarded(qxl_update_irq_bh, qxl, + &DEVICE(qxl)->mem_reentrancy_guard); qxl_reset_state(qxl); - qxl->update_area_bh = qemu_bh_new(qxl_render_update_area_bh, qxl); - qxl->ssd.cursor_bh = qemu_bh_new(qemu_spice_cursor_refresh_bh, &qxl->ssd); + qxl->update_area_bh = qemu_bh_new_guarded(qxl_render_update_area_bh, qxl, + &DEVICE(qxl)->mem_reentrancy_guard); + qxl->ssd.cursor_bh = qemu_bh_new_guarded(qemu_spice_cursor_refresh_bh, &qxl->ssd, + &DEVICE(qxl)->mem_reentrancy_guard); } static void qxl_realize_primary(PCIDevice *dev, Error **errp) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 5e15c79b94..66ac9b6cc5 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1339,8 +1339,10 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) g->ctrl_vq = virtio_get_queue(vdev, 0); g->cursor_vq = virtio_get_queue(vdev, 1); - g->ctrl_bh = qemu_bh_new(virtio_gpu_ctrl_bh, g); - g->cursor_bh = qemu_bh_new(virtio_gpu_cursor_bh, g); + g->ctrl_bh = qemu_bh_new_guarded(virtio_gpu_ctrl_bh, g, + &qdev->mem_reentrancy_guard); + g->cursor_bh = qemu_bh_new_guarded(virtio_gpu_cursor_bh, g, + &qdev->mem_reentrancy_guard); QTAILQ_INIT(&g->reslist); QTAILQ_INIT(&g->cmdq); QTAILQ_INIT(&g->fenceq); diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 55902e1df7..4e76d6b191 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1509,7 +1509,8 @@ static void ahci_cmd_done(const IDEDMA *dma) ahci_write_fis_d2h(ad); if (ad->port_regs.cmd_issue && !ad->check_bh) { - ad->check_bh = qemu_bh_new(ahci_check_cmd_bh, ad); + ad->check_bh = qemu_bh_new_guarded(ahci_check_cmd_bh, ad, + &ad->mem_reentrancy_guard); qemu_bh_schedule(ad->check_bh); } } diff --git a/hw/ide/ahci_internal.h b/hw/ide/ahci_internal.h index 303fcd7235..2480455372 100644 --- a/hw/ide/ahci_internal.h +++ b/hw/ide/ahci_internal.h @@ -321,6 +321,7 @@ struct AHCIDevice { bool init_d2h_sent; AHCICmdHdr *cur_cmd; NCQTransferState ncq_tfs[AHCI_MAX_CMDS]; + MemReentrancyGuard mem_reentrancy_guard; }; struct AHCIPCIState { diff --git a/hw/ide/core.c b/hw/ide/core.c index 45d14a25e9..de48ff9f86 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -513,6 +513,7 @@ BlockAIOCB *ide_issue_trim( BlockCompletionFunc *cb, void *cb_opaque, void *opaque) { IDEState *s = opaque; + IDEDevice *dev = s->unit ? s->bus->slave : s->bus->master; TrimAIOCB *iocb; /* Paired with a decrement in ide_trim_bh_cb() */ @@ -520,7 +521,8 @@ BlockAIOCB *ide_issue_trim( iocb = blk_aio_get(&trim_aiocb_info, s->blk, cb, cb_opaque); iocb->s = s; - iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb); + iocb->bh = qemu_bh_new_guarded(ide_trim_bh_cb, iocb, + &DEVICE(dev)->mem_reentrancy_guard); iocb->ret = 0; iocb->qiov = qiov; iocb->i = -1; diff --git a/hw/misc/imx_rngc.c b/hw/misc/imx_rngc.c index 632c03779c..082c6980ad 100644 --- a/hw/misc/imx_rngc.c +++ b/hw/misc/imx_rngc.c @@ -228,8 +228,10 @@ static void imx_rngc_realize(DeviceState *dev, Error **errp) sysbus_init_mmio(sbd, &s->iomem); sysbus_init_irq(sbd, &s->irq); - s->self_test_bh = qemu_bh_new(imx_rngc_self_test, s); - s->seed_bh = qemu_bh_new(imx_rngc_seed, s); + s->self_test_bh = qemu_bh_new_guarded(imx_rngc_self_test, s, + &dev->mem_reentrancy_guard); + s->seed_bh = qemu_bh_new_guarded(imx_rngc_seed, s, + &dev->mem_reentrancy_guard); } static void imx_rngc_reset(DeviceState *dev) diff --git a/hw/misc/macio/mac_dbdma.c b/hw/misc/macio/mac_dbdma.c index 43bb1f56ba..80a789f32b 100644 --- a/hw/misc/macio/mac_dbdma.c +++ b/hw/misc/macio/mac_dbdma.c @@ -914,7 +914,7 @@ static void mac_dbdma_realize(DeviceState *dev, Error **errp) { DBDMAState *s = MAC_DBDMA(dev); - s->bh = qemu_bh_new(DBDMA_run_bh, s); + s->bh = qemu_bh_new_guarded(DBDMA_run_bh, s, &dev->mem_reentrancy_guard); } static void mac_dbdma_class_init(ObjectClass *oc, void *data) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 53e1c32643..447f669921 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2917,7 +2917,8 @@ static void virtio_net_add_queue(VirtIONet *n, int index) n->vqs[index].tx_vq = virtio_add_queue(vdev, n->net_conf.tx_queue_size, virtio_net_handle_tx_bh); - n->vqs[index].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[index]); + n->vqs[index].tx_bh = qemu_bh_new_guarded(virtio_net_tx_bh, &n->vqs[index], + &DEVICE(vdev)->mem_reentrancy_guard); } n->vqs[index].tx_waiting = 0; diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f59dfe1cbe..fd917fcda1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -4607,7 +4607,8 @@ static void nvme_init_sq(NvmeSQueue *sq, NvmeCtrl *n, uint64_t dma_addr, QTAILQ_INSERT_TAIL(&(sq->req_list), &sq->io_req[i], entry); } - sq->bh = qemu_bh_new(nvme_process_sq, sq); + sq->bh = qemu_bh_new_guarded(nvme_process_sq, sq, + &DEVICE(sq->ctrl)->mem_reentrancy_guard); if (n->dbbuf_enabled) { sq->db_addr = n->dbbuf_dbs + (sqid << 3); @@ -5253,7 +5254,8 @@ static void nvme_init_cq(NvmeCQueue *cq, NvmeCtrl *n, uint64_t dma_addr, } } n->cq[cqid] = cq; - cq->bh = qemu_bh_new(nvme_post_cqes, cq); + cq->bh = qemu_bh_new_guarded(nvme_post_cqes, cq, + &DEVICE(cq->ctrl)->mem_reentrancy_guard); } static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeRequest *req) diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c index c485da792c..3de288b454 100644 --- a/hw/scsi/mptsas.c +++ b/hw/scsi/mptsas.c @@ -1322,7 +1322,8 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp) } s->max_devices = MPTSAS_NUM_PORTS; - s->request_bh = qemu_bh_new(mptsas_fetch_requests, s); + s->request_bh = qemu_bh_new_guarded(mptsas_fetch_requests, s, + &DEVICE(dev)->mem_reentrancy_guard); scsi_bus_init(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info); } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index c97176110c..3c20b47ad0 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -193,7 +193,8 @@ static void scsi_dma_restart_cb(void *opaque, bool running, RunState state) AioContext *ctx = blk_get_aio_context(s->conf.blk); /* The reference is dropped in scsi_dma_restart_bh.*/ object_ref(OBJECT(s)); - s->bh = aio_bh_new(ctx, scsi_dma_restart_bh, s); + s->bh = aio_bh_new_guarded(ctx, scsi_dma_restart_bh, s, + &DEVICE(s)->mem_reentrancy_guard); qemu_bh_schedule(s->bh); } } diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c index fa76696855..4de34536e9 100644 --- a/hw/scsi/vmw_pvscsi.c +++ b/hw/scsi/vmw_pvscsi.c @@ -1184,7 +1184,8 @@ pvscsi_realizefn(PCIDevice *pci_dev, Error **errp) pcie_endpoint_cap_init(pci_dev, PVSCSI_EXP_EP_OFFSET); } - s->completion_worker = qemu_bh_new(pvscsi_process_completion_queue, s); + s->completion_worker = qemu_bh_new_guarded(pvscsi_process_completion_queue, s, + &DEVICE(pci_dev)->mem_reentrancy_guard); scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(pci_dev), &pvscsi_scsi_info); /* override default SCSI bus hotplug-handler, with pvscsi's one */ diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c index 88f99c05d5..f013ded91e 100644 --- a/hw/usb/dev-uas.c +++ b/hw/usb/dev-uas.c @@ -937,7 +937,8 @@ static void usb_uas_realize(USBDevice *dev, Error **errp) QTAILQ_INIT(&uas->results); QTAILQ_INIT(&uas->requests); - uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas); + uas->status_bh = qemu_bh_new_guarded(usb_uas_send_status_bh, uas, + &d->mem_reentrancy_guard); dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE); scsi_bus_init(&uas->bus, sizeof(uas->bus), DEVICE(dev), &usb_uas_scsi_info); diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c index 8755e9cbb0..a0c4e782b2 100644 --- a/hw/usb/hcd-dwc2.c +++ b/hw/usb/hcd-dwc2.c @@ -1364,7 +1364,8 @@ static void dwc2_realize(DeviceState *dev, Error **errp) s->fi = USB_FRMINTVL - 1; s->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, dwc2_frame_boundary, s); s->frame_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, dwc2_work_timer, s); - s->async_bh = qemu_bh_new(dwc2_work_bh, s); + s->async_bh = qemu_bh_new_guarded(dwc2_work_bh, s, + &dev->mem_reentrancy_guard); sysbus_init_irq(sbd, &s->irq); } diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index d4da8dcb8d..c930c60921 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2533,7 +2533,8 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp) } s->frame_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ehci_work_timer, s); - s->async_bh = qemu_bh_new(ehci_work_bh, s); + s->async_bh = qemu_bh_new_guarded(ehci_work_bh, s, + &dev->mem_reentrancy_guard); s->device = dev; s->vmstate = qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s); diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index 8ac1175ad2..77baaa7a6b 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -1190,7 +1190,7 @@ void usb_uhci_common_realize(PCIDevice *dev, Error **errp) USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); } } - s->bh = qemu_bh_new(uhci_bh, s); + s->bh = qemu_bh_new_guarded(uhci_bh, s, &DEVICE(dev)->mem_reentrancy_guard); s->frame_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, uhci_frame_timer, s); s->num_ports_vmstate = NB_PORTS; QTAILQ_INIT(&s->queues); diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 176868d345..f500db85ab 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1141,7 +1141,8 @@ static void usb_host_nodev_bh(void *opaque) static void usb_host_nodev(USBHostDevice *s) { if (!s->bh_nodev) { - s->bh_nodev = qemu_bh_new(usb_host_nodev_bh, s); + s->bh_nodev = qemu_bh_new_guarded(usb_host_nodev_bh, s, + &DEVICE(s)->mem_reentrancy_guard); } qemu_bh_schedule(s->bh_nodev); } @@ -1739,7 +1740,8 @@ static int usb_host_post_load(void *opaque, int version_id) USBHostDevice *dev = opaque; if (!dev->bh_postld) { - dev->bh_postld = qemu_bh_new(usb_host_post_load_bh, dev); + dev->bh_postld = qemu_bh_new_guarded(usb_host_post_load_bh, dev, + &DEVICE(dev)->mem_reentrancy_guard); } qemu_bh_schedule(dev->bh_postld); dev->bh_postld_pending = true; diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index fd7df599bc..39fbaaab16 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1441,8 +1441,10 @@ static void usbredir_realize(USBDevice *udev, Error **errp) } } - dev->chardev_close_bh = qemu_bh_new(usbredir_chardev_close_bh, dev); - dev->device_reject_bh = qemu_bh_new(usbredir_device_reject_bh, dev); + dev->chardev_close_bh = qemu_bh_new_guarded(usbredir_chardev_close_bh, dev, + &DEVICE(dev)->mem_reentrancy_guard); + dev->device_reject_bh = qemu_bh_new_guarded(usbredir_device_reject_bh, dev, + &DEVICE(dev)->mem_reentrancy_guard); dev->attach_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, usbredir_do_attach, dev); packet_id_queue_init(&dev->cancelled, dev, "cancelled"); diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 66cb3f7c24..38ee660a30 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -1032,7 +1032,8 @@ static void usbback_alloc(struct XenLegacyDevice *xendev) QTAILQ_INIT(&usbif->req_free_q); QSIMPLEQ_INIT(&usbif->hotplug_q); - usbif->bh = qemu_bh_new(usbback_bh, usbif); + usbif->bh = qemu_bh_new_guarded(usbback_bh, usbif, + &DEVICE(xendev)->mem_reentrancy_guard); } static int usbback_free(struct XenLegacyDevice *xendev) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index fd06fcfb3f..d004cf29d2 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -886,8 +886,9 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp) precopy_add_notifier(&s->free_page_hint_notify); object_ref(OBJECT(s->iothread)); - s->free_page_bh = aio_bh_new(iothread_get_aio_context(s->iothread), - virtio_ballloon_get_free_page_hints, s); + s->free_page_bh = aio_bh_new_guarded(iothread_get_aio_context(s->iothread), + virtio_ballloon_get_free_page_hints, s, + &dev->mem_reentrancy_guard); } if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_REPORTING)) { diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 802e1b9659..2fe804510f 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1074,7 +1074,8 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp) vcrypto->vqs[i].dataq = virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_bh); vcrypto->vqs[i].dataq_bh = - qemu_bh_new(virtio_crypto_dataq_bh, &vcrypto->vqs[i]); + qemu_bh_new_guarded(virtio_crypto_dataq_bh, &vcrypto->vqs[i], + &dev->mem_reentrancy_guard); vcrypto->vqs[i].vcrypto = vcrypto; } From patchwork Thu Apr 27 21:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E04AC77B7C for ; Thu, 27 Apr 2023 21:11:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tA-0005sq-DV; Thu, 27 Apr 2023 17:10:52 -0400 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 1ps8t6-0005rx-0t for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:49 -0400 Received: from esa8.hc2706-39.iphmx.com ([216.71.140.196]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8t3-0005MH-82 for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:47 -0400 X-IronPort-RemoteIP: 209.85.222.199 X-IronPort-MID: 273267400 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:+IGXKaA07k9pqxVW/5fhw5YqxClBgxIJ4kV8jS/XYbTApGwrgTIDz WEeXT+DPfmIZ2X2fdAlPoWx/U8G78DSy9Y3TANkpHpgcSl2pJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdleF+lH2dOCn9SImvU2xbuKUIPbePSxsThNTRi4kiBZy88Y0mYctitWia++3k YqaT/b3ZRn0ilaYDkpOs/jY8E8146yp0N8llgdWic5j7Qe2e0Y9Ucp3yZGZdxPQXoRSF+imc OfPpJnRErTxpkpF5nuNy94XQ2VTKlLgFVHmZkl+AsBOtiN/Shkaic7XAha9hXB/0F1ll/gpo DlEWAfZpQ0BZ8Ugk8xEO/VU/r0X0QSrN9YrLFDm2fF/wXEqfFPGyqpEF1smALEkubl7XmJWr sJHGTskO0Xra+KemNpXS8Fpj8UnadDoZcYR4yAxiz7eCvkiTNbIRKCiCd1whm9hwJATW6yEP YxAOGsHgBfoOnWjPn8eDII4kP2AjGS5fjFFwL6QjfBouDKNk1ApiNABNvLqIPGTdOkSwX+U+ ELFxELhHA0cOe6AnG/tHnWEw7WncTnAcJsfEaD9+vN0jVm7wGsVBxsLE1yhrpGEZlWWXtteL wkN+XNro/FjpQqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxXQDokhYphAQaifIL IronPort-HdrOrdr: A9a23:tpe5R66AU/ywPhytLAPXwPHXdLJyesId70hD6qkRc20tTiX8ra qTdZsgtSMc5AxhP03Is+rwW5VoOEmsl6KdgrN+AV7BZniChILAFugLhrcKqAeQfxEWmNQts5 uIsJITNDQzNzVHZArBjzVQ2uxA/OW6 X-Talos-CUID: 9a23:J+VyKWnx4lwOShyXdceA2zgtfnrXOVfUk13LOV+FNVoqF7HKSkfLxvxVmOM7zg== X-Talos-MUID: 9a23:q2HQIgrTUrfcNGGofpoezw44Gd5Zz+PxMUxTsZY9ndGaKSp9CSjI2Q== Received: from mail-qk1-f199.google.com ([209.85.222.199]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:43 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74e0cfab3f0so1383337785a.1 for ; Thu, 27 Apr 2023 14:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629842; x=1685221842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3SdAMrXHXFKpIl5axn2Wa+vv4dRDlBMdBU9qEifc6x0=; b=KW7CV0J6EY0fDwThGtGw2mV/XIr2QVr9ZzmmCxQL3KD5G23HIbJP/Ts25JkCfWJ+RC IxqH5DOE5TQpIU5qq1u4hOuL3nbZrAkljXBE8lakBfKn7bTXfWNyNOCZz14xAvGyp0+S 2hGWcspqZ4+8E2sXL+sv2K0mdNtZj2GbZF9R1aa0i6SV9V89V7VGCreAM1BlXZ8ybVrV rqHkU/HW4W5kRTo+9zfKTibYMRJ9flsws+Snd0flNLR/81a6s0K1F6xk6k+oQ4LOPkO9 LYW0Q/4CCusiAk91x76HiHDTm7kXIVoCebsvov/G4taQnZfTgFuXGz/FGKq8VHbM4P9n agQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629842; x=1685221842; 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=3SdAMrXHXFKpIl5axn2Wa+vv4dRDlBMdBU9qEifc6x0=; b=cxMteY2wlHYSqj5WPa+TnQcxF9K44l6TrhekrJHif6A6d0hL11FeXK2frH6bcPi0Uk 1IWQE+xitGhHt+UrCXlzO0fxn/raDFJ4RZGghYS1cNGuxb1jHesWwFpCncFb42Y7hu6L Qcd7ynkWDwo7Wq1yY3LhmcAtFfC632qr/H9QMyww5Z2uli4xjJBIJxiF26aItcK5+udW riuyKvZ39Sl6/d9o0hPrkYlIsKMnxjDNCra+STHunq3DE/5E75brKZExlCQMtktTJnI+ l/0ihN7dLfWbQcP24UhNIUclfjqhBdOZ1h4YsjaCl0PdgpyyuB/OgQkICWnJcLHu9Rie FJtQ== X-Gm-Message-State: AC+VfDz2r+E1oowp2QLPUVlejiEKprhnO2wDbv0zwSiPwX6+DgnU4gRZ EPU2D4lAo4j4Q7busM7lY2x/BfuZ+Fabr+pdJ50bxwD9tAqSilSoeNWfIYXB2ZUQPan9PjhBKn1 osevOOpvycpDPjjSNSVH+dT/13UoSsZ8vI4aoK2LYPbg= X-Received: by 2002:a05:6214:20ee:b0:614:da60:f45d with SMTP id 14-20020a05621420ee00b00614da60f45dmr4902469qvk.30.1682629842287; Thu, 27 Apr 2023 14:10:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6B2366U41LLQszN6ihcZBrJk8YDRrKzcE3mBVfX6MFBk6kfHQJtYnCxk0tCNi7X4uqKewdLA== X-Received: by 2002:a05:6214:20ee:b0:614:da60:f45d with SMTP id 14-20020a05621420ee00b00614da60f45dmr4902422qvk.30.1682629842058; Thu, 27 Apr 2023 14:10:42 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id z30-20020a0ca95e000000b005ef61084fddsm5909401qva.131.2023.04.27.14.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:41 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev , Fiona Ebner , Fam Zheng Subject: [PATCH v10 5/8] lsi53c895a: disable reentrancy detection for script RAM Date: Thu, 27 Apr 2023 17:10:10 -0400 Message-Id: <20230427211013.2994127-6-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.196; envelope-from=alxndr@bu.edu; helo=esa8.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As the code is designed to use the memory APIs to access the script ram, disable reentrancy checks for the pseudo-RAM ram_io MemoryRegion. In the future, ram_io may be converted from an IO to a proper RAM MemoryRegion. Reported-by: Fiona Ebner Signed-off-by: Alexander Bulekov Reviewed-by: Thomas Huth Reviewed-by: Darren Kenny --- hw/scsi/lsi53c895a.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index af93557a9a..db27872963 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -2302,6 +2302,12 @@ static void lsi_scsi_realize(PCIDevice *dev, Error **errp) memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s, "lsi-io", 256); + /* + * Since we use the address-space API to interact with ram_io, disable the + * re-entrancy guard. + */ + s->ram_io.disable_reentrancy_guard = true; + address_space_init(&s->pci_io_as, pci_address_space_io(dev), "lsi-pci-io"); qdev_init_gpio_out(d, &s->ext_irq, 1); From patchwork Thu Apr 27 21:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A3ECC77B61 for ; Thu, 27 Apr 2023 21:12:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tD-0005up-H1; Thu, 27 Apr 2023 17:10:55 -0400 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 1ps8tC-0005uQ-Ks for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:54 -0400 Received: from esa16.hc2706-39.iphmx.com ([216.71.140.205]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8tB-0005N6-1u for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:10:54 -0400 X-IronPort-RemoteIP: 209.85.160.198 X-IronPort-MID: 273505222 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:L1ko/qMmjNAJjcXvrR0clcFynXyQoLVcMsEvi/4bfWQNrUpzhWZSy WUfUW2DPf7cMWrxf9gkbI+//BsPvsDUzN82SAZtpSBmQkwRlceUXt7xwmUcns+xwm8vaGo9s q3yv/GZdJhcokf0/0vraf656yEnj8lkf5KkYMbcICd9WAR4fykojBNnioYRj5VhxNO0GGthg /uryyHkEALjim8c3l48sfrZ80sz5quq41v0g3RlDRx1lA6G/5UqJM9HTU2BByOQapVZGOe8W 9HCwNmRlo8O105wYj8Nuu+TnnwiG9Y+DyDX4pZlc/HKbix5m8AH+v1T2MzwyKtgo27hc9hZk L2hvHErIOsjFvSkdO81CnG0H8ziVEHvFXCuzXWX6KSuI0P6n3TE76RwFmMaDKgj2LhRJ1AUz voGFA0OV0XW7w626OrTpuhEg80iKIzyINpatCgxnXfWCvEpRZ2FSKLPjTNa9G1o14YeQLCHO ZJfMGs/BPjDS0Qn1lM/AZYumuuyrnPiNTBUtTp5oIJtvDOOlFEriuKF3Nz9Q+WPHJlzgB6hv DyF8U6lHj9CD/HF4G/Qmp6rrqqV9c/hY6oLGbils/JnnlCX7moUDhIQSB28u/bRt6Klc9dWK khR4zZ36KZrpRztQd76UBm15nWDu3bwRuZtLgHz0ynVooK83upTLjJYJtKdQLTKbPMLeAE= IronPort-HdrOrdr: A9a23:OekdeK5sCWHurHwhSgPXwPLXdLJyesId70hD6qkXc3Bom62j+P xG+c5x6faaslgssR0b+OxoWpPwIk80hKQU3WB5B97LNmTbUQ2TXeRfBODZsl/d8kPFh4lg/J YlX69iCMDhSXhW5PyKhjVQyuxQpOW6zA== X-Talos-CUID: 9a23:JmGVPmjDK6bOEhuqmqhpZxuLFjJuXizD1lX8EmqDKzhPbozPclmOxJ5nqp87 X-Talos-MUID: 9a23:KtIfMwX5UMfVn2jq/AbVgWg+Etkw2r7wS04nzYko4/KpbwUlbg== Received: from mail-qt1-f198.google.com ([209.85.160.198]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:46 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3ef691d1eebso41123141cf.3 for ; Thu, 27 Apr 2023 14:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629845; x=1685221845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=baPw7HeUNSOgBdUdX5+Wv116KVOdtz82o0yKX11s6GY=; b=bLc+Sf5D1COH9x0JkJGO6Ctb9788JBLqleFbg1rk9fKeYwT1xuEpXgsPlBhLdBxhc8 +dHqKSk7ueRWZawLcd9+Lqpt+n57ngOvEilE/H/vrR4RembzJXWHy2UfrV5dI/YqXTOS lQtmWH3P2jAFFIoFwK1y0p/lKJerr8CicukEyGsfIZNl01WAhafJnv2jlDL24EjkEPru xXHtzIt1wpHEYtZdX6uiiXwxTqORr17CyOzXdCa1CrS9kWtARYnIOQ5v6cYDXWrD+aWm XbWeTViYxuACcF2UU7KxIm5JIn5LQ+xm2cOGEDpX1wfDJ3ArwMCvHTyw22PhEYrk17uc GNJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629845; x=1685221845; 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=baPw7HeUNSOgBdUdX5+Wv116KVOdtz82o0yKX11s6GY=; b=M2C9Ajbb6IVCXJcoMpZyL0E+nhXF5IR+or/D5s1U2SkoK96tjT0iZDRB2mB5SKeYIN p11KWbB4T3Dq8aOQmpR6bMLMQWibOcgUkybxuDfesHFpDhX7/jFelfFZqU3tH5km3NlH mwgo7mISidkzovYQg15kdKfa4SiNmIVFNyq74BJI9Rx4YebJXHQ+YTev9RqOsgTo3Cau vvzi39aHPhnZP/MIS3fjRWCTlgZCequluGj4qDa2aMUjZtRGceGYc1qVd/rMnR8Ovydp M/r32aM5ZLgLzRYHYAWdBeSTsyUss83ONPw0LeYGfTBGfjP1Hj8RTW2kATzS/SZv6zat pabQ== X-Gm-Message-State: AC+VfDxGPa99daqbrbwuUqTjcvkK1jJ+iSxtd9VtxnPGn5On1lGfk77y LsFFGcakv34p/DOnNP1ykQOxC9wrBPMksRHi53xNCxmgTQALyJJ6V9f1OGvEzS0grRTHYLKiy6w hkngDU08HtVoGsGvdV6yHZsMwe+lWQcpMYb6uoXP7J7M= X-Received: by 2002:ac8:57c4:0:b0:3ea:bac1:a5be with SMTP id w4-20020ac857c4000000b003eabac1a5bemr4760082qta.42.1682629845233; Thu, 27 Apr 2023 14:10:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qbri2Q+LH4NR35KATOGWb7DKHwgO2Xe2TuucXECJ/VltVtTl8c7BvSI8Jk5PVIxv7tHJtJg== X-Received: by 2002:ac8:57c4:0:b0:3ea:bac1:a5be with SMTP id w4-20020ac857c4000000b003eabac1a5bemr4760042qta.42.1682629844982; Thu, 27 Apr 2023 14:10:44 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id y11-20020ac8128b000000b003ef6582d971sm4947634qti.47.2023.04.27.14.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:44 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev , Peter Maydell , qemu-arm@nongnu.org (open list:Raspberry Pi) Subject: [PATCH v10 6/8] bcm2835_property: disable reentrancy detection for iomem Date: Thu, 27 Apr 2023 17:10:11 -0400 Message-Id: <20230427211013.2994127-7-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.205; envelope-from=alxndr@bu.edu; helo=esa16.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As the code is designed for re-entrant calls from bcm2835_property to bcm2835_mbox and back into bcm2835_property, mark iomem as reentrancy-safe. Signed-off-by: Alexander Bulekov Reviewed-by: Thomas Huth --- hw/misc/bcm2835_property.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c index 890ae7bae5..de056ea2df 100644 --- a/hw/misc/bcm2835_property.c +++ b/hw/misc/bcm2835_property.c @@ -382,6 +382,13 @@ static void bcm2835_property_init(Object *obj) memory_region_init_io(&s->iomem, OBJECT(s), &bcm2835_property_ops, s, TYPE_BCM2835_PROPERTY, 0x10); + + /* + * bcm2835_property_ops call into bcm2835_mbox, which in-turn reads from + * iomem. As such, mark iomem as re-entracy safe. + */ + s->iomem.disable_reentrancy_guard = true; + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); sysbus_init_irq(SYS_BUS_DEVICE(s), &s->mbox_irq); } From patchwork Thu Apr 27 21:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 709F0C77B73 for ; Thu, 27 Apr 2023 21:12:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tL-0005wu-AG; Thu, 27 Apr 2023 17:11:03 -0400 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 1ps8tJ-0005wD-I5 for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:01 -0400 Received: from esa6.hc2706-39.iphmx.com ([216.71.137.79]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8tI-0005Ov-22 for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:01 -0400 X-IronPort-RemoteIP: 209.85.160.197 X-IronPort-MID: 279189031 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:NWQ9OatJlLyuki7FmAlnZjIIHOfnVO9cMUV32f8akzHdYApBsoF/q tZmKT3SbvvbM2HxeookPN/n9E4C7cCDz95nS1Rlqn1kHnwR9ZOVVN+UEBzMMnLJJKUvbq7GA +byyDXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS+XuDgNyo4GlD5gBkOqgQ1LPjvyJ94Kw3dPnZw0TQH9E88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IPM0SQqkEqSh8ai87XAMEhhXJ/0F1lqTzQJ OJl7vRcQS9xVkHFdX90vxNwSkmSNoUfkFPLzOTWXWV+ACQqflO1q8iCAn3aMqU34PZ4CkVp5 cZFFxAEaQu8v8WYyZuCH7wEasQLdKEHPasas3BkiCjFVLMoGMGcBarN4tBc0XE7gcUm8fT2P ZJIL2oyKk2eO1sWawh/5JEWxY9EglH2dy1epEi9r7dx7mTOpOB0+OKyYYOFK4TRHK25mG6Su U/Lr07EOi1DJfOuzh+C43eOi9L2yHaTtIU6UefQGuRRqESew3FWBBAIWF+Tp/6/hUijHdVFJ CQpFjEGqKEz8AmyUoC4UUTp/ziLuRkTX9cWGOo/gO2Q9pfpD8+iLjBsZlZ8hBYO75FeqeACv rNRo+7UOA== IronPort-HdrOrdr: A9a23:0y2CWageyocUg78Kg6URRATF4HBQXgwji2hC6mlwRA09TyVXrb HLoB19726JtN91YhsdcL+7Sc+9qB/nhPxICMwqTMyftWrdyRaVxf9ZnPLfKlTbckWUh41gPO VbAtJD4bXLbWSS5vyKhzVQfexQpeWvweSDqd2b4U1QbTxHXYld0iYRMHflLqS0fmV77FgCea Z0KvAom9PZQwVuUi1zPBZlY9T+ X-Talos-CUID: 9a23:Y/Yitm7s+1NR90DwZtss21QEFcsBVW3nkUjwKkijNl5OZrS8cArF X-Talos-MUID: 9a23:y0solQsOaw4xytAJdM2nji5POZdC3pySUVEioJIjvNiBFyFNAmLI Received: from mail-qt1-f197.google.com ([209.85.160.197]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:49 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3ef3fc80bb6so103868531cf.1 for ; Thu, 27 Apr 2023 14:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629848; x=1685221848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=68oaiYGL7UhG3W5jva6oSZ0GIeZDrcn2k6P7uHwGxlY=; b=YSJAwvgbkH9fCZCzgmtIGlAln585VR2jxmWRALT8Yi2/XojQ5qUBmUfQEzau/aCnEK 7DCedm+QrBtV8fCgFzEBNcckbrbiaGOzt7ihuhMcFBsWIuVhuNq4x9thhQST/QW/mWbR 5sdJ0Ydw8YVaTPhpoBKMYZfOedNPehCOATEndJ2fmVdQDYcTrHzryH0sp4dZwvUgDjNK u9XAsGMywpSbUoVvtSIf7QqAPMLp85ZkX1/yuZsdo0j7phkruWM7ZjL5KfmffM7Cjw0b WwKizpYWu4jEYS4o8XqazzJoMXFZeYbZhLSdZQc6Bs+HQsSSwm04Gaaqyl5V6sbvYP6C AnCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629848; x=1685221848; 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=68oaiYGL7UhG3W5jva6oSZ0GIeZDrcn2k6P7uHwGxlY=; b=adMb1cepxVE144y9Xzi56+dSBgLJ1tk8vfCacMYy4ya6YCNJXzR4XQ8ZBmFSz8+3Or KuoRT6Ot4VstozyBvMM8UL2IROUPQHmaATNvNgZffurNq6GscbAmbt2n8DLjRKltGoOr 5YYjX/F2JNmR2JsR41+jLYrpN0vuWNg2JsSSknw/E1t8jdQz3GDZ8kW3UrcTl24wNHfU k8j35JoBusxM68sAXFeBnYOdlDXxCpcn4Z9tifZBaaBfKRVTUpVd/8Bif802HoF4Osd9 t4sRd9K+wrx2q7Q53GrlxfQiMP/NbAUQxk1QTjOxFlJxhg1W/4h+vPVIegaSJ11nuO/y Fg1Q== X-Gm-Message-State: AC+VfDzDnTPNIOs5iiAcmbuGLj5us/qV3tF9uD4iESB/w/gzt8gJYvJo rrz/fLdJX1cVhdztPG7DAvD2zmZhgNwig/9MWZMhlKVdaD33rPUgcu36O5CC5+BGA72mF3fxfy/ sfmgHbgtF1QDgE+Z/2bNjyERarmgp3mbcl0Rl5hzUc08= X-Received: by 2002:a05:622a:649:b0:3ef:3bad:6d24 with SMTP id a9-20020a05622a064900b003ef3bad6d24mr4087797qtb.47.1682629848454; Thu, 27 Apr 2023 14:10:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wcIS9ZrvhiadDC7X/QUy+vREYVt3Z6AlKXrwXCOzQvwDK1XzR/bvOsR0KVROqeeeemzrb7g== X-Received: by 2002:a05:622a:649:b0:3ef:3bad:6d24 with SMTP id a9-20020a05622a064900b003ef3bad6d24mr4087748qtb.47.1682629848140; Thu, 27 Apr 2023 14:10:48 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id z16-20020a05620a08d000b0074acaeeb7c3sm6204862qkz.91.2023.04.27.14.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:47 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev , =?utf-8?q?Herv=C3=A9_Poussineau?= , qemu-ppc@nongnu.org (open list:PReP) Subject: [PATCH v10 7/8] raven: disable reentrancy detection for iomem Date: Thu, 27 Apr 2023 17:10:12 -0400 Message-Id: <20230427211013.2994127-8-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.137.79; envelope-from=alxndr@bu.edu; helo=esa6.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As the code is designed for re-entrant calls from raven_io_ops to pci-conf, mark raven_io_ops as reentrancy-safe. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- hw/pci-host/raven.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/pci-host/raven.c b/hw/pci-host/raven.c index 072ffe3c5e..9a11ac4b2b 100644 --- a/hw/pci-host/raven.c +++ b/hw/pci-host/raven.c @@ -294,6 +294,13 @@ static void raven_pcihost_initfn(Object *obj) memory_region_init(&s->pci_memory, obj, "pci-memory", 0x3f000000); address_space_init(&s->pci_io_as, &s->pci_io, "raven-io"); + /* + * Raven's raven_io_ops use the address-space API to access pci-conf-idx + * (which is also owned by the raven device). As such, mark the + * pci_io_non_contiguous as re-entrancy safe. + */ + s->pci_io_non_contiguous.disable_reentrancy_guard = true; + /* CPU address space */ memory_region_add_subregion(address_space_mem, PCI_IO_BASE_ADDR, &s->pci_io); From patchwork Thu Apr 27 21:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 13225758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D48FBC77B61 for ; Thu, 27 Apr 2023 21:11:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps8tN-0005xN-V1; Thu, 27 Apr 2023 17:11:05 -0400 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 1ps8tM-0005ww-BQ for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:04 -0400 Received: from esa10.hc2706-39.iphmx.com ([216.71.140.198]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps8tJ-0005P8-U5 for qemu-devel@nongnu.org; Thu, 27 Apr 2023 17:11:03 -0400 X-IronPort-RemoteIP: 209.85.160.199 X-IronPort-MID: 277337817 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:Jmu5rapF85A5OqOpdiULYmbY/z1eBmKhZxIvgKrLsJaIsI4StFCzt garIBmPPviDZmqjL9p1bIrl8BxTsZWEzIQyTlFv+308RXlG95acVYWSI3mrAy7DdceroGCLT ik9hnssCOhuExcwcz/0auCJQUFUjP3OHfykTrafYEidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw//F+UIHUMja4mtC5QRiP68T5zcyqlFOZH4hDfDpR5fHatQMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+AsBOsDAbzsAB+v9T2M4nVKtio27hc+ada Tl6ncfYpQ8BZsUgkQmGOvVSO3gW0aZuodcrLZUj2CA6IoKvn3bEmp1T4E8K0YIw++pqLHNc0 sEjeDlURTmunPyq5o21Y7w57igjBJGD0II3v3hhyXTAEa9jT8mSEuPF4thX2Dp2jcdLdRrcT 5BBOHw/MVKZPUUJYwZGYH49tL7Aan3XejlIrl6PjaAqpWXf0WSd1ZC3b4WOIYPaHJo9ckCwp Wni9kegICMgBdWTlxPYzyPzvsWSpHauMG4VPPjinhJwu3WKy2kOTREbS1a/if++jEG4RpRYM UN8x8Y1ha079UjuV8WkGhPh8S/CsRkbVN5dVeY97Wlh15bp3upQPUBcJhYpVTDsnJVnLdD2/ jdlR+/UOAE= IronPort-HdrOrdr: A9a23:35YZdaqQflGr/aJv84lw8MEaV5oleYIsimQD101hICG9Afb5qy nOpp4mPHDP5Ar5NEtQ/OxofZPwJU80lqQb3WByB9qftWDd0QPCEGgh1/qA/9SKIUzDH4BmpM VdmuRFZuEZUDVB/KHH3DU= X-Talos-CUID: 9a23:+g5BYG8iTi6sqYbBezOVv08YB+03YFrg9yfZemSRJH13VJuqR3bFrQ== X-Talos-MUID: 9a23:AHs5UQloJ7KgL6L03XvkdnphP+NhwP2MOno8mJlYkpS5ZHNIEWqk2WE= Received: from mail-qt1-f199.google.com ([209.85.160.199]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Apr 2023 17:10:52 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3ef34e947edso103958281cf.3 for ; Thu, 27 Apr 2023 14:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682629852; x=1685221852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VCVW0/HeXmkSG974OczBBkQKZv6zFcpwChDreWsVAYs=; b=CG3zTuVEJhKMbMyUfD7jzbWH2W3t7/iYo37X7NCBLfzng8x292K0RSLSF3tqXgOCk4 T4hz68fxCMTzvNTeeACo85dj0LaeUqfdzxQTHyxI0wL6P0HevMrtL2UgoxoOQRCwMQ9q th0cD4hqU6LU7R1Xjw+PPynexCAPEGWk0kr6KFFvKZ9hV1Iv3F1uzRw/Ge8yb1GXJ76A J5qNmgaBollGNoG/+9/TSMxHYXJ7WOkEVS0ZKUkRxfFyDCC6reYAhGAeBhLafitNiQuI Ck2mDY2LRMgyF/JM+3DFLlZlh52z6NGOQsrIVf5sZfspZ6JiCVzKuAroWzEu7QcyPg5w Qgug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682629852; x=1685221852; 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=VCVW0/HeXmkSG974OczBBkQKZv6zFcpwChDreWsVAYs=; b=HeISDYN+VOCKCyHUE9efTyujRJ6O2HprF7PIMQQ8bD7qhMosiyrV/1jHa9rmAIANZa qI/orAZ7Q+gOR6OEWxRawfyTq4CP5wei3P4MLTG/fPPayp+oRBxP9/hM8tuNztlw1GfU W0JWRuURGgEyA/uEko0iagdLBD29LNIB7/Kbc28k/xZyasc2d/oXzMGZPovmgzfWVSbd oj0r8t5j22g0Z0h9NdHjVPGVPKlZBXG6AvHYfS4ADNutN36/htXofWJlsYict6xhtSM/ PPZ1WTUQMfoNvH52qHKXMNuG8TtRtFbYJG2bHZFYhM5GhSyTg+EXvxipgQGuBhdf9AcH 9YjA== X-Gm-Message-State: AC+VfDwYzAFylnwH7jjzDkPuiaGiVboxM4LwUxWDnLMAvzGWl50o8BPp hoSp8Bey4arglfwxBzsvJcCSZlq/8I/pxIVESdqdKPBMBt65IDvV3vFzOLgRxsJzaTutr3BVuLz uOHswpQqdvrvtqacOXsz29+51PeBWce9Asj0qby3WIGQ= X-Received: by 2002:a05:622a:1ba0:b0:3ef:7d5d:9c41 with SMTP id bp32-20020a05622a1ba000b003ef7d5d9c41mr4651247qtb.59.1682629851969; Thu, 27 Apr 2023 14:10:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qfpiBBwJj/WJmQRZMq3EbZALbqLQ558wusxGNjmhoQhcSYVCsLMMSDSX6i3qHnzxmLF3GlA== X-Received: by 2002:a05:622a:1ba0:b0:3ef:7d5d:9c41 with SMTP id bp32-20020a05622a1ba000b003ef7d5d9c41mr4651192qtb.59.1682629851634; Thu, 27 Apr 2023 14:10:51 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id e21-20020ac84e55000000b003bd0f0b26b0sm6515099qtw.77.2023.04.27.14.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 14:10:51 -0700 (PDT) From: Alexander Bulekov To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Peter Xu , Jason Wang , David Hildenbrand , Gerd Hoffmann , Thomas Huth , Laurent Vivier , Bandan Das , "Edgar E . Iglesias" , Darren Kenny , Bin Meng , Paolo Bonzini , "Michael S . Tsirkin" , Marcel Apfelbaum , =?utf-8?q?Daniel_P_=2E_Berra?= =?utf-8?q?ng=C3=A9?= , Eduardo Habkost , Jon Maloy , Siqi Chen , Michael Tokarev Subject: [PATCH v10 8/8] apic: disable reentrancy detection for apic-msi Date: Thu, 27 Apr 2023 17:10:13 -0400 Message-Id: <20230427211013.2994127-9-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230427211013.2994127-1-alxndr@bu.edu> References: <20230427211013.2994127-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.198; envelope-from=alxndr@bu.edu; helo=esa10.hc2706-39.iphmx.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.266, HK_RANDOM_FROM=0.999, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As the code is designed for re-entrant calls to apic-msi, mark apic-msi as reentrancy-safe. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Acked-by: Michael S. Tsirkin --- hw/intc/apic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 20b5a94073..ac3d47d231 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -885,6 +885,13 @@ static void apic_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s, "apic-msi", APIC_SPACE_SIZE); + /* + * apic-msi's apic_mem_write can call into ioapic_eoi_broadcast, which can + * write back to apic-msi. As such mark the apic-msi region re-entrancy + * safe. + */ + s->io_memory.disable_reentrancy_guard = true; + s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s); local_apics[s->id] = s;