Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp187340pxt; Wed, 4 Aug 2021 08:43:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFVetYJscOIMg3Z+haDg5qJKIKNVQ9WV/3Fltlwn9Ys36/9VvMntYwclwi2mO75ANREiuZ X-Received: by 2002:a17:906:b30d:: with SMTP id n13mr26835490ejz.401.1628091793684; Wed, 04 Aug 2021 08:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628091793; cv=none; d=google.com; s=arc-20160816; b=fmzgjdyeGIktJ13YgCV6ZUx+30FHkeeRz9pKP3jC3fynlgD9IeChCuXeTyXP8MeHDC F+5A7ZxfQMWUiDDbOq4RJ8BrIqrAwvc2mGD9njmzpRM/y9kh0Wvo4K2kGUW8qa/nc71v jS8Z6IghHuQ0E7oiWhG6bVy5YkzlskxxVOKYD5Cigqa6di6WC6tU5sh10ZSY4Ow1b+Ej 2vQKOAx4wwgewPQmwUXcP2XnHBVE/BJKnlHMPEHq6dJZ4/gBRnCow47wFQpb8qVraNP4 pTCibN5/Ed5Kt69auKchl/E54IJiuuDuL9HDM2Jn5w+oYKEJ0pHhlcch72VYHQD+romu ICpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FFbfKLEJV1IosSHf09FivuQbD9JamEdWVYs0ydI9R74=; b=C1SN/51rrZBOEwefL6KNLsHmYG3eVL2WCze+3LXr52Lpo6as9v/q+nwes/NXHZyx73 Oep4lIrn7Ya43GpmK/kiw8OVU1UhtBA2Eh7kQw2bGftUrM6IoMvN/ycyXxjdpGXGyGHA kIX00pvXTkXYQTXVuMhd5RML8wtvVnIsAwX2Ue9ur7r8ETw/8Ll7Jq8RaAotfy0ZD6xD /x5I4gIct49ztxmI04WhaTtQVeBcpiuHngNcitI7rXDD0a7vXQBHOQY2QSpSg+BRgQP5 U0zVhuAnd4VRutkwQCPBXOWrT62xNEhy2ZvJLU7B8vY4kWFaGWffxGK582r7ZyDyRkqc ixBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=g2T6c4YC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gz27si2304618ejc.629.2021.08.04.08.42.46; Wed, 04 Aug 2021 08:43:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=g2T6c4YC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239302AbhHDPlY (ORCPT + 99 others); Wed, 4 Aug 2021 11:41:24 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:24074 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239210AbhHDPlR (ORCPT ); Wed, 4 Aug 2021 11:41:17 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 174FZ1LB088942; Wed, 4 Aug 2021 11:41:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=FFbfKLEJV1IosSHf09FivuQbD9JamEdWVYs0ydI9R74=; b=g2T6c4YCHbmOITDy+ovclG+9dTlF9dwA2KC2LFDwoY0aBrQ+TyQJC9KJaFti0zEysl4M bFE3liRQpu00PDIQN3ev+kkjweFulCyNKE+hmLpzrwWMtVKMukGdYlHNEOg/wPBvQnrj P8pkVtsCvbDFuEfodWbcQJHUU57eVzMIxrrm7WVC3+/H4QGVRp74J8bsCsD+zveLprKP g2iL4YTJYfXBefA0q02yCosrOwaaYw9cYIxXebevA+KHTmaD/Olnc0JfvXJ4HqBnF7eV XEfCNXIyTb27SzVQe85wAN+mriUJK8uMAfgnuXqlRjxcPWeoNiC2DGd/V5mNr95nRMXw RQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a73493tc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 11:41:04 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 174FZA89090673; Wed, 4 Aug 2021 11:41:03 -0400 Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a73493tb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 11:41:03 -0400 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 174FY8Fw005195; Wed, 4 Aug 2021 15:41:01 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06fra.de.ibm.com with ESMTP id 3a4wsj0hv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 15:41:01 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 174Fbxqe55181614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Aug 2021 15:37:59 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 67DB34C052; Wed, 4 Aug 2021 15:40:57 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06CF64C058; Wed, 4 Aug 2021 15:40:57 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.2.150]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Aug 2021 15:40:56 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org Cc: cohuck@redhat.com, borntraeger@de.ibm.com, frankja@linux.ibm.com, thuth@redhat.com, pasic@linux.ibm.com, david@redhat.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Ulrich.Weigand@de.ibm.com Subject: [PATCH v3 08/14] KVM: s390: pv: usage counter instead of flag Date: Wed, 4 Aug 2021 17:40:40 +0200 Message-Id: <20210804154046.88552-9-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804154046.88552-1-imbrenda@linux.ibm.com> References: <20210804154046.88552-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: nK18OPJgU8bpo2dp8hkoTgcbNZIRcjw3 X-Proofpoint-GUID: 3dkKPh1OIbkVBWFuuF6ICsZgQ2zjkE7v X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-04_03:2021-08-04,2021-08-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 clxscore=1015 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 adultscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108040089 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the is_protected field as a counter instead of a flag. This will be used in upcoming patches. Increment the counter when a secure configuration is created, and decrement it when it is destroyed. Previously the flag was set when the set secure parameters UVC was performed. Signed-off-by: Claudio Imbrenda Acked-by: Janosch Frank --- arch/s390/kvm/pv.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c index 1e7f63c06a63..fd37e97a26b3 100644 --- a/arch/s390/kvm/pv.c +++ b/arch/s390/kvm/pv.c @@ -174,7 +174,8 @@ int kvm_s390_pv_deinit_vm(struct kvm *kvm, u16 *rc, u16 *rrc) cc = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), UVC_CMD_DESTROY_SEC_CONF, rc, rrc); WRITE_ONCE(kvm->arch.gmap->guest_handle, 0); - atomic_set(&kvm->mm->context.is_protected, 0); + if (!cc) + atomic_dec(&kvm->mm->context.is_protected); KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY VM: rc %x rrc %x", *rc, *rrc); WARN_ONCE(cc, "protvirt destroy vm failed rc %x rrc %x", *rc, *rrc); /* Intended memory leak on "impossible" error */ @@ -215,11 +216,14 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) /* Outputs */ kvm->arch.pv.handle = uvcb.guest_handle; + atomic_inc(&kvm->mm->context.is_protected); if (cc) { - if (uvcb.header.rc & UVC_RC_NEED_DESTROY) + if (uvcb.header.rc & UVC_RC_NEED_DESTROY) { kvm_s390_pv_deinit_vm(kvm, &dummy, &dummy); - else + } else { + atomic_dec(&kvm->mm->context.is_protected); kvm_s390_pv_dealloc_vm(kvm); + } return -EIO; } kvm->arch.gmap->guest_handle = uvcb.guest_handle; @@ -242,8 +246,6 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, *rrc = uvcb.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x", *rc, *rrc); - if (!cc) - atomic_set(&kvm->mm->context.is_protected, 1); return cc ? -EINVAL : 0; } -- 2.31.1