Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp586705rdf; Tue, 21 Nov 2023 10:23:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR3OKsFjlKgjxr7oRngU0xCxRMNlxd92IOqbG8XBA8SDpI56F8UWUiAJaf/wzbS7T0Ss2x X-Received: by 2002:a05:6a20:938c:b0:187:c8ca:75ad with SMTP id x12-20020a056a20938c00b00187c8ca75admr13788555pzh.31.1700590995854; Tue, 21 Nov 2023 10:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700590995; cv=none; d=google.com; s=arc-20160816; b=lY2nzN6D1zqG1KYdEJZFW2MPbLbBy7uWSHvBlbs6Nm04GLFsiyyfWIiomMw3Jepjs2 Ij7HizYfyc/iEavXkhZMfAK24HemMThWdMvY/+XGg94Flvr2HjdIjYrV8gAiEdYcnQ7f mHy6vDUcYj5f/KiOPyUL1y8xAj1f1AHFrvbrZc9SjJVAB4SQt7gjqrcIL+UFgFJjkeyI vfQFZxL1lI9yjxcZVayubR21DxlxQEzfhBmufmOdKK1/Imt5GbVXvhMW0vkCJOiep4Ig 8ExTHCMJni4sLNuO/Ihy9ooe99e52fzI+8UR3cYKCE75WKh9WjbJ7oQ9kxJl5/Lar/xM zE9w== 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:to:from :dkim-signature; bh=2v/tw5EmDGH5J/Vx7JjTudqum/NVLjEHFKfFueUTsWw=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=f3sP6ohK6aoH4ftLr1wPwlxOlaYgvhpK2pRwtCHK4GCsHY2c3q2jQ8Uec9p7KNcIKO 2GGGk/+iw9MrGYt9DgEtkjbX2LGLDy67eUdzrpUdK+dsBJOOi0Bujf8B8GmUY1NkWY8A hDmQJGMUmaHwTIGvXwCKhU/0UHlZwWAl0rIUdsYa9GMOafLn+AUUOMJMEh7UW7g5TEl1 xm2Xqa5JoeGuZx2zdo4rQs+mZ84WtlbUXsT9tBbKb3RKNC6TtoR0OVNj4PBRhP11IEvY yYSf8yYblvmanqKh4dOWOemgLPnaq4FOqkGWLBwTI0cdztJvbq/HrLoBu28FfDLwh8Fp YxYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=3ocrm837; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s18-20020a632c12000000b00578c64433c9si10607626pgs.894.2023.11.21.10.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=3ocrm837; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 995A5801B730; Tue, 21 Nov 2023 10:03:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234462AbjKUSDl (ORCPT + 99 others); Tue, 21 Nov 2023 13:03:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234351AbjKUSDa (ORCPT ); Tue, 21 Nov 2023 13:03:30 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA7DDD49; Tue, 21 Nov 2023 10:03:25 -0800 (PST) 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:To:From; bh=2v/tw5EmDGH5J/Vx7JjTudqum/NVLjEHFKfFueUTsWw=; b=3ocrm837Jdo6pOm3T5lMA+wXZS kI9p1KCrvzVMuubDI778O57+mTvMUUBNScU2cHTxxq7j8XaSK/y1eZryIEWNhcaVHN6EhpA9JE0F5 gnWQg5u6kQbIf3WePSxjW21+Q6j1CdLiupjSnnZ+Y2UESQluvZn6592zVED3mjVDlkfs=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5V5e-00084u-3E; Tue, 21 Nov 2023 18:03:14 +0000 Received: from 54-240-197-231.amazon.com ([54.240.197.231] 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 1r5V5d-0004Z3-Qr; Tue, 21 Nov 2023 18:03:14 +0000 From: Paul Durrant To: David Woodhouse , Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 06/15] KVM: pfncache: stop open-coding offset_in_page() Date: Tue, 21 Nov 2023 18:02:14 +0000 Message-Id: <20231121180223.12484-7-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231121180223.12484-1-paul@xen.org> References: <20231121180223.12484-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 10:03:57 -0800 (PST) From: Paul Durrant Some code in pfncache uses offset_in_page() but in other places it is open- coded. Use offset_in_page() consistently everywhere. Signed-off-by: Paul Durrant --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v8: - New in this version. --- virt/kvm/pfncache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 6f4b537eb25b..0eeb034d0674 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -48,7 +48,7 @@ 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 (offset_in_page(gpc->gpa) + len > PAGE_SIZE) return false; if (gpc->generation != slots->generation || kvm_is_error_hva(gpc->uhva)) @@ -192,7 +192,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) gpc->valid = true; gpc->pfn = new_pfn; - gpc->khva = new_khva + (gpc->gpa & ~PAGE_MASK); + gpc->khva = new_khva + offset_in_page(gpc->gpa); /* * Put the reference to the _new_ pfn. The pfn is now tracked by the @@ -213,7 +213,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) { struct kvm_memslots *slots = kvm_memslots(gpc->kvm); - unsigned long page_offset = gpa & ~PAGE_MASK; + unsigned long page_offset = offset_in_page(gpa); bool unmap_old = false; unsigned long old_uhva; kvm_pfn_t old_pfn; -- 2.39.2