Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp666807rdh; Wed, 14 Feb 2024 08:03:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXulnb4Qo1lhS5Pbb7ZJGivZPY4Ii7rMox1MtS4HU85TJwH0EQUP2zcGduZohC0XGiuI4SH6+3MTzQbVUzIsUpt8j8OstG5xHWnn64Smg== X-Google-Smtp-Source: AGHT+IG+Re9qnsjTD6CJdUne4kp6WfXCJL0WgCKmDi/PwJUR4RiMPj9mX5lQA4xEZsC22U2XoTs7 X-Received: by 2002:a05:620a:28c3:b0:787:3304:ce26 with SMTP id l3-20020a05620a28c300b007873304ce26mr207470qkp.70.1707926581195; Wed, 14 Feb 2024 08:03:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707926581; cv=pass; d=google.com; s=arc-20160816; b=msySrqiPqELSocp6A9Es4cog+xWPdH6g6eF4nrQ1V2A4Pw+PCkQ9CcPKrclKe5KSuX kPx4AXQBpeqbUhwebSHpfGezHRdlL3pE9B9CoMmB4spQ9uGLOVK6DFbYioqDcr6IE+C5 cMYKeUBWDsoZKv2Qr8YQIMrkOc54gJiIUEju1f++OI+TXRZAeGKEIRAd+sL03a4t9oHm GtKOFT8PuZqbGnNuMqvJ6PXM43uqeH5P/nbo+qkokxL+bCFgCwF0RM/vJnKj52SLH3NS evd1dQRByzuDMPEWw8OSQingXh0Ndra2yNJ+y5rLR111nMvYCUaoB/E69dR8DPdPBZvQ CLUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=vDhKhdgpExvnvihe9iHfOSKknaCWEhikPiTvyAPPe10=; fh=dOB0keBsClkherW2bHiYFTwEqBFdfJm5ixPRnxan0KI=; b=UrlBl+eQJcVuBIiOENX/nHeW9uO2KyIs3/YzcvKR+glLP16D3n3PuyO5EMbAeUv+TK vwD31Jq0kjA5+bZ3pALXN5oQj2ukjCP/Ox/8sqWPhWvhHDSuTaXKjQN8kBAPKgFAWbZ2 A/8jsUowzup8DfobJca9hN+q1qAiIlaUZI7V8oa5hoGuBZluyFUJQzRNM7LYkm+COe62 oIxwBbdWiHpvTXPl8kP0dEoao/jij2CtYGqd1UjHir6m/MdeDC9a+XI29UlQ2oYf/tyn faJv6vWb++NoXwbZ9Bovj3tDP8h3iYPJ/lL6+bPMm1Uc3G/EVKw1STrl5k66+q5QjI+V Hblg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="QAk/HqLg"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-65474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCU9hjItqAiiUfzS3OXmwdYXgHz4LUBar42ZDZB3OnQYDWz5dwgJwGiXPhMd6wxlczkFMVyBwj6OU3F/PVl81NVKQnyTJrSE21xz4lLckQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6-20020a05620a04c600b0078727078f30si2363258qks.408.2024.02.14.08.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:03:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="QAk/HqLg"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-65474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 465311C28253 for ; Wed, 14 Feb 2024 16:01:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DF195F54E; Wed, 14 Feb 2024 16:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QAk/HqLg" Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 222195D918 for ; Wed, 14 Feb 2024 16:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707926494; cv=none; b=m2gY6yRcImqjJG4yEgx7Q3XPCIgYWmWoA37nkKbao2AUPAPZzzgVldyrQldt78Rvom6ZQ4zvwQwQBGjl6xWRgGCdK9aPyXTlR9gcPdolDRyxsnDSedjjtBk346d0R37DNrvXMCxpmyP0oQKok0PJiiqlu4YdFtGGe6uhQJT8c7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707926494; c=relaxed/simple; bh=mG2aiDwQBefPaMNK+Pn14SJya/ggnAhZnM5ZfZrJYyQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m2SaYLHe6LTYGF+m6NAox64G8Vm3Rbj+wrjtR3Tce0m/k/cCVo0JJxLyejqpnzo9PLXxylSlOlpuWEhD6QlpTuCvn3+qvz+4s8yxdsID9mnt2/uElwK7r7bwcYVFwGODI4lPfxYHL6d8lyHlrm1CbETtCiWv5yOjSROdaQDkZOg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QAk/HqLg; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1d950445c0bso66990395ad.2 for ; Wed, 14 Feb 2024 08:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707926492; x=1708531292; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=vDhKhdgpExvnvihe9iHfOSKknaCWEhikPiTvyAPPe10=; b=QAk/HqLgYjvy6Jd8ZrrIpX6BQReMTR4BJ8VfS2KyGocywH12mm9VdOhAw2qDL75zrB INDry1X9/zQMf/DG3o8l1hIO1MW4M5Gleiv3DQsvUVg+MTsoft9wvAN/sY1iZIpgtGbB 95pjxJWCoVYDFlRjblZsJGDfI2iQb/lb7KKQMcOzp2obWq5n7sul+XXos3e4ttoWhynb LvyPWLC6SWMEanMLdRIIq6v65kWPKhHWWoC8rsx/cgFh0k83Nskf5/0YBLDeTlLlbFU/ pobeXxvQKcElKVjofGXavU2MLDzIuTFNV7NwBi7YA8n23gjqZcQbzrkqT+ohGlAGfVWw whLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707926492; x=1708531292; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=vDhKhdgpExvnvihe9iHfOSKknaCWEhikPiTvyAPPe10=; b=aKaQpd5Ht8R3jDXZnUkNQ2Yaxe/ZxgfhMwQ+Z8jQ1wB3iRGENH7Li8DZwNQwrqdqrC O3CV/EL6MOzAdXngl/zrE3MVwgRMV+GjEd3xOS+gXAJuq9a3zuGnFQyesgZzOdoLCgE1 cn3vOCRifIBjdlaRNipJoaKvYtCQF36jqgCzZaB4MkKu6WDtfPZt4UatUA6NoscqoDP1 PHGITUfVKST/KtlJYqkjc5jQa0OQ7FHVfAZYR8r0OvSfTqYnHHiKykP/wlQVQED/28ip UKvPYvkaCiH+H4CYlZV8jhbwyqZKXAW2blWWLMp5xHRUB6sxhJnOJC/GVgSkpVGhguil gwag== X-Forwarded-Encrypted: i=1; AJvYcCWFdZ98tDHOTWUs9QC0T5JmJD5u6dCrm1n9q7kOP+WRkKlqr6sF7tzP5I0U7LgbgF9e85VbiiF+NTHPnsVlpf1DUoBk8kwaIWr26s16 X-Gm-Message-State: AOJu0Yx8rUnzVua1c0W26jWdu+zuXfgZZDUZEMR5EZFnEIpxrAEI+15X JLsbxJkkS7KX8GrUyccFgOMFNFkwEguxTj6Y9/42t0uHUVhOGNsAjvECNV7U+Ukza54ZiIC5lYX XvQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:b90a:b0:1d9:f334:d9c5 with SMTP id bf10-20020a170902b90a00b001d9f334d9c5mr8303plb.10.1707926492284; Wed, 14 Feb 2024 08:01:32 -0800 (PST) Date: Wed, 14 Feb 2024 08:01:30 -0800 In-Reply-To: <7c31e31d0f0ad3f40619f8e0ecf67f1e3d3eef5f.camel@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240115125707.1183-1-paul@xen.org> <20240115125707.1183-9-paul@xen.org> <7c31e31d0f0ad3f40619f8e0ecf67f1e3d3eef5f.camel@infradead.org> Message-ID: Subject: Re: [PATCH v12 08/20] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA From: Sean Christopherson To: David Woodhouse Cc: Paul Durrant , Paolo Bonzini , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Shuah Khan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 06, 2024, David Woodhouse wrote: > On Tue, 2024-02-06 at 20:03 -0800, Sean Christopherson wrote: > > +s390 folks (question on kvm_is_error_gpa() for ya) > >=20 > > On Mon, Jan 15, 2024, Paul Durrant wrote: > > > @@ -1398,7 +1414,9 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache= *gpc); > > > =C2=A0 static inline void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache = *gpc) > > > =C2=A0 { > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0lockdep_assert_held(&= gpc->lock); > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0mark_page_dirty_in_slot(gp= c->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (gpc->gpa !=3D KVM_XEN_= INVALID_GPA) > >=20 > > KVM_XEN_INVALID_GPA absolutely doesn't belong in common code.=C2=A0 Not= to mention > > that it will break when Paolo (rightly) moves it to an x86 header. > >=20 > > https://lore.kernel.org/all/20240131233056.10845-3-pbonzini@redhat.com >=20 > We can use plain INVALID_GPA for that, I think. ISTR the reason we have > a separate KVM_XEN_INVALID_GPA is because that's a userspace API. >=20 > ... >=20 > > But! kvm_is_error_gpa() already exists, and it very, very sneakily > > does a memslot lookup and checks for a valid HVA. >=20 > Hm, that doesn't sound as fast as simple comparison. We also can't do > it from kvm_gpc_check(), can we? You snipped the part where I suggested renaming the existing kvm_is_error_g= pa(). I am suggesting we do the below (and obviously rename the s390 usage, too),= and then the gpc code can use use kvm_is_error_gpa(). diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index bbfefd7e612f..e1df988e4d57 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -148,6 +148,11 @@ static inline bool kvm_is_error_hva(unsigned long addr= ) =20 #endif =20 +static inline bool kvm_is_error_gpa(gpa_t gpa) +{ + return gpa =3D=3D INVALID_GPA; +} + #define KVM_ERR_PTR_BAD_PAGE (ERR_PTR(-ENOENT)) =20 static inline bool is_error_page(struct page *page) @@ -1787,7 +1792,7 @@ static inline hpa_t pfn_to_hpa(kvm_pfn_t pfn) return (hpa_t)pfn << PAGE_SHIFT; } =20 -static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa) +static inline bool kvm_gpa_is_in_memslot(struct kvm *kvm, gpa_t gpa) { unsigned long hva =3D gfn_to_hva(kvm, gpa_to_gfn(gpa)); =20