Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1811915lql; Wed, 13 Mar 2024 08:48:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVz66Q2YFuKGXsJ8iyz1TuQO5PXnsNVNwlMmYiHUX4afLwwQKm8MKG28rx0siTDy8KUYkzwNbo43eDdlP2Akv4Liki33O8kywtXjBSP8Q== X-Google-Smtp-Source: AGHT+IG40OQUyK2fTKn6ypqEcapPZJQReVnAthb7HK34YWL1uW/gUXblqX5CEfrBFTenEnwi4cVV X-Received: by 2002:a05:6358:4311:b0:17c:2214:6537 with SMTP id r17-20020a056358431100b0017c22146537mr366699rwc.30.1710344893127; Wed, 13 Mar 2024 08:48:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710344893; cv=pass; d=google.com; s=arc-20160816; b=C5IlL9znu2LliXPs3jqp7Xk+hZO8IGYJblNICloceP93VvDMo1owTREOHN6deh744w L3QAJ6v7P4Qw5U6ggE9nM26fNou+NCbAIe1AJPOgRXoajljnp1QQ4wqvfNHLVm2NIUEj 1RzQwjRtPTWlEBkx+42zV8XKI/rFBGS8X+xnRL54MzHLx7pfHGUQJUwegkPLLNJ+aWQN htzFxJnmgD47OESEaY2LNROxkL9hJ51gvCClrdzX0XDju8BJb0HFWaElQB6kgAnU/2wn AfVffA65/DGEvvLb5q5y+WQJ3Ojv94Tf5KtqMI9dSvezBCZxJnCXRIJLky6a3vfzf/jR q+0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=e/Z6H8FJpqkR5eo4Ljxl8hO8FSLCWuqRj+smCk6ObEc=; fh=JFmqxIRmWXjDi4auUot8EYiSX04ahgpwDSGxZ+cktII=; b=qUgC/RV25Q2bDAldkk0NX20FRuk1avIYFf9p/jSrl1Qx3uo/cPpTLQ086hZwBIXKVc ebYVDn+SL2BVbcmfXt5QQLis8lXvSt3aIH9LvuwCXurBacJv6YRG8wiY4NF4fSV+X3So P8X9mR3v/aMmUlqQRDEtIZmLvyVXZFWdh1lmDiDkLD5JXxxUymDNYNHhBDtLPaiUOchP xAvk7DILXQymCbbmpvq/LZZrgQg0ewDoCkoypW+gtKQf4nQOAD3rb/tVRfSR0lNXSzh9 afHOWF2+6Ae8Ln3SMJ3m53lMmcJeghc5GTgVh50NMpPUviJhSqL0aNzQ8QEhzHcLXIT9 RPtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="l+G/PNFS"; 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-101696-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101696-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u13-20020a63ef0d000000b005d8c5595ddbsi9257449pgh.271.2024.03.13.08.48.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 08:48:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101696-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="l+G/PNFS"; 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-101696-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101696-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CA2DF284A7C for ; Wed, 13 Mar 2024 15:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D296E47F6F; Wed, 13 Mar 2024 15:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l+G/PNFS" Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 61E7546BA6 for ; Wed, 13 Mar 2024 15:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710344870; cv=none; b=jqiYHWPcPwvJCz4N/KkJHZ6Xymz7YJA83ltYX+JcEaj2MMIhpUgiRpUHWUkTqHssipnZsV2M73T7Vuth5sG7eNy6CDmjBoG+siLgA5NDDk+0PU7TW2v7yrWD+Y2yJleS2P9Qy2qDDeQmzBiBpVYDnP/B/1rBdZ9Y7DcDa6W/YDQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710344870; c=relaxed/simple; bh=DXU7ph51IFvnFqSwDtmBTf5RGlHHgDbueVIPKluOaU8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A07UyIxGRL6pvjXQSYov3UypX/bxn5Rct1jLgjAcs9CVD2nHvcbVeP/LHMHIueU1QFlFn5y6bHVCLKgGglsKAVA8uZhl3Avm3uZ8PIymURM9lZKEPavUyOvZMtPwo5tdQUK3wSQKzwWn1osYVkV5LX/xBeCzwIyC7PCxXfwuDHQ= 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=l+G/PNFS; arc=none smtp.client-ip=209.85.214.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-pl1-f201.google.com with SMTP id d9443c01a7336-1dd916d7d55so11418335ad.2 for ; Wed, 13 Mar 2024 08:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710344869; x=1710949669; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=e/Z6H8FJpqkR5eo4Ljxl8hO8FSLCWuqRj+smCk6ObEc=; b=l+G/PNFSwp9RZZPCNF8SnQzJGaDxO/et1tiXBiyQ6KezckROFd2upWKeQKeNXK/kVd LlyUhOI7jJTbdiLeWY8ILK/UJO3nzs/cOLMb53mZT0mDkcjgzsrUrU3sCg9tnVNN9q7q 6zmj6yCvBiU8wGJEVDciMjykfyHU8kGaJgkvSNuyF4SEgspOr8vIOStK02XEgww7cNsu lgQ539GCoEg7jv/7G7Hc4WNOtW3+roxHAvo/XGFLpD0iSM/RubbStfnAtFBkm3E11uxy TL/+CaTiJRXEqmJL7ghb6PW1HGgV7GLfjQw/ScTVA9OOU5/6bvzV9tFChOUmyBDcGPs5 /etw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710344869; x=1710949669; h=content-transfer-encoding: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=e/Z6H8FJpqkR5eo4Ljxl8hO8FSLCWuqRj+smCk6ObEc=; b=Hjl5UnJHVCeKnkQnGc6/Xglno5hpLYr6OZjSGu/vFvp8qSCntTzk8YOA72/1/Bf6Fl c9NxdJrvIF0+xstWieJyb+RPRN8zvDS3TF8TsLScRfcozFzcCay3BnGFPgDHkDAGtv+Q KoNmGNDJZB5GnHUfIEdatmfJsNUUFDM4HpJDuhvLU8MPQ/VZOcaEgfu5WFN4eO9IUwqh 0JTS0poSfzGaVgUBHvEW1AuDZyYJo02rvnwzf3X0vzhDwhSYZWNlyL2tx/NG0pzTuWQ6 YRcnOME+qz4uoSizTaiqZRGrIL+BSTK2o7usryNY0oEs/ca+rf2n0E5KOaM7DjLUWkSe /GPg== X-Forwarded-Encrypted: i=1; AJvYcCVQJ1rWoTiECL8R/nqr01Go4rzESvIQ8ROxSLVdwv/I71UMK1twvG3yQ3CfGfgcAgOu3Xz/9bClm55eZyiswY1JZxt0+IFn/pHBjpXL X-Gm-Message-State: AOJu0YzMXiFdQw5Bc/LSCTWpFhRl+3SCjsyP0OwomUOCHxks1b5z99RS ZYaQXptN28b1yzHbsE6ewFDAzSeXF7hdkeH2sDyDkB0TCXSF172MmZ8AHKhsfhGE8UOrkq9eD3P ufg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d4c4:b0:1dd:47b7:47f9 with SMTP id o4-20020a170902d4c400b001dd47b747f9mr9378plg.11.1710344868617; Wed, 13 Mar 2024 08:47:48 -0700 (PDT) Date: Wed, 13 Mar 2024 15:47:47 +0000 In-Reply-To: <9e604f99-5b63-44d7-8476-00859dae1dc4@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240229025759.1187910-1-stevensd@google.com> <72285e50-6ffc-4f24-b97b-8c381b1ddf8e@amd.com> <0b109bc4-ee4c-4f13-996f-b89fbee09c0b@amd.com> <9e604f99-5b63-44d7-8476-00859dae1dc4@amd.com> Message-ID: Subject: Re: [PATCH v11 0/8] KVM: allow mapping non-refcounted pages From: Sean Christopherson To: "Christian =?utf-8?B?S8O2bmln?=" Cc: David Stevens , Christoph Hellwig , Paolo Bonzini , 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 Wed, Mar 13, 2024, Christian K=C3=B6nig wrote: > Am 13.03.24 um 15:48 schrieb Sean Christopherson: > > On Wed, Mar 13, 2024, Christian K=C3=B6nig wrote: > > > Am 13.03.24 um 14:34 schrieb Sean Christopherson: > > > > What Christoph is objecting to is that, in this series, KVM is expl= icitly adding > > > > support for mapping non-compound (huge)pages into KVM guests. Davi= d is arguing > > > > that Christoph's objection to _KVM_ adding support is unfair, becau= se the real > > > > problem is that the kernel already maps such pages into host usersp= ace. I.e. if > > > > the userspace mapping ceases to exist, then there are no mappings f= or KVM to follow > > > > and propagate to KVM's stage-2 page tables. > > > And I have to agree with Christoph that this doesn't make much sense.= KVM > > > should *never* map (huge) pages from VMAs marked with VM_PFNMAP into = KVM > > > guests in the first place. > > >=20 > > > What it should do instead is to mirror the PFN from the host page tab= les > > > into the guest page tables. > > That's exactly what this series does. Christoph is objecting to KVM pl= aying nice > > with non-compound hugepages, as he feels that such mappings should not = exist > > *anywhere*. >=20 > Well Christoph is right those mappings shouldn't exists and they also don= 't > exists. > > What happens here is that a driver has allocated some contiguous memory t= o > do DMA with. And then some page table is pointing to a PFN inside that > memory because userspace needs to provide parameters for the DMA transfer= . >=20 > This is *not* a mapping of a non-compound hugepage, it's simply a PTE > pointing to some PFN.=20 Yes, I know. And David knows. By "such mappings" I did not mean "huge PMD= mappings that point at non-compound pages", I meant "any mapping in the host userspa= ce VMAs and page tables that points at memory that is backed by a larger-than-= order-0, non-compound allocation". And even then, the whole larger-than-order-0 mapping is not something we on= the KVM side care about, at all. The _only_ new thing KVM is trying to do in t= his series is to allow mapping non-refcounted struct page memory into KVM guest= . Those details were brought up purely because they provide context on how/wh= y such non-refcounted pages exist. > It can trivially be that userspace only maps 4KiB of some 2MiB piece of > memory the driver has allocate. > > > I.e. Christoph is (implicitly) saying that instead of modifying KVM to = play nice, > > we should instead fix the TTM allocations. And David pointed out that = that was > > tried and got NAK'd. >=20 > Well as far as I can see Christoph rejects the complexity coming with the > approach of sometimes grabbing the reference and sometimes not. Unless I've wildly misread multiple threads, that is not Christoph's object= ion. From v9 (https://lore.kernel.org/all/ZRpiXsm7X6BFAU%2Fy@infradead.org): On Sun, Oct 1, 2023 at 11:25=E2=80=AFPM Christoph Hellwig wrote: > > On Fri, Sep 29, 2023 at 09:06:34AM -0700, Sean Christopherson wrote: > > KVM needs to be aware of non-refcounted struct page memory no matter = what; see > > CVE-2021-22543 and, commit f8be156be163 ("KVM: do not allow mapping v= alid but > > non-reference-counted pages"). =C2=A0I don't think it makes any sense= whatsoever to > > remove that code and assume every driver in existence will do the rig= ht thing. > > Agreed. > > > > > With the cleanups done, playing nice with non-refcounted paged instea= d of outright > > rejecting them is a wash in terms of lines of code, complexity, and o= ngoing > > maintenance cost. > > I tend to strongly disagree with that, though. =C2=A0We can't just let = these > non-refcounted pages spread everywhere and instead need to fix their > usage. > And I have to agree that this is extremely odd. Yes, it's odd and not ideal. But with nested virtualization, KVM _must_ "m= ap" pfns directly into the guest via fields in the control structures that are consumed by hardware. I.e. pfns are exposed to the guest in an "out-of-ban= d" structure that is NOT part of the stage-2 page tables. And wiring those up= to the MMU notifiers is extremely difficult for a variety of reasons[*]. Because KVM doesn't control which pfns are mapped this way, KVM's compromis= e is to grab a reference to the struct page while the out-of-band mapping exists= , i.e. to pin the page to prevent use-after-free. And KVM's historical ABI is to = support any refcounted page for these out-of-band mappings, regardless of whether t= he page was obtained by gup() or follow_pte(). Thus, to support non-refouncted VM_PFNMAP pages without breaking existing u= serspace, KVM resorts to conditionally grabbing references and disllowing non-refcoun= ted pages from being inserted into the out-of-band mappings. But again, I don't think these details are relevant to Christoph's objectio= n. [*] https://lore.kernel.org/all/ZBEEQtmtNPaEqU1i@google.com