From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 06FAC7803CD for ; Wed, 19 Jul 2023 22:03:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=WJJyiuhqKuK5hjdf5QCLLsw70BngXniuGAG3jzDFbOI=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:X-Received:X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version:References:In-Reply-To:From:Date:X-Gmail-Original-Message-ID:Message-ID:Subject:To:Cc:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:Content-Type; s=20140610; t=1689804224; v=1; b=Vx5j/9pr/w0YYDRnDqDk9YU1bvXGDQl5wo75MY+BJ1Ob4EU9w/XYq2BkHi9uHcBtJi8JtrHL ArvK5zj3H9cujXBmwQ8YFoVBA5+WiQwZ68S86sgnaalAqNEssEfl9q6XWgTFzApvXbRkEUJvysB 5tlAn3kqwgyaAsAMG/Ny09sc= X-Received: by 127.0.0.2 with SMTP id QH4FYY7687511xQ4Ab5Kq9Oj; Wed, 19 Jul 2023 15:03:44 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.2600.1689804223866797657 for ; Wed, 19 Jul 2023 15:03:44 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 62F59616FE for ; Wed, 19 Jul 2023 22:03:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD000C433C7 for ; Wed, 19 Jul 2023 22:03:42 +0000 (UTC) X-Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so147745e87.2 for ; Wed, 19 Jul 2023 15:03:42 -0700 (PDT) X-Gm-Message-State: vfFEc6y7SmO0GfJud25F7Xrzx7686176AA= X-Google-Smtp-Source: APBJJlGybMF4PdimRYGDGvJcaDLY1Y3xIEVBK8/X2oDRjXieoe/eo3c7vSpiAwgARNfABYAKHSsA9Tk5ET9w9KYPIyg= X-Received: by 2002:ac2:5324:0:b0:4fb:7c40:9f95 with SMTP id f4-20020ac25324000000b004fb7c409f95mr970920lfh.47.1689804220859; Wed, 19 Jul 2023 15:03:40 -0700 (PDT) MIME-Version: 1.0 References: <20230719163129.318992-1-kraxel@redhat.com> In-Reply-To: <20230719163129.318992-1-kraxel@redhat.com> From: "Ard Biesheuvel" Date: Thu, 20 Jul 2023 00:03:29 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v2 1/1] OvmfPkg/IoMmuDxe: add locking to IoMmuAllocateBounceBuffer To: devel@edk2.groups.io, kraxel@redhat.com Cc: Jordan Justen , Ard Biesheuvel , Michael Brown , Jiewen Yao Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="Vx5j/9pr"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Wed, 19 Jul 2023 at 18:31, Gerd Hoffmann wrote: > > Searching for an unused bounce buffer in mReservedMemBitmap and > reserving the buffer by flipping the bit is a critical section > which must not be interrupted. Raise the TPL level to ensure > that. > > Without this fix it can happen that IoMmuDxe hands out the same > bounce buffer twice, causing trouble down the road. Seen happening > in practice with VirtioNetDxe setting up the network interface (and > calling into IoMmuDxe from a polling timer callback) in parallel with > Boot Manager doing some disk I/O. An ASSERT() in VirtioNet caught > the buffer inconsistency. > > Full story with lots of details and discussions is available here: > https://bugzilla.redhat.com/show_bug.cgi?id=2211060 > > v2: > - add locking to IoMmuFreeBounceBuffer too, clearing bits in > mReservedMemBitmap is not guaranteed to be atomic (Michael Brown). > Please put this under the --- so I don't have to remove manually it when applying. > Signed-off-by: Gerd Hoffmann Pushed as #4665 Thanks, > --- > OvmfPkg/IoMmuDxe/IoMmuBuffer.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/OvmfPkg/IoMmuDxe/IoMmuBuffer.c b/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > index c8f6cf4818e8..103003cae376 100644 > --- a/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > +++ b/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > @@ -367,7 +367,9 @@ IoMmuAllocateBounceBuffer ( > { > EFI_STATUS Status; > UINT32 ReservedMemBitmap; > + EFI_TPL OldTpl; > > + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); > ReservedMemBitmap = 0; > Status = InternalAllocateBuffer ( > Type, > @@ -378,6 +380,7 @@ IoMmuAllocateBounceBuffer ( > ); > MapInfo->ReservedMemBitmap = ReservedMemBitmap; > mReservedMemBitmap |= ReservedMemBitmap; > + gBS->RestoreTPL (OldTpl); > > ASSERT (Status == EFI_SUCCESS); > > @@ -395,6 +398,8 @@ IoMmuFreeBounceBuffer ( > IN OUT MAP_INFO *MapInfo > ) > { > + EFI_TPL OldTpl; > + > if (MapInfo->ReservedMemBitmap == 0) { > gBS->FreePages (MapInfo->PlainTextAddress, MapInfo->NumberOfPages); > } else { > @@ -407,9 +412,11 @@ IoMmuFreeBounceBuffer ( > mReservedMemBitmap, > mReservedMemBitmap & ((UINT32)(~MapInfo->ReservedMemBitmap)) > )); > + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); > MapInfo->PlainTextAddress = 0; > mReservedMemBitmap &= (UINT32)(~MapInfo->ReservedMemBitmap); > MapInfo->ReservedMemBitmap = 0; > + gBS->RestoreTPL (OldTpl); > } > > return EFI_SUCCESS; > -- > 2.41.0 > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107063): https://edk2.groups.io/g/devel/message/107063 Mute This Topic: https://groups.io/mt/100238846/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-