Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5292275pxv; Wed, 28 Jul 2021 07:33:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+JKkJ+GX3/sjpRCmynQo/iFARXTiLlePoId6jvun0I833R8iIqpOWpfnFecu80bhxiRiH X-Received: by 2002:a17:906:cd14:: with SMTP id oz20mr974802ejb.478.1627482791494; Wed, 28 Jul 2021 07:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627482791; cv=none; d=google.com; s=arc-20160816; b=XSLQ7JdmRLegNYFVPbpK4EWlHxaqQWKWCzVVVMRjxjr0tNPkU3lyoKN10hPmf3L4um qz5LwnTVVKzjyYIWsawBapr98zTy1LhtSVoOzpXNO64Piyj4Ov6jbHGoOnf83djt3Vrg /wxtVJQjYhJNXUqQ2sHBPoIEoF2fVEO8+bMXsp8YSCy31OppXaEd7FsWQPv5vTUAMHvo v9FLrNqMm3fAEeTzJAs+mD/pIW7Li3jeVn15kexf8Yl54ZeLNKerFnF+On74DmXpSGq0 5/WXTW9LQFKrnKU0av47DTb9gAYQ+ry0gLgNqwSH8Car4gmsraw7aUJXlBOmCMdy9JJV gRWw== 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=7DuPp8TxLsWof8nza982Nvo7LfNGYAbpOl0+1+ZyoYQ=; b=Zs6TKzU0sYwUCNWg7YceRupVtv7b+J39rH6a/9snXXFg7ohcW42P6/ZqlYUnjwDKIz ukdvLQ6bzy6iF8N7KJiKFux5VbU+FYxdjoy8a8KOMULODYTSZF5t9rNfb8HABV0dNo0M FkOvBA/I0kucPi8ZEj8aVrDSvfbPj1Sx3WVHKNgFvu1NfCisPNgnF11GNKuSN19/36uq RGAUsJc6V8DfInReiQBZu/8Q5viv3x0+UT5alh47vf3nMTKX+WNd91kpLIsqKG0PTtkL LlZRNIe13hcckYQEgHNS15OQbhi/gJR/87ziLY9a55hJSfD+olyTPIG/TyEvSd/r2+Ww 1shA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=JLt1jzNt; 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 fx24si5711867ejb.356.2021.07.28.07.32.48; Wed, 28 Jul 2021 07:33:11 -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=JLt1jzNt; 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 S237294AbhG1O1i (ORCPT + 99 others); Wed, 28 Jul 2021 10:27:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36482 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236830AbhG1O0s (ORCPT ); Wed, 28 Jul 2021 10:26:48 -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 16SENP62062293; Wed, 28 Jul 2021 10:26:46 -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=7DuPp8TxLsWof8nza982Nvo7LfNGYAbpOl0+1+ZyoYQ=; b=JLt1jzNtcDnAOao+iPYCVj0H7Gwy5PaIGzXRyIPPHw7RcmQ7Y9PFwvCofG8zfooAiZiz 4nZBcSTKx6C0BRXa/sg2rY4RCucffcLUpUzVdhzX0bxv/oRl6JX5bgeECEh6/PJ2WBqo R8CwtRY7YoPnfj8amt6QA/sz9L1bU7C/o/c/thif8HZ7GSoEErRdC1d1MUnYT/BoX8+C 8D+k9Rmt7IajbjdIPwnav9Wy9C+SgmVxdHpy0KeFCpQkEI8Fm+sTfyVyvSGrGa0MBAeY DiMmy3FktLSGrnk4W87lQKU/s/HArOHH/KioPNpiMM7tiW5dAkxPtRuepnL3BFYleIrJ uQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a37xmj39u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 10:26:46 -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 16SENRek062468; Wed, 28 Jul 2021 10:26:45 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a37xmj38k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 10:26:45 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16SEJOKt011091; Wed, 28 Jul 2021 14:26:44 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3a235kh4h0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 14:26:43 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16SEQebr31719884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jul 2021 14:26:40 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 982B2A405E; Wed, 28 Jul 2021 14:26:40 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42658A405B; Wed, 28 Jul 2021 14:26:40 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.9.194]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 28 Jul 2021 14:26:40 +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 Subject: [PATCH v2 08/13] KVM: s390: pv: add export before import Date: Wed, 28 Jul 2021 16:26:26 +0200 Message-Id: <20210728142631.41860-9-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728142631.41860-1-imbrenda@linux.ibm.com> References: <20210728142631.41860-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: c0Uhz6dfoXplTVJ9ozP7hjgzcj4QA_dn X-Proofpoint-GUID: PTMMP7NHE1iHynscC2AVpdc-RXAsBLZz X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-28_08:2021-07-27,2021-07-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107280079 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 9cfd7979648c..1e67a26184b6 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -241,6 +241,12 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr, return rc; } +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.is_protected) > 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 @@ -284,6 +290,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.31.1