Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3302722imm; Fri, 25 May 2018 03:25:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrNKodYNYazbxVAWYqkJD4PExAYEzOTcfC8tAG6/L2sUMgn6jP3mgrNEbWHnU5M4yKtDF0i X-Received: by 2002:a62:ec6:: with SMTP id 67-v6mr1967820pfo.36.1527243908712; Fri, 25 May 2018 03:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527243908; cv=none; d=google.com; s=arc-20160816; b=HqwIHRQXQzM7nI54PZJBHPcm6dYKGszu0w57vcuHY3jpUE8b/qxRGa8ea1TgJo0BYV hSJuv3ua57YDHKzO2O8l2ucy1xqyL2v+JxNxZhhiioSlC8mKh2BIKTRDQgxshsQo5gbB 19sOg7lWYfXT3Fa9oWN4+Vq1ahFLmkKNnwiT6Awuvm6t4m+354DElqILwlk0uB5mpKvJ EhxsAtBibWnDjfpW9a9JLaaDniPdIZLzVXcR0zNGvBx5DOugAcFTLTW4mCmAkntK1O8T 1glzSF82RWxtptFVvXPm4UPv8+2g8b/4AEM58QZ+idpp2q7CaZHKRzxSNNTW7TQfSpLt BDPg== 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=AZFCxYmwH0a5u3KS/jD/P+TCvtG7oJMjRZbNrM61AQY=; b=ezNDz6KPdOnrbQ1gHNyNd7Qvj/qSe+vFLI9dZPw1jCLtjWxWc4cHN7yCL4/TafFr2i tJAeGD0IAU7eX65obqNW6Zs/6z93N1MQFPcHLPIj4cS0oXRXoL0Msgcg8q1+AXhlZEoW gXwWglmdAEpKLDDXEiiHd1Oc+chtk/rYYhQMxT2L4k4w+kGpLOzf1PZ7iEIzJ4Nc0trb Lrm8XJhQLiBrkGxjeTETkF/LuWc2xk0lnK2Dw8Bjw3ncm3la3GWcPxB/FRNtbGpMHhjV 2lRN4CKJeY/lqyk7EwKgp2m9oeEwUGNTm+xFtoF3UQH70lVAK/k01PFLI1zuTV/JGfkG gqAw== 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 61-v6si22705121plc.173.2018.05.25.03.24.54; Fri, 25 May 2018 03:25:08 -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 S965359AbeEYKXB (ORCPT + 99 others); Fri, 25 May 2018 06:23:01 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43276 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965920AbeEYKVd (ORCPT ); Fri, 25 May 2018 06:21:33 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4P9s8Tk079035 for ; Fri, 25 May 2018 06:21:33 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j6fmdtpv2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 25 May 2018 06:21:32 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 25 May 2018 11:21:30 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 25 May 2018 11:21:27 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4PALRw72556360; Fri, 25 May 2018 10:21:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CF38A4055; Fri, 25 May 2018 11:12:45 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2EEBA4059; Fri, 25 May 2018 11:12:44 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.33]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 May 2018 11:12:44 +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 v2 06/10] vfio: ccw: Make FSM functions atomic Date: Fri, 25 May 2018 12:21:14 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052510-0040-0000-0000-0000043DC0F2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052510-0041-0000-0000-000026430208 Message-Id: <1527243678-3140-7-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-25_04:,, 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-1805250113 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_private.h | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 6b7112e..98951d5 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) @@ -118,6 +116,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_private.h b/drivers/s390/cio/vfio_ccw_private.h index 6c74f73..241176c 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