All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chen, Tiejun" <tiejun.chen@intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"jbeulich@suse.com" <jbeulich@suse.com>,
	"tim@xen.org" <tim@xen.org>,
	"andrew.cooper3@citrix.com" <andrew.cooper3@citrix.com>,
	"Zhang, Yang Z" <yang.z.zhang@intel.com>,
	"wei.liu2@citrix.com" <wei.liu2@citrix.com>,
	"ian.campbell@citrix.com" <ian.campbell@citrix.com>,
	"Ian.Jackson@eu.citrix.com" <Ian.Jackson@eu.citrix.com>,
	"stefano.stabellini@citrix.com" <stefano.stabellini@citrix.com>
Cc: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [v3][PATCH 07/16] hvmloader/pci: skip reserved ranges
Date: Fri, 12 Jun 2015 15:53:36 +0800	[thread overview]
Message-ID: <557A9000.600@intel.com> (raw)
In-Reply-To: <AADFC41AFE54684AB9EE6CBC0274A5D12628A198@SHSMSX101.ccr.corp.intel.com>

On 2015/6/11 17:51, Tian, Kevin wrote:
>> From: Chen, Tiejun
>> Sent: Thursday, June 11, 2015 9:15 AM
>>
>> When allocating mmio address for PCI bars, we need to make
>> sure they don't overlap with reserved regions.
>>
>> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
>> ---
>>   tools/firmware/hvmloader/pci.c | 36
>> ++++++++++++++++++++++++++++++++++--
>>   1 file changed, 34 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
>> index 5ff87a7..98af568 100644
>> --- a/tools/firmware/hvmloader/pci.c
>> +++ b/tools/firmware/hvmloader/pci.c
>> @@ -59,8 +59,8 @@ void pci_setup(void)
>>           uint32_t bar_reg;
>>           uint64_t bar_sz;
>>       } *bars = (struct bars *)scratch_start;
>> -    unsigned int i, nr_bars = 0;
>> -    uint64_t mmio_hole_size = 0;
>> +    unsigned int i, j, nr_bars = 0;
>> +    uint64_t mmio_hole_size = 0, reserved_end, max_bar_sz = 0;
>>
>>       const char *s;
>>       /*
>> @@ -226,6 +226,8 @@ void pci_setup(void)
>>               bars[i].devfn   = devfn;
>>               bars[i].bar_reg = bar_reg;
>>               bars[i].bar_sz  = bar_sz;
>> +            if ( bar_sz > max_bar_sz )
>> +                max_bar_sz = bar_sz;
>>
>>               if ( ((bar_data & PCI_BASE_ADDRESS_SPACE) ==
>>                     PCI_BASE_ADDRESS_SPACE_MEMORY) ||
>> @@ -301,6 +303,21 @@ void pci_setup(void)
>>               pci_mem_start <<= 1;
>>       }
>>
>> +    /* Relocate PCI memory that overlaps reserved space, like RDM. */
>> +    for ( j = 0; j < memory_map.nr_map ; j++ )
>> +    {
>> +        if ( memory_map.map[j].type != E820_RAM )
>> +        {
>> +            reserved_end = memory_map.map[j].addr + memory_map.map[j].size;
>> +            if ( check_overlap(pci_mem_start, pci_mem_end,
>> +                               memory_map.map[j].addr,
>> +                               memory_map.map[j].size) )
>> +                pci_mem_start -= memory_map.map[j].size >> PAGE_SHIFT;
>
> what's the point of subtracting reserved size here? I think you want
> to move pci_mem_start higher instead of lower to avoid conflict, right?

No.

>
>> +                pci_mem_start = (pci_mem_start + max_bar_sz - 1) &
>> +                                    ~(uint64_t)(max_bar_sz - 1);
>
> better have some comment to explain what exactly you're trying to
> achieve here.

Actually I didn't have this code fragment. Here I add this chunk of 
codes to address one concern that Jan raised. Please see the below.

>
>> +        }
>> +    }
>> +
>>       if ( mmio_total > (pci_mem_end - pci_mem_start) )
>>       {
>>           printf("Low MMIO hole not large enough for all devices,"
>> @@ -407,8 +424,23 @@ void pci_setup(void)
>>           }
>>
>>           base = (resource->base  + bar_sz - 1) & ~(uint64_t)(bar_sz - 1);
>> + reallocate_mmio:
>
> In earlier comment you said:
>
>> +    /* Relocate PCI memory that overlaps reserved space, like RDM. */
>
> If pci_mem_start has been relocated to avoid overlapping, how will actual
> allocation here will conflict again? Sorry I may miss the two relocations here...
>
>>           bar_data |= (uint32_t)base;
>>           bar_data_upper = (uint32_t)(base >> 32);
>> +        for ( j = 0; j < memory_map.nr_map ; j++ )
>> +        {
>> +            if ( memory_map.map[j].type != E820_RAM )
>> +            {
>> +                reserved_end = memory_map.map[j].addr +
>> memory_map.map[j].size;
>> +                if ( check_overlap(base, bar_sz,
>> +                                   memory_map.map[j].addr,
>> +                                   memory_map.map[j].size) )
>> +                {
>> +                    base = (reserved_end  + bar_sz - 1) & ~(uint64_t)(bar_sz - 1);
>> +                    goto reallocate_mmio;

That is because our previous implementation is just skipping that 
conflict region,

"But you do nothing to make sure the MMIO regions all fit in the
available window (see the code ahead of this relocating RAM if
necessary)." and "...it simply skips assigning resources. Your changes 
potentially growing the space needed to fit all MMIO BARs therefore also 
needs to adjust the up front calculation, such that if necessary more 
RAM can be relocated to make the hole large enough."

And then I replied as follows,

"You're right.

Just think about we're always trying to check pci_mem_start to populate 
more RAM to obtain enough PCI mempry,

     /* Relocate RAM that overlaps PCI space (in 64k-page chunks). */
     while ( (pci_mem_start >> PAGE_SHIFT) < hvm_info->low_mem_pgend )
     {
         struct xen_add_to_physmap xatp;
         unsigned int nr_pages = min_t(
             unsigned int,
             hvm_info->low_mem_pgend - (pci_mem_start >> PAGE_SHIFT),
             (1u << 16) - 1);
         if ( hvm_info->high_mem_pgend == 0 )
             hvm_info->high_mem_pgend = 1ull << (32 - PAGE_SHIFT);
         hvm_info->low_mem_pgend -= nr_pages;
         printf("Relocating 0x%x pages from "PRIllx" to "PRIllx\
                " for lowmem MMIO hole\n",
                nr_pages,
                PRIllx_arg(((uint64_t)hvm_info->low_mem_pgend)<<PAGE_SHIFT),

PRIllx_arg(((uint64_t)hvm_info->high_mem_pgend)<<PAGE_SHIFT));
         xatp.domid = DOMID_SELF;
         xatp.space = XENMAPSPACE_gmfn_range;
         xatp.idx   = hvm_info->low_mem_pgend;
         xatp.gpfn  = hvm_info->high_mem_pgend;
         xatp.size  = nr_pages;
         if ( hypercall_memory_op(XENMEM_add_to_physmap, &xatp) != 0 )
             BUG();
         hvm_info->high_mem_pgend += nr_pages;
     }
"

I hope this can help you understand this background. And I will update 
that code comment like this,

     /*
      * We'll skip all space overlapping with reserved memory later,
      * so we need to decrease pci_mem_start to populate more RAM
      * to compensate them.
      */

Thanks
Tiejun

>> +                }
>> +            }
>> +        }
>>           base += bar_sz;
>>
>>           if ( (base < resource->base) || (base > resource->max) )
>> --
>> 1.9.1
>
>
>

  reply	other threads:[~2015-06-12  7:53 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11  1:15 [v3][PATCH 00/16] Fix RMRR Tiejun Chen
2015-06-11  1:15 ` [v3][PATCH 01/16] xen: introduce XENMEM_reserved_device_memory_map Tiejun Chen
2015-06-11  8:56   ` Tian, Kevin
2015-06-11  1:15 ` [v3][PATCH 02/16] xen/x86/p2m: introduce set_identity_p2m_entry Tiejun Chen
2015-06-11  7:33   ` Jan Beulich
2015-06-11  8:23     ` Chen, Tiejun
2015-06-11  9:23       ` Jan Beulich
2015-06-11  9:25         ` Chen, Tiejun
2015-06-11  9:00   ` Tian, Kevin
2015-06-11  9:18     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 03/16] xen/vtd: create RMRR mapping Tiejun Chen
2015-06-11  9:14   ` Tian, Kevin
2015-06-11  9:31     ` Chen, Tiejun
2015-06-11 14:07       ` Tim Deegan
2015-06-12  2:43         ` Chen, Tiejun
2015-06-12  5:58           ` Chen, Tiejun
2015-06-12  5:59             ` Tian, Kevin
2015-06-12  6:13               ` Chen, Tiejun
2015-06-18 10:07                 ` Tim Deegan
2015-06-19  0:37                   ` Chen, Tiejun
2015-06-17 10:03   ` Jan Beulich
2015-06-18  6:23     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 04/16] xen/passthrough: extend hypercall to support rdm reservation policy Tiejun Chen
2015-06-11  9:28   ` Tian, Kevin
2015-06-12  6:31     ` Chen, Tiejun
2015-06-12  8:45       ` Jan Beulich
2015-06-12  9:20         ` Chen, Tiejun
2015-06-12  9:26           ` Jan Beulich
2015-06-15  7:39           ` Chen, Tiejun
2015-06-16  2:30       ` Tian, Kevin
2015-06-17 10:11   ` Jan Beulich
2015-06-18  7:14     ` Chen, Tiejun
2015-06-18  7:53       ` Jan Beulich
2015-06-18  8:48         ` Chen, Tiejun
2015-06-18  9:13           ` Jan Beulich
2015-06-18  9:31             ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 05/16] xen: enable XENMEM_memory_map in hvm Tiejun Chen
2015-06-11  9:29   ` Tian, Kevin
2015-06-17 10:14   ` Jan Beulich
2015-06-18  8:53     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 06/16] hvmloader: get guest memory map into memory_map[] Tiejun Chen
2015-06-11  9:38   ` Tian, Kevin
2015-06-12  7:33     ` Chen, Tiejun
2015-06-17 10:22   ` Jan Beulich
2015-06-18  9:13     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 07/16] hvmloader/pci: skip reserved ranges Tiejun Chen
2015-06-11  9:51   ` Tian, Kevin
2015-06-12  7:53     ` Chen, Tiejun [this message]
2015-06-16  5:47       ` Tian, Kevin
2015-06-16  9:29         ` Chen, Tiejun
2015-06-16  9:40           ` Jan Beulich
2015-06-17  7:10             ` Chen, Tiejun
2015-06-17  7:19               ` Jan Beulich
2015-06-17  7:54                 ` Chen, Tiejun
2015-06-17  8:05                   ` Jan Beulich
2015-06-17  8:26                     ` Chen, Tiejun
2015-06-17  8:47                       ` Chen, Tiejun
2015-06-17  9:02                       ` Jan Beulich
2015-06-17  9:18                         ` Chen, Tiejun
2015-06-17  9:24                           ` Jan Beulich
2015-06-18  6:17                             ` Chen, Tiejun
2015-06-18  6:29                               ` Jan Beulich
2015-06-18  7:01                                 ` Chen, Tiejun
2015-06-18  8:05                                   ` Jan Beulich
2015-06-19  2:02                                     ` Chen, Tiejun
2015-06-23  9:46                                       ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 08/16] hvmloader/e820: construct guest e820 table Tiejun Chen
2015-06-11  9:59   ` Tian, Kevin
2015-06-12  8:19     ` Chen, Tiejun
2015-06-16  5:54       ` Tian, Kevin
2015-06-11  1:15 ` [v3][PATCH 09/16] tools/libxc: Expose new hypercall xc_reserved_device_memory_map Tiejun Chen
2015-06-11 10:00   ` Tian, Kevin
2015-06-11  1:15 ` [v3][PATCH 10/16] tools: extend xc_assign_device() to support rdm reservation policy Tiejun Chen
2015-06-11 10:02   ` Tian, Kevin
2015-06-12  8:25     ` Chen, Tiejun
2015-06-16  2:28       ` Tian, Kevin
2015-06-12 15:43   ` Wei Liu
2015-06-15  1:12     ` Chen, Tiejun
2015-06-15 14:58       ` Wei Liu
2015-06-16  2:31         ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 11/16] tools: introduce some new parameters to set rdm policy Tiejun Chen
2015-06-12 16:02   ` Wei Liu
2015-06-15  1:19     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 12/16] tools/libxl: passes rdm reservation policy Tiejun Chen
2015-06-12 16:17   ` Wei Liu
2015-06-15  1:26     ` Chen, Tiejun
2015-06-15 15:00       ` Wei Liu
2015-06-11  1:15 ` [v3][PATCH 13/16] tools/libxl: detect and avoid conflicts with RDM Tiejun Chen
2015-06-11 10:19   ` Tian, Kevin
2015-06-12  8:30     ` Chen, Tiejun
2015-06-12 16:39   ` Wei Liu
2015-06-15  1:50     ` Chen, Tiejun
2015-06-15 15:01       ` Wei Liu
2015-06-16  1:44         ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 14/16] tools/libxl: extend XENMEM_set_memory_map Tiejun Chen
2015-06-12 16:43   ` Wei Liu
2015-06-15  2:15     ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 15/16] xen/vtd: enable USB device assignment Tiejun Chen
2015-06-11 10:22   ` Tian, Kevin
2015-06-12  8:59     ` Chen, Tiejun
2015-06-16  5:58       ` Tian, Kevin
2015-06-16  6:09         ` Chen, Tiejun
2015-06-11  1:15 ` [v3][PATCH 16/16] xen/vtd: prevent from assign the device with shared rmrr Tiejun Chen
2015-06-11 10:25   ` Tian, Kevin
2015-06-12  8:44     ` Chen, Tiejun
2015-06-17 10:28   ` Jan Beulich
2015-06-18  9:23     ` Chen, Tiejun
2015-06-11  7:27 ` [v3][PATCH 00/16] Fix RMRR Jan Beulich
2015-06-11  8:42   ` Tian, Kevin
2015-06-11  9:06     ` Chen, Tiejun
2015-06-11 12:52 ` Tim Deegan
2015-06-12  2:10   ` Chen, Tiejun
2015-06-12  8:04     ` Jan Beulich
2015-06-12  8:20       ` Chen, Tiejun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=557A9000.600@intel.com \
    --to=tiejun.chen@intel.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yang.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.