From patchwork Thu Apr 6 15:14:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Tanure X-Patchwork-Id: 80322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1111737vqo; Thu, 6 Apr 2023 08:27:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YECrb8wso0s9e7nyxdcir/vCG1Ig+df/oaGQ0pg7w+x3wQNnnqo8ytCSodxerPd+HMZWR1 X-Received: by 2002:a17:906:b199:b0:92f:b8d0:746c with SMTP id w25-20020a170906b19900b0092fb8d0746cmr7295754ejy.20.1680794828718; Thu, 06 Apr 2023 08:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680794828; cv=none; d=google.com; s=arc-20160816; b=csSMIpgC1xixHKXnyNrQQ141S2M+jnDOHh7FSpEu83wqCPuM74v+zWkC2jQvoeLCCa 315zaRfNIA8562A5AorsmJNgrmVZc3gsIM1oCNSP8iT+UgzNmWUKyPG8tm7vOlmPPiJc vJbGQB8j+xz0cSFJvEhtU4CMAlw03uXlLsJnAe6QFmhNJx4ohZx8TFAHZh6u5fK/k/hX MiqvofHx4ii2G9XwzHkEJTxD/iAt1khUkAfxbvMBKUCoG9L7OJNzzzU+22xs9gHeESey u/IEs0jTTmFu08Sp6kfvlG77TX4Miqdq2WuA4YH412pHNdmeN7/S0Du19dB4gnhUfsK0 tRqQ== 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; bh=KTGfYrqfzS07zpfH0JC+lthwHQN3E94OuA9UZu3JUac=; b=KJDxfcMrgv+i78dwOFOSiQ6MfXKn+LNLMvZQBbObIk8Hh0kk4lvYRyIADwZ53nG8ki HEqCmRFvwW7i+EKejFLyEfcQ0WiZof6xmWN0quHcutcpJ4mm67E2KPPuvC4Csqvjrt8Z PI2XfHyrwm2OaeQDVkEGTYVyuL7Ixsrau0k/I9dO2ZJh4RlrY2E9AOVqDKxdjuY7BLvM AhfrWrokpiKL/H0H++D8VCLpz5jvlzBevcwNKstpZ9MKoCwUaOgV/fxsQz4slD1qCDO9 wtQjShHL3h4u7W87Lssm/rUUZwrJOnPTT6xj9CztKNsf/oxPGab9EpoCpxyLV1fdECs0 gdEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga20-20020a170906b85400b008b85ed1bbc7si1427758ejb.366.2023.04.06.08.26.44; Thu, 06 Apr 2023 08:27:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbjDFPPG (ORCPT + 99 others); Thu, 6 Apr 2023 11:15:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239726AbjDFPOt (ORCPT ); Thu, 6 Apr 2023 11:14:49 -0400 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67FA449FF; Thu, 6 Apr 2023 08:14:47 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id p34so22773574wms.3; Thu, 06 Apr 2023 08:14:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680794086; x=1683386086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KTGfYrqfzS07zpfH0JC+lthwHQN3E94OuA9UZu3JUac=; b=Q83y9iB1IJZ0G79EXIxMQMOIU9BpXDuLAjUf7pEp5b++Ovms/y1InFmGHEXQytR2GE p0QInp2rW1Gfd4q/g1PsKInyLIDBKOeCTPEym/P8Dvjkna6aj5On33YyxfiX/8sbiYDt hzOMbtAGSwk2GpGsfFr9uwPoZTrXVOl+r40IkAZfm+oKZnBvzJj7bm5RRYqEHi7GrNy+ WZVisxxRRovcdMuCRiyDVdtS/ENoj3v3+vmr3lvRkpeQY/xSaCTNabZ5EfWTKbV5AEAb 2ky8vG5Ibt2Ls69jcQPUhLTFgtykHaU74NCj2GVLBi+RDYDznzlg0YLnG5y6+rMPhzb8 38PA== X-Gm-Message-State: AAQBX9cYDWyvf/wo70LLYkoYY4Mq49ClfpRD6UM5JmvDPuKWbpOcR8E3 Rhia8c1dk2NorNOZFCZRLYE= X-Received: by 2002:a7b:c38a:0:b0:3ed:e715:1784 with SMTP id s10-20020a7bc38a000000b003ede7151784mr8689914wmj.15.1680794085640; Thu, 06 Apr 2023 08:14:45 -0700 (PDT) Received: from ryzen.lan (cpc87451-finc19-2-0-cust61.4-2.cable.virginm.net. [82.11.51.62]) by smtp.gmail.com with ESMTPSA id fj12-20020a05600c0c8c00b003ef67848a21sm5560213wmb.13.2023.04.06.08.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 08:14:45 -0700 (PDT) From: Lucas Tanure To: Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jbrunet@baylibre.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, martin.blumenstingl@googlemail.com, narmstrong@baylibre.com, stefan@agner.ch, Lucas Tanure Subject: [PATCH 1/2] memblock: Differentiate regions overlap from both regions being the same Date: Thu, 6 Apr 2023 16:14:28 +0100 Message-Id: <20230406151429.524591-2-tanure@linux.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230406151429.524591-1-tanure@linux.com> References: <20230406151429.524591-1-tanure@linux.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762441117894455759?= X-GMAIL-MSGID: =?utf-8?q?1762441117894455759?= Add support for memblock_addrs_overlap to return a different value when both regions are exactly the same region, where base and size are equal between the regions. Signed-off-by: Lucas Tanure --- include/linux/memblock.h | 18 +++++++++++++++--- mm/memblock.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..c7ba8b01a637 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -49,6 +49,18 @@ enum memblock_flags { MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ }; +/** + * enum memblock_overlap_type - result of comparison between two memory regions + * @MEMBLOCK_NO_OVERLAPS: there is no overlap between the two regions + * @MEMBLOCK_OVERLAPS: the two regions overlap each other, but are not the same + * @MEMBLOCK_EQUAL: both bases and sizes are equal, so the two regions are exactly the same + */ +enum memblock_overlap_type { + MEMBLOCK_NO_OVERLAPS, + MEMBLOCK_OVERLAPS, + MEMBLOCK_EQUAL, +}; + /** * struct memblock_region - represents a memory region * @base: base address of the region @@ -118,8 +130,8 @@ int memblock_reserve(phys_addr_t base, phys_addr_t size); int memblock_physmem_add(phys_addr_t base, phys_addr_t size); #endif void memblock_trim_memory(phys_addr_t align); -bool memblock_overlaps_region(struct memblock_type *type, - phys_addr_t base, phys_addr_t size); +unsigned int memblock_overlaps_region(struct memblock_type *type, + phys_addr_t base, phys_addr_t size); int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); @@ -486,7 +498,7 @@ bool memblock_is_memory(phys_addr_t addr); bool memblock_is_map_memory(phys_addr_t addr); bool memblock_is_region_memory(phys_addr_t base, phys_addr_t size); bool memblock_is_reserved(phys_addr_t addr); -bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); +unsigned int memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); void memblock_dump_all(void); diff --git a/mm/memblock.c b/mm/memblock.c index 25fd0626a9e7..948cc1bc3edf 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -175,24 +175,33 @@ static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size) /* * Address comparison utilities */ -static unsigned long __init_memblock memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1, - phys_addr_t base2, phys_addr_t size2) +static unsigned int __init_memblock memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1, + phys_addr_t base2, phys_addr_t size2) { - return ((base1 < (base2 + size2)) && (base2 < (base1 + size1))); + if (base1 == base2 && size1 == size2) + return MEMBLOCK_EQUAL; + + if ((base1 < (base2 + size2)) && (base2 < (base1 + size1))) + return MEMBLOCK_OVERLAPS; + + return MEMBLOCK_NO_OVERLAPS; } -bool __init_memblock memblock_overlaps_region(struct memblock_type *type, - phys_addr_t base, phys_addr_t size) +unsigned int __init_memblock memblock_overlaps_region(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) { - unsigned long i; + unsigned long i, ret; memblock_cap_size(base, &size); - for (i = 0; i < type->cnt; i++) - if (memblock_addrs_overlap(base, size, type->regions[i].base, - type->regions[i].size)) - break; - return i < type->cnt; + for (i = 0; i < type->cnt; i++) { + ret = memblock_addrs_overlap(base, size, type->regions[i].base, + type->regions[i].size); + if (ret) + return ret; + } + + return MEMBLOCK_NO_OVERLAPS; } /** @@ -1857,9 +1866,11 @@ bool __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t siz * memory block. * * Return: - * True if they intersect, false if not. + * MEMBLOCK_NO_OVERLAPS if there is no intersection, + * MEMBLOCK_OVERLAPS if they only intersect, + * MEMBLOCK_EQUAL if the region matches base and size to an reserved memory. */ -bool __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size) +unsigned int __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size) { return memblock_overlaps_region(&memblock.reserved, base, size); }