Received: from eggs.gnu.org ([209.51.188.92]:50334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtQE-0001TX-4u for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:50:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwtQC-0003dQ-4a for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:50:14 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:52882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwtQB-0003bo-Mk for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:50:12 -0500 Received: by mail-wm1-x344.google.com with SMTP id m1so10641806wml.2 for ; Thu, 21 Feb 2019 10:50:11 -0800 (PST) References: <20190218125615.18970-1-armbru@redhat.com> <20190218125615.18970-3-armbru@redhat.com> <2340eb1c-d8d8-3d92-bbb5-b541bb44dcba@redhat.com> <875ztfuc0j.fsf@dusky.pond.sub.org> <87sgwh5wef.fsf@dusky.pond.sub.org> <8d278f39-9549-5326-bfd8-b4bcabeacf84@redhat.com> <87d0nlxedj.fsf@dusky.pond.sub.org> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <87d0nlxedj.fsf@dusky.pond.sub.org> Date: Thu, 21 Feb 2019 18:50:09 +0000 Message-ID: <87y3692cym.fsf@zen.linaroharston> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 02/10] pflash: Macro PFLASH_BUG() is used just once, expand List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Peter Maydell , Laszlo Ersek , Kevin Wolf , Qemu-block , QEMU Developers , Max Reitz , qemu-ppc Markus Armbruster writes: > Philippe Mathieu-Daud=C3=A9 writes: > >> On 2/21/19 10:38 AM, Peter Maydell wrote: >>> On Thu, 21 Feb 2019 at 09:22, Markus Armbruster wro= te: >>>> Double-checking... you want me to keep goto reset_flash, like this: >>>> >>>> @@ -623,8 +617,8 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr = offset, >>>> pfl->wcycle =3D 0; >>>> pfl->status |=3D 0x80; >>>> } else { >>>> - DPRINTF("%s: unknown command for \"write block\"\n", = __func__); >>>> - PFLASH_BUG("Write block confirm"); >>>> + qemu_log_mask(LOG_GUEST_ERROR, >>>> + "unknown command for \"write block\"\n"= ); >>>> goto reset_flash; >>>> } >>>> break; >>> >>> Yes. (We seem to handle most kinds of guest errors in programming >>> the flash by reset_flash.) >> >> Oh I missed the context of the patch here. >> >> So for the case of the Multi-WRITE command (0xe8): >> >> 1/ On first write cycle we have >> >> - address =3D flash_page_address (we store it in pfl->counter) >> - data =3D flash_command (0xe8: enter Multi-WRITE) >> >> 2/ Second cycle: >> >> - address =3D flash_page_address >> We should check it matches flash_page_address >> of cycle 1/, but we don't. >> - data: N >> >> "N is the number of elements (bytes / words / double words), >> minus one, to be written to the write buffer. Expected count >> ranges are N =3D 00h to N =3D 7Fh (e.g., 1 to 128 bytes) in 8-bit >> mode, N =3D 00h to N =3D 003Fh in 16-bit mode, and N =3D 00h to >> N =3D 1Fh in 32-bit mode. Bus cycles 3 and higher are for writing >> data into the write buffer. The confirm command (D0h) is >> expected after exactly N + 1 write cycles; any other command at >> that point in the sequence will prevent the transfer of the >> buffer to the array (the write will be aborted)." >> >> Instead of starting to write the data in a buffer, we write it >> directly to the block backend. >> Instead of starting to write from cycle 3+, we write now in 2, >> and keep cycle count =3D=3D 2 (pfl->wcycle) until all data is >> written, where we increment at 3. >> >> 3/ Cycles 3+ >> >> - address =3D word index (relative to the page address) >> - data =3D word value >> >> We check for the CONFIRM command, and switch the device back >> to READ mode (setting Status), or reset the device (which is >> modelled the same way). >> >> Very silly: If the guest cancelled and never sent the CONFIRM >> command, the data is already written/flushed back. >> >> So back to the previous code snippet, regardless the value, this >> is neither a hw_error() nor a GUEST_ERROR. This code is simply not >> correct. Eventually the proper (polite) error message should be: >> >> qemu_log_mask(LOG_UNIMP, "MULTI_WRITE: Abort not implemented," >> " the data is already written" >> " on storage!\n" >> "Nevertheless resetting the flash" >> " into READ mode.\n"); > > Oww. > > This code is a swamp. > > Peter, Alex, do you agree with Phil's analysis? If yes, I'll update my > patch once more. I'm happy to defer to Phil's obvious expertise here ;-) -- Alex Benn=C3=A9e