From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5558C5519F for ; Wed, 18 Nov 2020 14:32:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36B35246B0 for ; Wed, 18 Nov 2020 14:32:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eubPXNLr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="v2fvZNY+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36B35246B0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qcwmW0GQtEk4YUWvkYVjs+rlMzd6U3rBkup93uxV4aI=; b=eubPXNLrcO12giJspR4W1BkEY I6R50cwMXdIF+4oKTtqrHU+5MOpOHV7+cX9Y2FCcn5Y/31Z8kkuppjwno+ZQMrkPfNxjhAGNMx/Eo vZh5uQHKfZpFAIyQzbyHt5uyZfoPHlYdr9yCn3DzELkvkR5ldGcXCKvERHwC2a2ZgB4rqAxw8fh7B DVRI3JlEapO0I06t/XQ+zXHqBBUO5LKN3T+diVs+cwLwcP9A9eEYMKEJy6LKNeObZRSWvZhfqG+1S D1+7KLPtLooO29usqoV3kxDa/piMLs9+kt5DKKyMmBBJlp4rY8ce3KdgNzpNKDQBOYUlIt94enlcu SDJxX6nDQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfOUx-0006NP-SW; Wed, 18 Nov 2020 14:31:51 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfOUu-0006N5-DM for linux-arm-kernel@lists.infradead.org; Wed, 18 Nov 2020 14:31:49 +0000 Received: by mail-wm1-x343.google.com with SMTP id s13so2913880wmh.4 for ; Wed, 18 Nov 2020 06:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=77gMImcbngsyFF3Kh1bUZt4EqmcmVNO0vErBUFdwx2w=; b=v2fvZNY+grT4giPGpG9AfdPemDFWlwFtdYpSOwbiaa6C9E4b1baIyzdWzuiGTlP7eS x7msBmtS2wkxDsy31kncXI7VGq0s/mnzfn74IKGpc1i9+QNjhLrd7j+dFe092Cn0dDjV KDBBZOuI5jZ5RjWsPPQtrwxEdGd6luqcgoD6zYO/sgtdKiCG8KBvsAVG/Iv4p8wQs65p mC5FtsmnqYnaDPfAvok/8WjV3T/akvz3RfZ2fgPXDWOAAS9WeK3XU9DWqe06ehUMfZRc /cUuRFAjKY3RD2J+A4EDKh5NRVcvHAClSrOyTCdwStFA3FuqGktmyzt85/OESDbT0Ssf k3Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=77gMImcbngsyFF3Kh1bUZt4EqmcmVNO0vErBUFdwx2w=; b=nELYfdQ5KEEmnOQ1xzVRBEzlrV/c4vgM0hUKDjiQQwdABigybPsTxbN4sJhXU1esW2 63jaw8q+YteLsPG29XwfgZm6/hwMOnUTpsfbMdh3Ml1M/d7kGomI6znAWKMq7mf2jFCj FD2PXkI69c4Ev2/hbbcqfami1/aaKV9grR2YJcefVK6sqoQ8AjZ9g0r6nydw80hedzKM k6faQRNR6skYr3hF5Q4WbReVipMO5Nbz+/WxCf3ykaXovOJJaVRIFEMUIyDYQHQMaK6r p7SfQGOHpSsBaKlv5rz/eXiUfjMSuvr4qE2cqF3VgFt5UlPQEW80pjIj6t+zWYNsmZtI p3yQ== X-Gm-Message-State: AOAM530XfxFOeVeFeKfKHTkmyhZXdJqHhsXFUg+HfMb9G2QR26FVUwX3 oiizRSOEd2H1u809rgH8D5H1rQ== X-Google-Smtp-Source: ABdhPJyiO0C6fIniO9A8G4+oXO/BFYBEEq1ifMK+gP7zPSNkLa+obZh4pOi4zfnF+eiaqN3P59YUgA== X-Received: by 2002:a7b:cbc8:: with SMTP id n8mr334272wmi.124.1605709906953; Wed, 18 Nov 2020 06:31:46 -0800 (PST) Received: from google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) by smtp.gmail.com with ESMTPSA id u5sm28800161wro.56.2020.11.18.06.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 06:31:45 -0800 (PST) Date: Wed, 18 Nov 2020 14:31:42 +0000 From: Quentin Perret To: Rob Herring Subject: Re: [RFC PATCH 15/27] of/fdt: Introduce early_init_dt_add_memory_hyp() Message-ID: <20201118143142.GA2220979@google.com> References: <20201117181607.1761516-1-qperret@google.com> <20201117181607.1761516-16-qperret@google.com> <20201118092547.GA2031536@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201118092547.GA2031536@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201118_093148_538665_F597274A X-CRM114-Status: GOOD ( 21.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , Android Kernel Team , Frank Rowand , Suzuki K Poulose , android-kvm@google.com, Catalin Marinas , open list , James Morse , "moderated list:ARM64 PORT \(AARCH64 ARCHITECTURE\)" , Marc Zyngier , Will Deacon , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 \(KVM/arm64\)" , Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wednesday 18 Nov 2020 at 09:25:47 (+0000), Quentin Perret wrote: > I'll have a go at the memblock stuff to see if I find a way to make it > work from that angle. OK, no luck with the memblock API, but I figured that I can actually postpone the KVM memory reservation to a later point, after unflatten_device_tree(), which lets me iterate over the memory nodes directly rather than having the fdt driver do it for me. The below seems to boot alright (though I'm not too familiar with of_address_to_resource() so I may not be using right) and keeps the whole thing in arch/arm64. Thoughts? Thanks, Quentin ---8<--- diff --git a/arch/arm64/kvm/hyp/reserved_mem.c b/arch/arm64/kvm/hyp/reserved_mem.c index 7da8e2915c1c..cab5ad587a3a 100644 --- a/arch/arm64/kvm/hyp/reserved_mem.c +++ b/arch/arm64/kvm/hyp/reserved_mem.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -16,7 +17,7 @@ phys_addr_t hyp_mem_base; phys_addr_t hyp_mem_size; -void __init early_init_dt_add_memory_hyp(u64 base, u64 size) +static int __init add_hyp_memblock_region(struct resource *rsrc) { struct hyp_memblock_region *reg; @@ -24,12 +25,14 @@ void __init early_init_dt_add_memory_hyp(u64 base, u64 size) kvm_nvhe_sym(hyp_memblock_nr) = -1; if (kvm_nvhe_sym(hyp_memblock_nr) < 0) - return; + return -ENOMEM; reg = kvm_nvhe_sym(hyp_memory); - reg[kvm_nvhe_sym(hyp_memblock_nr)].start = base; - reg[kvm_nvhe_sym(hyp_memblock_nr)].end = base + size; + reg[kvm_nvhe_sym(hyp_memblock_nr)].start = rsrc->start; + reg[kvm_nvhe_sym(hyp_memblock_nr)].end = rsrc->end; kvm_nvhe_sym(hyp_memblock_nr)++; + + return 0; } static int cmp_hyp_memblock(const void *p1, const void *p2) @@ -52,7 +55,10 @@ void kvm_sort_memblock_regions(void) extern bool enable_protected_kvm; void __init reserve_kvm_hyp(void) { + struct device_node *np; + struct resource rsrc; u64 nr_pages, prev; + int i; if (!enable_protected_kvm) return; @@ -60,8 +66,14 @@ void __init reserve_kvm_hyp(void) if (!is_hyp_mode_available() || is_kernel_in_hyp_mode()) return; - if (kvm_nvhe_sym(hyp_memblock_nr) <= 0) - return; + for_each_node_by_type(np, "memory") { + for (i = 0; !of_address_to_resource(np, i, &rsrc); i++) { + if (!add_hyp_memblock_region(&rsrc)) + continue; + kvm_err("Failed to add hyp memblock\n"); + return; + } + } hyp_mem_size += num_possible_cpus() << PAGE_SHIFT; hyp_mem_size += hyp_s1_pgtable_size(); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index f81da019b677..114f788a4da4 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -391,7 +391,6 @@ void __init arm64_memblock_init(void) reserve_elfcorehdr(); - reserve_kvm_hyp(); high_memory = __va(memblock_end_of_DRAM() - 1) + 1; @@ -423,6 +422,8 @@ void __init bootmem_init(void) dma_pernuma_cma_reserve(); + reserve_kvm_hyp(); + /* * sparse_init() tries to allocate memory from memblock, so must be * done after the fixed reservations diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index af2b5a09c5b4..4602e467ca8b 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1099,10 +1099,6 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, #define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0) #endif -void __init __weak early_init_dt_add_memory_hyp(u64 base, u64 size) -{ -} - void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) { const u64 phys_offset = MIN_MEMBLOCK_ADDR; @@ -1143,7 +1139,6 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size) base = phys_offset; } memblock_add(base, size); - early_init_dt_add_memory_hyp(base, size); } int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel