From nobody Tue Dec 30 01:50:08 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6839C61D97 for ; Wed, 22 Nov 2023 12:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344134AbjKVMUx (ORCPT ); Wed, 22 Nov 2023 07:20:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344121AbjKVMUT (ORCPT ); Wed, 22 Nov 2023 07:20:19 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9EEE7; Wed, 22 Nov 2023 04:19:42 -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=iyqOFrP3aGKoiCQ7WXZlsE4e+dflFfzsWYBVMlCow44=; b=5N4xUauPpW883nolRPymF7AuKZ eXSWlBPDaYPOFxdH7ZoApo368zGveZsaG3ED+LW/nhPXvDuUsipeAVvwAh8Sa2cFCL2DsuGvcxw41 AolsrjAQk6TX1wVPRzoeQVbhHrjtM59CbzhXrGoRuXPq5B9gWqD8oOuNw7fLadN9fLdE=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5mCY-0004xq-Uo; Wed, 22 Nov 2023 12:19:30 +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 1r5mCY-0004y9-Lx; Wed, 22 Nov 2023 12:19:30 +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 v9 06/15] KVM: pfncache: stop open-coding offset_in_page() Date: Wed, 22 Nov 2023 12:18:13 +0000 Message-Id: <20231122121822.1042-7-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231122121822.1042-1-paul@xen.org> References: <20231122121822.1042-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: David Woodhouse --- 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; =20 - if ((gpc->gpa & ~PAGE_MASK) + len > PAGE_SIZE) + if (offset_in_page(gpc->gpa) + len > PAGE_SIZE) return false; =20 if (gpc->generation !=3D slots->generation || kvm_is_error_hva(gpc->uhva)) @@ -192,7 +192,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cac= he *gpc) =20 gpc->valid =3D true; gpc->pfn =3D new_pfn; - gpc->khva =3D new_khva + (gpc->gpa & ~PAGE_MASK); + gpc->khva =3D new_khva + offset_in_page(gpc->gpa); =20 /* * 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 *g= pc, gpa_t gpa, unsigned long len) { struct kvm_memslots *slots =3D kvm_memslots(gpc->kvm); - unsigned long page_offset =3D gpa & ~PAGE_MASK; + unsigned long page_offset =3D offset_in_page(gpa); bool unmap_old =3D false; unsigned long old_uhva; kvm_pfn_t old_pfn; --=20 2.39.2