Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1727219ybi; Fri, 12 Jul 2019 23:02:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjsi2HGzFL6glJAp1oQBKzAhTJOTi3nTVS36ZWHlS4QgjdxJCDHyNnshNRQthCiWg07BHM X-Received: by 2002:a63:5903:: with SMTP id n3mr15118499pgb.369.1562997758570; Fri, 12 Jul 2019 23:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562997758; cv=none; d=google.com; s=arc-20160816; b=KzWHU+dL6u01pkay8aggkPCtzUIyXXla0XsZVpU7j9pfd1u45v/KD0+2ncWmk4Dw97 7zaU76Dsas9X8Yo9sWIGU3bOTMn3EIak2mWoUDTVU8ur9l6wyazDtXU19Hhju0fyYVcD sbGfx90mD571LAiXFCaeOdTDkBAUzkNLu0XxXwqAFLeY6b5DY7SkR3GvEQwXNWz4noZv lhx7qix7RmDugd8wpnyb1phhZyCCIoDicFJOOODFaQtuyfrdLpGtGfgAhMoxNfu1PV5u 1Dst3QbQkfdiUL5UscCimjepHxRvuzZjDmx1anpWrCanNYaNJ0X3k0TwVqBl1GAgzY1D +akw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=37w/l3Fm78rlfkpsBHU1WziFXdkXkWWOAlhhKuan3IY=; b=qjxesxrSbj5FtKtvBkl/5LFWgEFxHfYZn3N+hQkr+xyy798LRlH8VVN00W467PJwvS lo06/GGQ4iyhEzzrtb4vfSh4BngO7f1FAfVMcq+ArfHaCqYI0MNE+ReR4uHGKrQvcBa4 wpc8zJC1mxh/0y3IHY6JPNivOZ+Yv8K60W9IKc+drP6WC9hpuuV2rHBOYPailFt5DCAM LormbuN9gjbXhw33zM+LjBI1cIr2L1bCH99b/EAxTDYyKJuGHPvEiD2oAcG6Fbe1MgY8 Oot/Ko8o7nyvY413sOVsiuq67TiGALBkCFtlH/7uPW0Sdh+3vp+6XPF71pIpI8w1XL67 8+Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si10635015pgg.521.2019.07.12.23.02.23; Fri, 12 Jul 2019 23:02:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727694AbfGMGBP (ORCPT + 99 others); Sat, 13 Jul 2019 02:01:15 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44742 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727681AbfGMGBN (ORCPT ); Sat, 13 Jul 2019 02:01:13 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6D5uN0N133930 for ; Sat, 13 Jul 2019 02:01:12 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 2tq87uaatm-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 13 Jul 2019 02:01:12 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 13 Jul 2019 07:01:11 +0100 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sat, 13 Jul 2019 07:01:08 +0100 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x6D616Ju38600968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Jul 2019 06:01:06 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2AEAC605A; Sat, 13 Jul 2019 06:01:06 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C908AC6065; Sat, 13 Jul 2019 06:01:03 +0000 (GMT) Received: from morokweng.localdomain.com (unknown [9.85.135.203]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Sat, 13 Jul 2019 06:01:03 +0000 (GMT) From: Thiago Jung Bauermann To: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Alexey Kardashevskiy , Anshuman Khandual , Benjamin Herrenschmidt , Christoph Hellwig , Michael Ellerman , Mike Anderson , Paul Mackerras , Ram Pai , Claudio Carvalho , Thiago Jung Bauermann Subject: [PATCH v2 08/13] powerpc/pseries/svm: Unshare all pages before kexecing a new kernel Date: Sat, 13 Jul 2019 03:00:18 -0300 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190713060023.8479-1-bauerman@linux.ibm.com> References: <20190713060023.8479-1-bauerman@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19071306-0004-0000-0000-00001526F198 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011419; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01231433; UDB=6.00648705; IPR=6.01012726; MB=3.00027699; MTD=3.00000008; XFM=3.00000015; UTC=2019-07-13 06:01:10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19071306-0005-0000-0000-00008C6EF538 Message-Id: <20190713060023.8479-9-bauerman@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-13_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907130070 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ram Pai A new kernel deserves a clean slate. Any pages shared with the hypervisor is unshared before invoking the new kernel. However there are exceptions. If the new kernel is invoked to dump the current kernel, or if there is a explicit request to preserve the state of the current kernel, unsharing of pages is skipped. NOTE: While testing crashkernel, make sure at least 256M is reserved for crashkernel. Otherwise SWIOTLB allocation will fail and crash kernel will fail to boot. Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann --- arch/powerpc/include/asm/ultravisor-api.h | 1 + arch/powerpc/include/asm/ultravisor.h | 6 ++++++ arch/powerpc/kernel/machine_kexec_64.c | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/arch/powerpc/include/asm/ultravisor-api.h b/arch/powerpc/include/asm/ultravisor-api.h index c7513bbadf57..ab4f756cb91c 100644 --- a/arch/powerpc/include/asm/ultravisor-api.h +++ b/arch/powerpc/include/asm/ultravisor-api.h @@ -29,5 +29,6 @@ #define UV_UNSHARE_PAGE 0xF134 #define UV_PAGE_INVAL 0xF138 #define UV_SVM_TERMINATE 0xF13C +#define UV_UNSHARE_ALL_PAGES 0xF140 #endif /* _ASM_POWERPC_ULTRAVISOR_API_H */ diff --git a/arch/powerpc/include/asm/ultravisor.h b/arch/powerpc/include/asm/ultravisor.h index f7418b663a0e..80d4beaf61b8 100644 --- a/arch/powerpc/include/asm/ultravisor.h +++ b/arch/powerpc/include/asm/ultravisor.h @@ -106,6 +106,12 @@ static inline int uv_unshare_page(u64 pfn, u64 npages) return ucall(UV_UNSHARE_PAGE, retbuf, pfn, npages); } +static inline int uv_unshare_all_pages(void) +{ + unsigned long retbuf[UCALL_BUFSIZE]; + + return ucall(UV_UNSHARE_ALL_PAGES, retbuf); +} #endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_ULTRAVISOR_H */ diff --git a/arch/powerpc/kernel/machine_kexec_64.c b/arch/powerpc/kernel/machine_kexec_64.c index 75692c327ba0..b3d87d32e8f7 100644 --- a/arch/powerpc/kernel/machine_kexec_64.c +++ b/arch/powerpc/kernel/machine_kexec_64.c @@ -31,6 +31,7 @@ #include #include #include +#include int default_machine_kexec_prepare(struct kimage *image) { @@ -329,6 +330,13 @@ void default_machine_kexec(struct kimage *image) #ifdef CONFIG_PPC_PSERIES kexec_paca.lppaca_ptr = NULL; #endif + + if (is_secure_guest() && !(image->preserve_context || + image->type == KEXEC_TYPE_CRASH)) { + uv_unshare_all_pages(); + printk("kexec: Unshared all shared pages.\n"); + } + paca_ptrs[kexec_paca.paca_index] = &kexec_paca; setup_paca(&kexec_paca);