Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4291324pxb; Mon, 27 Sep 2021 13:41:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLRyCZ3ybWuPeORP5MLSRfKrJ0Q2gZOT+U/FN7KfnGQqKMrPbYeqRXjDGY0xGgMQXQ5cgU X-Received: by 2002:aa7:da98:: with SMTP id q24mr2635027eds.236.1632775272839; Mon, 27 Sep 2021 13:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632775272; cv=none; d=google.com; s=arc-20160816; b=dYJpT1NDBjv5MwUOdxJeZWQTh0G3vz6j6qqhgABvXRZxS6qr96JK2sJwCa3rF8X1Kf 9Xa9vxunXPG+t2X+jAwbr82SQLGdle/paQ3odhT/HtBwbnFQa86yz0poeDX+beDg0vK7 6ASFIbi+7Iv/wpUdflV0/yER0zFiz8GYP8vg5UBYoc4fXVkaAG4YTloAYk3TLE3Y/J5y zdAtJEav+h4wN2IrC4HicV7JpdlsvSczyMDpBm6zBmjgpF2g3cUFjJCdr/qJAl4wZF7/ nwGdYEYTSzS6B0BVHrSetFfVIBcPAmwaa04ebbpOZJnwdpObPnLSQzt4MUmZ4YB14xtq 5jPw== 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=kVhbRAJmKSprlQgg0jXpRAyAty2Z7WA2uiN0tVCX8Ys=; b=i0vmLEMiX8HZyjIG2qh04HuG3uESXF/d+5jkplzeuyY1JSPgmF2RvtVjCQv4rVvAs6 Tq8LbuiV9rIpo8IhfH2VN28bpqDWXMjhUQfP/OPdFqGAcRnNHqgK3hR68F6AR/yOdc/Z ukfxqrDURYJ2c2Wyu16bya0DbkZPofhTys/x1rDHKYmPnM6Ogv/3l46k/6w2vgyNvcqr T1CNMGIr24eA/+kxPQEozrk80jzsZABt5PA8X0xGJBxglZGJnMPJACcUNycsh33NQVr0 k2Wvx8mF1SWhkeJ+DqO1wZmGw6yy2L+KhmvalkS1Jau6hLS1rS0KhsJZ2UDj81dgm3g+ 2DNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="gL/puVNQ"; 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 x2si24028256ejy.385.2021.09.27.13.40.48; Mon, 27 Sep 2021 13:41:12 -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="gL/puVNQ"; 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 S236566AbhI0Ui6 (ORCPT + 99 others); Mon, 27 Sep 2021 16:38:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40546 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235865AbhI0Ui5 (ORCPT ); Mon, 27 Sep 2021 16:38:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632775038; 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=kVhbRAJmKSprlQgg0jXpRAyAty2Z7WA2uiN0tVCX8Ys=; b=gL/puVNQO3KYaGtpamy4HtjmX06nmvWR+xvDwj4rzZBTZ7jY7Hpu5vc+v7Q4R+HIbkSQ95 ZJOujZCwjTvpWuf0c2sR5ed3kQTo6pblVzmRAOuIyifKabBF7zOKi2pRgyqTj7+7R0L0Ex uCex6lDr5u2aC3tTdTzobUnPWqSyeCo= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-518-M5_YEQCLNzi4jgOt8B5mnA-1; Mon, 27 Sep 2021 16:37:15 -0400 X-MC-Unique: M5_YEQCLNzi4jgOt8B5mnA-1 Received: by mail-qk1-f200.google.com with SMTP id r5-20020a05620a298500b0045dac5fb940so60899934qkp.17 for ; Mon, 27 Sep 2021 13:37:15 -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=kVhbRAJmKSprlQgg0jXpRAyAty2Z7WA2uiN0tVCX8Ys=; b=e3jkG1XQ4YoNbVmjFc/aQ8svYd62yslj0TC2S4QSEQYViIrxc4zHdirsEhbdCRKEGE nAlIrd05/bBE5vtLTKtrEY8KGWJLua27bXOl83VCtB9WnGJHfVZLCV1rwCl9H97wGoYh xM7YVQD3wN0YMmRtwGbbRewUyv14JwMfyeBhJ2wE5MJEfY0vEjG0zBQBbljvGiKqkSn5 W77SBoaNuaPkPyI089pngFIsbl6zgwhoNEhwB3NnO3+qyCyfPdVe+tE+VhU5Tj6xi2ta vfYT0UcztvNEfj59FLPgWlGO5cTGtcPSiqt2gz8I2iR8vuq3mwUuxb7CqdX7UJNvMjib BjbA== X-Gm-Message-State: AOAM5339fAYFAB+h3ODa8xuflT5Uf2agWBESPtxKSqy52Tmx7NZPmKko iZtVdB6zkvE2VdXEF8YWMwtht2FAb6RZ9Wx0CEVRTyWC+nX5TZ4sgaTv9MbPRZPTUIig6Atl3jt ry6ghbmn5FH2btK4bNEMLqdrK X-Received: by 2002:a37:9c12:: with SMTP id f18mr2000950qke.18.1632775035140; Mon, 27 Sep 2021 13:37:15 -0700 (PDT) X-Received: by 2002:a37:9c12:: with SMTP id f18mr2000928qke.18.1632775034799; Mon, 27 Sep 2021 13:37:14 -0700 (PDT) Received: from t490s ([2607:fea8:56a2:9100::d3ec]) by smtp.gmail.com with ESMTPSA id j14sm11851289qtv.36.2021.09.27.13.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 13:37:14 -0700 (PDT) Date: Mon, 27 Sep 2021 16:37:12 -0400 From: Peter Xu To: Axel Rasmussen Cc: Linux MM , LKML , Andrew Morton , Andrea Arcangeli , Nadav Amit , Li Wang Subject: Re: [PATCH] mm/userfaultfd: selftests: Fix memory corruption with thp enabled Message-ID: References: <20210923232512.210092-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 10:49:39AM -0700, Axel Rasmussen wrote: > One small comment: > > I'd prefer to keep the "uffd_test_ops->release_pages(area_src);" > above, to ensure the src region is empty. It's not immediately obvious > to me that we overwrite *all* of the bytes in src when we initialize > it. (I'd have to go look at the definition of area_count and read the > loop carefully.) It may not be technically needed, but it makes the > guarantee that we're starting with a clean slate, free from any > changes from previous test cases, very clear + explicit. I think there're only two fields used, area_mutex and area_count. I'm not sure what's the initial idea from Andrea when the test case is merged, but IMHO it can be written as a struct too instead of using the long macros; struct could make it easier to undertand. And note again that we have your uffd_test_ctx_clear() called which contains munmap() of all the buffers before the release_pages() calls. It means at least for anon and shmem the pages won't be there 100% sure to me. hugetlbfs is the only one that may still keep the pages as the fs should hold another refcount on the inode, however as all the two fields got re-written anyway, so I think it'll be still very safe to drop the two release_pages(). > > Moving the release_pages(area_dst) down as you've done seems correct to me. > > Either way you can take: > > Reviewed-by: Axel Rasmussen > > > > > It's just that after the weekend when I look back I still don't see a 100% > > clean way to fix it yet. Mapping 4K PROT_NONE before/after each allocation is > > the most ideal but still looks tricky to me. > > > > Would you have time on looking for a better solution, so as to (see it a way > > to) complete what commit 8ba6e8640844 whats to do afterwards? > > Sure, it seems related to the other THP investigations we talked about > in the other thread, so I'm happy to look into it. > > Just to set expectations, progress may be slightly slow as I'm > balancing other work my employer wants done, and some upcoming time > off. But, I think with your patch the test is at least stable (not > flaky) enough that there is no *urgent* need for this, so it should be > fine. Thanks a lot on both reviewing the patch and willing to look into it. As long as we don't get any report for khugepaged (if it happens, I'll provide the PROT_NONE hack instead - that'll work 100% I believe but less clean; but for now IMHO we don't need to bother) then we don't need to rush on that. -- Peter Xu