Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1838089imm; Fri, 6 Jul 2018 07:24:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpedZrxwGodA7K9LMLJPebLQ35uZwqcX8e2FbHsIvIj+HzMG14VTJ1UhgF/xFfc47l6nNhhx X-Received: by 2002:a62:aa02:: with SMTP id e2-v6mr10751468pff.211.1530887079863; Fri, 06 Jul 2018 07:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530887079; cv=none; d=google.com; s=arc-20160816; b=Ao3ozhepdAW7FZgzAX8qn9DX0yMkMXl+R5Md8u7+4D3H0aQ7097h/3pk63FEEWERWN XRlfj+sFGjC9ZxwWkxoBErWJFNUPmzEvukOex/B/8/1Au+m4szf3rXk41KojDIikUjXQ z/KpxfZKGWnN+1pvyU3uM0f9KKSjuS7U6moa9AfPfm7mZhIxQ8tXT6bNZEyZF1X1U4Mu STgpuq+1DCjWUhAC6r4wkFbBwbE8aNT2afYbtjOFHrQBXOJjvueVgR08ajyaJRbCWAQq AiwRquxxPbJePAf0BsAxCuyfZ5oU+LsyJHsK1y/4iKCm8sIP9QIDvzCUyv8nnXBb9lKg J/8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=TdUPUYDpt7Io+bodg32SZdrB2SvpJvpgaAl9QiyGpKY=; b=tRqJAHQwn1jhDXrqeRWty9Htt8gQZ+wwE+ucvEAH/im5atK7goIXg8KcyWJTNI6PEA 6FblRPfV3/qW5WN4B7aya/T9mjEP+XWSKaZp91PeKcv5YuJYNk/xRRS+z8McdbDGBqXF KmnRUTGTSKf/2uLT+b+tB1XZIK/nzC2wz2AK3DoCSjLfrnoZzrnEVmS4xQ9Kr0MxGq3r kd+453ffvuYiO9j0pYTSnNz0sIDdPhKRBx4j3ybS4YlB5+Z6GpBuEBt6mBlXtwMuVomj YUd5LgCkc28mMM2k1qi4FdB6Mc8T3qZYDdxzKgXA7RMiHzlpgnweIYQMIHLninNcbO1H CsjQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8-v6si8145111ple.222.2018.07.06.07.24.23; Fri, 06 Jul 2018 07:24:39 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754058AbeGFOXI (ORCPT + 99 others); Fri, 6 Jul 2018 10:23:08 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:37548 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753632AbeGFOXH (ORCPT ); Fri, 6 Jul 2018 10:23:07 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 200D2ED1; Fri, 6 Jul 2018 07:23:07 -0700 (PDT) Received: from [10.1.206.73] (en101.cambridge.arm.com [10.1.206.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B47273F2EA; Fri, 6 Jul 2018 07:23:05 -0700 (PDT) Subject: Re: [PATCH v4 7/7] KVM: arm64: Add support for creating PUD hugepages at stage 2 To: Punit Agrawal Cc: kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, marc.zyngier@arm.com, Catalin Marinas , Will Deacon , Russell King , linux-arm-kernel@lists.infradead.org References: <20180705140850.5801-1-punit.agrawal@arm.com> <20180705140850.5801-8-punit.agrawal@arm.com> <51265e49-8b8f-cabb-d2c9-d776a8a4ace8@arm.com> <87k1q8qwqb.fsf@e105922-lin.cambridge.arm.com> From: Suzuki K Poulose Message-ID: <12486745-ffb7-751e-9b2b-ff4722c5fd80@arm.com> Date: Fri, 6 Jul 2018 15:23:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <87k1q8qwqb.fsf@e105922-lin.cambridge.arm.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Punit, On 06/07/18 15:12, Punit Agrawal wrote: > Suzuki K Poulose writes: > >> Hi Punit, >> >> On 05/07/18 15:08, Punit Agrawal wrote: >>> KVM only supports PMD hugepages at stage 2. Now that the various page >>> handling routines are updated, extend the stage 2 fault handling to >>> map in PUD hugepages. >>> >>> Addition of PUD hugepage support enables additional page sizes (e.g., >>> 1G with 4K granule) which can be useful on cores that support mapping >>> larger block sizes in the TLB entries. >>> >>> Signed-off-by: Punit Agrawal >>> Cc: Christoffer Dall >>> Cc: Marc Zyngier >>> Cc: Russell King >>> Cc: Catalin Marinas >>> Cc: Will Deacon >> >>> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c >>> index 0c04c64e858c..5912210e94d9 100644 >>> --- a/virt/kvm/arm/mmu.c >>> +++ b/virt/kvm/arm/mmu.c >>> @@ -116,6 +116,25 @@ static void stage2_dissolve_pmd(struct kvm *kvm, phys_addr_t addr, pmd_t *pmd) >>> put_page(virt_to_page(pmd)); >>> } >>> +/** >>> + * stage2_dissolve_pud() - clear and flush huge PUD entry >>> + * @kvm: pointer to kvm structure. >>> + * @addr: IPA >>> + * @pud: pud pointer for IPA >>> + * >>> + * Function clears a PUD entry, flushes addr 1st and 2nd stage TLBs. Marks all >>> + * pages in the range dirty. >>> + */ >>> +static void stage2_dissolve_pud(struct kvm *kvm, phys_addr_t addr, pud_t *pud) >>> +{ >>> + if (!pud_huge(*pud)) >>> + return; >>> + >>> + pud_clear(pud); >> >> You need to use the stage2_ accessors here. The stage2_dissolve_pmd() uses >> "pmd_" helpers as the PTE entries (level 3) are always guaranteed to exist. > > I've fixed this and other uses of the PUD helpers to go via the stage2_ > accessors. > > I've still not quite come to terms with the lack of certain levels at > stage 2 vis-a-vis stage 1. I'll be more careful about this going > forward. I accept that it can be quite confusing. Once we get level independent types and table accessors this might be easier. For now, the general rule is stick to stage2_ accessors whenever you deal with the stage2 table. Rest should be left to the stage2 code to deal with it. > >>> @@ -1572,7 +1631,18 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, >>> if (exec_fault) >>> invalidate_icache_guest_page(pfn, vma_pagesize); >>> - if (hugetlb && vma_pagesize == PMD_SIZE) { >>> + if (hugetlb && vma_pagesize == PUD_SIZE) { >> >> I think we may need to check if the stage2 indeed has 3 levels of >> tables to use stage2 PUD. Otherwise, fall back to PTE level mapping >> or even PMD huge pages. Also, this cannot be triggered right now, >> as we only get PUD hugepages with 4K and we are guaranteed to have >> at least 3 levels with 40bit IPA. May be I can take care of it in >> the Dynamic IPA series, when we run a guest with say 32bit IPA. >> So for now, it is worth adding a comment here. > > Good point. I've added the following comment. > > /* > * PUD level may not exist if the guest boots with two > * levels at Stage 2. This configuration is currently > * not supported due to IPA size supported by KVM. > * > * Revisit the assumptions about PUD levels when > * additional IPA sizes are supported by KVM. > */ > Yep, that looks fine to me. Suzuki