Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp554256rwb; Fri, 4 Aug 2023 18:15:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMtVW1Sd7NIcsFrYbf5cOOH06BvKfv0dO3SnjIAz/7Qoxf/F3p/ic6v/C0fgpEpa7AmPVm X-Received: by 2002:a17:90a:de14:b0:268:400:ecef with SMTP id m20-20020a17090ade1400b002680400ecefmr2739233pjv.45.1691198100591; Fri, 04 Aug 2023 18:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691198100; cv=none; d=google.com; s=arc-20160816; b=Jkb+xSmicgWUDE4l2wtDqnKzECrTYNJn9fph5JQewCPRGObXpx9EgCJ19WuOxLcW8s XHDzOtZpnWfCFuiY0GVfsIvagJmB3A83bPuNEtbKBRV2Fb7raSx+pKkswNhuUUe/TEzU PdeqvWNvHlaYM5OYpwBKoRfjeOIRrcolOJjMK7+6iDlKbjI/kwOlE9eThKGLOcMflOXC R+hnsA3l/6m4TIYF9Zt7s6yWkG/4lDvzKbIt20UC65fifVX3KJqu3uX23XbSzQk9f71N OVzb8dqyOfmXvN4bYafUEBrBnWHfrXuCjv/ejBcTKPTCUGHcaM+LwMwvtDleQ4Hifw7K z9AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=qzzGQVsyCKQuIHhNuvYJJsNQNLnIEOy51Xxy7T0276E=; fh=VJ1zU/z7a+c49iqy7P0gzyQCwHynzOngpSabUIemtgU=; b=E992DL1nrVwnc1nWsfXvoxTDXCV9JPc9lwjG756w4uiOaQC6MzP2pVd0tHARKd+WN7 VrxCplGBFHdjD5xoCMdMIzpQDRfONbc1EVbwgk41qwOJ/SjKV3DwKrd/8UIj9NA1C7Kx YvAyD9BBRCliH6JHbZvwPe4UAyVDVIemrlH55JF1hHu0gVaWknzmyhsh4UgwitRiD1YZ 5NiyDYFG/0xlETVj0kj2DwntxCjPLbTmZj4dAhiUGCZkdITpb+RZJaDV6QGJjucj7RzK Ezt3LsYmRASttdlQgKRa1mCPNH+gbR0hGdcqpuG0RnOWV3miszwEIPU004Vv14Aqf+Cw ydPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=vyT9iRvB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020a17090a644600b00267ec897aa7si2604100pjm.104.2023.08.04.18.14.47; Fri, 04 Aug 2023 18:15:00 -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=@google.com header.s=20221208 header.b=vyT9iRvB; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbjHDWpj (ORCPT + 99 others); Fri, 4 Aug 2023 18:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjHDWpi (ORCPT ); Fri, 4 Aug 2023 18:45:38 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F08BCC for ; Fri, 4 Aug 2023 15:45:37 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-586a5cd0ea9so13156617b3.2 for ; Fri, 04 Aug 2023 15:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691189136; x=1691793936; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=qzzGQVsyCKQuIHhNuvYJJsNQNLnIEOy51Xxy7T0276E=; b=vyT9iRvBkAPxrhUM4loOuXv0ZWxpARTSozCHpx4ia9Cea9tMKrN/2RonnEmIi/91Y6 D9/kIxa3brvZlRc6QGKk01Hyt0jEboWVl3Z8oGFhLtizQUeXWjYBQlLJ3hEkbES8ojIp xRHERUnWaRuKMo9qbYUtw33JY4PImnq6niFxGhMqp8fDR7KFDwcJ/mK4TqIKH6HSmO9R Cw2H5HztJsHwRfX7RoC4cz33QJ8+8AwE8bdX3ip787drt5sStO7eeTcFQcC2vu6O5EC1 Jrv3s4q/GFzOUfGTyRixDp4N8PQ6wNQ7wlh9jGLouPYEjbTRIjnzGQFCnlolt9BIg96Q MmWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691189136; x=1691793936; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=qzzGQVsyCKQuIHhNuvYJJsNQNLnIEOy51Xxy7T0276E=; b=Khdi6sNljuYsn6afvp6dpvoBRQwb7Sg16ZoENpsttUL2AMacgoOw0A6JuAeRwJJ7GR epUBz6Hka5PzAQiAqK+Onm2e5RPWhf8o1niJkUGR/LExkYmgn88MS4vOk18YV9G3vntw B0fZVRUuLayzOy8nPaqvxGfXwNhEvjOwrX2lLdRu1ao4tVCHaZFMowBJYw+6lVHB9v4p rzP5kEm7jb4u1Jw+WHti791m40XC//OayAQxzjrkgFO8Hv+3SknwjMk3EMn5HcWs+RAB iIvP9VhpfMPBAUsapZdJL5gRAqP5JS82CR9mQA5mdEz98JrUL+sOnjAgxJjRHUcazLY5 KhWg== X-Gm-Message-State: AOJu0Yx526G/CjuqpBkGPm+2TFF5+CdThvsEtzPcs+GVvOALaGc1uZyi g2MeM/K/EPXUMik5IF2buYioM4Kj6+g= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:6b4a:0:b0:cb6:6c22:d0f8 with SMTP id o10-20020a256b4a000000b00cb66c22d0f8mr16070ybm.4.1691189136427; Fri, 04 Aug 2023 15:45:36 -0700 (PDT) Date: Fri, 4 Aug 2023 15:45:34 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230704075054.3344915-1-stevensd@google.com> <20230704075054.3344915-6-stevensd@google.com> <20230705101800.ut4c6topn6ylwczs@linux.intel.com> Message-ID: Subject: Re: [PATCH v7 5/8] KVM: x86/mmu: Don't pass FOLL_GET to __kvm_follow_pfn From: Sean Christopherson To: David Stevens Cc: Yu Zhang , Marc Zyngier , Michael Ellerman , Peter Xu , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 On Thu, Jul 06, 2023, David Stevens wrote: > On Wed, Jul 5, 2023 at 7:17=E2=80=AFPM Yu Zhang wrote: > > > > On Tue, Jul 04, 2023 at 04:50:50PM +0900, David Stevens wrote: > > > From: David Stevens > > > > > > Stop passing FOLL_GET to __kvm_follow_pfn. This allows the host to ma= p > > > memory into the guest that is backed by un-refcounted struct pages - = for > > > example, higher order non-compound pages allocated by the amdgpu driv= er > > > via ttm_pool_alloc_page. > > > > I guess you mean the tail pages of the higher order non-compound pages? > > And as to the head page, it is said to be set to one coincidentally[*], > > and shall not be considered as refcounted. IIUC, refcount of this head > > page will be increased and decreased soon in hva_to_pfn_remapped(), so > > this may not be a problem(?). But treating this head page differently, > > as a refcounted one(e.g., to set the A/D flags), is weired. > > > > Or maybe I missed some context, e.g., can the head page be allocted to > > guest at all? >=20 > Yes, this is to allow mapping the tail pages of higher order > non-compound pages - I should have been more precise in my wording. > The head pages can already be mapped into the guest. Recording for posterity (or to make an incorrect statment and get corrected= ), because I recently had a conversation about the head page not actually bein= g refcounted. (I can't remember with whom I had the conversation, but I'm pr= etty sure it wasn't an imaginary friend). Even though whatever allocates the page doesn't explicit refcount the head = page, __free_pages() will still do the right thing and (a) keep the head page aro= und until its last reference is put. And my understanding is that even though = it's a "head" page, it's not a PG_head page, i.e. not a compound page and so is = treated as an order-0 page when KVM invoke put_page(). void __free_pages(struct page *page, unsigned int order) { /* get PageHead before we drop reference */ int head =3D PageHead(page); if (put_page_testzero(page)) <=3D=3D=3D will evaluate false if KVM holds = a ref free_the_page(page, order); else if (!head) <=3D=3D=3D will be false for non-compound pages while (order-- > 0) free_the_page(page + (1 << order), order); } EXPORT_SYMBOL(__free_pages);