Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1104E606A322 for ; Fri, 4 Dec 2026 15:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IyVLOtPi Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZVHX-0001YF-Pr; Fri, 04 Dec 2026 10:33:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZVHV-0001XA-BL for qemu-rust@nongnu.org; Fri, 04 Dec 2026 10:33:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZVHT-0000Tl-8Y for qemu-rust@nongnu.org; Fri, 04 Dec 2026 10:33:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796398382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=rH+xPA0TFAet/ltpS5DcvveiiBwZPwSMUmavqVi4z0M=; b=IyVLOtPiDeWdTbPUuKFhNMUZrknK1H26KYhk2u7qjnqFI9/OS0+E8x5YTZ+Ris2HRhjTm2 Wk2Q3OS4/xOxI14DlPhgtPhzIRLDxp7b2Xr7TuQ4p3Z41xFFjy0QCvqcMRPvZhktBfljga Av4rACixrp+ZkCPzA9+rExzlJJZVVgs= X-MC-Rep: binary re single Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-QZdjzlo5Nx2u4TuUouKy7Q-1; Fri, 4 Dec 2026 15:33:00 +0000 X-MC-Unique: QZdjzlo5Nx2u4TuUouKy7Q-1 X-Mimecast-MFC-AGG-ID: QZdjzlo5Nx2u4TuUouKy7Q_1796398379 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4925ef75fc4so774357f8f.1 for ; Fri, 04 Dec 2026 07:32:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398379; x=1797003179; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rH+xPA0TFAet/ltpS5DcvveiiBwZPwSMUmavqVi4z0M=; b=xgb33QF3ZE6qqTNnPv3kyRkDeBc8cbT7Hlayf4P7r2NdJz8Uh6JMVSTelHteMhc28S udGBTwLiRBNjcSUyfVu+PAPV7F68HB3ZikHbPr1Dfx46O9Tq0U5LUyns59Nn0uJRliKC poKbACKWkxZzT0bmbGSfzBuQxiGVCoedhSjnc1SRzPeCSMQ3ag5sWNvrUlWRsNBnQaDx Q4to+yjIZ62StSJenr1yTspM1/3zroNDo9Ja8/+V4fB7ArUT8DnUXB6m3/sajgofSEmY 0lIYuQUaJ2f3C0AsdLf3ZA2d3QXQP7J6d0z7fW2KZX7Kc9mRk8b8E+Y2FRasS7k+XjYX pJJA== X-Forwarded-Encrypted: i=1; AL+hErFEQN2Czgupo+3XF5qNSjdkjzc3lNh2A4Pn5yiUuu7tdR6rglnUrsPxbDrJLGExwf86RZPa3kNUJ8A=@nongnu.org X-Gm-Message-State: APuU4Z9njIATTVSdg3kRonxZfvW90X8pws4qY+1BQQ2dz7L+/L00DRT7 ZXL+Qtt+kWO1wQ4WNOeUVqP9g9CNG2yu40gy9JC0HL+YhTZU9NxpnTUCVgW1C7YbMKGI2oUzbeg YDF+pUSK8lrPtmOGR4E/xDijcaZFQ6/PqS1W61LEE9ynHvZC+cJLBtgM= X-Gm-Gg: AZFdTZfRzW2wYO1l98/yDVoNd0ZmQcjsnWiLl8FovPSyQN9vPsxrVR7IF9S76Z1yoWB otlq/fD/OLtq7VaTizBHcS0pTjejy6FCiBswzU+p5uS3BQgBxBs28/ZppmBTJnOvp+v7Wspd6Mr YyUtX9L9KC0Fflg5HbFeeOr6WVF2dlTiHTX1s/z8jxKtUuii7QRkcNplUQtcDw2XpA1AElJynnB oTjYrDU2egtv+RiVRmqF62nxz+wqcXu7SO+6BwugxGZgEMpOod2M674h9CMQOpakhPImkhOUcZA YJc6OgABZ47yR8H+Cgk1HOuERyXvsiFkktwwznOy3SMvlRrQ4JXYOT9vFCJwW5YFCVXoVKWVy0h MqI9nyZXzyWqjmsQMOABwjn8KSalcdwYkSx3iv5uypek= X-Received: by 2002:a05:600c:46d1:b0:4bb:69f2:87f7 with SMTP id 5b1f17b1804b1-4bbeb8b07ddmr42615795e9.18.1796398378932; Fri, 04 Dec 2026 07:32:58 -0800 (PST) X-Received: by 2002:a05:600c:46d1:b0:4bb:69f2:87f7 with SMTP id 5b1f17b1804b1-4bbeb8b07ddmr42615385e9.18.1796398378512; Fri, 04 Dec 2026 07:32:58 -0800 (PST) Received: from [192.168.0.9] ([47.64.113.95]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2a0484sm60985915e9.11.2026.12.04.07.32.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 07:32:57 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 16:32:56 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/6] util/qemu-timer: Support reentrancy guard and use in pcnet, hcd-xhci To: Peter Maydell , qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Fam Zheng , Manos Pitsidianakis , =?UTF-8?Q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault , Paolo Bonzini , qemu-rust@nongnu.org References: <20261204131946.2175006-1-peter.maydell@linaro.org> From: Thomas Huth Autocrypt: addr=thuth@redhat.com; keydata= xsFNBFH7eUwBEACzyOXKU+5Pcs6wNpKzrlJwzRl3VGZt95VCdb+FgoU9g11m7FWcOafrVRwU yYkTm9+7zBUc0sW5AuPGR/dp3pSLX/yFWsA/UB4nJsHqgDvDU7BImSeiTrnpMOTXb7Arw2a2 4CflIyFqjCpfDM4MuTmzTjXq4Uov1giGE9X6viNo1pxyEpd7PanlKNnf4PqEQp06X4IgUacW tSGj6Gcns1bCuHV8OPWLkf4hkRnu8hdL6i60Yxz4E6TqlrpxsfYwLXgEeswPHOA6Mn4Cso9O 0lewVYfFfsmokfAVMKWzOl1Sr0KGI5T9CpmRfAiSHpthhHWnECcJFwl72NTi6kUcUzG4se81 O6n9d/kTj7pzTmBdfwuOZ0YUSqcqs0W+l1NcASSYZQaDoD3/SLk+nqVeCBB4OnYOGhgmIHNW 0CwMRO/GK+20alxzk//V9GmIM2ACElbfF8+Uug3pqiHkVnKqM7W9/S1NH2qmxB6zMiJUHlTH gnVeZX0dgH27mzstcF786uPcdEqS0KJuxh2kk5IvUSL3Qn3ZgmgdxBMyCPciD/1cb7/Ahazr 3ThHQXSHXkH/aDXdfLsKVuwDzHLVSkdSnZdt5HHh75/NFHxwaTlydgfHmFFwodK8y/TjyiGZ zg2Kje38xnz8zKn9iesFBCcONXS7txENTzX0z80WKBhK+XSFJwARAQABzR5UaG9tYXMgSHV0 aCA8dGh1dGhAcmVkaGF0LmNvbT7CwXgEEwECACIFAlVgX6oCGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAAoJEC7Z13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261204131946.2175006-1-peter.maydell@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FYIunEGUbxAKX-H9MvCAvgm6r71DSCM7wCt56iMUoCg_1796398379 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-rust-bounces+qemu-rust=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Am 04.12.26 um 14:19 schrieb Peter Maydell: > It's common for devices that use QEMU timers to do things in their > timer callbacks that may either directly be a DMA operation, or to > call out to other device models (e.g. by setting an interrupt) that > might indirectly trigger a DMA operation. If the guest can arrange > for that DMA operation to be to an address which is in the device's > own memory-mapped registers, the device code will be re-entered in a > way it doesn't expect. > > Our mechanism for avoiding that is the MemReentrancyGuard. We > automatically set that when calling into a device's memory operation > read and write functions, and if the device directly uses the QEMUBH > API they can ask for the BH callbacks to be guarded (via e.g. > aio_bh_new_guarded() or qemu_bh_new_guarded()), but for a timer > callback the device has to manually enable its guard. We did that > for the USB XHCI device in commit f91b0544fe1f ("hw/usb/hcd-xhci: Set > reentrancy guard in timer functions"). > > To make it less awkward for devices to enable a reentrancy guard for > their timer callbacks, add support for the guard to the QEMU timer > API, in the same way that we did for the BH API in commit 9c86c97f12 > ("async: Add an optional reentrancy guard to the BH API"). > > This patchset updates the timer API, reworks the hcd-xhci fix to use > it instead of manually enabling the guard, and uses the new API to fix > a bug in the pcnet device. (This isn't a security issue as that device > is outside the security umbrella.) > > There are a lot of timer_new* and timer_init* variants; I have only > added versions that let you set the guard for the specific case that I > needed for this device, rather than adding a lot of new wrapper > functions with no callers. We can add others as we need them. Thanks a lot for tackling this! Patch series looks good (apart from some minor nits), and I also think this is the right way to go forward with these timer-reentrancy bugs! > Side question that I thought of while doing this: should the code that > enables a reentrancy guard take a QOM reference on the device while it > holds the guard? This timer code, like the AIO code, imposes an > implicit requirement that the AIO BH or timer callback doesn't > actually free the device (since it holds a pointer to the > MemReentrancyGuard across the callback call). That seems reasonable, > but maybe holding a ref would be more bulletproof? I'd say, let's start small, just with what is done in this patch series. If we later get bug reports that we can fix with additional QOM references, we still can add it easily on top since we now have everything properly wrapper in the timer API. Thomas