Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp654243ybh; Wed, 22 Jul 2020 09:45:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVOYybFRdTNTUca9U8grfYAJh1+rTn3gXiXKwbqaK7NEaujyjdbpHUi1v3mJxbF8yactWE X-Received: by 2002:a50:d6dd:: with SMTP id l29mr297480edj.345.1595436358230; Wed, 22 Jul 2020 09:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595436358; cv=none; d=google.com; s=arc-20160816; b=a4qDnDdKliFfGQ8RCxMefoAaiLiGP0QPBW15cPJ04DTxICQuf1P03ArrL/uAeHEi5H up2fb5PEWa0m2l+8DF2TjeV0EaXw29KHsStvl6YZwZXw+rfDBKeTVX/uM+y3jwec9Snh Jin9yks0P+ceXFCV935vgKWHuHxa7W1n9A0FXXw2Nibe5AKTgqZoQxLxsbmAZ4q0bCg0 ggkSu2eiKi1+YN92UYY8A/IYn/YCXFsuEC/ODQH2eLRZT21Z6J67sJ/7O4D8OiKToU4I n/E1bVSc9MPvfiX9bXP3QYBvcvky/6brYFhZ5Ynn7JU9MRCQ9lvn+akfb2oxkHwoGk63 TvnA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bcTngC2Bes9sF1CupaxPgWX3tAw0UoRfYaGJIdlmeeQ=; b=imJUrL/+h0mBCsii9w3VJaKTHNpwGMcuUvpwRxeT6PHTAq8fnKfpeCrWk0CM9MazlV ku4igZHZPeG+Zh7XKER+h+xoXQb4eDhHOG+c4DQZGugJqlkqkYKZGL/o42chgMuQaebX qRL3qhgzgCBTLucwuACvQXfVSnzni4DGhF8ye1hB1VEpbo6Js1OEC9tW2qgToYP/VTt+ LzNnv/H/3mpOgRzIJkO0N/539xPk9HDv93fp2LtSvncUWxyizj+A4M7rfhozYbvhAP2g 1AIB3sl6st95VNJz+gz0/+Dm9VFVd2enl0exoz9syFUiIyRSYhYWMUsTx6tqUsHl07Kh 09Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mvQ2D74Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de9si316824edb.404.2020.07.22.09.45.34; Wed, 22 Jul 2020 09:45:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mvQ2D74Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731316AbgGVQpQ (ORCPT + 99 others); Wed, 22 Jul 2020 12:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731204AbgGVQpN (ORCPT ); Wed, 22 Jul 2020 12:45:13 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1345C0619E0 for ; Wed, 22 Jul 2020 09:45:12 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id r12so2524651wrj.13 for ; Wed, 22 Jul 2020 09:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bcTngC2Bes9sF1CupaxPgWX3tAw0UoRfYaGJIdlmeeQ=; b=mvQ2D74QyUwCzSPTgbT4sWDjrm7UJoVfL3cHenKVZM4lEyQ4kiJMrsWap47ViZ/Wvr rZDWLr9NFPdHynImP8k+kUbehz7sK/izWI9taaixH28DDyAQxLDE2IVjI4JHth6sqvMd Bm3MyxL4Ev2MPQ719BJsT1suvEsdnYD9LiwdooMdWfuceghQTEMxSuCUAzFCiQNkszgr 776DU9p9GQmi0hKDgGS6X4PrAU7F1kaKRpoHIctLA3l3w5RGa68JqwP9mYrDKItjiXEp YdYfHynQXX5o0Cs0P73flkaXSX7R5VWhnBQrZk7Ew+typZtMNI/jv6YpF1C6khkBO0C0 nNTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bcTngC2Bes9sF1CupaxPgWX3tAw0UoRfYaGJIdlmeeQ=; b=S6cAsl2iwMhqrGhBs5OzHPDImYfc15l0PJbJZ21ulQXDWnHd/t7AWW+UP5F5o4jSox s+YllJwa3LrrsGieGGJt1DWtxs88JcpZ1kdV5kv+wjePQWNjGuG445xHp+FPzJa2+nEK u6ckVmdZ5l/hTZD+uxBG3fY44U/bEZA+CKU8+ECbXsAG13aky9uWtsldXIjaopntgR/6 6MF5VOHUqz6EnpLlRBiveQqzl13exQyk2k3rHsEwyEmqQSuWPe6MojNemU+JYLLzg7LX bGo7cBSpugHbeW8p6hKtGAANd+0At70nnjRYvxMFZ9xVGpF4ae6lhu1pJZHxY69qPW7m 9BbA== X-Gm-Message-State: AOAM531qaf8/QoXpkT73VvSbLdDLCvq+jN4mxdPG0xUhFf92j3dQYPUG VqD/ZF8fsF6uZl8VOgxdblLxzQ== X-Received: by 2002:a5d:558a:: with SMTP id i10mr388087wrv.146.1595436311404; Wed, 22 Jul 2020 09:45:11 -0700 (PDT) Received: from localhost ([2a01:4b00:8523:2d03:b0ee:900a:e004:b9d0]) by smtp.gmail.com with ESMTPSA id e5sm631557wrc.37.2020.07.22.09.45.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jul 2020 09:45:10 -0700 (PDT) From: David Brazdil To: Catalin Marinas , Will Deacon , Marc Zyngier , Dennis Zhou , Tejun Heo , Christoph Lameter , Arnd Bergmann Cc: James Morse , Julien Thierry , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, kernel-team@google.com, David Brazdil Subject: [PATCH 7/9] kvm: arm64: Mark hyp stack pages reserved Date: Wed, 22 Jul 2020 17:44:22 +0100 Message-Id: <20200722164424.42225-8-dbrazdil@google.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722164424.42225-1-dbrazdil@google.com> References: <20200722164424.42225-1-dbrazdil@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for unmapping hyp pages from host stage-2, allocate/free hyp stack using new helpers which automatically mark the pages reserved. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 49 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 0700c3d21b23..dc557b380c87 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1451,13 +1451,58 @@ static int init_subsystems(void) return err; } +/* + * Alloc pages and mark them reserved so the kernel never tries to + * take them away from the hypervisor. + */ +static unsigned long alloc_hyp_pages(gfp_t flags, unsigned int order) +{ + struct page *page; + unsigned long i; + + page = alloc_pages(flags, order); + if (!page) + return 0; + + for (i = 0; i < (1ul << order); ++i) + mark_page_reserved(page + i); + + return (unsigned long)page_address(page); +} + +static unsigned long alloc_hyp_page(gfp_t flags) +{ + return alloc_hyp_pages(flags, 0); +} + +/* + * Free pages which were previously marked reserved for the hypervisor. + */ +static void free_hyp_pages(unsigned long addr, unsigned int order) +{ + unsigned long i; + struct page *page; + + if (!addr) + return; + + page = virt_to_page(addr); + for (i = 0; i < (1ul << order); ++i) + free_reserved_page(page + i); +} + +static void free_hyp_page(unsigned long addr) +{ + return free_hyp_pages(addr, 0); +} + static void teardown_hyp_mode(void) { int cpu; free_hyp_pgds(); for_each_possible_cpu(cpu) - free_page(per_cpu(kvm_arm_hyp_stack_page, cpu)); + free_hyp_page(per_cpu(kvm_arm_hyp_stack_page, cpu)); } /** @@ -1481,7 +1526,7 @@ static int init_hyp_mode(void) for_each_possible_cpu(cpu) { unsigned long stack_page; - stack_page = __get_free_page(GFP_KERNEL); + stack_page = alloc_hyp_page(GFP_KERNEL); if (!stack_page) { err = -ENOMEM; goto out_err; -- 2.27.0