From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C479C433F5 for ; Fri, 24 Sep 2021 20:09:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 209FF61107 for ; Fri, 24 Sep 2021 20:09:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 209FF61107 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5DD426B0071; Fri, 24 Sep 2021 16:09:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 565716B0072; Fri, 24 Sep 2021 16:09:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E0196B0073; Fri, 24 Sep 2021 16:09:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 2BA176B0071 for ; Fri, 24 Sep 2021 16:09:42 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DE5A127777 for ; Fri, 24 Sep 2021 20:09:41 +0000 (UTC) X-FDA: 78623557362.29.A819061 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 91652600198B for ; Fri, 24 Sep 2021 20:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632514181; 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=JF7bGwTByYC0+rcfVC0+8sx246e3qoBcuxrMSDsRAXE=; b=XkSfMLSGLD6G8FoiQMIHJsYsIF490eb7h55tQVPdgCJH1ftsLWb8OJRtW0U8C79oefkLMI X9JmiWs/xJYrg0E8cuOGgTTQ7pzOy5bHErcCEaPHzNWC0nLqtJXNuRYUz0Sg1XtuhQC9CZ c7BsjRWdgLlMNlwMQ9nBYqcnwSh0uy8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-w2hheMGUPaa9_X-wCp4owQ-1; Fri, 24 Sep 2021 16:09:39 -0400 X-MC-Unique: w2hheMGUPaa9_X-wCp4owQ-1 Received: by mail-qt1-f198.google.com with SMTP id o7-20020ac86d07000000b002a69537d614so37529475qtt.21 for ; Fri, 24 Sep 2021 13:09:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JF7bGwTByYC0+rcfVC0+8sx246e3qoBcuxrMSDsRAXE=; b=DL67bLfc0w7J0qyghvufUlS4ePUWwqZA31J5NrT04UCNerCSGlaM6WRjSd7aoi9fOa 2rNIfkzCZN7X1EBS2qS33+fOfPCioAy2qOjzTM+xUIyFZHUqqgfBxNLiJFbSVA3tVdUv HLAGT25CUBYBVXW832rpFzElLQ+6f9G16K2jFtw6EZFo7RR3d0aHcfaMEmPANlfxEzBL 1TzTqDUdjhPbNS3Ybkhcu3VwwB66jGpnJT47YJ/aNT11TrCgIHJDwfzx9AoimGy5nZgE dOwBfXDCYcQ/VhVnmUyMwrd9hTqtIp6Wg0FVmc65tG6p4/ZldHmgtehbTc+kdJcgnObN zhvw== X-Gm-Message-State: AOAM530HhmYpIAReCIKi6FF4WawPIjVhyk2dC4C1eLyYhUQQtopBebo+ x4TP4RL/aSk8AmyRlfQkl32ocYSJ5YfR+tFxIte2LcGOvEfstZ4LouQKtC7ptJ7jgdR+27odrii rkdSRLvA9I+U= X-Received: by 2002:a37:a943:: with SMTP id s64mr12516643qke.422.1632514179212; Fri, 24 Sep 2021 13:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3gxLjGPmfLb2ZJlaFoBhFN2L9UI1Qd+uCG2DUMhvj32SghjV5co3PJAnbwRLS3/NhRODzVw== X-Received: by 2002:a37:a943:: with SMTP id s64mr12516610qke.422.1632514178902; Fri, 24 Sep 2021 13:09:38 -0700 (PDT) Received: from t490s ([2607:fea8:56a2:9100::d3ec]) by smtp.gmail.com with ESMTPSA id x18sm7190271qkx.94.2021.09.24.13.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 13:09:38 -0700 (PDT) Date: Fri, 24 Sep 2021 16:09:37 -0400 From: Peter Xu To: Jue Wang Cc: James Houghton , Axel Rasmussen , Andrew Morton , Shuah Khan , Linux MM , Linuxkselftest , LKML Subject: Re: [PATCH 1/3] userfaultfd/selftests: fix feature support detection Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XkSfMLSG; spf=none (imf10.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 91652600198B X-Stat-Signature: 7bnwjorjcsz81irkwf9hw6gwgegh11wa X-HE-Tag: 1632514181-687478 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Sep 22, 2021 at 10:43:40PM -0700, Jue Wang wrote: [...] > > > Could I know what's the workaround? Normally if the workaround works solidly, > > > then there's less need to introduce a kernel interface for that. Otherwise I'm > > > glad to look into such a formal proposal. > > > > The workaround is, for the region that you want to zap, run through > > this sequence of syscalls: mumap, mmap, and re-register with > > userfaultfd if it was registered before. If we're using tmpfs, we can > > use madvise(DONTNEED) instead, but this is kind of an abuse of the > > API. I don't think there's a guarantee that the PTEs will get zapped, > > but currently they will always get zapped if we're using tmpfs. I > > really like the idea of adding a new madvise() mode that is guaranteed > > to zap the PTEs. I see. > > > > > > > > > It's also useful for memory poisoning, I think, if the host > > > > decides some page(s) are "bad" and wants to intercept any future guest > > > > accesses to those page(s). > > > > > > Curious: isn't hwpoison information come from MCEs; or say, host kernel side? > > > Then I thought the host kernel will have full control of it already. > > > > > > Or there's other way that the host can try to detect some pages are going to be > > > rotten? So the userspace can do something before the kernel handles those > > > exceptions? > > > > Here's a general idea of how we would like to use userfaultfd to support MPR: > > > > If a guest accesses a poisoned page for the first time, we will get an > > MCE through the host kernel and send an MCE to the guest. The guest > > will now no longer be able to access this page, and we have to enforce > > this. After a live migration, the pages that were poisoned before > > probably won't still be poisoned (from the host's perspective), so we > > can't rely on the host kernel's MCE handling path. This is where > > userfaultfd and this new madvise mode come in: we can just > > madvise(MADV_ZAP) the poisoned page(s) on the target during a > > migration. Now all accesses will be routed to the VMM and we can > > inject an MCE. We don't *need* the new madvise mode, as we can also > > use fallocate(PUNCH_HOLE) (works for tmpfs and hugetlbfs), but it > > would be more convenient if we didn't have to use fallocate. > > > > Jue Wang can provide more context here, so I've cc'd him. There may be > > some things I'm wrong about, so Jue feel free to correct me. > > > James is right. > > The page is marked PG_HWPoison in the source VM host's kernel. The need > of intercepting guest accesses to it exist on the target VM host, where > the same physical page is no longer poisoned. > > On the target host, the hypervisor needs to intercept all guest accesses > to pages poisoned from the source VM host. Thanks for these information, James, Jue, Axel. I'm not familiar with memory failures yet, so please bare with me with a few naive questions. So now I can undertand that hw-poisonsed pages on src host do not mean these pages will be hw-poisoned on dest host too, but I may have missed the reason on why dest host needs to trap it with pgtable removed. AFAIU after pages got hw-poisoned on src, and after vmm injects MCEs into the guest, the guest shouldn't be accessing these pages any more, am I right? Then after migration completes, IIUC the guest shouldn't be accessing these pages too. My current understanding is, instead of trapping these pages on dest, we should just (somehow, which I have no real idea...) un-hw-poison these pages after migration because these pages are very possibly normal pages there. When there's real hw-poisoned pages reported on dst host, we should re-inject MCE errors to guest with another set of pages. Could you tell me where did I miss? Thanks, -- Peter Xu