Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp375236pxb; Mon, 16 Aug 2021 07:26:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGRFMfHICQ7nccGmtNk1QPIVObZ8itoVJ6kKSrF+8xSreOMCoNqGdf7945FexwCcXmKBey X-Received: by 2002:a92:a04c:: with SMTP id b12mr11927759ilm.80.1629124015863; Mon, 16 Aug 2021 07:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629124015; cv=none; d=google.com; s=arc-20160816; b=XAMPW4g9A/0l0pw9B8akUdY2OVp15WQgoYTmLc5yEy0eC9NeKXCKwSpQtQayuDsp/h BIJdh6AVwaEMhfmJmY8zCsG4wnThR8BOkp7H5fpmV5kftHFhZzlCDCliSyd1Fjjlczwp 3z24vuMmlgTda4273Tl8gsv2RfLfzSKoCq1bIZ+WKHtBRLhChLKS3jlhezefIIgfTYkO 31XfEG6GZMmy/3pHvA3CWeae5hCHx9IHibu/XuGZPsz0k1ywhBybKAP4vfg3h503Bqhr p1CFRQmhh1YKZzleNYQYAO4gU7XBBmsYgndCspVVOlumeI5laCBjQBC14EqaHAH22qW2 SrOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QfJ17b00++bWuSHxnMjiXEwJtyWC6f0LPnUvtr2zO94=; b=XW0XHxXSuN07F6e395YLZzoamYstyvnEwGuqChLPFwx2d+68lmil51DRup1RVdSjSS dgceeCAdPZbPlyuYwIE32H+OmS3HkYTNTdnxPIBJsY8tx2nx54ELcPxnPytWatDUefwW 2xcHN0htWdN0GgXvtPoLNDr59Rq1/OsZoGpoMLXOVf69VFQh+Nvl6TIBne7PtBZfBMDR 8DedCOLoqKX52/IlUsccJkabWxwYWz9XKCvP9fxT+tn5WHox+gk2pFFrBR6GcQuxX9w2 ujnsvMcPoJGDkB9k1Y1h8n5A0Y57nWJ8sotx96hw9BzAq3odq0JaJB5iwu8T33KUSftU 6igQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OooNVXZq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f31si12448509jav.78.2021.08.16.07.26.44; Mon, 16 Aug 2021 07:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OooNVXZq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbhHPO0Q (ORCPT + 99 others); Mon, 16 Aug 2021 10:26:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36304 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbhHPO0Q (ORCPT ); Mon, 16 Aug 2021 10:26:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629123944; 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=QfJ17b00++bWuSHxnMjiXEwJtyWC6f0LPnUvtr2zO94=; b=OooNVXZqtHGZc9GqsZOJyONGUVVVutgpqhW5SIUUvJ03Di+h4N/cDCU77hQUUr/CjK1w8z cxtZZ0sH0o5wHXoeZI0IROTDNTiqBGmm4VWTWG0Q9C9O4s7Q7wMHUV0D0Z34D34QvQi0hL FF74zXD0SflJjl6d+J0WzCngTGji90Q= 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-232-OaNHpWQ-Mna__9B2ypxbvQ-1; Mon, 16 Aug 2021 10:25:43 -0400 X-MC-Unique: OaNHpWQ-Mna__9B2ypxbvQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A207087D549; Mon, 16 Aug 2021 14:25:41 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB7619C46; Mon, 16 Aug 2021 14:25:30 +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 v2 3/3] kernel/resource: cleanup and optimize iomem_is_exclusive() Date: Mon, 16 Aug 2021 16:25:05 +0200 Message-Id: <20210816142505.28359-4-david@redhat.com> In-Reply-To: <20210816142505.28359-1-david@redhat.com> References: <20210816142505.28359-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's clean it up a bit, reusing for_each_resource() and avoiding traversing subtrees we are not interested in. Signed-off-by: David Hildenbrand --- kernel/resource.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index f57a14617c49..7e59b57afa56 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1759,10 +1759,9 @@ static int strict_iomem_checks; */ bool iomem_is_exclusive(u64 addr) { - struct resource *p = &iomem_resource; - bool err = false; - loff_t l; + bool skip_children = false, err = false; int size = PAGE_SIZE; + struct resource *p; if (!strict_iomem_checks) return false; @@ -1770,15 +1769,19 @@ 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_each_resource(&iomem_resource, p, skip_children) { /* * We can probably skip the resources without * IORESOURCE_IO attribute? */ if (p->start >= addr + size) break; - if (p->end < addr) + if (p->end < addr) { + skip_children = true; continue; + } + skip_children = false; + /* * A resource is exclusive if IORESOURCE_EXCLUSIVE is set * or CONFIG_IO_STRICT_DEVMEM is enabled and the -- 2.31.1