Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp1190255rdf; Wed, 22 Nov 2023 07:53:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhb+OnGE/9lwfDWZfzVjCypucsCKQ9idaFEnjKj1rVAlC6+GXBaVOc1Xd7b2+2Q32qTm6e X-Received: by 2002:a05:6808:2908:b0:3ad:fe8d:dfae with SMTP id ev8-20020a056808290800b003adfe8ddfaemr2425494oib.57.1700668406167; Wed, 22 Nov 2023 07:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700668406; cv=none; d=google.com; s=arc-20160816; b=Y7BfMTM3hUx6eCCgD2hylbPR5HoYoTEohPD18J1zbyurK3304n8UolXLHlUJBodHuT nFpQ94IoqZD0R7oEpIQ6dtCbJchD9fJPy1UUmincoXws6mJ34+0mu30tOI5gvozbaf8t qgLR64vBDy80rL+gC7bvXW1a2GpH2NRWBJ69xnsjR0DUweOGB8KFv8yAnDaUiT/amuHH aPaTMxfqQTCt4RsbhXhG5JRBjgxCE6lPubjM2/KHDFJLxdVdEXZw9AzesXTPCfpJyEIx zZdWWAVMG2S3iRBM65XHd2QcwAE0NiDuqr9MzJmhe4eWUdmmn7nhNA8t8lBQrd0mzprg wPNw== 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:cc:to:content-language:subject:reply-to :user-agent:mime-version:date:message-id:from:dkim-signature; bh=RlnRw7VYfGh/cCRGjlDuIvXRCgYuMpmQluWY6EzpRsc=; fh=aiMizjR7xfZUf1KvvGq2W6OLZ2Eu4j/szjLgBhAV3Qg=; b=T9/mNBUhEOdtnduuvLdJGE00OAV5DOBh7F/nFAj2s7NbDfnQ4gc5oJSMss/ukXn0CM WWNdeY6muBPtUVSc6SAfH3kSs3E+7eLIhNYbybamDP8kLyKv6+T1IPOJmPEmNsE1P0Db jtwxPBkcz+aQaIaNaZonW1bXNPCMWIQEzTpE4vb69awD1AR1RV1I7fAvU3UbkXDCEsY2 Hu4lwWL4KMllaNqfbSigeB4JeNaU0P3k/AXe6bDzDJU0A3GVuB/qLzv5iu9vqUDI4RJz YLovR8F3vqjXRrDy5CqzQ4/HJC9poaM+dUZbqjeJmCPQlynhtC9m0fa7oYe/zoZaKoNO h6PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CKtrTajc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id q3-20020a631f43000000b005b82f3dcec6si1689100pgm.269.2023.11.22.07.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 07:53:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CKtrTajc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id A47CA8250DF1; Wed, 22 Nov 2023 07:53:20 -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 S234691AbjKVPxH (ORCPT + 99 others); Wed, 22 Nov 2023 10:53:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjKVPxG (ORCPT ); Wed, 22 Nov 2023 10:53:06 -0500 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC80F9A; Wed, 22 Nov 2023 07:53:02 -0800 (PST) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c887d1fb8fso35620481fa.0; Wed, 22 Nov 2023 07:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700668381; x=1701273181; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:from:from:to:cc:subject:date:message-id:reply-to; bh=RlnRw7VYfGh/cCRGjlDuIvXRCgYuMpmQluWY6EzpRsc=; b=CKtrTajcBTHMRpwYT/eNKAatl2bPV8Qa1d6EcIhA2ZvF6a+6k2Vn+LTMCcVeVpHRaO +J/xM2Ihj0ahC9zggDE+l3dDqrFZtkqtFn4ntYxq45MAoBudDLaOLfOLnR8Xf8VtrVrA hGzJc1g7tDkbYOyPbJs3nq40OgIcUZwjHsKpknzIkJPQ0kytwcIpduajyNMbZ53bdZR9 es8MhUfCZscwX5eclMF2V9ui1XWLbebsswODLr4/i2Sg+bUOx0zak6UNXH3cMYKwB6p7 k81ylnkH7Rg09B151LPZsRGjMvhUELclobyAdoawoNQhxmqCh6/L8gEaDfD+Ym7s4CrG K4FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700668381; x=1701273181; h=content-transfer-encoding:in-reply-to:organization:references:cc: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=RlnRw7VYfGh/cCRGjlDuIvXRCgYuMpmQluWY6EzpRsc=; b=v3IffwPnFKx/Dv0vLcwdVZa1BrE7wn6wIAERAwTpa8+8AwIIG0sDonAoQLBEeF/3MF nXsknDVQC2JSE8qrML61Wckz0S/L9X7gm1AdMm0T2xxD66DdbqBy5pv4kKmbjcS5yxmh mOHmaJmWuSSxAoVCP0FCWkWUBcMoftqri5fVhUTpHZvEpF/llaMgYOvUWhQ8jvucEVHs WkCcSaq98yiIv7jZvQrR78y9pZl4/RQEmzlJtXVOjjVVuLxacHQOlZ3utEXB0Sg7SugT 5uQooNA8vPRJjuNDQc6R7sBEauf0jwtQ/xZu6BmqNm9QwbwKYapGopTA3VBl4GZ78xfv ro9Q== X-Gm-Message-State: AOJu0YxnPO/EQ8p4FYqFlnxTuKNNi9InG4cVHxVETa3seeBK2iTxvQ3C Uv6Nt6z2oG0gezhjmzGEZzE= X-Received: by 2002:a2e:9b4b:0:b0:2c8:7665:adb0 with SMTP id o11-20020a2e9b4b000000b002c87665adb0mr2021685ljj.46.1700668380812; Wed, 22 Nov 2023 07:53:00 -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-20020a05600c4f4300b0040b297fce5fsm2622058wmq.10.2023.11.22.07.52.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 07:53:00 -0800 (PST) From: Paul Durrant X-Google-Original-From: Paul Durrant Message-ID: Date: Wed, 22 Nov 2023 15:52:58 +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 , Xu Yilun Cc: 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> <7a038a4c2ae4387fb366f6c2e9b1ce512f5345bc.camel@infradead.org> Organization: Xen Project In-Reply-To: <7a038a4c2ae4387fb366f6c2e9b1ce512f5345bc.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 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 07:53:20 -0800 (PST) On 22/11/2023 15:42, David Woodhouse wrote: > On Wed, 2023-11-22 at 22:27 +0800, Xu Yilun wrote: >> On Wed, Nov 22, 2023 at 09:12:18AM +0000, David Woodhouse wrote: >>> On Wed, 2023-11-22 at 16:54 +0800, Xu Yilun wrote: >>>> >>>>> @@ -259,13 +258,25 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, >>>>>                         ret = -EFAULT; >>>>>                         goto out; >>>>>                 } >>>>> + >>>>> +               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. >>>> >>>> I don't understand how the uhva('s offset) could be changed when both gpa and >>>> slot are not changed. Maybe I have no knowledge of xen, but in later >>>> patch you said your uhva would never change... >>> >>> It doesn't change on a normal refresh with kvm_gpc_refresh(), which is >>> just for revalidation after memslot changes or MMU invalidation. >>> >>> But it can change if the gpc is being reinitialized with a new address >>> (perhaps because the guest has made another hypercall to set the >>> address, etc.) >>> >>> That new address could happen to be in the *same* page as the previous >> >> In this case, the lower bits of new gpa should be different to gpc->gpa, >> so will hit "if (gpc->gpa != gpa ...)" branch. > > I think that 'if (gpc->gpa != gpa); branch is also gratuitously > refreshing when it doesn't need to; it only needs to refresh if the > *aligned* gpas don't match. > I did look at that but decided that gfn_to_hva_memslot() was sufficiently lightweight that it was not really worth optimising. > But it was like that already, so I won't heckle Paul any further :) I appreciate it! :-) Paul