Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5857007ioo; Wed, 1 Jun 2022 14:14:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNbY2PWZMrA+T1vUeOuClm5HpGP2GFi/NPox0ds4g4rv9SM2VEM2cNEVP5rdc3uWtP06Oh X-Received: by 2002:a17:90a:5a48:b0:1e3:4180:a218 with SMTP id m8-20020a17090a5a4800b001e34180a218mr10155339pji.182.1654118062108; Wed, 01 Jun 2022 14:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654118062; cv=none; d=google.com; s=arc-20160816; b=Q2wzptNWUgsVp8IcP7vqSaCI7oFrGaa9OKCJaomt1Ps1T0Y1gmRZ06jOfyYx9eZLe+ hmbYqYDxZhbF9ybMLYi/xutgPSgJmW3F/Plo/WJyPpgeRZnRwGIvgnQ7AO67B6aVWWJv SZVDXAt4pXoKhSJ1rOlYHRdmyxsKsdqXHpgVNpkGcoEytckgT1NAfrvYHGN9vLyXkCCe qD+FkxNz+N1lIQ/3HxiBymp6oAdnXn//ehK48rxAepywf4aOX7UstgULcgbik8KsnjSD L0oIOMWhETRMEUKnZ/t5qAxj0tMT+abD5Tvg29rCnstXxH4YNLiblvmin5DnH9kQRBrH WnCg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=7vE2Qwr7p4el325+n6Yzgeqvi+thJCao+cwF1Iqhjng=; b=rA4F+WBi0YTFBNV7e6D2aY3clq2GkwMGXQxQBYapDIEtplSxVUcXe41lBbMisv7QOV 1kzITmbYlgZP9yCZ69wyZ0UQ48umcwvjbpWGnTXHoLMCglQFgithLInUWHCWRa/iFkb7 yFr6NiNmGrILiIMXLGNRkgNB/xvRvkukbM96s1Cfc2QGO3NpJCtRq8tvcs5s/hR7dIVA UjJvwMEY0ygV1iUt8a2aBP9hXqDAZ0/xyNr7G8PwOP9XVyhmyqn15ePhudJxwbk9VeGB KKMCBUWwK2ODTqZdfCM9Zu+TKss4kE25q2W1z7HBAtGYn6vXv6F4xvQJ+nuX/PT6Fckg UPMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=oLZ0Gkz7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i11-20020a63130b000000b003fc7efc3f5fsi4286826pgl.194.2022.06.01.14.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:14:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=oLZ0Gkz7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43DBC224D3E; Wed, 1 Jun 2022 13:05:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354965AbiFAQdX (ORCPT + 99 others); Wed, 1 Jun 2022 12:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350575AbiFAQdV (ORCPT ); Wed, 1 Jun 2022 12:33:21 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B38059B85 for ; Wed, 1 Jun 2022 09:33:20 -0700 (PDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 251Ftn2C012580; Wed, 1 Jun 2022 16:33:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=7vE2Qwr7p4el325+n6Yzgeqvi+thJCao+cwF1Iqhjng=; b=oLZ0Gkz7B+ZHfFMY7xcLjHYGMUDxEt3mCGmZ50duteQ7s7h9lFUAyrbCyB7NjGdM6T6N I8b3bMTJ6d7OjseeSwqrejDzJvXm6spIYpr604hPNIVMX8ZALffFSacxOlCaF2mv2Wgy FaPtzRceVxbDZA2VxOsd/eSbWZx7ur8LsoekAxa0DHc7PgGV+mQqpmNMWAMPC6Qg9i1J GNR6+/GeL0cOFOPramivNVmtIzKtSbfCOk4zkty1S9KuV4ERnngKP3fIZYwHuk5LP5M7 30NAyvSKaUe67NJ0UCZdvUFJU27cmZUxSdh2mxqJIebnZ+izfFFn1n87i1ptazlDA+m6 2w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3ge9djbx6p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jun 2022 16:33:05 +0000 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 251FYcYj014394; Wed, 1 Jun 2022 16:33:05 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3ge9djbx5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jun 2022 16:33:05 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 251G7Z50025471; Wed, 1 Jun 2022 16:33:03 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3gbcae5v7w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jun 2022 16:33:03 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 251GWxl644761414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Jun 2022 16:32:59 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC90842047; Wed, 1 Jun 2022 16:32:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DB184203F; Wed, 1 Jun 2022 16:32:56 +0000 (GMT) Received: from vajain21.in.ibm.com (unknown [9.43.94.137]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 1 Jun 2022 16:32:55 +0000 (GMT) Received: by vajain21.in.ibm.com (sSMTP sendmail emulation); Wed, 01 Jun 2022 22:02:54 +0530 From: Vaibhav Jain To: linux-kernel@vger.kernel.org Cc: Vaibhav Jain , "Aneesh Kumar K . V" , Andrew Morton , David Hildenbrand , Dan Williams , Miaohe Lin , Muchun Song Subject: [PATCH] resource: re-factor page_is_ram() Date: Wed, 1 Jun 2022 22:02:43 +0530 Message-Id: <20220601163243.3806231-1-vaibhav@linux.ibm.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KOLdGCwCmzhxQ9tw99YTmfyN9rUA2-XT X-Proofpoint-GUID: HLf-KffkVr4JaTrfWUaQNbklY0TRzOk5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-01_05,2022-06-01_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 clxscore=1011 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206010072 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Presently page_is_ram() relies on walk_system_ram_range() that performs a walk on kernel iomem resources hierarchy with a dummy callback __is_ram(). Before calling find_next_iomem_res(), walk_system_ram_range() does some book-keeping which can be avoided for page_is_ram() use-case. Hence this patch proposes to update page_is_ram() to directly call find_next_iomem_res() with minimal book-keeping needed. To avoid allocating a 'struct resource' the patch also updates find_next_iomem_res() to not return -EINVAL in case 'res == NULL'. Instead out 'struct resource *res' is only populated when its not NULL. Signed-off-by: Vaibhav Jain --- kernel/resource.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 34eaee179689..ecf6b9a50adc 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -311,7 +311,7 @@ EXPORT_SYMBOL(release_resource); * * If a resource is found, returns 0 and @*res is overwritten with the part * of the resource that's within [@start..@end]; if none is found, returns - * -ENODEV. Returns -EINVAL for invalid parameters. + * -ENODEV. * * @start: start address of the resource searched for * @end: end address of same resource @@ -328,9 +328,6 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, { struct resource *p; - if (!res) - return -EINVAL; - if (start >= end) return -EINVAL; @@ -356,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, break; } - if (p) { + if (p && res) { /* copy data */ *res = (struct resource) { .start = max(start, p->start), @@ -474,18 +471,18 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, return ret; } -static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg) -{ - return 1; -} - /* * This generic page_is_ram() returns true if specified address is * registered as System RAM in iomem_resource list. */ int __weak page_is_ram(unsigned long pfn) { - return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; + const resource_size_t pfn_res = PFN_PHYS(pfn); + + return find_next_iomem_res(pfn_res, + pfn_res + 1, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + IORES_DESC_NONE, NULL) == 0; } EXPORT_SYMBOL_GPL(page_is_ram); -- 2.35.3