Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p8UXb-00069g-QC for mharc-grub-devel@gnu.org; Thu, 22 Dec 2022 17:59:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8UXZ-00069U-No for grub-devel@gnu.org; Thu, 22 Dec 2022 17:59:53 -0500 Received: from gate.crashing.org ([63.228.1.57]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8UXX-0000ay-0E for grub-devel@gnu.org; Thu, 22 Dec 2022 17:59:53 -0500 Received: from [IPv6:::1] (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 2BMMwiAm020943; Thu, 22 Dec 2022 16:58:46 -0600 Message-ID: Subject: Re: [PATCH v2 8/8] serial: Add ability to specify MMIO ports via 'serial' From: Benjamin Herrenschmidt To: Daniel Kiper Cc: grub-devel@gnu.org Date: Fri, 23 Dec 2022 09:58:44 +1100 In-Reply-To: <20221222125417.civynew3rbk7r735@tomti.i.net-space.pl> References: <20221222061257.1598483-1-benh@kernel.crashing.org> <20221222061257.1598483-9-benh@kernel.crashing.org> <20221222125417.civynew3rbk7r735@tomti.i.net-space.pl> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 Received-SPF: pass client-ip=63.228.1.57; envelope-from=benh@kernel.crashing.org; helo=gate.crashing.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Dec 2022 22:59:53 -0000 On Thu, 2022-12-22 at 13:54 +0100, Daniel Kiper wrote: > Thank you for quick turn around! >=20 > Now patches looks much better but... Hehe :-) > >=20 > > =C2=A0#if (defined(__mips__) || defined (__i386__) || defined (__x86_64= __)) && !defined(GRUB_MACHINE_EMU) && !defined(GRUB_MACHINE_ARC) > > -=C2=A0 if (!port && grub_memcmp (name, "port", sizeof ("port") - 1) = =3D=3D 0 > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && grub_isxdigit (name [sizeof ("port")= - 1])) > > +=C2=A0 if (!port && grub_strncmp (name, "port", grub_strlen ("port")) = =3D=3D 0 >=20 > Maybe I was a bit imprecise but I was thinking about converting > grub_memcmp() to grub_strncmp() in your patches/changes only. > Sorry about that. Ok, that's fine, I wasn't sure what you wanted, it's easy enough for me to respin and re-test. > If you want still to do that I would prefer if you do this in separate > patch. And please do not change "sizeof () - 1" to "grub_strlen ()". I'll do a separate patch. I don't like sizeof () - 1 but it's indeed more efficient at this point because grub_strlen() doesn't exploit gcc's __builtin_strlen() (which would evaluate to a constant). So I'll put them back in for now, but we should look at using more gcc builtin's imho down the line. > In the worst case I am OK with a sentence in the commit message saying > you change grub_memcmp() to grub_strncmp() on the occasion. Otherwise it > is confusing to see such changes in the patch. Though separate patch > is preferred way to do this... Nah, I'll do a separate patch. I'll put it in the same series though. > And please replace grub_memcmp() with grub_strncmp() and 4 with > 'sizeof ("mmio") - 1' in patch #3. Ah I missed that one, thanks. >=20 > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && grub_isxdigit (name [grub_strlen ("p= ort")])) > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name =3D grub_serial_ns8250_add_po= rt (grub_strtoul (&name[sizeof ("port") - 1], > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A00, 16), NULL); > > @@ -164,6 +164,49 @@ grub_serial_find (const char *name) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (grub_strcmp (port-= >name, name) =3D=3D 0) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 brea= k; > > =C2=A0=C2=A0=C2=A0=C2=A0 } > > +=C2=A0 if (!port && grub_strncmp (name, "mmio,", grub_strlen ("mmio,")= ) =3D=3D 0 > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && grub_isxdigit (name [grub_strlen ("m= mio,")])) > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *p1, *p =3D &name[grub_strle= n ("mmio,")]; >=20 > s/grub_strlen ("mmio,")/sizeof ("mmio,") - 1/ Ack. > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 grub_addr_t addr =3D grub_strtoul (p, &= p1, 16); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int acc_size =3D 1; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int nlen =3D p1 - p; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Check address validity and general s= yntax */ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (addr =3D=3D 0 || (p1[0] !=3D '\0' &= & p1[0] !=3D '.')) >=20 > This condition looks wrong. I think it should be >=20 > =C2=A0 if (*p =3D=3D '\0' || (*p1 !=3D '.' && *p1 !=3D '\0') || addr =3D= =3D 0) >=20 > I think the most important thing is lack of "*p =3D=3D '\0'". Am I right? > And I changed a logic a bit to make it more readable... if *p is '\0' then addr is 0 (and *p1 is '\0'). But we wouldn't get there in the first place because of the grub_isxdigit() in the previous test. So we know *p is a digit at this point. In fact I don't even need to test addr =3D=3D 0, there could be universes where it's a valid MMIO address :-) (not kidding, I've seen it, though nowhere we run grub these days). So the only thing we really care about at this point is the first non- digit character which is *p1. It's either a dot or a '\0' for things to be valild. > Additionally, maybe we should print an error here to give a hint to > a user what is wrong. The grub_error(..., N_()) is your friend... Right, it would go to whatever console is still active at this point (probably BIOS console) which is probably not going to be terribly useful for people who are tyring to use a serial port (for a reason .. :-) but it won't hurt either. > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (p1[0] =3D=3D '.') > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 switch(p1[1]) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 case 'w': > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acc= _size =3D 2; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 case 'l': > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acc= _size =3D 3; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 case 'q': > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acc= _size =3D 4; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bre= ak; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 case 'b': > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acc= _size =3D 1; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* fallth= rough */ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 default: > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * S= hould we abort for an unknown size ? Let's just default > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * t= o 1 byte, it would increase the chance that the user who > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * d= id a typo can actually see the console. > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 acc_size = =3D 1; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name =3D grub_serial_ns8250_add_mmio (a= ddr, acc_size, NULL); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!name) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 FOR_SERIAL_PORTS (port) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (grub_strncmp (port->nam= e, name, nlen) =3D=3D 0) { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > +=C2=A0=C2=A0=C2=A0 } > > =C2=A0=C2=A0 if (!port && grub_strcmp (name, "auto") =3D=3D 0) > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Look for an SPCR if any. If not= , default to com0 */ > > @@ -178,9 +221,9 @@ grub_serial_find (const char *name) > > =C2=A0#endif > >=20 > > =C2=A0#ifdef GRUB_MACHINE_IEEE1275 > > -=C2=A0 if (!port && grub_memcmp (name, "ieee1275/", sizeof ("ieee1275/= ") - 1) =3D=3D 0) > > +=C2=A0 if (!port && grub_strncmp (name, "ieee1275/", grub_strlen ("iee= e1275/")) =3D=3D 0) >=20 > Ditto. Ack. I'll move the memcmp/strcmp change to a separate patch and leave the sizeof alone > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name =3D grub_ofserial_add_port (&name[= sizeof ("ieee1275/") - 1]); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name =3D grub_ofserial_add_port (&name[= grub_strlen ("ieee1275/")]); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!name) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return NULL; > >=20 > > @@ -212,7 +255,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int ar= gc, char **args) > >=20 > > =C2=A0=C2=A0 if (state[OPTION_PORT].set) > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (grub_memcmp (state[OPTION_PORT].arg= , "mmio", 4) =3D=3D 0) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (grub_strncmp (state[OPTION_PORT].ar= g, "mmio,", grub_strlen ("mmio,")) =3D=3D 0) >=20 > Ditto. >=20 > And if you fix this please fix coding style in grub_le_to_cpu*()/grub_cpu= _to_le*() > calls in patch #7 too. Oops :-) > I hope I did not miss other issues this time... No worries, I don't mind respinning. At least there is movement now :-) I'll have new patches later today hopefully. Cheers, Ben.=20