From patchwork Mon Aug 18 20:30:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Schopp X-Patchwork-Id: 4739131 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 00AF1C0338 for ; Mon, 18 Aug 2014 20:33:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D93E20125 for ; Mon, 18 Aug 2014 20:33:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58C9120121 for ; Mon, 18 Aug 2014 20:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752039AbaHRUdd (ORCPT ); Mon, 18 Aug 2014 16:33:33 -0400 Received: from mail-bn1blp0181.outbound.protection.outlook.com ([207.46.163.181]:9415 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751903AbaHRUdb (ORCPT ); Mon, 18 Aug 2014 16:33:31 -0400 Received: from BY1PR0201CA0028.namprd02.prod.outlook.com (25.160.191.166) by BY2PR02MB043.namprd02.prod.outlook.com (10.242.44.23) with Microsoft SMTP Server (TLS) id 15.0.1010.18; Mon, 18 Aug 2014 20:33:27 +0000 Received: from BN1BFFO11FD043.protection.gbl (2a01:111:f400:7c10::1:104) by BY1PR0201CA0028.outlook.office365.com (2a01:111:e400:4814::38) with Microsoft SMTP Server (TLS) id 15.0.1010.18 via Frontend Transport; Mon, 18 Aug 2014 20:33:26 +0000 Received: from atltwp02.amd.com (165.204.84.222) by BN1BFFO11FD043.mail.protection.outlook.com (10.58.144.106) with Microsoft SMTP Server id 15.0.1010.11 via Frontend Transport; Mon, 18 Aug 2014 20:33:25 +0000 X-WSS-ID: 0NAIRRN-08-1IG-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 27CE1BD8903; Mon, 18 Aug 2014 15:33:22 -0500 (CDT) Received: from SATLEXDAG02.amd.com (10.181.40.5) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 18 Aug 2014 15:33:33 -0500 Received: from jdevbox.amd.com (10.180.168.240) by SATLEXDAG02.amd.com (10.181.40.5) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 18 Aug 2014 16:33:24 -0400 Message-ID: <53F26282.5010103@amd.com> Date: Mon, 18 Aug 2014 15:30:58 -0500 From: Joel Schopp User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Christoffer Dall CC: , , , , Sungjinn Chung , Jungseok Lee Subject: Re: [PATCH v4] arm64: fix VTTBR_BADDR_MASK References: <20140811203823.2828.36074.stgit@joelaarch64.amd.com> <20140812160521.GO10550@cbox> In-Reply-To: <20140812160521.GO10550@cbox> X-Originating-IP: [10.180.168.240] X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019005)(6009001)(428002)(189002)(199003)(23756003)(102836001)(81342001)(64126003)(74502001)(105586002)(107046002)(77096002)(101416001)(95666004)(33656002)(59896002)(81542001)(110136001)(106466001)(21056001)(79102001)(50466002)(36756003)(87936001)(31966008)(77982001)(85852003)(74662001)(64706001)(85306004)(83322001)(44976005)(83506001)(76482001)(53416004)(47776003)(80316001)(20776003)(4396001)(99396002)(83072002)(68736004)(19580395003)(87266999)(50986999)(65806001)(65816999)(92566001)(575784001)(65956001)(97736001)(84676001)(46102001)(54356999)(76176999)(92726001)(86362001)(80022001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR02MB043; H:atltwp02.amd.com; FPR:; MLV:sfv; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 03077579FF Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=Joel.Schopp@amd.com; X-OriginatorOrg: amd4.onmicrosoft.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP #endif /* __ARM_KVM_MMU_H__ */ second problem is that pgd is a virtual address, ie pgd == 0xfffffe03bbb40000 while the vttbr masks off the high bits for a physical address, ie vttbr_baddr_mask=0x00007ffffffe0000 . Even correcting for those issues I haven't been able to make this check work properly. I'll resend v5 the patch with all the other suggested changes. --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 16e7994..70f0f02 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -521,6 +521,7 @@ int create_hyp_io_mappings(void *from, void *to, phys_addr_t phys_addr) */ int kvm_alloc_stage2_pgd(struct kvm *kvm) { + unsigned int s2_pgds, s2_pgd_order; pgd_t *pgd; if (kvm->arch.pgd != NULL) { @@ -528,10 +529,18 @@ int kvm_alloc_stage2_pgd(struct kvm *kvm) return -EINVAL; } - pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, S2_PGD_ORDER); + s2_pgds = (1 << (kvm_get_phys_addr_shift() - PGDIR_SHIFT)); + s2_pgd_order = get_order(s2_pgds * sizeof(pgd_t)); + + pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, s2_pgd_order); if (!pgd) return -ENOMEM; + if ((unsigned long)pgd & ~vttbr_baddr_mask) { + kvm_err("Stage-2 pgd not correctly aligned: %p\n", pgd); + return -EFAULT; + } There are two problems that I've found here. The first problem is that vttbr_baddr_mask isn't allocated yet at this point in the code. The