Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2167140pxb; Wed, 30 Mar 2022 18:14:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTk9ZsWZDTxZ1xBokflwpvwKE8TVt7GLaCgJ2yzRN3uC9HCIhxh5QnWeExIV4RtquaSQY9 X-Received: by 2002:a17:902:f10c:b0:156:36e0:20f8 with SMTP id e12-20020a170902f10c00b0015636e020f8mr2720747plb.156.1648689250682; Wed, 30 Mar 2022 18:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648689250; cv=none; d=google.com; s=arc-20160816; b=zoJkrzaA81cKwL4qxwiLGjDm6Z30F0/EeUxGVbO8yQH9uZdhF+MDmJAJD0KUh14EAd UHcIiKPwiNtLBQaADwY64cDqRiCOf9O5IPNhrHrVcx1CX4gMMcp7yz04Fr3rDAypJm/D 5AVSw3uTchowqJnsh9ojigJ+ZHcjkpIiCQHjEL23EqrtEFKp7kI+WVTEPM8+4tSTdBBB iLkypcMYeQCH0KQ4zlSLkPTsZ8AylEKO2TP3sIDbX5SoJl+oiLOGqQwQXOIZvOlUlIDR NBM3Lx1SWSNpJzpdRg2Y+NWjmGKXhE3kdHeR8Z+VQJZ5kTZwGvnwn/jseKEa4xZnDIfs aTJg== 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=BGeLpYuTrWHOYIpL7fInCW75F60ESVj+OwYhUNWWsVaG9b2nosQfvHXFkBXCcnWlCk YqnWaw+egbUiLLbVlZ7vqrjDVLeHVM1gA+fQaKDRva4ZdprzMi5gzO5jsnJYcCIXVwHG zxbqyDaKfFV9GXjwQvPjMzB/LY/FpEwAmtIhsORr1D6upw0uJDQ9LbS1O/s9BHebF3SS eeAoUZkFU3kAigVR19nekvYZlJbmQ52bSweMpXhIbtJsC8LIWiv7KcffRq+6JWJvCz8f 7H+1h2rwDnY265SsWqxcnt8bqn2lCReIGID4huORFHtVMv6ufyo2pyFXagYrKIU7NOJR 2KFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nP5pE0R9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k18-20020a056a00169200b004fa3a8e004csi23999903pfc.259.2022.03.30.18.13.42; Wed, 30 Mar 2022 18:14:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=nP5pE0R9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1345034AbiC3Mk6 (ORCPT + 99 others); Wed, 30 Mar 2022 08:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344383AbiC3Mh2 (ORCPT ); Wed, 30 Mar 2022 08:37:28 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8CEE90FDE; Wed, 30 Mar 2022 05:26:21 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22UBt3kS023265; Wed, 30 Mar 2022 12:26:21 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=nP5pE0R9zWA+JLGt4uIm0FwS8izASecRf1zuCQul4cI24uGI56B6K0oKcUf/LaJyqj8r YJxOVSP89NhdQby9Q8XILdaill2D9HHmAIGF75Ab8MARsrR2YUjiR1CRWVF/Q/3ApoSX 7y1p3kbZT3k0BHCx0LuMfmNSXyw82cVFdBDOdxSmpSZYSNmxNRYdDa8RiZfL45f7wGwF 0gc8qWQGo2rRYJ4LPH25beZ2AX/O6b0xIHn55AlkLPJLcEvY8ME5b8/azvG+n/PPKb+m rVrmQ/oz0lxoPoYBYFirsnkpwSoffWueVDoNC+imkx0B4yfSfyNP7yWEDEAAGTxP5i0u uA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40q24grw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:26:21 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22UCGkYC016395; Wed, 30 Mar 2022 12:26:20 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3f40q24gr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:26:20 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22UCNnUS018840; Wed, 30 Mar 2022 12:26:18 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3f1tf9ghys-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 12:26:17 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22UCQKu845482264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Mar 2022 12:26:20 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B48B711C04C; Wed, 30 Mar 2022 12:26:14 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3148611C04A; Wed, 30 Mar 2022 12:26:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.13.95]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 30 Mar 2022 12:26:14 +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 v9 06/18] KVM: s390: pv: add export before import Date: Wed, 30 Mar 2022 14:25:53 +0200 Message-Id: <20220330122605.247613-7-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330122605.247613-1-imbrenda@linux.ibm.com> References: <20220330122605.247613-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: gXfqcyKsWvIY-rVXczVJefZCFHB-FqPH X-Proofpoint-ORIG-GUID: Gpz6IQZB2U2gh3mYuP3AaMQhglV5nKKI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-30_04,2022-03-30_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203300062 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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