Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp187607pxt; Wed, 4 Aug 2021 08:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8+aDPupzb2Wx/GHE8MqmABC9Lj8GG0N5MwJMKIj1Fh08Amo+V5r5Sn1H76ouOcqAq4Ttr X-Received: by 2002:a17:906:4d50:: with SMTP id b16mr26934961ejv.501.1628091808804; Wed, 04 Aug 2021 08:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628091808; cv=none; d=google.com; s=arc-20160816; b=CQt59MmdTCF68ZkSBu6rOVSWcpWzzBsP/sk1sog4W20w+jTbI8WVf8f9Gi4OrcqvRf RiDxBdn+HBnLm0upClEbdON6/3AqDS3Cv9zMJbiWmPP+lPEhqyw8/KVxPD2F41THuklj xC68onD+MNOKvorF9H9u6C3Z29gbwaElvw2dVWfdeWYnbPLJyP+R6s9XpyUJtaw+m3PQ +QQ0kbuNNIoJWLToFyWLLmJBuWJ7a0zQjuF43MofN1GUNQdcjXlGU+Z0vZ/x1q5UrJcz iU1fYirGTvi1/KjFAhKWSLKQVOFtBl52R3tZBEGbb4YmjUvuxI8yYuRo7qrYhBplfa2X 2GGw== 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=bLN7wlEN7OAEA+iCFVqMEJ2dhP7gA+zizO6j6AfuPIE=; b=z+tCqYDGcE9i344yTnKXG0i6cxIKw3uMkyj77/86p1WS4Xiaa8SLXadmpqtuR9t0j7 Oa5eBxFPBdTKHaaqtLRQArrMqmq4R/bVUITOMdYejPtO9IzekQz14Dsu463eH5OGswaF hup0TQx56btjM4VJZSK9YzLdIQ+i272HviWCk0pRGwf1snCXtWMm3Xv80EUOX3TF/94N Z05vpjZvP564LqQuK+1XGUVT3OK5LbbzEbxQvyq5zZ+gNMeTUfaK1QjTXqwwGaTwYwSn yHKRiT/0qPiACaxOgl3CgUA/RY29YZms+65cIw1Um04cnClPG3m5Bx5vKHvgPALM4K6u gXEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=aKIcOvvQ; 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 i2si2782017edf.568.2021.08.04.08.42.59; Wed, 04 Aug 2021 08:43:28 -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=aKIcOvvQ; 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 S239395AbhHDPlb (ORCPT + 99 others); Wed, 4 Aug 2021 11:41:31 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32654 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239244AbhHDPlS (ORCPT ); Wed, 4 Aug 2021 11:41:18 -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 174FYxAM088660; Wed, 4 Aug 2021 11:41:05 -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=bLN7wlEN7OAEA+iCFVqMEJ2dhP7gA+zizO6j6AfuPIE=; b=aKIcOvvQg8bI6Gb0CYLJ5iFwGgm4L6QcWQjZg6Pi9wqwxES+IrtVJ8K8BavY6DfCq6Fc 8K3AeYr3mxM0gytrQ14oA8i/q3KhH5b6z6GDLWYvbah7JyR7u9Shu7R5Wxe9jjkbg8f6 N7gg2SDkyG04zTQIVu0NFeV6tImSmecg9qMOsCPYMPdAJgIB8iS0vIuYFPoLfhdEklon bi60wkMqcWnWVb6xoehYXw5r8m7ZQAstkthCZqwxsJNAY9AtY0m4Igt6cRAxiYndkBKz qxXWHY9Z7AAg/AI+TrZjk9LVHlyJnRwK3uE6hh5fxxn9YJ/HMWPGGziHgaWPGHgL3loh 3w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a73493tcy-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 174FZaUs092229; Wed, 4 Aug 2021 11:41:04 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 3a73493tbf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 11:41:04 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 174FZuS5028438; Wed, 4 Aug 2021 15:41:02 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3a4x598h5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Aug 2021 15:41:02 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 174Fc2Vd59244904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Aug 2021 15:38:02 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E979B4C04E; 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 81BED4C05C; 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:57 +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 09/14] KVM: s390: pv: add export before import Date: Wed, 4 Aug 2021 17:40:41 +0200 Message-Id: <20210804154046.88552-10-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: 6iTgFBBosOru21zecneJPZ_SE1c8c3gC X-Proofpoint-GUID: d7CnJ_HsdBCyGQforT8rZo4OSciA58L2 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 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 89ba36a5b4bb..bc79085d7152 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -249,6 +249,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.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 @@ -292,6 +298,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