Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1017270rdb; Fri, 9 Feb 2024 07:59:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEscmqXgAq5qj7OeQ6X63oAV3utyulHdK3MVmRgJIdnzP2NIkT5MH/42Ztcv8FtqWzLCMjR X-Received: by 2002:a0c:e111:0:b0:68c:4774:a9ea with SMTP id w17-20020a0ce111000000b0068c4774a9eamr2125810qvk.46.1707494356938; Fri, 09 Feb 2024 07:59:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707494356; cv=pass; d=google.com; s=arc-20160816; b=HlxfbMRq/HIdwLE1W3ulRYUM1/nC4h5bt0XD3ZJDIYSbnA0hWqt14To1XcglwVhjRF z2/ISnPi7RV/9uVPXq/VBMJTyy4Csl96vCwZkJ8VLQ+KCLV4P6/en6GhtBpPXhVG8k7D qKaUTkZsIi4VuZ6tMdI3foUo4nhwxrBQoh7bgAs53Q+00B+lcuxzFLD41MFQjflglmxL 4y1TkWDxgPQSLcfPXN5VD2LlVyOKDdWpj0wXEgQMGNNRV4pKYDxCftQEXV5rugC09ynf n0UdmOFHtk+07xehTIrXcDCO7bAHTip4LC39CcxcufKWvKtGU+cf8aWPnOR1St6b6YAf VwJw== 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=vmU1iVHFMR+KMXCRooeSWvSlFqesJV4w6OG3Cfb/DYA=; fh=vTm4NIFYJzm8kBdtym9/xN28XkwTx+oEjzzGEtx4mI8=; b=Keip8CtKAxXDNb3WU5C0mnUw12PaPfwysoReG6KDxg6FF81CVXJiVBTiwTxR196g/I VRXoPcGY5pumf0V/i9s8T/j8ptGpcY1nVsUp3onltqFOo6RMXsm3WnHP4mmnRiGYjV/l dmxz6YaxlzLwN5XSPd+CWY8a7c5LeWqolIfdvFlohj62Jk2vCyTvMHguL2SNFm2V9b5U GgHa0oMM1GtiH1TpGKf5ijY4IETGtm3KB/vmYM4G/DCRoybce1BU3khE68QReewb97s3 wvnACRAEfBf3EON2DmGw2K+m4pncV/F73Q0eBikP1UK9VgZGBQ4RW/2EUR4/XUOn+EYx lvHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ih9WpT7m; 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-59567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59567-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; AJvYcCVPRuMq7bhxkzd/WbAsYjmShfCdkKzOlZe9lvrHTivk4ZpMOdaB+36xdLiH/LDqg+01uwL4tRHoVr4yrMQA1OQSfs7QbFKuh2bwxU+wKw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id r8-20020a0562140c8800b0068cbcbb6c92si2127979qvr.182.2024.02.09.07.59.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 07:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59567-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=Ih9WpT7m; 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-59567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59567-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 ABF211C21C63 for ; Fri, 9 Feb 2024 15:59:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5E1C762E1; Fri, 9 Feb 2024 15:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ih9WpT7m" Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 67B1373186 for ; Fri, 9 Feb 2024 15:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707494344; cv=none; b=bEoFYEA+mov9ybfdY1lajj4oImDhv4s0TMZuT3BT3lLWD07jsniVUYG5oEtTaw5eRKZfchhaLbRcVKScR/kAiiUEPduHpF+rUTBFxZfYYOk717pcnZEiwQf8muScgWsOjoaJicj0WGnzs6jmZBVf4LKH4cqlHljCBWqjkrUprvA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707494344; c=relaxed/simple; bh=t8AOFvwk4ZsRfte4mt6qy5Qnrh895ZKYWxZaGpnZgQc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NC/mECUMM4F+8kweRleFAwYdW/WLyPplxtTHOVTVhCdzwwqqHw6JrayscEEUVpMhxVcr4cZa47RiGRyoPM1fDGmkWVD6HpJVAnHW/+eD4bfdYyoRFWWEUaDqCCQ5wwMwdaKqfD/5zrX5Vktyr8sLQ75vE18nH+fVwKCUQEGQ/ss= 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=Ih9WpT7m; arc=none smtp.client-ip=209.85.210.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-pf1-f201.google.com with SMTP id d2e1a72fcca58-6e04e1ac036so1424361b3a.3 for ; Fri, 09 Feb 2024 07:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707494341; x=1708099141; 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=vmU1iVHFMR+KMXCRooeSWvSlFqesJV4w6OG3Cfb/DYA=; b=Ih9WpT7myBDsTw1jCpnqGE0Abm0wEd9RUQQPjCsGBaElh0R9MIyqVn1LPzcv9ZNrCo 7W7i75Reo0LFMMvEJWyTGisjp+fpPTxUsv3/BtEtoIf4WH5rlJ/vMsipamEpE4MqYn0N gtfuy/GKlvIDB5ldu0rIIpNqn1qr6JhQxcyP87hVdfTJnZLd+Lo1KVIPylm2rvhkdeGS S1JQAi4SrcZQZmEI8ndBLebmKftD4grQTNkD9lgCPEa4w33In1WzS72Opy3RZRW1WHXC /RLlvgb/prfQoY681Coz1OYc1fuJ+w7UpHtch3g4e7jcTsSLjjM8RcE4WRrFP3rn3tHE iNsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707494341; x=1708099141; 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=vmU1iVHFMR+KMXCRooeSWvSlFqesJV4w6OG3Cfb/DYA=; b=F6lH05wnWl/GeB2iOONhJ685nShRKaUJqEhqdk0YILIi64aFRzlvsxoXnyr6YWFOWO lOTD1KEYMZEG+Z9qiWdt7RdAOcm96DHEmn6ZljNxOYxJgmSNv4j1MxC5QqVwgmtgfv4D oswGd/LDORD/MT1SgkFDoAXz3NkLU2lHRDzKqW2pm0uMxUfnqK8fjRy3HamVTC3GMu50 L+okUNC7o3ljOxCUxV7E9QPbvfaOoFQMmuwxhHula02aAPARvbPAMigCTkCaVVa3FdYH hYmO59gzIFxYHXnTDb2kBKVEXS0L6c8WYyKrJwpBEctyYgN9BycXuQS5TXzoC3IQ/gAD Q79g== X-Gm-Message-State: AOJu0YxIH9IXXiluh2gf3ledqySgAes2C4VDC3F5vEtENSMYjYUG6Oxp 28lidf+diOS1UY/PIgn4pb28ZvPhFFRqTQYvef8I40gge1hhcY5WX3uo42iSqHLjEfQAK5SMkWP vQw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:c88:b0:6e0:3e0b:44eb with SMTP id a8-20020a056a000c8800b006e03e0b44ebmr132321pfv.3.1707494340657; Fri, 09 Feb 2024 07:59:00 -0800 (PST) Date: Fri, 9 Feb 2024 07:58:59 -0800 In-Reply-To: <20240115125707.1183-5-paul@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-5-paul@xen.org> Message-ID: Subject: Re: [PATCH v12 04/20] KVM: pfncache: add a mark-dirty helper From: Sean Christopherson To: Paul Durrant 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 Content-Type: text/plain; charset="us-ascii" On Mon, Jan 15, 2024, Paul Durrant wrote: > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 7e7fd25b09b3..f3bb9e0a81fe 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1399,6 +1399,17 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len); > */ > void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); > > +/** > + * kvm_gpc_mark_dirty - mark a cached page as dirty. > + * > + * @gpc: struct gfn_to_pfn_cache object. > + */ > +static inline void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) > +{ > + lockdep_assert_held(&gpc->lock); > + mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); Can you opportunistically have this pre-check gpc->memslot? __kvm_gpc_refresh() should nullify gpc->memslot when using an hva. That way, you don't need to explicitly check for the "invalid gfn" case here (or you could, but WARN_ON_ONCE() if the memslot is non-NULL and the gfn is invalid?).