From: Jan Beulich <jbeulich@suse.com>
To: Ayan Kumar Halder <ayankuma@amd.com>,
Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Cc: sstabellini@kernel.org, stefano.stabellini@amd.com,
julien@xen.org, Volodymyr_Babchuk@epam.com,
bertrand.marquis@arm.com, andrew.cooper3@citrix.com,
george.dunlap@citrix.com, wl@xen.org, rahul.singh@arm.com,
xen-devel@lists.xenproject.org
Subject: Re: [XEN v4 04/11] xen/drivers: ns16550: Use paddr_t for io_base/io_size
Date: Thu, 30 Mar 2023 08:55:15 +0200 [thread overview]
Message-ID: <6196e90f-752e-e61a-45ce-37e46c22b812@suse.com> (raw)
In-Reply-To: <3e403b20-fa1a-5e0c-8e14-b89afbb10a0f@amd.com>
On 29.03.2023 16:35, Ayan Kumar Halder wrote:
> Please let me know if the below patch looks fine.
Apart from the comments below there may be formatting issues, which
I can't sensibly comment on when the patch was mangled by your mailer
anyway. (Which in turn is why it is generally better to properly send
a new version, rather than replying with kind-of-a-new-version on an
earlier thread.)
Additionally, up front: I'm sorry for the extra requests, but I'm
afraid to sensibly make the changes you want to make some things need
sorting first, to avoid extending pre-existing clumsiness. This is
irrespective of the present state of things clearly not being your
fault.
> @@ -1235,6 +1235,8 @@ pci_uart_config(struct ns16550 *uart, bool_t
> skip_amt, unsigned int idx)
> /* MMIO based */
> if ( param->mmio && !(bar & PCI_BASE_ADDRESS_SPACE_IO) )
> {
> + uint64_t pci_uart_io_base;
> +
> pci_conf_write32(PCI_SBDF(0, b, d, f),
> PCI_BASE_ADDRESS_0 + bar_idx*4, ~0u);
> len = pci_conf_read32(PCI_SBDF(0, b, d, f),
> @@ -1259,8 +1261,17 @@ pci_uart_config(struct ns16550 *uart, bool_t
> skip_amt, unsigned int idx)
> else
> size = len & PCI_BASE_ADDRESS_MEM_MASK;
>
> - uart->io_base = ((u64)bar_64 << 32) |
> - (bar & PCI_BASE_ADDRESS_MEM_MASK);
> + pci_uart_io_base = ((uint64_t)bar_64 << 32) |
> + (bar & PCI_BASE_ADDRESS_MEM_MASK);
> +
> + /* Truncation detected while converting to paddr_t */
> + if ( pci_uart_io_base != (paddr_t)pci_uart_io_base )
> + {
> + printk("ERROR: Truncation detected for io_base
> address");
> + return -EINVAL;
> + }
Further down the function returns -1, so here you assume EINVAL != 1.
Such assumptions (and mixing of value spaces) is generally not a good
idea. Since there are other issues (see below), maybe you really want
to add a prereq patch addressing those? That would include changing the
"return -1" to either "return 1" or making it use some sensible and
properly distinguishable errno value.
> @@ -1519,20 +1530,40 @@ static bool __init parse_positional(struct
> ns16550 *uart, char **str)
> #ifdef CONFIG_HAS_PCI
> if ( strncmp(conf, "pci", 3) == 0 )
> {
> - if ( pci_uart_config(uart, 1/* skip AMT */, uart -
> ns16550_com) )
> + int ret;
> +
> + ret = pci_uart_config(uart, 1/* skip AMT */, uart -
> ns16550_com);
> +
> + if ( ret == -EINVAL )
> + return false;
> + else if ( ret )
> return true;
With skip_amt != 0 the function presently can only return 0. You're
therefore converting pre-existing dead code to another form of dead
code. Otoh (and as, I think, previously indicated) ...
> +
> conf += 3;
> }
> else if ( strncmp(conf, "amt", 3) == 0 )
> {
> - if ( pci_uart_config(uart, 0, uart - ns16550_com) )
> + int ret = pci_uart_config(uart, 0, uart - ns16550_com);
> +
> + if ( ret == -EINVAL )
> + return false;
> + else if ( ret )
> return true;
... the equivalent of this in parse_namevalue_pairs() not checking
the return value is bogus. But it is further bogus that the case
where skip_amt has passed 1 for it sets dev_set to true
unconditionally, i.e. even when no device was found. IOW I also
question the correctness of the final "return 0" in pci_uart_config().
I looks to me as if this wants to be a skip_amt-independent
"return -ENODEV". skip_amt would only control whether uart->io_base is
restored before returning (leaving aside the question of why that is).
Jan
next prev parent reply other threads:[~2023-03-30 6:55 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 14:03 [XEN v4 00/11] Add support for 32 bit physical address Ayan Kumar Halder
2023-03-21 14:03 ` [XEN v4 01/11] xen/arm: Use the correct format specifier Ayan Kumar Halder
2023-03-30 19:58 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 02/11] xen/arm: domain_build: Track unallocated pages using the frame number Ayan Kumar Halder
2023-03-30 20:44 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 03/11] xen/arm: Typecast the DT values into paddr_t Ayan Kumar Halder
2023-03-30 21:10 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 04/11] xen/drivers: ns16550: Use paddr_t for io_base/io_size Ayan Kumar Halder
2023-03-21 14:16 ` Jan Beulich
2023-03-29 14:35 ` Ayan Kumar Halder
2023-03-30 6:55 ` Jan Beulich [this message]
2023-07-07 11:37 ` Ayan Kumar Halder
2023-03-21 14:03 ` [XEN v4 05/11] xen/arm: Introduce a wrapper for dt_device_get_address() to handle paddr_t Ayan Kumar Halder
2023-03-30 21:24 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 06/11] xen/arm: smmu: Use writeq_relaxed_non_atomic() for writing to SMMU_CBn_TTBR0 Ayan Kumar Halder
2023-03-30 21:27 ` Julien Grall
2023-04-03 12:49 ` Ayan Kumar Halder
2023-03-21 14:03 ` [XEN v4 07/11] xen/arm: Introduce choice to enable 64/32 bit physical addressing Ayan Kumar Halder
2023-03-21 14:22 ` Jan Beulich
2023-03-21 16:15 ` Ayan Kumar Halder
2023-03-21 16:53 ` Jan Beulich
2023-03-21 18:33 ` Ayan Kumar Halder
2023-03-22 6:59 ` Jan Beulich
2023-03-22 13:29 ` Julien Grall
2023-03-22 13:53 ` Jan Beulich
2023-03-27 11:46 ` Ayan Kumar Halder
2023-03-27 13:30 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 08/11] xen/arm: guest_walk: LPAE specific bits should be enclosed within "ifndef CONFIG_PHYS_ADDR_T_32" Ayan Kumar Halder
2023-03-21 14:03 ` [XEN v4 09/11] xen/arm: Restrict zeroeth_table_offset for ARM_64 Ayan Kumar Halder
2023-03-30 21:34 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 10/11] xen/arm: p2m: Use the pa_range_info table to support Arm_32 and Arm_64 Ayan Kumar Halder
2023-03-30 21:39 ` Julien Grall
2023-03-30 21:47 ` Julien Grall
2023-03-21 14:03 ` [XEN v4 11/11] xen/arm: p2m: Enable support for 32bit IPA for ARM_32 Ayan Kumar Halder
2023-03-30 21:45 ` Julien Grall
2023-04-04 10:38 ` Ayan Kumar Halder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6196e90f-752e-e61a-45ce-37e46c22b812@suse.com \
--to=jbeulich@suse.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=ayankuma@amd.com \
--cc=bertrand.marquis@arm.com \
--cc=george.dunlap@citrix.com \
--cc=julien@xen.org \
--cc=rahul.singh@arm.com \
--cc=sstabellini@kernel.org \
--cc=stefano.stabellini@amd.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.