Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36217569rwd; Mon, 10 Jul 2023 20:27:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlE8YLU9DAOg45CjYvyJ3C2kectUHTvHzWTEJ1qcaxd/YA0SDY2ZXypN/yM3lJXNrP4h+Uld X-Received: by 2002:a17:906:3282:b0:991:f7cb:cc3d with SMTP id 2-20020a170906328200b00991f7cbcc3dmr12291414ejw.65.1689046044721; Mon, 10 Jul 2023 20:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689046044; cv=none; d=google.com; s=arc-20160816; b=Oe/AKeYgoUFWcdJ0bSO/Gyz+i0wlJu2ci9i91bnGTm1FDjVsEI7zeEvcF4tQj80QX4 I/cz/rLjAp6uUYag9lj2NnATdH2rPeUVfOk3PfkryFRjDGzWyk+tkZgI5zao8hr/bZS3 Et1Lzu8DbU3W8K3oaBBUmj4ME2FLecusO3GCXf0dnXruP+mZe5KIwNGHXrwCqMO7iUGJ suJvrCX9N2TIUvus+qXfKxe0yex9oov/wJTiGndk66vLX1/kKQIBB2RihihLLgkE4pKH cPSFAzBvLniKaL9GWptRYC5yjmGEjBXjHVpsA88MyqjegrUMrhr6QEGdGjEVcv3FiRzB rlEw== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+DBmSxEV9koNvPnH4f6fQb1MyHlXgygw1qw/AWmL9NU=; fh=kXYxInfp3zP0E0/Jk3foitQJufcbNmZYjnx9jn/WtZw=; b=A0V67t7MCCYwpTtAMGNMknHZfozBfcWwCErTvU3gH0eP9rNpzXVY5IV4LXGjXeaz2I G2DZqoFM0YKOL62eEhACNRl+EBEUEDvyU6K46sJZMhe8ye+1JQXg5AmGTMQkD/AJAkmO mtYSP6n2bV2XqFOdvh/QsudWgXRL3MP69QB62TRX/xgkQ1PuObrUj3wA7QGC3IMXXrCi 3fJlcAia7HI2HzyVqtJelTWyyR+uRjkzbiQrEheeRKyBgKQvPPPoPQJJEaJTnMeugrMJ Ugxm0CKAEUcSnQZ1JIotiR8pC7woE5TUPAfcBSrIaOgIeVdSAem0ZYjmag6lEKH5Vgft a05w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jbRRZbz4; 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 t26-20020a170906179a00b009936735feccsi1175641eje.210.2023.07.10.20.27.00; Mon, 10 Jul 2023 20:27:24 -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=jbRRZbz4; 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 S229512AbjGKC7c (ORCPT + 99 others); Mon, 10 Jul 2023 22:59:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbjGKC7b (ORCPT ); Mon, 10 Jul 2023 22:59:31 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE77FE5C for ; Mon, 10 Jul 2023 19:59:21 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2b6f0508f54so79822861fa.3 for ; Mon, 10 Jul 2023 19:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689044360; x=1691636360; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+DBmSxEV9koNvPnH4f6fQb1MyHlXgygw1qw/AWmL9NU=; b=jbRRZbz4ynuhPqqeV5apPzs0jqkJtDi55aZFCp3oS1Ky8RkTvPlwMnB4q/fiemRBoQ /nqmDMG2P1A6auw8vdVkBVLFNlCCKg5J2gfTl+c6qkohrCouZIFJFDxXVd83G/CNdJVI qpp4LD8m9YAEdXqPmRzBi1781HakxZf9US60Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689044360; x=1691636360; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+DBmSxEV9koNvPnH4f6fQb1MyHlXgygw1qw/AWmL9NU=; b=cfk+923vyODBc2YDIHgxQV55n/q1jER6M1iYElAXTq7wedleQzG5++NI7yPG0YUc/X kIQnR8qPuU8QuM+ohvBHcuJ4y+orth2sxyyzvZtYeSdKIYcI13NPj+aJvoaxHbMCx5x5 xqF6fgrlcRTQwblkcQFpgj0nRc7dTZOqrYfDYg6cAOvAR5ljvY+TtixGP72MWAJfzJJO E0TuUFIQ/y7Y4BcYrWtJXb76vKhrTxMr0rVtePx+Wa9DvCU8XDItfN2rSVDf1ORHp1ya 79LNS2LrxWZVxMRiLjb8z3eAE+fQOsB1bREXVslXIGz66x1F2SJQhYlN6OBICOF4XnTE znGw== X-Gm-Message-State: ABy/qLZWllHzcb3mfznw/vPjHL+OETp+K56NItFgwc6obWM9YLc0aig6 vyy022LuvOI3nF+W2gz7t1kGt6j5sNQVEGyIAbr/eA== X-Received: by 2002:a2e:7e12:0:b0:2b7:1b63:4657 with SMTP id z18-20020a2e7e12000000b002b71b634657mr5157080ljc.37.1689044359940; Mon, 10 Jul 2023 19:59:19 -0700 (PDT) MIME-Version: 1.0 References: <20230704075054.3344915-1-stevensd@google.com> <20230704075054.3344915-6-stevensd@google.com> <20230705101800.ut4c6topn6ylwczs@linux.intel.com> <20230706155805.GD3894444@ls.amr.corp.intel.com> <20230710163448.GE3894444@ls.amr.corp.intel.com> In-Reply-To: <20230710163448.GE3894444@ls.amr.corp.intel.com> From: David Stevens Date: Tue, 11 Jul 2023 11:59:08 +0900 Message-ID: Subject: Re: [PATCH v7 5/8] KVM: x86/mmu: Don't pass FOLL_GET to __kvm_follow_pfn To: Isaku Yamahata Cc: Yu Zhang , Sean Christopherson , 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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On Tue, Jul 11, 2023 at 1:34=E2=80=AFAM Isaku Yamahata wrote: > > On Fri, Jul 07, 2023 at 10:35:02AM +0900, > David Stevens wrote: > > > > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > > > > > index e44ab512c3a1..b1607e314497 100644 > > > > > > --- a/arch/x86/kvm/mmu/mmu.c > > > > > > +++ b/arch/x86/kvm/mmu/mmu.c > > > > > > > > > > ... > > > > > > > > > > > @@ -2937,6 +2943,7 @@ static int mmu_set_spte(struct kvm_vcpu *= vcpu, struct kvm_memory_slot *slot, > > > > > > bool host_writable =3D !fault || fault->map_writable; > > > > > > bool prefetch =3D !fault || fault->prefetch; > > > > > > bool write_fault =3D fault && fault->write; > > > > > > + bool is_refcounted =3D !fault || fault->is_refcounted_pag= e; > > > > > > > > > > Just wonder, what if a non-refcounted page is prefetched? Or is = it possible in > > > > > practice? > > > > > > > > Prefetching is still done via gfn_to_page_many_atomic, which sets > > > > FOLL_GET. That's fixable, but it's not something this series curren= tly > > > > does. > > > > > > So if we prefetch a page, REFCOUNTED bit is cleared unconditionally w= ith this > > > hunk. kvm_set_page_{dirty, accessed} won't be called as expected for= prefetched > > > spte. If I read the patch correctly, REFCOUNTED bit in SPTE should r= epresent > > > whether the corresponding page is ref-countable or not, right? > > > > > > Because direct_pte_prefetch_many() is for legacy KVM MMU and FNAME(pr= efetch_pte) > > > is shadow paging, we need to test it with legacy KVM MMU or shadow pa= ging to hit > > > the issue, though. > > > > > > > direct_pte_prefetch_many and prefetch_gpte both pass NULL for the > > fault parameter, so is_refcounted will evaluate to true. So the spte's > > refcounted bit will get set in that case. > > Oops, my bad. My point is "unconditionally". Is the bit always set for > non-refcountable pages? Or non-refcountable pages are not prefeched? The bit is never set for non-refcounted pages, and is always set for refcounted pages. The current series never prefetches non-refcounted pages, since it continues to use the gfn_to_page_many_atomic API. -David