Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp775927lqp; Thu, 21 Mar 2024 15:38:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURRaEq66durz7QbB3vNVcITu/arR6uUfZX5rJBoh0UG+tgZ6gzxZH/tDcrtHgR1thrzBb9QoQlgbhvs5WguIQkGz7imparNtUs9HACGA== X-Google-Smtp-Source: AGHT+IGBPLBQuy6b7iePHHpc8nIVTxjYxXRHl4XtHF0PSCsiHFbB8vm2OCfLEq+FAidZ2RJHLxkV X-Received: by 2002:a17:90b:3606:b0:29b:fb23:863e with SMTP id ml6-20020a17090b360600b0029bfb23863emr467955pjb.17.1711060694351; Thu, 21 Mar 2024 15:38:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711060694; cv=pass; d=google.com; s=arc-20160816; b=eZ0v6iLeRuA8qROGg2slJetp3+UeZNoay1VnXA54QkuSpN+T7W+hOyTXNqU3xaZfRJ lNS+EZukhGqdjB7Ll0EeXJRfU8t9hqoPiEM7rBRW5Ew1npRZ1z/0wV1a7RxAhRryYRWm 5JRyORVWemf9cpsMQMSMvdXYNyF6AWfzFZtQL1VkUZf+zMolqxbtjqRFmIylapWDqkim 21dh3LmB1xxS+dVkRHJaOL9jVml2DaqqK8dYZaropu7fQgkTX6V9vz5IOrdDg31kOm11 jqVNCmld5gqtfD3Aj3N/b6ADDFMFT9qNimQnp8X2q4O6tw5THhokZ6m8YnvBx+RWe1y+ Dveg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=5MggRPNo3+tANcd2X7t6Sxe3iKsgn51LgGVLSTK7Imc=; fh=t/WD4leUpjjcCITj9STk/aS03HHIw2+z3gRF3/WdUl8=; b=S2iHMzVhXTnUIcby/Q2KTzCIP8hcvkkI9wpocRcyHK7Ka6ebxt+lVUQ0bTmBVD2kvt +Fl39HWNERV8FoYNkMOFaaihMjGcmYDozPpoMrgCAkv+h8iE3aoOG357HHLtTTsXbgoG pd60V4Tg10u6KuKV7Pkj5k/Q6WdnRwa5DQBsAHRLllHTqSy2pgSuqx1MNfNx9tx/VioD ga/wmuXYDbHbUx1+UNfb6JRrRNRjKRb1x+OFkfZMWosvBuMphwqe2pPt4rMNb7y8zxyB gJfBFe6UeS5+tkgT6UuDGWKKQ6P5dMe40CbmxM6IZT1Aon7dx70V/Sd4mPZzj0jcv7XA XeAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g6cHIZqz; 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-110762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110762-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x17-20020a17090a8a9100b002a038bbd178si248923pjn.6.2024.03.21.15.38.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 15:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=g6cHIZqz; 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-110762-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110762-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 270C6286F9C for ; Thu, 21 Mar 2024 22:30:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBED213775A; Thu, 21 Mar 2024 22:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g6cHIZqz" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 32C3F1369A4 for ; Thu, 21 Mar 2024 22:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711060192; cv=none; b=E06iS2Qqb+LicW9PEL4+q1hE6DFPyUFd7YaTDoJJ7SMNFrYqYOuocR9aYX3HpGTi/NmxYbxsQfB907YFNzqSKywdSLdAZnMbbECFEjApOJXXiksCxFXe42lFa3UtKh5JCCmm3gSu4Q0Y8uagHgxFg9c/t7CR33JGgVAXhUsDqCo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711060192; c=relaxed/simple; bh=dMjHyU5GItR9uCuiDMA0qfZIY8n0qTGA0Ob36mJDMtc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=M1nDhMXwIC5aaXFr+obMLibq6P6gRMNhx+45h2JCgZBuwS8SQjD2GVCmvUzDzHQxbYRZW0Ha+OVUZLX8Ujn39GJ4tVWgQ/5WWbbg30A7BYPNtKKa5Vq6TQvZi6Lf54Ne1O8wNN4nuQyZ8YbXxw+UPnA9a1bP32ShLgHks5v7yIs= 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=g6cHIZqz; arc=none smtp.client-ip=170.10.133.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=1711060190; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=5MggRPNo3+tANcd2X7t6Sxe3iKsgn51LgGVLSTK7Imc=; b=g6cHIZqzBRFcYwTkpxVB6OMsRzmr3fL1uLsF/5P/DQudm5SlUcvuxQ5vvADgMzdfCmTBB8 ZNLdt4xiT9+S5hLCmVm3ofp7arb+YdZh91OmDJMCBSNxJ/zSpqnpULjlDM4Eez4qkaCmwZ c9Zf1Q4Cqo3qaOVRrCwZhq1ulF7rkxM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-282-8m9vLcioOoSOqO0G1ScWxQ-1; Thu, 21 Mar 2024 18:29:48 -0400 X-MC-Unique: 8m9vLcioOoSOqO0G1ScWxQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-41401eef944so7244485e9.2 for ; Thu, 21 Mar 2024 15:29:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711060187; x=1711664987; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5MggRPNo3+tANcd2X7t6Sxe3iKsgn51LgGVLSTK7Imc=; b=dEiXDTdiXE/5u7xxj0KbiY2HM1qIBlQCXipXrmgpz2Ddd3WFJ4jqfH6NN6Zycdq7e7 q/+aENTNUPvBA4bp9+oAuk3451IH0s7X+zj1pR1jm4wqZAtyt+GL3k+rGkxLcm5wZc6O Kwgxxql7Cobe9ruevhyEy5pAIyu9yYj9yKdQ5WyKC7d42BgYTUTc4mN8WeXr5XHqi2N2 B1CjWIluR7J0vahmpmIKfSeCrMsH8WL5RG38UGaoTAF4+aNmFjs/iniQ9UCxQ/P8M9/K R9nTQKlAn9Clu6c5q+b3kJVs3TFb5bNMF6oMwz+t1MmCq77hhq9u9K2uYfQkeHXhtFXX 6N+A== X-Gm-Message-State: AOJu0YyYW2M+idCmdM7NyvePtNQS102vfIUfNqEwe8m3UimdZ7wR2qwc zTpAms9SajAgNKJgCnNTYuSRK/JLse/V6RfG5H4b2/Uksbj1mHjUJisPAZBMWKXX6B1Vl6ljo2L aiaTySeeNMg0lCA6WMU7HPXv4rJGt8vt6gC5qzDVGl2ZMTzoNbjuVjw8FNZMURE2GbyG7dA== X-Received: by 2002:a7b:cb87:0:b0:414:a69:f0b1 with SMTP id m7-20020a7bcb87000000b004140a69f0b1mr329198wmi.13.1711060187477; Thu, 21 Mar 2024 15:29:47 -0700 (PDT) X-Received: by 2002:a7b:cb87:0:b0:414:a69:f0b1 with SMTP id m7-20020a7bcb87000000b004140a69f0b1mr329179wmi.13.1711060186991; Thu, 21 Mar 2024 15:29:46 -0700 (PDT) Received: from ?IPV6:2003:cb:c711:6100:c68b:6e10:d7be:4e87? (p200300cbc7116100c68b6e10d7be4e87.dip0.t-ipconnect.de. [2003:cb:c711:6100:c68b:6e10:d7be:4e87]) by smtp.gmail.com with ESMTPSA id b2-20020a05600c4e0200b0041312c4865asm6981889wmq.2.2024.03.21.15.29.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Mar 2024 15:29:46 -0700 (PDT) Message-ID: <48d1282c-e4db-4b55-ab3f-3344af2440c4@redhat.com> Date: Thu, 21 Mar 2024 23:29:45 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/2] mm/userfaultfd: don't place zeropages when zeropages are disallowed To: Peter Xu 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 References: <20240321215954.177730-1-david@redhat.com> <20240321215954.177730-2-david@redhat.com> Content-Language: en-US From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M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FJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. Thanks for the fast review! -- Cheers, David / dhildenb