From patchwork Tue Nov 21 18:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 167891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp826326vqb; Tue, 21 Nov 2023 10:20:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0INJg8VtEznubFuOJ0lE4NzaPJCFVU80Z058Gfn3eV0wlkDXDVHPOcNBv0pfYX3p/Yipc X-Received: by 2002:a05:6a00:4c0f:b0:6cb:901a:874d with SMTP id ea15-20020a056a004c0f00b006cb901a874dmr9135757pfb.10.1700590843786; Tue, 21 Nov 2023 10:20:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700590843; cv=none; d=google.com; s=arc-20160816; b=chDRxLvP54pQJqBEtKxv5u1SUQOMP425ThdgkHnEfca/weAfQq+KpgvYJ44G5+4UH7 yMs18TLHYNMDTKDoJAkW+X2LA9GoJRlkFlTZhbWgXXBN4jDCeyPj31TtqhQl7+g3iWSu Q76zKX3pE5FbkP2Y4tOi7eDlCGJFgdBb47JgqqQNpOP36pw3kFypPSEwRmcUAedEo17o V025mTJ6MqRuVWCIodPAyJ7EHEO3d1HmBVW9f7JlLtr8aDp5R87ZY4+ht6BPIR3RdmSv YVpigFXxKle3IDBUf2lJS0k/EC4qynGNvhUUAEsYtdn6IbI2xaimotsA3FqtEzAreRci vnDg== 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 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t187-20020a632dc4000000b005852a35aff4si10829366pgt.227.2023.11.21.10.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:20:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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 2620:137:e000::3:7 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 04D7C80ECF17; Tue, 21 Nov 2023 10:03:56 -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 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:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783198744734450931 X-GMAIL-MSGID: 1783198744734450931 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;