[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH] x86/NUMA: correct off-by-1 in node map size calculation


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <Wei.Chen@xxxxxxx>
  • Date: Fri, 30 Sep 2022 02:03:04 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YUIrSkDojgIsAMGB4NZOMta2ZWq8pre8E8cSdPjMHLU=; b=j+4Oiml/TLIygP+R1W8n6ZHVmrLfT8dYStpLNzogzM8PJIlZ0zHguQ9i9BTMXRuQ8aaVHtbrhgMSRpGi+KYHS3WsGO4P+IUgn30H0rBSQGg5C5rr+V7iEJCL081PJi55TJ3/QT6XhJIVbMXY7glxckHce7vYXi2/hRJjsIasqtOR0mHxSbiVN2pWvi0Dr3Ohz/g7xFfZuzitemVBFBXlI7C5hMKReW7nMG3nxo5NAiuH1St4/6sPwQ9LDq42D6Vw7Qm5oNjmRg2f1f3LjYdHnYRMq+6XcotThEdd0qr6nVyo3emsb/tpI1bUvPKbwfNWR0KUfIYdYyTPkegKDTtiPg==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YUIrSkDojgIsAMGB4NZOMta2ZWq8pre8E8cSdPjMHLU=; b=VfBBte5k7PCoy5ZIsIqGa22gWvPG3XL0P7+tO2TUoCuJDEHbX4D9o8On3+t1PpSyidpLsgpQkgQPpHPS7Kuy6J6jm0tXCz6EdQA6Rk53o3TivkAnsdrPw9qm0/iusBJmFkzm2DYsDL4PtOBKuZo+z11q+rDeB7QU5PpS0Q+L9+Jp7LKeK+DseAhp8WNnH3BU1JzIOGPDRhn3+8SIV1sj8AOv7+8PelIr+qL1I/0W+4/AV0RD1+P13DYXLr9ArNYbmiicZmqsyvAKr3vdTfkz2tD6uP1W7YGkoNEzUWzBQJVTSPQBPPl0p6PLBGJtzDjZhqDVm1kEB+QJ8fOwev4KmQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=KGTYM85lprnTuWLTQqCEVCC5nHoZbK/w6pAyA2O8AG/xKo3I2qryJA6purGSAiG/4eyJp6+kIlCpggAgRPrFZk4IlIAiEn+Z+ALgw/nfqECadZgjt1e+brRw3p662q6bKVoyVyfpVA0K9w+H3lpFZ5es5iTPstHTsM5Q8g9O9VVRQInAv4CbYEzWNGwlnwgcOu44mccrUvm/CVwLC4wDiweaqZlx5XrRrg4eKRNplmSvbGba6PyyEB30WoDvybD3LfmUkAWyBJug8VZNn11fSj4Txp4tRwXg/UBzs/wIjZieVIuOg0BPzCYK0snuCx37HeKeUdUr7CuimpMG/e4NLQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LthxgXcQbw5QHZvE10jFllByKjwJfQXh9/lCU4Md7F95pB+BnpjlT7Fka94BRYlIBpe5FSDLb3Ran8inr1VBM/PDyzVWwhXFCq/BgN/ViXpTJtHwmabTc4pgbCW9Y8a4fHOcOMAUHOwk2qXjxJ6YiD1YSDcvQmoQOlK+ZfJVVn4amXWfRJNNjei7QVW53f/bFBIY4x4aFRXosPuvNV2mvd5S/EIU0xeuXWoCcy5eewgZYajr0BN4SpSwUt7TnWXks7c8bXkiQOMvSmC+KLx1NnDkbRGTCvNv9yPjsjwBxd+JDom8jBGBYdiZwSbUgBmBZLiR7W4hAor4RBP1m90Adw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Fri, 30 Sep 2022 02:03:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHY0nuHFsNZDqjVQEGO++a4qSB4Ua33PGOQ
  • Thread-topic: [PATCH] x86/NUMA: correct off-by-1 in node map size calculation

Hi Jan,

> -----Original Message-----
> From: Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx> On Behalf Of Jan
> Beulich
> Sent: 2022年9月27日 22:14
> To: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>; Wei Liu <wl@xxxxxxx>; Roger
> Pau Monné <roger.pau@xxxxxxxxxx>
> Subject: [PATCH] x86/NUMA: correct off-by-1 in node map size calculation
> 
> extract_lsb_from_nodes() accumulates "memtop" from all PDXes one past
> the covered ranges. Hence the maximum address which can validly by used
> to index the node map is one below this value, and we may currently set
> up a node map with an unused (and never initialized) trailing entry. In
> boundary cases this may also mean we dynamically allocate a page when
> the static (64-entry) map would suffice.
> 
> While there also correct the comment ahead of the function, for it to
> match the actual code: Linux commit 54413927f022 ("x86-64:
> x86_64-make-the-numa-hash-function-nodemap-allocation fix fix") removed
> the ORing in of the end address before we actually cloned their code.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> Really the shift value may end up needlessly small when there's
> discontiguous memory. Within a gap, any address can be taken for the
> node boundary, and hence neither the end of the lower range nor the
> start of the higher range necessarily is the best address to use. For
> example with these two node ranges (numbers are frame addresses)
> 
> [10000,17fff]
> [28000,2ffff]
> 
> we'd calculate the shift as 15 when 16 or even 17 (because the start of
> the 1st range can also be ignored) would do. I haven't tried to properly
> prove it yet, but it looks to me as if the top bit of the XOR of lower
> range (inclusive) end and higher range start would be what would want
> accumulating (of course requiring the entries to be sorted, or to be
> processed in address order). This would then "naturally" exclude lowest
> range start and highest range end.
> 
> --- a/xen/arch/x86/numa.c
> +++ b/xen/arch/x86/numa.c
> @@ -110,7 +110,7 @@ static int __init allocate_cachealigned_
>  }
> 
>  /*
> - * The LSB of all start and end addresses in the node map is the value of
> the
> + * The LSB of all start addresses in the node map is the value of the
>   * maximum possible shift.
>   */
>  static int __init extract_lsb_from_nodes(const struct node *nodes,
> @@ -135,7 +135,7 @@ static int __init extract_lsb_from_nodes
>          i = BITS_PER_LONG - 1;
>      else
>          i = find_first_bit(&bitfield, sizeof(unsigned long)*8);
> -    memnodemapsize = (memtop >> i) + 1;
> +    memnodemapsize = ((memtop - 1) >> i) + 1;
>      return i;
>  }
> 

Thanks for this fix.

Reviewed-by: Wei Chen <Wei.Chen@xxxxxxx>


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.