From patchwork Tue Jul 17 12:44:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10529345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 77B036020A for ; Tue, 17 Jul 2018 12:45:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E44828F40 for ; Tue, 17 Jul 2018 12:45:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52DC228FF0; Tue, 17 Jul 2018 12:45:05 +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 019EC28F40 for ; Tue, 17 Jul 2018 12:45:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731610AbeGQNRd (ORCPT ); Tue, 17 Jul 2018 09:17:33 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45944 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731513AbeGQNRc (ORCPT ); Tue, 17 Jul 2018 09:17:32 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6HCiGSu092094 for ; Tue, 17 Jul 2018 08:45:02 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k9fgfb97s-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 17 Jul 2018 08:45:01 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2018 13:44:59 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 17 Jul 2018 13:44:57 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6HCiuYB36569306 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 17 Jul 2018 12:44:56 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 41BCFA4053; Tue, 17 Jul 2018 15:45:14 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F08BA4051; Tue, 17 Jul 2018 15:45:14 +0100 (BST) Received: from s38lp20.boeblingen.de.ibm.com (unknown [9.152.224.110]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 17 Jul 2018 15:45:13 +0100 (BST) From: Janosch Frank To: kvm@vger.kernel.org Cc: david@redhat.com, borntraeger@de.ibm.com, schwidefsky@de.ibm.com Subject: [PATCH v7 08/12] s390/mm: Clear skeys for newly mapped huge guest pmds Date: Tue, 17 Jul 2018 13:44:22 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180717124426.6240-1-frankja@linux.ibm.com> References: <20180717124426.6240-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18071712-0012-0000-0000-0000028B279C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071712-0013-0000-0000-000020BCE690 Message-Id: <20180717124426.6240-9-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-17_03:, , 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=655 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807170133 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similarly to the pte skey handling, where we set the storage key to the default key for each newly mapped pte, we have to also do that for huge pmds. Signed-off-by: Janosch Frank Acked-by: David Hildenbrand --- arch/s390/mm/pgtable.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c index 09531f779271..60fff609ab61 100644 --- a/arch/s390/mm/pgtable.c +++ b/arch/s390/mm/pgtable.c @@ -410,12 +410,32 @@ static inline pmd_t pmdp_flush_lazy(struct mm_struct *mm, return old; } +static void pmdp_clear_skeys(struct mm_struct *mm, pmd_t *pmdp, pmd_t new) +{ + unsigned long paddr = pmd_val(new) & HPAGE_MASK; + + /* + * After a guest has used the first storage key instruction, + * we must ensure, that each newly mapped huge pmd has all + * skeys cleared before mapping it. + */ + if (!mm_uses_skeys(mm) || + !pmd_none(*pmdp) || + !pmd_large(new) || + (pmd_val(new) & _SEGMENT_ENTRY_INVALID)) + return; + + __storage_key_init_range(paddr, paddr + HPAGE_SIZE - 1); +} + pmd_t pmdp_xchg_direct(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t new) { pmd_t old; preempt_disable(); + if (mm_has_pgste(mm)) + pmdp_clear_skeys(mm, pmdp, new); old = pmdp_flush_direct(mm, addr, pmdp); *pmdp = new; preempt_enable(); @@ -429,6 +449,8 @@ pmd_t pmdp_xchg_lazy(struct mm_struct *mm, unsigned long addr, pmd_t old; preempt_disable(); + if (mm_has_pgste(mm)) + pmdp_clear_skeys(mm, pmdp, new); old = pmdp_flush_lazy(mm, addr, pmdp); *pmdp = new; preempt_enable();