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=-12.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham 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 95C36C48BDF for ; Thu, 24 Jun 2021 12:00:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78F05613EA for ; Thu, 24 Jun 2021 12:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbhFXMCw (ORCPT ); Thu, 24 Jun 2021 08:02:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49838 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbhFXMCw (ORCPT ); Thu, 24 Jun 2021 08:02:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624536032; 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; bh=avGojGcO92NTULuhKarR1IMbTxAu/KipAq8BEw7I0Ko=; b=NwH7B5NWjpeo7xHuBdxiGRVZh4xvFr+1lFCIJJITHPUdkX1qQF6HaOwh7QLG0Nd8FkYAvF xESavrCoW3oJDHBQuPpw3tbG2YBsPxiC6jO70F5rBsHr1BY5umW0PjAB5zZ5EoQX6wnH1p zktQA9JdpEloy+r80cSPmHzIxlXLtTM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-Y8QzNWRdMs22Vic2SAc0yg-1; Thu, 24 Jun 2021 08:00:31 -0400 X-MC-Unique: Y8QzNWRdMs22Vic2SAc0yg-1 Received: by mail-wr1-f71.google.com with SMTP id j1-20020adfb3010000b02901232ed22e14so2132622wrd.5 for ; Thu, 24 Jun 2021 05:00:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=avGojGcO92NTULuhKarR1IMbTxAu/KipAq8BEw7I0Ko=; b=TpUshdXzZ4bFGj4vu4hq890HqutfOS1tOCvKg8HjgRkpaL2Wl0/zw8Zs1noKS3TUpa 0NR70QnPPUaPbHMetA6l2zqJQOGWPPc3vbBXdPQu/qfQA7RNP1idYDwYRWuvXTEqQqov m1uU0EByT9QdnjV4fK/ifwslQNSGqqpch+omX1tVbFsrTjlzkLvLpFWzbUvAS+PEppck sRB5K0zoRRSlx+gLFMVXVnjzTAyr8dGD5v10mdenjawTD1+9M55PWukCgehwIqEdGpon nXw91VF/809Z4xVeWzhd0hIYPL+tf8ep6Ej9MJZX+VZe+7/0Yo90kCD/b4L3XpgmdAhB rBLA== X-Gm-Message-State: AOAM531+pF9dthMfbi/a9zCyqVR4r+g0CsN4lzPMVutKpM7DaM85Eo3q h3JTHlJb2tZBUl42odcO4bAbFo7o0yBOIkU/SN+JKKyj6uMWORSDpJ1Yu+M2SoDRCZEYhxpINSX b/7kva0Y9Lo2pcbafcXIkHw== X-Received: by 2002:a1c:f215:: with SMTP id s21mr3879322wmc.179.1624536030031; Thu, 24 Jun 2021 05:00:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXFCnAp+BCIAB50GwF3Py3d9h4g0enz3/eZSVNkNtDC1Z07h1ecnwnq+OHmfePVB6B9P4IuQ== X-Received: by 2002:a1c:f215:: with SMTP id s21mr3879281wmc.179.1624536029808; Thu, 24 Jun 2021 05:00:29 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id o2sm3074141wrp.53.2021.06.24.05.00.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 05:00:29 -0700 (PDT) To: Nicholas Piggin , Aleksandar Markovic , Huacai Chen , Marc Zyngier , Paul Mackerras , David Stevens , Zhenyu Wang , Zhi Wang Cc: Alexandru Elisei , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, James Morse , Jim Mattson , Joerg Roedel , kvmarm@lists.cs.columbia.edu, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Sean Christopherson , David Stevens , Suzuki K Poulose , Vitaly Kuznetsov , Wanpeng Li , Will Deacon References: <20210624035749.4054934-1-stevensd@google.com> <1624530624.8jff1f4u11.astroid@bobo.none> <1624534759.nj0ylor2eh.astroid@bobo.none> From: Paolo Bonzini Subject: Re: [PATCH 0/6] KVM: Remove uses of struct page from x86 and arm64 MMU Message-ID: Date: Thu, 24 Jun 2021 14:00:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <1624534759.nj0ylor2eh.astroid@bobo.none> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 24/06/21 13:42, Nicholas Piggin wrote: > +static int kvm_try_get_pfn(kvm_pfn_t pfn) > +{ > + if (kvm_is_reserved_pfn(pfn)) > + return 1; So !pfn_valid would always return true. Yeah, this should work and is certainly appealing! Paolo > + return get_page_unless_zero(pfn_to_page(pfn)); > +} > + > static int hva_to_pfn_remapped(struct vm_area_struct *vma, > unsigned long addr, bool *async, > bool write_fault, bool *writable, > @@ -2104,13 +2111,21 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, > * Whoever called remap_pfn_range is also going to call e.g. > * unmap_mapping_range before the underlying pages are freed, > * causing a call to our MMU notifier. > + * > + * Certain IO or PFNMAP mappings can be backed with valid > + * struct pages, but be allocated without refcounting e.g., > + * tail pages of non-compound higher order allocations, which > + * would then underflow the refcount when the caller does the > + * required put_page. Don't allow those pages here. > */ > - kvm_get_pfn(pfn); > + if (!kvm_try_get_pfn(pfn)) > + r = -EFAULT; > > out: > pte_unmap_unlock(ptep, ptl); > *p_pfn = pfn; > - return 0; > + > + return r; > } > > /* >