Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3657782ybt; Tue, 30 Jun 2020 08:16:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9FWEO77gsxVVGl3g8eUHjjRi+yuxgxo6XvDrbZ5E0gTINMrWxJBzdse2MlLyy4qKcPvXc X-Received: by 2002:aa7:c407:: with SMTP id j7mr23410587edq.96.1593530159929; Tue, 30 Jun 2020 08:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593530159; cv=none; d=google.com; s=arc-20160816; b=kMKAV3eq3XnqDgkxXlmgXeqLO4wCl5WRNTvduQtrLSa9pkz8LLS08C/eEz1y+Dyyid oAwI+FtHFqxQA2FhTVDyacSku1PhUzIyROPpk2Pw7d4e+Ou0TENUcw4Q3Jq+jR2lRFM2 pb50lPJVR39wI/jaiOeyW/RqRUw98/wpKFL9dg0a7Vw7auhdCnUxOWuF+Sanys+0oS3S Q2XiWX/QNjbiNK5A+fmCih2JisKgzyCwG4byBWGzjPK6OqOeJcUnPn76HImNomJpfE2E 9UrLbwCT3dGF39cxOA3+DAnnzGyQ8OIMdrZxxObqXvVq/6eAG0xwzgEJk6jmtMQQNkF2 TrLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=ZKG9midKxWXapiyhsCNvJA81s4+MOL+9sOnG0fsdr5k=; b=GU0nFYRYRgPT1OynhUEQNwXjxOVt0tAWyK6IRBPnBCk6UPvwpg/bnGutGAufpCTey4 GGFMlqjxHtEiY+zBwDVPk+V7pvewd9YS+qYzo/DUY7thx7X7Xrqx4aB/27FYqzN+QY6Y 4BSkm3/wfOGRCDhYoYux7TTXlfZSnUaXaGFi3B05QejqjJ812D0RWi/APtNYBfLKM0/X bM5U29csQ7ccqu4+7tQyTVrvu/sQ851BbrzbaEEMEeVyKth4VTEPA1tBpouRkkR5JcAh JG0OMqPU4JtUzAZrQYDve52hXG1qYRv0umLUbcPsMcMBA+OPXedqiK531OwSzqAq2yUW DaQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fV9N6K4d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si1968086edb.402.2020.06.30.08.15.36; Tue, 30 Jun 2020 08:15:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fV9N6K4d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389301AbgF3POD (ORCPT + 99 others); Tue, 30 Jun 2020 11:14:03 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:25416 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389254AbgF3POB (ORCPT ); Tue, 30 Jun 2020 11:14:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593530040; 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: in-reply-to:in-reply-to:references:references; bh=ZKG9midKxWXapiyhsCNvJA81s4+MOL+9sOnG0fsdr5k=; b=fV9N6K4de3YD4mme2gOQ7N/HzlFz29P1kIOZ1nwnIQ3q6N3izRpvJUOg7ooDDBLoADWXvl NVS3ioAAQ4mfg36th1VwYNz1e8bfDJHPbElqWDW4MNR1adTd9Y90GUwozrXAY2uYI9d7JM X6YDbqizUizjeaSFTzJaEmDPajq+ROI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-446-Mdczr8iiNquqqzT3WSBDFQ-1; Tue, 30 Jun 2020 11:13:58 -0400 X-MC-Unique: Mdczr8iiNquqqzT3WSBDFQ-1 Received: by mail-ej1-f69.google.com with SMTP id gz3so13267148ejb.13 for ; Tue, 30 Jun 2020 08:13:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=ZKG9midKxWXapiyhsCNvJA81s4+MOL+9sOnG0fsdr5k=; b=huSO9EzsRZidFF3DBmqcXqundhAl6m/9jsopkvhLEiRiRYu7IXCUi6XWL0M8KYHaV2 sUXp8H6N2hHd9cAYeZxep8euM2cePpWf0/MvcnrRE+qwG+T5TUUB8UXhMsuH/cnp3DZ7 uK9JPEyoLgVTOXgnpt+s+m371rl2sISyHnotyLRlov1dU97Uof3WDNfMh9loTACtGjQZ jHRhO9u1fhXd2n9FM5HlJVGMJapqfDwst+RdXnhKffJQYKtTC4yjVBekNAf4D3sy3eO6 tVp2eJdBRTQ3M9pCQNpW7pVatzbJNzTE0x3Dg7XsF0jquDMZYqn1VgxVBPYppZAe17+T uN3g== X-Gm-Message-State: AOAM5304QKSaQF+Cwe7CHcPE+0zJMhaBwVawuwZnnQJCXNYg0S7iqPuq v9u87GApxto8WNM4P0avLg0XOamCzPQYDN/wzDWfKzG/2mSqYd7cng7Kp/AoayMrSXRiyQ+V9EY gaItSv45vzGYi39lho8TRXp7k X-Received: by 2002:a17:906:4b59:: with SMTP id j25mr14217934ejv.301.1593530037379; Tue, 30 Jun 2020 08:13:57 -0700 (PDT) X-Received: by 2002:a17:906:4b59:: with SMTP id j25mr14217917ejv.301.1593530037138; Tue, 30 Jun 2020 08:13:57 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id w24sm3145277edt.28.2020.06.30.08.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 08:13:55 -0700 (PDT) From: Vitaly Kuznetsov To: Vivek Goyal Cc: kvm@vger.kernel.org, virtio-fs@redhat.com, pbonzini@redhat.com, sean.j.christopherson@intel.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] kvm,x86: Exit to user space in case of page fault error In-Reply-To: <20200630145303.GB322149@redhat.com> References: <20200625214701.GA180786@redhat.com> <87lfkach6o.fsf@vitty.brq.redhat.com> <20200626150303.GC195150@redhat.com> <874kqtd212.fsf@vitty.brq.redhat.com> <20200629220353.GC269627@redhat.com> <87sgecbs9w.fsf@vitty.brq.redhat.com> <20200630145303.GB322149@redhat.com> Date: Tue, 30 Jun 2020 17:13:54 +0200 Message-ID: <87mu4kbn7x.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vivek Goyal writes: > On Tue, Jun 30, 2020 at 03:24:43PM +0200, Vitaly Kuznetsov wrote: >> >> It's probably me who's missing something important here :-) but I think >> you describe how it *should* work as I'm not seeing how we can leave the >> loop in kvm_async_pf_task_wait_schedule() other than by >> "if (hlist_unhashed(&n.link)) break;" and this only happens when APF >> completes. > > We don't leave loop in kvm_async_pf_task_wait_schedule(). It will happen > before you return to user space. > > I have not looked too closely but I think following code path might be taken > after aync PF has completed. > > __kvm_handle_async_pf() > idtentry_exit_cond_rcu() > prepare_exit_to_usermode() > __prepare_exit_to_usermode() > exit_to_usermode_loop() > do_signal() > > So once you have been woken up (because APF completed), Ah, OK so we still need to complete APF and we can't kill the process before this happens, that's what I was missing. > you will > return to user space and before that you will check if there are > pending signals and handle that signal first before user space > gets a chance to run again and retry faulting instruction. ... > >> >> When guest receives the 'page ready' event with an error it (like for >> every other 'page ready' event) tries to wake up the corresponding >> process but if the process is dead already it can do in-kernel probing >> of the GFN, this way we guarantee that the error is always injected. I'm >> not sure if it is needed though but in case it is, this can be a >> solution. We can add a new feature bit and only deliver errors when the >> guest indicates that it knows what to do with them. > > - Process will be delivered singal after async PF completion and during > returning to user space. You have lost control by then. > So actually there's no way for kernel to know if the userspace process managed to re-try the instruction and get the error injected or if it was killed prior to that. > - If you retry in kernel, we will change the context completely that > who was trying to access the gfn in question. We want to retain > the real context and retain information who was trying to access > gfn in question. (Just so I understand the idea better) does the guest context matter to the host? Or, more specifically, are we going to do anything besides get_user_pages() which will actually analyze who triggered the access *in the guest*? -- Vitaly