From patchwork Wed Sep 19 08:47:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10605511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 168D26CB for ; Wed, 19 Sep 2018 08:49:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AA22B59F for ; Wed, 19 Sep 2018 08:49:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC1CA2B5AA; Wed, 19 Sep 2018 08:49:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DE6F2B59F for ; Wed, 19 Sep 2018 08:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731176AbeISO0J (ORCPT ); Wed, 19 Sep 2018 10:26:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58884 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731136AbeISO0I (ORCPT ); Wed, 19 Sep 2018 10:26:08 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8J8iXES040998 for ; Wed, 19 Sep 2018 04:49:15 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mkgtcpawy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 19 Sep 2018 04:49:15 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Sep 2018 09:49:13 +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) Wed, 19 Sep 2018 09:49:10 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8J8n9FP60620860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 19 Sep 2018 08:49:09 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A54BFAE04D; Wed, 19 Sep 2018 11:48:16 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC0C3AE045; Wed, 19 Sep 2018 11:48:15 +0100 (BST) Received: from s38lp20.boeblingen.de.ibm.com (unknown [9.145.184.145]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 Sep 2018 11:48:15 +0100 (BST) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, borntraeger@de.ibm.com, schwidefsky@de.ibm.com Subject: [RFC 09/14] s390/mm: Make gmap_protect_rmap EDAT1 compatible Date: Wed, 19 Sep 2018 10:47:57 +0200 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180919084802.183381-1-frankja@linux.ibm.com> References: <20180919084802.183381-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18091908-0028-0000-0000-000002FB67A8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18091908-0029-0000-0000-000023B52282 Message-Id: <20180919084802.183381-10-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-19_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=549 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809190091 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For the upcoming large page shadowing support, let's add the possibility to split a huge page and protect it with gmap_protect_rmap() for shadowing purposes. Signed-off-by: Janosch Frank --- arch/s390/mm/gmap.c | 87 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index ba0425f1c2c0..c64f9a48f5f8 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -1138,7 +1138,8 @@ static int gmap_protect_pmd(struct gmap *gmap, unsigned long gaddr, * Expected to be called with sg->mm->mmap_sem in read */ static int gmap_protect_pte(struct gmap *gmap, unsigned long gaddr, - pte_t *ptep, int prot, unsigned long bits) + unsigned long vmaddr, pte_t *ptep, + int prot, unsigned long bits) { int rc; unsigned long pbits = 0; @@ -1187,7 +1188,7 @@ static int gmap_protect_range(struct gmap *gmap, unsigned long gaddr, ptep = gmap_pte_from_pmd(gmap, pmdp, gaddr, &ptl_pte); if (ptep) - rc = gmap_protect_pte(gmap, gaddr, + rc = gmap_protect_pte(gmap, gaddr, vmaddr, ptep, prot, bits); else rc = -ENOMEM; @@ -1346,6 +1347,21 @@ static inline void gmap_insert_rmap(struct gmap *sg, unsigned long vmaddr, } } +static int gmap_protect_rmap_pte(struct gmap *sg, struct gmap_rmap *rmap, + unsigned long paddr, unsigned long vmaddr, + pte_t *ptep, int prot) +{ + int rc = 0; + + spin_lock(&sg->guest_table_lock); + rc = gmap_protect_pte(sg->parent, paddr, vmaddr, ptep, + prot, GMAP_NOTIFY_SHADOW); + if (!rc) + gmap_insert_rmap(sg, vmaddr, rmap); + spin_unlock(&sg->guest_table_lock); + return rc; +} + /** * gmap_protect_rmap - restrict access rights to memory (RO) and create an rmap * @sg: pointer to the shadow guest address space structure @@ -1362,16 +1378,15 @@ static int gmap_protect_rmap(struct gmap *sg, unsigned long raddr, struct gmap *parent; struct gmap_rmap *rmap; unsigned long vmaddr; - spinlock_t *ptl; + pmd_t *pmdp; pte_t *ptep; + spinlock_t *ptl_pmd = NULL, *ptl_pte = NULL; + struct page *page = NULL; int rc; BUG_ON(!gmap_is_shadow(sg)); parent = sg->parent; while (len) { - vmaddr = __gmap_translate(parent, paddr); - if (IS_ERR_VALUE(vmaddr)) - return vmaddr; rmap = kzalloc(sizeof(*rmap), GFP_KERNEL); if (!rmap) return -ENOMEM; @@ -1382,26 +1397,58 @@ static int gmap_protect_rmap(struct gmap *sg, unsigned long raddr, return rc; } rc = -EAGAIN; - ptep = gmap_pte_op_walk(parent, paddr, &ptl); - if (ptep) { - spin_lock(&sg->guest_table_lock); - rc = ptep_force_prot(parent->mm, paddr, ptep, PROT_READ, - PGSTE_VSIE_BIT); - if (!rc) - gmap_insert_rmap(sg, vmaddr, rmap); - spin_unlock(&sg->guest_table_lock); - gmap_pte_op_end(ptl); + vmaddr = __gmap_translate(parent, paddr); + if (IS_ERR_VALUE(vmaddr)) + return vmaddr; + vmaddr |= paddr & ~PMD_MASK; + pmdp = gmap_pmd_op_walk(parent, paddr, vmaddr, &ptl_pmd); + if (pmdp && !(pmd_val(*pmdp) & _SEGMENT_ENTRY_INVALID)) { + if (!pmd_large(*pmdp)) { + ptl_pte = NULL; + ptep = gmap_pte_from_pmd(parent, pmdp, paddr, + &ptl_pte); + if (ptep) + rc = gmap_protect_rmap_pte(sg, rmap, paddr, + vmaddr, ptep, + PROT_READ); + else + rc = -ENOMEM; + gmap_pte_op_end(ptl_pte); + if (!rc) { + paddr += PAGE_SIZE; + len -= PAGE_SIZE; + } + } else { + if (!page) { + /* Drop locks for allocation. */ + gmap_pmd_op_end(ptl_pmd); + ptl_pmd = NULL; + radix_tree_preload_end(); + kfree(rmap); + page = page_table_alloc_pgste(parent->mm); + if (!page) + return -ENOMEM; + continue; + } else { + gmap_pmd_split(parent, paddr, vmaddr, + pmdp, page); + page = NULL; + } + + } + gmap_pmd_op_end(ptl_pmd); } - radix_tree_preload_end(); - if (rc) { + if (page) + page_table_free_pgste(page); + else + radix_tree_preload_end(); + if (rc) kfree(rmap); + if (rc == -EAGAIN) { rc = gmap_fixup(parent, paddr, vmaddr, PROT_READ); if (rc) return rc; - continue; } - paddr += PAGE_SIZE; - len -= PAGE_SIZE; } return 0; }