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 EB74A7803E5 for ; Thu, 20 Jul 2023 08:34:47 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=DPgHJfs8BrmlPkYQBysyLQFK45WGZIgjHgc7zjGG5t8=; 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=1689842086; v=1; b=aV5xZlw63hfa4kYmUKYrIzqBhB0T49gM5HiYjkOt7+4xjIOYNbUpYsCGHYuBkNMe7ZaWAnGr j0rZIVFLtGf5euzwrSCfxyl7Lq+UTqXV03/s9lD4DzuoGxn60AiaP2+qoPGXKGdH7QYjHr8FrCN w0VACnIAXX41Z70h6RMEaveM= X-Received: by 127.0.0.2 with SMTP id 0xOHYY7687511xVeb1fnpIKh; Thu, 20 Jul 2023 01:34:46 -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.8459.1689842085817340298 for ; Thu, 20 Jul 2023 01:34:45 -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 477E96192A for ; Thu, 20 Jul 2023 08:34:45 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 838D9C433C9 for ; Thu, 20 Jul 2023 08:34:44 +0000 (UTC) X-Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-4fb7373dd35so2147333e87.1 for ; Thu, 20 Jul 2023 01:34:44 -0700 (PDT) X-Gm-Message-State: ZmIjkLuUmdcZqco6SEfWEFGEx7686176AA= X-Google-Smtp-Source: APBJJlFreGEbgbOKhqQF9ihXUysO+JIzMv1VTkP5Py/wrT828q5X/yCIgGdmYwm8oI30M/t+hfrUw4THj4j9zLTav7g= X-Received: by 2002:ac2:5e63:0:b0:4f8:6253:540 with SMTP id a3-20020ac25e63000000b004f862530540mr850651lfr.19.1689842082521; Thu, 20 Jul 2023 01:34:42 -0700 (PDT) MIME-Version: 1.0 References: <20230720082438.75669-1-kraxel@redhat.com> In-Reply-To: <20230720082438.75669-1-kraxel@redhat.com> From: "Ard Biesheuvel" Date: Thu, 20 Jul 2023 10:34:31 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 1/1] OvmfPkg/IoMmuDxe: add locking to IoMmuAllocateCommonBuffer To: Gerd Hoffmann Cc: devel@edk2.groups.io, Jordan Justen , Ard Biesheuvel , Jiewen Yao , Michael Brown 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=aV5xZlw6; 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 Thu, 20 Jul 2023 at 10:24, Gerd Hoffmann wrote: > > IoMmuAllocateCommonBuffer has the very same allocation pattern > IoMmuAllocateBounceBuffer uses, so the fix added by commit a52044a9e602 > ("OvmfPkg/IoMmuDxe: add locking to IoMmuAllocateBounceBuffer") is needed > here too. > > Reported-by: Michael Brown > Signed-off-by: Gerd Hoffmann Thanks. After pondering this a bit longer, I wonder whether we should simply use InterlockedCompareExchange32() instead, rather than play with the TPL levels. The only thing we are protecting here are concurrent modifications of mReservedMemBitmap, right? In any case, this patch appears to be correct too, so I won't insist. Thanks, > --- > OvmfPkg/IoMmuDxe/IoMmuBuffer.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/OvmfPkg/IoMmuDxe/IoMmuBuffer.c b/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > index 103003cae376..6fcf88b50ce1 100644 > --- a/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > +++ b/OvmfPkg/IoMmuDxe/IoMmuBuffer.c > @@ -442,7 +442,9 @@ IoMmuAllocateCommonBuffer ( > ) > { > EFI_STATUS Status; > + EFI_TPL OldTpl; > > + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); > Status = InternalAllocateBuffer ( > AllocateMaxAddress, > MemoryType, > @@ -453,6 +455,7 @@ IoMmuAllocateCommonBuffer ( > ASSERT (Status == EFI_SUCCESS); > > mReservedMemBitmap |= *ReservedMemBitmap; > + gBS->RestoreTPL (OldTpl); > > if (*ReservedMemBitmap != 0) { > *PhysicalAddress -= SIZE_4KB; > @@ -476,6 +479,8 @@ IoMmuFreeCommonBuffer ( > IN UINTN CommonBufferPages > ) > { > + EFI_TPL OldTpl; > + > if (!mReservedSharedMemSupported) { > goto LegacyFreeCommonBuffer; > } > @@ -494,7 +499,10 @@ IoMmuFreeCommonBuffer ( > mReservedMemBitmap & ((UINT32)(~CommonBufferHeader->ReservedMemBitmap)) > )); > > + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); > mReservedMemBitmap &= (UINT32)(~CommonBufferHeader->ReservedMemBitmap); > + gBS->RestoreTPL (OldTpl); > + > return EFI_SUCCESS; > > LegacyFreeCommonBuffer: > -- > 2.41.0 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107091): https://edk2.groups.io/g/devel/message/107091 Mute This Topic: https://groups.io/mt/100251949/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-