[PATCH] Drivers: HV: Fix the check for return value from kmsg get dump buffer

2018-07-26 Thread Sunil Muthuswamy
The code to support panic control message was checking the return was
checking the return value from kmsg_dump_get_buffer as error value, which
is not what the routine returns. This fixes it.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 drivers/hv/vmbus_drv.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..a7f33c1f42c5 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1047,13 +1047,10 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 * Write dump contents to the page. No need to synchronize; panic should
 * be single-threaded.
 */
-   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
- PAGE_SIZE, _written)) {
-   pr_err("Hyper-V: Unable to get kmsg data for panic\n");
-   return;
-   }
-
-   hyperv_report_panic_msg(panic_pa, bytes_written);
+   kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE,
+_written);
+   if (bytes_written)
+   hyperv_report_panic_msg(panic_pa, bytes_written);
 }
 
 static struct kmsg_dumper hv_kmsg_dumper = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch specific

2018-07-26 Thread Sunil Muthuswamy
I just sent three individual patches to address the below.

Thanks,
Sunil

> -Original Message-
> From: KY Srinivasan
> Sent: Thursday, July 26, 2018 11:53 AM
> To: Sunil Muthuswamy ; Michael Kelley (EOSG)
> 
> Cc: Stephen Hemminger ; Haiyang Zhang
> ; de...@linuxdriverproject.org
> Subject: RE: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch
> specific
> 
> 
> 
> > -Original Message-
> > From: Sunil Muthuswamy
> > Sent: Monday, July 23, 2018 11:31 AM
> > To: Michael Kelley (EOSG) ; Sunil
> > Muthuswamy 
> > Cc: KY Srinivasan ; Stephen Hemminger
> > ; Haiyang Zhang ;
> > de...@linuxdriverproject.org
> > Subject: [PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch
> > specific
> >
> > Moves the MSR access from arch independent code to arch
> > dependent code. Also includes minor bug fixes.
> 
> Please breakup this patch into 3 patches:
> 
> 1) Making the code ISA independent - moving the MSR accesses out of the
> common code.
> 2) Fixing the issue with checking the return value from
> kmsg_dump_get_buffer()
> 3) Fix the issue with freeing up hv_ctl_table_hdr
> 
> Thank you,
> 
> K. Y
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: Fix the issue with freeing up hv_ctl_table_hdr

2018-07-26 Thread Sunil Muthuswamy
The check to free the Hyper-V control table header was reversed. This
fixes it.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 drivers/hv/vmbus_drv.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..9380f115095b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1179,11 +1179,8 @@ static int vmbus_bus_init(void)
 
bus_unregister(_bus);
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
return ret;
 }
 
@@ -1894,11 +1891,8 @@ static void __exit vmbus_exit(void)
}
 
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
bus_unregister(_bus);
 
cpuhp_remove_state(hyperv_cpuhp_online);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: move the crash control MSR access out of common code

2018-07-26 Thread Sunil Muthuswamy
Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
 arch/x86/include/asm/mshyperv.h | 3 +++
 drivers/hv/vmbus_drv.c  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 406da8d159e3..4d82ad347b75 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -97,6 +97,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, 
u32 old_msg_type)
 #define hv_set_synint_state(int_num, val) \
wrmsrl(HV_X64_MSR_SINT0 + int_num, val)
 
+#define hv_get_crash_ctl(val) \
+   rdmsrl(HV_X64_MSR_CRASH_CTL, val)
+
 void hyperv_callback_vector(void);
 void hyperv_reenlightenment_vector(void);
 #ifdef CONFIG_TRACING
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..6f7686f75f86 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1149,7 +1149,7 @@ static int vmbus_bus_init(void)
 * Register for panic kmsg callback only if the right
 * capability is supported by the hypervisor.
 */
-   rdmsrl(HV_X64_MSR_CRASH_CTL, hyperv_crash_ctl);
+   hv_get_crash_ctl(hyperv_crash_ctl);
if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL);
if (hv_panic_page) {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch specific

2018-07-23 Thread Sunil Muthuswamy
Moves the MSR access from arch independent code to arch
dependent code. Also includes minor bug fixes.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over 
Hyper-V during panic")

Signed-off-by: Sunil Muthuswamy 
---
Have added a "Fixes" line to associate this with the original commit, which
it fixes.

---
 arch/x86/include/asm/mshyperv.h |  3 +++
 drivers/hv/vmbus_drv.c  | 26 +-
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 406da8d159e3..4d82ad347b75 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -97,6 +97,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, 
u32 old_msg_type)
 #define hv_set_synint_state(int_num, val) \
wrmsrl(HV_X64_MSR_SINT0 + int_num, val)
 
+#define hv_get_crash_ctl(val) \
+   rdmsrl(HV_X64_MSR_CRASH_CTL, val)
+
 void hyperv_callback_vector(void);
 void hyperv_reenlightenment_vector(void);
 #ifdef CONFIG_TRACING
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..ec131a26530e 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1047,13 +1047,11 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 * Write dump contents to the page. No need to synchronize; panic should
 * be single-threaded.
 */
-   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
- PAGE_SIZE, _written)) {
-   pr_err("Hyper-V: Unable to get kmsg data for panic\n");
-   return;
-   }
+   kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE,
+_written);
 
-   hyperv_report_panic_msg(panic_pa, bytes_written);
+   if (bytes_written)
+   hyperv_report_panic_msg(panic_pa, bytes_written);
 }
 
 static struct kmsg_dumper hv_kmsg_dumper = {
@@ -1149,7 +1147,7 @@ static int vmbus_bus_init(void)
 * Register for panic kmsg callback only if the right
 * capability is supported by the hypervisor.
 */
-   rdmsrl(HV_X64_MSR_CRASH_CTL, hyperv_crash_ctl);
+   hv_get_crash_ctl(hyperv_crash_ctl);
if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL);
if (hv_panic_page) {
@@ -1179,11 +1177,8 @@ static int vmbus_bus_init(void)
 
bus_unregister(_bus);
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
return ret;
 }
 
@@ -1894,11 +1889,8 @@ static void __exit vmbus_exit(void)
}
 
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
bus_unregister(_bus);
 
cpuhp_remove_state(hyperv_cpuhp_online);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Drivers: HV: panic kmsg dump, move MSR access to arch specific

2018-07-20 Thread Sunil Muthuswamy
Moves the MSR access from arch independent code to arch
dependent code. Also includes minor bug fixes.

Signed-off-by: Sunil Muthuswamy 
---
 arch/x86/include/asm/mshyperv.h |  3 +++
 drivers/hv/vmbus_drv.c  | 26 +-
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 406da8d159e3..4d82ad347b75 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -97,6 +97,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, 
u32 old_msg_type)
 #define hv_set_synint_state(int_num, val) \
wrmsrl(HV_X64_MSR_SINT0 + int_num, val)
 
+#define hv_get_crash_ctl(val) \
+   rdmsrl(HV_X64_MSR_CRASH_CTL, val)
+
 void hyperv_callback_vector(void);
 void hyperv_reenlightenment_vector(void);
 #ifdef CONFIG_TRACING
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 05e37283d7c3..ec131a26530e 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1047,13 +1047,11 @@ static void hv_kmsg_dump(struct kmsg_dumper *dumper,
 * Write dump contents to the page. No need to synchronize; panic should
 * be single-threaded.
 */
-   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
- PAGE_SIZE, _written)) {
-   pr_err("Hyper-V: Unable to get kmsg data for panic\n");
-   return;
-   }
+   kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE,
+_written);
 
-   hyperv_report_panic_msg(panic_pa, bytes_written);
+   if (bytes_written)
+   hyperv_report_panic_msg(panic_pa, bytes_written);
 }
 
 static struct kmsg_dumper hv_kmsg_dumper = {
@@ -1149,7 +1147,7 @@ static int vmbus_bus_init(void)
 * Register for panic kmsg callback only if the right
 * capability is supported by the hypervisor.
 */
-   rdmsrl(HV_X64_MSR_CRASH_CTL, hyperv_crash_ctl);
+   hv_get_crash_ctl(hyperv_crash_ctl);
if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL);
if (hv_panic_page) {
@@ -1179,11 +1177,8 @@ static int vmbus_bus_init(void)
 
bus_unregister(_bus);
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
return ret;
 }
 
@@ -1894,11 +1889,8 @@ static void __exit vmbus_exit(void)
}
 
free_page((unsigned long)hv_panic_page);
-   if (!hv_ctl_table_hdr) {
-   unregister_sysctl_table(hv_ctl_table_hdr);
-   hv_ctl_table_hdr = NULL;
-   }
-
+   unregister_sysctl_table(hv_ctl_table_hdr);
+   hv_ctl_table_hdr = NULL;
bus_unregister(_bus);
 
cpuhp_remove_state(hyperv_cpuhp_online);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-07-11 Thread Sunil Muthuswamy
Thanks, Michael. In which branch should I fix these now that the changes have 
been
merged with the char-misc-next branch?

Comments inline.

> -Original Message-
> From: Michael Kelley (EOSG)
> Sent: Tuesday, July 10, 2018 6:05 PM
> To: KY Srinivasan ; gre...@linuxfoundation.org; linux-
> ker...@vger.kernel.org; de...@linuxdriverproject.org; o...@aepfle.de;
> a...@canonical.com; jasow...@redhat.com; Stephen Hemminger
> ; vkuzn...@redhat.com
> Cc: Sunil Muthuswamy 
> Subject: RE: [PATCH 1/1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> From k...@linuxonhyperv.com   Sent: Saturday,
> July 7, 2018 7:57 PM
> >
> > From: Sunil Muthuswamy 
> >
> > In the VM mode on Hyper-V, currently, when the kernel panics, an error
> > code and few register values are populated in an MSR and the Hypervisor
> > notified. This information is collected on the host. The amount of
> > information currently collected is found to be limited and not very
> > actionable. To gather more actionable data, such as stack trace, the
> > proposal is to write one page worth of kmsg data on an allocated page
> > and the Hypervisor notified of the page address through the MSR.
> >
> > - Sysctl option to control the behavior, with ON by default.
> >
> > Cc: K. Y. Srinivasan 
> > Cc: Stephen Hemminger 
> > Signed-off-by: Sunil Muthuswamy 
> > Signed-off-by: K. Y. Srinivasan 
> > ---
> 
> > +   /*
> > +* Write dump contents to the page. No need to synchronize; panic
> should
> > +* be single-threaded.
> > +*/
> > +   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
> > + PAGE_SIZE, _written)) {
> > +   pr_err("Hyper-V: Unable to get kmsg data for panic\n");
> > +   return;
> 
> From what I can see, the return value from kmsg_dump_get_buffer()
> is not an indication of success or failure -- it's an indication of whether
> there is more data available.   There's no reason to output an error
> message.
> 
That seems correct. Will address this.
> > @@ -1065,6 +1136,32 @@ static int vmbus_bus_init(void)
> >  * Only register if the crash MSRs are available
> >  */
> > if (ms_hyperv.misc_features &
> HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
> > +   u64 hyperv_crash_ctl;
> > +   /*
> > +* Sysctl registration is not fatal, since by default
> > +* reporting is enabled.
> > +*/
> > +   hv_ctl_table_hdr = register_sysctl_table(hv_root_table);
> > +   if (!hv_ctl_table_hdr)
> > +   pr_err("Hyper-V: sysctl table register error");
> > +
> > +   /*
> > +* Register for panic kmsg callback only if the right
> > +* capability is supported by the hypervisor.
> > +*/
> > +   rdmsrl(HV_X64_MSR_CRASH_CTL, hyperv_crash_ctl);
> > +   if (hyperv_crash_ctl &
> HV_CRASH_CTL_CRASH_NOTIFY_MSG) {
> 
> vmbus_drv.c is architecture independent code, and should not be
> referencing
> x86/x64 MSRs.   Reading the MSR (and maybe the test as well?) should go
> in a separate function in an x86-specific source file.
> 
I will move the code.
> And just to confirm, is this the right way to test for the feature?  Usually,
> feature determination is based on one of the feature registers.  The
> NOTIFY_MSG flag seems to have a dual meaning -- on read it indicates
> the feature is present.  On write in hyperv_report_panic_msg(), it evidently
> means that the guest is sending a full page of data to Hyper-V.
> 
As per my conversation with John, this seems to be correct and something
also he suggested. The host sets these bits depending on whether it supports
these features or not.

> > @@ -1081,6 +1178,11 @@ static int vmbus_bus_init(void)
> > bus_unregister(_bus);
> > +   free_page((unsigned long)hv_panic_page);
> > +   if (!hv_ctl_table_hdr) {
> 
> The above test is backwards.  Remove the bang.
Good call, will do.
> 
> > @@ -1785,10 +1887,18 @@ static void __exit vmbus_exit(void)
> > +   free_page((unsigned long)hv_panic_page);
> > +   if (!hv_ctl_table_hdr) {
> 
> Same here.  Test is backwards.
> 
Will fix.
> Michael

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v3] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-11 Thread Sunil Muthuswamy
I haven't gotten any test build bot reports for the newer version of the 
patches that were
Submitted last week. Is there a way to know what's going on there or force a 
submission?

- sunil

> -Original Message-
> From: kbuild test robot 
> Sent: Wednesday, May 23, 2018 7:57 PM
> To: Sunil Muthuswamy 
> Cc: kbuild-...@01.org; Haiyang Zhang ;
> de...@linuxdriverproject.org; Sunil Muthuswamy
> ; Stephen Hemminger
> 
> Subject: Re: [PATCH v3] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> Hi Sunil,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on linus/master]
> [also build test WARNING on v4.17-rc6 next-20180517]
> [cannot apply to tip/x86/core]
> [if your patch is applied to the wrong git tree, please drop us a note to help
> improve the system]
> 
> url:
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
> .com%2F0day-ci%2Flinux%2Fcommits%2FSunil-Muthuswamy%2FDrivers-HV-
> Send-one-page-worth-of-kmsg-dump-over-Hyper-V-during-
> panic%2F20180523-
> 035336=02%7C01%7Csunilmut%40microsoft.com%7Cea8837620518441
> e279808d5c1221032%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6
> 36627274402211081=aRiQw64FhftuwLijjsPJigInUHEYBFWWl%2BMcgqI
> yNl4%3D=0
> reproduce:
> # apt-get install sparse
> make ARCH=x86_64 allmodconfig
> make C=1 CF=-D__CHECK_ENDIAN__
> 
> 
> sparse warnings: (new ones prefixed by >>)
> 
> >> drivers/hv/vmbus_drv.c:1028:5: sparse: symbol
> 'sysctl_record_panic_msg' was not declared. Should it be static?
>drivers/hv/vmbus_drv.c:1631:32: sparse: expression using sizeof(void)
>drivers/hv/vmbus_drv.c:1633:32: sparse: expression using sizeof(void)
>include/asm-generic/atomic-instrumented.h:358:24: sparse: cast truncates
> bits from constant value (8010 becomes 10)
>include/asm-generic/atomic-instrumented.h:360:24: sparse: cast truncates
> bits from constant value (8010 becomes 10)
> 
> Please review and possibly fold the followup patch.
> 
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.01
> .org%2Fpipermail%2Fkbuild-
> all=02%7C01%7Csunilmut%40microsoft.com%7Cea8837620518441e279
> 808d5c1221032%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63662
> 7274402211081=HhJj%2BMSiTeoaxbBDEdMLquOAO%2B5AuQR0yENX
> BZ%2B77gQ%3D=0   Intel Corporation
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v6] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-11 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

- Sysctl option to control the behavior, with ON by default.

Cc: K. Y. Srinivasan 
Cc: Stephen Hemminger 
Signed-off-by: Sunil Muthuswamy 
---
Changes since v1:
- Added a sysctl config option to allow the user to control if panic message
  should be reported to Hyper-V.

Changes since v2:
- Addressed comments from Greg KH.
- Moved the sysctl config option from 'kernel.hyperv' to 'kernel.' since the
  likelihood of having many Hyper-V specific sysctl config options seemed less
  and so having a specific dir for Hyper-V seemed unnecessary overhead.

Changes since v3:
- The feature is only enabled if the capability is supported by the hypervisor.
  This is done by reading the crash control MSR, in addition to the pre-existing
  check for the hypervisor feature using the CPUID.

Changes since v4:
- Addressed comments from Dexuan Cui: moved the global variable to static.

Changes since v5:
- Addressed comments from KY Srinivasan: errors during panic message
  initialization are no longer fatal.
---
 Documentation/sysctl/kernel.txt|  11 
 arch/x86/hyperv/hv_init.c  |  27 +
 arch/x86/include/asm/hyperv-tlfs.h |   5 +-
 arch/x86/include/asm/mshyperv.h|   1 +
 drivers/hv/vmbus_drv.c | 110 +
 5 files changed, 152 insertions(+), 2 deletions(-)

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index eded671d..5958503 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -39,6 +39,7 @@ show up in /proc/sys/kernel:
 - hung_task_check_count
 - hung_task_timeout_secs
 - hung_task_warnings
+- hyperv_record_panic_msg
 - kexec_load_disabled
 - kptr_restrict
 - l2cr[ PPC only ]
@@ -374,6 +375,16 @@ This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
 
 ==
 
+hyperv_record_panic_msg:
+
+Controls whether the panic kmsg data should be reported to Hyper-V.
+
+0: do not report panic kmsg data.
+
+1: report the panic kmsg data. This is the default behavior.
+
+==
+
 kexec_load_disabled:
 
 A toggle indicating if the kexec_load syscall has been disabled. This
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..af57162 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,33 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+/**
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ */
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..76c58af 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG  BIT_ULL(62)
+#define HV_CRASH_CTL_CRASH_NOTIFY  BIT_ULL(63)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_

RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-11 Thread Sunil Muthuswamy



> -Original Message-
> From: KY Srinivasan
> Sent: Monday, June 11, 2018 11:39 AM
> To: Sunil Muthuswamy ; Haiyang Zhang
> 
> Cc: de...@linuxdriverproject.org; Stephen Hemminger
> 
> Subject: RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> 
> 
> > -Original Message-
> > From: Sunil Muthuswamy
> > Sent: Monday, June 11, 2018 10:44 AM
> > To: KY Srinivasan ; Haiyang Zhang
> > 
> > Cc: de...@linuxdriverproject.org; Stephen Hemminger
> > 
> > Subject: RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump
> > over Hyper-V during panic
> >
> >
> >
> > > -Original Message-
> > > From: KY Srinivasan
> > > Sent: Sunday, June 10, 2018 2:54 PM
> > > To: Sunil Muthuswamy ; Haiyang Zhang
> > > 
> > > Cc: de...@linuxdriverproject.org; Stephen Hemminger
> > > 
> > > Subject: RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump
> > > over Hyper-V during panic
> > >
> > >
> > >
> > > > -Original Message-
> > > > From: Sunil Muthuswamy
> > > > Sent: Friday, June 8, 2018 11:39 AM
> > > > To: Haiyang Zhang 
> > > > Cc: de...@linuxdriverproject.org; Sunil Muthuswamy
> > > > ; KY Srinivasan ;
> > Stephen
> > > > Hemminger 
> > > > Subject: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump
> > over
> > > > Hyper-V during panic
> > > >
> > > > In the VM mode on Hyper-V, currently, when the kernel panics, an
> error
> > > > code and few register values are populated in an MSR and the
> Hypervisor
> > > > notified. This information is collected on the host. The amount of
> > > > information currently collected is found to be limited and not very
> > > > actionable. To gather more actionable data, such as stack trace, the
> > > > proposal is to write one page worth of kmsg data on an allocated page
> > > > and the Hypervisor notified of the page address through the MSR.
> > > >
> 
> Snip.
> 
> > > >  /*
> > > >   * vmbus_bus_init -Main vmbus driver initialization routine.
> > > > @@ -1065,6 +1136,38 @@ static int vmbus_bus_init(void)
> > > >  * Only register if the crash MSRs are available
> > > >  */
> > > > if (ms_hyperv.misc_features &
> > > > HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
> > > > +   u64 hyperv_crash_ctl;
> > > > +   if (!hv_ctl_table_hdr) {
> > > When vmus_bus_init is invoked, would hv_ctl_table_hdr  ever be
> > > Non-NULL?
> Ping.
Missed this somehow. It should not be. Will fix this as well in the next 
version.
> 
> Snip.
> 
> Regards,
> 
> K. Y
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-11 Thread Sunil Muthuswamy



> -Original Message-
> From: KY Srinivasan
> Sent: Sunday, June 10, 2018 2:54 PM
> To: Sunil Muthuswamy ; Haiyang Zhang
> 
> Cc: de...@linuxdriverproject.org; Stephen Hemminger
> 
> Subject: RE: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> 
> 
> > -Original Message-
> > From: Sunil Muthuswamy
> > Sent: Friday, June 8, 2018 11:39 AM
> > To: Haiyang Zhang 
> > Cc: de...@linuxdriverproject.org; Sunil Muthuswamy
> > ; KY Srinivasan ; Stephen
> > Hemminger 
> > Subject: [PATCH v5] Drivers: HV: Send one page worth of kmsg dump over
> > Hyper-V during panic
> >
> > In the VM mode on Hyper-V, currently, when the kernel panics, an error
> > code and few register values are populated in an MSR and the Hypervisor
> > notified. This information is collected on the host. The amount of
> > information currently collected is found to be limited and not very
> > actionable. To gather more actionable data, such as stack trace, the
> > proposal is to write one page worth of kmsg data on an allocated page
> > and the Hypervisor notified of the page address through the MSR.
> >
> > - Sysctl option to control the behavior, with ON by default.
> >
> > Cc: K. Y. Srinivasan 
> > Cc: Stephen Hemminger 
> > Signed-off-by: Sunil Muthuswamy 
> > ---
> > Changes since v1:
> > - Added a sysctl config option to allow the user to control if panic message
> >   should be reported to Hyper-V.
> >
> > Changes since v2:
> > - Addressed comments from Greg KH.
> > - Moved the sysctl config option from 'kernel.hyperv' to 'kernel.' since the
> >   likelihood of having many Hyper-V specific sysctl config options seemed
> less
> >   and so having a specific dir for Hyper-V seemed unnecessary overhead.
> >
> > Changes since v3:
> > - The feature is only enabled if the capability is supported by the
> hypervisor.
> >   This is done by reading the crash control MSR, in addition to the pre-
> existing
> >   check for the hypervisor feature using the CPUID.
> >
> > Changes since v4:
> > - Addressed comments from Dexuan Cui: moved the global variable to
> static.
> > ---
> >  Documentation/sysctl/kernel.txt|  11 
> >  arch/x86/hyperv/hv_init.c  |  27 +
> >  arch/x86/include/asm/hyperv-tlfs.h |   5 +-
> >  arch/x86/include/asm/mshyperv.h|   1 +
> >  drivers/hv/vmbus_drv.c | 116
> > +
> >  5 files changed, 158 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/sysctl/kernel.txt
> > b/Documentation/sysctl/kernel.txt
> > index eded671d..5958503 100644
> > --- a/Documentation/sysctl/kernel.txt
> > +++ b/Documentation/sysctl/kernel.txt
> > @@ -39,6 +39,7 @@ show up in /proc/sys/kernel:
> >  - hung_task_check_count
> >  - hung_task_timeout_secs
> >  - hung_task_warnings
> > +- hyperv_record_panic_msg
> >  - kexec_load_disabled
> >  - kptr_restrict
> >  - l2cr[ PPC only ]
> > @@ -374,6 +375,16 @@ This file shows up if CONFIG_DETECT_HUNG_TASK
> is
> > enabled.
> >
> >
> >
> ==
> > 
> >
> > +hyperv_record_panic_msg:
> > +
> > +Controls whether the panic kmsg data should be reported to Hyper-V.
> > +
> > +0: do not report panic kmsg data.
> > +
> > +1: report the panic kmsg data. This is the default behavior.
> > +
> >
> +=
> > =
> > +
> >  kexec_load_disabled:
> >
> >  A toggle indicating if the kexec_load syscall has been disabled. This
> > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> > index cfecc22..af57162 100644
> > --- a/arch/x86/hyperv/hv_init.c
> > +++ b/arch/x86/hyperv/hv_init.c
> > @@ -395,6 +395,33 @@ void hyperv_report_panic(struct pt_regs *regs,
> long
> > err)
> >  }
> >  EXPORT_SYMBOL_GPL(hyperv_report_panic);
> >
> > +/**
> > + * hyperv_report_panic_msg - report panic message to Hyper-V
> > + * @pa: physical address of the panic page containing the message
> > + * @size: size of the message in the page
> > + */
> > +void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
> > +{
> > +   /*
> > +* P3 to contain the physical address of the panic page & P4 to
> > +* contain the size of the panic data in that page. Rest of the
> > +* registers 

[PATCH v5] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-08 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

- Sysctl option to control the behavior, with ON by default.

Cc: K. Y. Srinivasan 
Cc: Stephen Hemminger 
Signed-off-by: Sunil Muthuswamy 
---
Changes since v1:
- Added a sysctl config option to allow the user to control if panic message
  should be reported to Hyper-V.

Changes since v2:
- Addressed comments from Greg KH.
- Moved the sysctl config option from 'kernel.hyperv' to 'kernel.' since the
  likelihood of having many Hyper-V specific sysctl config options seemed less
  and so having a specific dir for Hyper-V seemed unnecessary overhead.

Changes since v3:
- The feature is only enabled if the capability is supported by the hypervisor.
  This is done by reading the crash control MSR, in addition to the pre-existing
  check for the hypervisor feature using the CPUID.

Changes since v4:
- Addressed comments from Dexuan Cui: moved the global variable to static.
---
 Documentation/sysctl/kernel.txt|  11 
 arch/x86/hyperv/hv_init.c  |  27 +
 arch/x86/include/asm/hyperv-tlfs.h |   5 +-
 arch/x86/include/asm/mshyperv.h|   1 +
 drivers/hv/vmbus_drv.c | 116 +
 5 files changed, 158 insertions(+), 2 deletions(-)

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index eded671d..5958503 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -39,6 +39,7 @@ show up in /proc/sys/kernel:
 - hung_task_check_count
 - hung_task_timeout_secs
 - hung_task_warnings
+- hyperv_record_panic_msg
 - kexec_load_disabled
 - kptr_restrict
 - l2cr[ PPC only ]
@@ -374,6 +375,16 @@ This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
 
 ==
 
+hyperv_record_panic_msg:
+
+Controls whether the panic kmsg data should be reported to Hyper-V.
+
+0: do not report panic kmsg data.
+
+1: report the panic kmsg data. This is the default behavior.
+
+==
+
 kexec_load_disabled:
 
 A toggle indicating if the kexec_load syscall has been disabled. This
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..af57162 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,33 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+/**
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ */
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..76c58af 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG  BIT_ULL(62)
+#define HV_CRASH_CTL_CRASH_NOTIFY  BIT_ULL(63)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs, long err);
+void hyperv_report_panic_msg(phys_addr_t pa, siz

RE: [PATCH v4] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-07 Thread Sunil Muthuswamy
Thanks.

> -Original Message-
> From: Dexuan Cui
> Sent: Wednesday, June 6, 2018 5:31 PM
> To: Sunil Muthuswamy 
> Cc: de...@linuxdriverproject.org; KY Srinivasan ;
> Stephen Hemminger 
> Subject: RE: [PATCH v4] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> > From: Sunil Muthuswamy
> > Sent: Wednesday, June 6, 2018 12:31
> > ...
> > + int sysctl_record_panic_msg = 1;
> 
> This variable can be static.
Will be fixed in V5.
> 
> -- Dexuan

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-06-06 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

- Sysctl option to control the behavior, with ON by default.

Cc: K. Y. Srinivasan 
Cc: Stephen Hemminger 
Signed-off-by: Sunil Muthuswamy 

Drivers: HV:Send one page worth of kmsg dump over Hyper-V during panic
Signed-off-by: Sunil Muthuswamy 
---
Changes since v1:
- Added a sysctl config option to allow the user to control if panic message
  should be reported to Hyper-V.

Changes since v2:
- Addressed comments from Greg KH.
- Moved the sysctl config option from 'kernel.hyperv' to 'kernel.' since the
  likelihood of having many Hyper-V specific sysctl config options seemed less
  and so having a specific dir for Hyper-V seemed unnecessary overhead.

Changes since v3:
- The feature is only enabled if the capability is supported by the hypervisor.
  This is done by reading the crash control MSR, in addition to the pre-existing
  check for the hypervisor feature using the CPUID.
---
 Documentation/sysctl/kernel.txt|  11 
 arch/x86/hyperv/hv_init.c  |  27 +
 arch/x86/include/asm/hyperv-tlfs.h |   5 +-
 arch/x86/include/asm/mshyperv.h|   1 +
 drivers/hv/vmbus_drv.c | 116 +
 5 files changed, 158 insertions(+), 2 deletions(-)

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index eded671d..5958503 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -39,6 +39,7 @@ show up in /proc/sys/kernel:
 - hung_task_check_count
 - hung_task_timeout_secs
 - hung_task_warnings
+- hyperv_record_panic_msg
 - kexec_load_disabled
 - kptr_restrict
 - l2cr[ PPC only ]
@@ -374,6 +375,16 @@ This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
 
 ==
 
+hyperv_record_panic_msg:
+
+Controls whether the panic kmsg data should be reported to Hyper-V.
+
+0: do not report panic kmsg data.
+
+1: report the panic kmsg data. This is the default behavior.
+
+==
+
 kexec_load_disabled:
 
 A toggle indicating if the kexec_load syscall has been disabled. This
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..af57162 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,33 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+/**
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ */
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..76c58af 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG  BIT_ULL(62)
+#define HV_CRASH_CTL_CRASH_NOTIFY  BIT_ULL(63)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs, long err);
+void hyperv_report_panic_msg(phys_addr_t pa, siz

RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-31 Thread Sunil Muthuswamy
Hey K. Y,

Currently, while reporting the panic message, we don't have a check for the 
extra MSR capability. It 
key's off of the existing crash MSR bit. There are no operational issues with 
it. But, after some
discussions with John, for consistency purposes, the suggestion was to check 
for the additional bit
as well. Hold on to the patch for now, I will have a V4 with the changes.

- Sunil

> -Original Message-
> From: KY Srinivasan
> Sent: Wednesday, May 30, 2018 12:43 PM
> To: Sunil Muthuswamy ; Greg KH
> ; Haiyang Zhang ;
> Stephen Hemminger 
> Cc: de...@linuxdriverproject.org
> Subject: RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> 
> 
> > -Original Message-
> > From: Sunil Muthuswamy
> > Sent: Wednesday, May 30, 2018 12:40 PM
> > To: Greg KH ; Haiyang Zhang
> > ; Stephen Hemminger
> > ; KY Srinivasan 
> > Cc: de...@linuxdriverproject.org
> > Subject: RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> > over Hyper-V during panic
> >
> > The maintainers of Hyper-V; Haiyang Zhang and Stephen Hemminger have
> > always been included since the beginning in all mail & patches. I missed K.
> Y.
> > Srinivasan, whom I have added now.
> 
> I will take this patch through my tree.
> 
> K. Y
> 
> 
> >
> > @KY Srinivasan, @Stephen Hemminger, @Haiyang Zhang - Can we get
> some
> > reviews/sign-offs?
> >
> > Thanks,
> > Sunil
> >
> > > -Original Message-
> > > From: Greg KH 
> > > Sent: Tuesday, May 29, 2018 9:43 PM
> > > To: Sunil Muthuswamy 
> > > Cc: de...@linuxdriverproject.org; Haiyang Zhang
> > > ; Stephen Hemminger
> > > 
> > > Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> > > over Hyper-V during panic
> > >
> > > On Wed, May 30, 2018 at 06:42:14AM +0200, Greg KH wrote:
> > > > On Tue, May 29, 2018 at 08:11:40PM +, Sunil Muthuswamy wrote:
> > > > > The V3 patch should address the concerns/comments below. Happy
> to
> > > > > address any additional comments, if there are any.
> > > >
> > > > Why not respond to the v3 patch so I don't have to go dig it up?  :)
> > > >
> > > > And really, it's up to the maintainer of this subsystem to provide the
> > > > final review, and that's not me.  Why did you not cc: them on the patch
> > > > in the beginning?
> > >
> > > And as proof of that, I don't even have this patch in my "to-review"
> > > local queue as I assumed the hyperv maintainers would take care of it.
> > >
> > > thanks,
> > >
> > > greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-30 Thread Sunil Muthuswamy
The maintainers of Hyper-V; Haiyang Zhang and Stephen Hemminger have always 
been included since the beginning in all mail & patches. I missed K. Y. 
Srinivasan, whom I have added now.

@KY Srinivasan, @Stephen Hemminger, @Haiyang Zhang - Can we get some 
reviews/sign-offs?

Thanks,
Sunil

> -Original Message-
> From: Greg KH 
> Sent: Tuesday, May 29, 2018 9:43 PM
> To: Sunil Muthuswamy 
> Cc: de...@linuxdriverproject.org; Haiyang Zhang
> ; Stephen Hemminger
> 
> Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> On Wed, May 30, 2018 at 06:42:14AM +0200, Greg KH wrote:
> > On Tue, May 29, 2018 at 08:11:40PM +, Sunil Muthuswamy wrote:
> > > The V3 patch should address the concerns/comments below. Happy to
> > > address any additional comments, if there are any.
> >
> > Why not respond to the v3 patch so I don't have to go dig it up?  :)
> >
> > And really, it's up to the maintainer of this subsystem to provide the
> > final review, and that's not me.  Why did you not cc: them on the patch
> > in the beginning?
> 
> And as proof of that, I don't even have this patch in my "to-review"
> local queue as I assumed the hyperv maintainers would take care of it.
> 
> thanks,
> 
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-29 Thread Sunil Muthuswamy
The V3 patch should address the concerns/comments below. Happy to address any 
additional comments, if there are any.

- Sunil

> -Original Message-
> From: Sunil Muthuswamy
> Sent: Monday, May 21, 2018 9:48 AM
> To: 'Greg KH' 
> Cc: de...@linuxdriverproject.org; Haiyang Zhang
> ; Stephen Hemminger
> 
> Subject: RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> The v2 patch that I sent was prior to responding to this thread. I am sending
> out v3 which addresses the comments here.
> 
> > -Original Message-
> > From: Greg KH 
> > Sent: Saturday, May 19, 2018 12:01 AM
> > To: Sunil Muthuswamy 
> > Cc: de...@linuxdriverproject.org; Haiyang Zhang
> > ; Stephen Hemminger
> > 
> > Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> > over Hyper-V during panic
> >
> > On Fri, May 18, 2018 at 09:00:51PM +, Sunil Muthuswamy wrote:
> > > Thanks, Greg.
> > >
> > > My first patch to the Linux kernel. Still making mistakes, but, learning
> > through the documented process.
> > >
> > > > -Original Message-
> > > > From: Greg KH 
> > > > Sent: Wednesday, May 9, 2018 11:51 PM
> > > > To: Sunil Muthuswamy 
> > > > Cc: Haiyang Zhang ;
> > > > de...@linuxdriverproject.org; Stephen Hemminger
> > > > 
> > > > Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg
> dump
> > > > over Hyper-V during panic
> > > >
> > > > On Wed, May 09, 2018 at 07:19:24PM +, Sunil Muthuswamy wrote:
> > > > > In the VM mode on Hyper-V, currently, when the kernel panics, an
> > error
> > > > > code and few register values are populated in an MSR and the
> > Hypervisor
> > > > > notified. This information is collected on the host. The amount of
> > > > > information currently collected is found to be limited and not 
> > > > > very
> > > > > actionable. To gather more actionable data, such as stack trace, 
> > > > > the
> > > > > proposal is to write one page worth of kmsg data on an allocated
> page
> > > > > and the Hypervisor notified of the page address through the MSR.
> > > >
> > > > Odd indentation, what editor made you do that?  Please move it all to
> the
> > > > left.
> > > I inserted them. Will fix.
> > > >
> > > > >
> > > > > CC: k...@microsoft.com
> > > > > CC: sthem...@microsoft.com
> > > > > Signed-off-by: Sunil Muthuswamy 
> > > > > ---
> > > > >  arch/x86/hyperv/hv_init.c  | 28 +
> > > > >  arch/x86/include/asm/hyperv-tlfs.h |  5 ++--
> > > > >  arch/x86/include/asm/mshyperv.h|  1 +
> > > > >  drivers/hv/vmbus_drv.c | 61
> > > > ++
> > > > >  4 files changed, 93 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> > > > > index cfecc22..88ee90d 100644
> > > > > --- a/arch/x86/hyperv/hv_init.c
> > > > > +++ b/arch/x86/hyperv/hv_init.c
> > > > > @@ -395,6 +395,34 @@ void hyperv_report_panic(struct pt_regs
> > *regs,
> > > > > long err)  }  EXPORT_SYMBOL_GPL(hyperv_report_panic);
> > > > >
> > > > > +void hyperv_report_panic_msg(phys_addr_t pa, size_t size) {
> > > > > + static bool panic_msg_reported;
> > > > > +
> > > > > + if (panic_msg_reported)
> > > > > + return;
> > > > > + panic_msg_reported = true;
> > > >
> > > > Why do you only care about the first message?
> > > It is following the general direction from ' hyperv_report_panic', but, I
> don't
> > think it needs to. Will change.
> > > >
> > > > > +
> > > > > + /*
> > > > > +  * P3 to contain the physical address of the panic page & P4 to
> > > > > +  * contain the size of the panic data in that page. Rest of the
> > > > > +  * registers are no-op when the NOTIFY_MSG flag is set.
> > > > > +  */
> > > > > + wrmsrl(HV_X64_MSR_CRASH_P0, 0);
> > > > > + wrmsrl(HV_X64_MSR_CRASH_P1, 0);
> > > > > + 

[PATCH v3] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-21 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

- Sysctl option to control the behavior, with ON by default.

Cc: K. Y. Srinivasan <k...@microsoft.com>
Cc: Stephen Hemminger <sthem...@microsoft.com>
Signed-off-by: Sunil Muthuswamy <sunil...@microsoft.com>
---
Changes since v1:
- Added a sysctl config option to allow the user to control if panic message
  should be reported to Hyper-V.

Changes since v2:
- Addressed comments from Greg KH.
- Moved the sysctl config option from 'kernel.hyperv' to 'kernel.' since the
  likelihood of having many Hyper-V specific sysctl config options seemed less
  and so having a specific dir for Hyper-V seemed unnecessary overhead.
---
 Documentation/sysctl/kernel.txt|  11 
 arch/x86/hyperv/hv_init.c  |  27 ++
 arch/x86/include/asm/hyperv-tlfs.h |   5 +-
 arch/x86/include/asm/mshyperv.h|   1 +
 drivers/hv/vmbus_drv.c | 108 +
 5 files changed, 150 insertions(+), 2 deletions(-)

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index eded671d..5958503 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -39,6 +39,7 @@ show up in /proc/sys/kernel:
 - hung_task_check_count
 - hung_task_timeout_secs
 - hung_task_warnings
+- hyperv_record_panic_msg
 - kexec_load_disabled
 - kptr_restrict
 - l2cr[ PPC only ]
@@ -374,6 +375,16 @@ This file shows up if CONFIG_DETECT_HUNG_TASK is enabled.
 
 ==
 
+hyperv_record_panic_msg:
+
+Controls whether the panic kmsg data should be reported to Hyper-V.
+
+0: do not report panic kmsg data.
+
+1: report the panic kmsg data. This is the default behavior.
+
+==
+
 kexec_load_disabled:
 
 A toggle indicating if the kexec_load syscall has been disabled. This
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..af57162 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,33 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+/**
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ */
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..76c58af 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG  BIT_ULL(62)
+#define HV_CRASH_CTL_CRASH_NOTIFY  BIT_ULL(63)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs, long err);
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size);
 bool hv_is_hyperv_initialized(void);
 void hyperv_cleanup(void);
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index b10fe26..16b0505 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -56,6 +56,8 @@ st

RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-21 Thread Sunil Muthuswamy
The v2 patch that I sent was prior to responding to this thread. I am sending 
out v3 which addresses the comments here.

> -Original Message-
> From: Greg KH <gre...@linuxfoundation.org>
> Sent: Saturday, May 19, 2018 12:01 AM
> To: Sunil Muthuswamy <sunil...@microsoft.com>
> Cc: de...@linuxdriverproject.org; Haiyang Zhang
> <haiya...@microsoft.com>; Stephen Hemminger
> <sthem...@microsoft.com>
> Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> On Fri, May 18, 2018 at 09:00:51PM +, Sunil Muthuswamy wrote:
> > Thanks, Greg.
> >
> > My first patch to the Linux kernel. Still making mistakes, but, learning
> through the documented process.
> >
> > > -Original Message-
> > > From: Greg KH <gre...@linuxfoundation.org>
> > > Sent: Wednesday, May 9, 2018 11:51 PM
> > > To: Sunil Muthuswamy <sunil...@microsoft.com>
> > > Cc: Haiyang Zhang <haiya...@microsoft.com>;
> > > de...@linuxdriverproject.org; Stephen Hemminger
> > > <sthem...@microsoft.com>
> > > Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> > > over Hyper-V during panic
> > >
> > > On Wed, May 09, 2018 at 07:19:24PM +, Sunil Muthuswamy wrote:
> > > > In the VM mode on Hyper-V, currently, when the kernel panics, an
> error
> > > > code and few register values are populated in an MSR and the
> Hypervisor
> > > > notified. This information is collected on the host. The amount of
> > > > information currently collected is found to be limited and not very
> > > > actionable. To gather more actionable data, such as stack trace, the
> > > > proposal is to write one page worth of kmsg data on an allocated 
> > > > page
> > > > and the Hypervisor notified of the page address through the MSR.
> > >
> > > Odd indentation, what editor made you do that?  Please move it all to the
> > > left.
> > I inserted them. Will fix.
> > >
> > > >
> > > > CC: k...@microsoft.com
> > > > CC: sthem...@microsoft.com
> > > > Signed-off-by: Sunil Muthuswamy <sunil...@microsoft.com>
> > > > ---
> > > >  arch/x86/hyperv/hv_init.c  | 28 +
> > > >  arch/x86/include/asm/hyperv-tlfs.h |  5 ++--
> > > >  arch/x86/include/asm/mshyperv.h|  1 +
> > > >  drivers/hv/vmbus_drv.c | 61
> > > ++
> > > >  4 files changed, 93 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> > > > index cfecc22..88ee90d 100644
> > > > --- a/arch/x86/hyperv/hv_init.c
> > > > +++ b/arch/x86/hyperv/hv_init.c
> > > > @@ -395,6 +395,34 @@ void hyperv_report_panic(struct pt_regs
> *regs,
> > > > long err)  }  EXPORT_SYMBOL_GPL(hyperv_report_panic);
> > > >
> > > > +void hyperv_report_panic_msg(phys_addr_t pa, size_t size) {
> > > > +   static bool panic_msg_reported;
> > > > +
> > > > +   if (panic_msg_reported)
> > > > +   return;
> > > > +   panic_msg_reported = true;
> > >
> > > Why do you only care about the first message?
> > It is following the general direction from ' hyperv_report_panic', but, I 
> > don't
> think it needs to. Will change.
> > >
> > > > +
> > > > +   /*
> > > > +* P3 to contain the physical address of the panic page & P4 to
> > > > +* contain the size of the panic data in that page. Rest of the
> > > > +* registers are no-op when the NOTIFY_MSG flag is set.
> > > > +*/
> > > > +   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
> > > > +   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
> > > > +   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
> > > > +   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
> > > > +   wrmsrl(HV_X64_MSR_CRASH_P4, size);
> > > > +
> > > > +   /*
> > > > +* Let Hyper-V know there is crash data available along with
> > > > +* the panic message.
> > > > +*/
> > > > +   wrmsrl(HV_X64_MSR_CRASH_CTL,
> > > > +  (HV_CRASH_CTL_CRASH_NOTIFY |
> > > HV_CRASH_CTL_CRASH_NOTIFY_MSG));
> > > > +} EXPORT_SYMBOL_GPL(hyperv_report_p

RE: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-18 Thread Sunil Muthuswamy
Thanks, Greg.

My first patch to the Linux kernel. Still making mistakes, but, learning 
through the documented process.

> -Original Message-
> From: Greg KH <gre...@linuxfoundation.org>
> Sent: Wednesday, May 9, 2018 11:51 PM
> To: Sunil Muthuswamy <sunil...@microsoft.com>
> Cc: Haiyang Zhang <haiya...@microsoft.com>;
> de...@linuxdriverproject.org; Stephen Hemminger
> <sthem...@microsoft.com>
> Subject: Re: [PATCH v1] Drivers: HV: Send one page worth of kmsg dump
> over Hyper-V during panic
> 
> On Wed, May 09, 2018 at 07:19:24PM +, Sunil Muthuswamy wrote:
> > In the VM mode on Hyper-V, currently, when the kernel panics, an error
> > code and few register values are populated in an MSR and the Hypervisor
> > notified. This information is collected on the host. The amount of
> > information currently collected is found to be limited and not very
> > actionable. To gather more actionable data, such as stack trace, the
> > proposal is to write one page worth of kmsg data on an allocated page
> > and the Hypervisor notified of the page address through the MSR.
> 
> Odd indentation, what editor made you do that?  Please move it all to the
> left.
I inserted them. Will fix.
> 
> >
> > CC: k...@microsoft.com
> > CC: sthem...@microsoft.com
> > Signed-off-by: Sunil Muthuswamy <sunil...@microsoft.com>
> > ---
> >  arch/x86/hyperv/hv_init.c  | 28 +
> >  arch/x86/include/asm/hyperv-tlfs.h |  5 ++--
> >  arch/x86/include/asm/mshyperv.h|  1 +
> >  drivers/hv/vmbus_drv.c | 61
> ++
> >  4 files changed, 93 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> > index cfecc22..88ee90d 100644
> > --- a/arch/x86/hyperv/hv_init.c
> > +++ b/arch/x86/hyperv/hv_init.c
> > @@ -395,6 +395,34 @@ void hyperv_report_panic(struct pt_regs *regs,
> > long err)  }  EXPORT_SYMBOL_GPL(hyperv_report_panic);
> >
> > +void hyperv_report_panic_msg(phys_addr_t pa, size_t size) {
> > +   static bool panic_msg_reported;
> > +
> > +   if (panic_msg_reported)
> > +   return;
> > +   panic_msg_reported = true;
> 
> Why do you only care about the first message?
It is following the general direction from ' hyperv_report_panic', but, I don't 
think it needs to. Will change.
> 
> > +
> > +   /*
> > +* P3 to contain the physical address of the panic page & P4 to
> > +* contain the size of the panic data in that page. Rest of the
> > +* registers are no-op when the NOTIFY_MSG flag is set.
> > +*/
> > +   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
> > +   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
> > +   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
> > +   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
> > +   wrmsrl(HV_X64_MSR_CRASH_P4, size);
> > +
> > +   /*
> > +* Let Hyper-V know there is crash data available along with
> > +* the panic message.
> > +*/
> > +   wrmsrl(HV_X64_MSR_CRASH_CTL,
> > +  (HV_CRASH_CTL_CRASH_NOTIFY |
> HV_CRASH_CTL_CRASH_NOTIFY_MSG));
> > +} EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
> > +
> >  bool hv_is_hyperv_initialized(void)
> >  {
> > union hv_x64_msr_hypercall_contents hypercall_msr; diff --git
> > a/arch/x86/include/asm/hyperv-tlfs.h
> > b/arch/x86/include/asm/hyperv-tlfs.h
> > index 416cb0e..fc2932c 100644
> > --- a/arch/x86/include/asm/hyperv-tlfs.h
> > +++ b/arch/x86/include/asm/hyperv-tlfs.h
> > @@ -171,9 +171,10 @@
> >  #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
> >
> >  /*
> > - * Crash notification flag.
> > + * Crash notification flags.
> >   */
> > -#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
> > +#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
> > +#define HV_CRASH_CTL_CRASH_NOTIFY_MSG (1ULL << 62)
> 
> Not in numerical order?
> 
> And can you use the BIT() macro here instead?  Not a requirement, just a
> general question.
Will change in the next version.
> 
> >
> >  /* MSR used to identify the guest OS. */
> >  #define HV_X64_MSR_GUEST_OS_ID 0x4000
> > diff --git a/arch/x86/include/asm/mshyperv.h
> > b/arch/x86/include/asm/mshyperv.h index b90e796..ac83f2d 100644
> > --- a/arch/x86/include/asm/mshyperv.h
> > +++ b/arch/x86/include/asm/mshyperv.h
> > @@ -262,6 +262,7 @@ void hyperv_init(void);  void
> > hyperv_setup_mmu_ops(void);  void hyper_alloc_mmu(void);  void
> > hyperv_report_p

[PATCH v2] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-18 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

- Added a sysctl option to control the behavior, with ON by default.

CC: k...@microsoft.com
CC: sthem...@microsoft.com
Signed-off-by: Sunil Muthuswamy <sunil...@microsoft.com>
---
 arch/x86/hyperv/hv_init.c  |  35 ++
 arch/x86/include/asm/hyperv-tlfs.h |   5 +-
 arch/x86/include/asm/mshyperv.h|   1 +
 drivers/hv/vmbus_drv.c | 128 +
 4 files changed, 167 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..fc1e3cb 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,41 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+/**
+ * hyperv_report_panic_msg - report panic message to Hyper-V
+ * @pa: physical address of the panic page containing the message
+ * @size: size of the message in the page
+ *
+ */
+
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   static bool panic_msg_reported;
+
+   if (panic_msg_reported)
+   return;
+   panic_msg_reported = true;
+
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..fc2932c 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG (1ULL << 62)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs, long err);
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size);
 bool hv_is_hyperv_initialized(void);
 void hyperv_cleanup(void);
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index b10fe26..7b04f7f 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -56,6 +56,8 @@ static struct completion probe_event;
 
 static int hyperv_cpuhp_online;
 
+static void *hv_panic_page;
+
 static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
  void *args)
 {
@@ -1018,6 +1020,86 @@ static void vmbus_isr(void)
add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
 }
 
+/*
+ * Boolean to control whether to report panic messages over Hyper-V.
+ *
+ * It can be set via /proc/sys/kernel/hyperv/record_panic_msg
+ */
+int sysctl_record_panic_msg = 1;
+
+/*
+ * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg
+ * buffer and call into Hyper-V to transfer the data.
+ */
+static void hv_kmsg_dump(struct kmsg_dumper *dumper,
+enum kmsg_dump_reason reason)
+{
+   size_t bytes_written;
+   phys_addr_t panic_pa;
+
+   /* We are only interested in panics. */
+   if (reason != KMSG_DUMP_PANIC)
+   return;
+
+   if (!sysctl_record_panic_msg)
+   return;
+
+   if (!hv_panic_page)
+   return;
+
+   panic_pa = virt_to_phys(hv_panic_page);
+
+   /*
+* Write dump contents to the page. No need to synchronize; panic should
+* be single-threaded.
+*/
+   if (

[PATCH v1] Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic

2018-05-09 Thread Sunil Muthuswamy
In the VM mode on Hyper-V, currently, when the kernel panics, an error
code and few register values are populated in an MSR and the Hypervisor
notified. This information is collected on the host. The amount of
information currently collected is found to be limited and not very
actionable. To gather more actionable data, such as stack trace, the
proposal is to write one page worth of kmsg data on an allocated page
and the Hypervisor notified of the page address through the MSR.

CC: k...@microsoft.com
CC: sthem...@microsoft.com
Signed-off-by: Sunil Muthuswamy <sunil...@microsoft.com>
---
 arch/x86/hyperv/hv_init.c  | 28 +
 arch/x86/include/asm/hyperv-tlfs.h |  5 ++--
 arch/x86/include/asm/mshyperv.h|  1 +
 drivers/hv/vmbus_drv.c | 61 ++
 4 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index cfecc22..88ee90d 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -395,6 +395,34 @@ void hyperv_report_panic(struct pt_regs *regs, long err)
 }
 EXPORT_SYMBOL_GPL(hyperv_report_panic);
 
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size)
+{
+   static bool panic_msg_reported;
+
+   if (panic_msg_reported)
+   return;
+   panic_msg_reported = true;
+
+   /*
+* P3 to contain the physical address of the panic page & P4 to
+* contain the size of the panic data in that page. Rest of the
+* registers are no-op when the NOTIFY_MSG flag is set.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_P0, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P1, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P2, 0);
+   wrmsrl(HV_X64_MSR_CRASH_P3, pa);
+   wrmsrl(HV_X64_MSR_CRASH_P4, size);
+
+   /*
+* Let Hyper-V know there is crash data available along with
+* the panic message.
+*/
+   wrmsrl(HV_X64_MSR_CRASH_CTL,
+  (HV_CRASH_CTL_CRASH_NOTIFY | HV_CRASH_CTL_CRASH_NOTIFY_MSG));
+}
+EXPORT_SYMBOL_GPL(hyperv_report_panic_msg);
+
 bool hv_is_hyperv_initialized(void)
 {
union hv_x64_msr_hypercall_contents hypercall_msr;
diff --git a/arch/x86/include/asm/hyperv-tlfs.h 
b/arch/x86/include/asm/hyperv-tlfs.h
index 416cb0e..fc2932c 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -171,9 +171,10 @@
 #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED(1 << 14)
 
 /*
- * Crash notification flag.
+ * Crash notification flags.
  */
-#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)
+#define HV_CRASH_CTL_CRASH_NOTIFY_MSG (1ULL << 62)
 
 /* MSR used to identify the guest OS. */
 #define HV_X64_MSR_GUEST_OS_ID 0x4000
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index b90e796..ac83f2d 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -262,6 +262,7 @@ void hyperv_init(void);
 void hyperv_setup_mmu_ops(void);
 void hyper_alloc_mmu(void);
 void hyperv_report_panic(struct pt_regs *regs, long err);
+void hyperv_report_panic_msg(phys_addr_t pa, size_t size);
 bool hv_is_hyperv_initialized(void);
 void hyperv_cleanup(void);
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index b10fe26..40d915c 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -56,6 +56,8 @@ static struct completion probe_event;
 
 static int hyperv_cpuhp_online;
 
+static void *hv_panic_page;
+
 static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
  void *args)
 {
@@ -1018,6 +1020,41 @@ static void vmbus_isr(void)
add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
 }
 
+/*
+ * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg
+ * buffer and call into Hyper-V to transfer the data.
+ */
+static void hv_kmsg_dump(struct kmsg_dumper *dumper,
+enum kmsg_dump_reason reason)
+{
+   size_t bytes_written;
+   phys_addr_t panic_pa;
+
+   /* We are only interested in panics. */
+   if (reason != KMSG_DUMP_PANIC)
+   return;
+
+   if (!hv_panic_page)
+   return;
+
+   panic_pa = virt_to_phys(hv_panic_page);
+
+   /*
+* Write dump contents to the page. No need to synchronize; panic should
+* be single-threaded.
+*/
+   if (!kmsg_dump_get_buffer(dumper, true, hv_panic_page,
+ PAGE_SIZE, _written)) {
+   pr_err("Hyper-V - Unable to get kmsg data for panic\n");
+   return;
+   }
+
+   hyperv_report_panic_msg(panic_pa, bytes_written);
+}
+
+static struct kmsg_dumper hv_kmsg_dumper = {
+   .dump = hv_kmsg_dump,
+};
 
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
@@ -1065,6 +1102,19 @@ static int v