Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1418213rda; Mon, 23 Oct 2023 11:57:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvXGMazC1NZLHcal4lXL5kx6UYsrugmxib9ljZGSmE9lBMSsfJ/PHRrsxUqaocWmneJyu+ X-Received: by 2002:a05:6a20:da93:b0:179:fbd6:95f1 with SMTP id iy19-20020a056a20da9300b00179fbd695f1mr681067pzb.26.1698087440357; Mon, 23 Oct 2023 11:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698087440; cv=none; d=google.com; s=arc-20160816; b=BahgfaKMqTPu4ve3fqcDu6at7eLUGDSr+ca6dczpvp93sZ4UE0E14bUEnAAf63FjHT ideI6bMhRyEZXqSXZ/x2ZEgcvM88jUzRkmLzRl49Ubu929Qz2ZlBCbZZej7VHHs9hZn6 WKRRhl/+Cliyvqfmv/ZvmEf0CLrPJwShelo27W6u58GMsRfTVaE/MztHWNWQrP0n5NcA TztVfbCRWygX+7WQt5FkY8jqHrB6p4zFDXX33Aws9NOIhxHJoxCsbzVGp9GTKMeHNAc+ LKFNPLhRteVJlBLg78nOcsvixvxQKiQyhAEMGAJf6YZGixfctZhmQZ+TrWcDq/vclgzk /+vg== 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=2yqqvVSxSrZk5/pIhCtZC81tg5RVxwkjwG9586NW/1Y=; fh=a2cvMOZ5X6w2qF2UEJIjTbWs+epmi2diFTXo5EHEsmo=; b=LB9yZqhK8RY6WmXtjZZXEYRsu1f3gnaYeA9lIcgtvDWeaFBZXJ3sU+QEkwkhAdPWIQ YX0EnXS15veqUsWfUFUVYDmissYitPHhsaJRmNrbkvC6D+BxBcw8YBRIn08Kc+rTyJjo 1rJZSuh8RRstD/1tM91gcHv4LD+5DxaqegrdScCVW9cpUGoLk+2cZqpUkD7vJr0OZIVj intkDAvHw6fTAx/U2zef1NTHwR2qpkaUOnnjubzej8IuINsH8zg0dDp4IfiIDo7ZAWzM nxoMW3qswbyzSZMkLSIIwWQiF+2RVwsctc++1uvddNseMf0M+GN2Fup1CIFprHIXwcKU q7qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Wk56tLmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id fc14-20020a056a002e0e00b006933e57dde4si6982533pfb.0.2023.10.23.11.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:57:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Wk56tLmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 880B68062AC3; Mon, 23 Oct 2023 11:57:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbjJWS5J (ORCPT + 99 others); Mon, 23 Oct 2023 14:57:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbjJWS5I (ORCPT ); Mon, 23 Oct 2023 14:57:08 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F00ED78 for ; Mon, 23 Oct 2023 11:57:05 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-d9ace5370a0so2826400276.0 for ; Mon, 23 Oct 2023 11:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698087424; x=1698692224; darn=vger.kernel.org; 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=2yqqvVSxSrZk5/pIhCtZC81tg5RVxwkjwG9586NW/1Y=; b=Wk56tLmfhHoxYX77HGCVbTeFROiZFFkVFLPcQwJQqM7BSRIW5v2qGxIfsFGfv+S5Dl I6UG48TfQ2ovJu1bMLmhY6Vz+0bCVJZLIgOnDbqP9k6zR/m4irt4Xspx34KpmENbUwu4 3Iqo6d9SQi5BwpCxcuwIs6Dv2KT2qvRSjXLSQrEx73ALQskoJb+MTSnGVSDQCkOucYnH HElD7bALWRZusECe9Xqm7C1LHY6frbnASp7V9UvKr9VjrEtQyBkbpqSsh/iQRhKj3XHI CsmLjh53BW9oEqb4p+5mDigjDFG3gl1LVJS36sNkRjt8nHAp+L3WcQFpW9PcisW37yth wHzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698087424; x=1698692224; 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=2yqqvVSxSrZk5/pIhCtZC81tg5RVxwkjwG9586NW/1Y=; b=isISBXJpt9S+vGJ/keLZInTyL0iji4haX8fmD2Cr96CuRndqYt5LVqBqQOSe9hqLgt O5tCgrnpeKUIz5fddzgsrCUhTlPS9iIeZ+gd02jQ51gmLGlWj+Cj1Eodg5JzqUh4EVKb BR3ba37eKGdXHTid+2sl5SSzXmQrVcUK9l3S5OCk6EXnwwEBqPutyvIjO77iCRbzlCGY F323uHToo4vpLIf1gwaT/WPhvLU9SyDYKBDYc+3zdavBvb6v6HDvHEv8ezBA86YbytIU ggeNOVZNIiupb7/WVWXWuv0fcKbhRPAJtWErpw1Epgr8NSKTG2UDwadZ98jFHRJVuNc9 1uQQ== X-Gm-Message-State: AOJu0Yz94whNcjjyo/yH9rtVOG5lUYCvJlNGAKcZoUsNYQUFGcYqlvXG f3L6XkS2mWJb5dJCVnRw7y32f0mxtMIP8e7ogZ25Nw== X-Received: by 2002:a25:410e:0:b0:d9c:a3b8:f39d with SMTP id o14-20020a25410e000000b00d9ca3b8f39dmr8025930yba.65.1698087424379; Mon, 23 Oct 2023 11:57:04 -0700 (PDT) MIME-Version: 1.0 References: <20231009064230.2952396-1-surenb@google.com> <20231009064230.2952396-3-surenb@google.com> <721366d0-7909-45c9-ae49-f652c8369b9d@redhat.com> In-Reply-To: <721366d0-7909-45c9-ae49-f652c8369b9d@redhat.com> From: Suren Baghdasaryan Date: Mon, 23 Oct 2023 11:56:50 -0700 Message-ID: Subject: Re: [PATCH v3 2/3] userfaultfd: UFFDIO_MOVE uABI To: David Hildenbrand Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 11:57:17 -0700 (PDT) On Mon, Oct 23, 2023 at 5:29=E2=80=AFAM David Hildenbrand wrote: > > Focusing on validate_remap_areas(): > > > + > > +static int validate_remap_areas(struct vm_area_struct *src_vma, > > + struct vm_area_struct *dst_vma) > > +{ > > + /* Only allow remapping if both have the same access and protecti= on */ > > + if ((src_vma->vm_flags & VM_ACCESS_FLAGS) !=3D (dst_vma->vm_flags= & VM_ACCESS_FLAGS) || > > + pgprot_val(src_vma->vm_page_prot) !=3D pgprot_val(dst_vma->vm= _page_prot)) > > + return -EINVAL; > > Makes sense. I do wonder about pkey and friends and if we even have to > so anything special. I don't see anything special done for mremap. Do you have something in mind= ? > > > + > > + /* Only allow remapping if both are mlocked or both aren't */ > > + if ((src_vma->vm_flags & VM_LOCKED) !=3D (dst_vma->vm_flags & VM_= LOCKED)) > > + return -EINVAL; > > + > > + if (!(src_vma->vm_flags & VM_WRITE) || !(dst_vma->vm_flags & VM_W= RITE)) > > + return -EINVAL; > > Why does one of both need VM_WRITE? If one really needs it, then the > destination (where we're moving stuff to). As you noticed later, both should have VM_WRITE. > > > + > > + /* > > + * Be strict and only allow remap_pages if either the src or > > + * dst range is registered in the userfaultfd to prevent > > + * userland errors going unnoticed. As far as the VM > > + * consistency is concerned, it would be perfectly safe to > > + * remove this check, but there's no useful usage for > > + * remap_pages ouside of userfaultfd registered ranges. This > > + * is after all why it is an ioctl belonging to the > > + * userfaultfd and not a syscall. > > I think the last sentence is the important bit and the comment can > likely be reduced. Ok, I'll look into shortening it. > > > + * > > + * Allow both vmas to be registered in the userfaultfd, just > > + * in case somebody finds a way to make such a case useful. > > + * Normally only one of the two vmas would be registered in > > + * the userfaultfd. > > Should we just check the destination? That makes most sense to me, > because with uffd we are resolving uffd-events. And just like > copy/zeropage we want to resolve a page fault ("userfault") of a > non-present page on the destination. I think that makes sense. Not sure why the original implementation needed the check for source too. Seems unnecessary. > > > > + */ > > + if (!dst_vma->vm_userfaultfd_ctx.ctx && > > + !src_vma->vm_userfaultfd_ctx.ctx) > > + return -EINVAL; > > > > > + > > + /* > > + * FIXME: only allow remapping across anonymous vmas, > > + * tmpfs should be added. > > + */ > > + if (!vma_is_anonymous(src_vma) || !vma_is_anonymous(dst_vma)) > > + return -EINVAL; > > Why a FIXME here? Just drop the comment completely or replace it with > "We only allow to remap anonymous folios accross anonymous VMAs". Will do. I guess Andrea had plans to cover tmpfs as well. > > > + > > + /* > > + * Ensure the dst_vma has a anon_vma or this page > > + * would get a NULL anon_vma when moved in the > > + * dst_vma. > > + */ > > + if (unlikely(anon_vma_prepare(dst_vma))) > > + return -ENOMEM; > > Makes sense. > > > + > > + return 0; > > +} > > Thanks, Suren. > -- > Cheers, > > David / dhildenb > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >