KVM: PPC: Book3E: KVM HV host module doesn't work anymore

2024-12-31 Thread Christian Zigotzky

Hi All,

I have compiled the RC5 of kernel 6.13 [1] with the latest revert patch. [2]

After that, I successfully tested the following QEMU/KVM HV components.

- Guest performance: good
- Guest boot time: short
- KVM HV works (-enable-kvm)
- SMP works (-smp 4)
- QEMU User Networking (SLIRP) via VirtIO_net works (Tested it with SSH 
and with a web browser)

- QEMU USB Audio works (Tested it with some audio files in the guest system)
- VirtIO GPU works
- Virtual mouse and keyboard controller works (VirtIO input)
- 9p mount of a host folder via VirtIO works in the guest system
- Serial output from the guest works (console=ttyS0,115200)
- Shutdown and reboot works

The issue still exists but I hope Paolo's patch can fix the issue. [3]

Cheers,
Christian

[1] https://github.com/chzigotzky/kernels/releases/tag/v6.13.0-rc5
[2] 
https://github.com/chzigotzky/kernels/blob/main/patches/X5000/kvm_ppc_revert.patch

[3] https://github.com/chzigotzky/kernels/issues/4

--
Sent with BrassMonkey 33.4.0 
(https://github.com/wicknix/brass-monkey/releases/tag/33.4.0)




Re: [PATCH v2 0/3] sysfs: constify bin_attribute argument of sysfs_bin_attr_simple_read()

2024-12-31 Thread Thomas Weißschuh
On 2024-12-30 16:50:41-0800, Alexei Starovoitov wrote:
> On Sat, Dec 28, 2024 at 12:43 AM Thomas Weißschuh  
> wrote:
> >
> > Most users use this function through the BIN_ATTR_SIMPLE* macros,
> > they can handle the switch transparently.
> >
> > This series is meant to be merged through the driver core tree.
> 
> hmm. why?

Patch 1 changes the signature of sysfs_bin_attr_simple_read().
Before patch 1 sysfs_bin_attr_simple_read() needs to be assigned to the
callback member .read, after patch 1 it's .read_new.
(Both callbacks work exactly the same, except for their signature,
.read_new is only a transition mechanism and will go away again)

> I'd rather take patches 2 and 3 into bpf-next to avoid
> potential conflicts.
> Patch 1 looks orthogonal and independent.

If you pick up 2 and 3 through bpf-next you would need to adapt these
assignments. As soon as both patch 1 and the modified 2 and 3 hit
Linus' tree, the build would break due to mismatches function pointers.
(Casting function pointers to avoid the mismatch will blow up with KCFI)
Of course Linus can fix this up easily, but it somebody would need to
keep track of it and I wanted to avoid manual intervention.
Or we spread out both parts over two development cycles; maybe Greg can
even pick up patch 1 late in the 6.13 cycle.

Personally I am fine with any approach.



[PATCH v5 2/3] powerpc/pseries: Export hardware trace macro dump via debugfs

2024-12-31 Thread Abhishek Dubey
This patch adds debugfs interface to export Hardware Trace Macro (HTM)
function data in a LPAR. New hypervisor call "H_HTM" has been
defined to setup, configure, control and dump the HTM data.
This patch supports only dumping of HTM data in a LPAR.
New debugfs folder called "htmdump" has been added under
/sys/kernel/debug/arch path which contains files need to
pass required parameters for the H_HTM dump function. New Kconfig
option called "CONFIG_HTMDUMP" introduced in platform/pseries for the same.

With this module loaded, list of files in debugfs path

/sys/kernel/debug/powerpc/htmdump
coreindexonchip  htmtype  nodalchipindex  nodeindex  trace

Changelog:
  v4->v5 : Removed offset from available calculation, as offset is
   always zero leading to buffur size reads.
   Edited comments and commit message

v3 patch:
  
https://lore.kernel.org/linuxppc-dev/20240828085223.42177-2-ma...@linux.ibm.com/

Signed-off-by: Abhishek Dubey 
Co-developed-by: Madhavan Srinivasan 
Signed-off-by: Madhavan Srinivasan 
---
 arch/powerpc/platforms/pseries/Kconfig   |   9 ++
 arch/powerpc/platforms/pseries/Makefile  |   1 +
 arch/powerpc/platforms/pseries/htmdump.c | 120 +++
 3 files changed, 130 insertions(+)
 create mode 100644 arch/powerpc/platforms/pseries/htmdump.c

diff --git a/arch/powerpc/platforms/pseries/Kconfig 
b/arch/powerpc/platforms/pseries/Kconfig
index afc0f6a61337..e0fcd4bef986 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -128,6 +128,15 @@ config CMM
  will be reused for other LPARs. The interface allows firmware to
  balance memory across many LPARs.
 
+config HTMDUMP
+   tristate "PowerVM data dumper"
+   depends on PPC_PSERIES && DEBUG_FS
+   default m
+   help
+ Select this option, if you want to enable the kernel debugfs
+ interface to dump the Hardware Trace Macro (HTM) function data
+ in the LPAR.
+
 config HV_PERF_CTRS
bool "Hypervisor supplied PMU events (24x7 & GPCI)"
default y
diff --git a/arch/powerpc/platforms/pseries/Makefile 
b/arch/powerpc/platforms/pseries/Makefile
index 7bf506f6b8c8..3f3e3492e436 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o
 obj-$(CONFIG_HVCS) += hvcserver.o
 obj-$(CONFIG_HCALL_STATS)  += hvCall_inst.o
 obj-$(CONFIG_CMM)  += cmm.o
+obj-$(CONFIG_HTMDUMP)  += htmdump.o
 obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o
 obj-$(CONFIG_LPARCFG)  += lparcfg.o
 obj-$(CONFIG_IBMVIO)   += vio.o
diff --git a/arch/powerpc/platforms/pseries/htmdump.c 
b/arch/powerpc/platforms/pseries/htmdump.c
new file mode 100644
index ..9ba0507e54d7
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/htmdump.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) IBM Corporation, 2024
+ */
+
+#define pr_fmt(fmt) "htmdump: " fmt
+
+#include 
+#include 
+#include 
+#include 
+
+static void *htm_buf;
+static u32 nodeindex;
+static u32 nodalchipindex;
+static u32 coreindexonchip;
+static u32 htmtype;
+static struct dentry *htmdump_debugfs_dir;
+
+static ssize_t htmdump_read(struct file *filp, char __user *ubuf,
+size_t count, loff_t *ppos)
+{
+   void *htm_buf = filp->private_data;
+   unsigned long page, read_size, available;
+   loff_t offset;
+   long rc;
+
+   page = ALIGN_DOWN(*ppos, PAGE_SIZE);
+   offset = (*ppos) % PAGE_SIZE;
+
+   rc = htm_get_dump_hardware(nodeindex, nodalchipindex, coreindexonchip,
+  htmtype, virt_to_phys(htm_buf), PAGE_SIZE, 
page);
+
+   switch (rc) {
+   case H_SUCCESS:
+   /* H_PARTIAL for the case where all available data can't be
+* returned due to buffer size constraint.
+*/
+   case H_PARTIAL:
+   break;
+   /* H_NOT_AVAILABLE indicates reading from an offset outside the range,
+* i.e. past end of file.
+*/
+   case H_NOT_AVAILABLE:
+   return 0;
+   case H_BUSY:
+   case H_LONG_BUSY_ORDER_1_MSEC:
+   case H_LONG_BUSY_ORDER_10_MSEC:
+   case H_LONG_BUSY_ORDER_100_MSEC:
+   case H_LONG_BUSY_ORDER_1_SEC:
+   case H_LONG_BUSY_ORDER_10_SEC:
+   case H_LONG_BUSY_ORDER_100_SEC:
+   return -EBUSY;
+   case H_PARAMETER:
+   case H_P2:
+   case H_P3:
+   case H_P4:
+   case H_P5:
+   case H_P6:
+   return -EINVAL;
+   case H_STATE:
+   return -EIO;
+   case H_AUTHORITY:
+   return -EPERM;
+   }
+
+   available = PAGE_SIZE;
+   read_size = min(count, available);
+   *ppos += read_size;
+   return simple_read_from_buffer(ubuf, count, &offset, htm_buf, 
available);
+}
+
+static const struct file_operations htmdump_fops = 

[PATCH v5 1/3] powerpc/pseries: Macros and wrapper functions for H_HTM call

2024-12-31 Thread Abhishek Dubey
Define macros and wrapper functions to handle
H_HTM (Hardware Trace Macro) hypervisor call.
H_HTM is new HCALL added to export data from
Hardware Trace Macro (HTM) function.

v3 patch:
  
https://lore.kernel.org/linuxppc-dev/20240828085223.42177-1-ma...@linux.ibm.com/

Signed-off-by: Abhishek Dubey 
Co-developed-by: Madhavan Srinivasan 
Signed-off-by: Madhavan Srinivasan 
---
 arch/powerpc/include/asm/hvcall.h | 34 +++
 arch/powerpc/include/asm/plpar_wrappers.h | 21 ++
 2 files changed, 55 insertions(+)

diff --git a/arch/powerpc/include/asm/hvcall.h 
b/arch/powerpc/include/asm/hvcall.h
index 7a8495660c2f..7ad13685c127 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -348,6 +348,7 @@
 #define H_SCM_FLUSH0x44C
 #define H_GET_ENERGY_SCALE_INFO0x450
 #define H_PKS_SIGNED_UPDATE0x454
+#define H_HTM  0x458
 #define H_WATCHDOG 0x45C
 #define H_GUEST_GET_CAPABILITIES 0x460
 #define H_GUEST_SET_CAPABILITIES 0x464
@@ -497,6 +498,39 @@
 #define H_GUEST_CAP_POWER10(1UL<<(63-2))
 #define H_GUEST_CAP_BITMAP2(1UL<<(63-63))
 
+/*
+ * Defines for H_HTM - Macros for hardware trace macro (HTM) function.
+ */
+#define H_HTM_FLAGS_HARDWARE_TARGET(1ul << 63)
+#define H_HTM_FLAGS_LOGICAL_TARGET (1ul << 62)
+#define H_HTM_FLAGS_PROCID_TARGET  (1ul << 61)
+#define H_HTM_FLAGS_NOWRAP (1ul << 60)
+
+#define H_HTM_OP_SHIFT (63-15)
+#define H_HTM_OP(x)((unsigned long)(x)<
 
diff --git a/arch/powerpc/include/asm/plpar_wrappers.h 
b/arch/powerpc/include/asm/plpar_wrappers.h
index 71648c126970..a63a4d29cfdf 100644
--- a/arch/powerpc/include/asm/plpar_wrappers.h
+++ b/arch/powerpc/include/asm/plpar_wrappers.h
@@ -65,6 +65,27 @@ static inline long register_dtl(unsigned long cpu, unsigned 
long vpa)
return vpa_call(H_VPA_REG_DTL, cpu, vpa);
 }
 
+static inline long htm_call(unsigned long flags, unsigned long target,
+   unsigned long operation, unsigned long param1,
+   unsigned long param2, unsigned long param3)
+{
+   return plpar_hcall_norets(H_HTM, flags, target, operation,
+ param1, param2, param3);
+}
+
+static inline long htm_get_dump_hardware(unsigned long nodeindex,
+   unsigned long nodalchipindex, unsigned long coreindexonchip,
+   unsigned long type, unsigned long addr, unsigned long size,
+   unsigned long offset)
+{
+   return htm_call(H_HTM_FLAGS_HARDWARE_TARGET,
+   H_HTM_TARGET_NODE_INDEX(nodeindex) |
+   H_HTM_TARGET_NODAL_CHIP_INDEX(nodalchipindex) |
+   H_HTM_TARGET_CORE_INDEX_ON_CHIP(coreindexonchip),
+   H_HTM_OP(H_HTM_OP_DUMP_DATA) | H_HTM_TYPE(type),
+   addr, size, offset);
+}
+
 extern void vpa_init(int cpu);
 
 static inline long plpar_pte_enter(unsigned long flags,
-- 
2.44.0




[PATCH v5 3/3] powerpc: Document details on H_HTM hcall

2024-12-31 Thread Abhishek Dubey
Add documentation to 'papr_hcalls.rst' describing the
input, output and return values of the H_HTM hcall as
per the internal specification.

v3 patch:
  
https://lore.kernel.org/linuxppc-dev/20240828085223.42177-3-ma...@linux.ibm.com/

Signed-off-by: Abhishek Dubey 
Co-developed-by: Madhavan Srinivasan 
Signed-off-by: Madhavan Srinivasan 
---
 Documentation/arch/powerpc/papr_hcalls.rst | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/arch/powerpc/papr_hcalls.rst 
b/Documentation/arch/powerpc/papr_hcalls.rst
index 80d2c0aadab5..805e1cb9bab9 100644
--- a/Documentation/arch/powerpc/papr_hcalls.rst
+++ b/Documentation/arch/powerpc/papr_hcalls.rst
@@ -289,6 +289,17 @@ to be issued multiple times in order to be completely 
serviced. The
 subsequent hcalls to the hypervisor until the hcall is completely serviced
 at which point H_SUCCESS or other error is returned by the hypervisor.
 
+**H_HTM**
+
+| Input: flags, target, operation (op), op-param1, op-param2, op-param3
+| Out: *dumphtmbufferdata*
+| Return Value: *H_Success,H_Busy,H_LongBusyOrder,H_Partial,H_Parameter,
+H_P2,H_P3,H_P4,H_P5,H_P6,H_State,H_Not_Available,H_Authority*
+
+H_HTM supports setup, configuration, control and dumping of Hardware Trace
+Macro (HTM) function and its data. HTM buffer stores tracing data for functions
+like core instruction, core LLAT and nest.
+
 References
 ==
 .. [1] "Power Architecture Platform Reference"
-- 
2.44.0




[PATCH] KVM: allow NULL writable argument to __kvm_faultin_pfn

2024-12-31 Thread Paolo Bonzini
kvm_follow_pfn() is able to work with NULL in the .map_writable field
of the homonymous struct.  But __kvm_faultin_pfn() rejects the combo
despite KVM for e500 trying to use it.  Indeed .map_writable is not
particularly useful if the flags include FOLL_WRITE and readonly
guest memory is not supported, so add support to __kvm_faultin_pfn()
for this case.

Fixes: 1c7b627e9306 ("KVM: Add kvm_faultin_pfn() to specifically service guest 
page faults")
Reported-by: Christian Zigotzky 
Tested-by: Christian Zigotzky 
Cc: linuxppc-dev@lists.ozlabs.org
Cc: regressi...@lists.linux.dev
Signed-off-by: Paolo Bonzini 
---
 virt/kvm/kvm_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index de2c11dae231..5177e56fdbd5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2975,10 +2975,11 @@ kvm_pfn_t __kvm_faultin_pfn(const struct 
kvm_memory_slot *slot, gfn_t gfn,
.refcounted_page = refcounted_page,
};
 
-   if (WARN_ON_ONCE(!writable || !refcounted_page))
+   if (WARN_ON_ONCE(!refcounted_page))
return KVM_PFN_ERR_FAULT;
 
-   *writable = false;
+   if (writable)
+   *writable = false;
*refcounted_page = NULL;
 
return kvm_follow_pfn(&kfp);
-- 
2.43.5