Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp203792imw; Mon, 4 Jul 2022 07:45:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTewQWgYzcXRqny3fHe9MihIJOjR2P5ul0MUcpFKLC6b9v2Ea5NBGt2EcQWdUpb887SHAp X-Received: by 2002:a17:907:3f88:b0:726:a6a3:750c with SMTP id hr8-20020a1709073f8800b00726a6a3750cmr29637408ejc.142.1656945943823; Mon, 04 Jul 2022 07:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656945943; cv=none; d=google.com; s=arc-20160816; b=TyjG0GuISjDtxvmmBObM2PPJjUB0NebV99CAt3Pr7wkLAysQZer+3ODeTLfqSHAfkV 9DbYRSJMNzVPHXP/LA3AnRb5j8SVrMv9Z7rDH0phBsyD6YL9nCmf9HytMnKwuJVAeTGU kAQ7L2FvltdqzI+6ircfOFZvRzLDTBSEDWiE2u7gRYDI9VDXvkTZxjFKvRb2EYEVvQNU 3daMTIy/2mJYTya5oX4s4Y21V1+Z2tOe0MrI3h+RB/qwEAHOkt+P7etkDcZwYRPurktl QOAxh3FOK8Rzc1rT5eBkhIbvBfGQuz/m7b2FYx4aLTUZ4jxepxPZJxi/4iHdf3Hu5Ynr 2nXg== 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=rnE47zkhbqWUJCOF0oFEixfkiu1ztx/JWB/tGri5YXI=; b=awO+oyf52IaoRn6b562XixCaAAKaplPV+qsoA/UuUfAcvB7PNSZBYDbKScZEdRVSDu b1R/XfAPR9on8QGa7h0h0AIcwjrI2Dzfw+E5aUwCbDHHR9yOiw5yemuI1GBT2V/Dtkvk 4fXYi5D0Xh/7qFNncz6NtLSOdL5jRw8wIiGfvMthrlRg6MZsn7ifLHDrFUfss75IJd5m J6UKR9BeKeXulkwMWflucKUQ3mLX3Lfo3rZB1xmBbYslsmThN0RL+Ltc9qIuiK4VKyt3 A+vuj3dri3m5tKNf2uUsC8b0BNnUkqKby0Cbzi+jdBG0ZimDfTgtOtqMogZDXwfCPsCu sJBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=LPaDJYKM; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc17-20020a1709071c1100b007269dd78a15si22991619ejc.341.2022.07.04.07.45.18; Mon, 04 Jul 2022 07:45:43 -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; dkim=pass header.i=@eclypsium.com header.s=google header.b=LPaDJYKM; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234831AbiGDN7s (ORCPT + 99 others); Mon, 4 Jul 2022 09:59:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234836AbiGDN73 (ORCPT ); Mon, 4 Jul 2022 09:59:29 -0400 Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE83CE0A7 for ; Mon, 4 Jul 2022 06:59:21 -0700 (PDT) Received: by mail-vk1-xa33.google.com with SMTP id h26so4481043vkc.2 for ; Mon, 04 Jul 2022 06:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rnE47zkhbqWUJCOF0oFEixfkiu1ztx/JWB/tGri5YXI=; b=LPaDJYKM/DGiUp92Hh+jPbmInAsxrzuU0gaRNet6zG9cOie6oZ549PRb7KfPsYEAE+ HT+Z8VnJYmxAZDDADvU5oJsQTb96tcokrDSY9ESIQ/Avq4F0dqKDdRdiVdhzH5+fc+su fTZHP+JiqUbKTr5LPoZ3FJyLmgK/NTHxa0HmS1z60R9vUPkQ6YFr8wjBwHBpDiB4ndAi +oWLWmAKK3VzUR0A5KgO+mouqtrfvhrJf2JcoZdlBIohxQoLcA6EXMSTgVkgDl+MuMRv 00ZdBkTssQWwSgp7WN00hdh5KoWXbc4eMznXdDuJk4B/+n7DH9HCAl9gWwxm76WIA8a7 XkLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rnE47zkhbqWUJCOF0oFEixfkiu1ztx/JWB/tGri5YXI=; b=UIJUmQAiWqAU9oqGOQGJEH8aAW7LpnArjE5yE4gAlFfAQeOOhiz55q2UNmXYdwQLxr hyQ8N2xOT1MUCe/uHCNWVBTWZB2zXHnva2kafMDeqeUR3JSePCAGVEUSAKQY0b8QuUU0 QtQwxSAJ36IQQZwtT4r330WbOOOeUhAzLXVBZVck3yQZgvy3hSxZ8JUjVVcy6jWT3ByK NCVk/UDP0UNkKkH4WYtHge5yjiNRc6Zbd+oYUACbMOpWqJiX3Kn/G89MMp9hjlkZmBQG VQo3KfWth8MMPmoHeSNrvZXkkdkZyVlE34lDHsrDYQpJ9+uEG/xWnjbkxDOOymXJYU4Y mKvg== X-Gm-Message-State: AJIora8lGZZqMLxHWMZMVd/FWKY6q46t24QtZKxw574eB2t/6K2UFu3s UyjxjnffmESj9oEhwHcdYFH1HTuoI14pbku5AESLZIQJ2t7eYLRKvhCyT4ABSdFK7qBY7sVAJMW FYnhxIx7XxJEMk2El+V63kac9KgafwsnckjFG4kCbqpExBMn6DUguKpMaUCQFjzwuW2c8kUIZP0 7t29zR0yqVGh0K0tiO X-Received: by 2002:a05:6122:1485:b0:36c:c60b:877f with SMTP id z5-20020a056122148500b0036cc60b877fmr17367399vkp.4.1656943160742; Mon, 04 Jul 2022 06:59:20 -0700 (PDT) Received: from localhost ([181.97.174.128]) by smtp.gmail.com with ESMTPSA id w1-20020ab055c1000000b0037c965ac47fsm4564520uaa.31.2022.07.04.06.59.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Jul 2022 06:59:20 -0700 (PDT) From: Martin Fernandez To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, ardb@kernel.org, dvhart@infradead.org, andy@infradead.org, gregkh@linuxfoundation.org, rafael@kernel.org, rppt@kernel.org, akpm@linux-foundation.org, daniel.gutson@eclypsium.com, hughsient@gmail.com, alex.bazhaniuk@eclypsium.com, alison.schofield@intel.com, keescook@chromium.org, Martin Fernandez Subject: [PATCH v9 5/9] x86/e820: Refactor e820__range_remove Date: Mon, 4 Jul 2022 10:58:29 -0300 Message-Id: <20220704135833.1496303-6-martin.fernandez@eclypsium.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220704135833.1496303-1-martin.fernandez@eclypsium.com> References: <20220704135833.1496303-1-martin.fernandez@eclypsium.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Refactor e820__range_remove with the introduction of e820_remover_data, indented to be used as the void pointer in the e820_entry_updater callbacks, and the implementation of the callbacks remove a range in the e820_table. Signed-off-by: Martin Fernandez --- arch/x86/kernel/e820.c | 94 ++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 53 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 36a22c0a2199..0e5aa13ebdb8 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -669,66 +669,54 @@ static u64 __init e820__range_update_kexec(u64 start, u64 size, return __e820__range_update(e820_table_kexec, start, size, old_type, new_type); } -/* Remove a range of memory from the E820 table: */ -u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, bool check_type) -{ - int i; - u64 end; - u64 real_removed_size = 0; - - if (size > (ULLONG_MAX - start)) - size = ULLONG_MAX - start; - - end = start + size; - printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1); - if (check_type) - e820_print_type(old_type); - pr_cont("\n"); - - for (i = 0; i < e820_table->nr_entries; i++) { - struct e820_entry *entry = &e820_table->entries[i]; - u64 final_start, final_end; - u64 entry_end; - - if (check_type && entry->type != old_type) - continue; +/* + * Type helper for the e820_entry_updater callbacks. + */ +struct e820_remover_data { + enum e820_type old_type; + bool check_type; +}; - entry_end = entry->addr + entry->size; +static bool __init remover__should_update(const struct e820_entry *entry, + const void *data) +{ + const struct e820_remover_data *remover_data = data; - /* Completely covered? */ - if (entry->addr >= start && entry_end <= end) { - real_removed_size += entry->size; - memset(entry, 0, sizeof(*entry)); - continue; - } + return !remover_data->check_type || + entry->type == remover_data->old_type; +} - /* Is the new range completely covered? */ - if (entry->addr < start && entry_end > end) { - e820__range_add(end, entry_end - end, entry->type); - entry->size = start - entry->addr; - real_removed_size += size; - continue; - } +static void __init remover__update(struct e820_entry *entry, const void *data) +{ + memset(entry, 0, sizeof(*entry)); +} - /* Partially covered: */ - final_start = max(start, entry->addr); - final_end = min(end, entry_end); - if (final_start >= final_end) - continue; +/* + * Remove [@start, @start + @size) from e820_table. If @check_type is + * true remove only entries with type @old_type. + */ +u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, + bool check_type) +{ + struct e820_entry_updater updater = { + .should_update = remover__should_update, + .update = remover__update, + .new = NULL + }; - real_removed_size += final_end - final_start; + struct e820_remover_data data = { + .check_type = check_type, + .old_type = old_type + }; - /* - * Left range could be head or tail, so need to update - * the size first: - */ - entry->size -= final_end - final_start; - if (entry->addr < final_start) - continue; + printk(KERN_DEBUG "e820: remove [mem %#018Lx-%#018Lx] ", start, + start + size - 1); + if (check_type) + e820_print_type(old_type); + pr_cont("\n"); - entry->addr = final_end; - } - return real_removed_size; + return __e820__handle_range_update(e820_table, start, size, &updater, + &data); } void __init e820__update_table_print(void) -- 2.30.2