Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4901977imm; Mon, 11 Jun 2018 22:20:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI7I1Fkejj+OQcJwm/Ur0A+wMZh/n6/mjxd8RuxLzdiZIKCXzRIqW8aTURqkqaEu55rzpo4 X-Received: by 2002:a17:902:9b82:: with SMTP id y2-v6mr2378811plp.69.1528780846485; Mon, 11 Jun 2018 22:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528780846; cv=none; d=google.com; s=arc-20160816; b=pyb/sJ86uMFuyqGBv1TCvID/XduM9V1shU9+5gthBA4nM97+nEoHJHBjigPkOLQZ6z 7OhzUsfJ9DbSE1oKRLbKe9hUO329TuwwwN2JuRiQjsJ/LgXkA+hrQmxgKBJUa5orNv/4 te5wIoQa2KRyGxZ8tDLb9gAWgIIhT3pg1F20IabQl3UyYe+XQZUxhoTIujM4pAwZbezr cS+fgRLkI0wCrd44ozN4O54MSKT71UlC6z9NMZTTTV30RlDwiwwEc9KBHFgIZ7NiW7Y+ iuIeovglajdmDN1T6sOQYLk3IsDC8DOr1EI4eFi6wk8uPze7vnqaqBm2dwoA3tBy1uul /iqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=DaB8vWJ68sFEnIrtuzzGhWg4GjWa6Dj2BTujj/A31Z8=; b=RCG4W7rgf5xUIJ1mkBai4Y5fwfzsDfwicRA2C3d4yLwm97Jxv243CByyePkUc45YLC yThH/od3l+yEnRuNCI/iY4DImkFPKJWf0NsUSDVpOMHQv/RUuVi1kvwnL8bsiGeLwf1y qn21e/3Cg+KF1AMxBKI8WYTMsDg5efTbN6KZ+BsaJobJt2f3Rw2CDg92bpSUaM1h5xq2 QFXAFhmeLy7E+j5yktE1EM08RwMN+Q7wSnZJjwSdRQ+LcoW1wb+B9nktP4PVC7ofzuOZ CNsM1S14TrEYecvYMOzVM2GJWFlyKZCPl4ijLTa2xR7puIk6BYaw/R5pnW7+m3IcAbc2 dxGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m21-v6si19999pgn.599.2018.06.11.22.20.32; Mon, 11 Jun 2018 22:20:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932412AbeFLFT6 (ORCPT + 99 others); Tue, 12 Jun 2018 01:19:58 -0400 Received: from gate.crashing.org ([63.228.1.57]:51955 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932137AbeFLFT5 (ORCPT ); Tue, 12 Jun 2018 01:19:57 -0400 Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w5C5JDa3008698; Tue, 12 Jun 2018 00:19:17 -0500 From: Benjamin Herrenschmidt To: openbmc@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Joel Stanley , Andrew Jeffery , Greg Kroah-Hartman , Benjamin Herrenschmidt Subject: [RFC PATCH 1/5] fsi/scom: Add mutex around FSI2PIB accesses Date: Tue, 12 Jun 2018 15:19:07 +1000 Message-Id: <20180612051911.20690-2-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180612051911.20690-1-benh@kernel.crashing.org> References: <20180612051911.20690-1-benh@kernel.crashing.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Otherwise, multiple clients can open the driver and attempt to access the PIB at the same time, thus clobbering each other in the process. Signed-off-by: Benjamin Herrenschmidt --- drivers/fsi/fsi-scom.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c index c8eb5e5b94a7..3cba0eb645e1 100644 --- a/drivers/fsi/fsi-scom.c +++ b/drivers/fsi/fsi-scom.c @@ -37,6 +37,7 @@ struct scom_device { struct list_head link; struct fsi_device *fsi_dev; struct miscdevice mdev; + struct mutex lock; char name[32]; int idx; }; @@ -53,21 +54,26 @@ static int put_scom(struct scom_device *scom_dev, uint64_t value, int rc; uint32_t data; + mutex_lock(&scom_dev->lock); + data = cpu_to_be32((value >> 32) & 0xffffffff); rc = fsi_device_write(scom_dev->fsi_dev, SCOM_DATA0_REG, &data, sizeof(uint32_t)); if (rc) - return rc; + goto bail; data = cpu_to_be32(value & 0xffffffff); rc = fsi_device_write(scom_dev->fsi_dev, SCOM_DATA1_REG, &data, sizeof(uint32_t)); if (rc) - return rc; + goto bail; data = cpu_to_be32(SCOM_WRITE_CMD | addr); - return fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data, + rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data, sizeof(uint32_t)); + bail: + mutex_unlock(&scom_dev->lock); + return rc; } static int get_scom(struct scom_device *scom_dev, uint64_t *value, @@ -76,27 +82,31 @@ static int get_scom(struct scom_device *scom_dev, uint64_t *value, uint32_t result, data; int rc; + + mutex_lock(&scom_dev->lock); *value = 0ULL; data = cpu_to_be32(addr); rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data, sizeof(uint32_t)); if (rc) - return rc; + goto bail; rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA0_REG, &result, sizeof(uint32_t)); if (rc) - return rc; + goto bail; *value |= (uint64_t)cpu_to_be32(result) << 32; rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA1_REG, &result, sizeof(uint32_t)); if (rc) - return rc; + goto bail; *value |= cpu_to_be32(result); - return 0; + bail: + mutex_unlock(&scom_dev->lock); + return rc; } static ssize_t scom_read(struct file *filep, char __user *buf, size_t len, @@ -183,6 +193,7 @@ static int scom_probe(struct device *dev) if (!scom) return -ENOMEM; + mutex_init(&scom->lock); scom->idx = ida_simple_get(&scom_ida, 1, INT_MAX, GFP_KERNEL); snprintf(scom->name, sizeof(scom->name), "scom%d", scom->idx); scom->fsi_dev = fsi_dev; -- 2.17.0