Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp962773rdf; Wed, 22 Nov 2023 01:31:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNoeGhveZgd/+NWrmdCNvf4CK061Rfdm/mXaSYQ4zL30c9Ud5PI505m1FfBH4WlIrarKyj X-Received: by 2002:a05:6a20:3ca2:b0:188:40a5:f7d4 with SMTP id b34-20020a056a203ca200b0018840a5f7d4mr1557174pzj.47.1700645512967; Wed, 22 Nov 2023 01:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700645512; cv=none; d=google.com; s=arc-20160816; b=E5ddYT2nBqx2rYSMMqs27NUdkFFWc3VUU6ltNYWKNNuwNXAqAHptoN8sN0OO+SKuty PZOD0jC1fZjZFdHrzdDr5fhZ+bgqRmC8l3g0BY2WxHfKAVsHiqB9M7FyLDteY8O5MNZW c1WFkHlm/FcyM74Uxs+vtK4DGo56wX9dJZaSarrJA+rt3GAi8lirI4Tuze1IW2Qlye2m YIwIQDSdbCbb32gPYGXgloSk8HSOgAGI9Us1B812aT1rtFN+IjQlshdHhF3mpJHo2osA mrfE6yrB3Mp/TGXMLn+lmjaMyUtpfmWt6/xfngHtuAYDe3/VVcrTZVZzDZA+vdfHrYLF /oDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:references:to:content-language:subject:reply-to :user-agent:mime-version:date:message-id:from:dkim-signature; bh=/Y7pziT/im3f9dxtYQCJMHC7zXrzbkMaL6w7pi5WdK0=; fh=1kot/E5G32+jyKnfvYn77eM9gm4irioNETK7mqQrhes=; b=UTouqnpoYq3bnTVQjZwEY5aMMYZZ8XZ8s5HzWVbsGxmqVwSlVOLUhhyMBvenmmDqhL /KarCIg45F9777ogDAyUfJZEI4D95VDSe/dkqF2bDW2YsQb5u8/LRaLdjJ22Y4AN8lS5 LkV7SeZxiceR39j7e8Y1KV6ZRCG37dOnoRw2qcmHSvGtnxMrHfLySwuQcNPsbGYt1Sdb yoeR+ofO+7I9ucUfpfHNYEUt5AnzLcHZ7Hc0RIkFYOvcNl0H7SqtHnusHqo4aoARn9Po tysbBeX70CX3RSIjzQEp9xrjhJmhCX+deSMoWBiVX6CGItnRTKpkftL9RGV7wwWLPtcH D/GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gXA9XZLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id c11-20020a170902aa4b00b001c5fc13fb2dsi11593739plr.294.2023.11.22.01.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gXA9XZLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 8EB248068A03; Wed, 22 Nov 2023 01:30:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235213AbjKVJaI (ORCPT + 99 others); Wed, 22 Nov 2023 04:30:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235243AbjKVJ35 (ORCPT ); Wed, 22 Nov 2023 04:29:57 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36B41BC; Wed, 22 Nov 2023 01:29:49 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-332cc1f176bso1534251f8f.2; Wed, 22 Nov 2023 01:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700645388; x=1701250188; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:references:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:from:from:to:cc:subject:date:message-id:reply-to; bh=/Y7pziT/im3f9dxtYQCJMHC7zXrzbkMaL6w7pi5WdK0=; b=gXA9XZLE7XQqIQxgVi4GVH7tXRyNgxW+IHwQHBWJKkVgEsO31wGqBX3Y5aGtp8vDLS gOGS33ZCI0cwbTAvgZ9RfYryfaemYECXM0EO8RgnHbN70YosedY9dTclv9Dc6FrZjLmJ vjaLI4SnhCGfR8JVf3kpoJ9Qlo/qGsLeX13XOPRZQkC+9NFfwSl1HX8QYzPNPHX75hrT AFTMc/PZUfmdGJ2hfFE6JFrddBJl/gn2yCyaBX4ZQcUzfSFcOystgjHZk1nRCvwg005u Q2sH8cFAGcnjyBlPQMEE/7s7yQIY8MHzaWGpW3zVpCXos20Pca1S2q4nZ2KUfXkIMH5J g7mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700645388; x=1701250188; h=content-transfer-encoding:in-reply-to:organization:references:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/Y7pziT/im3f9dxtYQCJMHC7zXrzbkMaL6w7pi5WdK0=; b=qtWyXh8ldX3Gole7RqVKcioFveYXgy84eMNMdajO/AfGDXErEVKhVOVVDXI8HEyuPp SlNZf/GetGjSMzvZoxs+XJkCiQshg0yC/mcYmqKASwwjxQBiOm7ZnmiJlxGBb8nVcVEt W85dAGX363B+nhT0UCVKWXhgzk7TNRRpoDA6plZAxEHLTURbfk8ll6/KzNIOmWIRAgqV kMyeVKSDqO+crMDYlZ5F39W4mpAG0o/+LDmeVicI5HFH8gy234bZcU644QnElBqNiI82 UMJ6xWcW/gCeYMjZQsl4pi+rkCxNpfUYlCY48CUgNa7/FHIpN1CQylEAumoUpQURnCnd 0ldA== X-Gm-Message-State: AOJu0YykFKiQUFx4IF0esdq5T/egZYzI68DUDwx2cCJt+aKzHYRGuhky YQyeDFXsFO6BLIua8rFO3Gw= X-Received: by 2002:a5d:5c0c:0:b0:32d:9a17:2a72 with SMTP id cc12-20020a5d5c0c000000b0032d9a172a72mr1724308wrb.55.1700645387853; Wed, 22 Nov 2023 01:29:47 -0800 (PST) Received: from [10.95.134.92] (54-240-197-234.amazon.com. [54.240.197.234]) by smtp.gmail.com with ESMTPSA id m3-20020adffa03000000b00323293bd023sm16628792wrr.6.2023.11.22.01.29.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 01:29:47 -0800 (PST) From: Paul Durrant X-Google-Original-From: Paul Durrant Message-ID: <04530097-a3b2-4acf-bf41-fba48143d4e1@xen.org> Date: Wed, 22 Nov 2023 09:29:46 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: paul@xen.org Subject: Re: [PATCH v8 07/15] KVM: pfncache: include page offset in uhva and use it consistently Content-Language: en-US To: David Woodhouse , 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 References: <20231121180223.12484-1-paul@xen.org> <20231121180223.12484-8-paul@xen.org> <5ffdf3ab49b047cd851289e5dc0697af0ffff45f.camel@infradead.org> Organization: Xen Project In-Reply-To: <5ffdf3ab49b047cd851289e5dc0697af0ffff45f.camel@infradead.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 22 Nov 2023 01:30:45 -0800 (PST) On 21/11/2023 22:35, David Woodhouse wrote: > On Tue, 2023-11-21 at 18:02 +0000, Paul Durrant wrote: >> @@ -242,8 +242,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, >>         } >> >>         old_pfn = gpc->pfn; >> -       old_khva = gpc->khva - offset_in_page(gpc->khva); >> -       old_uhva = gpc->uhva; >> +       old_khva = (void *)PAGE_ALIGN_DOWN((uintptr_t)gpc->khva); >> >>         /* If the userspace HVA is invalid, refresh that first */ >>         if (gpc->gpa != gpa || gpc->generation != slots->generation || >> @@ -259,13 +258,25 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, >>                         ret = -EFAULT; >>                         goto out; >>                 } > > > There's a subtle behaviour change here, isn't there? I'd *really* like > you do say 'No functional change intended' where that is true, and then > the absence of that sentence in this one would be meaningful. > > You are now calling hva_to_pfn_retry() even when the uhva page hasn't > changed. Which is harmless and probably not important, but IIUC fixable > by the addition of: > > + if (gpc->uhva != PAGE_ALIGN_DOWN(old_uhva)) True; I can keep that optimization and then I will indeed add 'no functional change'... Didn't seem worth it at the time, but no harm. >> +               hva_change = true; >> +       } else { >> +               /* >> +                * No need to do any re-mapping if the only thing that has >> +                * changed is the page offset. Just page align it to allow the >> +                * new offset to be added in. >> +                */ >> +               gpc->uhva = PAGE_ALIGN_DOWN(gpc->uhva); >>         } >> >> +       /* Note: the offset must be correct before calling hva_to_pfn_retry() */ >> +       gpc->uhva += page_offset; >> + >>         /* >>          * If the userspace HVA changed or the PFN was already invalid, >>          * drop the lock and do the HVA to PFN lookup again. >>          */ >> -       if (!gpc->valid || old_uhva != gpc->uhva) { >> +       if (!gpc->valid || hva_change) { >>                 ret = hva_to_pfn_retry(gpc); >>         } else { >>                 /* >> -- > > But I don't really think it's that important if you can come up with a > coherent justification for the change and note it in the commit > message. So either way: > > Reviewed-by: David Woodhouse Thanks, Paul