From patchwork Wed Aug 11 20:36:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 12431905 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 23004C4320E for ; Wed, 11 Aug 2021 20:36:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BF43961077 for ; Wed, 11 Aug 2021 20:36:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BF43961077 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 53DB78D0006; Wed, 11 Aug 2021 16:36:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4ED8C8D0001; Wed, 11 Aug 2021 16:36:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 393208D0006; Wed, 11 Aug 2021 16:36:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 1C0B18D0001 for ; Wed, 11 Aug 2021 16:36:39 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C61488249980 for ; Wed, 11 Aug 2021 20:36:38 +0000 (UTC) X-FDA: 78463958076.05.EA33AEF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 80CC6700800A for ; Wed, 11 Aug 2021 20:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628714198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p6LHuy13nKs4bZicpGZZauB7ft7dST8UEGnG3gy9DN8=; b=IGVgIEGuMK6m74XV6uU/qCN1ftVEXnCfhRg4RugJr/NmgOH39fgHv8hT4bwEv1rDqQPB05 W7ExvcniCa4i64EHu5+gjLI+/9CJOvPTHPesuLzez2xpXPHwOlVmtlNh3WmwAtYAolmvSW CYRYRLaKpV2Wh+gPjCssUs7I5vNg6aM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-QSB5eX08MEuIOl7_aCX0kQ-1; Wed, 11 Aug 2021 16:36:36 -0400 X-MC-Unique: QSB5eX08MEuIOl7_aCX0kQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BDEF8799EC; Wed, 11 Aug 2021 20:36:35 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 154021B46B; Wed, 11 Aug 2021 20:36:31 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , "Rafael J. Wysocki" , Andrew Morton , Dan Williams , Hanjun Guo , Andy Shevchenko , virtualization@lists.linux-foundation.org, linux-mm@kvack.org Subject: [PATCH v1 3/3] kernel/resource: cleanup and optimize iomem_is_exclusive() Date: Wed, 11 Aug 2021 22:36:12 +0200 Message-Id: <20210811203612.138506-4-david@redhat.com> In-Reply-To: <20210811203612.138506-1-david@redhat.com> References: <20210811203612.138506-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 80CC6700800A X-Stat-Signature: rfucxeyi1wsxm7k3nacmgbm5uz5z46bn Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IGVgIEGu; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1628714198-175248 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: Let's clean it up a bit, removing the unnecessary usage of r_next() by next_resource(), and use next_range_resource() in case we are not interested in a certain subtree. Signed-off-by: David Hildenbrand --- kernel/resource.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 2938cf520ca3..ea853a075a83 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1754,9 +1754,8 @@ static int strict_iomem_checks; */ bool iomem_is_exclusive(u64 addr) { - struct resource *p = &iomem_resource; + struct resource *p; bool err = false; - loff_t l; int size = PAGE_SIZE; if (!strict_iomem_checks) @@ -1765,27 +1764,31 @@ bool iomem_is_exclusive(u64 addr) addr = addr & PAGE_MASK; read_lock(&resource_lock); - for (p = p->child; p ; p = r_next(NULL, p, &l)) { + for (p = iomem_resource.child; p ;) { /* * We can probably skip the resources without * IORESOURCE_IO attribute? */ if (p->start >= addr + size) break; - if (p->end < addr) + if (p->end < addr) { + /* No need to consider children */ + p = next_resource_skip_children(p); continue; + } + /* * A resource is exclusive if IORESOURCE_EXCLUSIVE is set * or CONFIG_IO_STRICT_DEVMEM is enabled and the * resource is busy. */ - if ((p->flags & IORESOURCE_BUSY) == 0) - continue; - if (IS_ENABLED(CONFIG_IO_STRICT_DEVMEM) - || p->flags & IORESOURCE_EXCLUSIVE) { + if (p->flags & IORESOURCE_BUSY && + (IS_ENABLED(CONFIG_IO_STRICT_DEVMEM) || + p->flags & IORESOURCE_EXCLUSIVE)) { err = true; break; } + p = next_resource(p); } read_unlock(&resource_lock);