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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E0A8D17128 for ; Mon, 21 Oct 2024 19:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TRc3VGGNkUkUR9ifA4nNeX0hRZiSdlXeerhUJQ+tYBo=; b=K5hLm55IdC+AIukfEuTrsHwXva cZwO8/tsYCxd0NevDsWRBlb95LVWnCK90Jl5YuYgJqXaW0pbONFd8cPO4Y+lzdwa0nI/xcrr4IOk5 jUVKuT9TnkGe3lVd1jwIGZSKbx8Cik2PFGTktwe6RtSUbmKsGI/P2XQJWECmDeQkcffXJEW0qu87o PMjl2WdPJ9T+voxvrECBjBO6mEaGME/KpDiweHfsPIf/ioliux2qJQhX/i3+Z74H61AFJ9xmFZW2T aIgVMPVZskol20rH5YW6/PcxK5I0vNxICnySu3ELQ1ulQvgVh645KC6m++u9C8fbQCMbikH//06dg rOOkHt0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2xdr-00000008NU7-1u4p; Mon, 21 Oct 2024 19:00:35 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2xb9-00000008Mwu-0NSq for linux-arm-kernel@lists.infradead.org; Mon, 21 Oct 2024 18:57:49 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7e9b2d75d6dso3983411a12.1 for ; Mon, 21 Oct 2024 11:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729537065; x=1730141865; darn=lists.infradead.org; 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=TRc3VGGNkUkUR9ifA4nNeX0hRZiSdlXeerhUJQ+tYBo=; b=w9Go7hKJw2sDm5AgMc/FV593puEvk3b38U/G5B4gLnqr+6L2CVc+DVhm0V81WfmNKa OHhWH3KYMQkNthbrZIAX86lJgzPyTaDKhohCGsU/cJEtOIhLaC48gj+HQZwgl6NDJ1CZ nuexkOmhkgk7uKS5NUtdR9OkK3iGAG3XYzEN6sSk5TPMo0QDfu0N9hyhfUqQUyRfyvbp ieHl5KD+a1oeJ2uuZWoIu5C0Id2UKvSsJuAIWVOWdNmh98CuosswKtr1K/gSOmyXAYzF KEALUUdydCTmls7mejUTN3W4c2WdjjsEqXEKO0Ttkvcc1FFQ+dRin42dixn0k4IFNDwL EYmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729537065; x=1730141865; 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=TRc3VGGNkUkUR9ifA4nNeX0hRZiSdlXeerhUJQ+tYBo=; b=hAQ26coipbkR+g+3fH0TDWNuVVguwp+tRvLtPwNvWlf8g9mRC/rYg/rte4oYVjo3KG OulPcK9B/s51PkIinVsL1pvqF/af+N81CiKwfSmK6IoAmJL8lpxQIjTjr4OrsyzrUx10 CZYwa59IR6du6niQll2ryTUKmmqySl/YUj3okIT45sWgZHq2i/qMBvvQ1J88i2i/Rwbp u+MWFXcXqvLqHNYIJoSnabcGzitTAV3oQqSjgJcI4ndJm541Sw60KuG+o0o5sc+vFuxu xvhX+luGA6Axt9TcshSEwBsKHY9u9euTtP4Eh+zZ9Npa900ReVhTkm4BgW4mjxkB5VDp If8A== X-Forwarded-Encrypted: i=1; AJvYcCX7btk3qe7t+ewvzuRE5JDGsx7cDBgHj2IVjn+KnwQl9sgqNIaABVtAaIMAsh2Pw9XwXL8e693RusiCv4WU62aT@lists.infradead.org X-Gm-Message-State: AOJu0Yzh2SC69LNeUobO/nsnbUHQ8MKh1xkDLzwt7aMmr22hvYynKhMq to5XhjRRuOreTEWRjG07ecUIa+FTNUlefaRxVdvPm2ZhJm1LrH1M2soPgzbFyMJCjrGCbPw5EIZ 8CA== X-Google-Smtp-Source: AGHT+IHRYlBrX6M+NH4TUGVEqm9BFtB7q+VVhXD5EoRBvSsXa42IiMZxJc+hXyxs+ZPnB8HLQQfXC/cdu0E= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a63:3858:0:b0:7e9:f93c:22b9 with SMTP id 41be03b00d2f7-7eacc895cf2mr12508a12.10.1729537064143; Mon, 21 Oct 2024 11:57:44 -0700 (PDT) Date: Mon, 21 Oct 2024 11:57:42 -0700 In-Reply-To: Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> <20241010182427.1434605-52-seanjc@google.com> Message-ID: Subject: Re: [PATCH v13 51/85] KVM: VMX: Use __kvm_faultin_page() to get APIC access page/pfn From: Sean Christopherson To: Yan Zhao Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, "Alex =?utf-8?Q?Benn=C3=A9e?=" , David Matlack , David Stevens , Andrew Jones Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_115747_145515_CAF52C71 X-CRM114-Status: GOOD ( 25.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 21, 2024, Yan Zhao wrote: > On Thu, Oct 10, 2024 at 11:23:53AM -0700, Sean Christopherson wrote: > > Use __kvm_faultin_page() get the APIC access page so that KVM can > > precisely release the refcounted page, i.e. to remove yet another user > > of kvm_pfn_to_refcounted_page(). While the path isn't handling a guest > > page fault, the semantics are effectively the same; KVM just happens to > > be mapping the pfn into a VMCS field instead of a secondary MMU. > >=20 > > Tested-by: Alex Benn=C3=A9e > > Signed-off-by: Sean Christopherson > > --- ... > > @@ -6838,10 +6840,13 @@ void vmx_set_apic_access_page_addr(struct kvm_v= cpu *vcpu) > > vmcs_write64(APIC_ACCESS_ADDR, pfn_to_hpa(pfn)); > > =20 > > /* > > - * Do not pin apic access page in memory, the MMU notifier > > - * will call us again if it is migrated or swapped out. > > + * Do not pin the APIC access page in memory so that it can be freely > > + * migrated, the MMU notifier will call us again if it is migrated or > > + * swapped out. KVM backs the memslot with anonymous memory, the pfn > > + * should always point at a refcounted page (if the pfn is valid). > > */ > > - kvm_release_pfn_clean(pfn); > > + if (!WARN_ON_ONCE(!refcounted_page)) > > + kvm_release_page_clean(refcounted_page); > Why it's not > if (!WARN_ON_ONCE(!refcounted_page)) { > if (writable) > kvm_release_page_dirty(refcounted_page) > else > kvm_release_page_clean(refcounted_page) > } >=20 > or simply not pass "writable" to __kvm_faultin_pfn() as we know the slot = is > not read-only and then set dirty ? __kvm_faultin_pfn() requires a non-NULL @writable. The intent is to help e= nsure the caller is actually checking whether a readable vs. writable mapping was acquired. For cases that explicitly pass FOLL_WRITE, it's awkward, but tho= se should be few and far between. > if (!WARN_ON_ONCE(!refcounted_page)) > kvm_release_page_dirty(refcounted_page) Ya, this is probably more correct? Though I would strongly prefer to make = any change in behavior on top of this series. The use of kvm_release_page_clea= n() was added by commit 878940b33d76 ("KVM: VMX: Retry APIC-access page reload = if invalidation is in-progress"), and I suspect the only reason it added the kvm_set_page_accessed() call is because there was no "unused" variant. I.e= . there was no concious decision to set Accessed but not Dirty.