From patchwork Tue Dec 19 16:10:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 181071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2050573dyi; Tue, 19 Dec 2023 08:16:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuGRO6PpuhR45uHliACIHEgM2PdVXa9qS0+cWHpsENV+8d/UmPWmAgHjcoBQiBPgoppcTQ X-Received: by 2002:a05:6a20:d41f:b0:186:ff2d:f964 with SMTP id il31-20020a056a20d41f00b00186ff2df964mr17141383pzb.36.1703002580361; Tue, 19 Dec 2023 08:16:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703002580; cv=none; d=google.com; s=arc-20160816; b=qob+FIChUZYAcJQUYxl9uumrNHMRDHNjt4XXQvzRXce3L5wkXwSdHogQY4lQVby3xn 4oAEbS6HFFk6zlw1py3Xq/r6s40EyNXzx6jLo6EKXyeMt8uRBLGNfqT7kT9jrtY9RdSE c7UiaKXQsKKEnr+3TZ77js5o4cTcb9tsbXwHKG6oppw0E7XJosXiZSUiZCiwaQ4IvonC mx/cXwyVylZ1KEc67mkIpzzRCQhzomWu7Utp2eexwsULHVSuLrmmEbX/sImK6ageu5PB jc5wFl9mZJNLjeQCexpsVsJcaCHk/+cHiN1eQrwST2IUYb6jNAV24jYk80nPtWzvScAX wnVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=iyqOFrP3aGKoiCQ7WXZlsE4e+dflFfzsWYBVMlCow44=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=T+QgTknRO1PCqfspRMw2XLF7Rk3J+BFeFaVdrLpKwpJ7PRUs6N+ez3MZ0VrMhPoE1V BXCBDLFc9r4pwxAlkCJjbnT6G07NJr+S8b78RVTnaAHH190NwVFHBAsoaffPyNbbT04+ dAa1fh7rrJk9+6BKAcewlSJafa7SyHpMi3HFAnEzNNMfA3RRAC233rB9XEuxVY6dLTvd lq6nmFCsjUc8khFVGKFsRxyH+IP77v22rAlOVDSugayP/LU89TB22s+ytTBWCW791rEX joh/DDyyK552lcgcEfkdVZXBebg0ZSxwGA1OJhXSQSSnFWv1ivVakTpbbI+gWJkM263x NNlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=v157f0eo; spf=pass (google.com: domain of linux-kernel+bounces-5542-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5542-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c14-20020a6566ce000000b005cd896e80ebsi5098731pgw.504.2023.12.19.08.16.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:16:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5542-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=v157f0eo; spf=pass (google.com: domain of linux-kernel+bounces-5542-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5542-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2464E283678 for ; Tue, 19 Dec 2023 16:16:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CFC523778; Tue, 19 Dec 2023 16:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="v157f0eo" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D87531747; Tue, 19 Dec 2023 16:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen.org 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=v157f0eo4UPRvf4MyDGtBU1aZS ktb+3lqRS8eMjovvQAxBr3eJG6KjZ5CgwZfKF/dcUtEa8N4PJ/duZUa0v6cJinLWDKNRK+j71/m/R DX8/v0YUKP0rSm107mePYcpuOGDGUb0y6eOyYHIsv0Yy5XKgpbreGH84MpO9dWjPN80Q=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFck1-0005Ma-Bd; Tue, 19 Dec 2023 16:14:45 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] 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 1rFck1-0005h9-3B; Tue, 19 Dec 2023 16:14:45 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , Paul Durrant , Shuah Khan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v11 06/19] KVM: pfncache: stop open-coding offset_in_page() Date: Tue, 19 Dec 2023 16:10:56 +0000 Message-Id: <20231219161109.1318-7-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231219161109.1318-1-paul@xen.org> References: <20231219161109.1318-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785727633373979529 X-GMAIL-MSGID: 1785727633373979529 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;