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 X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70589C433FE for ; Fri, 4 Dec 2020 16:50:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F1D23229C9 for ; Fri, 4 Dec 2020 16:50:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1D23229C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6213B6B005C; Fri, 4 Dec 2020 11:50:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D28B6B005D; Fri, 4 Dec 2020 11:50:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 471536B006E; Fri, 4 Dec 2020 11:50:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 30D7E6B005C for ; Fri, 4 Dec 2020 11:50:44 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EF39E82499A8 for ; Fri, 4 Dec 2020 16:50:43 +0000 (UTC) X-FDA: 77556188766.07.pet87_1514934273c6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id D25541803F9AB for ; Fri, 4 Dec 2020 16:50:43 +0000 (UTC) X-HE-Tag: pet87_1514934273c6 X-Filterd-Recvd-Size: 8445 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Fri, 4 Dec 2020 16:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607100642; 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=zDhBYbRigRgMTSkYx/CVXw2uLJGwUrrBAdj8JD7lMUg=; b=LM+W433ez3uAyKLoOEvK6oG4JBEYjr3XtKZn+ZZc6XOBZGSrl0BSN56q5KhPi79t8w0dn9 ECF9eHpIs31TYeClQcPc3gNXmJWCnfZTnlIZ3U8pLZLBJcITK/caL1HSEp96N0wZjhb0w1 lo4ZSxvS13aWGSb407QkZdvKoOIU15w= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-aImqt_p1NQy2QnTnuErv7Q-1; Fri, 04 Dec 2020 11:50:40 -0500 X-MC-Unique: aImqt_p1NQy2QnTnuErv7Q-1 Received: by mail-qv1-f70.google.com with SMTP id e13so5182508qvl.19 for ; Fri, 04 Dec 2020 08:50:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zDhBYbRigRgMTSkYx/CVXw2uLJGwUrrBAdj8JD7lMUg=; b=l9hQNabMwNhLaQD5ezal1K+r7ax1bs6nk3kyeAQP0GlW4dTpOr5ZOa4OoN/VSU/93K zJYm2Zjt4nkRfRyVPfEB0OrxW0Rgzt2/ufbZAC7d/GWN4yP6NPRWVQae8KNdoZ+BzGaV Qzs93uRwUSr1RSwIwsyIAvwHBkLvbJ9RuiJZib8ZBAW/l8dpz3e6alj1MajMHmS6G+uD ePZBA7h6XZ5DDIEHes0tqKViN09inHUsZ5HXfldr3iqz3bmmUQbFXTMsyP0ANmBOQpUY 6Sc57lqI2E7xNTEn/NKcTKz0wFMZc43kbg6keZyJ5avydCBZvGWVAUS5KMtuDJsDYFTK LEmA== X-Gm-Message-State: AOAM530wJtrpZuxzuiS5CGptyUVj+pcT2jkGoxLq3EDiaO0ITPGABjzv t5SYoW1WAUiqoW9Vs25yMMbkQhuBMo2kRXaElBCNDiOBSMIyv0R6GpZxYiuI5YGHFeNG3YrToX5 I5C9wf0C+3Gc= X-Received: by 2002:ad4:4721:: with SMTP id l1mr6291651qvz.30.1607100640395; Fri, 04 Dec 2020 08:50:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8W9b0aSUJfDvIEMvltM32sy3kNaRtXFC+CMBz4UfuCjwXh+5TkjCxjHAEajE1cv4frgwCXQ== X-Received: by 2002:ad4:4721:: with SMTP id l1mr6291629qvz.30.1607100640106; Fri, 04 Dec 2020 08:50:40 -0800 (PST) Received: from xz-x1 ([142.126.94.187]) by smtp.gmail.com with ESMTPSA id x28sm4200117qtv.8.2020.12.04.08.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 08:50:39 -0800 (PST) Date: Fri, 4 Dec 2020 11:50:37 -0500 From: Peter Xu To: Hugh Dickins Cc: Andrea Arcangeli , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mike Rapoport , David Hildenbrand Subject: Re: [PATCH v2] mm: Don't fault around userfaultfd-registered regions on reads Message-ID: <20201204165037.GN108496@xz-x1> References: <20201201223033.GG3277@xz-x1> <20201202234117.GD108496@xz-x1> <20201203180234.GJ108496@xz-x1> <20201204023051.GL108496@xz-x1> MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Dec 03, 2020 at 09:59:50PM -0800, Hugh Dickins wrote: > On Thu, 3 Dec 2020, Andrea Arcangeli wrote: > > On Thu, Dec 03, 2020 at 09:30:51PM -0500, Peter Xu wrote: > > > I'm just afraid there's no space left for a migration entry, because migration > > > entries fills in the pfn information into swp offset field rather than a real > > > offset (please refer to make_migration_entry())? I assume PFN can use any bit. > > > Or did I miss anything? > > > > > > I went back to see the original proposal from Hugh: > > > > > > IIUC you only need a single value, no need to carve out another whole > > > swp_type: could probably be swp_offset 0 of any swp_type other than 0. > > > > > > Hugh/Andrea, sorry if this is a stupid swap question: could you help explain > > > why swp_offset=0 won't be used by any swap device? I believe it's correct, > > > it's just that I failed to figure out the reason myself. :( > > > > > It's because swp_offset 0 is the offset of the swap header, and if we > ever used that when allocating swap, then the swap header would get > overwritten, and that swap area become unrecognizable next time. > > But I said it would be usable for UFFD with any swp_type other than 0, > because a swap entry of type 0, offset 0 is simply 0, which looks just > like no swap entry at all, and there are (or were: I might not be > up-to-date) benign races where a swap entry might get passed down but > then found to be 0, and that was understandable and permitted (yes, > I still see the "if (!entry.val) goto out;" in __swap_info_get()). > > And that might be related to pte_none() being 0 on most architectures > (not s390 IIRC): we need to distinguish none from swap. Though that > all gets complicated by the way the swp_entry is munged before being > put into a pte, and the x86 swap munging got more complicated when > L1TF was revealed (and accompanied by prot none munging too) - > search git log of v4.19 for x86/speculation/l1tf if you need to. My thanks to both of you for explaining the details. > > > > > Hugh may want to review if I got it wrong, but there's basically three > > ways. > > > > swp_type would mean adding one more reserved value in addition of > > SWP_MIGRATION_READ and SWP_MIGRATION_WRITE (kind of increasing > > SWP_MIGRATION_NUM to 3). > > I'm not very keen on actually using any of the SWP_MIGRATION defines, > partly because in principle UFFD should not depend on CONFIG_MIGRATION, > partly because the uffd_wp entry would not behave anything like a > migration entry (whose pfn should always indicate a locked page). > > swp_offset 0 of swp_type 1 perhaps? > > > > > swp_offset = 0 works in combination of SWP_MIGRATION_WRITE and > > SWP_MIGRATION_READ if we enforce pfn 0 is never used by the kernel > > (I'd feel safer with pfn value -1UL truncated to the bits of the swp > > offset, since the swp_entry format is common code). > > > > The bit I was suggesting is just one more bit like _PAGE_SWP_UFFD_WP > > from the pte, one that cannot ever be set in any swp entry today. I > > assume it can't be _PAGE_SWP_UFFD_WP since that already can be set but > > you may want to verify it... > > I don't see why you would need another bit for this. > > The code that checks non-present non-none entries in page table, > for whether they are actually swap or migration entries or whatever, > would now also check for swp_offset 0 of swp_type 1 and go off to > the UFFD WP processing if so. > > I didn't pay much attention to below, it seemed over-complicated. > And I don't think Peter's PROT_NONE alternative was unworkable, > but would have to be more careful about pfn and L1TF than shown. > And I am more comfortable to focus on the swap-like direction, > than think in two directions at once - never my strength! Yes, I think both of them may work, but I'll follow your advise on using swap entries, assuming easier and cleaner than _PAGE_PROTNONE. For example, current pte_present() does make more sense to return false for such an uffd-wp reserved pte. Then I won't make _PAGE_PROTNONE even more complicated too. So I guess I'll start with type==1 && offset==0. (PS: I still think "swp_entry(0, _UFFD_SWP_UFFD_WP) && !vma_is_anonymous(vma)" could also be a good candidate comparing to "swp_entry(1, 0)" considering type==1 here is kind of randomly chosen from all the other numbers except 0; but maybe that's not extremely important - the major logic should be the same) Thanks! -- Peter Xu