Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp724531rdb; Fri, 26 Jan 2024 08:47:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNrD7Guj5DF5M6YMgzd1hC75ZBs67lmLGWRhyScML+5edkkb/dlYe6535ypzZi2/ZIS0jT X-Received: by 2002:a05:6358:4425:b0:176:a428:36c1 with SMTP id z37-20020a056358442500b00176a42836c1mr2698791rwc.22.1706287679184; Fri, 26 Jan 2024 08:47:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706287679; cv=pass; d=google.com; s=arc-20160816; b=G1K1wk7l1iU1y53WKW0+OehZyV6ngYJAN76K6q2sMuextcWvcaI8DoqNvJfVo9P4cg 31rFgaT1QnqsHATDpXTtzuzzCV1RM1dlEs/vvUs7AhT2eiN3PVD6PvBGsytpvGH1QLca mrm4YBau6It7g026q4UfMXAsHdeGuQZHe7FOkhn2g67JKg+HyLSzZ1oytzQr4R5m48Ih tLH5EISvIq2ifuaw6cXedWzoCx6BYPq5Cbnk6AHo44nQ8L2b4zRHP2yJH5AHp0o4FIoz Gkkg/OnAvOJZJex74MSlQiDVVdTvhnww/wYfHlUc7u8g0hk+N54DQFTjm/pAdJu0Xxwp L98Q== 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=2ZpNenkMM62G0MLKLgK9Oo0SvrSlKfpzY/Gj9FXzciw=; fh=IZqcejxgrvRuKTV2fYd4ZvglmKzKU9eGS5sLqB0Fi0w=; b=e9LOYbob8fDM1FqF1j4vJ7vHklu5jpTfr3MvcSJ+4C/4gkQCKa2Jy/Y6FE+JxVS2jk ViSuwibBXdC2/9Wr+ppXPUSAbPVhif+lfJ5QzYRF+GE4+jEhtrKdg7rHCAawGo8bD3Dy ERMQ7/jbdAe8mhyphcGVd6My4INZaqj1FprrbYgLYV0Y8+T6biV1tU09GcpbFM9nyM9d 4HUkbc+5xRbsYcyburcuSdnXR4QeR3VciXoLrFcGPXRt1tVlt0nJzmlxpcK6rTGwGYMY dcXjVuaU11VzTnwEyXFHNmeLTrRZ1nC0xzxl9WXlSzFyewhcAvrrGn4k8LSA2tj/ch8m Mjpw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NuOarXt1; 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-40353-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40353-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 bx30-20020a056a02051e00b005cdba90861asi1448712pgb.159.2024.01.26.08.47.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 08:47:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40353-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=NuOarXt1; 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-40353-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40353-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 50A7228C12E for ; Fri, 26 Jan 2024 16:39:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC1891DFC5; Fri, 26 Jan 2024 16:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NuOarXt1" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 A2A071DFE1 for ; Fri, 26 Jan 2024 16:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706287164; cv=none; b=QfvNobf3aXMUZYgU7if4LY4XMVHQRDe0UOx6yJVJYzWr6md+CdBlXr9KtkXLy8ovbWXk4PeXz3iZ+/OrVtB1mkzVVkvcwCsOnFNSnhD9WRhmnsle6IpXv09VQRc5u9JPGFyPc+HOxoErzUAgS+puOxdZkdVIppMCXqaT///b8x0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706287164; c=relaxed/simple; bh=y9OvmThwjw+K3nfMBDe1SkN9D4kRML05OGlUopManuQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ulobnu/cbv2OVtTjU5tCHHD0xwlPMZSmUU3kEyaGFbV8a5kQhDJAd4Vc+q18gx7Q1POxtsJHJ9Qa/vGLHrAZ8tCqwELJZa4t/vbRWm3l/KhX4d1kzqLv0m447bw0Gdh0zbIw9UfF9UHCbtFpb4hpz75TH+UdHlwAhaC3ys3wJVw= 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=NuOarXt1; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-602d22a54caso6702157b3.3 for ; Fri, 26 Jan 2024 08:39:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706287161; x=1706891961; 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=2ZpNenkMM62G0MLKLgK9Oo0SvrSlKfpzY/Gj9FXzciw=; b=NuOarXt1qCmZYwnOBUaQZOME0Dbqw5BZyG/4NHElLgV0/IGmROUVu7xP84pqX48Lzl XQCQ4UB6PKLeb2Y5WFjJPWwD+a43tsQdQPc9OJ9oFeCHmgr9vW2VRcwfqMJCwHs0odg2 WmqR5o+2C9x8HBkHnD2agwlNiavrCQ5vdHSdmnEz9IwVBSNJXnlHqssztx8v+CFv0uh+ 2TMjF/Tx+3BQnX4WvcghlOedVKnxDDJ7RHPJT/BSh/nQRC125Q10g1ZJp7bDJStXeLj1 i0pAa7mf2l2Me0JZmEhRBOJPo3h2LaM1Xg3Q/5Pe37O1RIsLJFNR+QZNNxpQ/rIeDoA7 c4FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706287161; x=1706891961; 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=2ZpNenkMM62G0MLKLgK9Oo0SvrSlKfpzY/Gj9FXzciw=; b=OtxhRiCKKoj+YbkIdqyhUEMKCsH8wA0bvsO4LyqnJH1MGEvH3J1DLaDNONS/HgVcc+ L0prgT1+bqObmaz2y80Y2CgMLzHYwwYQJBUnvLNOp45o3S9cktE3lN6uZDLTX+GcYWTt 67/brMN0xXbeH2IixyNAcvocr/H53oYfdRYqTQSKM/J3ouG5xaX4rjcJJphAeX33jPVC X7rzbyFQ1DYNMaN6oIKwRElDnV1IFiSdauw989TIngHHcWR8FZv9wqz1bmQ+G3Eobh/u RPxsNw9+KG/LErTe5Xo+QEfCMwU2V2ObfBRPq0pcdBtNlphRIpBIiGPvEATOGtq7UDhA 2ZRw== X-Gm-Message-State: AOJu0YzhNwOs/sFUEP1HTFxvECuWFLbUdW6+aj5u2eOK9q2mYeh8Mpdq 11Nbib2TAkrVt8td0qY/McbuvYiLvwsNkKwPj+M/8gOyVvP66WVjUpBn/LchWRH84g/efClFJ93 kfw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:4cd3:0:b0:5ff:9698:729c with SMTP id z202-20020a814cd3000000b005ff9698729cmr6889ywa.3.1706287161724; Fri, 26 Jan 2024 08:39:21 -0800 (PST) Date: Fri, 26 Jan 2024 08:39:20 -0800 In-Reply-To: <87sf2k83qb.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240110011533.503302-1-seanjc@google.com> <20240110011533.503302-4-seanjc@google.com> <87sf2k83qb.fsf@redhat.com> Message-ID: Subject: Re: [PATCH 3/4] KVM: Get reference to VM's address space in the async #PF worker From: Sean Christopherson To: Vitaly Kuznetsov Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Xu Yilun Content-Type: text/plain; charset="us-ascii" On Fri, Jan 26, 2024, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > Get a reference to the target VM's address space in async_pf_execute() > > instead of gifting a reference from kvm_setup_async_pf(). Keeping the > > address space alive just to service an async #PF is counter-productive, > > i.e. if the process is exiting and all vCPUs are dead, then NOT doing > > get_user_pages_remote() and freeing the address space asap is > > desirable. > > It took me a while to realize why all vCPU fds are managed by the same > mm which did KVM_CREATE_VM as (AFAIU) fds can be passed around. Turns > out, we explicitly forbid this in kvm_vcpu_ioctl(): > > if (vcpu->kvm->mm != current->mm || vcpu->kvm->vm_dead) > return -EIO; > > so this indeed means that grabbing current->mm in kvm_setup_async_pf() > can be avoided. I'm not sure whether it's just me or a "all vCPUs are > quired to be managed by the same mm" comment somewhere would be helpful. It's definitely not just you. Documentation/virt/kvm/* could use thorough documentation of what all in KVM relies on vCPUs, and all meaningful ioctls(), to be executed in the same mm_struct (address space). Because that requirement is pervasive throughout KVM. E.g. sharing KVM page tables across vCPUs is safe iff all vCPUs are in the same address space, otherwise the hva=>pfn translations through the memslot would diverge, mmu_notifiers would be all kinds of broken, etc.