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

RE: [PATCH v3 4/6] xen/x86: use arch_get_ram_range to get information from E820 map


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Wei Chen <Wei.Chen@xxxxxxx>
  • Date: Mon, 29 Aug 2022 10:17:38 +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=jRNhH2fkOYjz9s/JKS8HNghlnSDdFFVSgBW+uGA9CIQ=; b=e8YYD/6bLBh7KT+88AQAZ543CwpOZu9KfQq/b1mSph0CCguPz/mZP60zUQUzGOgCHwWdx5wiO/ryrLxGen9H3eMqFdtqwFdahqgmwU5XaaXliWC8JkhfpBBTG1+gXS8UcKCbE1j/K+2MJX4RX2UD8y5bQaWvjwsW4a7WDian8aj6M17PDwKvnemu5Zg5pNmgbQfclsHBLlQqtOD3IF5gn5VLiCxdobtZomTB1XQ9yxT86S8GNddNfJS8b6V8xbgVpitTQnjCEtE0T82C/TAbXvebZ8sSfcNyTI/DPoGbp78qTDKrHBaseTkxNW4ysC7+lBNcTX9CtGPo/mQ36cOEHQ==
  • 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=jRNhH2fkOYjz9s/JKS8HNghlnSDdFFVSgBW+uGA9CIQ=; b=fmqNPg2mzA83JXpiNf6Hgx6mhiMZ3Mf/LOVeTf5gS9hR6wrF5+xdjXQQTxWY6O/retseVbhNjFxVHX83EHZMBPQHkJM7VQ2tKB9wwewtt4G4ejAnxWY2SL5hENhqhZ4PRM5twsqv17ncO5qoQ56LM3+JBT3vLEHk8mnm7CXvQCpnkrc08Vfmk0QG/EABjtMCv51mXeS8GdeqYuXRcExFRqF7YbZSsh+JaJ7wcC9GqyDPXy6kwf8qK4pVjW1NWuj43rlIcavnm+YEjn2BBGzd3Ujf1a9B6xRbUjFLTXqWFb5Ju2sRnZMkFC6nwjnIzqaakMsySbXDGj0/673FUQx0tA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=TZ3y35cUnluUotDOeVoo0qmhyLCfvJEIGaDsubu5pH5hHifTejJpVnXEMAnw52HpLXmYz5DlDRCUr3E7LziZQD6QPTAKVXK6BTnQMVqC8PgcnfD1ZmsGElrPcNyixhCk0FEfyCTQ/Dd1FrMlVucs9Cpgvl2pqeofRt1+zIA1m2fYdWm45qt83s0EA4iKgerEorcth+zFhIvZdnTIgyeXje8ht1Mea9KLRj4SwnfCr8kbPLHlygxR2jOzaw/ndWk7CWM6VrZU3R6C/+6OPa6P/ZeNNc+Vz2nyEC2VTGBHTDMsK7oGxY3V9F33zGWS9mX85+ULZbn6HnDRnQvNOGIdbg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1z/ip4LnaRWjkG8P9Nd1S4bmbXgBxrV9ZFQ8pD60D8HU3X1rdKUzK/wgSt/3836FRTfGWmmFpztuBEpD70C6peVe+QmOuA3kzjNCrUq3vql1bcblReaFl06QC3sHtqev6I8FNpVEEfZAv18TRY720D2hsnK6Df8Py6XByO/k8hPBbvkT5GaivTm7QaODhN9lvzlKEMb9ijGo7u15CCbbqzauutLP5zY5AAAPlF0DWugGaRQJewysGSUQx5FWZ107TLreyTI7Xy2lS/l3MomK9flb5MNga1cyBCpaIWJNey+t8MHx+xXnmACnVpnvmUqLfwEnNPdPXqTsfk4rmz9zg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: nd <nd@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 29 Aug 2022 10:18:05 +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: AQHYtdMz1vGBusPHbkWa5f3aYmkHna2/jMQAgAYiKbA=
  • Thread-topic: [PATCH v3 4/6] xen/x86: use arch_get_ram_range to get information from E820 map

Hi Jan,

> -----Original Message-----
> From: Jan Beulich <jbeulich@xxxxxxxx>
> Sent: 2022年8月25日 20:14
> To: Wei Chen <Wei.Chen@xxxxxxx>
> Cc: nd <nd@xxxxxxx>; Andrew Cooper <andrew.cooper3@xxxxxxxxxx>; Roger Pau
> Monné <roger.pau@xxxxxxxxxx>; Wei Liu <wl@xxxxxxx>; George Dunlap
> <george.dunlap@xxxxxxxxxx>; Julien Grall <julien@xxxxxxx>; Stefano
> Stabellini <sstabellini@xxxxxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx
> Subject: Re: [PATCH v3 4/6] xen/x86: use arch_get_ram_range to get
> information from E820 map
> 
> On 22.08.2022 04:58, Wei Chen wrote:
> > @@ -96,3 +97,27 @@ unsigned int __init arch_get_dma_bitsize(void)
> >                   flsl(node_start_pfn(node) + node_spanned_pages(node) /
> 4 - 1)
> >                   + PAGE_SHIFT, 32);
> >  }
> > +
> > +/*
> > + * This function provides the ability for caller to get one RAM entry
> > + * from architectural memory map by index.
> > + *
> > + * This function will return zero if it can return a proper RAM entry.
> > + * otherwise it will return -ENOENT for out of scope index, or return
> > + * -EINVAL for non-RAM type memory entry.
> > + *
> > + * Note: the range is exclusive at the end, e.g. [start, end).
> > + */
> > +int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t
> *end)
> 
> Since the comment is intended to apply to all architectures providing,
> I think it should go with the declaration (once) rather than the
> definition (at least one instance per arch).
> 

Ok, I will move the comment to header file.

> > +{
> > +    if ( idx >= e820.nr_map )
> > +        return -ENOENT;
> > +
> > +    if ( e820.map[idx].type != E820_RAM )
> > +        return -EINVAL;
> 
> EINVAL is so heavily (over)loaded that I'm inclined to ask to use e.g.
> -ENODATA here.
> 

Ok.

> > --- a/xen/arch/x86/srat.c
> > +++ b/xen/arch/x86/srat.c
> > @@ -428,18 +428,22 @@ acpi_numa_memory_affinity_init(const struct
> acpi_srat_mem_affinity *ma)
> >     Make sure the PXMs cover all memory. */
> >  static int __init nodes_cover_memory(void)
> >  {
> > -   int i;
> > +   unsigned int i;
> >
> > -   for (i = 0; i < e820.nr_map; i++) {
> > +   for (i = 0; ; i++) {
> >             int j, found;
> >             paddr_t start, end;
> >
> > -           if (e820.map[i].type != E820_RAM) {
> > +           /* Try to loop memory map from index 0 to end to get RAM
> ranges. */
> > +           found = arch_get_ram_range(i, &start, &end);
> > +
> > +           /* Index relate entry is not RAM, skip it. */
> > +           if (found == -EINVAL)
> >                     continue;
> > -           }
> >
> > -           start = e820.map[i].addr;
> > -           end = e820.map[i].addr + e820.map[i].size;
> > +           /* Reach the end of arch's memory map */
> > +           if (found == -ENOENT)
> > +                   break;
> 
> What if an arch returns a 3rd error indicator? The way you've written
> it code below would assume success and use uninitialized data. I'd
> like to suggest to only special-case -ENOENT and treat all other

Yes, I hadn't taken the 3rd error case into account. I will follow your
Comment in next version.

> errors the same. But of course the variable (re)used doesn't really
> fit that:
> 
>               /* Reach the end of arch's memory map */
>               if (found == -ENOENT)
>                       break;
> 
>               /* Index relate entry is not RAM, skip it. */
>               if (found)
>                       continue;
> 
> because here really you mean "not found". Since in fact "found" would
> want to be of "bool" type in the function, and "j" would want to be
> "unsigned int" just like "i" is, I recommend introducing a new local
> variable, e.g. "err".
> 

Ok.

Cheers,
Wei Chen

> Jan
> 
> >             do {
> >                     found = 0;

 


Rackspace

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