From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25B72C433B4 for ; Tue, 20 Apr 2021 14:44:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3992E6100A for ; Tue, 20 Apr 2021 14:44:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3992E6100A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 881A86B006C; Tue, 20 Apr 2021 10:44:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 859426B006E; Tue, 20 Apr 2021 10:44:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D2526B0070; Tue, 20 Apr 2021 10:44:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id 526746B006C for ; Tue, 20 Apr 2021 10:44:14 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0E96C2C9D for ; Tue, 20 Apr 2021 14:44:14 +0000 (UTC) X-FDA: 78053015628.34.22D40B0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 8286240002DE for ; Tue, 20 Apr 2021 14:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618929853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=suIGX8gxDAa1NnElSORJBHL/+yMG1ICjZh8iApb4hRQ=; b=RNlRgnsg4YWzN2bFljL+uk7ubLWGYRCLOnRpngyRcMgT73dQHLQ/CPAG6cA+qXmQPbKpTi Pv4N7xr23XDC3o0sDutjsG606P/PNXszC4SjrrINIeCEe2DJUQXpjddYNcwxl4jQG7ZcI6 m0HibYVY06pAS4qMD1TnFdUe7+mKlu4= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-S4bo3Iq8PHOjIGpAwAXIqQ-1; Tue, 20 Apr 2021 10:43:39 -0400 X-MC-Unique: S4bo3Iq8PHOjIGpAwAXIqQ-1 Received: by mail-ed1-f69.google.com with SMTP id p16-20020a0564021550b029038522733b66so5179723edx.11 for ; Tue, 20 Apr 2021 07:43:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=suIGX8gxDAa1NnElSORJBHL/+yMG1ICjZh8iApb4hRQ=; b=h18FDES5W73MRxfeHXjTxcACaArWLW3C78a1Ksb568lCuGR/NLJIuH/UchVOKMyCl1 vgUHu7eBpIX4p5LN9zAC+bGT6xrXNTqWjykmiP3i3oiKyVQkDRxUwf+Graicw6pk4PsC LmFYakiaEW9rfXJ2Lo4ZBDaCOEqbasN/9uGu+48zLjiR36oqUHwYen0YgsEEmhAfg4OB zpiboaCpCLyYoBeavUs8eLKD33C5pj8k2g8+aDTzQrBcySDS84cRTD2nud4zaamflM73 Lu36//pIqWeW98DV3PtAzjs7N7Op7Pc9vH7kyjeHnKWhFZd5h1xDcyv5wSGuVe99nQaL oMow== X-Gm-Message-State: AOAM5323mJYpqKQ1p1B2V6yyETXSqE8fV56+2CQzfYKVVuNkWBQnMdWw Gssv9TAY77yk29CevAtGhZd+pJaB6OvgA4rYSivAptLrXx8MRTr8seYgPYTqntfsjrUZQwWsiAK 6Ecmed7Dj1d8= X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr32367884edt.181.1618929818066; Tue, 20 Apr 2021 07:43:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycKxTX6uIvzg4SlHy5vEivTK5R28RJSkXNygI/D6/70trVtgRV/7yyyDFHnPHVinXCN//pAA== X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr32367855edt.181.1618929817824; Tue, 20 Apr 2021 07:43:37 -0700 (PDT) Received: from [192.168.3.132] (p4ff2390a.dip0.t-ipconnect.de. [79.242.57.10]) by smtp.gmail.com with ESMTPSA id x20sm3359873edd.58.2021.04.20.07.43.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Apr 2021 07:43:37 -0700 (PDT) Subject: Re: [PATCH v5 2/3] kernel/resource: Refactor __request_region to allow external locking To: Alistair Popple , 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 References: <20210419070109.4780-1-apopple@nvidia.com> <20210419070109.4780-2-apopple@nvidia.com> From: David Hildenbrand Organization: Red Hat Message-ID: <935515a6-7f9e-5622-36f8-3205f0cc0690@redhat.com> Date: Tue, 20 Apr 2021 16:43:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210419070109.4780-2-apopple@nvidia.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 8286240002DE X-Stat-Signature: 5oooc4py514jeds7y8pejbfqphfoxn4f X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618929847-291760 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > --- > 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 -- Thanks, David / dhildenb