linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform
@ 2021-01-16 10:41 Wesley Zhao
  2021-01-16 10:41 ` [PATCH v2 1/2] lib/cmdline: add new function get_option_ull() Wesley Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Wesley Zhao @ 2021-01-16 10:41 UTC (permalink / raw)
  To: akpm
  Cc: andriy.shevchenko, keescook, tglx, kerneldev, nivedita, joe,
	gpiccoli, aquini, gustavoars, zhaowei1102, ojeda, ndesaulniers,
	linux-kernel, david, dan.j.williams, guohanjun, mchehab+huawei

I was trying to reserve some memory to save logs incase that Android panic or hang and then
I can read the logs from QNX side from the memory reserved before on the Qualcomm 8155 hypervisor platform,
and I find the "reserve=" parameter only support 32bit,so I made some change and send these patches.

testcase:
	I test on the qemu with some cmdline like[qemu-system-x86_64 -kernel linux-next/arch/x86_64/boot/bzImage
	-hda ubuntu-system.ext4 -append "root=/dev/sda init=/bin/bash console=ttyS0 reserve=0x180000000,0x123456"
	-nographic]	and check the /proc/iomem with 180000000-180123455 : reserved.
	And some other tests with the get_option with the parameter(-12345678) and so on

Wesley Zhao (2):
  lib/cmdline: add new function get_option_ull()
  resource: Make it possible to reserve memory on 64bit platform

 include/linux/kernel.h |  2 ++
 kernel/resource.c      |  6 ++--
 lib/cmdline.c          | 94 ++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 85 insertions(+), 17 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] lib/cmdline: add new function get_option_ull()
  2021-01-16 10:41 [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Wesley Zhao
@ 2021-01-16 10:41 ` Wesley Zhao
  2021-01-17 19:02 ` [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Dan Williams
  2021-01-18 10:42 ` Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Wesley Zhao @ 2021-01-16 10:41 UTC (permalink / raw)
  To: akpm
  Cc: andriy.shevchenko, keescook, tglx, kerneldev, nivedita, joe,
	gpiccoli, aquini, gustavoars, zhaowei1102, ojeda, ndesaulniers,
	linux-kernel, david, dan.j.williams, guohanjun, mchehab+huawei

In the future we would pass the unsigned long long parameter
like(0x123456781234) in cmdline on the 64bit platform, so add a new
option parse function get_option_ull()

Signed-off-by: Wesley Zhao <zhaowei1102@thundersoft.com>
---
 include/linux/kernel.h |  2 ++
 lib/cmdline.c          | 94 ++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 82 insertions(+), 14 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f7902d8c1048..eb1f0b14a0c5 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -348,6 +348,8 @@ extern __scanf(2, 0)
 int vsscanf(const char *, const char *, va_list);
 
 extern int get_option(char **str, int *pint);
+extern int get_option_ll(char **str, long long *pll);
+extern int get_option_ull(char **str, unsigned long long *pull);
 extern char *get_options(const char *str, int nints, int *ints);
 extern unsigned long long memparse(const char *ptr, char **retptr);
 extern bool parse_option_str(const char *str, const char *option);
diff --git a/lib/cmdline.c b/lib/cmdline.c
index b390dd03363b..d32b585d287d 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -31,6 +31,81 @@ static int get_range(char **str, int *pint, int n)
 		*pint++ = x;
 	return inc_counter;
 }
+/**
+ *	get_option_ull - Parse unsigned long long from an option string
+ *	@str: option string
+ *	@pull: (output) unsigned long long value parsed from @str
+ *
+ *	Read an unsigned long long from an option string; if available accept a subsequent
+ *	comma as well.
+ *
+ *	Return values:
+ *	0 - no ull in string
+ *	1 - ull found, no subsequent comma
+ *	2 - ull found including a subsequent comma
+ *	3 - hyphen found to denote a range
+ */
+
+int get_option_ull(char **str, unsigned long long *pull)
+{
+	char *cur = *str;
+	unsigned long long value;
+
+	if (!cur || !(*cur))
+		return 0;
+	value = simple_strtoull(cur, str, 0);
+	if (pull)
+		*pull = value;
+	if (cur == *str)
+		return 0;
+	if (**str == ',') {
+		(*str)++;
+		return 2;
+	}
+	if (**str == '-')
+		return 3;
+
+	return 1;
+}
+EXPORT_SYMBOL(get_option_ull);
+
+/**
+ *	get_option_ll - Parse long long from an option string
+ *	@str: option string
+ *	@pll: (output) long long value parsed from @str
+ *
+ *	Read an long long from an option string; if available accept a subsequent
+ *	comma as well.
+ *
+ *	Return values:
+ *	0 - no ll in string
+ *	1 - ll found, no subsequent comma
+ *	2 - ll found including a subsequent comma
+ *	3 - hyphen found to denote a range
+ */
+
+int get_option_ll(char **str, long long *pll)
+{
+	char *cur = *str;
+	unsigned long long value;
+	int ret;
+
+	if (!cur || !(*cur))
+		return 0;
+	if (*cur == '-') {
+		cur = cur + 1;
+		ret = get_option_ull((char **)&cur, &value);
+		if (pll)
+			*pll = -value;
+	} else {
+		ret = get_option_ull(str, &value);
+		if (pll)
+			*pll = value;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(get_option_ll);
 
 /**
  *	get_option - Parse integer from an option string
@@ -56,26 +131,17 @@ static int get_range(char **str, int *pint, int n)
 int get_option(char **str, int *pint)
 {
 	char *cur = *str;
-	int value;
+	long long value;
+	int ret;
 
 	if (!cur || !(*cur))
 		return 0;
-	if (*cur == '-')
-		value = -simple_strtoull(++cur, str, 0);
-	else
-		value = simple_strtoull(cur, str, 0);
+	ret = get_option_ll(str, &value);
+
 	if (pint)
 		*pint = value;
-	if (cur == *str)
-		return 0;
-	if (**str == ',') {
-		(*str)++;
-		return 2;
-	}
-	if (**str == '-')
-		return 3;
 
-	return 1;
+	return ret;
 }
 EXPORT_SYMBOL(get_option);
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform
  2021-01-16 10:41 [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Wesley Zhao
  2021-01-16 10:41 ` [PATCH v2 1/2] lib/cmdline: add new function get_option_ull() Wesley Zhao
@ 2021-01-17 19:02 ` Dan Williams
       [not found]   ` <202101181151049299923@thundersoft.com>
  2021-01-18 10:42 ` Andy Shevchenko
  2 siblings, 1 reply; 6+ messages in thread
From: Dan Williams @ 2021-01-17 19:02 UTC (permalink / raw)
  To: Wesley Zhao
  Cc: Andrew Morton, Andy Shevchenko, Kees Cook, Thomas Gleixner,
	kerneldev, Arvind Sankar, Joe Perches, gpiccoli, aquini,
	gustavoars, ojeda, ndesaulniers, Linux Kernel Mailing List,
	David Hildenbrand, guohanjun, mchehab+huawei

On Sat, Jan 16, 2021 at 2:43 AM Wesley Zhao <zhaowei1102@thundersoft.com> wrote:
>
> I was trying to reserve some memory to save logs incase that Android panic or hang and then
> I can read the logs from QNX side from the memory reserved before on the Qualcomm 8155 hypervisor platform,
> and I find the "reserve=" parameter only support 32bit,so I made some change and send these patches.

See Documentation/admin-guide/kernel-parameters.txt

        memmap=nn[KMG]$ss[KMG]
                        [KNL,ACPI] Mark specific memory as reserved.
                        Region of memory to be reserved is from ss to ss+nn.
                        Example: Exclude memory from 0x18690000-0x1869ffff
                                 memmap=64K$0x18690000
                                 or
                                 memmap=0x10000$0x18690000
                        Some bootloaders may need an escape character
before '$',
                        like Grub2, otherwise '$' and the following number
                        will be eaten.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform
       [not found]   ` <202101181151049299923@thundersoft.com>
@ 2021-01-18  9:50     ` David Hildenbrand
       [not found]       ` <202101221536190259795@thundersoft.com>
  0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand @ 2021-01-18  9:50 UTC (permalink / raw)
  To: zhaowei1102, Dan Williams
  Cc: Andrew Morton, Andy Shevchenko, Kees Cook, Thomas Gleixner,
	kerneldev, Arvind Sankar, Joe Perches, gpiccoli, aquini,
	gustavoars, ojeda, Linux Kernel Mailing List, guohanjun,
	mchehab+huawei

On 18.01.21 04:51, zhaowei1102@thundersoft.com wrote:
>     On Sat, Jan 16, 2021 at 2:43 AM Wesley Zhao
>     <zhaowei1102@thundersoft.com> wrote:
>     >>
>     >> I was trying to reserve some memory to save logs incase that
>     Android panic or hang and then
>     >> I can read the logs from QNX side from the memory reserved before
>     on the Qualcomm 8155 hypervisor platform,
>     >> and I find the "reserve=" parameter only support 32bit,so I made
>     some change and send these patches.
>     > 
>     >See Documentation/admin-guide/kernel-parameters.txt
>     > 
>     >        memmap=nn[KMG]$ss[KMG]
>     >                        [KNL,ACPI] Mark specific memory as reserved.
>     >                        Region of memory to be reserved is from ss
>     to ss+nn.
>     >                        Example: Exclude memory from
>     0x18690000-0x1869ffff
>     >                                 memmap=64K$0x18690000
>     >                                 or
>     >                                 memmap=0x10000$0x18690000
>     >                        Some bootloaders may need an escape character
>     >before '$',
>     >                        like Grub2, otherwise '$' and the following
>     number
>     >                        will be eaten.
>     Sorry,what is your point:
>      static int __init reserve_setup(char *str)
>      static struct resource reserve[MAXRESERVE];
>      for (;;) {
>      unsigned int io_start, io_num;*  // these code is not compatible
>     with 64bit,i start from here*
> 

Dan's point is that you should look into using "memmap=" instead of
"reserve=".

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform
  2021-01-16 10:41 [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Wesley Zhao
  2021-01-16 10:41 ` [PATCH v2 1/2] lib/cmdline: add new function get_option_ull() Wesley Zhao
  2021-01-17 19:02 ` [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Dan Williams
@ 2021-01-18 10:42 ` Andy Shevchenko
  2 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2021-01-18 10:42 UTC (permalink / raw)
  To: Wesley Zhao
  Cc: akpm, keescook, tglx, kerneldev, nivedita, joe, gpiccoli, aquini,
	gustavoars, ojeda, ndesaulniers, linux-kernel, david,
	dan.j.williams, guohanjun, mchehab+huawei

On Sat, Jan 16, 2021 at 02:41:11AM -0800, Wesley Zhao wrote:
> I was trying to reserve some memory to save logs incase that Android panic or hang and then
> I can read the logs from QNX side from the memory reserved before on the Qualcomm 8155 hypervisor platform,
> and I find the "reserve=" parameter only support 32bit,so I made some change and send these patches.

Your series has disrupter in-reply-to change, can you fix your tools to have
all patches in one email thread?

> testcase:
> 	I test on the qemu with some cmdline like[qemu-system-x86_64 -kernel linux-next/arch/x86_64/boot/bzImage
> 	-hda ubuntu-system.ext4 -append "root=/dev/sda init=/bin/bash console=ttyS0 reserve=0x180000000,0x123456"
> 	-nographic]	and check the /proc/iomem with 180000000-180123455 : reserved.
> 	And some other tests with the get_option with the parameter(-12345678) and so on

It's good but I was talking about unit test. Look into cmdline_kunit.c.

> Wesley Zhao (2):
>   lib/cmdline: add new function get_option_ull()
>   resource: Make it possible to reserve memory on 64bit platform

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform
       [not found]       ` <202101221536190259795@thundersoft.com>
@ 2021-01-22 10:21         ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2021-01-22 10:21 UTC (permalink / raw)
  To: zhaowei1102
  Cc: David Hildenbrand, Dan Williams, Andrew Morton, Kees Cook,
	Thomas Gleixner, kerneldev, Arvind Sankar, Joe Perches, gpiccoli,
	aquini, gustavoars, ojeda, Linux Kernel Mailing List, guohanjun,
	mchehab+huawei

On Fri, Jan 22, 2021 at 03:36:19PM +0800, zhaowei1102@thundersoft.com wrote:
> On 18.01.21 04:51, zhaowei1102@thundersoft.com wrote:
> > >     On Sat, Jan 16, 2021 at 2:43 AM Wesley Zhao
> > >     <zhaowei1102@thundersoft.com> wrote:

> > Dan's point is that you should look into using "memmap=" instead of
> > "reserve=".
> Oh~,sorry miss understand,i can try this, thanks!!

And AFAICS you don't need to alter cmdline.c. But if you are going to, don't
forget test cases (and FYI: I have few patches pending against it here [1]).

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel.git/log/?h=for-next

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-22 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-16 10:41 [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Wesley Zhao
2021-01-16 10:41 ` [PATCH v2 1/2] lib/cmdline: add new function get_option_ull() Wesley Zhao
2021-01-17 19:02 ` [PATCH v2 0/2] Make it possible to reserve memory on 64bit platform Dan Williams
     [not found]   ` <202101181151049299923@thundersoft.com>
2021-01-18  9:50     ` David Hildenbrand
     [not found]       ` <202101221536190259795@thundersoft.com>
2021-01-22 10:21         ` Andy Shevchenko
2021-01-18 10:42 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).