From patchwork Tue Sep 19 13:41:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 142060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3612297vqi; Tue, 19 Sep 2023 12:00:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXyYkISuncHthibcA49SgYHDALXaokH+6y58ACobsyoxnwcuXaC6pZ7tJ8t8u842e+Fv4p X-Received: by 2002:a05:6a00:a06:b0:690:d2de:14cc with SMTP id p6-20020a056a000a0600b00690d2de14ccmr654704pfh.33.1695150023605; Tue, 19 Sep 2023 12:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695150023; cv=none; d=google.com; s=arc-20160816; b=VmEZ71lnNzG9d/WVK1n3NGgKE4dRVBUILsb4I/tzObzruGkBcvqvh9m7y1kPjWScWb 7uhFvodD+xXZ0Dm3KLysKE9whABDP1JF+EtkY5MB6PauJCFA8QbqTCdpXxClnKVaBYlP fe2wViYudIqNQjNJrKflOwstTA+pEmMB9srFJJeD1kFbOy+3nz8QpZBXwDV17xTdSsSX 3AbUh9HzRlaCdRzz5QBUqAYHD9Eku89i01hoj0cVqs+JImoO1L1JIF3hRjsYLu6YvdEC O9i6is74IXdOmOQppH19fWhE5JQ8FfGZ5SBkrbMW/7vy3quY9oltb7y98FwV1BAl7htV ImIQ== 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=neSgbLsrLVu+d568g2rc+Zl1Dtx0QnTTpn1XRtzsBWS+6HcuA8KgjA4muU6oaw/3XL p5qjusPZEH4kDMhxGK29YuWT9dAp+qQO8LMqOHwSf6YJFchaMAfcFOg5vZnxOZv7NTu7 Do9CcEDrVRgtJNcGw/pt8CGupeZDAuahVhlb2qdy+PVJwtP/IYuqSfoUeNL+D4LPnTU8 Iq+gG5YcoXmrnQb23m3FkdPCVlhtAnjP76tQ6RcAdpjwcLIGIX0OXXL+klo98F/NYB7e U5a5Nxch5LZwBYrVodZogrmmso4fE2FDUqNKEkOEozyziH3ksVvOs74tvQLoRHxG3tm6 Y9EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=aWT9IHJh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id bx15-20020a056a00428f00b0068c7033a5f5si9901329pfb.74.2023.09.19.12.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 12:00:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=aWT9IHJh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 24E41801F987; Tue, 19 Sep 2023 06:42:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232453AbjISNmM (ORCPT + 26 others); Tue, 19 Sep 2023 09:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232377AbjISNmJ (ORCPT ); Tue, 19 Sep 2023 09:42:09 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F0EFF3; Tue, 19 Sep 2023 06:42:02 -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=aWT9IHJhCl/h+j2wnakCkd0VzX DuQ+I07TZFr/DZuSUACvpJVz82ADyWnjUciZGAm0o11UDBlhQLEp2mESd2V2RoQVegZAf37UM1NkN tG8+jhSV0ISQBHRk2ezSU2BOa9/nFXs4T1uuFkvIwwSkTVUHeMf3uEhg+cMIV008Dkgk=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiazJ-00045n-6I; Tue, 19 Sep 2023 13:42:01 +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 ) id 1qiazI-0005jy-Up; Tue, 19 Sep 2023 13:42:01 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , David Woodhouse , Paolo Bonzini Subject: [PATCH v4 04/13] KVM: pfncache: base offset check on khva rather than gpa Date: Tue, 19 Sep 2023 13:41:40 +0000 Message-Id: <20230919134149.6091-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230919134149.6091-1-paul@xen.org> References: <20230919134149.6091-1-paul@xen.org> MIME-Version: 1.0 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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 19 Sep 2023 06:42:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777493631046321338 X-GMAIL-MSGID: 1777493631046321338 From: Paul Durrant 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 Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: David Woodhouse Cc: Paolo Bonzini --- virt/kvm/pfncache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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);