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.web10.323.1585069503954286452 for ; Tue, 24 Mar 2020 10:05:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XyM920O6; 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=1585069503; 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=HWF/a6vPTbAfAmqbFGb3j3VPFOmFgdBH70Q5FDWBgkw=; b=XyM920O6gO90VK1Ha1Angm8xvjY6LPFPkxhT5uktE/oppBPHbudtCPh5P41fW98PbyCw7v rEku2HwemJKpXdNOOwG1Aj56exFAoS4KAaSgL7LPdvjU4CYE9X4caFwGIfyDHDgtxHBWxk O6wafUCljYm+hvaPnSgS4nK3WWQ+BKw= 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-219-Nia5eby6Ov-TqsttuwBGgg-1; Tue, 24 Mar 2020 13:04:59 -0400 X-MC-Unique: Nia5eby6Ov-TqsttuwBGgg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC1EC8017CC; Tue, 24 Mar 2020 17:04:57 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-139.ams2.redhat.com [10.36.115.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB4CC1001938; Tue, 24 Mar 2020 17:04:48 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 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: <20200316150113.104630-1-liran.alon@oracle.com> <20200316150113.104630-17-liran.alon@oracle.com> From: "Laszlo Ersek" Message-ID: <174f8297-97b4-934f-24ef-9dd8a26778c1@redhat.com> Date: Tue, 24 Mar 2020 18:04:38 +0100 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: <20200316150113.104630-17-liran.alon@oracle.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/16/20 16:01, 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: Nikita Leshenko > Signed-off-by: Liran Alon > --- > OvmfPkg/PvScsiDxe/PvScsi.c | 42 +++++++++++++++++++++++++++++++++++++- > OvmfPkg/PvScsiDxe/PvScsi.h | 1 + > 2 files changed, 42 insertions(+), 1 deletion(-) > > diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c > index e7d0a23db6ab..33167c177b42 100644 > --- a/OvmfPkg/PvScsiDxe/PvScsi.c > +++ b/OvmfPkg/PvScsiDxe/PvScsi.c > @@ -1156,6 +1156,30 @@ PvScsiUninit ( > } > } > > +// > +// Event notification called by ExitBootServices() > +// (1) Comment style -- please use: /** Blah. **/ > +STATIC > +VOID > +EFIAPI > +PvScsiExitBoot ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + PVSCSI_DEV *Dev; > + > + Dev = Context; > + > + // > + // Reset the device. 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. > + // > + PvScsiWriteCmdDesc (Dev, PVSCSI_CMD_ADAPTER_RESET, NULL, 0); > +} > + (2) Please log a DEBUG_VERBOSE message here, something like: DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __FUNCTION__, Context)); Notification functions for EVT_SIGNAL_EXIT_BOOT_SERVICES are very important, and sometimes obscure bugs can be tracked down somewhat more easily if the firmware log captures the order in which the handlers are queued / executed. > // > // Driver Binding > // > @@ -1249,6 +1273,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 > // > @@ -1260,11 +1295,14 @@ PvScsiDriverBindingStart ( > &Dev->PassThru > ); > if (EFI_ERROR (Status)) { > - goto UninitDev; > + goto CloseExitBoot; > } > > return EFI_SUCCESS; > > +CloseExitBoot: > + gBS->CloseEvent (Dev->ExitBoot); > + > UninitDev: > PvScsiUninit (Dev); > > @@ -1319,6 +1357,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 08e876b75930..e68a7dedf71f 100644 > --- a/OvmfPkg/PvScsiDxe/PvScsi.h > +++ b/OvmfPkg/PvScsiDxe/PvScsi.h > @@ -41,6 +41,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; > These parts look fine. With (1) and (2) addressed: Reviewed-by: Laszlo Ersek Thanks, Laszlo