Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1831459rwl; Thu, 30 Mar 2023 02:01:53 -0700 (PDT) X-Google-Smtp-Source: AK7set+8rb8xa2K5IUDUUqxalAY/t0144pMKUoqw1yEDJKVhOHJXM4lHyHOcolzhoNBb+AJSWhLp X-Received: by 2002:a17:90b:1241:b0:233:a836:15f4 with SMTP id gx1-20020a17090b124100b00233a83615f4mr18667802pjb.1.1680166912829; Thu, 30 Mar 2023 02:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680166912; cv=none; d=google.com; s=arc-20160816; b=DLDNiYq9Nt9KXZb/OBnS5N3IMhWEqEolcQS6pJJGdR+lbi1IvS0v7C2/T2mJB5eytH uYkuetJIeu+23Q1MHB3MDz/A5IKrdfo0v8gC80n5f0Qmz5eCprcv6L2ZpPxHXWBht7D8 rPvL4lgpalSKKionFutKhdcsmPiLoMiNtpzPvWD4XQhX13sD/Yt1vhoJm3FW9liFbHTf KrF6el7ggt+aCivllEhCQBJ22L8tvbfTBJKoCoAZpeK7zJonDp3RZ3d+J0n2hXVy5y/w HR71l6fbFmd3cx/LL7bTT0arYNmYMJm2sQvZzy4PGOip+focPTy6pIt6rT1Hvi0GUqNQ ZT9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RprU1FQJyxxcIHKiSPrHpqU5Norly3mnaXVCeZUl59M=; b=jFT1qopFeqKdk6jfLZ9y0xTOgBbPp/oGQKuj+KaOo42B0ruKlGWw/X6A9ubIogvdOs UpzFEX/BoKDW+3FHtzo1duYNxpQ8D9JKMWz6ZZu91q+NX3ZFzeGrxknmi1oArcf2N2fS IozluKrVNo/I7ObTgX+hEyyMY83PlIwYR4di3+PyWLciq1DyH+kewxPRBmGokp3+Yapn JjIGhK2wRc5xtFyAWpbAyHDilsergcrWbQpHErRUWO79FQ4n9K+3Zu0+hPMFcq5OKR4X 4qV10Gial0Zygvwu3/YmNHGyECUUqW+xOyhA3Dbnbrpi2v0KV/0f342Kq6kO4KARM65w V6Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QDHkG5g+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a17090a318c00b00237b958814fsi3571197pjb.74.2023.03.30.02.01.24; Thu, 30 Mar 2023 02:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QDHkG5g+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230416AbjC3I6m (ORCPT + 99 others); Thu, 30 Mar 2023 04:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbjC3I6a (ORCPT ); Thu, 30 Mar 2023 04:58:30 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B0F7682 for ; Thu, 30 Mar 2023 01:58:24 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id ix20so17473673plb.3 for ; Thu, 30 Mar 2023 01:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1680166704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RprU1FQJyxxcIHKiSPrHpqU5Norly3mnaXVCeZUl59M=; b=QDHkG5g+mhdDG+FzgKVq7FS5dKNc0YNfht7PzrIPGup07HPZi96FiixkgwPtKVIYGG YvA5YfJDQPGG3571GI68xmqSNKdRgYDNHzSXM1UF4Q6IX2GZf6W5zqMvZt/sbbPzmznM kDgvKePhP/3e133fLy2oCD4sa564mWqMu9USM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680166704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RprU1FQJyxxcIHKiSPrHpqU5Norly3mnaXVCeZUl59M=; b=wa5OZ2EVHLzh9utsdLPo/v9JslnBHos0JH07syKKrsx/fM/ru2pR/VbcOoie54boMt dHt2SpO0xbIjHUk14jMhgp9eCr7W6wZOFgFpry52RR/PIQvMLStDk1CYncV6nAE+m79N LAmPMZdWY6oZuQcj9nIo2zSFD4f7FiBn/kR+Winod79Dy4rflTJqqg7Z5Nh315XNnRn+ MRgRxMhgKPnq8PSn5bY8anduiB4rd2lSQz9HmDS1tiOzJF1uI5cAFIdSxTf9yuJd96D3 rm/h385p9eYA7fn6Dc8V8ZJQXekS1ae2/pEEz3Sccr7z6FlA4/KKgUiC6rgPYpo1gAlS Yheg== X-Gm-Message-State: AAQBX9c0P+PaHXoXPVV/RBF77LSgOgzMLHfB+jpoo5c9ujgZliHUo3wA JtyvCN/oZQ3hUJWSRSPNDdeybg== X-Received: by 2002:a17:902:c44c:b0:1a1:8edc:c5f8 with SMTP id m12-20020a170902c44c00b001a18edcc5f8mr18986019plm.56.1680166703992; Thu, 30 Mar 2023 01:58:23 -0700 (PDT) Received: from localhost ([2401:fa00:8f:203:1320:eef8:d0bb:b161]) by smtp.gmail.com with UTF8SMTPSA id bi11-20020a170902bf0b00b0019f11caf11asm24358430plb.166.2023.03.30.01.58.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Mar 2023 01:58:23 -0700 (PDT) From: David Stevens X-Google-Original-From: David Stevens To: Marc Zyngier , Sean Christopherson Cc: Oliver Upton , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, David Stevens Subject: [PATCH v6 3/4] KVM: arm64/mmu: use gfn_to_pfn_noref Date: Thu, 30 Mar 2023 17:58:01 +0900 Message-Id: <20230330085802.2414466-4-stevensd@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog In-Reply-To: <20230330085802.2414466-1-stevensd@google.com> References: <20230330085802.2414466-1-stevensd@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Stevens Switch the arm64 mmu to the new gfn_to_pfn_noref functions. This allows IO and PFNMAP mappings backed with valid struct pages but without refcounting (e.g. tail pages of non-compound higher order allocations) to be mapped into the guest. Signed-off-by: David Stevens --- arch/arm64/kvm/mmu.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 7113587222ff..0fd726e82a19 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1082,7 +1082,7 @@ static bool fault_supports_stage2_huge_mapping(struct kvm_memory_slot *memslot, static unsigned long transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memslot, unsigned long hva, kvm_pfn_t *pfnp, - phys_addr_t *ipap) + struct page **page, phys_addr_t *ipap) { kvm_pfn_t pfn = *pfnp; @@ -1091,7 +1091,8 @@ transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memslot, * sure that the HVA and IPA are sufficiently aligned and that the * block map is contained within the memslot. */ - if (fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE) && + if (*page && + fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE) && get_user_mapping_size(kvm, hva) >= PMD_SIZE) { /* * The address we faulted on is backed by a transparent huge @@ -1112,10 +1113,11 @@ transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memslot, * page accordingly. */ *ipap &= PMD_MASK; - kvm_release_pfn_clean(pfn); + kvm_release_page_clean(*page); pfn &= ~(PTRS_PER_PMD - 1); - get_page(pfn_to_page(pfn)); *pfnp = pfn; + *page = pfn_to_page(pfn); + get_page(*page); return PMD_SIZE; } @@ -1201,6 +1203,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, short vma_shift; gfn_t gfn; kvm_pfn_t pfn; + struct page *page; bool logging_active = memslot_is_logging(memslot); unsigned long fault_level = kvm_vcpu_trap_get_fault_level(vcpu); unsigned long vma_pagesize, fault_granule; @@ -1301,8 +1304,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, */ smp_rmb(); - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL, - write_fault, &writable, NULL); + pfn = __gfn_to_pfn_noref_memslot(memslot, gfn, false, false, NULL, + write_fault, &writable, NULL, &page); if (pfn == KVM_PFN_ERR_HWPOISON) { kvm_send_hwpoison_signal(hva, vma_shift); return 0; @@ -1348,7 +1351,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, vma_pagesize = fault_granule; else vma_pagesize = transparent_hugepage_adjust(kvm, memslot, - hva, &pfn, + hva, + &pfn, &page, &fault_ipa); } @@ -1395,8 +1399,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, out_unlock: read_unlock(&kvm->mmu_lock); - kvm_set_pfn_accessed(pfn); - kvm_release_pfn_clean(pfn); + kvm_release_pfn_noref_clean(pfn, page); return ret != -EAGAIN ? ret : 0; } -- 2.40.0.348.gf938b09366-goog