Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp310175pxm; Wed, 2 Mar 2022 16:03:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyO8j0Vo0MrEfOhMC60kyxv8W0CI80dDj8PQc/gMMDSAX5uHbI3h8eB6TpSEz+KYqd4Ago X-Received: by 2002:a17:90a:a60c:b0:1bd:6058:1dd9 with SMTP id c12-20020a17090aa60c00b001bd60581dd9mr2392984pjq.118.1646265825210; Wed, 02 Mar 2022 16:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646265825; cv=none; d=google.com; s=arc-20160816; b=oGuZJgGQEtQ4F4Wab3nFYjFlveZhWttyx31cOvbyH4sSEjjOYWeZdEa2EzrM1OTeNO TZqI9yRPTBNG/+cIG4TMzvOOmutjnWVdcKMc8otGr7Hk8Ir69/3xnJkUmAwj8uRUzOnp +figVexFI+6rx2sz9D3zzUdUrSJb5VUxY1rdelREwZHk0iO+qYonwT+zQtka/prmKeJj fbZPk4sVzEZo8bTi+KlHcaDUzqwmpsbH2kP5OA4WgohjX1KLrOG2xLc57TS7vk9mlhFA HuFKhja017h0isGp6d9CbY+wzBYIjBCzzDT13I1XhIrmyyPDEom872bgEWgJLO/1zdiD 6m6g== 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=lagUF/hPFWZEQhSlZcnZFa4GuKJdxTR/1fBbKvob8I4=; b=BI6c19Ahecxx1prVqXLTacBHew36Jss9Wm1ayDq93E6XE2Jr9NvS/BHQj4gwA/cbaU EmQHH1IQj8/Dw370GP6QYBB6Xj0mWpsGJDyf4XH5key7y6atbwahE/yYZS/fSy2miPqK zLC7mO6E7BD/qE4zeDQzjyik9lrj+TBsG9HdBsj2RDcqKzQl91HqxAbHr6iDqiCKVVVc t3CkUS6NUdUpAReYOkTzfBe0fhbt+pqvc5wabJRxZ1Ld4wjbi7Mm/Z840NWbWAWe2JG+ gz04aYudP8KZKNvdLcWqoYckgPyJtmnxODukiim5Tj1KfpmW7QRbpVT/Li75Q58B8qiD zdPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SGnKnT4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u14-20020a62ed0e000000b004f35ee26414si470029pfh.97.2022.03.02.16.03.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:03:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SGnKnT4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E22881A58D8; Wed, 2 Mar 2022 15:21:42 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244555AbiCBSMw (ORCPT + 99 others); Wed, 2 Mar 2022 13:12:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244461AbiCBSMj (ORCPT ); Wed, 2 Mar 2022 13:12:39 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D99ECEA3D; Wed, 2 Mar 2022 10:11:54 -0800 (PST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 222FnMZM003212; Wed, 2 Mar 2022 18:11:54 GMT 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=lagUF/hPFWZEQhSlZcnZFa4GuKJdxTR/1fBbKvob8I4=; b=SGnKnT4Hxkn4ue+x+dVvkR0weL9gd4SLHSEb3hMMl4St4NxsXHU1u+F9BR0O9m+iAGdR aztbjpod6dUvo0dGQIHGCJAbfGxY7S8v1vJBSdOcd4IEpDPtqho199gKyIQ8IJonYLo1 fN8EKfhg5vg+1d94HUakAMi+qsjPXE621AjYzT2MY1rAZ9xnJYpDCHgZJDpKRRKY53TX vBxYak3E+CePPziBrQoFRlcYCtWfToHhwwSxBgKgALiBOT3w7afJcyzxmcxqKNDWIsOQ icOgeTQsQaS81uU8vzISEd3+EBJUCJkHNx1lxb7rJOQfJKowL02xfzUeSxwnzRRqaG5R Sw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ejbj4u0bp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Mar 2022 18:11:53 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 222HwHhU006009; Wed, 2 Mar 2022 18:11:53 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ejbj4u0as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Mar 2022 18:11:53 +0000 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 222I8qDb022892; Wed, 2 Mar 2022 18:11:51 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 3efbu9e1m9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Mar 2022 18:11:50 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 222IBlYK46399772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Mar 2022 18:11:47 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C867852054; Wed, 2 Mar 2022 18:11:47 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.145.5.37]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 4772652052; Wed, 2 Mar 2022 18:11:47 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org Cc: 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, scgl@linux.ibm.com, mimu@linux.ibm.com, nrb@linux.ibm.com Subject: [PATCH v8 06/17] KVM: s390: pv: add export before import Date: Wed, 2 Mar 2022 19:11:32 +0100 Message-Id: <20220302181143.188283-7-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220302181143.188283-1-imbrenda@linux.ibm.com> References: <20220302181143.188283-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: B3qqMftZfcT6-0t8alg4QwsT2zGL1zKE X-Proofpoint-GUID: xhNEDQNsRqs026-c7LO-nL97T060SG2v X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-02_12,2022-02-26_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 phishscore=0 clxscore=1015 impostorscore=0 adultscore=0 mlxscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2203020078 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Due to upcoming changes, it will be possible to temporarily have multiple protected VMs in the same address space, although only one will be actually active. In that scenario, it is necessary to perform an export of every page that is to be imported, since the hardware does not allow a page belonging to a protected guest to be imported into a different protected guest. This also applies to pages that are shared, and thus accessible by the host. Signed-off-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- arch/s390/kernel/uv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index 2754471cc789..e358b8bd864b 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -234,6 +234,12 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr, return uvcb->rc == 0x10a ? -ENXIO : -EINVAL; } +static bool should_export_before_import(struct uv_cb_header *uvcb, struct mm_struct *mm) +{ + return uvcb->cmd != UVC_CMD_UNPIN_PAGE_SHARED && + atomic_read(&mm->context.protected_count) > 1; +} + /* * Requests the Ultravisor to make a page accessible to a guest. * If it's brought in the first time, it will be cleared. If @@ -277,6 +283,8 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) lock_page(page); ptep = get_locked_pte(gmap->mm, uaddr, &ptelock); + if (should_export_before_import(uvcb, gmap->mm)) + uv_convert_from_secure(page_to_phys(page)); rc = make_secure_pte(ptep, uaddr, page, uvcb); pte_unmap_unlock(ptep, ptelock); unlock_page(page); -- 2.34.1