Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp59773lfe; Fri, 15 Apr 2022 19:28:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/PSGzmCg90PMLXeUYSjEtdIZRHoj6kJIyhCpZud/cc7wZiUzWV31TR6xr0FEwl3Gr7teu X-Received: by 2002:a17:902:ca04:b0:158:eab9:2676 with SMTP id w4-20020a170902ca0400b00158eab92676mr608742pld.1.1650076103522; Fri, 15 Apr 2022 19:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076103; cv=none; d=google.com; s=arc-20160816; b=enXhsZJN7aeLvckP1XYuuTHR5d89kwOxzBXm2OjyYRCaonYsPmSIulR5G88QrgMlgO JlCFj7N90rVlkABZv1ZPPA1M1PN6UDYFH4oUCzoJfusEc3RTYfs+FEqTtkjsBz3eu8bq O7pLt27g786fRBXszbmAa45AzyhI0WisxgGY8HiKoJ5OvNaZsINe9ffRhPQyj/6lSv6Q KiTLdZIqYHsCBwJKSkm6oPE9pWvxsn1+ykX4gxezWEICe/YjGaOMVKhquwclcr9EwWgC EpwU/5LJm7QCXbtGbThfxp1o0mrxTGYaXbLXkxSb27bCn+euIJOjAcA02nEh3oVaFppV DnVw== 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=rxxr9T6ksZ9JWndwccHYcQfrGQVbkg8UzJ7+I1+Pg3P3pieW12lwxTZyyPeaYuNlE/ E3ri3Wr+Aa3KrU8+K45zWIe5iJP1+p6Ag/Gi0WtPZBace7XA2nYGARRGEBkFQTqir+m7 BEEUm5FQ1CpLKKapgctq2HSMDU8WIBpLfrDCd2hQzrWBgFXmNt3bv45Vn8xmFlxu7qJE u6OQXJ7McIiWedbCHvmB3sPXhM3CWsMk3tyyfQbouu/4In5+OEdMq8Kkqg/x/8bOwlyN uuYxDyQAI2wMU2O03TNnPp/zuGSRFCKyCKtut4NHKGGJAvXJ7uG6wUnxJqK6BRjvbLws 7OHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=auaTt73X; 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 m6-20020a17090a920600b001d25b8d283bsi59137pjo.59.2022.04.15.19.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:28:23 -0700 (PDT) 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=auaTt73X; 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 09D6AF94F7; Fri, 15 Apr 2022 18:40:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240833AbiDNIG3 (ORCPT + 99 others); Thu, 14 Apr 2022 04:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240724AbiDNIFv (ORCPT ); Thu, 14 Apr 2022 04:05:51 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B6484D24B; Thu, 14 Apr 2022 01:03:27 -0700 (PDT) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23E70hZQ024861; Thu, 14 Apr 2022 08:03:27 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=auaTt73X5UK9l5RPWwssrSCZIsV0G1BH5IVJdeHm3BsLIKzX9izC7Cw2KaaMZ2aAlrLS nszo/CXLrGj2cgH6IWSjp7pKWo5xxnExXGc0+qMaEEGq4z0iVRY9tdZVRjQeKhZlDz8j dvVCScRWm2hsbdrIIFrEiPeiGzE4NfKCjnt4LnDOiHXe3b4dCn5VBPbeE3ZxvjfMXzIP aLR1EEXneZTGeLpWJGt+v6f1GQH6VKGLSe7bRiLvgWbv7bEfjiLvKxwiV6mF4+aD/fCa vke10IrFt6QKa9DTtJUy92x7obWqelTdrcnzuU3XVgzGzSYL1f3vtkc9EzhodhViy04P tA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3feeun13rd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Apr 2022 08:03:27 +0000 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23E7vHgi025582; Thu, 14 Apr 2022 08:03:26 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3feeun13qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Apr 2022 08:03:26 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23E7lYCO018814; Thu, 14 Apr 2022 08:03:24 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06fra.de.ibm.com with ESMTP id 3fbsj05cps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Apr 2022 08:03:24 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23E83L5033751380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Apr 2022 08:03:21 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFE58AE055; Thu, 14 Apr 2022 08:03:20 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F43DAE04D; Thu, 14 Apr 2022 08:03:20 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.1.140]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 14 Apr 2022 08:03:20 +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 v10 06/19] KVM: s390: pv: add export before import Date: Thu, 14 Apr 2022 10:02:57 +0200 Message-Id: <20220414080311.1084834-7-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414080311.1084834-1-imbrenda@linux.ibm.com> References: <20220414080311.1084834-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lzOWG3YyTD0aJ8iiiI7-rd6StJh6BeL2 X-Proofpoint-GUID: D3Yahk8Ad_92nXnCZ17JMeGHcCI4aeiE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_01,2022-04-13_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 spamscore=0 clxscore=1015 suspectscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140040 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