From patchwork Tue Aug 14 06:44:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 957371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41qNPx3cPGz9s8k for ; Tue, 14 Aug 2018 16:45:09 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41qNPx2GM4zF0bZ for ; Tue, 14 Aug 2018 16:45:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=permerror (mailfrom) smtp.mailfrom=kernel.crashing.org (client-ip=63.228.1.57; helo=gate.crashing.org; envelope-from=benh@kernel.crashing.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41qNPs4cF9zF0WK for ; Tue, 14 Aug 2018 16:45:04 +1000 (AEST) Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7E6ixrR020628 for ; Tue, 14 Aug 2018 01:45:00 -0500 Message-ID: <7a62778e680d8d6201d5f7b00341e7d06aa67c0d.camel@kernel.crashing.org> From: Benjamin Herrenschmidt To: skiboot@lists.ozlabs.org Date: Tue, 14 Aug 2018 16:44:59 +1000 X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Subject: [Skiboot] [PATCH 1/2] i2c: Fix multiple-enqueue of the same request on NACK X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" i2c_request_send() will retry the request if the error is a NAK, however it forgets to clear the "ud.done" flag. It will thus loop again and try to re-enqueue the same request causing internal request list corruption. Signed-off-by: Benjamin Herrenschmidt --- core/i2c.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/i2c.c b/core/i2c.c index d4311c27..070a0f6f 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -224,11 +224,10 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, rc = ud.rc; - if (rc == OPAL_I2C_NACK_RCVD) - continue; - else - /* error or success */ + /* error or success */ + if (rc != OPAL_I2C_NACK_RCVD) break; + ud.done = false; } prlog(PR_DEBUG, "I2C: %s req op=%x offset=%x buf=%016llx buflen=%d " From patchwork Tue Aug 14 06:45:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 957372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41qNQH4zBDz9s8k for ; Tue, 14 Aug 2018 16:45:27 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41qNQH3Ns5zF1df for ; Tue, 14 Aug 2018 16:45:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=permerror (mailfrom) smtp.mailfrom=kernel.crashing.org (client-ip=63.228.1.57; helo=gate.crashing.org; envelope-from=benh@kernel.crashing.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41qNPw0bZ1zF0Qs for ; Tue, 14 Aug 2018 16:45:07 +1000 (AEST) Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7E6j338020634 for ; Tue, 14 Aug 2018 01:45:04 -0500 Message-ID: <2f79194719d79c71b905be26c4537292649312b2.camel@kernel.crashing.org> From: Benjamin Herrenschmidt To: skiboot@lists.ozlabs.org Date: Tue, 14 Aug 2018 16:45:03 +1000 X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Subject: [Skiboot] [PATCH 2/2] i2c: Ensure ordering between i2c_request_send() and completion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" i2c_request_send loops waiting for a flag "uc.done" set by the completion routine, and then look for a result code also set by that same completion. There is no synchronization, the completion can happen on another processor, so we need to order the stores to uc and the reads from uc so that uc.done is stored last and tested first using memory barriers. Signed-off-by: Benjamin Herrenschmidt --- core/i2c.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/i2c.c b/core/i2c.c index 070a0f6f..e8333105 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -20,6 +20,7 @@ #include #include #include +#include static LIST_HEAD(i2c_bus_list); @@ -148,6 +149,7 @@ static void i2c_sync_request_complete(int rc, struct i2c_request *req) { struct i2c_sync_userdata *ud = req->user_data; ud->rc = rc; + lwsync(); ud->done = true; } @@ -222,6 +224,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, waited += time_to_wait; } while (!ud.done); + lwsync(); rc = ud.rc; /* error or success */