Received: by 10.192.165.156 with SMTP id m28csp803186imm; Thu, 19 Apr 2018 07:50:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dQ5F5b5SoTra6ybasdcMYjjbxRY+hxHaTOMWMzkOhzSJ6W5oqdWuQ7uAeLZdmiGxf0KTt X-Received: by 2002:a17:902:b604:: with SMTP id b4-v6mr6533708pls.109.1524149409944; Thu, 19 Apr 2018 07:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524149409; cv=none; d=google.com; s=arc-20160816; b=EINDZxxEjhISXaNHEbD7WSE9AzEGUiSLHBXfqCwx0bHa+LGzPKkZMcFcnRz14RmQAs KHSiTBeiRSUhA0rbW/OPCRhwf4l4GApOHfyD+tMIuLMrtrBYLHQa+Zy4CUlQ5yesHtop 7GVFcpYyrefUEo8ucYldhv5h3mVDMtRH0c0iE9nHxND8CI3Yai3K4lHjZOPUobq9+7mz +5GtuGLdrTT+io5FHGtEpPR9g9EZO20wDRSHSBfSsH05kk+ki8Xbj6Hvr6BgyMYfWI4F wwIE7Wt/Lc9ATzixDTrJ1aMf9GWFx6GOnTUFbwIBH42dUajU3veM+njHS85XrFuoeYIQ nJjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=TLposUbAhd502LF1AXVaBsy/BpB16M/BdDaowb+tqfM=; b=kO1rqLvBc2LvDz+BE8ES+VfNn7JFd28dgxPqEHjBtCUom6cDhvwUpX8CD1Ef3dvUEj +fKl47Qi6FR7i0mmYZ40hZqY9j0H80W+OUdj6z1dKLR0/aAHv06FRATTypEOJCRr0kvo GV0tZiyzNIQXZTsFEl+gVFxPTur9LsGJiYa9nYmxR1KYiw2TROUrZ1J1rhob10FHjtK8 chvJm4hSLk7F/aKwV6VtBbF0p1glV56QUvfF38bN/YPHl9G2o+wf5xU96nu0VXS1CDuB W4ZPIzj9w59o23Xlsm0udLctTkpcmmKowmsME6qhekTlrk3zTaCT0fV8ctvZB2Rbx4BY P5oA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si2692638pfn.303.2018.04.19.07.49.55; Thu, 19 Apr 2018 07:50:09 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753415AbeDSOsi (ORCPT + 99 others); Thu, 19 Apr 2018 10:48:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43228 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752854AbeDSOsb (ORCPT ); Thu, 19 Apr 2018 10:48:31 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3JEmG7B072752 for ; Thu, 19 Apr 2018 10:48:30 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2heuvc4kpe-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 19 Apr 2018 10:48:28 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 19 Apr 2018 15:48:24 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 19 Apr 2018 15:48:22 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3JEmLKW49545254; Thu, 19 Apr 2018 14:48:21 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE6455203F; Thu, 19 Apr 2018 14:39:07 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.146]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8A2BB52054; Thu, 19 Apr 2018 14:39:07 +0100 (BST) From: Pierre Morel To: pasic@linux.vnet.ibm.com, bjsdjshi@linux.vnet.ibm.com Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, cohuck@redhat.com Subject: [PATCH 06/10] vfio: ccw: Make FSM functions atomic Date: Thu, 19 Apr 2018 16:48:09 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041914-0020-0000-0000-00000413BD37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041914-0021-0000-0000-000042A80A49 Message-Id: <1524149293-12658-7-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-19_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804190131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We use mutex around the FSM function call to make the FSM event handling and state change atomic. Signed-off-by: Pierre Morel --- drivers/s390/cio/vfio_ccw_drv.c | 3 +-- drivers/s390/cio/vfio_ccw_fsm.c | 2 -- drivers/s390/cio/vfio_ccw_ops.c | 4 +--- drivers/s390/cio/vfio_ccw_private.h | 3 +++ 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 8a91eee..1c9422a 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -73,8 +73,6 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) private = container_of(work, struct vfio_ccw_private, io_work); vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INTERRUPT); - if (private->mdev) - private->state = VFIO_CCW_STATE_IDLE; } static void vfio_ccw_sch_event_todo(struct work_struct *work) @@ -120,6 +118,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) return -ENOMEM; private->sch = sch; dev_set_drvdata(&sch->dev, private); + mutex_init(&private->state_mutex); spin_lock_irq(sch->lock); private->state = VFIO_CCW_STATE_NOT_OPER; diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index f8ded70..d85bcfc 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -109,8 +109,6 @@ static int fsm_io_request(struct vfio_ccw_private *private) union orb *orb = (union orb *)io_region->orb_area; struct mdev_device *mdev = private->mdev; - private->state = VFIO_CCW_STATE_BOXED; - io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev), orb); if (io_region->ret_code) goto err_out; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 4da7b61..dac8ce4 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -204,10 +204,8 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, return -EINVAL; vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_SSCH_REQ); - if (region->ret_code != 0) { - private->state = VFIO_CCW_STATE_IDLE; + if (region->ret_code != 0) return region->ret_code; - } return count; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 823e46c..cf197cf 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -51,6 +51,7 @@ struct vfio_ccw_private { struct eventfd_ctx *io_trigger; struct work_struct io_work; struct work_struct event_work; + struct mutex state_mutex; } __aligned(8); extern int vfio_ccw_mdev_reg(struct subchannel *sch); @@ -92,7 +93,9 @@ extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS]; static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private, int event) { + mutex_lock(&private->state_mutex); private->state = vfio_ccw_jumptable[private->state][event](private); + mutex_unlock(&private->state_mutex); } extern struct workqueue_struct *vfio_ccw_work_q; -- 2.7.4