From: Bjorn Helgaas <helgaas@kernel.org>
To: John Garry <john.garry@huawei.com>
Cc: xuwei5@huawei.com, linuxarm@huawei.com, arm@kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
joe@perches.com
Subject: Re: [PATCH 2/5] lib: logic_pio: Add logic_pio_unregister_range()
Date: Fri, 21 Jun 2019 08:49:55 -0500 [thread overview]
Message-ID: <20190621134955.GD82584@google.com> (raw)
In-Reply-To: <1561026716-140537-3-git-send-email-john.garry@huawei.com>
On Thu, Jun 20, 2019 at 06:31:53PM +0800, John Garry wrote:
> Add a function to unregister a logical PIO range.
>
> The method used to allocate LOGIC_PIO_CPU_MMIO regions during registration
> is slightly modified to ensure that we get no overlap when regions are
> unregistered. This is needed because the allocation scheme assumed that no
> regions are ever unregistered.
>
> Logical PIO space can still be leaked when unregistering certain
> LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no
> callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO
> region allocation scheme would need significant work to improve this.
>
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
> include/linux/logic_pio.h | 1 +
> lib/logic_pio.c | 16 +++++++++++++++-
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h
> index cbd9d8495690..88e1e6304a71 100644
> --- a/include/linux/logic_pio.h
> +++ b/include/linux/logic_pio.h
> @@ -117,6 +117,7 @@ struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode);
> unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
> resource_size_t hw_addr, resource_size_t size);
> int logic_pio_register_range(struct logic_pio_hwaddr *newrange);
> +void logic_pio_unregister_range(struct logic_pio_hwaddr *range);
> resource_size_t logic_pio_to_hwaddr(unsigned long pio);
> unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr);
>
> diff --git a/lib/logic_pio.c b/lib/logic_pio.c
> index 761296376fbc..45eb57af2574 100644
> --- a/lib/logic_pio.c
> +++ b/lib/logic_pio.c
> @@ -56,7 +56,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
> /* for MMIO ranges we need to check for overlap */
> if (start >= range->hw_start + range->size ||
> end < range->hw_start) {
> - mmio_sz += range->size;
> + mmio_sz = range->io_start + range->size;
Should this be renamed to something like "mmio_end"? Computing a
"size" as "start + size" looks wrong at first glance. The code overall
probably makes sense, but maybe breaking this out as a separate "avoid
overlaps" patch that renames "mmio_sz" might make it clearer.
> } else {
> ret = -EFAULT;
> goto end_register;
> @@ -98,6 +98,20 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
> return ret;
> }
>
> +/**
> + * logic_pio_unregister_range - unregister logical PIO range for a host
> + * @range: pointer to the IO range which has been already registered.
> + *
> + * Unregister a previously-registered IO range node.
> + */
> +void logic_pio_unregister_range(struct logic_pio_hwaddr *range)
> +{
> + mutex_lock(&io_range_mutex);
> + list_del_rcu(&range->list);
> + mutex_unlock(&io_range_mutex);
> + synchronize_rcu();
> +}
> +
> /**
> * find_io_range_by_fwnode - find logical PIO range for given FW node
> * @fwnode: FW node handle associated with logical PIO range
> --
> 2.17.1
>
next prev parent reply other threads:[~2019-06-21 13:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 10:31 [PATCH 0/5] Fixes for HiSilicon LPC driver and logical PIO code John Garry
2019-06-20 10:31 ` [PATCH 1/5] lib: logic_pio: Fix RCU usage John Garry
2019-06-21 13:43 ` Bjorn Helgaas
2019-06-21 14:12 ` John Garry
2019-06-20 10:31 ` [PATCH 2/5] lib: logic_pio: Add logic_pio_unregister_range() John Garry
2019-06-21 13:49 ` Bjorn Helgaas [this message]
2019-06-21 14:19 ` John Garry
2019-06-20 10:31 ` [PATCH 3/5] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free John Garry
2019-06-20 10:31 ` [PATCH 4/5] bus: hisi_lpc: Add .remove method to avoid driver unbind crash John Garry
2019-06-21 13:56 ` Bjorn Helgaas
2019-06-21 14:33 ` John Garry
2019-06-20 10:31 ` [PATCH 5/5] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration John Garry
2019-06-20 12:42 ` [PATCH 0/5] Fixes for HiSilicon LPC driver and logical PIO code Olof Johansson
2019-06-20 12:56 ` John Garry
2019-06-20 13:42 ` Olof Johansson
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=20190621134955.GD82584@google.com \
--to=helgaas@kernel.org \
--cc=arm@kernel.org \
--cc=joe@perches.com \
--cc=john.garry@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=xuwei5@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox