Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1019343rdb; Fri, 9 Feb 2024 08:01:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFHOS/8xQe3UtcwPfTlCvLgqw0qnmzDt27uj3dY5R2A5a1ss8LmjNnUttY48FQtW0yJHD6 X-Received: by 2002:a05:6214:29e7:b0:68c:cb81:44b6 with SMTP id jv7-20020a05621429e700b0068ccb8144b6mr2685961qvb.62.1707494512854; Fri, 09 Feb 2024 08:01:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707494512; cv=pass; d=google.com; s=arc-20160816; b=ZgO4g40tsjf5Rk1Nnq6t0dXsAc7VBHe5sSoZPpN9gvAo3pbp/gKWPsErtPiDZDfO20 8K8C2/K7xrGSpXIN/9YD6EJM3xnRddFAL/9jUTfPpkzfHS8uKrJ/iIr6ZKDbs3GMGGPx 4c3i0s3Pw91YyPeAILM55x8eE1dr93jp2YwG+napBiyilblr5c2IYV0y0+kyJ2BIOxJg HBTlM7wVS13AAEktBVGm39WG0OiC22LlljFNvUUXT1dTCNR9EIeuDzX5SmpNomboJobC 2c3GA6J0gjxfAjTRfP8UTiDGsUR8+z7JEuPxcruLhvofCum8xXOXQntkw+aJcsAo3HKA z4RA== 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=WbkXeYUaDBncgeOsZac9v7h/OYs9uDYhnmPMW2APu84=; fh=UNb348XFiPJKWrKxj2Kl0X7wGySDqEI1BQqLBUK2TYk=; b=wZv7ts5iJRfnD1wXRkqZILtQjEl/z1XdGhRF91F85bF3uHWVPGfhZ8daonyWdnLqDP 1PKHD7kfd7flC9mO2bojWm0WSzCUkoShxEMw3Z9+vaz1f9hRxVKcNDqeAZqXAg2MiHTY sLhWisKyeCLhUrCv+CB8zFW6f8OEoBIMad3EdYtJLIOLGQErCaApvGy3xhhgd52ywsRd +aqD4MXP42DRAe72xUJCvmEIgzkFRsbKll6LIn+uk/vKsIDZ2JfQP8KQ/QSLqBFJJecu iR4Pt6CjaHkz/+CF0pjbGSFTxnaxp2o/pJQZyUl+EVe/Xb+DZ47qCvVn1qd7gMnJuMM+ jnrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4EplVMy4; 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-59568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59568-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; AJvYcCWdwvS40ktZPFXPharFZZk14SrzvVk9sWmCs3E39e47lmjoCVfDeYrkS74O7mgoXZj4C6PjhF5SDatqvi996ACu7TQRHIt7S68X1X/+ow== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 10-20020a0562140d0a00b0068c711cf6cdsi2201083qvh.475.2024.02.09.08.01.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:01:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4EplVMy4; 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-59568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59568-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 9918A1C20EBB for ; Fri, 9 Feb 2024 16:01:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6B12762DD; Fri, 9 Feb 2024 16:01:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4EplVMy4" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 876D54D58C for ; Fri, 9 Feb 2024 16:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707494501; cv=none; b=F+rQKM47cvUSufolQ9fiF3Anydg6uDUYnlDNqpqs+UX/voaUmFBk8/ybj/3KnrTCgS7tOlTpLb9YoLz44mSqSxjPruwR0gvP32qys++zspdKJtbDhFPUoYVzY5Bou1epEKI4tL93gKnycDFMRyaTHGn28WA4Ur4OcXmIa07xi9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707494501; c=relaxed/simple; bh=A0ppvdAEssQ0RgSYaqSvMhcfnozN/meETnSjtqFC/tI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RCyKez1zsIFaiOK6AUnh8ZZVroz3FjvHQjIclfKieAERV7iChNZI6dnHYXc+ikk9CC3oMTT5UAHP5YffRWp6ay6+/Ht0Fmrn8VcKpbXu5t1jPcx+xL7pHr/QD7uUdCcZEzh46anXBFyvHJPQXCIDdOs8S+/OKqzYFc8h7kcMpsE= 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=4EplVMy4; arc=none smtp.client-ip=209.85.215.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-pg1-f202.google.com with SMTP id 41be03b00d2f7-5cfc2041cdfso976506a12.2 for ; Fri, 09 Feb 2024 08:01:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707494500; x=1708099300; 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=WbkXeYUaDBncgeOsZac9v7h/OYs9uDYhnmPMW2APu84=; b=4EplVMy4iyA5l3qKCK/51jsJKeEElOoEZRUasbbSiG0izQEILpQOILYbxCQzAKKLPc LD1RbJI5dGagCBD4yMfXdUG4O3ObMeVnfKoxoolzEKS5CAPsat2yW1TBqLdRPsViIKHA ez6NA5PGp4106LAXXHcANhSdGE8fPcwpQMCyH/7wzrBRhBXPr1IRveSt+LwahkOKPvgr RzpfGqqZ7GP/Qir5+oeir3f40HP10hFCbkfb3cfCwtIiPZzQEiC8Akqqx5hPceMgFqpd yvDOOIHC5YaGOYJZ/1fclQIOfnq3umsuS/GpBsdchhcmNRW6HT6STIEZ6IxitEX1KyLa qA5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707494500; x=1708099300; 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=WbkXeYUaDBncgeOsZac9v7h/OYs9uDYhnmPMW2APu84=; b=dqH+HThkn2656nRMNG62bYm8FM0dUaNMx7HBJExenOGoV3VUsSF2gPxMhQEJhyxHCy f/mE6pfilOtlfWUozNzSbtm4dDMnTneEEvw0A+00U7UhFyRKNPDohjt1Z3IvLccbRGoJ aWRdXys70guXRdWAQJt0045UoIFlEIDP5GhL6N+Ag2fw765jSBeML9/D79jzroHcQHa/ epVIUheC4TyV8lIXbPCv+TBWQhPaJqBvn0BBk8fWtvxinHJ4DBJfv6PaaH+owBhGrm2/ foyry778eoW1+oG9bxKrSWOZAapqaYBgMaaF8Nb+FyJqzEOXY0rQK/xYXdYYc/YdJ1zl IbHA== X-Gm-Message-State: AOJu0Yz4fiHf3e9ADYKXTIjbUV9/+FvhzvqgGhX/ydrOHwSbnu/NonUh 41sq8Cv/iA+yUSyaKeISCPaJfkgtAAJfjn0HoJ0OEpt+99fNfbYis3iKVgQa/P48+5gJRgH4/zm Xyg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6e8e:0:b0:5d8:cd91:44e4 with SMTP id bm14-20020a656e8e000000b005d8cd9144e4mr5426pgb.12.1707494499773; Fri, 09 Feb 2024 08:01:39 -0800 (PST) Date: Fri, 9 Feb 2024 08:01:38 -0800 In-Reply-To: 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-12-paul@xen.org> <92918ee8-3cc9-41c3-a284-5cd6648abc05@xen.org> <148d903c-fcc5-4a6a-aef1-c1e77e74d0fc@xen.org> Message-ID: Subject: Re: [PATCH v12 11/20] KVM: xen: allow shared_info to be mapped by fixed HVA From: Sean Christopherson To: David Woodhouse Cc: paul@xen.org, 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 Content-Type: text/plain; charset="us-ascii" On Thu, Feb 08, 2024, David Woodhouse wrote: > Using anything except NULL as the "no value" value doesn't make sense > to me. It violates the principle of least surprise and would be a > really bad API. I'm a-ok with using '0'. My only request is to check for "!hva" as opposed to "hva == 0", both because that's preferred kernel style, and because it better conveys that it's really checking for !NULL as opposed to address '0'. Side topic, I think the code will end up in a more readable state if the GFN vs. HVA sub-commands are handled in separate case statements, especially if/when xen_lock goes away. E.g. something like this: case KVM_XEN_ATTR_TYPE_SHARED_INFO: { int idx; if (data->u.shared_info.gfn == KVM_XEN_INVALID_GFN) { kvm_gpc_deactivate(&kvm->arch.xen.shinfo_cache); r = 0; break; } idx = srcu_read_lock(&kvm->srcu); r = kvm_gpc_activate(&kvm->arch.xen.shinfo_cache, gfn_to_gpa(data->u.shared_info.gfn), PAGE_SIZE); if (!r && kvm->arch.xen.shinfo_cache.active) r = kvm_xen_shared_info_init(kvm); srcu_read_unlock(&kvm->srcu, idx); break; } case KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA: { unsigned long hva = data->u.shared_info.hva; if (hva != untagged_addr(hva) || !access_ok((void __user *)hva) || !PAGE_ALIGNED(hva)) { r = -EINVAL; break; } if (!hva) { kvm_gpc_deactivate(&kvm->arch.xen.shinfo_cache); r = 0; break; } r = kvm_gpc_activate_hva(&kvm->arch.xen.shinfo_cache, hva, PAGE_SIZE); if (!r && kvm->arch.xen.shinfo_cache.active) r = kvm_xen_shared_info_init(kvm); break; } Side topic #2, the above requires that __kvm_gpc_refresh() not grab kvm_memslots() in the "using an hva" path, but I think that'd actually be a good thing as it would make it a bit more clear that using an hva bypasses memslots by design.