Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp681785rdh; Wed, 14 Feb 2024 08:20:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWFGwhj/txi8B6LaSFzY7JFzUq7IQ/IOw53aQVNJmeAr2eI9pl7Ze12SuTGCBfPY4jMNAg2NKjpPROpDicsgMgHN7fvEToRM4rC3iHRXw== X-Google-Smtp-Source: AGHT+IEhQzZJAKf1UIiTR88XgxTVTS66M1BpYcjgCOrVJU16gcvAKDRJa+6C6cmAGF7GQMBVv1Tg X-Received: by 2002:aa7:c1d4:0:b0:560:6469:a190 with SMTP id d20-20020aa7c1d4000000b005606469a190mr2189204edp.30.1707927635912; Wed, 14 Feb 2024 08:20:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707927635; cv=pass; d=google.com; s=arc-20160816; b=dRHsoT3kC3HUf5XsLk66sbNPZkBdAldzYq5+gmxt0XyR8hOKxpd9HLzNIEv5l5pnDr XFb0tolj5HFsKzThWl5CDBfeSC7SDQLNV+qg6Hgw9IpJ/ewRi4QnZNExRxgQ9Nbn1Xkr t8EbvgerrW0bKzCXTjYMIytbxCOP81I2akCORjg/nkWkadZgIASR0ETbjG7WNaZRCT01 tvYdqTbhcbsn4fKueZUBZc8KIwN9oGGPtgSOStiVNmvdoV417DZBUQ2e+6VY1KLDiuRv qP05S0wZ42iK+LwI5zy5vEWhWPOF+ULzvmVCC0V7O7U6Qrw5vR4jucE/UoIR9x02Uu79 OO8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=Fm0rEdFpfBw8yrd8ZCjG8lJI7FOozunf2bgbBsdJdm0=; fh=V1rCbFNuHheSWrSypL1mxoHWTKv321lOxhrxlbIFEyM=; b=0x1lre78p+FDkvPZiu9EBDQPnRVpvDWl+OkPZ8cBX7cKDZI6PrI0EiuTdtP/Jv82B4 /qK58nrOrXPWYjZhYAMwzdS3QELNmAyTZjZKAChYP7DjE4cu09o6rLoz22Tr1qc0/Ook vWE9v1xaj6LShi0AG6LFHBZkI5IfjOfDqFyijlA55hZFZ001V3gz52zJb2rx3A/POpbu lrRD8Q8iTvc+GbwVmtXEMfOCYf710vwqQvR5uZBs4izLfzisKAf9jIUzLJgww1McgpCS +s7xNIju51x3oVoJkNK0QZJm4bcH1Wn6hmj/GocE1Zox3gx+D29EE35Wybs8wBDX8MnK 8mpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hb+Ua2jq; 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-65507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65507-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; AJvYcCVqMINGVMXeidHW1n0nZDqtzUo2mPilX22Vdz1JtlonMrse9WmB/o45y3bnw7/0SaySasVHhYtFcU7hB3D3nHcS6lJGoHHVzUyshKaRLQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e11-20020a056402190b00b00561fd402c8esi1660439edz.110.2024.02.14.08.20.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:20:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hb+Ua2jq; 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-65507-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65507-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 776EF1F24D4A for ; Wed, 14 Feb 2024 16:20:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7AE46026B; Wed, 14 Feb 2024 16:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hb+Ua2jq" Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 694275EE76 for ; Wed, 14 Feb 2024 16:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707927619; cv=none; b=PMiLk6vHBNr/ZT4OFcVybIva1lI72QLIVVVt2y9eNzp218y/mpP/qwjTavroSp0q53G04w3rVQNNAcIen1CDhzgSYxeMP/kaVe1SQg0xcQOmAByWpp0Jt7G23XkZKmEJYe6r5vuw5OV8bV9FYKYY6+hV2zPAblYxQfl7qiu2Xfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707927619; c=relaxed/simple; bh=0HcfJmmBqgnxEibVXmvtKiQfWDI/qjmiO3qS4+TsxxY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=atCcyJamqyffM7MzOEzwwvsa+wB5jmSWa1D6M+CbfulJ7T4AQ069wtRPiS99awOny0iF4n38XejqdcsuajknVt+dYvjhutlcd/E/IE1gG9BVeMANzp9PngBkwMqekOni3d8oc74CFDp2gjW6WWxI/LITuVU08fFLunyZ8QxCPZw= 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=Hb+Ua2jq; arc=none smtp.client-ip=209.85.215.201 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-pg1-f201.google.com with SMTP id 41be03b00d2f7-5c66a69ec8eso5685706a12.3 for ; Wed, 14 Feb 2024 08:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707927617; x=1708532417; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fm0rEdFpfBw8yrd8ZCjG8lJI7FOozunf2bgbBsdJdm0=; b=Hb+Ua2jq7CbJygC6codkBXNvS1oHVKlJW5tWam94GlvHyNLvyJYHO5Sz/JIySq7SzE mAMywQxAe5T7l/K2vsvPHq2jA1WI6Mt7S0jqdKxf+10UtTwP4T/Xj64RE79Moh8Ptwgy Th0IzgdFW4WGqKe8c39h7FzSe3ztIZqR0iNzL4vDdHbeZNDs4wX1PptBcob7WC/9If1/ t/BjKNUO0qqXjnupAhoV2dAEcJ64m0Cc/upo2p4HhCxaR8ipC1JdzFqRuVYzdYwt5+Fz IB7I7iliqYufEd9VrbJ4rtc4ipr0m6XbSJYOrV6MZRwMSkATIHexopkx/n4IevzYwePF ADHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707927617; x=1708532417; h=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=Fm0rEdFpfBw8yrd8ZCjG8lJI7FOozunf2bgbBsdJdm0=; b=RberIlH+9emHPTlQhEMyTZK50SS8PzXoUdqoTz7FBAhur4VuutfiyqDscNPpna8T9w MXmgKUFOFfALKvdj9i5iMauB44fNK5JgFmH+18LCBAw+t2m8wItCoy/EWyiqzIJyhB7T HJNdjIupbaLWB9+RsdTAgytIpwwMAp+FHHUNi5HQOdFV5Ty9O5fjvVUNgcA2vjoTOj8V OO0gTg4c4koiATIwvvamluhp6vZSKL1oMUdnA6L3IC4fbeC2d0on3J9ZXbqKyf/9NvqL 0OY8GpM6ogpo3a15cg3HdG8obd+hqhpRFpDtFgnLhWOVxS6NRJmWOOq7d5kUthjbVZ9z hkmw== X-Forwarded-Encrypted: i=1; AJvYcCWXk3k6adz/2Oijuj8HlpVrIbp48E7tTB53bsRgfm3LUUqrRuPEonWetyDhchW1XqY1f7n3yxAcnu6h7gRIXbGJXZnQQ9ESJXmDKczH X-Gm-Message-State: AOJu0YyqPsSl/+M3GeuqDAsuRLMldsLFXi6k7BeXocd7Ydm84DzzabOG xbrbK7ALXgy5mRRyZ9+vBgerdGW8R2IAVH/w0bhlpzEa0tIbS9tQZ9MAD3J2e9KHgqgYQJ8rjIb xOA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:996:b0:5ce:6c6:6973 with SMTP id cl22-20020a056a02099600b005ce06c66973mr40244pgb.8.1707927616820; Wed, 14 Feb 2024 08:20:16 -0800 (PST) Date: Wed, 14 Feb 2024 08:20:15 -0800 In-Reply-To: <9c542f39-959e-4ab1-94a5-39e049a30743@xen.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> <9c542f39-959e-4ab1-94a5-39e049a30743@xen.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: paul@xen.org Cc: Paolo Bonzini , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , 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="us-ascii" On Wed, Feb 14, 2024, Paul Durrant wrote: > On 07/02/2024 04:03, Sean Christopherson wrote: > > +s390 folks (question on kvm_is_error_gpa() for ya) > > But! kvm_is_error_gpa() already exists, and it very, very sneakily does a memslot > > lookup and checks for a valid HVA. > > > > s390 people, any objection to renaming kvm_is_error_gpa() to something like > > kvm_gpa_has_memslot() or kvm_gpa_is_in_memslot()? s390 is the only code that > > uses the existing helper. > > > > That would both to free up the name to pair with kvm_is_error_hva(), and would > > make it obvious what the helper does; I was quite surprised that "error" means > > "is covered by a valid memslot". > > > > Seemingly no response to this; I'll define a local helper rather than > re-working the open-coded tests to check against INVALID_GPA. This can then > be trivially replaced if need be. How about we force a decision with a patch? This should be easy enough to slot in, and I would be quite surprised if s390 is overly attached to kvm_is_error_gpa(). From: Sean Christopherson Date: Wed, 14 Feb 2024 08:05:49 -0800 Subject: [PATCH] KVM: s390: Refactor kvm_is_error_gpa() into kvm_is_gpa_in_memslot() Rename kvm_is_error_gpa() to kvm_is_gpa_in_memslot() and invert the polarity accordingly in order to (a) free up kvm_is_error_gpa() to match with kvm_is_error_{hva,page}(), and (b) to make it more obvious that the helper is doing a memslot lookup, i.e. not simply checking for INVALID_GPA. No functional change intended. Signed-off-by: Sean Christopherson --- arch/s390/kvm/diag.c | 2 +- arch/s390/kvm/gaccess.c | 14 +++++++------- arch/s390/kvm/kvm-s390.c | 4 ++-- arch/s390/kvm/priv.c | 4 ++-- arch/s390/kvm/sigp.c | 2 +- include/linux/kvm_host.h | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c index 3c65b8258ae6..2a32438e09ce 100644 --- a/arch/s390/kvm/diag.c +++ b/arch/s390/kvm/diag.c @@ -102,7 +102,7 @@ static int __diag_page_ref_service(struct kvm_vcpu *vcpu) parm.token_addr & 7 || parm.zarch != 0x8000000000000000ULL) return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); - if (kvm_is_error_gpa(vcpu->kvm, parm.token_addr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, parm.token_addr)) return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); vcpu->arch.pfault_token = parm.token_addr; diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c index 5bfcc50c1a68..415c99649e43 100644 --- a/arch/s390/kvm/gaccess.c +++ b/arch/s390/kvm/gaccess.c @@ -664,7 +664,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, case ASCE_TYPE_REGION1: { union region1_table_entry rfte; - if (kvm_is_error_gpa(vcpu->kvm, ptr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, ptr)) return PGM_ADDRESSING; if (deref_table(vcpu->kvm, ptr, &rfte.val)) return -EFAULT; @@ -682,7 +682,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, case ASCE_TYPE_REGION2: { union region2_table_entry rste; - if (kvm_is_error_gpa(vcpu->kvm, ptr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, ptr)) return PGM_ADDRESSING; if (deref_table(vcpu->kvm, ptr, &rste.val)) return -EFAULT; @@ -700,7 +700,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, case ASCE_TYPE_REGION3: { union region3_table_entry rtte; - if (kvm_is_error_gpa(vcpu->kvm, ptr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, ptr)) return PGM_ADDRESSING; if (deref_table(vcpu->kvm, ptr, &rtte.val)) return -EFAULT; @@ -728,7 +728,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, case ASCE_TYPE_SEGMENT: { union segment_table_entry ste; - if (kvm_is_error_gpa(vcpu->kvm, ptr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, ptr)) return PGM_ADDRESSING; if (deref_table(vcpu->kvm, ptr, &ste.val)) return -EFAULT; @@ -748,7 +748,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, ptr = ste.fc0.pto * (PAGE_SIZE / 2) + vaddr.px * 8; } } - if (kvm_is_error_gpa(vcpu->kvm, ptr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, ptr)) return PGM_ADDRESSING; if (deref_table(vcpu->kvm, ptr, &pte.val)) return -EFAULT; @@ -770,7 +770,7 @@ static unsigned long guest_translate(struct kvm_vcpu *vcpu, unsigned long gva, *prot = PROT_TYPE_IEP; return PGM_PROTECTION; } - if (kvm_is_error_gpa(vcpu->kvm, raddr.addr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, raddr.addr)) return PGM_ADDRESSING; *gpa = raddr.addr; return 0; @@ -957,7 +957,7 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar, return rc; } else { gpa = kvm_s390_real_to_abs(vcpu, ga); - if (kvm_is_error_gpa(vcpu->kvm, gpa)) { + if (!kvm_is_gpa_in_memslot(vcpu->kvm, gpa)) { rc = PGM_ADDRESSING; prot = PROT_NONE; } diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index ea63ac769889..3e5a1d7aa81a 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -2878,7 +2878,7 @@ static int kvm_s390_vm_mem_op_abs(struct kvm *kvm, struct kvm_s390_mem_op *mop) srcu_idx = srcu_read_lock(&kvm->srcu); - if (kvm_is_error_gpa(kvm, mop->gaddr)) { + if (!kvm_is_gpa_in_memslot(kvm, mop->gaddr)) { r = PGM_ADDRESSING; goto out_unlock; } @@ -2940,7 +2940,7 @@ static int kvm_s390_vm_mem_op_cmpxchg(struct kvm *kvm, struct kvm_s390_mem_op *m srcu_idx = srcu_read_lock(&kvm->srcu); - if (kvm_is_error_gpa(kvm, mop->gaddr)) { + if (!kvm_is_gpa_in_memslot(kvm, mop->gaddr)) { r = PGM_ADDRESSING; goto out_unlock; } diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c index f875a404a0a0..1be19cc9d73c 100644 --- a/arch/s390/kvm/priv.c +++ b/arch/s390/kvm/priv.c @@ -149,7 +149,7 @@ static int handle_set_prefix(struct kvm_vcpu *vcpu) * first page, since address is 8k aligned and memory pieces are always * at least 1MB aligned and have at least a size of 1MB. */ - if (kvm_is_error_gpa(vcpu->kvm, address)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, address)) return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); kvm_s390_set_prefix(vcpu, address); @@ -464,7 +464,7 @@ static int handle_test_block(struct kvm_vcpu *vcpu) return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm); addr = kvm_s390_real_to_abs(vcpu, addr); - if (kvm_is_error_gpa(vcpu->kvm, addr)) + if (!kvm_is_gpa_in_memslot(vcpu->kvm, addr)) return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); /* * We don't expect errors on modern systems, and do not care diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c index d9696b530064..55c34cb35428 100644 --- a/arch/s390/kvm/sigp.c +++ b/arch/s390/kvm/sigp.c @@ -172,7 +172,7 @@ static int __sigp_set_prefix(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, * first page, since address is 8k aligned and memory pieces are always * at least 1MB aligned and have at least a size of 1MB. */ - if (kvm_is_error_gpa(vcpu->kvm, irq.u.prefix.address)) { + if (!kvm_is_gpa_in_memslot(vcpu->kvm, irq.u.prefix.address)) { *reg &= 0xffffffff00000000UL; *reg |= SIGP_STATUS_INVALID_PARAMETER; return SIGP_CC_STATUS_STORED; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 7e7fd25b09b3..d175b64488ec 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1788,11 +1788,11 @@ static inline hpa_t pfn_to_hpa(kvm_pfn_t pfn) return (hpa_t)pfn << PAGE_SHIFT; } -static inline bool kvm_is_error_gpa(struct kvm *kvm, gpa_t gpa) +static inline bool kvm_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa) { unsigned long hva = gfn_to_hva(kvm, gpa_to_gfn(gpa)); - return kvm_is_error_hva(hva); + return !kvm_is_error_hva(hva); } enum kvm_stat_kind { base-commit: 687d8f4c3dea0758afd748968d91288220bbe7e3 --