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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDA47C04A94 for ; Fri, 4 Aug 2023 22:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbjHDWpk (ORCPT ); Fri, 4 Aug 2023 18:45:40 -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-Google-Smtp-Source: AGHT+IEWfwtnQQ08PS920/iWYAxu1snSlSkt7kEi/UPqLCtV3oacTE1j6eL7G0tfMsosYlmzaiDwjq+gcnQ= 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 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);