Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1383918rdb; Mon, 19 Feb 2024 13:52:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV3mJO1dNe7iFUSBzmPM4UoIPY+kMqjbJLgL/mJA/t7acRp09tLg7IaTlW8/mnKsLOhYs8HIY1UdIc+RejnPVqISt19uv/itKqQwIQKpA== X-Google-Smtp-Source: AGHT+IGrn9VR8Wn/mz+/3B5lOzO+y+xxsXMpUylCVziBQEiNrS9n4lO46ESuG0KIdFIarM0jy9AA X-Received: by 2002:a05:6e02:1a04:b0:365:c5c:df9e with SMTP id s4-20020a056e021a0400b003650c5cdf9emr13467298ild.22.1708379527482; Mon, 19 Feb 2024 13:52:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708379527; cv=pass; d=google.com; s=arc-20160816; b=e8sXhs2rao/pf+AUqYyxJTLsj7+twdGeA3YrCWabBc0AI4cF0rPsvwi/Ai1X6PInzE pqhyK6/h5hr+h4P+kvb98ik/JZAHo6FezV8ueA7BAIXkCEGq7RnNVylL+l7wkcsSJDLn N1dPPrUBFE5CnBbva+eVi78Uc777le/zobEr7o1UbSmg6PFhCJ4DuywLBQ2R/uOzapS1 EJ/IqmZNeLsLI+K2r3XdnwzC6NibHWzjMvi7if3vaOBpqC6SMysutK6TNNCKrRLU6RPq wgIfXl4npl1sdMimiYQXpqSzHIoIHE5UWpB+S+8EwklVEgsyo+sxWEkUG+JLjDJeqATm y2rQ== 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=rfULs70pvI7Ceuv9WP6jFUGiLY8ut6R2G7DJK71RQkY=; fh=7mO7/+vWgx9N2V6/OQU+H12cJ4SQcmioJqkt5XbhxWM=; b=pojLzzlTeUivcqIhRV7nuw/OArpDZQemPSnrWpbmzcf0lC9TpzRI46IIwLdqD8NJ3W t9zZyNA05O/Dvj9arddbjmuUdIAJvpZcNh9otnmDfURQsrPz5EZ9jhf8U0xqgMg9N+Vi Tcwk7k7MHvbivk5BWuIdsB0B/qXYcpRGku4klHrbd30rm7JLBfOOKdosZszLjzAWqpc4 /jakg6I1nnlMsZeUVlN8mPIQgBbJgHJrb149wK440VS7ShKE9VxR/+4TTvlUdOuOxz2A 4Ziiio+f4UmRtGnFAZWjgm+G86YK08eHW1B/TcOXkA2qLpte6e7+PBvEoyhXjyYi1H09 z9RQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NCgw1UP1; 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-72028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id by41-20020a056a0205a900b005dc82971737si4308998pgb.365.2024.02.19.13.52.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 13:52:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NCgw1UP1; 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-72028-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72028-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 10EFBB21E49 for ; Mon, 19 Feb 2024 21:49:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E26854F94; Mon, 19 Feb 2024 21:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NCgw1UP1" Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 85C4F482FC for ; Mon, 19 Feb 2024 21:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708379371; cv=none; b=gojcM0hFaBujzyr6jp08FBNBMw585Rzqcwz8VOLGZ8JjtpI1NvCDba/UBnYukDFVKKe0efX+3zNSZTlqzZWZf8Lgk6Cmo5vbnKo+q7IeodSw6EMASkaAnmTDTKUHVyl8Gxhmu4m2H1m2sJBi3Mzo2iYFm42CR7bRtUWiwL29qkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708379371; c=relaxed/simple; bh=KItFpHig7GKB5eVb83kBF+Sj8VfMjfLDxIkJsHCGAAA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tU7ZlvNY2w8unwNTClt1dqEmclXkAF9pSVSFUQP8zXKmPcjO+Xx2/tNhPUzwph+JUfz5kShAf2DSj5Ex2l70axQ8JsOApyTxRlZsVq8lCJH/rfVgwJaOpnzDkfVK+33gh0TgqBE5Z1ntvZtKtb4bOI+qmQWIz3hZJ3pqh8vsMdg= 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=NCgw1UP1; arc=none smtp.client-ip=209.85.216.74 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-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2993035cd15so3204162a91.0 for ; Mon, 19 Feb 2024 13:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708379368; x=1708984168; 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=rfULs70pvI7Ceuv9WP6jFUGiLY8ut6R2G7DJK71RQkY=; b=NCgw1UP1hH90/FQ/kuw6bS/QgCNpfraT4U5YBUE5OIytm/sgbrey2Pfng72N+ZD8dj DN3Y2DwcShM4JtwlsEy/Ffh7XHP7h+hsUytvvibI8QiEmcoI12Cm4GxQ0A5UW214eXHT vvz+ifVNxyKQ0bQHrq7tysE6HvM5B7jAQyD+leBK7anLBETDQapw0iC8VDay1swX/owq v/oaaNA8Iy8TmEZJOjG6A16OydqPeQCxnby+8hZ9a2+EiR2vmE/rOZTJeq2x3IOtQqFC 7rngs3f4kqFMB6ax82KRVSsmrx7erjij1DLVt9xClC9MuA/q+A0w8KZw6gXzlwzWF5DS 1d6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708379368; x=1708984168; 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=rfULs70pvI7Ceuv9WP6jFUGiLY8ut6R2G7DJK71RQkY=; b=rVO6pzgfybfQ1ukO6xwzgFDjUtRIxRBoDokgFzkR3D1xO1fRXos0FZrwZAfbYvg8o4 T0r6ZAesQnmdjRARGZaOy/vlzQkjD9SYimuRQOng8DPqxh1auxAAeouPTK/lIPCjMkWF RFT/uT3hPoV7UbttYPvtqFXpfnx3+WI3r6WT9RCw3Pbnzt+ds/A24ESY5FU1/1jpIUtv oY/dttSexPSamMjZCcAmxWoVtTbwxKYpHCBxFhgNavXR0jTJVcULEFYFNa6QWbUG1tc+ zeya3hvy2Zejad9CbJxlNSctLDiPHGJ34qWZJiXzirv89Cwz1d+BEu+GFN9k6tLAmrEs 6XEw== X-Forwarded-Encrypted: i=1; AJvYcCVcXagChBbjrHKwb7nFeZQ9SBhiQCD5GeJq4PbMV2yc/lOXatg2eLGF7yiJv4saGVIuVjOfJz7t1ZrvSiSJaKgwTummQHYNpkese+gt X-Gm-Message-State: AOJu0YyblDWpi5e/vzVUgQQLAg6Yh+fm/bszMGpW1/2Srmx2jbZIRpw8 F79MhV8Ja5t8hPQveatdy1jGfXf/zPnt8ofGAxHCx8B2Hc1L0TOAd0Rj2sZvgLWpJ+VgUSEDbq7 sBA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:1583:b0:299:cda:3178 with SMTP id lc3-20020a17090b158300b002990cda3178mr154276pjb.4.1708379367964; Mon, 19 Feb 2024 13:49:27 -0800 (PST) Date: Mon, 19 Feb 2024 13:49:26 -0800 In-Reply-To: <20240215152916.1158-10-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240215152916.1158-1-paul@xen.org> <20240215152916.1158-10-paul@xen.org> Message-ID: Subject: Re: [PATCH v13 09/21] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA From: Sean Christopherson To: Paul Durrant Cc: Paolo Bonzini , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , 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-s390@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Feb 15, 2024, Paul Durrant wrote: > @@ -319,7 +340,16 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, > > int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len) > { > - return __kvm_gpc_refresh(gpc, gpc->gpa, len); > + unsigned long uhva = gpc->uhva; > + > + /* > + * If the GPA is valid then invalidate the HVA, otherwise > + * __kvm_gpc_refresh() will fail its strict either/or address check. > + */ It's not just to make the strict check happy, though that's obviously the direct motivation, it's so that there's one root of truth. The strict check is there to enforce that behavior and to make it more clear to readers that it's an either/or situation. > + if (!kvm_is_error_gpa(gpc->gpa)) > + uhva = KVM_HVA_ERR_BAD; This would be a good time to use a ternary operator. /* * If the GPA is valid then ignore the HVA, as a cache can be GPA-based * or HVA-based, not both. For GPA-based caches, the HVA will be * recomputed during refresh if necessary. */ unsigned long uhva = kvm_is_error_gpa(gpc->gpa) ? gpc->uhva : KVM_HVA_ERR_BAD;