Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp115195rwd; Wed, 17 May 2023 15:38:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D2//ftsu4MIEvRDeDJp7K94YubKW6dgaKR4Rk9PIxiFJHDyFxQbpRrevsaXlVWk0wgHPA X-Received: by 2002:a05:6a20:734f:b0:107:35ed:28b5 with SMTP id v15-20020a056a20734f00b0010735ed28b5mr7188737pzc.2.1684363113869; Wed, 17 May 2023 15:38:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684363113; cv=none; d=google.com; s=arc-20160816; b=KKzKI2Ak20RFKK/vAIcQ6sPhnbOAlPNdPGBqbytk1kc8DCR3b3MuzZ0brwWiWJa5YH ZYx4x5X0YVPoq41DblL9gu0eTToIoAmJNQ0ohn5vb8vHHPaEkxf0BbUd3vyBUlPDnTsb J267VIkMYR/eIHc0+8EwedX2yp2rpmyK2BMsbPk1Ye3HTSl/0ceGSyMX2SiYIx4Fm8kg mktLyecUHaWLKfEqw1QmoPS9PBwHcuVGXhJb7cT3GJe97UFYCSHWhLKa6O/5tN0nPdLn joH/ZsnYWRXSK1ie/7VGQbDVcMuzyzHLwA5O2c6OpKkts0o+nI/83pAt/xGTcukgcDGU L/dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=d2BAYWqQjLBVkE55QBWk4MFNy2EEFsBkFqfU0qi3jzc=; b=Ln8+FbkloXzurgsBZNHyH3nK44bWwXnuSZDzRUJG0k1UMk/yfNl4CX1bBwzzsxNXYH tcOmfHzbFlJGhRx3s31DljSeMznn74+pQARpe6U6SKN0NTtvwUaqW6ckr5ppuIhZDOfN K1LY/uNu2lNBPySKBt5Oi2ej8Vx6p+RuzXqZGpEMT/IeCmKLL3whsUOHzZsOD1aO9SV8 14QUpfHyxWEs9cbKgfb4NPgVud650iGZGev3/fG0ezKlm5Y2DQsC51ZVCiDklxlQn5J5 odceuIXJYPO71LXJZD1HxKiyFKN+21dbAXIG0x/2C+5J2AW72OKT+co8/NF8AiGT+stp ozow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M+WlNWdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a639d0a000000b0051b313bdebesi9444618pgd.1.2023.05.17.15.38.18; Wed, 17 May 2023 15:38:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M+WlNWdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbjEQW3Q (ORCPT + 99 others); Wed, 17 May 2023 18:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjEQW3P (ORCPT ); Wed, 17 May 2023 18:29:15 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E00659F4 for ; Wed, 17 May 2023 15:29:13 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-62383441211so6365756d6.0 for ; Wed, 17 May 2023 15:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684362552; x=1686954552; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=d2BAYWqQjLBVkE55QBWk4MFNy2EEFsBkFqfU0qi3jzc=; b=M+WlNWdcv9Cj8/VGWAKAsYqCgExA/M4rLKGdFF8/npUX4+QKU2Jdh4rGJInziOkc06 osc5shbKCWK2/zUsItJLjJLF8OQs4gZTwJ3KwQ/awo9F5wliR92evQJxQTr/s8VATbPn V1ciBuxnbdZYpX+lFYfWTbZ7MJoA/YCHRf7ZaRq/UZwEF3OywvlaAHY+WaapyLNudmAQ 8szFUz+2/21OEWWQPzpATMbuH+QcBzzCqGTjOG2KmIzine92NOWjNXZu0H9U/qE3Gy1R uZtzj3xFn+Y9FLGGPappEm7s5I5/dozIXeJNSS8So42TNY4NElzX9HRJyZ9BVcWNTNq5 rEDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684362552; x=1686954552; 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=d2BAYWqQjLBVkE55QBWk4MFNy2EEFsBkFqfU0qi3jzc=; b=jN26Tq1LwZJJeKVEH78sYIWuT4nGxPx0EvEQpGpfpGBosYGLJQSkmJrFXa2ZoCc9Wt 6Hdp++e734kHYchy2YFnw2Fy9bgK1tU7WyiouQBy0klZfbF3Ys9d73GfxxgxVv2xOOEQ j+5JV3TOieb4ltng+BNLe96k4MOuE/j++/t4NVNRdU6AzBLaIKKGBDCaDLJa6poO32ic 5l9189vOMrze/FkOrXHFCXOQl1Mzm/ZEoghDQT0OYuLMTaDqxqkxiqbPOeVcfEuwv6LX PJm01uDXqkKoix2IgGz7St+QgtnpNN057WIEaXobVX+x+Ni3FfpMIH8Z9tkEFG5i40Ae c+TQ== X-Gm-Message-State: AC+VfDwDJnfBWbHD9KFR9Y7AB8K898IvtzbwoBBm/lESgDzOEMeSgySr yyx96gyTgY6zzBtrvfV+06vzfoM5jdE9vBpEhQnxbQ== X-Received: by 2002:a05:6214:518b:b0:621:64c7:235f with SMTP id kl11-20020a056214518b00b0062164c7235fmr2158490qvb.27.1684362552551; Wed, 17 May 2023 15:29:12 -0700 (PDT) MIME-Version: 1.0 References: <20230511182426.1898675-1-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Wed, 17 May 2023 15:28:36 -0700 Message-ID: Subject: Re: [PATCH 1/3] mm: userfaultfd: add new UFFDIO_SIGBUS ioctl To: Peter Xu Cc: James Houghton , Alexander Viro , Andrew Morton , Christian Brauner , David Hildenbrand , Hongchen Zhang , Huang Ying , "Liam R. Howlett" , Miaohe Lin , "Mike Rapoport (IBM)" , Nadav Amit , Naoya Horiguchi , Shuah Khan , ZhangPeng , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Anish Moorthy , Jiaqi Yan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 17, 2023 at 3:20=E2=80=AFPM Peter Xu wrote: > > On Wed, May 17, 2023 at 06:12:33PM -0400, Peter Xu wrote: > > On Thu, May 11, 2023 at 03:00:09PM -0700, James Houghton wrote: > > > On Thu, May 11, 2023 at 11:24=E2=80=AFAM Axel Rasmussen > > > wrote: > > > > > > > > So the basic way to use this new feature is: > > > > > > > > - On the new host, the guest's memory is registered with userfaultf= d, in > > > > either MISSING or MINOR mode (doesn't really matter for this purp= ose). > > > > - On any first access, we get a userfaultfd event. At this point we= can > > > > communicate with the old host to find out if the page was poisone= d. > > > > - If so, we can respond with a UFFDIO_SIGBUS - this places a swap m= arker > > > > so any future accesses will SIGBUS. Because the pte is now "prese= nt", > > > > future accesses won't generate more userfaultfd events, they'll j= ust > > > > SIGBUS directly. > > > > > > I want to clarify the SIGBUS mechanism here when KVM is involved, > > > keeping in mind that we need to be able to inject an MCE into the > > > guest for this to be useful. > > > > > > 1. vCPU gets an EPT violation --> KVM attempts GUP. > > > 2. GUP finds a PTE_MARKER_UFFD_SIGBUS and returns VM_FAULT_SIGBUS. > > > 3. KVM finds that GUP failed and returns -EFAULT. > > > > > > This is different than if GUP found poison, in which case KVM will > > > actually queue up a SIGBUS *containing the address of the fault*, and > > > userspace can use it to inject an appropriate MCE into the guest. Wit= h > > > UFFDIO_SIGBUS, we are missing the address! > > > > > > I see three options: > > > 1. Make KVM_RUN queue up a signal for any VM_FAULT_SIGBUS. I think > > > this is pointless. > > > 2. Don't have UFFDIO_SIGBUS install a PTE entry, but instead have a > > > UFFDIO_WAKE_MODE_SIGBUS, where upon waking, we return VM_FAULT_SIGBUS > > > instead of VM_FAULT_RETRY. We will keep getting userfaults on repeate= d > > > accesses, just like how we get repeated signals for real poison. > > > 3. Use this in conjunction with the additional KVM EFAULT info that > > > Anish proposed (the first part of [1]). > > > > > > I think option 3 is fine. :) > > > > Or... option 4) just to use either MADV_HWPOISON or hwpoison-inject? :) > > I just remember Axel mentioned this in the commit message, and just in ca= se > this is why option 4) was ruled out: > > They expect that once poisoned, pages can never become > "un-poisoned". So, when we live migrate the VM, we need to preser= ve > the poisoned status of these pages. > > Just to supplement on this point: we do have unpoison (echoing to > "debug/hwpoison/hwpoison_unpoison"), or am I wrong? > > > > > Besides what James mentioned on "missing addr", I didn't quickly see wh= at's > > the major difference comparing to the old hwpoison injection methods ev= en > > without the addr requirement. If we want the addr for MCE then it's mor= e of > > a question to ask. > > > > I also didn't quickly see why for whatever new way to inject a pte erro= r we > > need to have it registered with uffd. Could it be something like > > MADV_PGERR (even if MADV_HWPOISON won't suffice) so you can inject even > > without an userfault context (but still usable when uffd registered)? > > > > And it'll be alawys nice to have a cover letter too (if there'll be a n= ew > > version) explaining the bits. I do plan a v2, if for no other reason than to update the documentation. Happy to add a cover letter with it as well. +Jiaqi back to CC, this is one piece of a larger memory poisoning / recovery design Jiaqi is working on, so he may have some ideas why MADV_HWPOISON or MADV_PGER will or won't work. One idea is, at least for our use case, we have to have the range be userfaultfd registered, because we need to intercept the first access and check at that point whether or not it should be poisoned. But, I think in principle a scheme like this could work: 1. Intercept first access with UFFD 2. Issue MADV_HWPOISON or MADV_PGERR or etc to put a pte denoting the poisoned page in place 3. UFFDIO_WAKE to have the faulting thread retry, see the new entry, and SI= GBUS It's arguably slightly weird, since normally UFFD events are resolved with UFFDIO_* operations, but I don't see why it *couldn't* work. Then again I am not super familiar with MADV_HWPOISON, I will have to do a bit of reading to understand if its semantics are the same (future accesses to this address get SIGBUS). > > > > Thanks, > > > > -- > > Peter Xu > > -- > Peter Xu >