From patchwork Wed Apr 26 16:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=XbuXcj6P; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q63zx3FH1z23s0 for ; Thu, 27 Apr 2023 02:22:21 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhuI-0003u3-S4; Wed, 26 Apr 2023 12:22:14 -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 1prhuH-0003q4-Jl for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:22:13 -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 1prhuE-00062o-QT for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:22:12 -0400 X-IronPort-RemoteIP: 209.85.219.71 X-IronPort-MID: 278852838 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:1hWYx6l17Ck4pqBo183zWdvo5gw+JERdPkR7XQ2eYbSJt1+Wr1Gzt xJLXm6OPv6IM2Pyf4gkaom/8h4O6MDVnNZkSAU++SpmFS4T+ZvOCOrCEkqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvPrRC9H5qyo42tE5AJmP5ingXeF/5UrJMNHTU2OByagKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0xK6aYD76vRxjnVaPpIACRYpQRw/ZwNlPjxG4 I4lWZSYEW/FN0BX8QgXe0Aw/ypWZMWq9FJbSJQWXAP6I0DuKhPRL/tS4E4eIKYz18tSPlN18 98dMiEONw28hv256efuIgVsrpxLwMjDOYoevjR502icA6l/B5/ERKrO6JlT2zJYasJmR66PI ZpEL2A2PVKfOnWjOX9OYH46tO6sln/zaRVStRSYqbdfD237llMhgOW3YIGFEjCMbZh3gVvH+ 0Dew0fgCDoCM5+V9zeIy1v504cjmgu+Aur+DoaQ7/NvnRify3IeDDUQUl20p+T/jVSxM++zM GQR8ysq6LEsrQmlEYC7UBq/r3qJ+BUbXrK8DtEH1e1E8YKMiy7xO4TOZmUQOLTKaOdeqeQW6 2K0 IronPort-HdrOrdr: A9a23:QF4mJano4Ss5RjVmDrk7b5VfpGjpDfIi3DAbv31ZSRFFG/Fw9v re+8jzsCWftN9/YhAdcLy7V5VoIkmsl6Kdg7NhWYtKNTOO0AeVxedZnOjfKlXbcBEWndQy6U 4PSchD4Y3LYGSTz67BkWyFL+o= X-Talos-CUID: 9a23:mijpKm/axRWBGAkBWwGVv1M/Me0IV0Lv93HzJlWpCj90d7yKRnbFrQ== X-Talos-MUID: 9a23:zohsCgh/fmOMD1d8Ds9Pk8MpaeV3/vvzKlgxsowMkNGDdiZONjqkpWHi 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; 26 Apr 2023 12:20:01 -0400 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5ef5e31f3f5so47282106d6.3 for ; Wed, 26 Apr 2023 09:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526000; x=1685118000; 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=DIPG2iyayBlt4p6H01QYAbvbIBO5K/+RNbOuzH/t0Fs=; b=XbuXcj6P9eeh6mj+PCo2MViD46uk0CxUC2ZBJHdlnleJBjw8/L68YonOm1Mm9vmrSV KGtJK6rjp8b88dVGHjZZuVCkUxd2hJjMwHGiMzubpqeUq8dzJAt5dn/akqv1YhefxN44 k4iYCfki/eJPMZmwQdJLUlM/g6tBowvV2eMTb5gtAR9DqZf8JjnFZlgMhbMHDfx1PAp/ ZW9BWY9KdfsbPjvhs9T9LJpPuGq6Hki8lVXJdYo1cwDEIT3Jo/Zl//Pau/2LE4XxAMr7 OOihpT/9y5UIA8GexMTNS/O2ujhRpOugwPmSN4/asvC04kuAfwW/ttimV3j1sF+iktub ZfDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526000; x=1685118000; 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=DIPG2iyayBlt4p6H01QYAbvbIBO5K/+RNbOuzH/t0Fs=; b=CpxNv+8Ft7zlaSfxx28MUJh57M/d+M0o2coaAZ7rY7B7iEbogc/Gs2ZyXwI5qEDxe8 9HyyeSJvQwOKC49KusHzWNxwZEjpsWyLDblBYDrbTQfoYRNb10yg9plkFLFbrJ1Ibtc3 YivVwl1DwfHDyoJEX0zI1fxLX02Vgsyt+XcTXrR6D8IyC0IQTDGRfzpw1pg/cJ4+PdL/ 0kj93WEpVhSq3gdPbL3GL16X7aoZPSb3Lx6rgKDx0OzAYWVDZz+rTuqb3pLkX2phIOPC 2MLMbktlp761rdL3nENPGTjyHO5UTHzmTNynU3y1Ws4bU2bgFXRX2cew7e8zahTneopJ rM9Q== X-Gm-Message-State: AAQBX9eN7lWvTRpaiuN6f7IOeVqyr7rWPG5OiScv8v+UQScFqyCJXiR4 Dw0hJ2iD6R8ykn0zHc1bE9BSZeJmyDPo1fLlCYSuHUsUP5AB39Ke9AaXUkb6fIoNAI5lynfJYp8 uBtcnjvyeupat/TWymOPQHQwewVVu3FIk2dMPtldISqY= X-Received: by 2002:a05:6214:da1:b0:5ee:a282:d38e with SMTP id h1-20020a0562140da100b005eea282d38emr40169104qvh.10.1682526000661; Wed, 26 Apr 2023 09:20:00 -0700 (PDT) X-Google-Smtp-Source: AKy350ZfSboGfnlCQARBsmZy+n2/aCxVP4eWny8aIGwdSNNPuSvCfkoIx5GHCDJ7mR/YtCwF/U+hdg== X-Received: by 2002:a05:6214:da1:b0:5ee:a282:d38e with SMTP id h1-20020a0562140da100b005eea282d38emr40169054qvh.10.1682526000317; Wed, 26 Apr 2023 09:20:00 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id v2-20020a0ce1c2000000b005e95c46e42asm4963544qvl.74.2023.04.26.09.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:00 -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 v9 1/8] memory: prevent dma-reentracy issues Date: Wed, 26 Apr 2023 12:19:44 -0400 Message-Id: <20230426161951.2948996-2-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 | 14 ++++++++++++++ softmmu/trace-events | 1 + 4 files changed, 27 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..af9365bb81 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -542,6 +542,16 @@ 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) { + trace_memory_region_reentrant_io(get_cpu_index(), mr, addr, size); + 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 +566,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 +1183,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) { diff --git a/softmmu/trace-events b/softmmu/trace-events index 22606dc27b..62d04ea9a7 100644 --- a/softmmu/trace-events +++ b/softmmu/trace-events @@ -13,6 +13,7 @@ memory_region_ops_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, u memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, const char *name) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u name '%s'" memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" +memory_region_reentrant_io(int cpu_index, void *mr, uint64_t offset, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_sync_dirty(const char *mr, const char *listener, int global) "mr '%s' listener '%s' synced (global=%d)" From patchwork Wed Apr 26 16:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=GDaUfRlw; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q63yj4h1qz23s0 for ; Thu, 27 Apr 2023 02:21:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhst-0000lZ-BG; Wed, 26 Apr 2023 12:20:47 -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 1prhsr-0000lM-LP for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:46 -0400 Received: from esa9.hc2706-39.iphmx.com ([216.71.140.197]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prhsp-0005jY-1p for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:45 -0400 X-IronPort-RemoteIP: 209.85.160.69 X-IronPort-MID: 276516072 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:qTNit63eR23Y0EnnGvbD5W9zkn2cJEfYwER7XKvMYLTBsI5bp2MBz mcbUTuAOPyKNDejKthyPITloBwG78OGnYUyTgZkqSg9HnlHl5H5CIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv666yE6jfrSLlbFILasEjhrQgN5QzsWhxtmmuoo6qZlmtH8CA6W0 T/Ii5S31GSNhnglYwr414rZ8Ek05Kio5mtC1rADTasjUGH2xiF94K03ePnZw0vQGuF8AuO8T uDf+7C1lkuxE8AFU47Nfh7TKyXmc5aLVeS8oiM+t5uK23CukhcPPpMTb5LwX6v2ZwKhxLidw P0V3XC5pJxA0qfkwYzxWDEBe81y0DEvFBYq7hFTvOTKp3AqfUcAzN1fD1tpN4YJ6992AFBj3 6MnIWkzczSc0rfeLLKTEoGAh+wmJcjveYQW4zRuk2CfAvEhTpTOBa7N4Le03h9q3pEITauYP pRBL2Q+BPjDS0Qn1lM/AZYumuuyrnPiNTBUtTp5oIJtvDaOlVIpj+KF3Nz9VNW1Xc51t1+jr 2OY0EjLUi4Hb4CG1m/Qmp6rrqqV9c/hY6oLGbils/JnnlCX7moUDhIQSB28u/bRt6Klc9dWK khR/SN36KZspQqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxWjhsouJpADD+iPILeA== IronPort-HdrOrdr: A9a23:3xUEw6oGTluB/pLjnTkc2dkaV5qaeYIsimQD101hICG9Lfbo8P xGzc5rsSMc1gxhPU3I+erwQ5VoJkmsh6KdgLNhTotKOTOWwldAQ7sSkLcKqQeAJ8STzJ8g6U 5LSdkwNDSINykwsS+Y2njJLz9D+qj4zEnAv463pBcdND2Gc5sQlzuRYjzrdHGeLzM2dKbReq DsmfaujVKbCAMqh86Adzc4t/CpnbP2fGeMW3E77t0chTVmTwnD1Fc3KWn64v5PaUIG/V8PmV K15zAQy82YwoeGIjC17R6n03x28OGRg+eqX6S3+4IowmeFsHfkWG2pYdHy3gzc9omUmRoXrO U= X-Talos-CUID: 9a23:OjgR9Grc9YDY4c1Y9hMABqfmUfEmaCLXx2bBGk65OEtDF4KcEGGN3Lwxxg== X-Talos-MUID: 9a23:VayL2AZKhDsL7OBTmTbTnDpCHd5T6qXwJ2w/waob4JWdKnkl Received: from mail-oa1-f69.google.com ([209.85.160.69]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:26 -0400 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-18efc77f853so4039999fac.0 for ; Wed, 26 Apr 2023 09:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526025; x=1685118025; 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=GDaUfRlwrigB29cnZTwowZYKrhUvgoRjtB178BxImD3aUDIcYs3EuyO68Uq0y25upO k2li0UaEpaO6if7ZyKvUl7v2ZYhxRU/dZVuEOiSzjuIpA0AMixZV8SEdLWaBSmVcvDOp Xa0/alQeQvYaYe/OB/ATFWIfnSvMCZOMeH0/9MZwFWWmDlLas+7btm68PNVMkBonrrwL +/rmFg33VaNC+rcfZxj5SKkvz4nWL/aA5b5wEKXTg0E1qxTkS1dRAZGWP9DfLanmo+SP bm0ZyxgmFCkcBy0aH8/B+Qr3I8uxRSP0elIGMbsI60jPLUqjrXUXUTCVJPTB16/m9Xgk tHBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526025; x=1685118025; 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=gOS7zH1nRLJDC+YlsItLnTv3me78RIONSPl62oGA90U2Z3REY6mmACrw7noAvUlLm3 wut2dNaozKVihI+N6qp18P0thL762+h698USb6QNDwhkgEtt3KyOss3qN0OPaJYtEazA eUM5DRDj/HZFZkDUEiUhZi+qSKtDpCuIZFSGhQTc0BnoU7FkSH6pJ8BdDvRdchTux1q6 /wffM/fa/lXWa4Rf+MWT+R0imqKH2jIkLp6+RQe29DhFWimLGXVlb7zyjCRnkPvpgANx ve75CSaPc08B+ziuSzPFRs+u16oYPvmdrBizhxRHV7R0RPJJi53vH7U+pzjhjcWY6sqv H1/g== X-Gm-Message-State: AC+VfDw9VD/Uasxsn7cGTNNDlR1J1v/WdVPosurYcj0TFy/tTTKsZ3xb 1+dQWg1uuSuWF1rkKxMKwGbxpiUBiAWMb/aPk37KhmFoqDMzOwqi2X+ia96aa3D5WYUoIvTXdEB hcfUHMMSkaKraR8i02QsZk9NLzYUtvQDxnbszHH/9Clc= X-Received: by 2002:ac8:5a07:0:b0:3ef:5c5a:8932 with SMTP id n7-20020ac85a07000000b003ef5c5a8932mr5237324qta.18.1682526004396; Wed, 26 Apr 2023 09:20:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61Ms3bgDhhuMamyq9UBH85tt1gsvpdytLNXUUXNyUXZo3r6NfvfbwCAFHhAj16jFc3H4XiVw== X-Received: by 2002:ac8:5a07:0:b0:3ef:5c5a:8932 with SMTP id n7-20020ac85a07000000b003ef5c5a8932mr5237273qta.18.1682526004092; Wed, 26 Apr 2023 09:20:04 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id ge8-20020a05622a5c8800b003e3914c6839sm2662208qtb.43.2023.04.26.09.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:03 -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 v9 2/8] async: Add an optional reentrancy guard to the BH API Date: Wed, 26 Apr 2023 12:19:45 -0400 Message-Id: <20230426161951.2948996-3-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.197; envelope-from=alxndr@bu.edu; helo=esa9.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Wed Apr 26 16:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=OvNI2kO2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q63yj4wBgz23vJ for ; Thu, 27 Apr 2023 02:21:17 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhsy-0000ow-B8; Wed, 26 Apr 2023 12:20: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 1prhsu-0000lq-Ny for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:49 -0400 Received: from esa9.hc2706-39.iphmx.com ([216.71.140.197]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prhsf-0005eY-AR for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:48 -0400 X-IronPort-RemoteIP: 209.85.219.70 X-IronPort-MID: 276515920 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:avLob62kUv9I3C9QovbD5W9zkn2cJEfYwER7XKvMYLTBsI5bpzwFm DAYWGnSM6vcM2enL9EgPo7j9x4H75KBy4dmGwc4qSg9HnlHl5H5CIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv666yE6jfrSLlbFILasEjhrQgN5QzsWhxtmmuoo6qZlmtH8CA6W0 T/Ii5S31GSNhnglYwr414rZ8Ek05Kio5mtC1rADTasjUGH2xiF94K03ePnZw0vQGuF8AuO8T uDf+7C1lkuxE8AFU47Nfh7TKyXmc5aLVeS8oiM+t5uK23CukhcPPpMTb5LwX6v2ZwKhxLidw P0V3XC5pJxA0qfkwYzxWDEBe81y0DEvFBYq7hFTvOTKp3AqfUcAzN1tN1wnbYgmq91nBDlx5 e40EhMKKRG60rfeLLKTEoGAh+wmJcjveZoB4zRukmmfAvEhTpTOBa7N4Le03h9q3pEITauYP ZNIL2U3BPjDS0Qn1lM/AZYumuuyrnPiNTBUtTp5oIJtvDaOlVEgiuCF3Nz9JIeaeeN8zkukp kH8xl/zWR9Bb96m1m/Qmp6rrqqV9c/hY6oLGbils/JnnlCX7moUDhIQSB28u/bRt6Klc9dWK khR4zR36KZtrAqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxWTNsouJpADD+iPILeA== IronPort-HdrOrdr: A9a23:ozzFZqz5CQ/OLOuMTqGZKrPw+r1zdoMgy1knxilNoNJuA6ilfq eV7YgmPHrP4gr5N0tQ/+xoVJPwI080sKQFmrX5Xo3SITUOxlHYVb2KhLGKq1aQeBEWtNQtr5 uIG5IfNDSaNykcsS+V2njcL/8QhPOqyuSHv9v/8ltaZT1WSshbnnhE48WgfnGehjMqOXP0Lv ShD7J81kKdkL0sAaWGOkU= X-Talos-CUID: 9a23:pV3nLmO5dBu8X+5DWxJ65R4RJJEeYniF82fCD3WbDiFocejA X-Talos-MUID: 9a23:kmizWQxyVZn/LFxWMaacDv9E8rqaqPr1GHwruMULh8mnDxVLMWyT12+1e5Byfw== Received: from mail-qv1-f70.google.com ([209.85.219.70]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:09 -0400 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-5ef433ecde8so86191186d6.3 for ; Wed, 26 Apr 2023 09:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526008; x=1685118008; 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=OvNI2kO24YfAOwQg3Ye3rc/amiT/WWXi8kBtDJTBr07mZoy3jdhc/+j4zs8ka45B4h WNMI4QgIqBYJy1Bghu+hlDJ/6W3dPLLWo/CaCbH9GgeHdR2xT1SRlrOa2rehN2ajHC17 /S7vwfCczDEJ5TSwXfutVXBo656I1bsEnZQXvYiKXOKhX1Q0gMxlqqRoTLAvg/4GZIn9 Y5wIrjoJ01kFpljBZLo2Gved33nGPF+POs0VwaTRL+5wYhnu2P5Jk9Bu+mSx+9aXMEfk x58kXJw6l6VvQ4ck62wI8uOQuGgLAeYzmlt38a7og5hRwbilRdVNWFSoypI/PWJkl5YE mqbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526008; x=1685118008; 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=Ru+oKRq6odcnVIYIgsCEmyZTgUCjjT4HGZR6yGy3aU31YS9WkKxrIuiF5QSH7XM6gW VzW6YCNr0TMX4Pi6fe4mOjPSCR0iN3zPkJ6NaRd68qgPtsONyLLoIrWeFDzQxcgRoQ3Q i9wYG2qSOWxmgBBjGp7lypyGKjtRvOfP+2Yz6dBOtBMr+zZazPmNBKaDERZAEbkf6Xel C4ecgxU38jnWmYk+35Z0eiLAI27xpBI5qF/NAOfnd8oyeRxiZcblbrnvIzP4JZlk2Jof vzLNJ808eahYuE1wGa7lUNpECvwC0EyqTgQN6mEq5sSSti1cLifKFOIHsMv1ut9LexnX 88mg== X-Gm-Message-State: AAQBX9eZrvYmNqJSpK/Dg+5XkEa6T99bECVg7wlwRCD9kavpV/+6Jxjk JksFHUntGZrT0gVnecn6Wk5LAefYVTKFcc9TeAhPD9h+OnJ+cN3lmqE5MaL7Kb9bJI17NGW4n1y v+lDmb7M4XfY9cfkOQK3sHWjVfy457BqmFNWm6Yw35mQ= X-Received: by 2002:a05:6214:5184:b0:5ef:83cf:91cc with SMTP id kl4-20020a056214518400b005ef83cf91ccmr31410659qvb.44.1682526007905; Wed, 26 Apr 2023 09:20:07 -0700 (PDT) X-Google-Smtp-Source: AKy350ZZvF4BN23MesPeHsvQVLijSVmfauRkvdR2QLnuVM3FVNsqzfLeKKAzxoKfdZ4HItwSddaqNA== X-Received: by 2002:a05:6214:5184:b0:5ef:83cf:91cc with SMTP id kl4-20020a056214518400b005ef83cf91ccmr31410620qvb.44.1682526007697; Wed, 26 Apr 2023 09:20:07 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id k15-20020a0cf58f000000b005dd8b934595sm4984993qvm.45.2023.04.26.09.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:07 -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 v9 3/8] checkpatch: add qemu_bh_new/aio_bh_new checks Date: Wed, 26 Apr 2023 12:19:46 -0400 Message-Id: <20230426161951.2948996-4-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.197; envelope-from=alxndr@bu.edu; helo=esa9.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Wed Apr 26 16:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=iE1TTT1F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q64175Wj0z23s0 for ; Thu, 27 Apr 2023 02:23:22 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhvI-0005Er-Ju; Wed, 26 Apr 2023 12:23:16 -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 1prhvH-0005CI-5k for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:23:15 -0400 Received: from esa12.hc2706-39.iphmx.com ([216.71.137.82]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prhvE-0006Am-15 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:23:14 -0400 X-IronPort-RemoteIP: 209.85.210.198 X-IronPort-MID: 274996511 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:e35iGqKqXonhLBIYFE+RaZclxSXFcZb7ZxGr2PjKsXjdYENSgjYDn zMXW22FPvuOYWXxeN8gbYTn9U0BsZLUx9EyGVRorCE8RH908vbIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkjk7xdOOn9T8kjvvgqoPUUIbsIjp2SRJvVBAvgBdin/9RqoNziJ2yDhjlV ena+qUzA3f4nW8lWo4ow/jb8kg34K6s4GlwUmEWPpingnePzxH5M7pCfcldH1OgKqFIE+izQ fr0zb3R1gs1KD90V7tJOp6iGqE7aue60Tqm0xK6aID76vR2nRHe545gXBYqhea7vB3S9zx54 I0lWZVd0m7FNIWV8AgWe0Aw/y2TocSqUVIISJSymZX78qHIT5fj6/FPMWUaYoA0wc9IED1ex MZCLyETUh/W0opawJrjIgVtrsEqLc2uJI1G/385nGGfAvEhTpTOBa7N4Le03h9q3pEITauYP ZNBL2M+PHwsYDUWUrsTIJs6jOGknFH1bntVpE/9Sa8fuTePnV0vjeG0WDbTUtzbadsS2XfFn CHX4DzDXRQQPda0xAPQpxpAgceKx0sXQrk6DbC967tmjUOewkQVDxsZU0b9puO24nNSQPpaI k0QvzIg9O08rR37CNb6WBK8rTiPuRt0t8dsLtDWITqlksL8izt1zEBaE2YphAAO3CPueQEX6 w== IronPort-HdrOrdr: A9a23:C74cY62Au+lIinh7MqZNJwqjBGQkLtp133Aq2lEZdPWaSL39qy nIpoVm6faQslwssR4b6La90cW7MBHhHNtOkPIs1NSZLXTbURWTXfhfBOLZqlWKak7DH6xmpN 1dmsBFaOEYZmIK6voSjjPIduoI8Z2s3Jrtq93j70pAeylXVoAI1XYHNu9ZKCFLrct9aKbR2K Dz2iM+nUvZRZ3fVKvbOkU4 X-Talos-CUID: 9a23:aCufcWDcQNfaBTr6Ey1GyWo4Rc0JSVTi3SvAEnXiDnd3dLLAHA== X-Talos-MUID: 9a23:zMInaA4a/te1Vh0V77wXs0QpxoxosoiwTwc8zK9FqtbcD3N1MT6XpzmOF9o= Received: from mail-pf1-f198.google.com ([209.85.210.198]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:34 -0400 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-63b64ada305so8531556b3a.0 for ; Wed, 26 Apr 2023 09:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526033; x=1685118033; 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=iE1TTT1FHxaEvPl5pFP7UtQGtLVlQV2LnCGm1vV614edkOz53U26xzHhCl18WuFMvN 18w7iUk1NRQMjqz9lsnLwQltGYQE2F77sg4CvTfpukR5v7WPZtkxTxsPFzPJnAHlHUQe rra6eb4jjOJIAHfS85xwkE9NaeQyZ4uHTUXxsjc6nwSBhkbCCu7nvTWuSusi2rQQ0h+d 1PdWPIChBeCxO+DQmkXDjvQMLUWMDr932zQox4wVieCD5gohG/xE0j4Mf4gQAIEaNKTt bFPKoz07FD8S71o+9HcM5W6Zz7oLhT406LE4R8bZamrwm6L73AO3dU10sF4m/fxMbtaY DVzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526033; x=1685118033; 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=QYtfieTsGp5V2A2W845NksW6pohSlbZVnX1l/D4utf6byCHr4v8muRRvoYz5cdXAG8 4Sq6E8oqRd29AXgzuyVZleS/BRprFe8yRr/IuVKOzLtCUoa2ylk8ygvGjLbAdoUfww1q MKpV9X+28tvSmtrPvD7cYPj9eIu1etI7oBR8Ra30yQ+D3jo0Rfw3404kM1TeT3a/4iac 1PBm+Fz6872XEPuhxEZ971Ft9saPUtOW0MfEH+Xb5mEunhf9jyoZ2QVtPbwL4NRLknTx tvoTIG9ua+7qsU08/cU5/LmAHmW5678GfxNIO3XnYeXmqGYj7Zip/t8EdJl4Mvgx66pQ uVKA== X-Gm-Message-State: AAQBX9c5tnxMA2vV5mRW8plPjVmOU7Di1GKgfI9xISL+u4X4tI4hz20D IiO60nVF2+iHjSu4Y7EyIEDe+5j/bLXIdirGxX7yf4vHhN0XeuGEjoChcLPxqvyjZgtTQgzT4qz VvrtE0HGkRUVF7QOOdm1K3wNMTwOSn5/usM/6kYHaokc= X-Received: by 2002:a05:6214:21e2:b0:5ef:9b22:dc7e with SMTP id p2-20020a05621421e200b005ef9b22dc7emr32955977qvj.8.1682526012306; Wed, 26 Apr 2023 09:20:12 -0700 (PDT) X-Google-Smtp-Source: AKy350aIyo/hhWU+vCFPCfUcLp7e6OYg/xUEp5KMz7jZpd1jbs6u7UCc+TlkRLn285gB+3L9GIoDMw== X-Received: by 2002:a05:6214:21e2:b0:5ef:9b22:dc7e with SMTP id p2-20020a05621421e200b005ef9b22dc7emr32955882qvj.8.1682526011717; Wed, 26 Apr 2023 09:20:11 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id b19-20020a0cb3d3000000b005e8d802ce32sm4899810qvf.143.2023.04.26.09.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:11 -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:Old World (g3beige)) Subject: [PATCH v9 4/8] hw: replace most qemu_bh_new calls with qemu_bh_new_guarded Date: Wed, 26 Apr 2023 12:19:47 -0400 Message-Id: <20230426161951.2948996-5-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.137.82; envelope-from=alxndr@bu.edu; helo=esa12.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Wed Apr 26 16:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=QoIDC32m; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q63zl3P2Hz23s0 for ; Thu, 27 Apr 2023 02:22:11 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhtS-0001Ws-1t; Wed, 26 Apr 2023 12:21:22 -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 1prhtP-0001T9-Pe for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:21:19 -0400 Received: from esa14.hc2706-39.iphmx.com ([216.71.140.199]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prhtN-0005wn-JQ for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:21:19 -0400 X-IronPort-RemoteIP: 209.85.219.197 X-IronPort-MID: 298807095 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:pscfZ6B/yZWXRBVW/5Hhw5YqxClBgxIJ4kV8jS/XYbTApGsq0zQOz DcXWmiCPfmKYmqgf90iOoWw9hsC7JaEx95gTANkpHpgcSl2pJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdleF+lH2dOCn9SImvU2xbuKUIPbePSxsThNTRi4kiBZy88Y0mYctitWia++3k YqaT/b3ZRn0ilaYDkpOs/jY8E814qyo0N8llgdWic5j7Qe2e0Y9Ucp3yZGZdxPQXoRSF+imc OfPpJnRErTxpkpF5nuNy94XQ2VTKlLgFVHmZkl+AsBOtiN/Shkaic7XAha9hXB/0F1ll/gpo DlEWAfZpQ0BZ8Ugk8xEO/VU/r0X0QSrN9YrLFDm2fF/wXEqfFPd3uw/PmQVZbQY0cFUD3MQt tolLDk0O0Xra+KemNpXS8Fpj8UnadjhZcYR4yA/iz7eCvkiTNbIRKCiCd1whm9hwJATW6yHN oxAOGUHgBfoOnWjPn8eDII4kP2AjGS5fjFFwL6QjfBmsziLk1QgjdABNvLOPeHQdNwEjH2Ro 3ro4FiiDi0FF+KmnG/tHnWEw7WncTnAcJsfEaD9+vN0jVm7wGsVBxsLE1yhrpGEZlWWXtteL wkF8HNro/FjqwqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxXDRcJtKdQLTKbPMLeAE= IronPort-HdrOrdr: A9a23:FLLm8q5lfUscqeI6XAPXwbaCI+orL9Y04lQ7vn2ZFiYlEfBwxv rPoB1E737JYW4qKQwdcKO7SdW9qBLnhMxICOwqTNWftWbdyRCVxb9ZnN7fKlHbakrDHgA079 Y/T0BRYOeAXWSSp/yKvDVRKr4bsYi6GErBv5aM854Vd3A0V0gC1XY0Nu/4KDwNeOAcP+tlKH P03KMuzFDMFRt4H6HLYkXtcNKz8+Ej/6iWOSLuciRXkDVm+gnYkYISfSLouCv2egk/jovLMA D+4lfEz5Tml8v+5g7X1mfV4ZgTssDm0MF/CMuFjdVQAinwiy6zDb4RFYGqjXQQmqWC+VwqmN 7Dr1MLJMJo8U7ceWmzvF/ExxTg6jAz8HXvoGXowEcL4PaJBA7SOfAxx76xQSGprnbIe+sMlJ 6j6ljp9Ka/yymw2xgVqeK4ES2C3XDE3kbK2dRj8UC23uMlGeVsRMokjRpo+d47bVPHwZFiH+ 90AM7G4vFKNVuccnDCp2FqhMehR3IpA369MwM/U2Ouok1rdV1CvgIlLfYk7z893YN4T4MB6/ XPM6xumr0LRsgKbbhlDONERcesEGTCTR/FLWrXeD3cZew6EmOIr4Sy7KQ+5emsdpBNxJwumI 7ZWFcdsWIpYUrhBcCHwZUO+BHQR2e2Wyjr16hlltJEk6y5QKCuPTyISVgoncflq/IDAtfDU/ L2I55SC++LFxqZJW4EtDeOL6W66UNuJ/H9luxLKW5m+Pi7WrECntarA8ruGA== X-Talos-CUID: 9a23:MMPUtG8tF2YmyrxlBLCVv38JA5EXV16F9Xf7BGy2GzgqboCRQGbFrQ== X-Talos-MUID: 9a23:+Ya9PQToaRGDXY9cRXT3www4Bd458Z+nDVgjjqldt/WbFhJJbmI= Received: from mail-yb1-f197.google.com ([209.85.219.197]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:37 -0400 Received: by mail-yb1-f197.google.com with SMTP id 3f1490d57ef6-b9a2b777ff2so2719266276.3 for ; Wed, 26 Apr 2023 09:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526036; x=1685118036; 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=QoIDC32migVEzUPBoeoodOuS1v0jNqOULXEcZafDuMTZhw/vIeBLq5i37qCUuxhAH4 uWskatSsk5al1HKfr/SXmHqT9O/bALY8NgQEb4T390sx9PSTz/uk4W2y59UtJtxvXwXi dOwaoKuYLyIwgT4mp92iqXuH/BZviz0YohS8Vz2S3fCyB/oy9eQdIwf4U7Z58B41rGPi eO9bcKpWICvcrfD5Da8M4l9eYK5wsuLwuNq78iBi+ZenHqoleEebAoi9b4Pxv8c5wbki o7CH5poCxxmHEuj1tS23ntch9rZVt7IlIrWH0ox9pjOUhGvFEtyfHBMJNfgQXvSGesG6 nUuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526036; x=1685118036; 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=W8tf3FW5gxaHcNfVSAkV+y/A86zZrTw/cBc0Y7FJnKJiXmOOncFbjZLttuR+EOMj2/ SS5ycmHISQA3ufEH/e4+BuK73Sd0lQ+7kVNmEq1pBWKwxAioPLxjowFla5FXDluPSWsh LtCqZiGweWkz1WHnh4IKJFs3Aj8duq6BEsbLMKjqxR8uqcSn4L/aiUUbyoni8/6rWft1 fOyM679Uu1O5nPsDxhBU5mEWInuVl5QVK+bZmCLZaM7niLmK4zFXQ54sr0rvYKlDLeDq ku+dElXnYpQrXblb7Sa3rKUDg3SzJqG2stM1WptwrSaxn5g+HqflJNH0dQdXRDgzGBQ+ H6Jg== X-Gm-Message-State: AAQBX9fJBJ4g6to+lvbumHTb6gsKb1OpDSq1u05yRdwOCD13ns2+Cs0B bFSmnLnMqUhuuZiy/2iiP3A0Cyes/RSy4yjvBnoS0RJBPPeTHXJr/5U00sGVR7fYJ2JBBVb9PnP LhJBwcC/G4RkYxrMm9pody4Zyov7BV0pRPVJowilRxcA= X-Received: by 2002:a05:6214:5097:b0:5df:4d41:954d with SMTP id kk23-20020a056214509700b005df4d41954dmr34483371qvb.3.1682526015565; Wed, 26 Apr 2023 09:20:15 -0700 (PDT) X-Google-Smtp-Source: AKy350YCPqhh2ueUNhIuDIWpWIA4JFBO5U0tZnkeqz4bLtjv4MFDCuE3rLbrYFCY7PqxcXUIziSuHQ== X-Received: by 2002:a05:6214:5097:b0:5df:4d41:954d with SMTP id kk23-20020a056214509700b005df4d41954dmr34483328qvb.3.1682526015314; Wed, 26 Apr 2023 09:20:15 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id q17-20020a0ce211000000b005f5b71f75f3sm4950683qvl.125.2023.04.26.09.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:14 -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 v9 5/8] lsi53c895a: disable reentrancy detection for script RAM Date: Wed, 26 Apr 2023 12:19:48 -0400 Message-Id: <20230426161951.2948996-6-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.140.199; envelope-from=alxndr@bu.edu; helo=esa14.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Wed Apr 26 16:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=HOTBcmjz; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q640z6NN1z23s0 for ; Thu, 27 Apr 2023 02:23:15 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhup-0004wm-8N; Wed, 26 Apr 2023 12:22:47 -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 1prhun-0004vV-L4 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:22:45 -0400 Received: from esa5.hc2706-39.iphmx.com ([216.71.137.63]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prhum-00068J-21 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:22:45 -0400 X-IronPort-RemoteIP: 209.85.219.69 X-IronPort-MID: 287060773 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:Qswvqa3BTl9bOU3hCvbD5Wxzkn2cJEfYwER7XKvMYLTBsI5bp2cHz 2odXTiOOv3bNDDycopxaI3j800F68DUzdU2SwM/qSg9HnlHl5H5CIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv666yE6jfrSLlbFILasEjhrQgN5QzsWhxtmmuoo6qZlmtH8CA6W0 T/Ii5S31GSNhnglYwr414rZ8Ek05Kio5mtC1rADTasjUGH2xiF94K03ePnZw0vQGuF8AuO8T uDf+7C1lkuxE8AFU47Nfh7TKyXmc5aLVeS8oiM+t5uK23CukhcPPpMTb5LwX6v2ZwKhxLidw P0V3XC5pJxA0qfkwYzxWDEBe81y0DEvFBYq7hFTvOTKp3AqfUcAzN1VBmI0E58xvdpMOl1q8 qVIEh1dREqq0rfeLLKTEoGAh+wmJcjveZoB4zRuk2CfAvEhTpTOBa7N4Le03h9q3pEITauYP ZNIL2Q+BPjDS0Qn1lM/AZYumuuyrnPiNTBUtTp5oIJtszeLklQuj+OF3Nz9WP2Xfeh7uGKh+ WOdoHXCAUgQKJ/Axm/Qmp6rrqqV9c/hY6oLGbils/JnnlCX7moUDhIQSB28u/bRt6Klc9dWK khR4zR36KZspQqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxWjNdJtKdQLTKbPMLeAE= IronPort-HdrOrdr: A9a23:JoLkvasFrWzpFTv3f852q+Ti7skDT9V00zEX/kB9WHVpm62j+f xG+c5w6faaslkssQ4b6La90cW7MBHhHP1OgLX5X43PYOCOggLBEGgF1+vfKlbbakjDH4BmuJ uJjMBFeb7N5FJB/KHHCVmDeOrJabG8gcSVuds= X-Talos-CUID: 9a23:qiJubmOGLr6/i+5DYyNE9mAGM4cZSUbh6HCJc3WVWUwzYejA X-Talos-MUID: 9a23:5vd7nwp9/FE5IOYuLqUezxNDKf9FzYKKMR8MysoXgMrdPzAzZDjI2Q== Received: from mail-qv1-f69.google.com ([209.85.219.69]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:20 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef4b68f47bso45312456d6.2 for ; Wed, 26 Apr 2023 09:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526019; x=1685118019; 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=HOTBcmjzK+VrSqZG+hRfhMXWw5DnTHU8N63AWA5iXVJqZGte35yFYlcUvc++1cOMei NzudhD/vOPObQp42GDavrwghDDg8j75lpv1Oregf7XZVStL6sVMHG+Q2R0dSURonvXxu /P856opItzGwjYbcLMNbk4YSOtxh3dvixnxa04XVY795+6ChUeECk8g+sFdLiHYJPW65 7WLof1T5equXfYCH1cbYAczD5mO7qcl4lTN6YptepTgzzgAkWi4mdlY+q4RlEVQC51Mj WDJWKwWX7PzOhX3mUKAPUEkn54Ayc9nRPNzMi/2UfZTIoiUJiTgQLHiJpjsdgGevjWmB +a7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526019; x=1685118019; 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=FzD3Bhyj/5eq/X8GEcN5eo0RbcxaWQuQZNo/V/OFfEX7JpjQCvSS3lpEzW7Lc0yC+G T+4MwXQ8Y668JxJrliaJROdt4660RudNT1+LmPswbobVHP8SMV+xBYerwOyRCAt7CwLg TayadTdoLXKhM50vjXKb/LOFixiQp+Yr5yc4YNOSTGVHwRNq5Fdu4uUO755taYl3RXUF vzqC+IWypE8nghS5z3boQS9TYNjGNVcuPCyTuz6iqrsOnHykjhkXVSS0YDo2yZ9jxjyM G5jDJ8hrWzYZaZ3fVENtt+vG/YLG8mgQRl9Eikh4U7Ds9WCq5YRtbF5umQDG95ozQTQw 10Jw== X-Gm-Message-State: AAQBX9eLwbCwxsD2DD7bfeyxhp5qVN7O5F497P76wQqXnv+jNfQ4dFag vA5lrrfWgs/YDKcchvaSTahpJ9LorAsaUEN/qSf5ll9JlJ4Y4oKgwxTLxl0DOqb6cEOUeQmVbBI hRWxuIQeA5Wsk+33mcN/P5P/yzpIHbNa3rIjsbGTd/64= X-Received: by 2002:a05:6214:1c4f:b0:5ef:5144:9d24 with SMTP id if15-20020a0562141c4f00b005ef51449d24mr38061703qvb.21.1682526019488; Wed, 26 Apr 2023 09:20:19 -0700 (PDT) X-Google-Smtp-Source: AKy350bp+GsjrdVdootw/GoXQWNlgEnT+dB9PI9t6pL2vHlJD3PuCKJkKZtUMUHgY78QX3EQ0oJ62g== X-Received: by 2002:a05:6214:1c4f:b0:5ef:5144:9d24 with SMTP id if15-20020a0562141c4f00b005ef51449d24mr38061600qvb.21.1682526018604; Wed, 26 Apr 2023 09:20:18 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id r8-20020a0ccc08000000b005f160622f3esm4953167qvk.85.2023.04.26.09.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:18 -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 v9 6/8] bcm2835_property: disable reentrancy detection for iomem Date: Wed, 26 Apr 2023 12:19:49 -0400 Message-Id: <20230426161951.2948996-7-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-1-alxndr@bu.edu> MIME-Version: 1.0 X-CES-GSUITE_AUTH: bf3aNvsZpxl8 Received-SPF: pass client-ip=216.71.137.63; envelope-from=alxndr@bu.edu; helo=esa5.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Wed Apr 26 16:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=FEYlrYCH; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q64423g0hz23vF for ; Thu, 27 Apr 2023 02:25:54 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prhxT-00073Q-LC; Wed, 26 Apr 2023 12:25:31 -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 1prhxQ-00072r-2p for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:25:30 -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 1prhxO-0006iv-2d for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:25:27 -0400 X-IronPort-RemoteIP: 209.85.222.200 X-IronPort-MID: 276150411 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:3OVDwqI5T4iG2NnFFE+RapclxSXFcZb7ZxGr2PjKsXjdYENShGdWz TEaXjjQbKnZM2r2eNAlaNiyoUgPvZ7UyN8yS1dorCE8RH908vbIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkjk7xdOOn9T8kjvvgqoPUUIbsIjp2SRJvVBAvgBdin/9RqoNziJ2yDhjlV ena+qUzA3f4nW8lWo4ow/jb8kg34K6s4GlwUmEWPpingnePzxH5M7pCfcldH1OgKqFIE+izQ fr0zb3R1gs1KD90V7tJOp6iGqE7aue60Tqm0xK6aID76vR2nRHe545gXBYqhea7vB3S9zx54 I0lWZVd0m7FNIWV8AgWe0Aw/y2TocSqUVIISJSymZX78qHIT5fj669rAEIJIIIywPQ0EDFs1 NMZdBk1bx/W0opawJrjIgVtrsEqLc2uJYBG/386lWmfAvEhTpTOBa7N4Le03h9q3pEITauYP ZBDL2A3NHwsYDUWUrsTIJs6jOGknFH1bntVpE/9Sa8fuTeNlVEpjOG0WDbTUo3WbMxOxXipn z/p3kXSEihKb/qayhPQpxpAgceKx0sXQrk6DbC967tmjUOewkQVDxsZU0b9puO24nNSQPpaI k0QvzMt9O08rhTzCNb6WBK8rTiPuRt0t8dsLtDWITqlksL8izt1zEBdEmEZADD6nKfanQAX6 2I= IronPort-HdrOrdr: A9a23:qmTFV6ik1tiNBjnciSCKlXFfUHBQXgwji2hC6mlwRA09TyVXrb HLoB19726JtN91YhsdcL+7Sc+9qB/nhPxICMwqTMyftWrdyRaVxf9ZnPLfKlTbckWUh41gPO VbAtJD4bXLbWSS5vyKhzVQfexQpeWvweSDqd2b4U1QbTxHXYld0iYRMHflLqS0fmV77FgCea Z0KvAom9PZQwVuUi1zPBZlY9T+ X-Talos-CUID: 9a23:WGO+e2lXUwx09LGKheM9eOFxbxvXOSfYwHTvPkCSM3QqWe23aHCRpIpcksU7zg== X-Talos-MUID: 9a23:FlPTAw9RksNWxecreJB2R8aQf5Y0yq21U348qMgpmuivJRUgYBGYjx3iFw== Received: from mail-qk1-f200.google.com ([209.85.222.200]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:24 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74d62b70922so1142145485a.3 for ; Wed, 26 Apr 2023 09:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526023; x=1685118023; 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=y8lqfGW40ktWobrkJtbGNnWDtsD/7tWAErgFuibUF9w=; b=FEYlrYCHHuX4QmzFaQ5KfpQhp00jrDbB9ZRDOMynR4KFyHWbhgl6Nork4IyBDFGuKn v5DrH3r3yVUuFuABYUNFh9xy1Q41lrGPJXz0QIIP5HCuH+0xE1BNSkCJK1wqtOAUW6nW rB6s1QsKlZcMiDJBbf0xawxp4anmNIfdit+8kSWpnNJ+rB6c7rM6a8Megz06kJ6/8XY/ VAJB/+M38DwmBWuIU3fr7HEzasGtpl5/YnINdmoHUwybZqnbbGmeEnTA0Y6adtSIMO9n xQ3sXtF+Vl77JNp81kpM9uJgO3FBgIal6ak+SecSlICrFQf0FhskjBa484ouYB9MZiTn cSCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526023; x=1685118023; 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=y8lqfGW40ktWobrkJtbGNnWDtsD/7tWAErgFuibUF9w=; b=N3U1Eyhe1Kh/9TyHSJLZgzo/G4Z/fh+vGpsBTzD/PjmqdAzk4OmMRD1pTcFP3eaEDS Oh1BmKtRxJSJ3/TkD7nW0qM6/3RCPsy/TnpGSKQHqs4Ris9hZTAIVWn4CgL0cZ6xZsoc ESUB9qt8+wtwMl0WqIfpRkjYpl4jT2XerUIF0vp8whaC+H1+O831naecK/G4bHnyOfMj PLe5g9TSH+45gT2ZQRSubt74aL2ervUunpI1bBeCghi+X4Mz5uilQKNMn71pOpHPZJZY K3FWsteeSrUo+67tVOYnXbO6kMoY+bGrGtl0ct3M+dbQAyn2zc2aJtSc99E6cgFKyP0W ckVA== X-Gm-Message-State: AAQBX9d3ABVnql4VY4tNee62ketMfzcbHn5o9nG+Ny/im9oTcXnL/Yo1 VpATwePI/UIWdSOOImsfd9IZNHYAPThZ3uE5V1hwDPlRIH9q0d6RyBwrDgHLB4CJT46NF+H4uV7 YnqU0lb7qgCqPyVRBlAuGYrz4HQ9Zp0ctoACt5wyEpwM= X-Received: by 2002:a05:6214:d67:b0:5ef:46a9:15d2 with SMTP id 7-20020a0562140d6700b005ef46a915d2mr40741316qvs.7.1682526022963; Wed, 26 Apr 2023 09:20:22 -0700 (PDT) X-Google-Smtp-Source: AKy350aDDhrY6YFKE9X7SgJ6MzvzBVadcWbwKdF+LFCJ3AQz2pkJzC5OKajgqomyhuFMm3gRhZyNpg== X-Received: by 2002:a05:6214:d67:b0:5ef:46a9:15d2 with SMTP id 7-20020a0562140d6700b005ef46a915d2mr40741269qvs.7.1682526022721; Wed, 26 Apr 2023 09:20:22 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id z18-20020a0ca952000000b005dd8b9345d3sm4939392qva.107.2023.04.26.09.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:22 -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 , qemu-block@nongnu.org (open list:Block I/O path) Subject: [PATCH v9 7/8] memory: abort on re-entrancy in debug builds Date: Wed, 26 Apr 2023 12:19:50 -0400 Message-Id: <20230426161951.2948996-8-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is useful for using unit-tests/fuzzing to detect bugs introduced by the re-entrancy guard mechanism into devices that are intentionally re-entrant. Signed-off-by: Alexander Bulekov Reviewed-by: Thomas Huth --- softmmu/memory.c | 3 +++ util/async.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/softmmu/memory.c b/softmmu/memory.c index af9365bb81..d038633a6c 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -547,6 +547,9 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, !mr->ram_device && !mr->ram && !mr->rom_device && !mr->readonly) { if (mr->dev->mem_reentrancy_guard.engaged_in_io) { trace_memory_region_reentrant_io(get_cpu_index(), mr, addr, size); +#ifdef DEBUG + abort(); +#endif return MEMTX_ACCESS_ERROR; } mr->dev->mem_reentrancy_guard.engaged_in_io = true; diff --git a/util/async.c b/util/async.c index a9b528c370..2dc9389e0d 100644 --- a/util/async.c +++ b/util/async.c @@ -160,6 +160,9 @@ void aio_bh_call(QEMUBH *bh) last_engaged_in_io = bh->reentrancy_guard->engaged_in_io; if (bh->reentrancy_guard->engaged_in_io) { trace_reentrant_aio(bh->ctx, bh->name); +#ifdef DEBUG + abort(); +#endif } bh->reentrancy_guard->engaged_in_io = true; } From patchwork Wed Apr 26 16:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1774177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bu.edu header.i=@bu.edu header.a=rsa-sha256 header.s=s1gsbu header.b=GPwkKqfM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q63z96Dp5z23s0 for ; Thu, 27 Apr 2023 02:21:41 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prht5-0000qw-Bp; Wed, 26 Apr 2023 12:21:00 -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 1prht1-0000pu-3i for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:55 -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 1prhsy-0005pS-Jn for qemu-devel@nongnu.org; Wed, 26 Apr 2023 12:20:54 -0400 X-IronPort-RemoteIP: 209.85.222.197 X-IronPort-MID: 274887218 X-IronPort-Reputation: None X-IronPort-Listener: OutgoingMail X-IronPort-SenderGroup: RELAY_GSUITE X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:s32PR6BEe7p8rBVW/5Dhw5YqxClBgxIJ4kV8jS/XYbTApDh33zwDx mUeDDuFPv6KNGKkf9wiOom09EgH6J7Rn4BkTANkpHpgcSl2pJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdleF+lH2dOCn9SImvU2xbuKUIPbePSxsThNTRi4kiBZy88Y0mYctitWia++3k YqaT/b3ZRn0ilaYDkpOs/jY8E814qyo0N8llgdWic5j7Qe2e0Y9Ucp3yZGZdxPQXoRSF+imc OfPpJnRErTxpkpF5nuNy94XQ2VTKlLgFVHmZkl+AsBOtiN/Shkaic7XAha9hXB/0F1ll/gpo DlEWAfZpQ0BZ8Ugk8xEO/VU/r0X0QSrN9YrLFDm2fF/wXEqfFPj39VKFWcYF7YF2c9QP3weq sEWAw4kO0Xra+KemNpXS8Fpj8UnadDoZcYR4yA/iz7eCvkiTNbIRKCiCd1whm9hwJATW6yEP YxAOGUHgBfoOnWjPn8eDII4kP2AjGS5fjFFwL6QjfBovziDk1YogNABNvLSQp+YV+8IgH2Gt 1vE0lTeKDo2M/m2nG/tHnWEw7WncTnAcJsfEaD9+vN0jVm7wGsVBxsLE1yhrpGEZlWWXtteL wkN+XNro/FjqwqkSd7yWxD+q3mB1vIBZ+dt/yQBwFnl4sLpD8yxVjhsouJpADD+iPILeA== IronPort-HdrOrdr: A9a23:VfV79qOYir+728BcTv+jsMiBIKoaSvp037BL7TEVdfUxSKalfq +V8sjzpSWYtN9vYgBZpTntAsm9qArnhOdICOoqTNWftWvd11dARbsKheCP/9SKIUzDH4BmpM RdmxYSMqyVMbDH4PyKhjVRrLsbsb66zJw= X-Talos-CUID: 9a23:felHj2DPrRD65Bj6EyZ71GoNPO4PSWD+5VDuPh/nNGhCdpTAHA== X-Talos-MUID: 9a23:FdQ9YgRtX0mrjolKRXTrvHJwJu01/Z+wGXkPvKUhkeKoMglZbmI= Received: from mail-qk1-f197.google.com ([209.85.222.197]) by ob1.hc2706-39.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Apr 2023 12:20:28 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74dfe945c74so480491985a.3 for ; Wed, 26 Apr 2023 09:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=s1gsbu; t=1682526026; x=1685118026; 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=GPwkKqfMeRvTFAZrgPKv8bMlXpyYlBayJKhJzqHG5BIK6OrTDro8JzVteKvvXlbHlt EB1n295qx5imnztk8ou4Fs8FjAciy1VcAZ0QKbqM9ylsYRwHRoTEA/LrN4gKPtbWJzyS /AAyO8lrDZXNWjv7e5HfeEHZK+fAGyxkYLRi1z+CX1nSRs3mxHrce6l6ojymGhFJbJE5 m+xi9uE85yrD8cOvUGr4Rl1ZY2KwfLFIqzUM5Y4moyGWbwqU/L4CZXXOnxd019jCQUpJ Xq1YccGNS8kFpEWQEfu3fvzbX/FdpGPqsGl2XcGCl25+Z9EOtAdUWUuXR53XumLyaLUa Hi6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682526026; x=1685118026; 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=fVyZSzRvkZAw5RXr3e+udrMgglTgxZMdhtQT1L5mLz37Sn+IO5M42rz9sP7i/wy8qn euGCYjTlqp/xSqGrZeG+N2UZosUGJ4DfS/Gw5A4ehwVdXEmmY35UmCmkhcyNxtxtdEIl Ri1/tXjC+92lhOU31/58pv3eTOyPfqjcn5xxTGgvMqssGYDNJL9j4jKJymdstpv8yL8+ TuhzNoOpi4FjL8gDk06n1YPCTxTC/V2l50bvd/BkG/iLGUA+KE1tmu4zwyHwQMkJgTz5 qBeDKr/Krrs/FW0mmT1jVNgG+GdiEVgmQiFo9qY7nvHrzz8QokoSM3fd33L9Pn9hGw/r ZItQ== X-Gm-Message-State: AAQBX9dARgfI99DZlmTQgBkNdqTECQUlwa6ibAVMspI564CSKNzyNq6t gZqriAOt1wNsVb2W3K0NIkwdnHITfbjccIZQ6qaIqKRlEaBPA3jQF+KGB78bWi442CT9ShKWhCs gEim1IWy1168y9SI3KoaENgqBKfjBx6g7FYbFIpGW62M= X-Received: by 2002:a05:622a:170b:b0:3ef:2fbd:90ba with SMTP id h11-20020a05622a170b00b003ef2fbd90bamr36987139qtk.43.1682526026314; Wed, 26 Apr 2023 09:20:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZQ8VKoo+uzlCju2hLXsNgUukt/YuhPXMH+1U2lg+TgXrBGRCGZoz4tHhYIZMqzVz3YbCwMlg== X-Received: by 2002:a05:622a:170b:b0:3ef:2fbd:90ba with SMTP id h11-20020a05622a170b00b003ef2fbd90bamr36987110qtk.43.1682526026089; Wed, 26 Apr 2023 09:20:26 -0700 (PDT) Received: from mozz.bu.edu (mozz.bu.edu. [128.197.127.33]) by smtp.gmail.com with ESMTPSA id l13-20020a05622a050d00b003ef38277445sm5432332qtx.16.2023.04.26.09.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 09:20:25 -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 v9 8/8] raven: disable reentrancy detection for iomem Date: Wed, 26 Apr 2023 12:19:51 -0400 Message-Id: <20230426161951.2948996-9-alxndr@bu.edu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230426161951.2948996-1-alxndr@bu.edu> References: <20230426161951.2948996-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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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: Thomas Huth --- 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);