Message ID | b8fc66dcb783d06a099a303e5cfc69087bb3357a.camel@linux.ibm.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Herbert Xu |
Headers | show |
Series | Enable VAS and NX-GZIP support on PowerVM | expand |
Excerpts from Haren Myneni's message of June 18, 2021 6:37 am: > > NX generates an interrupt when sees a fault on the user space > buffer and the hypervisor forwards that interrupt to OS. Then > the kernel handles the interrupt by issuing H_GET_NX_FAULT hcall > to retrieve the fault CRB information. > > This patch also adds changes to setup and free IRQ per each > window and also handles the fault by updating the CSB. In as much as this pretty well corresponds to the PowerNV code AFAIKS, it looks okay to me. Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Could you have an irq handler in your ops vector and have the core code set up the irq and call your handler, so the Linux irq handling is in one place? Not something for this series, I was just wondering. Thanks, Nick > > Signed-off-by: Haren Myneni <haren@linux.ibm.com> > --- > arch/powerpc/platforms/pseries/vas.c | 102 +++++++++++++++++++++++++++ > 1 file changed, 102 insertions(+) > > diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c > index f5a44f2f0e99..3385b5400cc6 100644 > --- a/arch/powerpc/platforms/pseries/vas.c > +++ b/arch/powerpc/platforms/pseries/vas.c > @@ -11,6 +11,7 @@ > #include <linux/types.h> > #include <linux/delay.h> > #include <linux/slab.h> > +#include <linux/interrupt.h> > #include <asm/machdep.h> > #include <asm/hvcall.h> > #include <asm/plpar_wrappers.h> > @@ -155,6 +156,50 @@ int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result) > } > EXPORT_SYMBOL_GPL(h_query_vas_capabilities); > > +/* > + * hcall to get fault CRB from the hypervisor. > + */ > +static int h_get_nx_fault(u32 winid, u64 buffer) > +{ > + long rc; > + > + rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer); > + > + if (rc == H_SUCCESS) > + return 0; > + > + pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n", > + rc, winid, buffer); > + return -EIO; > + > +} > + > +/* > + * Handle the fault interrupt. > + * When the fault interrupt is received for each window, query the > + * hypervisor to get the fault CRB on the specific fault. Then > + * process the CRB by updating CSB or send signal if the user space > + * CSB is invalid. > + * Note: The hypervisor forwards an interrupt for each fault request. > + * So one fault CRB to process for each H_GET_NX_FAULT hcall. > + */ > +irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data) > +{ > + struct pseries_vas_window *txwin = data; > + struct coprocessor_request_block crb; > + struct vas_user_win_ref *tsk_ref; > + int rc; > + > + rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb)); > + if (!rc) { > + tsk_ref = &txwin->vas_win.task_ref; > + vas_dump_crb(&crb); > + vas_update_csb(&crb, tsk_ref); > + } > + > + return IRQ_HANDLED; > +} > + > /* > * Allocate window and setup IRQ mapping. > */ > @@ -166,10 +211,51 @@ static int allocate_setup_window(struct pseries_vas_window *txwin, > rc = h_allocate_vas_window(txwin, domain, wintype, DEF_WIN_CREDS); > if (rc) > return rc; > + /* > + * On PowerVM, the hypervisor setup and forwards the fault > + * interrupt per window. So the IRQ setup and fault handling > + * will be done for each open window separately. > + */ > + txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq); > + if (!txwin->fault_virq) { > + pr_err("Failed irq mapping %d\n", txwin->fault_irq); > + rc = -EINVAL; > + goto out_win; > + } > + > + txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d", > + txwin->vas_win.winid); > + if (!txwin->name) { > + rc = -ENOMEM; > + goto out_irq; > + } > + > + rc = request_threaded_irq(txwin->fault_virq, NULL, > + pseries_vas_fault_thread_fn, IRQF_ONESHOT, > + txwin->name, txwin); > + if (rc) { > + pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n", > + txwin->vas_win.winid, txwin->fault_virq, rc); > + goto out_free; > + } > > txwin->vas_win.wcreds_max = DEF_WIN_CREDS; > > return 0; > +out_free: > + kfree(txwin->name); > +out_irq: > + irq_dispose_mapping(txwin->fault_virq); > +out_win: > + h_deallocate_vas_window(txwin->vas_win.winid); > + return rc; > +} > + > +static inline void free_irq_setup(struct pseries_vas_window *txwin) > +{ > + free_irq(txwin->fault_virq, txwin); > + kfree(txwin->name); > + irq_dispose_mapping(txwin->fault_virq); > } > > static struct vas_window *vas_allocate_window(int vas_id, u64 flags, > @@ -284,6 +370,11 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags, > return &txwin->vas_win; > > out_free: > + /* > + * Window is not operational. Free IRQ before closing > + * window so that do not have to hold mutex. > + */ > + free_irq_setup(txwin); > h_deallocate_vas_window(txwin->vas_win.winid); > out: > atomic_dec(&cop_feat_caps->used_lpar_creds); > @@ -303,7 +394,18 @@ static int deallocate_free_window(struct pseries_vas_window *win) > { > int rc = 0; > > + /* > + * The hypervisor waits for all requests including faults > + * are processed before closing the window - Means all > + * credits have to be returned. In the case of fault > + * request, a credit is returned after OS issues > + * H_GET_NX_FAULT hcall. > + * So free IRQ after executing H_DEALLOCATE_VAS_WINDOW > + * hcall. > + */ > rc = h_deallocate_vas_window(win->vas_win.winid); > + if (!rc) > + free_irq_setup(win); > > return rc; > } > -- > 2.18.2 > > >
On Fri, 2021-06-18 at 09:34 +1000, Nicholas Piggin wrote: > Excerpts from Haren Myneni's message of June 18, 2021 6:37 am: > > NX generates an interrupt when sees a fault on the user space > > buffer and the hypervisor forwards that interrupt to OS. Then > > the kernel handles the interrupt by issuing H_GET_NX_FAULT hcall > > to retrieve the fault CRB information. > > > > This patch also adds changes to setup and free IRQ per each > > window and also handles the fault by updating the CSB. > > In as much as this pretty well corresponds to the PowerNV code > AFAIKS, > it looks okay to me. > > Reviewed-by: Nicholas Piggin <npiggin@gmail.com> > > Could you have an irq handler in your ops vector and have > the core code set up the irq and call your handler, so the Linux irq > handling is in one place? Not something for this series, I was just > wondering. Not possible to have common core code for IRQ setup. PowerNV: Every VAS instance will be having IRQ and this setup will be done during initialization (system boot). A fault FIFO will be assigned for each instance and registered to VAS so that VAS/NX writes fault CRB into this FIFO. PowerVM: Each window will have an IRQ and the setup will be done during window open. Thanks Haren > > Thanks, > Nick > > > Signed-off-by: Haren Myneni <haren@linux.ibm.com> > > --- > > arch/powerpc/platforms/pseries/vas.c | 102 > > +++++++++++++++++++++++++++ > > 1 file changed, 102 insertions(+) > > > > diff --git a/arch/powerpc/platforms/pseries/vas.c > > b/arch/powerpc/platforms/pseries/vas.c > > index f5a44f2f0e99..3385b5400cc6 100644 > > --- a/arch/powerpc/platforms/pseries/vas.c > > +++ b/arch/powerpc/platforms/pseries/vas.c > > @@ -11,6 +11,7 @@ > > #include <linux/types.h> > > #include <linux/delay.h> > > #include <linux/slab.h> > > +#include <linux/interrupt.h> > > #include <asm/machdep.h> > > #include <asm/hvcall.h> > > #include <asm/plpar_wrappers.h> > > @@ -155,6 +156,50 @@ int h_query_vas_capabilities(const u64 hcall, > > u8 query_type, u64 result) > > } > > EXPORT_SYMBOL_GPL(h_query_vas_capabilities); > > > > +/* > > + * hcall to get fault CRB from the hypervisor. > > + */ > > +static int h_get_nx_fault(u32 winid, u64 buffer) > > +{ > > + long rc; > > + > > + rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer); > > + > > + if (rc == H_SUCCESS) > > + return 0; > > + > > + pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n", > > + rc, winid, buffer); > > + return -EIO; > > + > > +} > > + > > +/* > > + * Handle the fault interrupt. > > + * When the fault interrupt is received for each window, query the > > + * hypervisor to get the fault CRB on the specific fault. Then > > + * process the CRB by updating CSB or send signal if the user > > space > > + * CSB is invalid. > > + * Note: The hypervisor forwards an interrupt for each fault > > request. > > + * So one fault CRB to process for each H_GET_NX_FAULT hcall. > > + */ > > +irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data) > > +{ > > + struct pseries_vas_window *txwin = data; > > + struct coprocessor_request_block crb; > > + struct vas_user_win_ref *tsk_ref; > > + int rc; > > + > > + rc = h_get_nx_fault(txwin->vas_win.winid, > > (u64)virt_to_phys(&crb)); > > + if (!rc) { > > + tsk_ref = &txwin->vas_win.task_ref; > > + vas_dump_crb(&crb); > > + vas_update_csb(&crb, tsk_ref); > > + } > > + > > + return IRQ_HANDLED; > > +} > > + > > /* > > * Allocate window and setup IRQ mapping. > > */ > > @@ -166,10 +211,51 @@ static int allocate_setup_window(struct > > pseries_vas_window *txwin, > > rc = h_allocate_vas_window(txwin, domain, wintype, > > DEF_WIN_CREDS); > > if (rc) > > return rc; > > + /* > > + * On PowerVM, the hypervisor setup and forwards the fault > > + * interrupt per window. So the IRQ setup and fault handling > > + * will be done for each open window separately. > > + */ > > + txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq); > > + if (!txwin->fault_virq) { > > + pr_err("Failed irq mapping %d\n", txwin->fault_irq); > > + rc = -EINVAL; > > + goto out_win; > > + } > > + > > + txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d", > > + txwin->vas_win.winid); > > + if (!txwin->name) { > > + rc = -ENOMEM; > > + goto out_irq; > > + } > > + > > + rc = request_threaded_irq(txwin->fault_virq, NULL, > > + pseries_vas_fault_thread_fn, > > IRQF_ONESHOT, > > + txwin->name, txwin); > > + if (rc) { > > + pr_err("VAS-Window[%d]: Request IRQ(%u) failed with > > %d\n", > > + txwin->vas_win.winid, txwin->fault_virq, rc); > > + goto out_free; > > + } > > > > txwin->vas_win.wcreds_max = DEF_WIN_CREDS; > > > > return 0; > > +out_free: > > + kfree(txwin->name); > > +out_irq: > > + irq_dispose_mapping(txwin->fault_virq); > > +out_win: > > + h_deallocate_vas_window(txwin->vas_win.winid); > > + return rc; > > +} > > + > > +static inline void free_irq_setup(struct pseries_vas_window > > *txwin) > > +{ > > + free_irq(txwin->fault_virq, txwin); > > + kfree(txwin->name); > > + irq_dispose_mapping(txwin->fault_virq); > > } > > > > static struct vas_window *vas_allocate_window(int vas_id, u64 > > flags, > > @@ -284,6 +370,11 @@ static struct vas_window > > *vas_allocate_window(int vas_id, u64 flags, > > return &txwin->vas_win; > > > > out_free: > > + /* > > + * Window is not operational. Free IRQ before closing > > + * window so that do not have to hold mutex. > > + */ > > + free_irq_setup(txwin); > > h_deallocate_vas_window(txwin->vas_win.winid); > > out: > > atomic_dec(&cop_feat_caps->used_lpar_creds); > > @@ -303,7 +394,18 @@ static int deallocate_free_window(struct > > pseries_vas_window *win) > > { > > int rc = 0; > > > > + /* > > + * The hypervisor waits for all requests including faults > > + * are processed before closing the window - Means all > > + * credits have to be returned. In the case of fault > > + * request, a credit is returned after OS issues > > + * H_GET_NX_FAULT hcall. > > + * So free IRQ after executing H_DEALLOCATE_VAS_WINDOW > > + * hcall. > > + */ > > rc = h_deallocate_vas_window(win->vas_win.winid); > > + if (!rc) > > + free_irq_setup(win); > > > > return rc; > > } > > -- > > 2.18.2 > > > > > >
Excerpts from Haren Myneni's message of June 18, 2021 12:09 pm: > On Fri, 2021-06-18 at 09:34 +1000, Nicholas Piggin wrote: >> Excerpts from Haren Myneni's message of June 18, 2021 6:37 am: >> > NX generates an interrupt when sees a fault on the user space >> > buffer and the hypervisor forwards that interrupt to OS. Then >> > the kernel handles the interrupt by issuing H_GET_NX_FAULT hcall >> > to retrieve the fault CRB information. >> > >> > This patch also adds changes to setup and free IRQ per each >> > window and also handles the fault by updating the CSB. >> >> In as much as this pretty well corresponds to the PowerNV code >> AFAIKS, >> it looks okay to me. >> >> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> >> >> Could you have an irq handler in your ops vector and have >> the core code set up the irq and call your handler, so the Linux irq >> handling is in one place? Not something for this series, I was just >> wondering. > > Not possible to have common core code for IRQ setup. > > PowerNV: Every VAS instance will be having IRQ and this setup will be > done during initialization (system boot). A fault FIFO will be assigned > for each instance and registered to VAS so that VAS/NX writes fault CRB > into this FIFO. > > PowerVM: Each window will have an IRQ and the setup will be done during > window open. Yeah, I thought as much. Just wondering. Thanks, Nick
diff --git a/arch/powerpc/platforms/pseries/vas.c b/arch/powerpc/platforms/pseries/vas.c index f5a44f2f0e99..3385b5400cc6 100644 --- a/arch/powerpc/platforms/pseries/vas.c +++ b/arch/powerpc/platforms/pseries/vas.c @@ -11,6 +11,7 @@ #include <linux/types.h> #include <linux/delay.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include <asm/machdep.h> #include <asm/hvcall.h> #include <asm/plpar_wrappers.h> @@ -155,6 +156,50 @@ int h_query_vas_capabilities(const u64 hcall, u8 query_type, u64 result) } EXPORT_SYMBOL_GPL(h_query_vas_capabilities); +/* + * hcall to get fault CRB from the hypervisor. + */ +static int h_get_nx_fault(u32 winid, u64 buffer) +{ + long rc; + + rc = plpar_hcall_norets(H_GET_NX_FAULT, winid, buffer); + + if (rc == H_SUCCESS) + return 0; + + pr_err("H_GET_NX_FAULT error: %ld, winid %u, buffer 0x%llx\n", + rc, winid, buffer); + return -EIO; + +} + +/* + * Handle the fault interrupt. + * When the fault interrupt is received for each window, query the + * hypervisor to get the fault CRB on the specific fault. Then + * process the CRB by updating CSB or send signal if the user space + * CSB is invalid. + * Note: The hypervisor forwards an interrupt for each fault request. + * So one fault CRB to process for each H_GET_NX_FAULT hcall. + */ +irqreturn_t pseries_vas_fault_thread_fn(int irq, void *data) +{ + struct pseries_vas_window *txwin = data; + struct coprocessor_request_block crb; + struct vas_user_win_ref *tsk_ref; + int rc; + + rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb)); + if (!rc) { + tsk_ref = &txwin->vas_win.task_ref; + vas_dump_crb(&crb); + vas_update_csb(&crb, tsk_ref); + } + + return IRQ_HANDLED; +} + /* * Allocate window and setup IRQ mapping. */ @@ -166,10 +211,51 @@ static int allocate_setup_window(struct pseries_vas_window *txwin, rc = h_allocate_vas_window(txwin, domain, wintype, DEF_WIN_CREDS); if (rc) return rc; + /* + * On PowerVM, the hypervisor setup and forwards the fault + * interrupt per window. So the IRQ setup and fault handling + * will be done for each open window separately. + */ + txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq); + if (!txwin->fault_virq) { + pr_err("Failed irq mapping %d\n", txwin->fault_irq); + rc = -EINVAL; + goto out_win; + } + + txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d", + txwin->vas_win.winid); + if (!txwin->name) { + rc = -ENOMEM; + goto out_irq; + } + + rc = request_threaded_irq(txwin->fault_virq, NULL, + pseries_vas_fault_thread_fn, IRQF_ONESHOT, + txwin->name, txwin); + if (rc) { + pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n", + txwin->vas_win.winid, txwin->fault_virq, rc); + goto out_free; + } txwin->vas_win.wcreds_max = DEF_WIN_CREDS; return 0; +out_free: + kfree(txwin->name); +out_irq: + irq_dispose_mapping(txwin->fault_virq); +out_win: + h_deallocate_vas_window(txwin->vas_win.winid); + return rc; +} + +static inline void free_irq_setup(struct pseries_vas_window *txwin) +{ + free_irq(txwin->fault_virq, txwin); + kfree(txwin->name); + irq_dispose_mapping(txwin->fault_virq); } static struct vas_window *vas_allocate_window(int vas_id, u64 flags, @@ -284,6 +370,11 @@ static struct vas_window *vas_allocate_window(int vas_id, u64 flags, return &txwin->vas_win; out_free: + /* + * Window is not operational. Free IRQ before closing + * window so that do not have to hold mutex. + */ + free_irq_setup(txwin); h_deallocate_vas_window(txwin->vas_win.winid); out: atomic_dec(&cop_feat_caps->used_lpar_creds); @@ -303,7 +394,18 @@ static int deallocate_free_window(struct pseries_vas_window *win) { int rc = 0; + /* + * The hypervisor waits for all requests including faults + * are processed before closing the window - Means all + * credits have to be returned. In the case of fault + * request, a credit is returned after OS issues + * H_GET_NX_FAULT hcall. + * So free IRQ after executing H_DEALLOCATE_VAS_WINDOW + * hcall. + */ rc = h_deallocate_vas_window(win->vas_win.winid); + if (!rc) + free_irq_setup(win); return rc; }
NX generates an interrupt when sees a fault on the user space buffer and the hypervisor forwards that interrupt to OS. Then the kernel handles the interrupt by issuing H_GET_NX_FAULT hcall to retrieve the fault CRB information. This patch also adds changes to setup and free IRQ per each window and also handles the fault by updating the CSB. Signed-off-by: Haren Myneni <haren@linux.ibm.com> --- arch/powerpc/platforms/pseries/vas.c | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+)