powerpc/vas: Page fault handling for user space NX requests
Subsystems (2)
v3 cover powerpc/vas: Page fault handling for user space NX requests
On power9, Virtual Accelerator Switchboard (VAS) allows user space or kernel to communicate with Nest Accelerator (NX) directly using COPY/PASTE instructions. NX provides verious functionalities such as compression, encryption and etc. But only compression (842 and GZIP formats) is supported in Linux kernel on power9.
842 compression driver (drivers/crypto/nx/nx-842-powernv.c) is already included in Linux. Only GZIP support will be available from user space.
Applications can issue GZIP compression / decompression requests to NX with COPY/PASTE instructions. When NX is processing these requests, can hit fault on the request buffer (not in memory). It issues an interrupt and pastes fault CRB in fault FIFO. Expects kernel to handle this fault and return credits for both send and fault windows after processing.
This patch series adds IRQ and fault window setup, and NX fault handling:
- Read IRQ# from "interrupts" property and configure IRQ per VAS instance.
- Set port# for each window to generate an interrupt when noticed fault.
- Set fault window and FIFO on which NX paste fault CRB.
- Setup IRQ thread fault handler per VAS instance.
- When receiving an interrupt, Read CRBs from fault FIFO and update coprocessor_status_block (CSB) in the corresponding CRB with translation failure (CSB_CC_TRANSLATION). After issuing NX requests, process polls on CSB address. When it sees translation error, can touch the request buffer to bring the page in to memory and reissue NX request.
- If copy_to_user fails on user space CSB address, OS sends SEGV signal.
Tested these patches with NX-GZIP support and will be posting this series soon.
Patch 2: Define nx_fault_stamp on which NX writes fault status for the fault
CRB
Patch 3: Read interrupts and port properties per VAS instance Patch 4: Setup fault window per each VAS instance. This window is used for
NX to paste fault CRB in FIFO.
Patches 5 & 6: Setup threaded IRQ per VAS and register NX with fault window
ID and port number for each send window so that NX paste fault CRB in this window.
Patch 7: Reference to pid and mm so that pid is not used until window closed.
Needed for multi thread application where child can open a window and can be used by parent later.
Patches 8 and 9: Process CRBs from fault FIFO and notify tasks by
updating CSB or through signals.
Patches 10 and 11: Return credits for send and fault windows after handling
faults.
Patch 13:Fix closing send window after all credits are returned. This issue
happens only for user space requests. No page faults on kernel request buffer.
Changelog:
V2:
- Use threaded IRQ instead of own kernel thread handler
- Use pswid insted of user space CSB address to find valid CRB
- Removed unused macros and other changes as suggested by Christoph Hellwig
V3:
- Rebased to 5.5-rc2
- Use struct pid * instead of pid_t for vas_window tgid
- Code cleanup as suggested by Christoph Hellwig
Haren Myneni (13):
powerpc/vas: Describe vas-port and interrupts properties powerpc/vas: Define nx_fault_stamp in coprocessor_request_block powerpc/vas: Read interrupts and vas-port device tree properties powerpc/vas: Setup fault window per VAS instance powerpc/vas: Setup thread IRQ handler per VAS instance powerpc/vas: Register NX with fault window ID and IRQ port value powerpc/vas: Take reference to PID and mm for user space windows powerpc/vas: Update CSB and notify process for fault CRBs powerpc/vas: Print CRB and FIFO values
powerpc/vas: Do not use default credits for receive window powerpc/VAS: Return credits after handling fault powerpc/vas: Display process stuck message
powerpc/vas: Free send window in VAS instance after credits returned
.../devicetree/bindings/powerpc/ibm,vas.txt | 5 + arch/powerpc/include/asm/icswx.h | 18 +- arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/vas-debug.c | 2 +- arch/powerpc/platforms/powernv/vas-fault.c | 328 +++++++++++++++++++++ arch/powerpc/platforms/powernv/vas-window.c | 182 +++++++++++- arch/powerpc/platforms/powernv/vas.c | 79 ++++- arch/powerpc/platforms/powernv/vas.h | 38 ++- scripts/pnmtologo | Bin 0 -> 71976 bytes 9 files changed, 628 insertions(+), 26 deletions(-) create mode 100644 arch/powerpc/platforms/powernv/vas-fault.c create mode 100755 scripts/pnmtologo
Signature · 1 line
1.8.3.1
PATCH v3 1/13 powerpc/vas: Describe vas-port and interrupts properties
--- Documentation/devicetree/bindings/powerpc/ibm,vas.txt | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/powerpc/ibm,vas.txt +5 -0
@@ -11,6 +11,8 @@ Required properties: window context start and length, OS/User window context start and length, "Paste address" start and length, "Paste window id" start bit and number of bits) +- ibm,vas-port : Port address for the interrupt. +- interrupts: IRQ value for each VAS instance and level. Example:
@@ -18,5 +20,8 @@ Example: compatible = "ibm,vas", "ibm,power9-vas"; reg = <0x6019100000000 0x2000000 0x6019000000000 0x100000000 0x8000000000000 0x100000000 0x20 0x10>; name = "vas"; + interrupts = <0x1f 0>; + interrupt-parent = <&mpic>; ibm,vas-id = <0x1>; + ibm,vas-port = <0x6010001000000>; };
Signature · 1 line
1.8.3.1
Rob Herring
maintainerRe: [PATCH V3 01/13] powerpc/vas: Describe vas-port and interrupts properties
Quoted 1 line · Haren Myneni
Commit message?
Quoted 1 line
Signed-off-by Haren Myneni <[email protected]>
Your author and S-o-b emails don't match.
Documentation/devicetree/bindings/powerpc/ibm,vas.txt Required properties: · line 14
Quoted 13 lines
--- Documentation/devicetree/bindings/powerpc/ibm,vas.txt | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/powerpc/ibm,vas.txt +1
-0@@ -11,6 +11,8 @@ Required properties: window context start and length, OS/User window context start and length, "Paste address" start and length, "Paste window id" start bit and number of bits) +- ibm,vas-port : Port address for the interrupt.
64-bit?
Quoted 18 lines
Documentation/devicetree/bindings/powerpc/ibm,vas.txt +4
-0+- interrupts: IRQ value for each VAS instance and level. Example:@@ -18,5 +20,8 @@ Example: compatible = "ibm,vas", "ibm,power9-vas"; reg = <0x6019100000000 0x2000000 0x6019000000000 0x100000000 0x8000000000000 0x100000000 0x20 0x10>; name = "vas"; + interrupts = <0x1f 0>; + interrupt-parent = <&mpic>; ibm,vas-id = <0x1>; + ibm,vas-port = <0x6010001000000>; };Signature · 1 line
1.8.3.1
Re: [PATCH V3 01/13] powerpc/vas: Describe vas-port and interrupts properties
Quoted 8 lines · Rob Herring
Quoted 1 line · Haren Myneni
Commit message?
Quoted 1 line
Signed-off-by Haren Myneni <[email protected]>Your author and S-o-b emails don't match.
Thanks, Oliver suggested IRQ assign in the kernel instead of skiboot. In this case, we may not need this patch.
Quoted 35 lines
Quoted 10 lines
--- Documentation/devicetree/bindings/powerpc/ibm,vas.txt | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/powerpc/ibm,vas.txt +0
-0Documentation/devicetree/bindings/powerpc/ibm,vas.txt Required properties: · line 14
Quoted 4 lines
Documentation/devicetree/bindings/powerpc/ibm,vas.txt +1
-0@@ -11,6 +11,8 @@ Required properties: window context start and length, OS/User window context start and length, "Paste address" start and length, "Paste window id" start bit and number of bits) +- ibm,vas-port : Port address for the interrupt.64-bit?
Quoted 18 lines
Documentation/devicetree/bindings/powerpc/ibm,vas.txt +4
-0+- interrupts: IRQ value for each VAS instance and level. Example:@@ -18,5 +20,8 @@ Example: compatible = "ibm,vas", "ibm,power9-vas"; reg = <0x6019100000000 0x2000000 0x6019000000000 0x100000000 0x8000000000000 0x100000000 0x20 0x10>; name = "vas"; + interrupts = <0x1f 0>; + interrupt-parent = <&mpic>; ibm,vas-id = <0x1>; + ibm,vas-port = <0x6010001000000>; };Signature · 1 line
1.8.3.1
PATCH v3 2/13 powerpc/vas: Define nx_fault_stamp in coprocessor_request_block
In reply to Haren MyneniKernel sets fault address and status in CRB for NX page fault on user space address after processing page fault. User space gets the signal and handles the fault mentioned in CRB by bringing the page in to memory and send NX request again.
--- arch/powerpc/include/asm/icswx.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/icswx.h +17 -1
@@ -108,6 +108,17 @@ struct data_descriptor_entry {__be64 address; } __packed__aligned(DDE_ALIGN) ; +/* 4.3.2 NX-stamped Fault CRB */ + +#define NX_STAMP_ALIGN (0x10) + +struct nx_fault_stamp { +__be64 fault_storage_addr; +__be16 reserved; +__u8 flags; +__u8 fault_status; +__be32 pswid; +} __packed__aligned(NX_STAMP_ALIGN) ;/* Chapter 6.5.2 Coprocessor-Request Block (CRB) */
@@ -135,7 +146,12 @@ struct coprocessor_request_block {struct coprocessor_completion_block ccb; -u8 reserved[48 ]; +union { +struct nx_fault_stamp nx; +u8 reserved[16 ]; + } stamp; + +u8 reserved[32 ];struct coprocessor_status_block csb; } __packed__aligned(CRB_ALIGN) ;
Signature · 1 line
1.8.3.1
PATCH v3 3/13 powerpc/vas: Read interrupts and vas-port device tree properties
In reply to Haren MyneniRead interrupts and vas-port device tree properties per each VAS instance. NX generates an interrupt when it sees page fault on the request buffer. Interrupts property is used to setup IRQ for handing the fault and set port value for each user space send window.
--- arch/powerpc/platforms/powernv/vas.c | 40 ++++++++++++++++++++++++++++-------- arch/powerpc/platforms/powernv/vas.h | 2 ++ 2 files changed, 34 insertions(+), 8 deletions(-)
arch/powerpc/platforms/powernv/vas.c +32 -8
@@ -25,10 +25,11 @@static int init_vas_instance (struct platform_device *pdev) { -int rc, cpu, vasid; -struct resource *res; -struct vas_instance *vinst;struct device_node *dn = pdev->dev.of_node; +int rc, cpu, vasid, nresources =5 ; +struct vas_instance *vinst; +struct resource *res; +uint64_t port; rc =of_property_read_u32 (dn,"ibm,vas-id" , &vasid);if (rc) {
@@ -36,7 +37,18 @@ static int init_vas_instance(struct platform_device *pdev)return -ENODEV ; } -if (pdev->num_resources !=4 ) { + rc =of_property_read_u64 (dn,"ibm,vas-port" , &port); +if (rc) { +pr_err ("No ibm,vas-port property for %s?\n" , pdev->name); +/* No interrupts property */ + nresources =4 ; + } + +/* +* interrupts property is available with 'ibm,vas-port' property. +* 4 Resources and 1 IRQ if interrupts property is available. +*/ +if (pdev->num_resources != nresources) {pr_err ("Unexpected DT configuration for [%s, %d]\n" , pdev->name, vasid);return -ENODEV ;
@@ -51,6 +63,7 @@ static int init_vas_instance(struct platform_device *pdev)mutex_init (&vinst->mutex); vinst->vas_id = vasid; vinst->pdev = pdev; + vinst->irq_port = port; res = &pdev->resource[0 ]; vinst->hvwc_bar_start = res->start;
@@ -66,12 +79,23 @@ static int init_vas_instance(struct platform_device *pdev)pr_err ("Bad 'paste_win_id_shift' in DT, %llx\n" , res->end); goto free_vinst; } - vinst->paste_win_id_shift =63 - res->end; -pr_devel ("Initialized instance [%s, %d], paste_base 0x%llx, " -"paste_win_id_shift 0x%llx\n" , pdev->name, vasid, - vinst->paste_base_addr, vinst->paste_win_id_shift); +/* interrupts property */ +if (pdev->num_resources ==5 ) { + res = &pdev->resource[4 ]; + vinst->virq = res->start; +if (vinst->virq <=0 ) { +pr_err ("IRQ resource is not available for [%s, %d]\n" , + pdev->name, vasid); + vinst->virq =0 ; + } + } + +pr_devel ("Initialized instance [%s, %d] paste_base 0x%llx paste_win_id_shift 0x%llx IRQ %d Port 0x%llx\n" , + pdev->name, vasid, vinst->paste_base_addr, + vinst->paste_win_id_shift, vinst->virq, + vinst->irq_port);for_each_possible_cpu (cpu) {if (cpu_to_chip_id (cpu) ==of_get_ibm_chip_id (dn))
arch/powerpc/platforms/powernv/vas.h +2 -0
@@ -313,6 +313,8 @@ struct vas_instance {u64 paste_base_addr;u64 paste_win_id_shift; +u64 irq_port; +int virq;struct mutex mutex;struct vas_window *rxwin[VAS_COP_TYPE_MAX ];struct vas_window *windows[VAS_WINDOWS_PER_CHIP ];
Signature · 1 line
1.8.3.1
PATCH v3 4/13 powerpc/vas: Setup fault window per VAS instance
In reply to Haren MyneniSetup fault window for each VAS instance. When NX gets fault on request buffer, write fault CRBs in the corresponding fault FIFO and then sends an interrupt to the OS.
--- arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/vas-fault.c | 73 ++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/vas-window.c | 3 +- arch/powerpc/platforms/powernv/vas.c | 20 ++++++++ arch/powerpc/platforms/powernv/vas.h | 5 ++ scripts/pnmtologo | Bin 0 -> 71976 bytes 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/platforms/powernv/vas-fault.c create mode 100755 scripts/pnmtologo
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -17,7 +17,7 @@ obj-$(CONFIG_MEMORY_FAILURE) += opal-memory-errors.o obj-$(CONFIG_OPAL_PRD) += opal-prd.o obj-$(CONFIG_PERF_EVENTS) += opal-imc.o obj-$(CONFIG_PPC_MEMTRACE) += memtrace.o -obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o +obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o vas-fault.o obj-$(CONFIG_OCXL_BASE) += ocxl.o obj-$(CONFIG_SCOM_DEBUGFS) += opal-xscom.o obj-$(CONFIG_PPC_SECURE_BOOT) += opal-secvar.o
arch/powerpc/platforms/powernv/vas-fault.c new file +73 -0
73 lines not on this page · raw message
arch/powerpc/platforms/powernv/vas-window.c +2 -1
@@ -827,9 +827,10 @@ void vas_init_rx_win_attr(struct vas_rx_win_attr *rxattr, enum vas_cop_type cop) rxattr->fault_win = true; rxattr->notify_disable = true; rxattr->rx_wcred_mode = true; - rxattr->tx_wcred_mode = true; rxattr->rx_win_ord_mode = true; rxattr->tx_win_ord_mode = true; + rxattr->rej_no_credit = true; + rxattr->tc_mode =VAS_THRESH_DISABLED ; }else if (cop ==VAS_COP_TYPE_FTW ) { rxattr->user_win = true; rxattr->intr_disable = true;
arch/powerpc/platforms/powernv/vas.c +20 -0
@@ -23,6 +23,11 @@ static DEFINE_PER_CPU(int, cpu_vas_id); +static int vas_irq_fault_window_setup (struct vas_instance *vinst) +{ +return vas_setup_fault_window (vinst); +} +static int init_vas_instance (struct platform_device *pdev) {struct device_node *dn = pdev->dev.of_node;
@@ -106,6 +111,21 @@ static int init_vas_instance(struct platform_device *pdev)list_add (&vinst->node, &vas_instances);mutex_unlock (&vas_mutex); +/* +* IRQ and fault handling setup is needed only for user space +* send windows. +*/ +if (vinst->virq) { + rc =vas_irq_fault_window_setup (vinst); +/* +* Fault window is used only for user space send windows. +* So if vinst->virq is NULL, tx_win_open returns -ENODEV +* for user space. +*/ +if (rc) + vinst->virq =0 ; + } +vas_instance_init_dbgdir (vinst);dev_set_drvdata (&pdev->dev, vinst);
arch/powerpc/platforms/powernv/vas.h +5 -0
@@ -315,6 +315,10 @@ struct vas_instance {u64 irq_port;int virq; +int fault_fifo_size; +void *fault_fifo; +struct vas_window *fault_win;/* Fault window */ +struct mutex mutex;struct vas_window *rxwin[VAS_COP_TYPE_MAX ];struct vas_window *windows[VAS_WINDOWS_PER_CHIP ];
@@ -408,6 +412,7 @@ struct vas_winctx {extern void vas_instance_init_dbgdir (struct vas_instance *vinst);extern void vas_window_init_dbgdir (struct vas_window *win);extern void vas_window_free_dbgdir (struct vas_window *win); +extern int vas_setup_fault_window (struct vas_instance *vinst);static inline void vas_log_write (struct vas_window *win,char *name,void *regptr,u64 val)
PATCH v3 5/13 powerpc/vas: Setup thread IRQ handler per VAS instance
In reply to Haren MyneniSetup thread IRQ handler per each VAS instance. When NX sees a fault on CRB, kernel gets an interrupt and vas_fault_handler will be executed to process fault CRBs. Read all valid CRBs from fault FIFO, determine the corresponding send window from CRB and process fault requests.
--- arch/powerpc/platforms/powernv/vas-fault.c | 83 +++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/vas-window.c | 60 +++++++++++++++++++++ arch/powerpc/platforms/powernv/vas.c | 21 +++++++- arch/powerpc/platforms/powernv/vas.h | 4 ++ 4 files changed, 167 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/vas-fault.c +83 -0
@@ -11,6 +11,7 @@#include <linux/slab.h> #include <linux/uaccess.h> #include <linux/kthread.h> +#include <linux/mmu_context.h> #include <asm/icswx.h> #include "vas.h"
@@ -25,6 +26,88 @@#define VAS_FAULT_WIN_FIFO_SIZE (4 << 20)/* +* Process CRBs that we receive on the fault window. +*/ +irqreturn_t vas_fault_handler (int irq,void *data) +{ +struct vas_instance *vinst = data; +struct coprocessor_request_block buf, *crb; +struct vas_window *window; +void *fifo; + +/* +* VAS can interrupt with multiple page faults. So process all +* valid CRBs within fault FIFO until reaches invalid CRB. +* NX updates nx_fault_stamp in CRB and pastes in fault FIFO. +* kernel retrives send window from parition send window ID +* (pswid) in nx_fault_stamp. So pswid should be non-zero and +* use this to check whether CRB is valid. +* After reading CRB entry, it is reset with 0's in fault FIFO. +* +* In case kernel receives another interrupt with different page +* fault and CRBs are processed by the previous handling, will be +* returned from this function when it sees invalid CRB (means 0's). +*/ +do { +mutex_lock (&vinst->mutex); + +/* +* Advance the fault fifo pointer to next CRB. +* Use CRB_SIZE rather than sizeof(*crb) since the latter is +* aligned to CRB_ALIGN (256) but the CRB written to by VAS is +* only CRB_SIZE in len. +*/ + fifo = vinst->fault_fifo + (vinst->fault_crbs *CRB_SIZE ); + crb = fifo; + +/* +* pswid returned from NX will be in _be32, but just +* checking non-zero value to make sure the CRB is valid. +* Return if reached invalid CRB. +*/ +if (!crb->stamp.nx.pswid) { +mutex_unlock (&vinst->mutex); +return IRQ_HANDLED ; + } + + vinst->fault_crbs++; +if (vinst->fault_crbs == (vinst->fault_fifo_size /CRB_SIZE )) + vinst->fault_crbs =0 ; + + crb = &buf; +memcpy (crb, fifo,CRB_SIZE ); +memset (fifo,0 ,CRB_SIZE ); +mutex_unlock (&vinst->mutex); + +pr_devel ("VAS[%d] fault_fifo %p, fifo %p, fault_crbs %d\n" , + vinst->vas_id, vinst->fault_fifo, fifo, + vinst->fault_crbs); + + window =vas_pswid_to_window (vinst, +be32_to_cpu (crb->stamp.nx.pswid)); + +if (IS_ERR (window)) { +/* +* We got an interrupt about a specific send +* window but we can't find that window and we can't +* even clean it up (return credit). +* But we should not get here. +*/ +pr_err ("VAS[%d] fault_fifo %p, fifo %p, pswid 0x%x, fault_crbs %d bad CRB?\n" , + vinst->vas_id, vinst->fault_fifo, fifo, +be32_to_cpu (crb->stamp.nx.pswid), + vinst->fault_crbs); + +WARN_ON_ONCE (1 ); +return IRQ_HANDLED ; + } + + }while (true); + +return IRQ_HANDLED ; +} + +/* * Fault window is opened per VAS instance. NX pastes fault CRB in fault * FIFO upon page faults. */
arch/powerpc/platforms/powernv/vas-window.c +60 -0
69 lines not on this page · raw message
arch/powerpc/platforms/powernv/vas.c +20 -1
@@ -14,6 +14,8 @@#include <linux/of_platform.h> #include <linux/of_address.h> #include <linux/of.h> +#include <linux/irqdomain.h> +#include <linux/interrupt.h> #include <asm/prom.h> #include "vas.h"
@@ -25,7 +27,24 @@static int vas_irq_fault_window_setup (struct vas_instance *vinst) { -return vas_setup_fault_window (vinst); +char devname[64 ]; +int rc =0 ; + +snprintf (devname,sizeof (devname),"vas-%d" , vinst->vas_id); + rc =request_threaded_irq (vinst->virq,NULL , vas_fault_handler, +IRQF_ONESHOT , devname, vinst); +if (rc) { +pr_err ("VAS[%d]: Request IRQ(%d) failed with %d\n" , + vinst->vas_id, vinst->virq, rc); + goto out; + } + + rc =vas_setup_fault_window (vinst); +if (rc) +free_irq (vinst->virq, vinst); + +out: +return rc; }static int init_vas_instance (struct platform_device *pdev)
arch/powerpc/platforms/powernv/vas.h +4 -0
@@ -315,6 +315,7 @@ struct vas_instance {u64 irq_port;int virq; +int fault_crbs;int fault_fifo_size;void *fault_fifo;struct vas_window *fault_win;/* Fault window */
@@ -413,6 +414,9 @@ struct vas_winctx {extern void vas_window_init_dbgdir (struct vas_window *win);extern void vas_window_free_dbgdir (struct vas_window *win);extern int vas_setup_fault_window (struct vas_instance *vinst); +extern irqreturn_t vas_fault_handler (int irq,void *data); +extern struct vas_window *vas_pswid_to_window (struct vas_instance *vinst, +uint32_t pswid);static inline void vas_log_write (struct vas_window *win,char *name,void *regptr,u64 val)
Signature · 1 line
1.8.3.1
PATCH v3 6/13 powerpc/vas: Register NX with fault window ID and IRQ port value
In reply to Haren MyneniFor each user space send window, register NX with fault window ID and port value so that NX paste CRBs in this fault FIFO when it sees fault on the request buffer.
--- arch/powerpc/platforms/powernv/vas-window.c | 15 +++++++++++++-- arch/powerpc/platforms/powernv/vas.h | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/vas-window.c +13 -2
@@ -373,7 +373,7 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)init_xlate_regs (window, winctx->user_win); val =0ULL ; - val =SET_FIELD (VAS_FAULT_TX_WIN , val,0 ); + val =SET_FIELD (VAS_FAULT_TX_WIN , val, winctx->fault_win_id);write_hvwc_reg (window,VREG (FAULT_TX_WIN ), val);/* In PowerNV, interrupts go to HV. */
@@ -748,6 +748,8 @@ static void init_winctx_for_rxwin(struct vas_window *rxwin, winctx->min_scope =VAS_SCOPE_LOCAL ; winctx->max_scope =VAS_SCOPE_VECTORED_GROUP ; +if (rxwin->vinst->virq) + winctx->irq_port = rxwin->vinst->irq_port; } static bool rx_win_args_valid(enum vas_cop_type cop,
@@ -945,13 +947,22 @@ static void init_winctx_for_txwin(struct vas_window *txwin, winctx->lpid = txattr->lpid; winctx->pidr = txattr->pidr; winctx->rx_win_id = txwin->rxwin->winid; +/* +* IRQ and fault window setup is successful. Set fault window +* for the send window so that ready to handle faults. +*/ +if (txwin->vinst->virq) + winctx->fault_win_id = txwin->vinst->fault_win->winid; winctx->dma_type =VAS_DMA_TYPE_INJECT ; winctx->tc_mode = txattr->tc_mode; winctx->min_scope =VAS_SCOPE_LOCAL ; winctx->max_scope =VAS_SCOPE_VECTORED_GROUP ; +if (txwin->vinst->virq) + winctx->irq_port = txwin->vinst->irq_port; - winctx->pswid =0 ; + winctx->pswid = txattr->pswid ? txattr->pswid : +encode_pswid (txwin->vinst->vas_id, txwin->winid); } static bool tx_win_args_valid(enum vas_cop_type cop,
arch/powerpc/platforms/powernv/vas.h +15 -0
@@ -455,6 +455,21 @@ static inline u64 read_hvwc_reg(struct vas_window *win,return in_be64 (win->hvwc_map+reg); } +/* +* Encode/decode the Partition Send Window ID (PSWID) for a window in +* a way that we can uniquely identify any window in the system. i.e. +* we should be able to locate the 'struct vas_window' given the PSWID. +* +* Bits Usage +* 0:7 VAS id (8 bits) +* 8:15 Unused, 0 (3 bits) +* 16:31 Window id (16 bits) +*/ +static inline u32 encode_pswid (int vasid,int winid) +{ +return ((u32 )winid | (vasid << (31 -7 ))); +} +static inline void decode_pswid (u32 pswid,int *vasid,int *winid) {if (vasid)
Signature · 1 line
1.8.3.1
PATCH v3 7/13 powerpc/vas: Take reference to PID and mm for userspace windows
In reply to Haren MyneniProcess close windows after its requests are completed. In multi-thread applications, child can open a window but release FD will not be called upon its exit. Parent thread will be closing it later upon its exit.
The parent can also send NX requests with this window and NX can generate page faults. After kernel handles the page fault, send signal to process by using PID if CSB address is invalid. Parent thread will not receive signal since its PID is different from the one saved in vas_window. So use tgid in case if the task for the pid saved in window is not running and send signal to its parent.
To prevent reusing the pid until the window closed, take reference to pid and task mm.
--- arch/powerpc/platforms/powernv/vas-debug.c | 2 +- arch/powerpc/platforms/powernv/vas-window.c | 53 ++++++++++++++++++++++++++--- arch/powerpc/platforms/powernv/vas.h | 9 ++++- 3 files changed, 57 insertions(+), 7 deletions(-)
arch/powerpc/platforms/powernv/vas-debug.c +1 -1
@@ -38,7 +38,7 @@ static int info_show(struct seq_file *s, void *private)seq_printf (s,"Type: %s, %s\n" ,cop_to_str (window->cop), window->tx_win ?"Send" :"Receive" ); -seq_printf (s,"Pid : %d\n" , window->pid); +seq_printf (s,"Pid : %d\n" ,vas_window_pid (window)); unlock:mutex_unlock (&vas_mutex);
arch/powerpc/platforms/powernv/vas-window.c +48 -5
85 lines not on this page · raw message
arch/powerpc/platforms/powernv/vas.h +8 -1
@@ -340,7 +340,9 @@ struct vas_window {bool user_win;/* True if user space window */ void *hvwc_map;/* HV window context */ void *uwc_map;/* OS/User window context */ -pid_t pid;/* Linux process id of owner */ +struct pid *pid;/* Linux process id of owner */ +struct pid *tgid;/* Thread group ID of owner */ +struct mm_struct *mm;/* Linux process mm_struct */ int wcreds_max;/* Window credits */ char *dbgname;
@@ -418,6 +420,11 @@ struct vas_winctx {extern struct vas_window *vas_pswid_to_window (struct vas_instance *vinst,uint32_t pswid); +static inline int vas_window_pid (struct vas_window *window) +{ +return pid_vnr (window->pid); +} +static inline void vas_log_write (struct vas_window *win,char *name,void *regptr,u64 val) {
Signature · 1 line
1.8.3.1
PATCH v3 8/13 powerpc/vas: Update CSB and notify process for fault CRBs
In reply to Haren MyneniFor each fault CRB, update fault address in CRB (fault_storage_addr) and translation error status in CSB so that user space can touch the fault address and resend the request. If the user space passed invalid CSB address send signal to process with SIGSEGV.
--- arch/powerpc/platforms/powernv/vas-fault.c | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+)
arch/powerpc/platforms/powernv/vas-fault.c +121 -0
@@ -11,6 +11,7 @@#include <linux/slab.h> #include <linux/uaccess.h> #include <linux/kthread.h> +#include <linux/sched/signal.h> #include <linux/mmu_context.h> #include <asm/icswx.h>
@@ -26,6 +27,125 @@#define VAS_FAULT_WIN_FIFO_SIZE (4 << 20)/* +* Update the CSB to indicate a translation error. +* +* If the fault is in the CSB address itself or if we are unable to +* update the CSB, send a signal to the process, because we have no +* other way of notifying the user process. +* +* Remaining settings in the CSB are based on wait_for_csb() of +* NX-GZIP. +*/ +static void update_csb (struct vas_window *window, +struct coprocessor_request_block *crb) +{ +int rc; +struct pid *pid; +void __user *csb_addr; +struct task_struct *tsk; +struct kernel_siginfo info; +struct coprocessor_status_block csb; + +/* +* NX user space windows can not be opened for task->mm=NULL +* and faults will not be generated for kernel requests. +*/ +if (!window->mm || !window->user_win) +return ; + + csb_addr = (void *)be64_to_cpu (crb->csb_addr); + + csb.cc =CSB_CC_TRANSLATION ; + csb.ce =CSB_CE_TERMINATION ; + csb.cs =0 ; + csb.count =0 ; + +/* +* Returns the fault address in CPU format since it is passed with +* signal. But if the user space expects BE format, need changes. +* i.e either kernel (here) or user should convert to CPU format. +* Not both! +*/ + csb.address =be64_to_cpu (crb->stamp.nx.fault_storage_addr); + csb.flags =0 ; + +use_mm (window->mm); + rc =copy_to_user (csb_addr, &csb,sizeof (csb)); +/* +* User space polls on csb.flags (first byte). So add barrier +* then copy first byte with csb flags update. +*/ +smp_mb (); +if (!rc) { + csb.flags =CSB_V ; + rc =copy_to_user (csb_addr, &csb,sizeof (u8)); + } +unuse_mm (window->mm); + +/* Success */ +if (!rc) +return ; + +/* +* User space passed invalid CSB address, Notify process with +* SEGV signal. +*/ + pid = window->pid; + tsk =get_pid_task (pid,PIDTYPE_PID ); +/* +* Send window will be closed after processing all NX requests +* and process exits after closing all windows. In multi-thread +* applications, thread may not exists, but does not close FD +* (means send window) upon exit. Parent thread (tgid) can use +* and close the window later. +* pid and mm references are taken when window is opened by +* process (pid). So tgid is used only when child thread is not +* available in multithread tasks. +* +*/ +if (!tsk) { + pid = window->tgid; + tsk =get_pid_task (pid,PIDTYPE_PID ); +/* +* Parent thread will be closing window during its exit. +* So should not get here. +*/ +if (!tsk) +return ; + } + +/* Do not notify if the task is exiting. */ +if (tsk->flags &PF_EXITING ) { +put_task_struct (tsk); +return ; + } +put_task_struct (tsk); + +pr_err ("Invalid CSB address 0x%p signalling pid(%d)\n" , + csb_addr,pid_vnr (pid)); + +clear_siginfo (&info); + info.si_signo =SIGSEGV ; + info.si_errno =EFAULT ; + info.si_code =SEGV_MAPERR ; + info.si_addr = csb_addr; + +/* +* process will be polling on csb.flags after request is sent to +* NX. So generally CSB update should not fail except when an +* application does not follow the process properly. So an error +* message will be displayed and leave it to user space whether +* to ignore or handle this signal. +*/ +rcu_read_lock (); + rc =kill_pid_info (SIGSEGV , &info, pid); +rcu_read_unlock (); + +pr_devel ("%s(): pid %d kill_proc_info() rc %d\n" , __func__, +pid_vnr (pid), rc); +} + +/* * Process CRBs that we receive on the fault window. */ irqreturn_t vas_fault_handler (int irq,void *data)
@@ -102,6 +222,7 @@ irqreturn_t vas_fault_handler(int irq, void *data)return IRQ_HANDLED ; } +update_csb (window, crb); }while (true);return IRQ_HANDLED ;
Signature · 1 line
1.8.3.1
PATCH v3 9/13 powerpc/vas: Print CRB and FIFO values
In reply to Haren MyneniDump FIFO entry values if could not find send window and print CRB for debugging.
--- arch/powerpc/platforms/powernv/vas-fault.c | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
arch/powerpc/platforms/powernv/vas-fault.c +41 -0
@@ -26,6 +26,28 @@*/ #define VAS_FAULT_WIN_FIFO_SIZE (4 << 20) +static void dump_crb (struct coprocessor_request_block *crb) +{ +struct data_descriptor_entry *dde; +struct nx_fault_stamp *nx; + + dde = &crb->source; +pr_devel ("SrcDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n" , +be64_to_cpu (dde->address),be32_to_cpu (dde->length), + dde->count, dde->index, dde->flags); + + dde = &crb->target; +pr_devel ("TgtDDE: addr 0x%llx, len %d, count %d, idx %d, flags %d\n" , +be64_to_cpu (dde->address),be32_to_cpu (dde->length), + dde->count, dde->index, dde->flags); + + nx = &crb->stamp.nx; +pr_devel ("NX Stamp: PSWID 0x%x, FSA 0x%llx, flags 0x%x, FS 0x%x\n" , +be32_to_cpu (nx->pswid), +be64_to_cpu (crb->stamp.nx.fault_storage_addr), + nx->flags,be32_to_cpu (nx->fault_status)); +} +/* * Update the CSB to indicate a translation error. *
@@ -145,6 +167,23 @@ static void update_csb(struct vas_window *window, pid_vnr(pid), rc); } +static void dump_fifo (struct vas_instance *vinst,void *entry) +{ +int i; +unsigned long *fifo = entry; + +pr_err ("Fault fifo size %d, max crbs %d, crb size %lu\n" , + vinst->fault_fifo_size, + vinst->fault_fifo_size /CRB_SIZE , +sizeof (struct coprocessor_request_block )); + +pr_err ("Fault FIFO Entry Dump:\n" ); +for (i =0 ; i <CRB_SIZE ; i +=4 , fifo +=4 ) { +pr_err ("[%.3d, %p]: 0x%.16lx 0x%.16lx 0x%.16lx 0x%.16lx\n" , + i, fifo, *fifo, *(fifo+1 ), *(fifo+2 ), *(fifo+3 )); + } +} +/* * Process CRBs that we receive on the fault window. */
@@ -203,6 +242,7 @@ irqreturn_t vas_fault_handler(int irq, void *data) vinst->vas_id, vinst->fault_fifo, fifo, vinst->fault_crbs); +dump_crb (crb); window =vas_pswid_to_window (vinst,be32_to_cpu (crb->stamp.nx.pswid));
@@ -213,6 +253,7 @@ irqreturn_t vas_fault_handler(int irq, void *data)* even clean it up (return credit). * But we should not get here. */ +dump_fifo (vinst, (void *)crb); pr_err("VAS[%d] fault_fifo %p, fifo %p, pswid 0x%x, fault_crbs %d bad CRB?\n", vinst->vas_id, vinst->fault_fifo, fifo, be32_to_cpu(crb->stamp.nx.pswid),
Signature · 1 line
1.8.3.1
PATCH v3 10/13 powerpc/vas: Do not use default credits for receive window
In reply to Haren MyneniSystem checkstops if RxFIFO overruns with more requests than the maximum possible number of CRBs allowed in FIFO at any time. So max credits value (rxattr.wcreds_max) is set and is passed to vas_rx_win_open() by the the driver.
--- arch/powerpc/platforms/powernv/vas-window.c | 4 ++-- arch/powerpc/platforms/powernv/vas.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/vas-window.c +2 -2
@@ -772,7 +772,7 @@ static bool rx_win_args_valid(enum vas_cop_type cop,if (attr->rx_fifo_size >VAS_RX_FIFO_SIZE_MAX )return false; -if (attr->wcreds_max >VAS_RX_WCREDS_MAX ) +if (!attr->wcreds_max)return false;if (attr->nx_win) {
@@ -878,7 +878,7 @@ struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop, rxwin->nx_win = rxattr->nx_win; rxwin->user_win = rxattr->user_win; rxwin->cop = cop; - rxwin->wcreds_max = rxattr->wcreds_max ?:VAS_WCREDS_DEFAULT ; + rxwin->wcreds_max = rxattr->wcreds_max;init_winctx_for_rxwin (rxwin, rxattr, &winctx);init_winctx_regs (rxwin, &winctx);
arch/powerpc/platforms/powernv/vas.h +0 -2
@@ -101,11 +101,9 @@/* * Initial per-process credits. * Max send window credits: 4K-1 (12-bits in VAS_TX_WCRED) -* Max receive window credits: 64K-1 (16 bits in VAS_LRX_WCRED) * * TODO: Needs tuning for per-process credits */ -#define VAS_RX_WCREDS_MAX ((64 << 10) - 1)#define VAS_TX_WCREDS_MAX ((4 << 10) - 1)#define VAS_WCREDS_DEFAULT (1 << 10)
Signature · 1 line
1.8.3.1
PATCH v3 11/13 powerpc/VAS: Return credits after handling fault
In reply to Haren MyneniNX expects OS to return credit for send window after processing each fault. Also credit has to be returned even for fault window.
--- arch/powerpc/platforms/powernv/vas-fault.c | 10 ++++++++++ arch/powerpc/platforms/powernv/vas-window.c | 17 +++++++++++++++++ arch/powerpc/platforms/powernv/vas.h | 1 + 3 files changed, 28 insertions(+)
arch/powerpc/platforms/powernv/vas-fault.c +10 -0
@@ -238,6 +238,11 @@ irqreturn_t vas_fault_handler(int irq, void *data)memset (fifo,0 ,CRB_SIZE );mutex_unlock (&vinst->mutex); +/* +* Return credit for the fault window. +*/ +vas_return_credit (vinst->fault_win,0 ); +pr_devel ("VAS[%d] fault_fifo %p, fifo %p, fault_crbs %d\n" , vinst->vas_id, vinst->fault_fifo, fifo, vinst->fault_crbs);
@@ -264,6 +269,11 @@ irqreturn_t vas_fault_handler(int irq, void *data) }update_csb (window, crb); +/* +* Return credit for send window after processing +* fault CRB. +*/ +vas_return_credit (window,1 ); }while (true);return IRQ_HANDLED ;
arch/powerpc/platforms/powernv/vas-window.c +17 -0
@@ -1319,6 +1319,23 @@ int vas_win_close(struct vas_window *window) }EXPORT_SYMBOL_GPL (vas_win_close); +/* +* Return credit for the given window. +*/ +void vas_return_credit (struct vas_window *window,bool tx) +{ +uint64_t val; + + val =0ULL ; +if (tx) {/* send window */ + val =SET_FIELD (VAS_TX_WCRED , val,1 ); +write_hvwc_reg (window,VREG (TX_WCRED_ADDER ), val); + }else { + val =SET_FIELD (VAS_LRX_WCRED , val,1 ); +write_hvwc_reg (window,VREG (LRX_WCRED_ADDER ), val); + } +} +struct vas_window *vas_pswid_to_window (struct vas_instance *vinst,uint32_t pswid) {
arch/powerpc/platforms/powernv/vas.h +1 -0
@@ -415,6 +415,7 @@ struct vas_winctx {extern void vas_window_free_dbgdir (struct vas_window *win);extern int vas_setup_fault_window (struct vas_instance *vinst);extern irqreturn_t vas_fault_handler (int irq,void *data); +extern void vas_return_credit (struct vas_window *window,bool tx);extern struct vas_window *vas_pswid_to_window (struct vas_instance *vinst,uint32_t pswid);
Signature · 1 line
1.8.3.1
PATCH v3 12/13 powerpc/vas: Display process stuck message
In reply to Haren MyneniProcess can not close send window until all requests are processed. Means wait until window state is not busy and send credits are returned. Display debug message in case taking longer to close the window.
--- arch/powerpc/platforms/powernv/vas-window.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/powerpc/platforms/powernv/vas-window.c +26 -0
@@ -1183,6 +1183,7 @@ static void poll_window_credits(struct vas_window *window) {u64 val;int creds, mode; +int count =0 ; val =read_hvwc_reg (window,VREG (WINCTL ));if (window->tx_win)
@@ -1201,10 +1202,25 @@ static void poll_window_credits(struct vas_window *window) creds =GET_FIELD (VAS_LRX_WCRED , val); } +/* +* Takes around few microseconds to complete all pending requests +* and return credits. +* TODO: Issue CRB Kill to stop all pending requests. Need only +* if there is a bug in NX or fault handling in kernel. +*/ if (creds < window->wcreds_max) { val =0 ;set_current_state (TASK_UNINTERRUPTIBLE );schedule_timeout (msecs_to_jiffies (10 )); + count++; +/* +* Process can not close send window until all credits are +* returned. +*/ +if (!(count %10000 )) +pr_debug ("%s() pid %d stuck? retries %d\n" , __func__, +vas_window_pid (window), count); + goto retry; } }
@@ -1218,6 +1234,7 @@ static void poll_window_busy_state(struct vas_window *window) {int busy;u64 val; +int count =0 ; retry: val =read_hvwc_reg (window,VREG (WIN_STATUS ));
@@ -1226,6 +1243,15 @@ static void poll_window_busy_state(struct vas_window *window) val =0 ;set_current_state (TASK_UNINTERRUPTIBLE );schedule_timeout (msecs_to_jiffies (5 )); + count++; +/* +* Takes around 5 microseconds to process all pending +* requests. +*/ +if (!(count %10000 )) +pr_debug ("%s() pid %d stuck? retries %d\n" , __func__, +vas_window_pid (window), count); + goto retry; } }
Signature · 1 line
1.8.3.1
PATCH v3 13/13 powerpc/vas: Free send window in VAS instance after credits returned
In reply to Haren MyneniNX may be processing requests while trying to close window. Wait until all credits are returned and then free send window from VAS instance.
--- arch/powerpc/platforms/powernv/vas-window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/vas-window.c +2 -2
@@ -1316,14 +1316,14 @@ int vas_win_close(struct vas_window *window)unmap_paste_region (window); -clear_vinst_win (window); -poll_window_busy_state (window);unpin_close_window (window);poll_window_credits (window); +clear_vinst_win (window); +poll_window_castout (window);/* if send window, drop reference to matching receive window */
Signature · 1 line
1.8.3.1