From patchwork Wed Nov 22 12:18:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 168333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1280968vqb; Wed, 22 Nov 2023 04:23:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcV7CqEWZJsn5d5jA7f6XFmUd9Nx2D4gEayNDn/hNFaO/8DtU8OHtFBoJispW8ApKsLanD X-Received: by 2002:a05:6a00:421a:b0:6cb:bb61:5686 with SMTP id cd26-20020a056a00421a00b006cbbb615686mr1935851pfb.31.1700655791385; Wed, 22 Nov 2023 04:23:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700655791; cv=none; d=google.com; s=arc-20160816; b=Abw2c94Cv+L8kfFvkdF00z8bh9enCPWbsVPieqHUcl6qYsk312E73+cX5waSx17mMM V6JcMHMB2Y6wkXa7IC2VlTCfgBq3+Uq8UQiEP1xuRZYuIz+Le8EkyneTKpocFtOcgOgw +6w4ybL7vA8xM+G45kp+wLaxNwALb4B4nCvCkHM9F3ldFPALfRpI1GAYQtv4QHwgGQ9t lMmDlXgrdIyLKqEYx55GewWc8sxf39Srd/4V2rXKgh8B1C4f4w/Yee8BN76ZT5lmPQ+w RoYlgLim0Kcf3btplWaxJyEib0ziB6PJ1mP642nztZ/gEOHKBmOnE4Ea18Poe+LdK49v RWPg== 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=iyqOFrP3aGKoiCQ7WXZlsE4e+dflFfzsWYBVMlCow44=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=N29C30Z5qvmOm7iMqdfO80h7bV1wL0t2CWyNQmgtVIrSFDVrOf2L1CzcruX0KXZx6T cAYvU/3T3Vo9cvEezLSwTor7e4g5yzjGuxenzqIcpAT3OUio8YUJZ2jMrP87COdORV6k vX0AwUKhBOaPrrLYeZA0tbfbRx2TsD9Cdg/g4XVF59wRcsAMTQTJlCNu/hO90WS3Dz5G eTMe8c5lsyTmLkoVQRQ6Tn3f1mw2HhO2QA0EdfpEzJPK2pcv4u/2Nvo9wB1DDvIwbdoi LMKiENSgLBIUtCVdvzrsWQel8FXHXW3tJjGEFGvHQ6p+mwD3jyq0Nesl387niwu1c0Li wGRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=5N4xUauP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id y5-20020a633205000000b005bdbda280c2si12581860pgy.364.2023.11.22.04.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:23:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=5N4xUauP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id DB49781C3D6C; Wed, 22 Nov 2023 04:22:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344190AbjKVMUv (ORCPT + 99 others); Wed, 22 Nov 2023 07:20:51 -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 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 04:22:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783266847041618693 X-GMAIL-MSGID: 1783266847041618693 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; - 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;