Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1656739imu; Thu, 17 Jan 2019 00:50:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN74pC2lKPS84w7gLXyAQW1ncKT9asjD4uO+kkTlkgCBxRYJ5X8yVB81HpWv46HP5khpsnH2 X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr13971041plo.194.1547715056879; Thu, 17 Jan 2019 00:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547715056; cv=none; d=google.com; s=arc-20160816; b=dl9/XFQMsAdKXnGhqbRr4bQsNMiK08n4JFqllY4Eo+cGkDH6hTGpTAGS1c/rVRvaZj PSP/irN+BZP1l7sioeV6eUeMra9sqgD5FNkpcm3sML4Z1im4ENAImvrsdfuWxz7vgFBL 3RoinNmkGIVzJhlQc4k1G0ntiExu1G1NVIHaE6Y/F4dNlgyUIjhlYegoOY9Z0qohsMEW WEIB35/tFgDxDEBCKuKWB4vxMFDjDzYNmVlKSPuQ2eIz8vOCVVVv641+WnxcCS6bNsa4 SGWLgZjFgV0OEJf7z9CJ02B56hW7XTbMlv9lhAgTqRBNr4w44oyLXk9fp/KSK5/3WuGf LEyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xXEBPjOdak8QwZkMQHeRZFRcszRz8+Nv1AwXFdIhgKg=; b=osQ0eKyiVhQVvfTEiz020yZGltMQTfswT960LDxcZSwudBEQo5YCjKt6Jm6kYmbK7i JDKAriNudK1vPPmPYaPLeqxt46j5KVvAuVmE399z5tF7u0fPgArkJQJm7bwfSzkQftaa M5JHMa6yZOv3MT7fEOgY08UjPqgWQeS4tL+fA8F5a7X/Jbl3W+sFxC6lOwdmF4JP5Num islhztrulsjLBEjAXlsYMOik+z7yuM2/iR90U7H/p6oEcQruLM4satfP5i7hXugKZU19 rkjRS1OueXhFN4pOY6wApcHW+gpfiaod17cNiJxcYJRNDOIp9DRl3QQin6Y7eRXqoxL1 F44A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si1145605plq.25.2019.01.17.00.50.41; Thu, 17 Jan 2019 00:50:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbfAQDV1 (ORCPT + 99 others); Wed, 16 Jan 2019 22:21:27 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:40675 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727772AbfAQDV0 (ORCPT ); Wed, 16 Jan 2019 22:21:26 -0500 X-IronPort-AV: E=Sophos;i="5.56,488,1539619200"; d="scan'208";a="52187350" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Jan 2019 11:21:24 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id A5A624BAD9C2; Thu, 17 Jan 2019 11:21:22 +0800 (CST) Received: from localhost.localdomain (10.167.225.56) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 17 Jan 2019 11:21:29 +0800 Date: Thu, 17 Jan 2019 11:20:27 +0800 From: Chao Fan To: Borislav Petkov CC: , , , , , , , , , Subject: Re: [PATCH v15 5/6] x86/boot: Parse SRAT address from RSDP and store immovable memory Message-ID: <20190117032027.GA31097@localhost.localdomain> References: <20190107032243.25324-1-fanc.fnst@cn.fujitsu.com> <20190107032243.25324-6-fanc.fnst@cn.fujitsu.com> <20190116110158.GC15409@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190116110158.GC15409@zn.tnic> User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [10.167.225.56] X-yoursite-MailScanner-ID: A5A624BAD9C2.AE99A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: fanc.fnst@cn.fujitsu.com X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 12:01:58PM +0100, Borislav Petkov wrote: >On Mon, Jan 07, 2019 at 11:22:42AM +0800, Chao Fan wrote: >> +void get_immovable_mem(void) >> +{ >> + struct acpi_table_header *table_header; >> + struct acpi_subtable_header *table; >> + struct acpi_srat_mem_affinity *ma; >> + char arg[MAX_ACPI_ARG_LENGTH]; >> + unsigned long table_end; >> + int i = 0; >> + >> + if (cmdline_find_option("acpi", arg, sizeof(arg)) == 3 && >> + !strncmp(arg, "off", 3)) >> + return; >> + >> + table_header = get_acpi_srat_table(); >> + if (!table_header) >> + return; >> + >> + table_end = (unsigned long)table_header + table_header->length; >> + table = (struct acpi_subtable_header *) >> + ((unsigned long)table_header + sizeof(struct acpi_table_srat)); >> + >> + while (((unsigned long)table) + >> + sizeof(struct acpi_subtable_header) < table_end) { >> + if (table->type == ACPI_SRAT_TYPE_MEMORY_AFFINITY) { >> + ma = (struct acpi_srat_mem_affinity *)table; >> + if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) { >> + immovable_mem[i].start = ma->base_address; >> + immovable_mem[i].size = ma->length; >> + i++; >> + } >> + >> + if (i >= MAX_NUMNODES*2) { >> + debug_putstr("Too many immovable memory regions, aborting.\n"); >> + return; >> + } >> + } >> + table = (struct acpi_subtable_header *) >> + ((unsigned long)table + table->length); > >That's a lot of unnecessary casting AFAICT. You can return an unsigned >long from get_acpi_srat_table() and get rid of all that casting here. > Hi Boris, I have changed as you suggested, looks clear without type cast, and we need some variable as long to calculate the address, and at same time as the struct pointer to find it's length, so I change as below, and get_acpi_srat_table() return an unsigned long. How do you think of that. int get_immovable_mem_num(void) { unsigned long table_addr, table_end, table; struct acpi_table_header *table_header; struct acpi_subtable_header *sub_table; char arg[MAX_ACPI_ARG_LENGTH]; int num = 0; if (cmdline_find_option("acpi", arg, sizeof(arg)) == 3 && !strncmp(arg, "off", 3)) return; table_addr = get_acpi_srat_table(); if (!table_addr) return; table_header = (struct acpi_table_header *)table_addr; table_end = table_addr + table_header->length; table = table_addr + sizeof(struct acpi_table_srat); while (table + sizeof(struct acpi_subtable_header) < table_end) { sub_table = (struct acpi_subtable_header *)table; if (sub_table->type == ACPI_SRAT_TYPE_MEMORY_AFFINITY) { struct acpi_srat_mem_affinity *ma; ma = (struct acpi_srat_mem_affinity *)table; if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)) { immovable_mem[num].start = ma->base_address; immovable_mem[num].size = ma->length; num++; } if (num >= MAX_NUMNODES*2) { debug_putstr("Too many immovable memory regions, aborting.\n"); return 0; } } table += sub_table->length; } return num; } Thanks, Chao Fan