Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp320146ybi; Fri, 7 Jun 2019 08:34:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfN5aUQBB2iJZBD1lo4sTumcXoAdGVRACz/VmpJm8qGXT/8aEJgK4pnFqe7g/4fN7rAcPE X-Received: by 2002:a65:490e:: with SMTP id p14mr3256506pgs.287.1559921672975; Fri, 07 Jun 2019 08:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559921672; cv=none; d=google.com; s=arc-20160816; b=yXyw2+Ri11cr5Hi3Y9ie3ogVCSG22XvjrLOlMEB+jmmwE/Li8e3XwCLhSarT5d1GF6 koWRGzj22bGqe34IRjY9ilW5OSTJoabSv/ONs/0UhqLAbxMhOJDfgfrBPE8V3HbYdF/Z qrWo/jMh0ADw0YB68HOmMAsVWbL/yawOYJe/61GxeXWVGvYvNFgSb8dOdtt8HMzzw2Xj PDgCNyIHljbWTigSWwwoHZhLprB6Q1uFX5WtjHQ40NMBG2a+ZXahVBGXkekAqwPKgGO5 7pNzV+SGb/1cW/9S0bfikb+fc2SWpHkENPiW4393VGP55UMygD74sPhMUM8YMQi+Y8qf Zmug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=g45tfFAAm6rV+ATl1MEOkMUyRV07Gh+FD59lBx375Q4=; b=uE8+JZrYA8O4CV6bU0YRRcv0vzshci+BB2vLciUzgxgzjtz1t9ybpwx9H4YJ8P1izk Pvq+mPEUg0kYkKB0SHUNa7tZF6xV4i1lccMcZwEcB7DG5G5StbpFX7/DjuyKMlxsbSih uHVN6jo99XLQmB/i2Fws7n6Irbul2ezQx0IaXW8c6G/UVNaKO9v9UMcT3x3xqjvcxw8I kmZMb8AXd83V9DVJymABqeQljyDMbtlN/RCMvn5MIF50kwd7JIlyuRcpBz8Zk7maPY7G I2d+Rtr2YGzLQ/hv9EcNsOAdTH5Ak+ea8ir1mKmTmQbxcKnmaREGQ09WNOVa4mYpMUWT xMag== 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 31si1162207pgu.103.2019.06.07.08.34.13; Fri, 07 Jun 2019 08:34:32 -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 S1729351AbfFGOrT (ORCPT + 99 others); Fri, 7 Jun 2019 10:47:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54104 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728198AbfFGOrS (ORCPT ); Fri, 7 Jun 2019 10:47:18 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x57El2ld087474 for ; Fri, 7 Jun 2019 10:47:17 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2syqwsxq41-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 07 Jun 2019 10:47:16 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Jun 2019 15:47:15 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 7 Jun 2019 15:47:11 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x57El9GY21627024 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 7 Jun 2019 14:47:09 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 47EB611C05C; Fri, 7 Jun 2019 14:47:09 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CFB311C054; Fri, 7 Jun 2019 14:47:06 +0000 (GMT) Received: from ram.ibm.com (unknown [9.85.131.246]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 7 Jun 2019 14:47:06 +0000 (GMT) Date: Fri, 7 Jun 2019 07:47:03 -0700 From: Ram Pai 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 , Claudio Carvalho , Ryan Grimm , Thiago Jung Bauermann Subject: [RFC PATCH 1/1] powerpc/pseries/svm: Unshare all pages before kexecing a new kernel Reply-To: Ram Pai References: <20190521044912.1375-1-bauerman@linux.ibm.com> <20190521044912.1375-13-bauerman@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190521044912.1375-13-bauerman@linux.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19060714-0028-0000-0000-0000037848C8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19060714-0029-0000-0000-000024382D1F Message-Id: <20190607144703.GB8604@ram.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-07_07:,, 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-1906070104 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org powerpc/pseries/svm: Unshare all pages before kexecing a new kernel. 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: Reserve atleast 256M for crashkernel. Otherwise SWIOTLB allocation fails and crash kernel fails to boot. Signed-off-by: Ram Pai diff --git a/arch/powerpc/include/asm/ultravisor-api.h b/arch/powerpc/include/asm/ultravisor-api.h index 8a6c5b4d..c8dd470 100644 --- a/arch/powerpc/include/asm/ultravisor-api.h +++ b/arch/powerpc/include/asm/ultravisor-api.h @@ -31,5 +31,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 bf5ac05..73c44ff 100644 --- a/arch/powerpc/include/asm/ultravisor.h +++ b/arch/powerpc/include/asm/ultravisor.h @@ -120,6 +120,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 75692c3..a93e3ab 100644 --- a/arch/powerpc/kernel/machine_kexec_64.c +++ b/arch/powerpc/kernel/machine_kexec_64.c @@ -329,6 +329,13 @@ void default_machine_kexec(struct kimage *image) #ifdef CONFIG_PPC_PSERIES kexec_paca.lppaca_ptr = NULL; #endif + + if (is_svm_platform() && !(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);