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 1DF13740035 for ; Wed, 19 Jul 2023 17:40:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Yeaa/g2fhtx5Rlzr1qEa1Xc010/mGC2L4zpYkaqiKEA=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:Message-ID:Date:MIME-Version:User-Agent:To:Cc:References:From:Subject:In-Reply-To:X-Spam-Status:X-Spam-Checker-Version:Feedback-ID:X-SES-Outgoing:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1689788414; v=1; b=dFaebxYVJgduoyrohH8bC5Y9jdimcNCEAvPW/dbnmzuguROp7Wbi5FTsfGR6ioMfPxBzQwrq HTMRnJblIaY2LuxIe10DH7QLMGcyokeT7TLaOpyfErh8gStWMSnSWdPPL4q0vGIcN0k4QmvaKz7 RS2eXMv/WGNa7YSdgwVjGk60= X-Received: by 127.0.0.2 with SMTP id HAFLYY7687511xe2Inmtf2Zs; Wed, 19 Jul 2023 10:40:14 -0700 X-Received: from a7-18.smtp-out.eu-west-1.amazonses.com (a7-18.smtp-out.eu-west-1.amazonses.com [54.240.7.18]) by mx.groups.io with SMTP id smtpd.web10.1741.1689788413457337284 for ; Wed, 19 Jul 2023 10:40:13 -0700 Message-ID: <010201896f3cee08-297652da-0698-47a8-8832-246bc0d63518-000000@eu-west-1.amazonses.com> Date: Wed, 19 Jul 2023 17:40:11 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: Ard Biesheuvel , Gerd Hoffmann Cc: devel@edk2.groups.io, Jiewen Yao , Jordan Justen References: <20230719113317.276124-1-kraxel@redhat.com> <010201896ee54d34-2b5c712c-d799-49b0-a2eb-f0838988b313-000000@eu-west-1.amazonses.com> From: "Michael Brown" Subject: Re: [edk2-devel] [PATCH 1/1] OvmfPkg/IoMmuDxe: add locking to IoMmuAllocateBounceBuffer In-Reply-To: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on blyat.fensystems.co.uk Feedback-ID: 1.eu-west-1.fspj4M/5bzJ9NLRzJP0PaxRwxrpZqiDQJ1IF94CF2TA=:AmazonSES X-SES-Outgoing: 2023.07.19-54.240.7.18 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,mcb30@ipxe.org X-Gm-Message-State: zhxFxEUmBwnuiXTkorsFRjL4x7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=dFaebxYV; dmarc=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 19/07/2023 17:52, Ard Biesheuvel wrote: > On Wed, 19 Jul 2023 at 18:32, Gerd Hoffmann wrote: >> On Wed, Jul 19, 2023 at 04:04:28PM +0000, Michael Brown wrote: >>> It looks as though IoMmuFreeBounceBuffer() should also raise to TPL_NOT= IFY >>> while modifying mReservedMemBitmap, since the modification made in >>> IoMmuFreeBounceBuffer() is not an atomic operation: >>> >>> mReservedMemBitmap &=3D (UINT32)(~MapInfo->ReservedMemBitmap); >> >> I'd expect modern compilers optimize that to a single instruction, >=20 > You mean something along the lines of >=20 > andl %reg, mReservedMemBitmap(%rip) >=20 > right? Even with a single orl/andl instruction, the operation is unlocked.=20 It's guaranteed atomic against interrupts (since interrupts always occur=20 at instruction boundaries) but it's not guaranteed atomic against=20 concurrent accesses to the same global variable from other processors. (I have no idea if the UEFI model allows APs to call into the IOMMU=20 protocol or not, so I don't know if this is a real problem.) On a quick review of the code, there appear to be other points that also=20 modify mReservedMemBitmap (IoMmuAllocateCommonBuffer() and=20 IoMmuFreeCommonBuffer()). I'd guess that these also need to raise to=20 TPL_NOTIFY, but I'm not familiar with the code so I don't know if=20 there's anything that makes this unnecessary. Sorry not to be more help. Thanks, Michael -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107060): https://edk2.groups.io/g/devel/message/107060 Mute This Topic: https://groups.io/mt/100233359/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-