Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29290161rwd; Wed, 5 Jul 2023 09:40:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlGC2qy7atRiZfB1yCx4uznIJViD2+pMS3wE/f3CvnBnCO1JSCyG4GXlXh6jcWbr4MOO0sKg X-Received: by 2002:a05:6a21:7898:b0:12e:7ca3:e22 with SMTP id bf24-20020a056a21789800b0012e7ca30e22mr11863825pzc.27.1688575254460; Wed, 05 Jul 2023 09:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688575254; cv=none; d=google.com; s=arc-20160816; b=jHJk4yIIs+TrLrzgr5vkwPs+clDpOhBn6zItWwO5zM/Pk4TT6CJmbtFzfkvNz9GdSF 82uLvb58FSlQUO/5OvGFcLqNCsEsOtZkJfYynVgf1UUkSOjdtsdMsddN3xZX0vfZvh+x gUuaYWWnvUIm/J0hlUrkft7Q4ZNZMdGEQHBd/anOMhvVtwv8lgBRvyniUjigz0YYAwTl rG4U6FAUgJgjjZAsCag/Woz/HXtATySV/bY8gpMALpCLI2n/4RqjIZijzsW0SUnwwioo Jt8IUyxU/D3P9Lc9+KrI/Q9uOyGUdO9yj94ae4qsATy/G3GIIdRxDqoyWwslYOr2ox2e puOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=41PfzToKq/ZuIyZbmkk75ijXjF0S6iwGioZqQv3YYas=; fh=jstJzqPXlyB1/5on9hwdG/WwGIvuQQ+XKaE5FzcZpLk=; b=TaU472FRS21SVosn2h0tD1CoVgIYE4OgmU+u+T2jkjR5CE9XF6OLADgb1F7XFazcZ1 yMH/NKdaMXcSJtQYrNLUP8UeF+1eB7ecGHmj7JE2kHFpvzOiLReoP7dnLfqZ/YEh/thb A4yDKb49Hx+um+1dIxY1inRGtvvefq4YzdQoEhPxvV3ShHd80Km0qbxBaCxq8f2LQHYv UBF5vqtF82zFhRJS3GjcOcaITA2hed/r09v/+lcyoWpRjyMg8KK60ACHf9Ff89OXdcW2 MBGR+xe58vJRjJ/Sxbn6H+3gDCP5+6v2WJRO6lD1Lvc52OC25u8G4snSX4oMFnG9q5Hx X7Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WvPEzUC3; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a170902b49500b001b3cd9079basi22237853plr.118.2023.07.05.09.40.41; Wed, 05 Jul 2023 09:40:54 -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=@redhat.com header.s=mimecast20190719 header.b=WvPEzUC3; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232527AbjGEQQK (ORCPT + 99 others); Wed, 5 Jul 2023 12:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjGEQQJ (ORCPT ); Wed, 5 Jul 2023 12:16:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5DE1726 for ; Wed, 5 Jul 2023 09:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688573726; 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=41PfzToKq/ZuIyZbmkk75ijXjF0S6iwGioZqQv3YYas=; b=WvPEzUC3lj1tQOlUj9N/wJLicQhC5OzYowVlGfmvsnNbqIXFsF3WjhHi49t9lJkx822mxc QMoC4cYOM0aGYjQJEdO7X6FlywRjNuBQ5c/SnCzNp0TAGqr97T6zU+n6z7A/eD/6g9tU0r eRwJHE22oO0qTwQsQbPEoVehlC/RXP8= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-UC_MAGkpMeSHzFWc3uAtWg-1; Wed, 05 Jul 2023 12:15:25 -0400 X-MC-Unique: UC_MAGkpMeSHzFWc3uAtWg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-401e1fc831fso10145571cf.1 for ; Wed, 05 Jul 2023 09:15:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688573725; x=1691165725; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=41PfzToKq/ZuIyZbmkk75ijXjF0S6iwGioZqQv3YYas=; b=iJD2hRJnmTa3qJBff8vub51XAUkBHfASfdjDT2XHWA4WeuiS63XTrJH6tbdU/CHg6C KBgUblXO+xHUOX+8CaRjMFOHItxlT8AJtJc4wIswPAaG2NCvnfvxKa46lcnlJZRxAIOJ 1l6BNEHcR9bFEYOb2ApR8mQveIbK8V3ukw4DcKjj5xoA8CcOnhX8HHltgHQhHgcvitCT bnC6G3pKk11FM5EHput2okohYITwVc/hoTwrGALiikqKhZq0woGh/lZZwCZ3P7h35FjT eQtoBlQwka1PsBnMeeFwtISZsyx+pAQ3/dS7NIA8wPXr42Im3PQV5+ErEuFhMCKmwNsM dOlg== X-Gm-Message-State: AC+VfDwI9VyRYXEm38n96PsPgJz4mJJDV1by1zgrh4k6kyKk9y3i/4p9 +GGkJC0o9MUxj/36LwjadFZ2R+ZVy/L3PGi+qKZDKLKoTbZw0zyD4Zpuy8vAtaDC0y2vbq3IxTt 3ZhMhT4UpyPtPGNKjcV75zNhB/82sNlNx X-Received: by 2002:a05:622a:1308:b0:403:28e3:8ab7 with SMTP id v8-20020a05622a130800b0040328e38ab7mr22343565qtk.5.1688573724891; Wed, 05 Jul 2023 09:15:24 -0700 (PDT) X-Received: by 2002:a05:622a:1308:b0:403:28e3:8ab7 with SMTP id v8-20020a05622a130800b0040328e38ab7mr22343534qtk.5.1688573724597; Wed, 05 Jul 2023 09:15:24 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id e16-20020ac80110000000b0040346ce43a5sm6442576qtg.44.2023.07.05.09.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:15:24 -0700 (PDT) Date: Wed, 5 Jul 2023 12:15:22 -0400 From: Peter Xu To: James Houghton Cc: Axel Rasmussen , Alexander Viro , Andrew Morton , Christian Brauner , David Hildenbrand , Huang Ying , Hugh Dickins , Jiaqi Yan , Jonathan Corbet , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Shuah Khan , ZhangPeng , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 1/6] mm: userfaultfd: add new UFFDIO_POISON ioctl Message-ID: References: <20230629205040.665834-1-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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, Jul 05, 2023 at 09:09:19AM -0700, James Houghton wrote: > > > diff --git a/include/linux/swapops.h b/include/linux/swapops.h > > > index 4c932cb45e0b..8259fee32421 100644 > > > --- a/include/linux/swapops.h > > > +++ b/include/linux/swapops.h > > > @@ -394,7 +394,8 @@ typedef unsigned long pte_marker; > > > > > > #define PTE_MARKER_UFFD_WP BIT(0) > > > #define PTE_MARKER_SWAPIN_ERROR BIT(1) > > > -#define PTE_MARKER_MASK (BIT(2) - 1) > > > +#define PTE_MARKER_UFFD_POISON BIT(2) > > > > One more tab. > > > > Though I remembered the last time we discussed IIRC we plan to rename > > SWAPIN_ERROR and reuse it, could you explain why a new bit is still needed? > > > > I think I commented this but I'll do it again: IIUC any existing host > > swapin errors for guest pages should be reported as MCE too, afaict, > > happened in kvm context. > > I think swapin errors are treated differently than poison. Swapin > errors get VM_FAULT_SIGBUS, and poison gets VM_FAULT_HWPOISON, so > UFFDIO_POISON should also get VM_FAULT_HWPOISON (so that's what Axel > has implemented). And I think that needs a separate PTE marker. My question was, should we also make SWAPIN_ERROR return VM_FAULT_HWPOISON always? Just to recap from what I already commented above - if a guest page got error in swapin due to block sector failures, it should be treated as VM_FAULT_HWPOISON too, IMHO. IOW, I think current SWAPIN_ERROR is wrong when in kvm context and we should fix it first. > > > > > > +#define PTE_MARKER_MASK (BIT(3) - 1) > > > > > > static inline swp_entry_t make_pte_marker_entry(pte_marker marker) > > > { > > > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h > > > index ac7b0c96d351..ac8c6854097c 100644 > > > --- a/include/linux/userfaultfd_k.h > > > +++ b/include/linux/userfaultfd_k.h > > > @@ -46,6 +46,7 @@ enum mfill_atomic_mode { > > > MFILL_ATOMIC_COPY, > > > MFILL_ATOMIC_ZEROPAGE, > > > MFILL_ATOMIC_CONTINUE, > > > + MFILL_ATOMIC_POISON, > > > NR_MFILL_ATOMIC_MODES, > > > }; > > > > > > @@ -83,6 +84,9 @@ extern ssize_t mfill_atomic_zeropage(struct mm_struct *dst_mm, > > > extern ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long dst_start, > > > unsigned long len, atomic_t *mmap_changing, > > > uffd_flags_t flags); > > > +extern ssize_t mfill_atomic_poison(struct mm_struct *dst_mm, unsigned long start, > > > + unsigned long len, atomic_t *mmap_changing, > > > + uffd_flags_t flags); > > > extern int mwriteprotect_range(struct mm_struct *dst_mm, > > > unsigned long start, unsigned long len, > > > bool enable_wp, atomic_t *mmap_changing); > > > diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h > > > index 66dd4cd277bd..62151706c5a3 100644 > > > --- a/include/uapi/linux/userfaultfd.h > > > +++ b/include/uapi/linux/userfaultfd.h > > > @@ -39,7 +39,8 @@ > > > UFFD_FEATURE_MINOR_SHMEM | \ > > > UFFD_FEATURE_EXACT_ADDRESS | \ > > > UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \ > > > - UFFD_FEATURE_WP_UNPOPULATED) > > > + UFFD_FEATURE_WP_UNPOPULATED | \ > > > + UFFD_FEATURE_POISON) > > > #define UFFD_API_IOCTLS \ > > > ((__u64)1 << _UFFDIO_REGISTER | \ > > > (__u64)1 << _UFFDIO_UNREGISTER | \ > > > @@ -49,12 +50,14 @@ > > > (__u64)1 << _UFFDIO_COPY | \ > > > (__u64)1 << _UFFDIO_ZEROPAGE | \ > > > (__u64)1 << _UFFDIO_WRITEPROTECT | \ > > > - (__u64)1 << _UFFDIO_CONTINUE) > > > + (__u64)1 << _UFFDIO_CONTINUE | \ > > > + (__u64)1 << _UFFDIO_POISON) > > > #define UFFD_API_RANGE_IOCTLS_BASIC \ > > > ((__u64)1 << _UFFDIO_WAKE | \ > > > (__u64)1 << _UFFDIO_COPY | \ > > > + (__u64)1 << _UFFDIO_WRITEPROTECT | \ > > > (__u64)1 << _UFFDIO_CONTINUE | \ > > > - (__u64)1 << _UFFDIO_WRITEPROTECT) > > > + (__u64)1 << _UFFDIO_POISON) > > > > May not be a large deal, but it's still better to declare the feature & > > ioctls after all things implemented. Maybe make these few lines > > (UFFD_API*, and the new feature bit) as the last patch to enable the > > feature? > > I agree. Another option would be to have a separate feature for > UFFDIO_POISON for hugetlb, but I don't think we should do that. :) Yeah let's make the features "memory-type-free" if possible. :) Thanks, -- Peter Xu