From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.groups.io with SMTP id smtpd.web11.54410.1585585418715749559 for ; Mon, 30 Mar 2020 09:23:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C7ocGizN; spf=pass (domain: redhat.com, ip: 216.205.24.74, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585585417; 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; bh=Kz07XamKPLOjytFEExeyn67dhM5evv1Z5QKL9ko+hI4=; b=C7ocGizNngOW01eyj2BebTDaS0wmb23/II6tTxOvUDHcINV5R4I+3c+vcRcTkpYjcdd8Av U0ykfgygoh/MwduKcnHEVNsvGl0H4xohjELgsEoiO8HrvwtGQkJQBVCDmWjA6Ddck9kcR3 IvtGYeY80GHhxVUBEHosSnKIscXutYk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-6RravDW8OY-X3ufHdYfQ6Q-1; Mon, 30 Mar 2020 12:23:36 -0400 X-MC-Unique: 6RravDW8OY-X3ufHdYfQ6Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4A41801E6C; Mon, 30 Mar 2020 16:23:34 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-191.ams2.redhat.com [10.36.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70EEB5DA76; Mon, 30 Mar 2020 16:23:33 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v3 16/17] OvmfPkg/PvScsiDxe: Reset device on ExitBootServices() To: devel@edk2.groups.io, liran.alon@oracle.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org References: <20200328200100.60786-1-liran.alon@oracle.com> <20200328200100.60786-17-liran.alon@oracle.com> From: "Laszlo Ersek" Message-ID: Date: Mon, 30 Mar 2020 18:23:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200328200100.60786-17-liran.alon@oracle.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 03/28/20 21:00, Liran Alon wrote: > This causes the device to forget about the request/completion rings. > We allocated said rings in EfiBootServicesData type memory, and code > executing after ExitBootServices() is permitted to overwrite it. > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 > Reviewed-by: Laszlo Ersek > Signed-off-by: Liran Alon > --- > OvmfPkg/PvScsiDxe/PvScsi.c | 43 +++++++++++++++++++++++++++++++++++++- > OvmfPkg/PvScsiDxe/PvScsi.h | 1 + > 2 files changed, 43 insertions(+), 1 deletion(-) > > diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c > index da3535c75220..d7f0d3c8790c 100644 > --- a/OvmfPkg/PvScsiDxe/PvScsi.c > +++ b/OvmfPkg/PvScsiDxe/PvScsi.c > @@ -1221,6 +1221,31 @@ PvScsiUninit ( > PvScsiRestorePciAttributes (Dev); > } > > +/** > + Event notification called by ExitBootServices() > +**/ > +STATIC > +VOID > +EFIAPI > +PvScsiExitBoot ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + PVSCSI_DEV *Dev; > + > + Dev = Context; > + DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context)); > + > + // > + // Reset the device to stop device usage of the rings. > + // > + // We allocated said rings in EfiBootServicesData type memory, and code > + // executing after ExitBootServices() is permitted to overwrite it. > + // > + PvScsiResetAdapter (Dev); > +} > + My R-b stands. Thanks Laszlo > // > // Driver Binding > // > @@ -1314,6 +1339,17 @@ PvScsiDriverBindingStart ( > goto ClosePciIo; > } > > + Status = gBS->CreateEvent ( > + EVT_SIGNAL_EXIT_BOOT_SERVICES, > + TPL_CALLBACK, > + &PvScsiExitBoot, > + Dev, > + &Dev->ExitBoot > + ); > + if (EFI_ERROR (Status)) { > + goto UninitDev; > + } > + > // > // Setup complete, attempt to export the driver instance's PassThru interface > // > @@ -1325,11 +1361,14 @@ PvScsiDriverBindingStart ( > &Dev->PassThru > ); > if (EFI_ERROR (Status)) { > - goto UninitDev; > + goto CloseExitBoot; > } > > return EFI_SUCCESS; > > +CloseExitBoot: > + gBS->CloseEvent (Dev->ExitBoot); > + > UninitDev: > PvScsiUninit (Dev); > > @@ -1384,6 +1423,8 @@ PvScsiDriverBindingStop ( > return Status; > } > > + gBS->CloseEvent (Dev->ExitBoot); > + > PvScsiUninit (Dev); > > gBS->CloseProtocol ( > diff --git a/OvmfPkg/PvScsiDxe/PvScsi.h b/OvmfPkg/PvScsiDxe/PvScsi.h > index 02feac734743..544359ebc05c 100644 > --- a/OvmfPkg/PvScsiDxe/PvScsi.h > +++ b/OvmfPkg/PvScsiDxe/PvScsi.h > @@ -51,6 +51,7 @@ typedef struct { > typedef struct { > UINT32 Signature; > EFI_PCI_IO_PROTOCOL *PciIo; > + EFI_EVENT ExitBoot; > UINT64 OriginalPciAttributes; > PVSCSI_RING_DESC RingDesc; > PVSCSI_DMA_BUFFER *DmaBuf; >