Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp180888imw; Mon, 4 Jul 2022 07:18:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1udy6IsCT7xDCcbtfvL6J3Se9I7EVvmSGIeQCy27sYzdQudB2gNNvWE5VKVfvLO7Ll1/8Z1 X-Received: by 2002:a17:906:9bd1:b0:72a:5b6f:a3c8 with SMTP id de17-20020a1709069bd100b0072a5b6fa3c8mr24322611ejc.21.1656944332673; Mon, 04 Jul 2022 07:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656944332; cv=none; d=google.com; s=arc-20160816; b=xMAeHKWZavV6hV+HGgJQ5Vq0T340nllSgOgdNMCStK9jH4V0KYsulNP9B2HF/Wig3K 4gRcPQ2DqTNDeRg8ULpz4gpJwsE85RzFiY6ihmHWAQa3GwZeTUSv1jurS29VwKfcOpfU RGzC2lLHN7VVkXmfiCsGPJs67D2yjpQA8rIp9KwQeWouAQgueXjv43D4w27yKskpwIUG Xsw+EYJ9gdZdCQH00b3Tnb5SnXNchv1T4CY44lDbpOPG/fUoJuKzj1nPE2e53V/PpOQx 9EDXlMGsXbEiJRP4Wy480Zm/FJHUcq6iQ+zhL4SonlEobzDRTC5DtgmcCwi7PZHNi6Uu Q2eg== 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=PLuObBmPkIWHGGIa0YgrZ0Lq4zFfhIdvg//A8xn7ggo=; b=YAcrZIrZ2w7ifbslnSg2kudahtPxmCuZvRE41sQooDHLJ+DzpzemvCWznqWbXAVxAf tkCacgtCXvBcq+FtcY9mz2xPA6GgemJEuZj6LquZc5lYy2tuUTfpn/idPcMcpCNYj7W4 Nu+glFPcYiW1o//04u4Wq6cNebDQMzKv9q29NSEzJGPgsxQSBt2hrDRfKejiVsEaQxVF Gyk3ioDTSs4LSYHSYjYtmBvH85r6sSp/gSuJWcuVoQo1NQJYNvxhaWf+OHNQCr57C0QR JNTA9eduENFvy5qM6MRqHkQRTfvDxIonBLiBwqFUrBjqPdIKJxZsGuYKBmplxG3LG3Mm e44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=gN9JTuRL; 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 ef14-20020a05640228ce00b0043a6d0eed24si1807233edb.249.2022.07.04.07.18.26; Mon, 04 Jul 2022 07:18:52 -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=gN9JTuRL; 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 S234868AbiGDN7n (ORCPT + 99 others); Mon, 4 Jul 2022 09:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234774AbiGDN7Z (ORCPT ); Mon, 4 Jul 2022 09:59:25 -0400 Received: from mail-ua1-x933.google.com (mail-ua1-x933.google.com [IPv6:2607:f8b0:4864:20::933]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1FC3DFC4 for ; Mon, 4 Jul 2022 06:59:14 -0700 (PDT) Received: by mail-ua1-x933.google.com with SMTP id u41so1366626uau.8 for ; Mon, 04 Jul 2022 06:59:14 -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=PLuObBmPkIWHGGIa0YgrZ0Lq4zFfhIdvg//A8xn7ggo=; b=gN9JTuRL5WoxiIFiSJH2BsN3ItwrNWqzLFOY4N3NUhOsXJIwDtjxxMEHz41YepsIDP W5E6V7n5JvDJ/i5baNtKTxaK2W6aWVWX9mVibtQoRH44epoqm/m8uN5jdit9wmjVdYS8 +hdvMwPPAKccBpDl0ixE6hnJML8ORQ3KT/4DcMLEnag6hMpoBtf2VLDNqUlCMCeEImNz uwHVQaW6fsQ3nXFqvFUctCXE6YBk4kl9EDCXPRv58XWMJg+HfRVk6NzIQX7sp6cQPuJY KZMLXxpZoH/68Tlsu1k83O0hChoQL7Pyx5RKXY6wF4QbeZ3eKGDBfBcgbvElggYQeek8 lyrw== 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=PLuObBmPkIWHGGIa0YgrZ0Lq4zFfhIdvg//A8xn7ggo=; b=OWlwl0C6ndq1wq9DfUxR6yQOpE4+hO96vXtwSc1CCzMmDMAoPjWRq0lqDC1aAmrpZx YPWdc038gL+GZ2MI1VZw4023/fg53BAKGMQ9zKJJFwict3mhOq1hsrpcXZNbPBc3F9wn 1I9QZOku0ps17n+I0k8DY+7lyQQ/d8EF9pN3efdwHGVI41PQkctJQbgPmYTSEZsa8Cgl 0m58OhNjRZFstxxTR4PMLxOza7Ws1jFEg0MJZd2eqPNDTFfqBwYL3udWKMFYDyz1c3AA LiaRUlDOk8DYqTETdi36Hd/1jlmM8J/T6fxyWo8cWCr5H+6Ty38Q6RVtjVHHlh8nzYld YG8Q== X-Gm-Message-State: AJIora89xI34cNLCuF8+T7OWUY+x41U44QGx4IUeeU3iH7YNDL7/laGB 72xqivK87x9rZqpi0yBEdFmC4p1OQKWOaAOvcSG9v6aVygCynun1QEw7nYveI3xDwKrTpGsqzFH yCY5ZuyrhE7RxUjQor6LNC2Md3cUBivKO53siMhkzazMMdLlge3jXm6QeZhLpoYkX/KsE1goCbg cy1uVgvwyPEuBI6fDrj4s= X-Received: by 2002:a9f:22ac:0:b0:382:3c6c:f238 with SMTP id 41-20020a9f22ac000000b003823c6cf238mr5926773uan.123.1656943153149; Mon, 04 Jul 2022 06:59:13 -0700 (PDT) Received: from localhost ([181.97.174.128]) by smtp.gmail.com with ESMTPSA id x24-20020ab036f8000000b0038296f80d22sm723705uau.8.2022.07.04.06.59.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Jul 2022 06:59:12 -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 4/9] x86/e820: Refactor __e820__range_update Date: Mon, 4 Jul 2022 10:58:28 -0300 Message-Id: <20220704135833.1496303-5-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_update with the introduction of e820_type_updater_data, indented to be used as the void pointer in the e820_entry_updater callbacks, and the implementation of the callbacks to perform the update of the type in a range of a e820_table. Signed-off-by: Martin Fernandez --- arch/x86/kernel/e820.c | 119 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index e0fa3ab755a5..36a22c0a2199 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -586,80 +586,85 @@ __e820__handle_range_update(struct e820_table *table, return updated_size; } -static u64 __init -__e820__range_update(struct e820_table *table, u64 start, u64 size, enum e820_type old_type, enum e820_type new_type) -{ - u64 end; - unsigned int i; - u64 real_updated_size = 0; - - BUG_ON(old_type == new_type); - - if (size > (ULLONG_MAX - start)) - size = ULLONG_MAX - start; +/* + * Type helper for the e820_entry_updater callbacks. + */ +struct e820_type_updater_data { + enum e820_type old_type; + enum e820_type new_type; +}; - end = start + size; - printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1); - e820_print_type(old_type); - pr_cont(" ==> "); - e820_print_type(new_type); - pr_cont("\n"); +static bool __init type_updater__should_update(const struct e820_entry *entry, + const void *data) +{ + const struct e820_type_updater_data *type_updater_data = data; - for (i = 0; i < table->nr_entries; i++) { - struct e820_entry *entry = &table->entries[i]; - u64 final_start, final_end; - u64 entry_end; + return entry->type == type_updater_data->old_type; +} - if (entry->type != old_type) - continue; +static void __init type_updater__update(struct e820_entry *entry, + const void *data) +{ + const struct e820_type_updater_data *type_updater_data = data; - entry_end = entry->addr + entry->size; + entry->type = type_updater_data->new_type; +} - /* Completely covered by new range? */ - if (entry->addr >= start && entry_end <= end) { - entry->type = new_type; - real_updated_size += entry->size; - continue; - } +static void __init type_updater__new(struct e820_table *table, u64 new_start, + u64 new_size, + const struct e820_entry *original, + const void *data) +{ + const struct e820_type_updater_data *type_updater_data = data; - /* New range is completely covered? */ - if (entry->addr < start && entry_end > end) { - __e820__range_add(table, start, size, new_type); - __e820__range_add(table, end, entry_end - end, entry->type); - entry->size = start - entry->addr; - real_updated_size += size; - continue; - } + __e820__range_add(table, new_start, new_size, + type_updater_data->new_type); +} - /* Partially covered: */ - final_start = max(start, entry->addr); - final_end = min(end, entry_end); - if (final_start >= final_end) - continue; +static u64 __init __e820__range_update(struct e820_table *table, u64 start, + u64 size, enum e820_type old_type, + enum e820_type new_type) +{ + struct e820_entry_updater updater = { + .should_update = type_updater__should_update, + .update = type_updater__update, + .new = type_updater__new + }; - __e820__range_add(table, final_start, final_end - final_start, new_type); + struct e820_type_updater_data data = { + .old_type = old_type, + .new_type = new_type + }; - real_updated_size += final_end - final_start; + BUG_ON(old_type == new_type); - /* - * Left range could be head or tail, so need to update - * its size first: - */ - entry->size -= final_end - final_start; - if (entry->addr < final_start) - continue; + printk(KERN_DEBUG "e820: update [mem %#018Lx-%#018Lx] ", start, + start + size - 1); + e820_print_type(old_type); + pr_cont(" ==> "); + e820_print_type(new_type); + pr_cont("\n"); - entry->addr = final_end; - } - return real_updated_size; + return __e820__handle_range_update(table, start, size, &updater, &data); } -u64 __init e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type) +/* + * Update type of addresses in [@start, @start + @size) from @old_type + * to @new_type in e820_table. + */ +u64 __init e820__range_update(u64 start, u64 size, enum e820_type old_type, + enum e820_type new_type) { return __e820__range_update(e820_table, start, size, old_type, new_type); } -static u64 __init e820__range_update_kexec(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type) +/* + * Update type of addresses in [@start, @start + @size) from @old_type + * to @new_type in e820_table_kexec. + */ +static u64 __init e820__range_update_kexec(u64 start, u64 size, + enum e820_type old_type, + enum e820_type new_type) { return __e820__range_update(e820_table_kexec, start, size, old_type, new_type); } -- 2.30.2