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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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=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 9B9ECC4338F for ; Thu, 12 Aug 2021 07:07:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1AD326103E for ; Thu, 12 Aug 2021 07:07:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1AD326103E 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 86C956B006C; Thu, 12 Aug 2021 03:07:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81C916B0071; Thu, 12 Aug 2021 03:07:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E3E08D0001; Thu, 12 Aug 2021 03:07:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 52D0E6B006C for ; Thu, 12 Aug 2021 03:07:47 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F16808249980 for ; Thu, 12 Aug 2021 07:07:46 +0000 (UTC) X-FDA: 78465548532.28.5545364 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id A068B5038F68 for ; Thu, 12 Aug 2021 07:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628752066; 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=QgOG1KaHZGrp2vIMn7queyr7qSVpNW7VY1VTdadCTbg=; b=LdvzkUTiq5XQqUvuZn4KJ9VBAERgr2x+yGG3MAwVYzTFDLy1b9khYJWyS+Wdzz7w6oPhdI UIr1RW1nFPl4KGg+6ELjxfR4BdfiSWuDh7ALiGYWhYA6XntT67PyvsBJ8M34puqVEEDYpz GyJ2x0T3QWuxWCdGL54hklk8sY7dzU0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-moXdJ_HvPzmexG9ayPAwFg-1; Thu, 12 Aug 2021 03:07:44 -0400 X-MC-Unique: moXdJ_HvPzmexG9ayPAwFg-1 Received: by mail-wr1-f70.google.com with SMTP id x18-20020a5d49120000b0290154e9dcf3dbso1499365wrq.7 for ; Thu, 12 Aug 2021 00:07:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:organization:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QgOG1KaHZGrp2vIMn7queyr7qSVpNW7VY1VTdadCTbg=; b=R/aZ4wWnRf+eqPUWlpBHR0qJg7R+yGDylRNE5dKFjGDQURffQuxU64AJZlx5wFWBEp ApTvWt10Hdtq0gOK3wsu0AL+/UEi2fr+JVKrqc6z6m2rmyjBFwlCHyq0bLsuV5XVvA2m 5QNXmcrvafYLUWvDomrJUVoE9mz5whEFH+nTJl2zDJdLYZ+KRaIdtybf3Is+GGynd34A e3cmg6xpW8e7AUEhxatGJ7xftuqO0YozL0+ajlo9fuGCSy88tNGiLfccbYsPLwWnf9XM qPR699AcpFf4CYCV/09+fIVbpknoqdfutil9l3W4a/SZ3FGX0HoCN8rNtVOueKHepD8L KKIQ== X-Gm-Message-State: AOAM530tvh84gYUHSOvTe7wl/Fsa5MYYG1pU3Jmvon9k7mhOw/R7nbsm Yvs6/8AjP8xJUfRlVmMLNngSDlmpvQPukh19X6FAKW8lsMA82UNaEEHwwcaMY/+eftauhwx1jdN 95UX0Pxri5BFIWcs9NtM5Sljp/fuGDFEVG0rU4H2gnoY5hndfGxaH3uf99Tk= X-Received: by 2002:a05:600c:a08:: with SMTP id z8mr2323956wmp.52.1628752063705; Thu, 12 Aug 2021 00:07:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/dQjmzRpVnjhu2nYG+mODfNo/0E2cQXbxEhmzGgBMgSVGnSaxBpdZxfEwooDN34fMK4D4Zw== X-Received: by 2002:a05:600c:a08:: with SMTP id z8mr2323911wmp.52.1628752063241; Thu, 12 Aug 2021 00:07:43 -0700 (PDT) Received: from [192.168.3.132] (p4ff23d8b.dip0.t-ipconnect.de. [79.242.61.139]) by smtp.gmail.com with ESMTPSA id i10sm8311155wmq.21.2021.08.12.00.07.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Aug 2021 00:07:42 -0700 (PDT) To: Andy Shevchenko Cc: "linux-kernel@vger.kernel.org" , 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" References: <20210811203612.138506-1-david@redhat.com> <20210811203612.138506-4-david@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v1 3/3] kernel/resource: cleanup and optimize iomem_is_exclusive() Message-ID: <37179df3-13d7-9b98-4cd8-13bb7f735129@redhat.com> Date: Thu, 12 Aug 2021 09:07:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A068B5038F68 X-Stat-Signature: 434iit9q1x75srzzfhmpwp9faxeqfhyh Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LdvzkUTi; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.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: 1628752066-111567 Content-Transfer-Encoding: quoted-printable 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 11.08.21 22:47, Andy Shevchenko wrote: >=20 >=20 > On Wednesday, August 11, 2021, David Hildenbrand > wrote: >=20 > 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. >=20 > Signed-off-by: David Hildenbrand > > --- > =C2=A0kernel/resource.c | 19 +++++++++++-------- > =C2=A01 file changed, 11 insertions(+), 8 deletions(-) >=20 > 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; > =C2=A0 */ > =C2=A0bool iomem_is_exclusive(u64 addr) > =C2=A0{ > -=C2=A0 =C2=A0 =C2=A0 =C2=A0struct resource *p =3D &iomem_resource; > +=C2=A0 =C2=A0 =C2=A0 =C2=A0struct resource *p; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 bool err =3D false; > -=C2=A0 =C2=A0 =C2=A0 =C2=A0loff_t l; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 int size =3D PAGE_SIZE; >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!strict_iomem_checks) > @@ -1765,27 +1764,31 @@ bool iomem_is_exclusive(u64 addr) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 addr =3D addr & PAGE_MASK; >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 read_lock(&resource_lock); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0for (p =3D p->child; p ; p =3D r_next(N= ULL, p, &l)) { > +=C2=A0 =C2=A0 =C2=A0 =C2=A0for (p =3D iomem_resource.child; p ;) { >=20 Hi Andy, >=20 > I consider the ordinal part of p initialization is slightly better and=20 > done outside of read lock. >=20 > Something like > p=3D &iomem_res...; > read lock > for (p =3D p->child; ...) { Why should we care about doing that outside of the lock? That smells=20 like a micro-optimization the compiler will most probably overwrite=20 either way as the address of iomem_resource is just constant? Also, for me it's much more readable and compact if we perform a single=20 initialization instead of two separate ones in this case. We're using the pattern I use in, find_next_iomem_res() and=20 __region_intersects(), while we use the old pattern in=20 iomem_map_sanity_check(), where we also use the same unnecessary=20 r_next() call. I might just cleanup iomem_map_sanity_check() in a similar way. --=20 Thanks, David / dhildenb