Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b5de968 authored by Joachim Fenkes's avatar Joachim Fenkes Committed by Roland Dreier
Browse files

IB/ehca: Serialize MR alloc and MR free hvCalls



Some firmware levels exhibit a race condition between H_ALLOC_RESOURCE(MR)
and H_FREE_RESOURCE(MR).  Work around this problem by locking these hvCalls
against each other.

Signed-off-by: default avatarJoachim Fenkes <fenkes@de.ibm.com>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent e90d0b3d
Loading
Loading
Loading
Loading
+21 −7
Original line number Original line Diff line number Diff line
@@ -120,15 +120,28 @@ static long ehca_plpar_hcall_norets(unsigned long opcode,
				    unsigned long arg7)
				    unsigned long arg7)
{
{
	long ret;
	long ret;
	int i, sleep_msecs;
	int i, sleep_msecs, do_lock;
	unsigned long flags;


	ehca_gen_dbg("opcode=%lx " HCALL7_REGS_FORMAT,
	ehca_gen_dbg("opcode=%lx " HCALL7_REGS_FORMAT,
		     opcode, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
		     opcode, arg1, arg2, arg3, arg4, arg5, arg6, arg7);


	/* lock H_FREE_RESOURCE(MR) against itself and H_ALLOC_RESOURCE(MR) */
	if ((opcode == H_FREE_RESOURCE) && (arg7 == 5)) {
		arg7 = 0; /* better not upset firmware */
		do_lock = 1;
	}

	for (i = 0; i < 5; i++) {
	for (i = 0; i < 5; i++) {
		if (do_lock)
			spin_lock_irqsave(&hcall_lock, flags);

		ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4,
		ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4,
					 arg5, arg6, arg7);
					 arg5, arg6, arg7);


		if (do_lock)
			spin_unlock_irqrestore(&hcall_lock, flags);

		if (H_IS_LONG_BUSY(ret)) {
		if (H_IS_LONG_BUSY(ret)) {
			sleep_msecs = get_longbusy_msecs(ret);
			sleep_msecs = get_longbusy_msecs(ret);
			msleep_interruptible(sleep_msecs);
			msleep_interruptible(sleep_msecs);
@@ -161,23 +174,24 @@ static long ehca_plpar_hcall9(unsigned long opcode,
			      unsigned long arg9)
			      unsigned long arg9)
{
{
	long ret;
	long ret;
	int i, sleep_msecs, lock_is_set = 0;
	int i, sleep_msecs, do_lock;
	unsigned long flags = 0;
	unsigned long flags = 0;


	ehca_gen_dbg("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT, opcode,
	ehca_gen_dbg("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT, opcode,
		     arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
		     arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);


	/* lock H_ALLOC_RESOURCE(MR) against itself and H_FREE_RESOURCE(MR) */
	do_lock = ((opcode == H_ALLOC_RESOURCE) && (arg2 == 5));

	for (i = 0; i < 5; i++) {
	for (i = 0; i < 5; i++) {
		if ((opcode == H_ALLOC_RESOURCE) && (arg2 == 5)) {
		if (do_lock)
			spin_lock_irqsave(&hcall_lock, flags);
			spin_lock_irqsave(&hcall_lock, flags);
			lock_is_set = 1;
		}


		ret = plpar_hcall9(opcode, outs,
		ret = plpar_hcall9(opcode, outs,
				   arg1, arg2, arg3, arg4, arg5,
				   arg1, arg2, arg3, arg4, arg5,
				   arg6, arg7, arg8, arg9);
				   arg6, arg7, arg8, arg9);


		if (lock_is_set)
		if (do_lock)
			spin_unlock_irqrestore(&hcall_lock, flags);
			spin_unlock_irqrestore(&hcall_lock, flags);


		if (H_IS_LONG_BUSY(ret)) {
		if (H_IS_LONG_BUSY(ret)) {
@@ -807,7 +821,7 @@ u64 hipz_h_free_resource_mr(const struct ipz_adapter_handle adapter_handle,
	return ehca_plpar_hcall_norets(H_FREE_RESOURCE,
	return ehca_plpar_hcall_norets(H_FREE_RESOURCE,
				       adapter_handle.handle,    /* r4 */
				       adapter_handle.handle,    /* r4 */
				       mr->ipz_mr_handle.handle, /* r5 */
				       mr->ipz_mr_handle.handle, /* r5 */
				       0, 0, 0, 0, 0);
				       0, 0, 0, 0, 5);
}
}


u64 hipz_h_reregister_pmr(const struct ipz_adapter_handle adapter_handle,
u64 hipz_h_reregister_pmr(const struct ipz_adapter_handle adapter_handle,