Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp749599ybl; Thu, 12 Dec 2019 04:23:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxkjE6sMPlBNBGlKvmWVm/fDLfDOw2a0plYRlSicMC1IpvhXfk5NsYM22N3eoOdctyCBWXJ X-Received: by 2002:a9d:1d07:: with SMTP id m7mr7959603otm.261.1576153398173; Thu, 12 Dec 2019 04:23:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576153398; cv=none; d=google.com; s=arc-20160816; b=XLwHiUBg5GFbuAWE5arcEelz7Mry6Z3QliTEFOWGERr2yO2erhXM3DhGCsowG68i5X YLvlJMpMCw7/vek3BTn5jkRgkF4zJityoFyQq+fz9Izw7QD7xt4kJarozSd27HJUH5BC lf4cqPcSZTddKnaCfuolJhFJoDLJeKzDRdpQcfCJdVT9fkoekotynrhwl0XSsbIpxpH+ O8gnpi3u2YSujk7bZjmLfTQ2Ii/Ck48tRYJAWWRW75N+YgTQ0uF/4ea0+CeihvWZ65He mnWDQ6/5aFFabvpb4r2zU6lEoqym2hSu9/iNPhSqJlT87ug82yCCzs57asHzT3n+Qatf y4qw== 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:organization:autocrypt:from:references:cc:to:subject :dkim-signature; bh=1qesrVN4EimxHknkcna6mR6JDjMYcUUxw/rPgRUa9lk=; b=pQTYyCP7aPSyNeN5FHnXSm3j34cuZcOklVV+w5PUbaKqFFytPoLmQCmUvmM2/GWhrD uDFl/nVw1pv9u2Ps8akfn9mN4SFEklEn8+/zICNF7f84K39MgcKs5GRYgCRYvd7U32cL yy2YWPStFoeeSzpKEpJ5W8oi0ztUEiCz9FyIHHh87xtkXX4xZ7HXzDAM7k1KJGwpEpOy bzZu4unnaRlxb/3tkJhQN/eV7XpXqjduEuP1kpGhhfAdPMiclFA9T1gi2ZswfB7h/NWb mDrr3VvdlPMhjWECiPm7AlqiIkUTyrpgpsJRNxoeNt0kuyjMnqJjvgECa+F/YCHMnY/A 47CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a7MONRIP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z23si2899033otm.284.2019.12.12.04.23.05; Thu, 12 Dec 2019 04:23:18 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a7MONRIP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729186AbfLLMWX (ORCPT + 99 others); Thu, 12 Dec 2019 07:22:23 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:54681 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729118AbfLLMWW (ORCPT ); Thu, 12 Dec 2019 07:22:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576153340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=1qesrVN4EimxHknkcna6mR6JDjMYcUUxw/rPgRUa9lk=; b=a7MONRIPEzKEoAW58X3JqgC9dPa4YedZRYH5/t8LKkbzrsejI66EI7AkWeSxNgaDpMBrI4 6ARcyRj8D3G/R8BIa22bVWqBzmIzSGqXWrw5DIFmMUzQ2edupm0ub2YWQVJ6kJT1VoZV+F 3Wl9nLwEw0twX3wl+MYju4I+DCEW784= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-357-feVWBmqHMe6e8ynZ-r4yKw-1; Thu, 12 Dec 2019 07:22:16 -0500 X-MC-Unique: feVWBmqHMe6e8ynZ-r4yKw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E99038024E9; Thu, 12 Dec 2019 12:22:14 +0000 (UTC) Received: from [10.36.117.91] (ovpn-117-91.ams2.redhat.com [10.36.117.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id C949319C58; Thu, 12 Dec 2019 12:22:12 +0000 (UTC) Subject: Re: [PATCH v4 2/2] kvm: Use huge pages for DAX-backed files To: Barret Rhoden , Paolo Bonzini , Dan Williams , Dave Jiang , Alexander Duyck Cc: linux-nvdimm@lists.01.org, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jason.zeng@intel.com References: <20191211213207.215936-1-brho@google.com> <20191211213207.215936-3-brho@google.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7An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Ic6MSyGUozASX+bmIuPeIecc9UsFRatc91LuJCKMkD9Uv GOcWSeFpLrSGRQ1Z7EMzFVU//qVs6uzhsNk0RYMyS0B6oloW3FpyQ+zOVylFWQCzoyyf227y GW8HnXunJSC+4PtlL2AY4yZjAVAPLK2l6mhgClVXTQ/S7cBoTQKP+jvVJOoYkpnFxWE9pn4t H5QIFk7Ip8TKr5k3fXVWk4lnUi9MTF/5L/mWqdyIO1s7cjharQCstfWCzWrVeVctpVoDfJWp 4LwTuQ5yEM2KcPeElLg5fR7WB2zH97oI6/Ko2DlovmfQqXh9xWozQt0iGy5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: Date: Thu, 12 Dec 2019 13:22:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191211213207.215936-3-brho@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11.12.19 22:32, Barret Rhoden wrote: > This change allows KVM to map DAX-backed files made of huge pages with > huge mappings in the EPT/TDP. > > DAX pages are not PageTransCompound. The existing check is trying to > determine if the mapping for the pfn is a huge mapping or not. For > non-DAX maps, e.g. hugetlbfs, that means checking PageTransCompound. > For DAX, we can check the page table itself. > > Note that KVM already faulted in the page (or huge page) in the host's > page table, and we hold the KVM mmu spinlock. We grabbed that lock in > kvm_mmu_notifier_invalidate_range_end, before checking the mmu seq. > > Signed-off-by: Barret Rhoden > --- > arch/x86/kvm/mmu/mmu.c | 36 ++++++++++++++++++++++++++++++++---- > 1 file changed, 32 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 6f92b40d798c..cd07bc4e595f 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3384,6 +3384,35 @@ static int kvm_handle_bad_page(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) > return -EFAULT; > } > > +static bool pfn_is_huge_mapped(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn) > +{ > + struct page *page = pfn_to_page(pfn); > + unsigned long hva; > + > + if (!is_zone_device_page(page)) > + return PageTransCompoundMap(page); > + > + /* > + * DAX pages do not use compound pages. The page should have already > + * been mapped into the host-side page table during try_async_pf(), so > + * we can check the page tables directly. > + */ > + hva = gfn_to_hva(kvm, gfn); > + if (kvm_is_error_hva(hva)) > + return false; > + > + /* > + * Our caller grabbed the KVM mmu_lock with a successful > + * mmu_notifier_retry, so we're safe to walk the page table. > + */ > + switch (dev_pagemap_mapping_shift(hva, current->mm)) { > + case PMD_SHIFT: > + case PUD_SIZE: Shouldn't this be PUD_SHIFT? But I agree with Paolo, that this is simply return dev_pagemap_mapping_shift(hva, current->mm) > PAGE_SHIFT; > + return true; > + } > + return false; > +} > + > static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu, > gfn_t gfn, kvm_pfn_t *pfnp, > int *levelp) > @@ -3398,8 +3427,8 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu, > * here. > */ > if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) && > - !kvm_is_zone_device_pfn(pfn) && level == PT_PAGE_TABLE_LEVEL && > - PageTransCompoundMap(pfn_to_page(pfn)) && > + level == PT_PAGE_TABLE_LEVEL && > + pfn_is_huge_mapped(vcpu->kvm, gfn, pfn) && > !mmu_gfn_lpage_is_disallowed(vcpu, gfn, PT_DIRECTORY_LEVEL)) { > unsigned long mask; > /* > @@ -6015,8 +6044,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, > * mapping if the indirect sp has level = 1. > */ > if (sp->role.direct && !kvm_is_reserved_pfn(pfn) && > - !kvm_is_zone_device_pfn(pfn) && > - PageTransCompoundMap(pfn_to_page(pfn))) { > + pfn_is_huge_mapped(kvm, sp->gfn, pfn)) { > pte_list_remove(rmap_head, sptep); > > if (kvm_available_flush_tlb_with_range()) > Patch itself looks good to me (especially, cleans up these two places a bit). I am not an expert on the locking part, so I can't give my RB. -- Thanks, David / dhildenb