Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp187257pxt; Wed, 4 Aug 2021 08:43:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7cKEo+mQPd/unInoc8l89yogV/OwTIhQ1zp+v2jNv4YY9tKyQNHSPKinGZQnSVk4UJ1Ge X-Received: by 2002:a17:906:85ce:: with SMTP id i14mr26416790ejy.77.1628091788779; Wed, 04 Aug 2021 08:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628091788; cv=none; d=google.com; s=arc-20160816; b=DkF7vQ9dgTRiTxLaWobEoV7CO2GFAm7lGntxNnWIGjZj87YSRYwQhEuhSeLqXhWoev pQSmxJOic+FXO2/KP01krHpDwnrZERNLdqOHnEVLTRNmqkXP2qodnbpKQc7oLOstWMzA 0DUQh+BnoqU5GB1TQkOrWCK9UYAH5JdsQo/HAS8axFvD7BC1F8vroX69LVIp01gYOjUW 7DbF9QwgHbH5ZKtDGxpKZSykPb0lF/GylzDYTiFonTBd9qmHSSK7ixn8PPMtT7/rWv0C sZWcYQWtGuccgNLKrB7AHY2zLJVlAE3lZeREz0bdZnTQYL95oKFbWQJ9cvF17aY6f8+1 ftAQ== 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=n+OAxHC/hIrIosQxTKloaw80NsRG+8w9Uf3zfR/EpRk=; b=fPaapIvsBWwnyheFPRVEbgmiurD4NaYfBMJz8DzA8KbkcyHoM1orIiLwJt576o7dl3 Uw6/gC4PTgPH64eHaKYvKmPk5G0VTbjOyvEkzjsiF6mehA+MlSyCWWGm+ziswSnjy+cP SuZTIsJizcrsdzsJdaFnQ93HfCySa2OG1QqQsuuWo3jkn8RK16B2X0q9qOLizx3jjcc+ JNjiHiE3HOK7SiyZ5uxTqnBHaKJdFgLt06U4BXhPOmVW7a4mp00IDApyiKt9kXr+pTNa luAnVujiGjASMz5IJO0wf1ZwGJz/5KcYscOhh+kJU7fa2AW2BPx8qcuzRCSE8Z79BGFy G2+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="UWo/Ftbh"; 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 g19si665654edb.507.2021.08.04.08.42.38; Wed, 04 Aug 2021 08:43:08 -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="UWo/Ftbh"; 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 S239220AbhHDPlR (ORCPT + 99 others); Wed, 4 Aug 2021 11:41:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:1774 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239162AbhHDPlP (ORCPT ); Wed, 4 Aug 2021 11:41:15 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 174FXkKk174330; Wed, 4 Aug 2021 11:41:02 -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=n+OAxHC/hIrIosQxTKloaw80NsRG+8w9Uf3zfR/EpRk=; b=UWo/Ftbh4HyXCi9ye6y29zuh0mdHya/3+5IhPv39wgxmq6lfQd5Wdzj27k33cMP+Rd79 q3CygBATwPQQYawL9s7qleyzLP+Zq2CzCfOm+/XAb8HoEaIIvKbW41UmWZovX8uICbtS We74F4V5DgMBhf0AgnIZVm0Ylc4Wl5NHx2izDkabRB+omqDtKYFXsPnhMTPX9N4KzJSm LHCCmHsD3a0+r9s0ruO/UYiF9AYC7gqcgeswIjnPUnWt852oNg/J5hk9b+BOZozH0BVT 8vcBflmYX4bAHq6oUEuhgIME2Q1XL7u8VaZE7eymbxSmdez4WmyFEA+encuWjxZgDFs/ 5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a7rjba54s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 11:41:02 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 174FXkrr174296; Wed, 4 Aug 2021 11:41:01 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a7rjba53m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 11:41:01 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 174FZPgq027540; Wed, 4 Aug 2021 15:40:58 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 3a4x58rj6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 15:40:58 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 174FesS659638256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Aug 2021 15:40:54 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 636E04C058; Wed, 4 Aug 2021 15:40:54 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 057954C075; Wed, 4 Aug 2021 15:40:54 +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:53 +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 02/14] KVM: s390: pv: avoid stall notifications for some UVCs Date: Wed, 4 Aug 2021 17:40:34 +0200 Message-Id: <20210804154046.88552-3-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-GUID: P4iwglZWaB-ebKDoSOk2lpFgQvVwSk5w X-Proofpoint-ORIG-GUID: d4itgAOjKDi4UR_BWN6GP-Xfpnnw6Qwx 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 bulkscore=0 adultscore=0 impostorscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 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 Improve make_secure_pte to avoid stalls when the system is heavily overcommitted. This was especially problematic in kvm_s390_pv_unpack, because of the loop over all pages that needed unpacking. Also fix kvm_s390_pv_init_vm to avoid stalls when the system is heavily overcommitted. Signed-off-by: Claudio Imbrenda Fixes: 214d9bbcd3a672 ("s390/mm: provide memory management functions for protected KVM guests") --- arch/s390/kernel/uv.c | 29 +++++++++++++++++++++++------ arch/s390/kvm/pv.c | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index aeb0a15bcbb7..68a8fbafcb9c 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -180,7 +180,7 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr, { pte_t entry = READ_ONCE(*ptep); struct page *page; - int expected, rc = 0; + int expected, cc = 0; if (!pte_present(entry)) return -ENXIO; @@ -196,12 +196,25 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr, if (!page_ref_freeze(page, expected)) return -EBUSY; set_bit(PG_arch_1, &page->flags); - rc = uv_call(0, (u64)uvcb); + /* + * If the UVC does not succeed or fail immediately, we don't want to + * loop for long, or we might get stall notifications. + * On the other hand, this is a complex scenario and we are holding a lot of + * locks, so we can't easily sleep and reschedule. We try only once, + * and if the UVC returned busy or partial completion, we return + * -EAGAIN and we let the callers deal with it. + */ + cc = __uv_call(0, (u64)uvcb); page_ref_unfreeze(page, expected); - /* Return -ENXIO if the page was not mapped, -EINVAL otherwise */ - if (rc) - rc = uvcb->rc == 0x10a ? -ENXIO : -EINVAL; - return rc; + /* + * Return -ENXIO if the page was not mapped, -EINVAL for other errors. + * If busy or partially completed, return -EAGAIN. + */ + if (cc == UVC_CC_OK) + return 0; + else if (cc == UVC_CC_BUSY || cc == UVC_CC_PARTIAL) + return -EAGAIN; + return uvcb->rc == 0x10a ? -ENXIO : -EINVAL; } /* @@ -254,6 +267,10 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) mmap_read_unlock(gmap->mm); if (rc == -EAGAIN) { + /* + * If we are here because the UVC returned busy or partial + * completion, this is just a useless check, but it is safe. + */ wait_on_page_writeback(page); } else if (rc == -EBUSY) { /* diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c index c8841f476e91..e007df11a2fe 100644 --- a/arch/s390/kvm/pv.c +++ b/arch/s390/kvm/pv.c @@ -196,7 +196,7 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) uvcb.conf_base_stor_origin = (u64)kvm->arch.pv.stor_base; uvcb.conf_virt_stor_origin = (u64)kvm->arch.pv.stor_var; - cc = uv_call(0, (u64)&uvcb); + cc = uv_call_sched(0, (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc; KVM_UV_EVENT(kvm, 3, "PROTVIRT CREATE VM: handle %llx len %llx rc %x rrc %x", -- 2.31.1