drm/amdgpu: imlement mmio byte access helpers
PATCH 1/4 drm/amdgpu: imlement mmio byte access helpers
mailbox register can be accessed with a byte boundry according to BIF team, so this patch prepares register byte access and will be used by following patches
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
@@ -1635,6 +1635,9 @@ uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t acc_flags);void amdgpu_mm_wreg (struct amdgpu_device *adev,uint32_t reg,uint32_t v,uint32_t acc_flags); +void amdgpu_mm_wreg8 (struct amdgpu_device *adev,uint32_t offset,uint8_t value); +uint8_t amdgpu_mm_rreg8 (struct amdgpu_device *adev,uint32_t offset); +u32 amdgpu_io_rreg (struct amdgpu_device *adev,u32 reg);void amdgpu_io_wreg (struct amdgpu_device *adev,u32 reg,u32 v);
@@ -1658,6 +1661,9 @@ int emu_soc_asic_init(struct amdgpu_device *adev);#define RREG32_NO_KIQ (reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)#define WREG32_NO_KIQ (reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ) +#define RREG8 (reg) amdgpu_mm_rreg8(adev, (reg)) +#define WREG8 (reg, v) amdgpu_mm_wreg8(adev, (reg), (v)) +#define RREG32 (reg) amdgpu_mm_rreg(adev, (reg), 0)#define RREG32_IDX (reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)#define DREG32 (reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +26 -0
@@ -121,6 +121,32 @@ uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,return ret; } +/* +* MMIO register read with bytes helper functions +* @offset:bytes offset from MMIO start +* +*/ + +uint8_t amdgpu_mm_rreg8 (struct amdgpu_device *adev,uint32_t offset) { +if (offset < adev->rmmio_size) +return (readb (adev->rmmio + offset)); +BUG (); +} + +/* +* MMIO register write with bytes helper functions +* @offset:bytes offset from MMIO start +* @value: the value want to be written to the register +* +*/ +void amdgpu_mm_wreg8 (struct amdgpu_device *adev,uint32_t offset,uint8_t value) { +if (offset < adev->rmmio_size) +writeb (value, adev->rmmio + offset); +else +BUG (); +} + +void amdgpu_mm_wreg (struct amdgpu_device *adev,uint32_t reg,uint32_t v,uint32_t acc_flags) {
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1520306150-29325-1-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org
PATCH 2/4 drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
this patch actually refactor mailbox implmentations, and all below changes are needed together to fix all those mailbox handshake issues exposured by heavey TDR test.
1)refactor all mailbox functions based on byte accessing for mb_control reason is to avoid touching non-related bits when writing trn/rcv part of mailbox_control, this way some incorrect INTR sent to hypervisor side could be avoided, and it fixes couple handshake bug.
2)trans_msg function re-impled: put a invalid
logic before transmitting message to make sure the ACK bit is in a clear status, otherwise there is chance that ACK asserted already before transmitting message and lead to fake ACK polling. (hypervisor side have some tricks to workaround ACK bit being corrupted by VF FLR which hase an side effects that may make guest side ACK bit asserted wrongly), and clear TRANS_MSG words after message transferred.
3)for mailbox_flr_work, it is also re-worked: it takes the mutex lock first if invoked, to block gpu recover's participate too early while hypervisor side is doing VF FLR. (hypervisor sends FLR_NOTIFY to guest before doing VF FLR and sentds FLR_COMPLETE after VF FLR done, and the FLR_NOTIFY will trigger interrupt to guest which lead to mailbox_flr_work being invoked)
This can avoid the issue that mailbox trans msg being cleared by its VF FLR.
4)for mailbox_rcv_irq IRQ routine, it should only peek msg and schedule mailbox_flr_work, instead of ACK to hypervisor itself, because FLR_NOTIFY msg sent from hypervisor side doesn't need VF's ACK (this is because VF's ACK would lead to hypervisor clear its trans_valid/msg, and this would cause handshake bug if trans_valid/msg is cleared not due to correct VF ACK but from a wrong VF ACK like this "FLR_NOTIFY" one)
This fixed handshake bug that sometimes GUEST always couldn't receive "READY_TO_ACCESS_GPU" msg from hypervisor.
5)seperate polling time limite accordingly:
POLL ACK cost no more than 500ms
POLL MSG cost no more than 12000ms
POLL FLR finish cost no more than 500ms
6) we still need to set adev into in_gpu_reset mode after we received FLR_NOTIFY from host side, this can prevent innocent app wrongly succesed to open amdgpu dri device.
FLR_NOFITY is received due to an IDLE hang detected from hypervisor side which indicating GPU is already die in this VF.
--- drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 200 ++++++++++++++++++---------------- drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h | 4 +- 2 files changed, 111 insertions(+), 93 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +108 -92
@@ -33,56 +33,42 @@static void xgpu_ai_mailbox_send_ack (struct amdgpu_device *adev) { -u32 reg; -int timeout =AI_MAILBOX_TIMEDOUT ; -u32 mask =REG_FIELD_MASK (BIF_BX_PF0_MAILBOX_CONTROL ,RCV_MSG_VALID ); - - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); - reg =REG_SET_FIELD (reg,BIF_BX_PF0_MAILBOX_CONTROL ,RCV_MSG_ACK ,1 ); -WREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL), reg); - -/*Wait for RCV_MSG_VALID to be 0*/ - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); -while (reg & mask) { -if (timeout <=0 ) { -pr_err ("RCV_MSG_VALID is not cleared\n" ); -break ; - } -mdelay (1 ); - timeout -=1 ; - - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); - } +const u32 offset =SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL) *4 +1 ; +WREG8 (offset,2 ); }static void xgpu_ai_mailbox_set_valid (struct amdgpu_device *adev,bool val) { -u32 reg; +const u32 offset =SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL) *4 ; +WREG8 (offset, val ?1 :0 ); +} - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); - reg =REG_SET_FIELD (reg,BIF_BX_PF0_MAILBOX_CONTROL , -TRN_MSG_VALID , val ?1 :0 ); -WREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL), - reg); +/* +* this peek_msg could *only* be called in IRQ routine becuase in IRQ routine +* RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1 +* by host. +* +* if called no in IRQ routine, this peek_msg cannot guaranteed to return the +* correct value since it doesn't return the RCV_DW0 under the case that +* RCV_MSG_VALID is set by host. +*/ +static enum idh_event xgpu_ai_mailbox_peek_msg (struct amdgpu_device *adev) +{ +return RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , + mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0)); } +static int xgpu_ai_mailbox_rcv_msg (struct amdgpu_device *adev,enum idh_event event) { +const u32 offset =SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL) *4 +1 ;u32 reg; -u32 mask =REG_FIELD_MASK (BIF_BX_PF0_MAILBOX_CONTROL ,RCV_MSG_VALID ); -if (event !=IDH_FLR_NOTIFICATION_CMPL ) { - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); -if (!(reg & mask)) -return -ENOENT ; - } +/* return -1 if didn't receive RCV_MSG_VALID */ +if (event !=IDH_FLR_NOTIFICATION_CMPL ) +if (!(RREG8 (offset) &1 )) +return -1 ; reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
@@ -94,54 +80,69 @@ static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,return 0 ; } +static uint8_t xgpu_ai_peek_ack (struct amdgpu_device *adev) { +const u32 offset =SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL) *4 ; +return (RREG8 (offset) &2 ); +} +static int xgpu_ai_poll_ack (struct amdgpu_device *adev) { -int r =0 , timeout =AI_MAILBOX_TIMEDOUT ; -u32 mask =REG_FIELD_MASK (BIF_BX_PF0_MAILBOX_CONTROL ,TRN_MSG_ACK ); -u32 reg; +const u32 offset =SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_CONTROL) *4 ; +int timeout =AI_MAILBOX_POLL_ACK_TIMEDOUT ; +u8 reg; + +do { + reg =RREG8 (offset); +if (reg &2 ) +return 0 ; - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); -while (!(reg & mask)) { -if (timeout <=0 ) { -pr_err ("Doesn't get ack from pf.\n" ); - r = -ETIME ; -break ; - }mdelay (5 ); timeout -=5 ; + }while (timeout >1 ); - reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , - mmBIF_BX_PF0_MAILBOX_CONTROL)); - } +pr_err ("Doesn't get TRN_MSG_ACK from pf in %d msec\n" ,AI_MAILBOX_POLL_ACK_TIMEDOUT ); -return r; +return -ETIME ; }static int xgpu_ai_poll_msg (struct amdgpu_device *adev,enum idh_event event) { -int r =0 , timeout =AI_MAILBOX_TIMEDOUT ; - - r =xgpu_ai_mailbox_rcv_msg (adev, event); -while (r) { -if (timeout <=0 ) { -pr_err ("Doesn't get msg:%d from pf.\n" , event); - r = -ETIME ; -break ; - } -mdelay (5 ); - timeout -=5 ; +int r, timeout =AI_MAILBOX_POLL_MSG_TIMEDOUT ; +do { r =xgpu_ai_mailbox_rcv_msg (adev, event); - } +if (!r) +return 0 ; -return r; +msleep (10 ); + timeout -=10 ; + }while (timeout >1 ); + +pr_err ("Doesn't get msg:%d from pf, error=%d\n" , event, r); + +return -ETIME ; }static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,enum idh_request req,u32 data1,u32 data2,u32 data3) {u32 reg;int r; +uint8_t trn; + +/* IMPORTANT: +* clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK +* and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK +* which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack() +* will return immediatly +*/ +do { +xgpu_ai_mailbox_set_valid (adev, false); + trn =xgpu_ai_peek_ack (adev); +if (trn) { +pr_err ("trn=%x ACK should not asssert! wait again !\n" , trn); +msleep (1 ); + } + }while (trn); reg =RREG32_NO_KIQ (SOC15_REG_OFFSET (NBIO ,0 , mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
@@ -245,15 +246,32 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work) { struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work); struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt); - -/* wait until RCV_MSG become 3 */ -if (xgpu_ai_poll_msg (adev,IDH_FLR_NOTIFICATION_CMPL )) { -pr_err ("failed to recieve FLR_CMPL\n" ); -return ; - } - -/* Trigger recovery due to world switch failure */ -amdgpu_device_gpu_recover (adev,NULL , false); +int timeout =AI_MAILBOX_POLL_FLR_TIMEDOUT ; +int locked; + +/* block amdgpu_gpu_recover till msg FLR COMPLETE received, +* otherwise mailbox msg from being ruined/reseted by +* VF FLR triggered by hypervisor's idle fail. +*/ + locked =mutex_trylock (&adev->lock_reset); +if (locked) + adev->in_gpu_reset =1 ; + +do { +if (xgpu_ai_mailbox_peek_msg (adev) ==IDH_FLR_NOTIFICATION_CMPL ) + goto flr_done; + +msleep (10 ); + timeout -=10 ; + }while (timeout >1 ); + +flr_done: +if (locked) +mutex_unlock (&adev->lock_reset); + +/* Trigger recovery for world switch failure if no TDR */ +if (amdgpu_lockup_timeout ==0 ) +amdgpu_device_gpu_recover (adev,NULL , true); } static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -274,24 +292,22 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,struct amdgpu_irq_src *source, struct amdgpu_iv_entry *entry) { - int r; - -/* trigger gpu-reset by hypervisor only if TDR disbaled */ -if (!amdgpu_gpu_recovery) { -/* see what event we get */ - r =xgpu_ai_mailbox_rcv_msg (adev,IDH_FLR_NOTIFICATION ); - -/* sometimes the interrupt is delayed to inject to VM, so under such case -* the IDH_FLR_NOTIFICATION is overwritten by VF FLR from GIM side, thus -* above recieve message could be failed, we should schedule the flr_work -* anyway + enum idh_event event = xgpu_ai_mailbox_peek_msg(adev); + +switch (event) { +case IDH_FLR_NOTIFICATION : +if (amdgpu_sriov_runtime (adev)) +schedule_work (&adev->virt.flr_work); +break ; +/* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore +* it byfar since that polling thread will handle it, +* other msg like flr complete is not handled here. */ -if (r) { -DRM_ERROR ("FLR_NOTIFICATION is missed\n" ); -xgpu_ai_mailbox_send_ack (adev); - } - -schedule_work (&adev->virt.flr_work); +case IDH_CLR_MSG_BUF : +case IDH_FLR_NOTIFICATION_CMPL : +case IDH_READY_TO_ACCESS_GPU : +default : +break ; }return 0 ;
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h +3 -1
@@ -24,7 +24,9 @@#ifndef __MXGPU_AI_H__#define __MXGPU_AI_H__ -#define AI_MAILBOX_TIMEDOUT 12000 +#define AI_MAILBOX_POLL_ACK_TIMEDOUT 500 +#define AI_MAILBOX_POLL_MSG_TIMEDOUT 12000 +#define AI_MAILBOX_POLL_FLR_TIMEDOUT 500enum idh_request { IDH_REQ_GPU_INIT_ACCESS = 1,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1520306150-29325-2-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
It’s a long patch which could split into 6 pieces at most… anyway I got some questions inline to have a better understanding.
—
Sincerely Yours,
Pixel
On 06/03/2018, 11:29 AM, "amd-gfx on behalf of Monk Liu" <[email protected] on behalf of [email protected]> wrote:
this patch actually refactor mailbox implmentations, and all below changes are needed together to fix all those mailbox handshake issues exposured by heavey TDR test.
1)refactor all mailbox functions based on byte accessing for mb_control reason is to avoid touching non-related bits when writing trn/rcv part of mailbox_control, this way some incorrect INTR sent to hypervisor side could be avoided, and it fixes couple handshake bug.
2)trans_msg function re-impled: put a invalid
logic before transmitting message to make sure the ACK bit is in a clear status, otherwise there is chance that ACK asserted already before transmitting message and lead to fake ACK polling. (hypervisor side have some tricks to workaround ACK bit being corrupted by VF FLR which hase an side effects that may make guest side ACK bit asserted wrongly), and clear TRANS_MSG words after message transferred.
3)for mailbox_flr_work, it is also re-worked: it takes the mutex lock first if invoked, to block gpu recover's participate too early while hypervisor side is doing VF FLR. (hypervisor sends FLR_NOTIFY to guest before doing VF FLR and sentds FLR_COMPLETE after VF FLR done, and the FLR_NOTIFY will trigger interrupt to guest which lead to mailbox_flr_work being invoked)
This can avoid the issue that mailbox trans msg being cleared by its VF FLR.
4)for mailbox_rcv_irq IRQ routine, it should only peek msg and schedule mailbox_flr_work, instead of ACK to hypervisor itself, because FLR_NOTIFY msg sent from hypervisor side doesn't need VF's ACK (this is because VF's ACK would lead to hypervisor clear its trans_valid/msg, and this would cause handshake bug if trans_valid/msg is cleared not due to correct VF ACK but from a wrong VF ACK like this "FLR_NOTIFY" one)
Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
This fixed handshake bug that sometimes GUEST always couldn't receive
"READY_TO_ACCESS_GPU" msg from hypervisor.
5)seperate polling time limite accordingly:
POLL ACK cost no more than 500ms
POLL MSG cost no more than 12000ms
POLL FLR finish cost no more than 500ms
6) we still need to set adev into in_gpu_reset mode after we received
FLR_NOTIFY from host side, this can prevent innocent app wrongly succesed
to open amdgpu dri device.
FLR_NOFITY is received due to an IDLE hang detected from hypervisor side
which indicating GPU is already die in this VF.
Change-Id: I17df8b4490a5b53a1cc2bd6c8f9bc3ee14c23f1a
Signed-off-by: Monk Liu <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 200 ++++++++++++++++++----------------
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h | 4 +-
2 files changed, 111 insertions(+), 93 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
index 271452d..8d09380 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
@@ -33,56 +33,42 @@
static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
{
- u32 reg;
- int timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_ACK, 1);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL), reg);
-
- /*Wait for RCV_MSG_VALID to be 0*/
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (reg & mask) {
- if (timeout <= 0) {
- pr_err("RCV_MSG_VALID is not cleared\n");
- break;
- }
- mdelay(1);
- timeout -=1;
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- } + const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
+ WREG8(offset, 2);
it’s not clear to understand the last 2 lines of code here to set RCV_MSG_ACK bit: 0x10 to +1 byte offset. Can we define some macros to make it clear?
}
static void xgpu_ai_mailbox_set_valid(struct amdgpu_device *adev, bool val)
{
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4; + WREG8(offset, val ? 1 : 0);
same problem here. 0x1 to +0 byte offset.
+}
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL,
- TRN_MSG_VALID, val ? 1 : 0);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL),
- reg);
+/* + * this peek_msg could *only* be called in IRQ routine becuase in IRQ routine
+ * RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1
+ * by host.
+ *
+ * if called no in IRQ routine, this peek_msg cannot guaranteed to return the
+ * correct value since it doesn't return the RCV_DW0 under the case that
+ * RCV_MSG_VALID is set by host.
+ */
typos in comments.
+static enum idh_event xgpu_ai_mailbox_peek_msg(struct amdgpu_device *adev)
+{
+ return RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
+ mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
}
+
static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
enum idh_event event)
{
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
u32 reg;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
- if (event != IDH_FLR_NOTIFICATION_CMPL) {
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- if (!(reg & mask))
- return -ENOENT;
- }
+ /* return -1 if didn't receive RCV_MSG_VALID */
+ if (event != IDH_FLR_NOTIFICATION_CMPL)
+ if (!(RREG8(offset) & 1))
+ return -1;Can we also set valid bit for IDH_FLR_NOTIFICATION_CMPL event in GIM? By now guest use peek_msg to catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also use peek_ack to ack CMPL if it’s necessary. any problem?
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
@@ -94,54 +80,69 @@ static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
return 0;
}
+static uint8_t xgpu_ai_peek_ack(struct amdgpu_device *adev) {
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ return (RREG8(offset) & 2);
+}
+
static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, TRN_MSG_ACK);
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ int timeout = AI_MAILBOX_POLL_ACK_TIMEDOUT;
+ u8 reg;
+
+ do {
+ reg = RREG8(offset);
+ if (reg & 2)
+ return 0;
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (!(reg & mask)) {
- if (timeout <= 0) {
- pr_err("Doesn't get ack from pf.\n");
- r = -ETIME;
- break;
- }
mdelay(5);
timeout -= 5;
+ } while (timeout > 1);
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ pr_err("Doesn't get TRN_MSG_ACK from pf in %d msec\n", AI_MAILBOX_POLL_ACK_TIMEDOUT);
- return r;
+ return -ETIME;
}
static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
-
- r = xgpu_ai_mailbox_rcv_msg(adev, event);
- while (r) {
- if (timeout <= 0) {
- pr_err("Doesn't get msg:%d from pf.\n", event);
- r = -ETIME;
- break;
- }
- mdelay(5);
- timeout -= 5;
+ int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
+ do {
r = xgpu_ai_mailbox_rcv_msg(adev, event);
- }
+ if (!r)
+ return 0;
- return r;
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+ pr_err("Doesn't get msg:%d from pf, error=%d\n", event, r);
+
+ return -ETIME;
}
static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
enum idh_request req, u32 data1, u32 data2, u32 data3) {
u32 reg;
int r;
+ uint8_t trn;
+
+ /* IMPORTANT:
+ * clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK
+ * and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK
+ * which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack()
+ * will return immediatly
+ */
+ do {
+ xgpu_ai_mailbox_set_valid(adev, false);
+ trn = xgpu_ai_peek_ack(adev);
+ if (trn) {
+ pr_err("trn=%x ACK should not asssert! wait again !\n", trn);
+ msleep(1);
+ }
+ } while(trn);
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
@@ -245,15 +246,32 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
{
struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work);
struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt);
-
- /* wait until RCV_MSG become 3 */
- if (xgpu_ai_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL)) {
- pr_err("failed to recieve FLR_CMPL\n");
- return;
- }
-
- /* Trigger recovery due to world switch failure */
- amdgpu_device_gpu_recover(adev, NULL, false);
+ int timeout = AI_MAILBOX_POLL_FLR_TIMEDOUT;
+ int locked;
+
+ /* block amdgpu_gpu_recover till msg FLR COMPLETE received,
+ * otherwise mailbox msg from being ruined/reseted by
+ * VF FLR triggered by hypervisor's idle fail.
+ */
+ locked = mutex_trylock(&adev->lock_reset);
+ if (locked)
+ adev->in_gpu_reset = 1;
+
+ do {
+ if (xgpu_ai_mailbox_peek_msg(adev) == IDH_FLR_NOTIFICATION_CMPL)
+ goto flr_done;
+
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+flr_done:
+ if (locked)
+ mutex_unlock(&adev->lock_reset);
+
+ /* Trigger recovery for world switch failure if no TDR */
+ if (amdgpu_lockup_timeout == 0)
+ amdgpu_device_gpu_recover(adev, NULL, true);
}
static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -274,24 +292,22 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
struct amdgpu_irq_src *source,
struct amdgpu_iv_entry *entry)
{
- int r;
-
- /* trigger gpu-reset by hypervisor only if TDR disbaled */
- if (!amdgpu_gpu_recovery) {
- /* see what event we get */
- r = xgpu_ai_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
-
- /* sometimes the interrupt is delayed to inject to VM, so under such case
- * the IDH_FLR_NOTIFICATION is overwritten by VF FLR from GIM side, thus
- * above recieve message could be failed, we should schedule the flr_work
- * anyway
+ enum idh_event event = xgpu_ai_mailbox_peek_msg(adev);
+
+ switch (event) {
+ case IDH_FLR_NOTIFICATION:
+ if (amdgpu_sriov_runtime(adev))
+ schedule_work(&adev->virt.flr_work);
+ break;
+ /* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
+ * it byfar since that polling thread will handle it,
+ * other msg like flr complete is not handled here.
*/
- if (r) {
- DRM_ERROR("FLR_NOTIFICATION is missed\n");
- xgpu_ai_mailbox_send_ack(adev);
- }
-
- schedule_work(&adev->virt.flr_work);
+ case IDH_CLR_MSG_BUF:
+ case IDH_FLR_NOTIFICATION_CMPL:
+ case IDH_READY_TO_ACCESS_GPU:
+ default:
+ break;
}
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
index 67e7857..7ca4be5 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
@@ -24,7 +24,9 @@
#ifndef __MXGPU_AI_H__
#define __MXGPU_AI_H__
-#define AI_MAILBOX_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_ACK_TIMEDOUT 500
+#define AI_MAILBOX_POLL_MSG_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_FLR_TIMEDOUT 500
enum idh_request {
IDH_REQ_GPU_INIT_ACCESS = 1,
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 64AC6506-8FCF-49BE-B243-3786DBB701FD-5C7GfCeVMHo@public.gmane.org
RE: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
HI Pixel
The patch better not to be split, otherwise the stress TDR test still fail since there are couple issues and some of them mixed together
For your concerns:
Quoted 1 line
Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case
FLR_NOTIFYfollowed byREADY_TO_ACCESS_GPUimmediately). Is it correct? If so, maybe we need further protection in GIM.
We had a lot of fixings in GIM side along with this patch to make stress TDR test finally passed, you can watch the history, anyway GIM side is not related with this patch
Quoted 1 line
it’s not clear to understand the last 2 lines of code here to set
RCV_MSG_ACKbit:0x10to +1 byte offset. Can we define some macros to make it clear?
Can you do that ? looks to me the MACRO in amdgpu only works for DW aligned register names, so I'm afraid we cannot do that gracefully
Quoted 1 line
Can we also set valid bit for
IDH_FLR_NOTIFICATION_CMPLevent in GIM? By now guest usepeek_msgto catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also usepeek_ackto ack CMPL if it’s necessary. any problem?
I don't understand your point
-----Original Message-----
From: Ding, Pixel
Sent: 2018年3月7日 16:31
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
It’s a long patch which could split into 6 pieces at most… anyway I got some questions inline to have a better understanding.
—
Sincerely Yours,
Pixel
On 06/03/2018, 11:29 AM, "amd-gfx on behalf of Monk Liu" <[email protected] on behalf of [email protected]> wrote:
this patch actually refactor mailbox implmentations, and all below changes are needed together to fix all those mailbox handshake issues exposured by heavey TDR test.
1)refactor all mailbox functions based on byte accessing for mb_control reason is to avoid touching non-related bits when writing trn/rcv part of mailbox_control, this way some incorrect INTR sent to hypervisor side could be avoided, and it fixes couple handshake bug.
2)trans_msg function re-impled: put a invalid
logic before transmitting message to make sure the ACK bit is in a clear status, otherwise there is chance that ACK asserted already before transmitting message and lead to fake ACK polling. (hypervisor side have some tricks to workaround ACK bit being corrupted by VF FLR which hase an side effects that may make guest side ACK bit asserted wrongly), and clear TRANS_MSG words after message transferred.
3)for mailbox_flr_work, it is also re-worked: it takes the mutex lock first if invoked, to block gpu recover's participate too early while hypervisor side is doing VF FLR. (hypervisor sends FLR_NOTIFY to guest before doing VF FLR and sentds FLR_COMPLETE after VF FLR done, and the FLR_NOTIFY will trigger interrupt to guest which lead to mailbox_flr_work being invoked)
This can avoid the issue that mailbox trans msg being cleared by its VF FLR.
4)for mailbox_rcv_irq IRQ routine, it should only peek msg and schedule mailbox_flr_work, instead of ACK to hypervisor itself, because FLR_NOTIFY msg sent from hypervisor side doesn't need VF's ACK (this is because VF's ACK would lead to hypervisor clear its trans_valid/msg, and this would cause handshake bug if trans_valid/msg is cleared not due to correct VF ACK but from a wrong VF ACK like this "FLR_NOTIFY" one)
Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
This fixed handshake bug that sometimes GUEST always couldn't receive
"READY_TO_ACCESS_GPU" msg from hypervisor.
5)seperate polling time limite accordingly:
POLL ACK cost no more than 500ms
POLL MSG cost no more than 12000ms
POLL FLR finish cost no more than 500ms
6) we still need to set adev into in_gpu_reset mode after we received
FLR_NOTIFY from host side, this can prevent innocent app wrongly succesed
to open amdgpu dri device.
FLR_NOFITY is received due to an IDLE hang detected from hypervisor side
which indicating GPU is already die in this VF.
Change-Id: I17df8b4490a5b53a1cc2bd6c8f9bc3ee14c23f1a
Signed-off-by: Monk Liu <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 200 ++++++++++++++++++----------------
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h | 4 +-
2 files changed, 111 insertions(+), 93 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
index 271452d..8d09380 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
@@ -33,56 +33,42 @@
static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
{
- u32 reg;
- int timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_ACK, 1);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL), reg);
-
- /*Wait for RCV_MSG_VALID to be 0*/
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (reg & mask) {
- if (timeout <= 0) {
- pr_err("RCV_MSG_VALID is not cleared\n");
- break;
- }
- mdelay(1);
- timeout -=1;
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- } + const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
+ WREG8(offset, 2);
it’s not clear to understand the last 2 lines of code here to set RCV_MSG_ACK bit: 0x10 to +1 byte offset. Can we define some macros to make it clear?
}
static void xgpu_ai_mailbox_set_valid(struct amdgpu_device *adev, bool val)
{
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4; + WREG8(offset, val ? 1 : 0);
same problem here. 0x1 to +0 byte offset.
+}
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL,
- TRN_MSG_VALID, val ? 1 : 0);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL),
- reg);
+/* + * this peek_msg could *only* be called in IRQ routine becuase in IRQ routine
+ * RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1
+ * by host.
+ *
+ * if called no in IRQ routine, this peek_msg cannot guaranteed to return the
+ * correct value since it doesn't return the RCV_DW0 under the case that
+ * RCV_MSG_VALID is set by host.
+ */
typos in comments.
+static enum idh_event xgpu_ai_mailbox_peek_msg(struct amdgpu_device *adev)
+{
+ return RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
+ mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
}
+
static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
enum idh_event event)
{
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
u32 reg;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
- if (event != IDH_FLR_NOTIFICATION_CMPL) {
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- if (!(reg & mask))
- return -ENOENT;
- }
+ /* return -1 if didn't receive RCV_MSG_VALID */
+ if (event != IDH_FLR_NOTIFICATION_CMPL)
+ if (!(RREG8(offset) & 1))
+ return -1;Can we also set valid bit for IDH_FLR_NOTIFICATION_CMPL event in GIM? By now guest use peek_msg to catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also use peek_ack to ack CMPL if it’s necessary. any problem?
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
@@ -94,54 +80,69 @@ static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
return 0;
}
+static uint8_t xgpu_ai_peek_ack(struct amdgpu_device *adev) {
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ return (RREG8(offset) & 2);
+}
+
static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, TRN_MSG_ACK);
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ int timeout = AI_MAILBOX_POLL_ACK_TIMEDOUT;
+ u8 reg;
+
+ do {
+ reg = RREG8(offset);
+ if (reg & 2)
+ return 0;
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (!(reg & mask)) {
- if (timeout <= 0) {
- pr_err("Doesn't get ack from pf.\n");
- r = -ETIME;
- break;
- }
mdelay(5);
timeout -= 5;
+ } while (timeout > 1);
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ pr_err("Doesn't get TRN_MSG_ACK from pf in %d msec\n", AI_MAILBOX_POLL_ACK_TIMEDOUT);
- return r;
+ return -ETIME;
}
static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
-
- r = xgpu_ai_mailbox_rcv_msg(adev, event);
- while (r) {
- if (timeout <= 0) {
- pr_err("Doesn't get msg:%d from pf.\n", event);
- r = -ETIME;
- break;
- }
- mdelay(5);
- timeout -= 5;
+ int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
+ do {
r = xgpu_ai_mailbox_rcv_msg(adev, event);
- }
+ if (!r)
+ return 0;
- return r;
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+ pr_err("Doesn't get msg:%d from pf, error=%d\n", event, r);
+
+ return -ETIME;
}
static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
enum idh_request req, u32 data1, u32 data2, u32 data3) {
u32 reg;
int r;
+ uint8_t trn;
+
+ /* IMPORTANT:
+ * clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK
+ * and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK
+ * which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack()
+ * will return immediatly
+ */
+ do {
+ xgpu_ai_mailbox_set_valid(adev, false);
+ trn = xgpu_ai_peek_ack(adev);
+ if (trn) {
+ pr_err("trn=%x ACK should not asssert! wait again !\n", trn);
+ msleep(1);
+ }
+ } while(trn);
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
@@ -245,15 +246,32 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
{
struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work);
struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt);
-
- /* wait until RCV_MSG become 3 */
- if (xgpu_ai_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL)) {
- pr_err("failed to recieve FLR_CMPL\n");
- return;
- }
-
- /* Trigger recovery due to world switch failure */
- amdgpu_device_gpu_recover(adev, NULL, false);
+ int timeout = AI_MAILBOX_POLL_FLR_TIMEDOUT;
+ int locked;
+
+ /* block amdgpu_gpu_recover till msg FLR COMPLETE received,
+ * otherwise mailbox msg from being ruined/reseted by
+ * VF FLR triggered by hypervisor's idle fail.
+ */
+ locked = mutex_trylock(&adev->lock_reset);
+ if (locked)
+ adev->in_gpu_reset = 1;
+
+ do {
+ if (xgpu_ai_mailbox_peek_msg(adev) == IDH_FLR_NOTIFICATION_CMPL)
+ goto flr_done;
+
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+flr_done:
+ if (locked)
+ mutex_unlock(&adev->lock_reset);
+
+ /* Trigger recovery for world switch failure if no TDR */
+ if (amdgpu_lockup_timeout == 0)
+ amdgpu_device_gpu_recover(adev, NULL, true);
}
static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -274,24 +292,22 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
struct amdgpu_irq_src *source,
struct amdgpu_iv_entry *entry)
{
- int r;
-
- /* trigger gpu-reset by hypervisor only if TDR disbaled */
- if (!amdgpu_gpu_recovery) {
- /* see what event we get */
- r = xgpu_ai_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
-
- /* sometimes the interrupt is delayed to inject to VM, so under such case
- * the IDH_FLR_NOTIFICATION is overwritten by VF FLR from GIM side, thus
- * above recieve message could be failed, we should schedule the flr_work
- * anyway
+ enum idh_event event = xgpu_ai_mailbox_peek_msg(adev);
+
+ switch (event) {
+ case IDH_FLR_NOTIFICATION:
+ if (amdgpu_sriov_runtime(adev))
+ schedule_work(&adev->virt.flr_work);
+ break;
+ /* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
+ * it byfar since that polling thread will handle it,
+ * other msg like flr complete is not handled here.
*/
- if (r) {
- DRM_ERROR("FLR_NOTIFICATION is missed\n");
- xgpu_ai_mailbox_send_ack(adev);
- }
-
- schedule_work(&adev->virt.flr_work);
+ case IDH_CLR_MSG_BUF:
+ case IDH_FLR_NOTIFICATION_CMPL:
+ case IDH_READY_TO_ACCESS_GPU:
+ default:
+ break;
}
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
index 67e7857..7ca4be5 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
@@ -24,7 +24,9 @@
#ifndef __MXGPU_AI_H__
#define __MXGPU_AI_H__
-#define AI_MAILBOX_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_ACK_TIMEDOUT 500
+#define AI_MAILBOX_POLL_MSG_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_FLR_TIMEDOUT 500
enum idh_request {
IDH_REQ_GPU_INIT_ACCESS = 1,
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BLUPR12MB0449FA6BB0EB1934AA8DACA984D80-7LeqcoF/[email protected]
Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
See comments inline.
—
Sincerely Yours,
Pixel
On 07/03/2018, 4:58 PM, "Liu, Monk" <[email protected]> wrote:
HI Pixel
The patch better not to be split, otherwise the stress TDR test still fail since there are couple issues and some of them mixed together
For your concerns:
> Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
We had a lot of fixings in GIM side along with this patch to make stress TDR test finally passed, you can watch the history, anyway GIM side is not related with this patch
[Pixel]Per talked offline, understand your point here.
Quoted 1 line
it’s not clear to understand the last 2 lines of code here to set
RCV_MSG_ACKbit:0x10to +1 byte offset. Can we define some macros to make it clear?
Can you do that ? looks to me the MACRO in amdgpu only works for DW aligned register names, so I'm afraid we cannot do that gracefully
[Pixel] some readable macros can help us easily understand which register field is accessed.
Quoted 1 line
Can we also set valid bit for
IDH_FLR_NOTIFICATION_CMPLevent in GIM? By now guest usepeek_msgto catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also usepeek_ackto ack CMPL if it’s necessary. any problem?
I don't understand your point
[Pixel]generally, CMPL is not handled by rcv_msg anymore but in peek_msg. we can remove the logics here.
-----Original Message-----
From: Ding, Pixel
Sent: 2018年3月7日 16:31
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
It’s a long patch which could split into 6 pieces at most… anyway I got some questions inline to have a better understanding.
—
Sincerely Yours,
Pixel
On 06/03/2018, 11:29 AM, "amd-gfx on behalf of Monk Liu" <[email protected] on behalf of [email protected]> wrote:
this patch actually refactor mailbox implmentations, and
all below changes are needed together to fix all those mailbox
handshake issues exposured by heavey TDR test.
1)refactor all mailbox functions based on byte accessing for mb_control
reason is to avoid touching non-related bits when writing trn/rcv part of
mailbox_control, this way some incorrect INTR sent to hypervisor
side could be avoided, and it fixes couple handshake bug.
2)trans_msg function re-impled: put a invalid
logic before transmitting message to make sure the ACK bit is in
a clear status, otherwise there is chance that ACK asserted already
before transmitting message and lead to fake ACK polling.
(hypervisor side have some tricks to workaround ACK bit being corrupted
by VF FLR which hase an side effects that may make guest side ACK bit
asserted wrongly), and clear TRANS_MSG words after message transferred.
3)for mailbox_flr_work, it is also re-worked: it takes the mutex lock
first if invoked, to block gpu recover's participate too early while
hypervisor side is doing VF FLR. (hypervisor sends FLR_NOTIFY to guest
before doing VF FLR and sentds FLR_COMPLETE after VF FLR done, and
the FLR_NOTIFY will trigger interrupt to guest which lead to
mailbox_flr_work being invoked)
This can avoid the issue that mailbox trans msg being cleared by its VF FLR.
4)for mailbox_rcv_irq IRQ routine, it should only peek msg and schedule
mailbox_flr_work, instead of ACK to hypervisor itself, because FLR_NOTIFY
msg sent from hypervisor side doesn't need VF's ACK (this is because
VF's ACK would lead to hypervisor clear its trans_valid/msg, and this
would cause handshake bug if trans_valid/msg is cleared not due to
correct VF ACK but from a wrong VF ACK like this "FLR_NOTIFY" one)
Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
This fixed handshake bug that sometimes GUEST always couldn't receive
"READY_TO_ACCESS_GPU" msg from hypervisor.
5)seperate polling time limite accordingly:
POLL ACK cost no more than 500ms
POLL MSG cost no more than 12000ms
POLL FLR finish cost no more than 500ms
6) we still need to set adev into in_gpu_reset mode after we received
FLR_NOTIFY from host side, this can prevent innocent app wrongly succesed
to open amdgpu dri device.
FLR_NOFITY is received due to an IDLE hang detected from hypervisor side
which indicating GPU is already die in this VF.
Change-Id: I17df8b4490a5b53a1cc2bd6c8f9bc3ee14c23f1a
Signed-off-by: Monk Liu <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 200 ++++++++++++++++++----------------
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h | 4 +-
2 files changed, 111 insertions(+), 93 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
index 271452d..8d09380 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
@@ -33,56 +33,42 @@
static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
{
- u32 reg;
- int timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_ACK, 1);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL), reg);
-
- /*Wait for RCV_MSG_VALID to be 0*/
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (reg & mask) {
- if (timeout <= 0) {
- pr_err("RCV_MSG_VALID is not cleared\n");
- break;
- }
- mdelay(1);
- timeout -=1;
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
+ WREG8(offset, 2);
it’s not clear to understand the last 2 lines of code here to set RCV_MSG_ACK bit: 0x10 to +1 byte offset. Can we define some macros to make it clear?
}
static void xgpu_ai_mailbox_set_valid(struct amdgpu_device *adev, bool val)
{
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ WREG8(offset, val ? 1 : 0);
same problem here. 0x1 to +0 byte offset.
+}
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL,
- TRN_MSG_VALID, val ? 1 : 0);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL),
- reg);
+/*
+ * this peek_msg could *only* be called in IRQ routine becuase in IRQ routine
+ * RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1
+ * by host.
+ *
+ * if called no in IRQ routine, this peek_msg cannot guaranteed to return the
+ * correct value since it doesn't return the RCV_DW0 under the case that
+ * RCV_MSG_VALID is set by host.
+ */
typos in comments.
+static enum idh_event xgpu_ai_mailbox_peek_msg(struct amdgpu_device *adev)
+{
+ return RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
+ mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
}
+
static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
enum idh_event event)
{
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
u32 reg;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
- if (event != IDH_FLR_NOTIFICATION_CMPL) {
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- if (!(reg & mask))
- return -ENOENT;
- }
+ /* return -1 if didn't receive RCV_MSG_VALID */
+ if (event != IDH_FLR_NOTIFICATION_CMPL)
+ if (!(RREG8(offset) & 1))
+ return -1;
Can we also set valid bit for IDH_FLR_NOTIFICATION_CMPL event in GIM? By now guest use peek_msg to catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also use peek_ack to ack CMPL if it’s necessary. any problem?
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
@@ -94,54 +80,69 @@ static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
return 0;
}
+static uint8_t xgpu_ai_peek_ack(struct amdgpu_device *adev) {
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ return (RREG8(offset) & 2);
+}
+
static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, TRN_MSG_ACK);
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ int timeout = AI_MAILBOX_POLL_ACK_TIMEDOUT;
+ u8 reg;
+
+ do {
+ reg = RREG8(offset);
+ if (reg & 2)
+ return 0;
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (!(reg & mask)) {
- if (timeout <= 0) {
- pr_err("Doesn't get ack from pf.\n");
- r = -ETIME;
- break;
- }
mdelay(5);
timeout -= 5;
+ } while (timeout > 1);
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ pr_err("Doesn't get TRN_MSG_ACK from pf in %d msec\n", AI_MAILBOX_POLL_ACK_TIMEDOUT);
- return r;
+ return -ETIME;
}
static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
-
- r = xgpu_ai_mailbox_rcv_msg(adev, event);
- while (r) {
- if (timeout <= 0) {
- pr_err("Doesn't get msg:%d from pf.\n", event);
- r = -ETIME;
- break;
- }
- mdelay(5);
- timeout -= 5;
+ int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
+ do {
r = xgpu_ai_mailbox_rcv_msg(adev, event);
- }
+ if (!r)
+ return 0;
- return r;
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+ pr_err("Doesn't get msg:%d from pf, error=%d\n", event, r);
+
+ return -ETIME;
}
static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
enum idh_request req, u32 data1, u32 data2, u32 data3) {
u32 reg;
int r;
+ uint8_t trn;
+
+ /* IMPORTANT:
+ * clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK
+ * and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK
+ * which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack()
+ * will return immediatly
+ */
+ do {
+ xgpu_ai_mailbox_set_valid(adev, false);
+ trn = xgpu_ai_peek_ack(adev);
+ if (trn) {
+ pr_err("trn=%x ACK should not asssert! wait again !\n", trn);
+ msleep(1);
+ }
+ } while(trn);
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
@@ -245,15 +246,32 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
{
struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work);
struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt);
-
- /* wait until RCV_MSG become 3 */
- if (xgpu_ai_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL)) {
- pr_err("failed to recieve FLR_CMPL\n");
- return;
- }
-
- /* Trigger recovery due to world switch failure */
- amdgpu_device_gpu_recover(adev, NULL, false);
+ int timeout = AI_MAILBOX_POLL_FLR_TIMEDOUT;
+ int locked;
+
+ /* block amdgpu_gpu_recover till msg FLR COMPLETE received,
+ * otherwise mailbox msg from being ruined/reseted by
+ * VF FLR triggered by hypervisor's idle fail.
+ */
+ locked = mutex_trylock(&adev->lock_reset);
+ if (locked)
+ adev->in_gpu_reset = 1;
+
+ do {
+ if (xgpu_ai_mailbox_peek_msg(adev) == IDH_FLR_NOTIFICATION_CMPL)
+ goto flr_done;
+
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+flr_done:
+ if (locked)
+ mutex_unlock(&adev->lock_reset);
+
+ /* Trigger recovery for world switch failure if no TDR */
+ if (amdgpu_lockup_timeout == 0)
+ amdgpu_device_gpu_recover(adev, NULL, true);
}
static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -274,24 +292,22 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
struct amdgpu_irq_src *source,
struct amdgpu_iv_entry *entry)
{
- int r;
-
- /* trigger gpu-reset by hypervisor only if TDR disbaled */
- if (!amdgpu_gpu_recovery) {
- /* see what event we get */
- r = xgpu_ai_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
-
- /* sometimes the interrupt is delayed to inject to VM, so under such case
- * the IDH_FLR_NOTIFICATION is overwritten by VF FLR from GIM side, thus
- * above recieve message could be failed, we should schedule the flr_work
- * anyway
+ enum idh_event event = xgpu_ai_mailbox_peek_msg(adev);
+
+ switch (event) {
+ case IDH_FLR_NOTIFICATION:
+ if (amdgpu_sriov_runtime(adev))
+ schedule_work(&adev->virt.flr_work);
+ break;
+ /* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
+ * it byfar since that polling thread will handle it,
+ * other msg like flr complete is not handled here.
*/
- if (r) {
- DRM_ERROR("FLR_NOTIFICATION is missed\n");
- xgpu_ai_mailbox_send_ack(adev);
- }
-
- schedule_work(&adev->virt.flr_work);
+ case IDH_CLR_MSG_BUF:
+ case IDH_FLR_NOTIFICATION_CMPL:
+ case IDH_READY_TO_ACCESS_GPU:
+ default:
+ break;
}
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
index 67e7857..7ca4be5 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
@@ -24,7 +24,9 @@
#ifndef __MXGPU_AI_H__
#define __MXGPU_AI_H__
-#define AI_MAILBOX_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_ACK_TIMEDOUT 500
+#define AI_MAILBOX_POLL_MSG_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_FLR_TIMEDOUT 500
enum idh_request {
IDH_REQ_GPU_INIT_ACCESS = 1,
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 35796F46-44A2-494C-909B-9100BAEFDA20-5C7GfCeVMHo@public.gmane.org
RE: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Quoted 1 line
Can you do that ? looks to me the MACRO in amdgpu only works for DW aligned register names, so I'm afraid we cannot do that gracefully
[Pixel] some readable macros can help us easily understand which register field is accessed.
[ml] I can try it
Quoted 1 line
[Pixel]generally, CMPL is not handled by
rcv_msganymore but inpeek_msg. we can remove the logics here.
Yeah, we can remove it
/Monk
-----Original Message-----
From: Ding, Pixel
Sent: 2018年3月7日 17:22
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
See comments inline.
—
Sincerely Yours,
Pixel
On 07/03/2018, 4:58 PM, "Liu, Monk" <[email protected]> wrote:
HI Pixel
The patch better not to be split, otherwise the stress TDR test still fail since there are couple issues and some of them mixed together
For your concerns:
> Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
We had a lot of fixings in GIM side along with this patch to make stress TDR test finally passed, you can watch the history, anyway GIM side is not related with this patch
[Pixel]Per talked offline, understand your point here.
Quoted 1 line
it’s not clear to understand the last 2 lines of code here to set
RCV_MSG_ACKbit:0x10to +1 byte offset. Can we define some macros to make it clear?
Can you do that ? looks to me the MACRO in amdgpu only works for DW aligned register names, so I'm afraid we cannot do that gracefully
[Pixel] some readable macros can help us easily understand which register field is accessed.
Quoted 1 line
Can we also set valid bit for
IDH_FLR_NOTIFICATION_CMPLevent in GIM? By now guest usepeek_msgto catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also usepeek_ackto ack CMPL if it’s necessary. any problem?
I don't understand your point
[Pixel]generally, CMPL is not handled by rcv_msg anymore but in peek_msg. we can remove the logics here.
-----Original Message-----
From: Ding, Pixel
Sent: 2018年3月7日 16:31
To: Liu, Monk <[email protected]>; [email protected]
Subject: Re: [PATCH 2/4] drm/amdgpu: refactoring mailbox to fix TDR handshake bugs
Hi Monk,
It’s a long patch which could split into 6 pieces at most… anyway I got some questions inline to have a better understanding.
—
Sincerely Yours,
Pixel
On 06/03/2018, 11:29 AM, "amd-gfx on behalf of Monk Liu" <[email protected] on behalf of [email protected]> wrote:
this patch actually refactor mailbox implmentations, and
all below changes are needed together to fix all those mailbox
handshake issues exposured by heavey TDR test.
1)refactor all mailbox functions based on byte accessing for mb_control
reason is to avoid touching non-related bits when writing trn/rcv part of
mailbox_control, this way some incorrect INTR sent to hypervisor
side could be avoided, and it fixes couple handshake bug.
2)trans_msg function re-impled: put a invalid
logic before transmitting message to make sure the ACK bit is in
a clear status, otherwise there is chance that ACK asserted already
before transmitting message and lead to fake ACK polling.
(hypervisor side have some tricks to workaround ACK bit being corrupted
by VF FLR which hase an side effects that may make guest side ACK bit
asserted wrongly), and clear TRANS_MSG words after message transferred.
3)for mailbox_flr_work, it is also re-worked: it takes the mutex lock
first if invoked, to block gpu recover's participate too early while
hypervisor side is doing VF FLR. (hypervisor sends FLR_NOTIFY to guest
before doing VF FLR and sentds FLR_COMPLETE after VF FLR done, and
the FLR_NOTIFY will trigger interrupt to guest which lead to
mailbox_flr_work being invoked)
This can avoid the issue that mailbox trans msg being cleared by its VF FLR.
4)for mailbox_rcv_irq IRQ routine, it should only peek msg and schedule
mailbox_flr_work, instead of ACK to hypervisor itself, because FLR_NOTIFY
msg sent from hypervisor side doesn't need VF's ACK (this is because
VF's ACK would lead to hypervisor clear its trans_valid/msg, and this
would cause handshake bug if trans_valid/msg is cleared not due to
correct VF ACK but from a wrong VF ACK like this "FLR_NOTIFY" one)
Any VF ACK could lead missing msg if timing is bad while hypervisor send msg quite frequently and guest send ack frequently (suck like the case FLR_NOTIFY followed by READY_TO_ACCESS_GPU immediately). Is it correct? If so, maybe we need further protection in GIM.
This fixed handshake bug that sometimes GUEST always couldn't receive
"READY_TO_ACCESS_GPU" msg from hypervisor.
5)seperate polling time limite accordingly:
POLL ACK cost no more than 500ms
POLL MSG cost no more than 12000ms
POLL FLR finish cost no more than 500ms
6) we still need to set adev into in_gpu_reset mode after we received
FLR_NOTIFY from host side, this can prevent innocent app wrongly succesed
to open amdgpu dri device.
FLR_NOFITY is received due to an IDLE hang detected from hypervisor side
which indicating GPU is already die in this VF.
Change-Id: I17df8b4490a5b53a1cc2bd6c8f9bc3ee14c23f1a
Signed-off-by: Monk Liu <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 200 ++++++++++++++++++----------------
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h | 4 +-
2 files changed, 111 insertions(+), 93 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
index 271452d..8d09380 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c
@@ -33,56 +33,42 @@
static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
{
- u32 reg;
- int timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_ACK, 1);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL), reg);
-
- /*Wait for RCV_MSG_VALID to be 0*/
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (reg & mask) {
- if (timeout <= 0) {
- pr_err("RCV_MSG_VALID is not cleared\n");
- break;
- }
- mdelay(1);
- timeout -=1;
-
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
+ WREG8(offset, 2);
it’s not clear to understand the last 2 lines of code here to set RCV_MSG_ACK bit: 0x10 to +1 byte offset. Can we define some macros to make it clear?
}
static void xgpu_ai_mailbox_set_valid(struct amdgpu_device *adev, bool val)
{
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ WREG8(offset, val ? 1 : 0);
same problem here. 0x1 to +0 byte offset.
+}
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_CONTROL,
- TRN_MSG_VALID, val ? 1 : 0);
- WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL),
- reg);
+/*
+ * this peek_msg could *only* be called in IRQ routine becuase in IRQ routine
+ * RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1
+ * by host.
+ *
+ * if called no in IRQ routine, this peek_msg cannot guaranteed to return the
+ * correct value since it doesn't return the RCV_DW0 under the case that
+ * RCV_MSG_VALID is set by host.
+ */
typos in comments.
+static enum idh_event xgpu_ai_mailbox_peek_msg(struct amdgpu_device *adev)
+{
+ return RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
+ mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
}
+
static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
enum idh_event event)
{
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4 + 1;
u32 reg;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, RCV_MSG_VALID);
- if (event != IDH_FLR_NOTIFICATION_CMPL) {
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- if (!(reg & mask))
- return -ENOENT;
- }
+ /* return -1 if didn't receive RCV_MSG_VALID */
+ if (event != IDH_FLR_NOTIFICATION_CMPL)
+ if (!(RREG8(offset) & 1))
+ return -1;
Can we also set valid bit for IDH_FLR_NOTIFICATION_CMPL event in GIM? By now guest use peek_msg to catch this event, so I think it’s OK to set valid for it. Then the code here would be clear without CMPL condition. We can also use peek_ack to ack CMPL if it’s necessary. any problem?
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
@@ -94,54 +80,69 @@ static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
return 0;
}
+static uint8_t xgpu_ai_peek_ack(struct amdgpu_device *adev) {
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ return (RREG8(offset) & 2);
+}
+
static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
- u32 mask = REG_FIELD_MASK(BIF_BX_PF0_MAILBOX_CONTROL, TRN_MSG_ACK);
- u32 reg;
+ const u32 offset = SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_CONTROL) * 4;
+ int timeout = AI_MAILBOX_POLL_ACK_TIMEDOUT;
+ u8 reg;
+
+ do {
+ reg = RREG8(offset);
+ if (reg & 2)
+ return 0;
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- while (!(reg & mask)) {
- if (timeout <= 0) {
- pr_err("Doesn't get ack from pf.\n");
- r = -ETIME;
- break;
- }
mdelay(5);
timeout -= 5;
+ } while (timeout > 1);
- reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
- mmBIF_BX_PF0_MAILBOX_CONTROL));
- }
+ pr_err("Doesn't get TRN_MSG_ACK from pf in %d msec\n", AI_MAILBOX_POLL_ACK_TIMEDOUT);
- return r;
+ return -ETIME;
}
static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
{
- int r = 0, timeout = AI_MAILBOX_TIMEDOUT;
-
- r = xgpu_ai_mailbox_rcv_msg(adev, event);
- while (r) {
- if (timeout <= 0) {
- pr_err("Doesn't get msg:%d from pf.\n", event);
- r = -ETIME;
- break;
- }
- mdelay(5);
- timeout -= 5;
+ int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
+ do {
r = xgpu_ai_mailbox_rcv_msg(adev, event);
- }
+ if (!r)
+ return 0;
- return r;
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+ pr_err("Doesn't get msg:%d from pf, error=%d\n", event, r);
+
+ return -ETIME;
}
static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
enum idh_request req, u32 data1, u32 data2, u32 data3) {
u32 reg;
int r;
+ uint8_t trn;
+
+ /* IMPORTANT:
+ * clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK
+ * and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK
+ * which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack()
+ * will return immediatly
+ */
+ do {
+ xgpu_ai_mailbox_set_valid(adev, false);
+ trn = xgpu_ai_peek_ack(adev);
+ if (trn) {
+ pr_err("trn=%x ACK should not asssert! wait again !\n", trn);
+ msleep(1);
+ }
+ } while(trn);
reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
@@ -245,15 +246,32 @@ static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
{
struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work);
struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt);
-
- /* wait until RCV_MSG become 3 */
- if (xgpu_ai_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL)) {
- pr_err("failed to recieve FLR_CMPL\n");
- return;
- }
-
- /* Trigger recovery due to world switch failure */
- amdgpu_device_gpu_recover(adev, NULL, false);
+ int timeout = AI_MAILBOX_POLL_FLR_TIMEDOUT;
+ int locked;
+
+ /* block amdgpu_gpu_recover till msg FLR COMPLETE received,
+ * otherwise mailbox msg from being ruined/reseted by
+ * VF FLR triggered by hypervisor's idle fail.
+ */
+ locked = mutex_trylock(&adev->lock_reset);
+ if (locked)
+ adev->in_gpu_reset = 1;
+
+ do {
+ if (xgpu_ai_mailbox_peek_msg(adev) == IDH_FLR_NOTIFICATION_CMPL)
+ goto flr_done;
+
+ msleep(10);
+ timeout -= 10;
+ } while (timeout > 1);
+
+flr_done:
+ if (locked)
+ mutex_unlock(&adev->lock_reset);
+
+ /* Trigger recovery for world switch failure if no TDR */
+ if (amdgpu_lockup_timeout == 0)
+ amdgpu_device_gpu_recover(adev, NULL, true);
}
static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
@@ -274,24 +292,22 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
struct amdgpu_irq_src *source,
struct amdgpu_iv_entry *entry)
{
- int r;
-
- /* trigger gpu-reset by hypervisor only if TDR disbaled */
- if (!amdgpu_gpu_recovery) {
- /* see what event we get */
- r = xgpu_ai_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION);
-
- /* sometimes the interrupt is delayed to inject to VM, so under such case
- * the IDH_FLR_NOTIFICATION is overwritten by VF FLR from GIM side, thus
- * above recieve message could be failed, we should schedule the flr_work
- * anyway
+ enum idh_event event = xgpu_ai_mailbox_peek_msg(adev);
+
+ switch (event) {
+ case IDH_FLR_NOTIFICATION:
+ if (amdgpu_sriov_runtime(adev))
+ schedule_work(&adev->virt.flr_work);
+ break;
+ /* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
+ * it byfar since that polling thread will handle it,
+ * other msg like flr complete is not handled here.
*/
- if (r) {
- DRM_ERROR("FLR_NOTIFICATION is missed\n");
- xgpu_ai_mailbox_send_ack(adev);
- }
-
- schedule_work(&adev->virt.flr_work);
+ case IDH_CLR_MSG_BUF:
+ case IDH_FLR_NOTIFICATION_CMPL:
+ case IDH_READY_TO_ACCESS_GPU:
+ default:
+ break;
}
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
index 67e7857..7ca4be5 100644
--- a/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
+++ b/drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h
@@ -24,7 +24,9 @@
#ifndef __MXGPU_AI_H__
#define __MXGPU_AI_H__
-#define AI_MAILBOX_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_ACK_TIMEDOUT 500
+#define AI_MAILBOX_POLL_MSG_TIMEDOUT 12000
+#define AI_MAILBOX_POLL_FLR_TIMEDOUT 500
enum idh_request {
IDH_REQ_GPU_INIT_ACCESS = 1,
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: give warning before sleep in kiq_r/wreg
In reply to a message not in the archiveto catch error that may schedule in atomic context early on
--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +7 -0
@@ -167,6 +167,9 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)if (r <1 && (adev->in_gpu_reset ||in_interrupt ())) goto failed_kiq_read; +if (in_interrupt ()) +might_sleep (); +while (r <1 && cnt++ <MAX_KIQ_REG_TRY ) {msleep (MAX_KIQ_REG_BAILOUT_INTERVAL ); r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );
@@ -212,7 +215,11 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)if (r <1 && (adev->in_gpu_reset ||in_interrupt ())) goto failed_kiq_write; +if (in_interrupt ()) +might_sleep (); +while (r <1 && cnt++ <MAX_KIQ_REG_TRY ) { +msleep (MAX_KIQ_REG_BAILOUT_INTERVAL ); r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1520306150-29325-3-git-send-email-Monk.Liu-5C7GfCeVMHo@public.gmane.org
Christian König
Reviewed-byRe: [PATCH 3/4] drm/amdgpu: give warning before sleep in kiq_r/wreg
Am 06.03.2018 um 04:15 schrieb Monk Liu:
Quoted 4 lines
to catch error that may schedule in atomic context early on
Change-Id I49dec7c55470011729b7fa7d3e1ecfe1f38ed89fSigned-off-by Monk Liu <[email protected]>
Quoted 20 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +3
-0@@ -167,6 +167,9 @@ uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg)if (r <1 && (adev->in_gpu_reset ||in_interrupt ())) goto failed_kiq_read; +if (in_interrupt ()) +might_sleep (); +while (r <1 && cnt++ <MAX_KIQ_REG_TRY ) {msleep (MAX_KIQ_REG_BAILOUT_INTERVAL ); r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT );@@ -212,7 +215,11 @@ void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)if (r <1 && (adev->in_gpu_reset ||in_interrupt ()))
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) · line 225
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +4
-0goto failed_kiq_write; +if (in_interrupt ()) +might_sleep (); +while (r <1 && cnt++ <MAX_KIQ_REG_TRY ) { +msleep (MAX_KIQ_REG_BAILOUT_INTERVAL ); r =amdgpu_fence_wait_polling (ring, seq,MAX_KIQ_REG_WAIT ); }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 dma-buf/reservation: should keep the new fence in add_shared_inplace
In reply to a message not in the archive--- drivers/dma-buf/reservation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma-buf/reservation.c +1 -1
@@ -118,7 +118,7 @@ reservation_object_add_shared_inplace(struct reservation_object *obj, old_fence =rcu_dereference_protected (fobj->shared[i],reservation_object_held (obj)); -if (old_fence->context == fence->context) { +if (dma_fence_is_later (fence, old_fence)) {/* memory barrier is added by write_seqcount_begin */ RCU_INIT_POINTER (fobj->shared[i], fence);write_seqcount_end (&obj->seq);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx