From patchwork Thu Jan 23 09:14:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11347105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D25813A4 for ; Thu, 23 Jan 2020 09:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 358402467E for ; Thu, 23 Jan 2020 09:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726188AbgAWJOo (ORCPT ); Thu, 23 Jan 2020 04:14:44 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41832 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbgAWJOo (ORCPT ); Thu, 23 Jan 2020 04:14:44 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00N9DCbK050516 for ; Thu, 23 Jan 2020 04:14:43 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2xp3u88m55-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 23 Jan 2020 04:14:42 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 23 Jan 2020 09:14:40 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 23 Jan 2020 09:14:38 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 00N9EbWQ60293258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Jan 2020 09:14:37 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 41C84A4066; Thu, 23 Jan 2020 09:14:37 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55D8EA4054; Thu, 23 Jan 2020 09:14:36 +0000 (GMT) Received: from localhost.localdomain (unknown [9.152.224.146]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 23 Jan 2020 09:14:36 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, borntraeger@de.ibm.com, linux-s390@vger.kernel.org, david@redhat.com, cohuck@redhat.com Subject: [kvm-unit-tests PATCH] s390x: smp: Rework cpu start and active tracking Date: Thu, 23 Jan 2020 04:14:21 -0500 X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20012309-0020-0000-0000-000003A33EDD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20012309-0021-0000-0000-000021FAD773 Message-Id: <20200123091421.3409-1-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-01-23_01:2020-01-23,2020-01-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=881 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 suspectscore=1 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-2001230079 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The architecture specifies that processing sigp orders may be asynchronous, and this is indeed the case on some hypervisors, so we need to wait until the cpu runs before we return from the setup/start function. As there was a lot of duplicate code, a common function for cpu restarts has been introduced. Signed-off-by: Janosch Frank Reviewed-by: Cornelia Huck --- lib/s390x/smp.c | 56 ++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c index f57f420..4578003 100644 --- a/lib/s390x/smp.c +++ b/lib/s390x/smp.c @@ -104,35 +104,52 @@ int smp_cpu_stop_store_status(uint16_t addr) return rc; } +static int smp_cpu_restart_nolock(uint16_t addr, struct psw *psw) +{ + int rc; + struct cpu *cpu = smp_cpu_from_addr(addr); + + if (!cpu) + return -1; + if (psw) { + cpu->lowcore->restart_new_psw.mask = psw->mask; + cpu->lowcore->restart_new_psw.addr = psw->addr; + } + /* + * Stop the cpu, so we don't have a race between a running cpu + * and the restart in the test that checks if the cpu is + * running after the restart. + */ + smp_cpu_stop_nolock(addr, false); + rc = sigp(addr, SIGP_RESTART, 0, NULL); + if (rc) + return rc; + /* + * The order has been accepted, but the actual restart may not + * have been performed yet, so wait until the cpu is running. + */ + while (!smp_cpu_running(addr)) + mb(); + cpu->active = true; + return 0; +} + int smp_cpu_restart(uint16_t addr) { - int rc = -1; - struct cpu *cpu; + int rc; spin_lock(&lock); - cpu = smp_cpu_from_addr(addr); - if (cpu) { - rc = sigp(addr, SIGP_RESTART, 0, NULL); - cpu->active = true; - } + rc = smp_cpu_restart_nolock(addr, NULL); spin_unlock(&lock); return rc; } int smp_cpu_start(uint16_t addr, struct psw psw) { - int rc = -1; - struct cpu *cpu; - struct lowcore *lc; + int rc; spin_lock(&lock); - cpu = smp_cpu_from_addr(addr); - if (cpu) { - lc = cpu->lowcore; - lc->restart_new_psw.mask = psw.mask; - lc->restart_new_psw.addr = psw.addr; - rc = sigp(addr, SIGP_RESTART, 0, NULL); - } + rc = smp_cpu_restart_nolock(addr, &psw); spin_unlock(&lock); return rc; } @@ -192,10 +209,7 @@ int smp_cpu_setup(uint16_t addr, struct psw psw) lc->sw_int_crs[0] = 0x0000000000040000UL; /* Start processing */ - rc = sigp_retry(cpu->addr, SIGP_RESTART, 0, NULL); - if (!rc) - cpu->active = true; - + smp_cpu_restart_nolock(addr, NULL); out: spin_unlock(&lock); return rc;