Message ID | 20231002095740.1472907-5-paul@xen.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1407150vqb; Mon, 2 Oct 2023 06:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkJFKcEEIBdevjV77GhWGpcbClxFU/XC0fU2vxtoDvWEJMSqF+J6l7M+9Ir/qqzEUixjEH X-Received: by 2002:a05:6a00:3a1e:b0:68e:417c:ed5c with SMTP id fj30-20020a056a003a1e00b0068e417ced5cmr10896980pfb.32.1696251656421; Mon, 02 Oct 2023 06:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696251656; cv=none; d=google.com; s=arc-20160816; b=T974KMZPuBUgxql+ipYxpya5webkjM5viqWgD+xjBLp19DueaWaA5a0AFnAI4BjPzi D+Zo6hSiy9HOlPU+aUVy6cQNxi5MxrWFQfHraXAXHrHKu2v6z5GpiflisvuHWQJp0cwm F1Hau6C7H20Svg08W+4So+hW8H7vc/ndUac4JA3a7TNySmT3u/T1ob6SsX7DYCWoW/4M 6mJ5LmZP2qoSHzZUReRRFZT1IAtRtLbtcuLIRol/I1L78093O/sfDBQkHbhKwyRPsqyJ eljVQa0K0HF52H/LYqtfvl6cr6pF30bPDu5HsvoElHcmdH2mTr78D9NSOtzzl8VEk3nG llQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e3Vz0tH7MeijOYhCrJMXMH52NUfYnF7z8/TCVVMfMcA=; fh=eFj9v25W9Wrh6fN+JLpeVaL0rwE8+rsOVorNY/OMc1Y=; b=Ko4ngKvNbTqSg9TSe30KlyArz5x4xF4+CrI3i7Cd02jtE+0sCwqrJD4+/7xSMvMo+f ds+Inj/1hWKJ5fzJqosm4EP0LPgjbU9Dor5bZnoo3P0M7eXSv1jr+waSsL33IScS+u7t NlQMV+6AALiKOU61D3SQCfBnro1NcVq/EKTCuLKcmRQhBRcQdrwy/cOoeywAUjdA8zPG t+rIVkKaZZdPdXE6wRbUTFBALhKdoyyBWirN9nJJluL9pTt8y80W24Jmu3r9gLncn7Ge 8VXS7LjCmVf5QTbFVnFjXw36RvcW/o28FsTL7uFz7BGU91tHDlXVOwFcpXjClAlxPZ2u wnxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UhrWedc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t23-20020a056a00139700b0069058764684si29686049pfg.367.2023.10.02.06.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:00:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UhrWedc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 16534809B755; Mon, 2 Oct 2023 02:58:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236350AbjJBJ6F (ORCPT <rfc822;pwkd43@gmail.com> + 16 others); Mon, 2 Oct 2023 05:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbjJBJ56 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 2 Oct 2023 05:57:58 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4FC8E; Mon, 2 Oct 2023 02:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e3Vz0tH7MeijOYhCrJMXMH52NUfYnF7z8/TCVVMfMcA=; b=UhrWedc2ETd6hv21kAS/H9HsLA g2p7N0GoSaVmF2VoZcVu0DN0fCKq+NB4bfZUKOaDqVnv/KZJCYGYr0+f5/UuQVwR2BmgO9oLpPwgI VEpVB8ldkn0GPnT1ROnEXA0ty2Dj0WjlrGoA9VPPJPr6CW2T+h4Ul9zOPlFVAZjPkHqA=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from <paul@xen.org>) id 1qnFgY-0000vN-5s; Mon, 02 Oct 2023 09:57:54 +0000 Received: from ec2-63-33-11-17.eu-west-1.compute.amazonaws.com ([63.33.11.17] helo=REM-PW02S00X.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <paul@xen.org>) id 1qnFgX-0000Ft-Ub; Mon, 02 Oct 2023 09:57:54 +0000 From: Paul Durrant <paul@xen.org> To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant <pdurrant@amazon.com>, David Woodhouse <dwmw@amazon.co.uk>, Sean Christopherson <seanjc@google.com>, David Woodhouse <dwmw2@infradead.org>, Paolo Bonzini <pbonzini@redhat.com> Subject: [PATCH v7 04/11] KVM: pfncache: base offset check on khva rather than gpa Date: Mon, 2 Oct 2023 09:57:33 +0000 Message-Id: <20231002095740.1472907-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778648776664353189 X-GMAIL-MSGID: 1778648776664353189 |
Series |
KVM: xen: update shared_info and vcpu_info handling
|
|
Commit Message
Paul Durrant
Oct. 2, 2023, 9:57 a.m. UTC
From: Paul Durrant <pdurrant@amazon.com> After a subsequent patch, the gpa may not always be set whereas khva will (as long as the cache valid flag is also set). No functional change intended. Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> --- Cc: Sean Christopherson <seanjc@google.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Paolo Bonzini <pbonzini@redhat.com> --- virt/kvm/pfncache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Comments
On Mon, Oct 02, 2023, Paul Durrant wrote: > From: Paul Durrant <pdurrant@amazon.com> > > After a subsequent patch, the gpa may not always be set whereas khva will > (as long as the cache valid flag is also set). This holds true only because there are no users of KVM_GUEST_USES_PFN, and because hva_to_pfn_retry() rather oddly adds the offset to a NULL khva. I think it's time to admit using this to map PFNs into the guest is a bad idea and rip out KVM_GUEST_USES_PFN before fully relying on khva. https://lore.kernel.org/all/ZQiR8IpqOZrOpzHC@google.com
On 31/10/2023 23:40, Sean Christopherson wrote: > On Mon, Oct 02, 2023, Paul Durrant wrote: >> From: Paul Durrant <pdurrant@amazon.com> >> >> After a subsequent patch, the gpa may not always be set whereas khva will >> (as long as the cache valid flag is also set). > > This holds true only because there are no users of KVM_GUEST_USES_PFN, and > because hva_to_pfn_retry() rather oddly adds the offset to a NULL khva. > > I think it's time to admit using this to map PFNs into the guest is a bad idea > and rip out KVM_GUEST_USES_PFN before fully relying on khva. > > https://lore.kernel.org/all/ZQiR8IpqOZrOpzHC@google.com Is this something you want me to fix? Paul
On Thu, Nov 02, 2023, Paul Durrant wrote: > On 31/10/2023 23:40, Sean Christopherson wrote: > > On Mon, Oct 02, 2023, Paul Durrant wrote: > > > From: Paul Durrant <pdurrant@amazon.com> > > > > > > After a subsequent patch, the gpa may not always be set whereas khva will > > > (as long as the cache valid flag is also set). > > > > This holds true only because there are no users of KVM_GUEST_USES_PFN, and > > because hva_to_pfn_retry() rather oddly adds the offset to a NULL khva. > > > > I think it's time to admit using this to map PFNs into the guest is a bad idea > > and rip out KVM_GUEST_USES_PFN before fully relying on khva. > > > > https://lore.kernel.org/all/ZQiR8IpqOZrOpzHC@google.com > > Is this something you want me to fix? Yes? I don't want to snowball your series, but I also really don't like the confusion that is introduced by relying on khva while KVM_GUEST_USES_PFN is still a thing. Can you give it a shot, and then holler if it's a bigger mess than I'm anticipating? I'm assuming/hoping it's a relatively small, one-off patch, but I haven't actually dug through in-depth to figure out what all needs to change.
diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 17afbb464a70..37bcb4399780 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -83,15 +83,18 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len) if (!gpc->active) return false; - if ((gpc->gpa & ~PAGE_MASK) + len > PAGE_SIZE) + if (gpc->generation != slots->generation) return false; - if (gpc->generation != slots->generation || kvm_is_error_hva(gpc->uhva)) + if (kvm_is_error_hva(gpc->uhva)) return false; if (!gpc->valid) return false; + if (offset_in_page(gpc->khva) + len > PAGE_SIZE) + return false; + return true; } EXPORT_SYMBOL_GPL(kvm_gpc_check);