From: David Hildenbrand <david@redhat.com>
To: Alistair Popple <apopple@nvidia.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
daniel.vetter@ffwll.ch, dan.j.williams@intel.com,
gregkh@linuxfoundation.org, jhubbard@nvidia.com,
jglisse@redhat.com, bsingharora@gmail.com, smuchun@gmail.com
Subject: Re: [PATCH v5 2/3] kernel/resource: Refactor __request_region to allow external locking
Date: Tue, 20 Apr 2021 16:43:35 +0200 [thread overview]
Message-ID: <935515a6-7f9e-5622-36f8-3205f0cc0690@redhat.com> (raw)
In-Reply-To: <20210419070109.4780-2-apopple@nvidia.com>
On 19.04.21 09:01, Alistair Popple wrote:
> Refactor the portion of __request_region() done whilst holding the
> resource_lock into a separate function to allow callers to hold the
> lock.
>
> Signed-off-by: Alistair Popple <apopple@nvidia.com>
> ---
> kernel/resource.c | 52 +++++++++++++++++++++++++++++------------------
> 1 file changed, 32 insertions(+), 20 deletions(-)
>
> diff --git a/kernel/resource.c b/kernel/resource.c
> index 736768587d2d..75f8da722497 100644
> --- a/kernel/resource.c
> +++ b/kernel/resource.c
> @@ -1181,31 +1181,16 @@ struct address_space *iomem_get_mapping(void)
> return smp_load_acquire(&iomem_inode)->i_mapping;
> }
>
> -/**
> - * __request_region - create a new busy resource region
> - * @parent: parent resource descriptor
> - * @start: resource start address
> - * @n: resource region size
> - * @name: reserving caller's ID string
> - * @flags: IO resource flags
> - */
> -struct resource * __request_region(struct resource *parent,
> +static int __request_region_locked(struct resource *res, struct resource *parent,
> resource_size_t start, resource_size_t n,
> const char *name, int flags)
> {
> DECLARE_WAITQUEUE(wait, current);
> - struct resource *res = alloc_resource(GFP_KERNEL);
> - struct resource *orig_parent = parent;
> -
> - if (!res)
> - return NULL;
>
> res->name = name;
> res->start = start;
> res->end = start + n - 1;
>
> - write_lock(&resource_lock);
> -
> for (;;) {
> struct resource *conflict;
>
> @@ -1241,13 +1226,40 @@ struct resource * __request_region(struct resource *parent,
> continue;
> }
> /* Uhhuh, that didn't work out.. */
> - free_resource(res);
> - res = NULL;
> - break;
> + return -EBUSY;
> }
> +
> + return 0;
> +}
> +
> +/**
> + * __request_region - create a new busy resource region
> + * @parent: parent resource descriptor
> + * @start: resource start address
> + * @n: resource region size
> + * @name: reserving caller's ID string
> + * @flags: IO resource flags
> + */
> +struct resource *__request_region(struct resource *parent,
> + resource_size_t start, resource_size_t n,
> + const char *name, int flags)
> +{
> + struct resource *res = alloc_resource(GFP_KERNEL);
> + int ret;
> +
> + if (!res)
> + return NULL;
> +
> + write_lock(&resource_lock);
> + ret = __request_region_locked(res, parent, start, n, name, flags);
> write_unlock(&resource_lock);
>
> - if (res && orig_parent == &iomem_resource)
> + if (ret) {
> + free_resource(res);
> + return NULL;
> + }
> +
> + if (parent == &iomem_resource)
> revoke_iomem(res);
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2021-04-20 14:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 7:01 [PATCH v5 1/3] kernel/resource: Allow region_intersects users to hold resource_lock Alistair Popple
2021-04-19 7:01 ` [PATCH v5 2/3] kernel/resource: Refactor __request_region to allow external locking Alistair Popple
2021-04-20 14:43 ` David Hildenbrand [this message]
2021-04-19 7:01 ` [PATCH v5 3/3] kernel/resource: Fix locking in request_free_mem_region Alistair Popple
2021-04-20 14:48 ` David Hildenbrand
2021-04-19 14:18 ` [PATCH v5 1/3] kernel/resource: Allow region_intersects users to hold resource_lock David Hildenbrand
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=935515a6-7f9e-5622-36f8-3205f0cc0690@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bsingharora@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=gregkh@linuxfoundation.org \
--cc=jglisse@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=smuchun@gmail.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