Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp217295lqt; Mon, 18 Mar 2024 06:11:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVL5hqAx2U4kE0AYXCWE9+nIDLX6p2hMCAJpC+eWm/k+NI9WIwUNEkyzjtHRxhneL9zHsedr1KF6DAOXjz9e7o2/3uUZo/5NKIObhkYWA== X-Google-Smtp-Source: AGHT+IHdq3xz7RA7M0wiaZF9F+ZzzLd49lo40Bpu0j9SpRPC53cEtqH0GRENOgvRppQzGXLmMMpO X-Received: by 2002:a17:906:22cd:b0:a46:5a46:7512 with SMTP id q13-20020a17090622cd00b00a465a467512mr7662669eja.74.1710767485781; Mon, 18 Mar 2024 06:11:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710767485; cv=pass; d=google.com; s=arc-20160816; b=hpGAZoFtFPwDgWLblduQS9Usqg5058QpP7yXErdZmuGs13Acg12DTgD0FORuj3gQ3u Ho0ylvVsEih9OygeyQ2HRWEx+FcKUuVZ97z/3wYAIswUZTb7Eg+sYs7cslRKL4Z0T4Re l/s78jergmlI3ImCgPYIUqXO77Xr+WU24YXpvO2g/jZokb3GeP1DWWqs2N/xlUHjdbrL 5GQGcNj3qZy6hdGfpaeloJfne6yYo1BDXo7FFzXcWWyS8KvvZfPdSh8daFR206vB263H Kd7S76BjbGnAPP5OGK+Pide/Cs4s7jS9sKXlIfeeVaUArnRCwh3EAtV64h3Rxx3pCmI8 b9uA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=9neb2kg1Bn3mmLQBIkZNqW8zmI6QIZ7MrEWOD5a8wx4=; fh=K0lL8+C1WN1UECiOQr1TQAyT7Rkv8QIWw2ucgJyKIxs=; b=q0gnGY48UYSHv1YPzsvCMPHYdytqMZz39vjabHldJGVc1hvEyxtMKm2t5xs67HwRjz vkwSuiAwmOEgAHiSjErIzk5FG3cCwo2g2Qr3bDGvd5E0ezpOB4PDMY0Rf8YPj+TYDNHp TOFPRGhBm71mc14zqsQTMVnpJ0WwWJGDT40LEW5hZITZWT3yPNWmoM8PJWNVlOKtIy+r +oewMUeNFOFr+5T8gXd+Bt5UwRN2SzaxLexS38/xwwb+dZ1fHZVZaSZXNc5cOWhI5XyG HzhLx/peGbGLebDjg9J5KVgdz6Z3bRmEfHbz8+6affOLk1MoTyJbg7mdFzRnX4J5yLim OI+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jRTR+Fdo; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-106151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r21-20020a1709067fd500b00a465467781bsi4228872ejs.77.2024.03.18.06.11.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 06:11:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jRTR+Fdo; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-106151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 58F6B1F2201B for ; Mon, 18 Mar 2024 13:11:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EF0E38FA0; Mon, 18 Mar 2024 13:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jRTR+Fdo" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B998A2A for ; Mon, 18 Mar 2024 13:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710767473; cv=none; b=j9lBcnhdJ0+cbMwZhls6s7R5Z99MxL8q+g/ablpeZg5DHyLcW6XsI9X0TL1LO9KU65UHu6Xdp3pVmvf6c57vcR//EmRsBhIcV4Yw3hQeb57aumJGnRFpnolj6a4HoLFKfvdVM6N+7oTgSFwV5ryiUwzmceZjFjK+lYxQ8yaHKuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710767473; c=relaxed/simple; bh=6+niSvsrlTdoebUFvZkR5TjyZ5KAxqQlNjvmrnyAdUU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=uWibMpNaJ5bD85Aei2Iy6owL1mJlEO5K8WcTad8BRYMxBOGsOg1UOkiUn8VPpgpjc/rAERrCoW4jbAMWIHFxZBw6EDJ9tnFJSSa6tUh/xHCuzyUw28Hv9oHZ543i7wG6NHIrpT7PG/FIozJruwsjH2tpeUSAJI9Xf/uXZzeMtQo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jRTR+Fdo; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710767470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9neb2kg1Bn3mmLQBIkZNqW8zmI6QIZ7MrEWOD5a8wx4=; b=jRTR+Fdo6kD947iFo1P9h3gAUq28BtHva9YEe1d7yv9af4o+6wjjX5VKeqYhyOq1iUCu40 WfXyQaVH7ckLYsrl/uAF8BfiitK9HNMBInbgrZ8+EJFamvBiMiqg3mTtQm0kwET+SPCjWa kW+PPubLsl2Q86HbRIuzmp7FQJF2N6k= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-439-xiGdaQMPM9SXZhLYrbgOUQ-1; Mon, 18 Mar 2024 09:11:09 -0400 X-MC-Unique: xiGdaQMPM9SXZhLYrbgOUQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33ec0700091so2865450f8f.0 for ; Mon, 18 Mar 2024 06:11:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710767468; x=1711372268; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9neb2kg1Bn3mmLQBIkZNqW8zmI6QIZ7MrEWOD5a8wx4=; b=WBJWXCHzqHg5xwqgmfjTDLM0gosdWVo2t+8vxIKlRfiPimXE+2lHEnWyMYDe3mU7jX /5YCKmMUgg1ugL7ec+WerUxCWmKInH1/jpzkp8UHU56rB2brm8SImxvK5ZxmhYpaBh1E KDSLPlY7obYoeNFMAFUIszoMRQDwtOPSBteBkxznhlJqmziewhJIInJBQAnLbVWNwy71 Ocf52BjyqNe3M/YGaFJxziGUzyWjIW+kDmuPsNYN/q5fJaFkl3uQDTvXiAJhk8WbnfQl tjZW97jNY0Hxnqb52b5m1HHgnp3tPWYEjvYQsRUcviNIsEmGCoJzgLam9ZhXDk+HtKGP ERIg== X-Forwarded-Encrypted: i=1; AJvYcCWsu2/wrnYt18TXXz/OTkavTcpdTC416pMl4yddqi6fEZZ4/O7mNNL21cuumTD+emU8H8pzrs3fzTPhHTBO2sHe40yyCxEH8g/SYpoO X-Gm-Message-State: AOJu0YzKGYHJi//P12TElcHN3YriXiBg3wa+cYbGRte5/ji7BTyu2rPY SMs1e8EB6rFmcksSAE+O439blYtNb3wjhennzUmDypZGn/8D/Dang51MYKwZGdakKQtVHafEZYY hmBOcF2NXVgMtaHdiIPl5ueoklb+R+PhG+OWL/Yo5Ky1uM91cOyxrbxlUe53XfsrRArkodQWlOd a3oW3HPVhfm+6POmVk4SuuMPjg8POP1eBeRCCf X-Received: by 2002:adf:e745:0:b0:33e:7621:e15f with SMTP id c5-20020adfe745000000b0033e7621e15fmr8170830wrn.39.1710767468018; Mon, 18 Mar 2024 06:11:08 -0700 (PDT) X-Received: by 2002:adf:e745:0:b0:33e:7621:e15f with SMTP id c5-20020adfe745000000b0033e7621e15fmr8170817wrn.39.1710767467700; Mon, 18 Mar 2024 06:11:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <0b109bc4-ee4c-4f13-996f-b89fbee09c0b@amd.com> <9e604f99-5b63-44d7-8476-00859dae1dc4@amd.com> <93df19f9-6dab-41fc-bbcd-b108e52ff50b@amd.com> <985fd7f8-f8dd-4ce4-aa07-7e47728e3ebd@amd.com> In-Reply-To: From: Paolo Bonzini Date: Mon, 18 Mar 2024 14:10:55 +0100 Message-ID: Subject: Re: [PATCH v11 0/8] KVM: allow mapping non-refcounted pages To: Christoph Hellwig Cc: =?UTF-8?Q?Christian_K=C3=B6nig?= , David Stevens , Sean Christopherson , Yu Zhang , Isaku Yamahata , Zhi Wang , Maxim Levitsky , kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 18, 2024 at 3:07=E2=80=AFAM Christoph Hellwig wrote: > > > Fundamentally, what this series is doing is > > > allowing pfns returned by follow_pte to be mapped into KVM's shadow > > > MMU without inadvertently translating them into struct pages. > > > > As far as I can tell that is really the right thing to do. Yes. > > IFF your callers don't need pages and you just want to track the > mapping in the shadow mmu and never take a refcount that is a good > thing. Yes, that's the case and for everything else we can use a function that goes from guest physical address to struct page with a reference taken, similar to the current gfn_to_page family of functions. > But unless I completely misunderstood the series that doesn't seem > to be the case - it builds a new kvm_follow_pfn API which is another > of these weird multiplexers like get_user_pages that can to tons of > different things depending on the flags. And some of that still > grabs the refcount, right? Yes, for a couple reasons. First, a lot of the lookup logic is shared by the two cases; second, it's easier for both developers and reviewers if you first convert to the new API, and remove the refcount in a separate commit. Also, you have to do this for every architecture since we agree that this is the direction that all of them should move to. So what we could do, would be to start with something like David's patches, and move towards forbidding the FOLL_GET flag (the case that returns the page with elevated refcount) in the new kvm_follow_pfn() API. Another possibility is to have a double-underscore version that allows FOLL_GET, and have the "clean" kvm_follow_pfn() forbid it. So you would still have the possibility to convert to __kvm_follow_pfn() with FOLL_GET first, and then when you remove the refcount you switch to kvm_follow_pfn(). Paolo > > Completely agree. In my thinking when you go a step further and offload > > grabbing the page reference to get_user_pages() then you are always on = the > > save side. > > Agreed. > > > Because then it is no longer the responsibility of the KVM code to get = all > > the rules around that right, instead you are relying on a core function= ality > > which should (at least in theory) do the correct thing. > > Exactly. >