Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp779432lqp; Thu, 21 Mar 2024 15:46:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW544U7Qgq9Nr/PiOkGdHwA20AeaVCau5wAwOxgRgSrdm3ib/kmxKB/09X8Dfe+sIZSycqTsS7wGuzO4DiC2aBE+JV7M5h6LYjFBvJG0w== X-Google-Smtp-Source: AGHT+IFXmSFndUOq2Y9uenwiKL5OsSfflIV1y61hsjosDkrnnw0T09HWUcpVBu0PizVmvoqWMJDT X-Received: by 2002:a05:6218:2613:b0:17f:1ccc:e9b with SMTP id oy19-20020a056218261300b0017f1ccc0e9bmr885639rwc.2.1711061211579; Thu, 21 Mar 2024 15:46:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711061211; cv=pass; d=google.com; s=arc-20160816; b=rXoVqAhw6ttsHh8FuAAUJRiBTVxXzfcFp+cBRbdNWT6K55BxUXpOk80UaPVLNCM07j PVeVS/I0RirrThVWJBFcKlE6F3ASQokxfEqc5BgO6MAWJbp78bW1t1dIjavYVI1Iuqd+ suwzP6SqAHAfQiqMdZ2O3IbsO1mglDttn9J1i20f8LgaRB7hAvXqG16NviNPkDXjZJCe UqZdKIwv5sJ3QnGyzS+IWSM5GgwCfblm2xLsssjisajlJY3MKyngR5NS+rrewn29Ym03 JbJGTMVwrcfZCwEv0JpGxFzc/JC6WVyVfArTbxc+L6cNcCb7KyVgdQS5Ly84/xf8SOjU KKFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=X+ogJgpF1gr7B2+yDkmrhnOgUU+a3QN7Ii9aLHiqC4o=; fh=iqEwCwwUlN+eG9hbV4l82Q5ujCywRlwXh1hXadaO5C4=; b=VHCk4cFuhgl5q2G+/QqRfmMhr7wXgsc7YFvr6fldnETsDKrqhud6r+Nd/WH36I9lGR xT9JapgRPjMWAhnGUPmPWOmvqrZMrAY9/yE/Gwo16JCdc9SI4FbZMXz7vE4u0a9uUcmb d9zPrtEGGXjmhHYGv/SPYCWtKSE+Qf9ddf4GSrzazA83sgLNxp1y3TkbHOpCbu2kFPAh WCa7vD67BzBnidRU1g8rrDrLbbEssTFi8NsKrnNpeKf2PH1S6XDJNAwcgmgN9sPH3Av0 aTfHHGyJN3A/UqYm+q1y/4i1GbpfPaYvoRCqIV94FXCk5Wi5D0FFHy04caGHHCeEh4wO AJog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dnT/TDYG"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-110770-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110770-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b26-20020a631b5a000000b005d8505c96e1si617702pgm.423.2024.03.21.15.46.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:46:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110770-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dnT/TDYG"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-110770-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110770-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 37C692823B5 for ; Thu, 21 Mar 2024 22:46:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C62F64A1D; Thu, 21 Mar 2024 22:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dnT/TDYG" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3786E15CB for ; Thu, 21 Mar 2024 22:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711061205; cv=none; b=SHjxE+U8dBpGSmGXV1kL0EsL3COmHXwuO0CXh7JmcBFzpT4BcYg2VZ1ejLHHYa0uVJfnIJpBYhvIA3Hm9RXS0oXuF6V6ot1JpTkMlNctGRI1HkAeYIheAuHYk02jT/RBvXi6e5oxWLQsEBoXiot2CO1oVuXyk1kCPzz+ULpmf8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711061205; c=relaxed/simple; bh=vNGqhhjcjfvIkP3k/1YJ9OCzOqm/zrEoLPEYsL0lby0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eAXedGX1xvehBAFFDGHOp8Ijg8AzbeHHfyrr1oNC9gs3OVuDKNjddqvnPQ940fytQDdB6LBJ/RnoqgbPmzEaWVWUZeD0MGElBlDzQKKzEaMw6VQ5VVGo/tK90qj7ZvTQQyk0xwszdktQ8f9LeSLIyIOw/zSJ9b4vNIiOxjx9S5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dnT/TDYG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711061203; 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=X+ogJgpF1gr7B2+yDkmrhnOgUU+a3QN7Ii9aLHiqC4o=; b=dnT/TDYGrEHrHHi23ffETfkIaG+ujf6hQ9L/CFTc4YtnsTMe7lus+pq7ruyutVaCvU045U 8RKD9I66xRQJiq75OatHAv0e6FEgQz0mvcQD9otj+3MugY8DK7uDwGqAqb5UwCuZud1BA3 KxkyEI3i4mdR6C9QX/LwKTKS2ZLd5nk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-tyjAlesWNEasPefrwRqZ2Q-1; Thu, 21 Mar 2024 18:46:42 -0400 X-MC-Unique: tyjAlesWNEasPefrwRqZ2Q-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6961a54234cso2725516d6.1 for ; Thu, 21 Mar 2024 15:46:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711061201; x=1711666001; 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=X+ogJgpF1gr7B2+yDkmrhnOgUU+a3QN7Ii9aLHiqC4o=; b=sTHdg2A6HxRtU0QPU+CUursS/SGhfl70v0J5aBlOwr2WD/QuTUfWdQtf0V53gkDeLU nhCpYda738Krw/Ce9a1TBX4W21Yxs+DDVRoKjEmXZd55qnVqXiz253c0HA1au+2NXDKM Vq5quWMhfCkQamhmGwQjovetyK7cZJu8yGIj8haRNYgKJXEQnx45b5pVmvOHRpYsNY27 yF1jyOJD0cGPSH7J89C+PVCSqDZ6bDJzhNkVUgV+Y9PJHGXuiEoKAMJftkzYMRHa3Nvy EYl1IAzDAhxWd/RT5RT4Ytc5M7pCSc9z6UNhy8qWGUFRe2hjmA3zKkqSu1EO6OMnkcg1 F/VQ== X-Gm-Message-State: AOJu0YxsChzrF7xPjbLtPl61oarEHar0xL26K+Ft2LeGXDHi+q8PcYgt 4MdIhUZKDXWiv97+bWnvfDRdmoEn0BPFmLD+4X6z1idRUmqeQAe+c+JCAZRwP8bGtM+lrUq5931 tdGE06y7pSX8vk3C+DKc4c2SPLR+N5BN4HN4L8/zJfGk55XcsRqpSNEHBqznrZA== X-Received: by 2002:a05:6214:5984:b0:68f:dc8d:8ad3 with SMTP id qp4-20020a056214598400b0068fdc8d8ad3mr341926qvb.0.1711061201393; Thu, 21 Mar 2024 15:46:41 -0700 (PDT) X-Received: by 2002:a05:6214:5984:b0:68f:dc8d:8ad3 with SMTP id qp4-20020a056214598400b0068fdc8d8ad3mr341902qvb.0.1711061200836; Thu, 21 Mar 2024 15:46:40 -0700 (PDT) Received: from x1n ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id gw8-20020a0562140f0800b0068f6e1c3582sm380456qvb.146.2024.03.21.15.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:46:40 -0700 (PDT) Date: Thu, 21 Mar 2024 18:46:38 -0400 From: Peter Xu To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Andrew Morton , Alexander Gordeev , Sven Schnelle , Gerald Schaefer , Andrea Arcangeli , kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: Re: [PATCH v1 1/2] mm/userfaultfd: don't place zeropages when zeropages are disallowed Message-ID: References: <20240321215954.177730-1-david@redhat.com> <20240321215954.177730-2-david@redhat.com> <48d1282c-e4db-4b55-ab3f-3344af2440c4@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <48d1282c-e4db-4b55-ab3f-3344af2440c4@redhat.com> On Thu, Mar 21, 2024 at 11:29:45PM +0100, David Hildenbrand wrote: > On 21.03.24 23:20, Peter Xu wrote: > > On Thu, Mar 21, 2024 at 10:59:53PM +0100, David Hildenbrand wrote: > > > s390x must disable shared zeropages for processes running VMs, because > > > the VMs could end up making use of "storage keys" or protected > > > virtualization, which are incompatible with shared zeropages. > > > > > > Yet, with userfaultfd it is possible to insert shared zeropages into > > > such processes. Let's fallback to simply allocating a fresh zeroed > > > anonymous folio and insert that instead. > > > > > > mm_forbids_zeropage() was introduced in commit 593befa6ab74 ("mm: introduce > > > mm_forbids_zeropage function"), briefly before userfaultfd went > > > upstream. > > > > > > Note that we don't want to fail the UFFDIO_ZEROPAGE request like we do > > > for hugetlb, it would be rather unexpected. Further, we also > > > cannot really indicated "not supported" to user space ahead of time: it > > > could be that the MM disallows zeropages after userfaultfd was already > > > registered. > > > > > > Fixes: c1a4de99fada ("userfaultfd: mcopy_atomic|mfill_zeropage: UFFDIO_COPY|UFFDIO_ZEROPAGE preparation") > > > Signed-off-by: David Hildenbrand > > > > Reviewed-by: Peter Xu > > > > Still, a few comments below. > > > > > --- > > > mm/userfaultfd.c | 35 +++++++++++++++++++++++++++++++++++ > > > 1 file changed, 35 insertions(+) > > > > > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > > > index 712160cd41eca..1d1061ccd1dea 100644 > > > --- a/mm/userfaultfd.c > > > +++ b/mm/userfaultfd.c > > > @@ -316,6 +316,38 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, > > > goto out; > > > } > > > +static int mfill_atomic_pte_zeroed_folio(pmd_t *dst_pmd, > > > + struct vm_area_struct *dst_vma, unsigned long dst_addr) > > > +{ > > > + struct folio *folio; > > > + int ret; > > > > nitpick: we can set -ENOMEM here, then > > > > > + > > > + folio = vma_alloc_zeroed_movable_folio(dst_vma, dst_addr); > > > + if (!folio) > > > + return -ENOMEM; > > > > return ret; > > > > > + > > > + ret = -ENOMEM; > > > > drop. > > Sure! > > > > > > + if (mem_cgroup_charge(folio, dst_vma->vm_mm, GFP_KERNEL)) > > > + goto out_put; > > > + > > > + /* > > > + * The memory barrier inside __folio_mark_uptodate makes sure that > > > + * preceding stores to the page contents become visible before > > > + * the set_pte_at() write. > > > + */ > > > > This comment doesn't apply. We can drop it. > > > > I thought the same until I spotted that comment (where uffd originally > copied this from I strongly assume) in do_anonymous_page(). > > "Preceding stores" here are: zeroing out the memory. Ah.. that's okay then. Considering that userfault used to be pretty cautious on such ordering, as its specialty to involve many user updates on the page, would you mind we mention those details out? /* * __folio_mark_uptodate contains the memory barrier to make sure * the page updates to the zero page will be visible before * installing the pgtable entries. See do_anonymous_page(). */ Or anything better than my wordings. Thanks! -- Peter Xu