From: Jacob Shin <jacob.shin@amd.com>
To: Tejun Heo <tj@kernel.org>
Cc: X86-ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Yinghai Lu <yinghai@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Andreas Herrmann <andreas.herrmann3@amd.com>
Subject: Re: [PATCH 1/5] x86: Only direct map addresses that are marked as E820_RAM
Date: Mon, 13 Aug 2012 09:31:59 -0500 [thread overview]
Message-ID: <20120813143159.GB8441@jshin-Toonie> (raw)
In-Reply-To: <20120811194948.GC2874@dhcp-172-17-108-109.mtv.corp.google.com>
On Sat, Aug 11, 2012 at 12:49:48PM -0700, Tejun Heo wrote:
> Hello, Jacob.
Hi,
>
> On Thu, Aug 09, 2012 at 04:23:05PM -0500, Jacob Shin wrote:
> > +struct range pfn_mapped[E820_X_MAX];
> > +int nr_pfn_mapped;
>
> Why aren't these __initdata? Are they gonna be used for other
> purposes?
Yes, the thought was that later code may want to know what pfns are direct
mapped or not. For example, memory hotplug has to call init_memory_mapping and
updates direct mapping.
>
> > +void add_pfn_range_mapped(unsigned long start_pfn, unsigned long end_pfn)
> > +{
> > + nr_pfn_mapped = add_range_with_merge(pfn_mapped, E820_X_MAX,
> > + nr_pfn_mapped, start_pfn, end_pfn);
> > +
> > + if (end_pfn > max_pfn_mapped)
> > + max_pfn_mapped = end_pfn;
>
> Maybe use max()?
Okay,
>
> > + if ((end_pfn <= (1UL << (32 - PAGE_SHIFT))) &&
> > + (end_pfn > max_low_pfn_mapped))
> > + max_low_pfn_mapped = end_pfn;
> > +}
> > +
> > +int pfn_range_is_mapped(unsigned long start_pfn, unsigned long end_pfn)
>
> bool?
Okay, will change to bool.
>
> > +{
> > + int i;
> > +
> > + for (i = 0; i < nr_pfn_mapped; i++)
> > + if ((start_pfn >= pfn_mapped[i].start) &&
> > + (end_pfn <= pfn_mapped[i].end))
> > + break;
> > +
> > + return i < nr_pfn_mapped;
> > +}
>
> for (...)
> if (xxx)
> return true;
> return false;
>
> > +int pfn_is_mapped(unsigned long pfn)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < nr_pfn_mapped; i++)
> > + if ((pfn >= pfn_mapped[i].start) &&
> > + (pfn < pfn_mapped[i].end))
> > + break;
> > +
> > + return i < nr_pfn_mapped;
> > +}
>
> How about...
>
> return pfn_range_is_mapped(pfn, pfn + 1);
Okay,
>
> > @@ -913,14 +958,40 @@ void __init setup_arch(char **cmdline_p)
> >
> > init_gbpages();
> >
> > - /* max_pfn_mapped is updated here */
> > - max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
> > - max_pfn_mapped = max_low_pfn_mapped;
> > + init_pfn = max_pfn_mapped;
> > +
> > + memset(pfn_mapped, 0, sizeof(pfn_mapped));
> > + nr_pfn_mapped = 0;
>
> Are these necessary? We clear .bss way before control reaches here.
Ah okay, I'll remove them, and test to double check.
>
> > +
> > + add_pfn_range_mapped(0, max_pfn_mapped);
> > +
> > + for (i = 0; i < e820.nr_map; i++) {
> > + struct e820entry *ei = &e820.map[i];
> > + u64 start = ei->addr;
> > + u64 end = ei->addr + ei->size;
> > +
> > + if (ei->type != E820_RAM)
> > + continue;
> > +
> > + if (end <= (init_pfn << PAGE_SHIFT))
> > + continue;
> > +
> > + if (start < (init_pfn << PAGE_SHIFT))
> > + start = init_pfn << PAGE_SHIFT;
> > +
> > +#ifdef CONFIG_X86_32
> > + if ((start >> PAGE_SHIFT) >= max_low_pfn)
> > + continue;
> > +
> > + if ((end >> PAGE_SHIFT) > max_low_pfn)
> > + end = max_low_pfn << PAGE_SHIFT;
> > +#endif
> > + pfn = init_memory_mapping(start, end);
> > + add_pfn_range_mapped(start >> PAGE_SHIFT, pfn);
> > + }
>
> Some comments please? Also, while this may be the right thing to do,
> if I'm not mistaken, this is also likely to make linear space to use
> smaller mappings depending on how the physical memory is laid out,
> which could be a trade off we're willing to make, but that *should* be
> explicit. Please describe what's going on and provide rationale.
Ah .. okay, so you are concerned about BIOSes with E820 that break up a
large linear memory range into 2 different E820 entries? But if I'm not
mistaken, the E820 code does some cleansing of the values it gets from
the BIOS, in arch/x86/kernel/e820.c: sanitize_e820_map
But yes, I'll add comments, as well as break this logic out to its own
function as Yinghai suggested.
Thanks!
-Jacob
>
> Thanks.
>
> --
> tejun
>
next prev parent reply other threads:[~2012-08-13 14:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-09 21:23 [PATCH 0/5] Only create direct mappings for E820_RAM regions Jacob Shin
2012-08-09 21:23 ` [PATCH 1/5] x86: Only direct map addresses that are marked as E820_RAM Jacob Shin
2012-08-09 22:03 ` Yinghai Lu
2012-08-11 18:36 ` H. Peter Anvin
2012-08-13 14:11 ` Jacob Shin
2012-08-11 19:49 ` Tejun Heo
2012-08-13 14:31 ` Jacob Shin [this message]
2012-08-09 21:23 ` [PATCH 2/5] x86: find_early_table_space based on memory ranges that are being mapped Jacob Shin
2012-08-11 19:56 ` Tejun Heo
2012-08-09 21:23 ` [PATCH 3/5] x86: Keep track of direct mapped pfn ranges Jacob Shin
2012-08-11 19:57 ` Tejun Heo
2012-08-09 21:23 ` [PATCH 4/5] x86: Fixup code testing if a pfn is direct mapped Jacob Shin
2012-08-09 21:23 ` [PATCH 5/5] x86: Move enabling of PSE and PGE out of init_memory_mapping Jacob Shin
2012-08-11 20:01 ` Tejun Heo
2012-08-13 7:34 ` Borislav Petkov
2012-08-13 23:20 ` Tejun Heo
2012-08-14 8:49 ` Borislav Petkov
2012-08-14 19:52 ` Jacob Shin
2012-08-14 20:20 ` Tejun Heo
2012-08-11 19:51 ` [PATCH 0/5] Only create direct mappings for E820_RAM regions Tejun Heo
2012-08-13 21:46 [PATCH V2 0/5] x86: Create direct mappings for E820_RAM only Jacob Shin
2012-08-13 21:47 ` [PATCH 1/5] x86: Only direct map addresses that are marked as E820_RAM Jacob Shin
2012-08-13 21:58 ` Tejun Heo
2012-08-13 22:00 ` H. Peter Anvin
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=20120813143159.GB8441@jshin-Toonie \
--to=jacob.shin@amd.com \
--cc=andreas.herrmann3@amd.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=x86@kernel.org \
--cc=yinghai@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®