Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp334065lqo; Fri, 10 May 2024 00:54:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1HApQ4+3VstJHX9rrexAqA0A6z+ZgYNVjyBH1c3762d62BQ5b/SlMwD4Zw+CWqWtgkhbGX2pTim1l16EruXzaoTDfVOki+OFbGSCqGg== X-Google-Smtp-Source: AGHT+IH6xfmiIJZntsyuqHgldhNLF29irEP5LVBOtnldF2pHsjMZvD+bnpEPU2rXduKLn6WYP9th X-Received: by 2002:a17:902:f788:b0:1eb:3ef7:1237 with SMTP id d9443c01a7336-1ef440496ffmr20934325ad.50.1715327689241; Fri, 10 May 2024 00:54:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715327689; cv=pass; d=google.com; s=arc-20160816; b=INtAozDSGNo2o1mjxk7Fx4IAaIhVCXXw2tFMQO2sAI2jD+xGUg+1EU7zwJqOOvFY4M I5iIMCTFSMtWsbSzyDa6A8ZSm4vW04SJRrDBHO7UEKb2DY0nAndIhhG/VYzNalbDoCUn uRRNlq0UWuxkog5tbUpVCqx8kjXfp5NpY5DdBFBI0VPUmAOqG9gRPYciM5sLaLYZ6GYO sb3H/m9+ITOxVYQSur266NY3P9LYRyqOSlieS987JOiERz3ubiqJvYUOZcVbbSda1b8U /VeeW9tJ9B9j7gAiZDtE0EymTnl5mHD1KHsm5PH65IS/ih6Yre3c2e6LdHWI2cYlPEa+ PH7w== 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 :content-language:from:references:cc:to:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=nweOFAsLnbVW/1iPfd3jnuSWx2J2WyWpGQwKCD45C1M=; fh=QKGQA5f6iGpbD33m7f5zL5mIgVoRT76hBAQYsM2FKF4=; b=dMkc0MQ3L+3XBE6539WdRWpp220LGoR6nveTkBGHkAAYyST8UKbyoFxAAXO9Hg1h8a TCXF2Fbj+41XhHBjFwTduWBIBUegXb4jVTlGZjjhG7t1g/UExRq+HsSm8MCw/gJ2KJ7f qtuZdi714Wfv8vyslJA++ymELFFeXVMIwGudlMTSI4+wsenT5koIrATaWYinlmEqdFmV VX4hQXTBkfQQgojtMfalDEbXzExhg4SUpTb3sK9zi6f7ESPsOM1azBtQsbRUv1vhRgFm 3gMuYYK4NS9hX3ioVzgLbSktG3438Qj9QGaf3K9ljEVM3AraRKN30LTOuBWOcQF0ucY6 KJAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S7a9D5n3; 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-175416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175416-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bad60fbsi29900265ad.134.2024.05.10.00.54.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 00:54:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S7a9D5n3; 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-175416-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175416-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 00075B2157E for ; Fri, 10 May 2024 07:54:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7484D15F40B; Fri, 10 May 2024 07:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S7a9D5n3" 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 C3AF415250F for ; Fri, 10 May 2024 07:54:28 +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=1715327670; cv=none; b=jMPBS8ra0IldCmTipdQi3pws/QEIBKL/nHcycuz4G/juuQ+nnrlUU0BJDh1d9ywSHfc2lv2rp8lKAYdpMKBYtPlHthKi/28Gs+mOrfSIvCAGV/Ua4y6v/VRHIzuuX7dZuLl0E857naoT4zOLoBxcqRyb9YJSI5AIW3IkDRHZ1S0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715327670; c=relaxed/simple; bh=xPN36Ro0Y3FxkOW2cmytKMS5KsQx8KJCNNPw+5HliTU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FE97L7XclHLsBEcLj4C0gwqr7ImkwxDl6uGYMhlcvbCB46Ah906oa1odFxRmHmp+llUW/mkaTR/i817XST0iZnE6AWIVosqR7XtqHGL3RrbSkW1nkBGSlVyx5KwieFAddw8ikQWPD+3Z9bd+z7UeEtwcLI/wOZlezmX/wcrCArM= 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=S7a9D5n3; 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=1715327667; 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=nweOFAsLnbVW/1iPfd3jnuSWx2J2WyWpGQwKCD45C1M=; b=S7a9D5n3P1bITxtyALNhunmHBKl4va4R2v7Z8IMdO6tHuj3EoZhBuMFwLqIY467sjqLOHG 3J8Xr/K9Z6vecdE6j1ec/dWVK0DCUf5sjUJfzX+Mccxt7t+JBinDqGI+XplqSrCWk4g0Gp +bpUNZUjI8Hrh9NVwM6KODnJxt2sqYo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-fLZdw9cKNdS35l8Zlr4Bhw-1; Fri, 10 May 2024 03:54:23 -0400 X-MC-Unique: fLZdw9cKNdS35l8Zlr4Bhw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-41fffe9849bso560085e9.3 for ; Fri, 10 May 2024 00:54:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715327662; x=1715932462; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from: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=nweOFAsLnbVW/1iPfd3jnuSWx2J2WyWpGQwKCD45C1M=; b=qmjjKRMkN5L3Fkm8iNt5kbMmubI9OTBiPcBH8g6Q/vqZLRW369t+FIAOM+r//mK0N3 2Z0Vt8/zBVrkTuW0kd4+ls7rXnh9M9mP2H7F9Y8JJ+0FTDgE7SENAuS1IHf8ASIbsFr5 erkksEsvK5h9tlZPkYuU3LbnwelkuRW2XegnI3BqAfDHr3fLHtCoBeTS8pR6ox7o0WFJ kylnxBRabsRRU/7I7MBzNxiMCR0p1mHh1sGV4PKgWAjDfI87btqCUSMaTu/W2eIeVsZ/ /+KkoeyUiue+2ZyerVYLUKQjwLbN/o3YXYTHwSLR+xO6Cekgscfldnp8zz5nicjY1Qh4 hmaA== X-Forwarded-Encrypted: i=1; AJvYcCWcfxAfLpOpXCCF0gmcOuGhw4cAIfuIwNsPwTzfWFDufE4GkzSykT5/At6M9ysBOWqbA3WQUQGDyyz3YKprrHbWsr6FXbPdaCk75rrg X-Gm-Message-State: AOJu0YxIZLk+pBc2wO//OBsfretxlzni2fved2+gbF2X7u0IkRKDEUqU je36J+jLS+/amKTnFCO9cdWC1eg8O86UgnV3bNi+4ouon+5TFtgM0ayJqrvtm/XS774hIW/FzcF oFq1IV9uNc1nOGwdtbw7PeMcHsHc/YKo8ehumQcGlR8DUTrkaPnJAw4XUc/vBQg== X-Received: by 2002:a05:600c:3849:b0:41b:a4ce:aa45 with SMTP id 5b1f17b1804b1-41feab44abamr13325275e9.23.1715327662295; Fri, 10 May 2024 00:54:22 -0700 (PDT) X-Received: by 2002:a05:600c:3849:b0:41b:a4ce:aa45 with SMTP id 5b1f17b1804b1-41feab44abamr13325155e9.23.1715327661813; Fri, 10 May 2024 00:54:21 -0700 (PDT) Received: from ?IPV6:2003:cb:c710:2b00:9c9f:9357:3f4c:5358? (p200300cbc7102b009c9f93573f4c5358.dip0.t-ipconnect.de. [2003:cb:c710:2b00:9c9f:9357:3f4c:5358]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b8969fbsm3791380f8f.37.2024.05.10.00.54.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 May 2024 00:54:21 -0700 (PDT) Message-ID: Date: Fri, 10 May 2024 09:54:20 +0200 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: [RFC] RDMA/umem: pin_user_pages*() can temporarily fail due to migration glitches To: John Hubbard , Alistair Popple , Jason Gunthorpe Cc: Christoph Hellwig , Andrew Morton , LKML , linux-rdma@vger.kernel.org, linux-mm@kvack.org, Mike Marciniszyn , Leon Romanovsky , Artemy Kovalyov , Michael Guralnik , Pak Markthub , Vivek Kasireddy References: <20240501003117.257735-1-jhubbard@nvidia.com> <20240501121032.GA941030@nvidia.com> <87r0el3tfi.fsf@nvdebian.thelocal> <92289167-5655-4c51-8dfc-df7ae53fdb7b@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR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ecsQDv0fFJOA9ag5O3LLNk+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: 8bit On 02.05.24 20:10, John Hubbard wrote: > On 5/1/24 11:56 PM, David Hildenbrand wrote: >> On 02.05.24 03:05, Alistair Popple wrote: >>> Jason Gunthorpe writes: > ... >>>>> This doesn't make sense.  IFF a blind retry is all that is needed it >>>>> should be done in the core functionality.  I fear it's not that easy, >>>>> though. >>>> >>>> +1 >>>> >>>> This migration retry weirdness is a GUP issue, it needs to be solved >>>> in the mm not exposed to every pin_user_pages caller. >>>> >>>> If it turns out ZONE_MOVEABLE pages can't actually be reliably moved >>>> then it is pretty broken.. >>> >>> I wonder if we should remove the arbitrary retry limit in >>> migrate_pages() entirely for ZONE_MOVEABLE pages and just loop until >>> they migrate? By definition there should only be transient references on >>> these pages so why do we need to limit the number of retries in the >>> first place? >> >> There are some weird things that still needs fixing: vmsplice() is the >> example that doesn't use FOLL_LONGTERM. >> > > Hi David! > Sorry for the late reply! > Do you have any other call sites in mind? It sounds like one way forward > is to fix each call site... We also have udmabuf, that is currently getting fixed [1] similarly to how we handle GUP. Could you and/or Jason also have a look at the GUP-related bits? I acked it but the patch set does not seem to make progress. https://lkml.kernel.org/r/20240411070157.3318425-1-vivek.kasireddy@intel.com The sad story is: (a) vmsplice() is harder to fix (identify all put_page() and replace them by unpin_user_page()), but will get fixed at some point. (b) even !longterm DMA can take double-digit seconds (c) other wrong code is likely to exist or to appear again and it's rather hard to identify+prevent reliably IMHO we should expect migration to take a longer time and maybe never happening in some cases. Memory offlining (e.g., echo "offline" > sys/devices/system/memory/memory0/state) currently tries forever to migrate pages and can be killed if started from user space using a fatal signal. If memory offlining happens from kernel context (unplugging DIMM, ACPI code triggers offlining), we'd much rather want to fail at some point instead of looping forever, but it hasn't really popped up as a problem so far. virtio-mem uses alloc_contig_range() for best-effort allocation and will skip such temporarily unmovable ranges to try again later. Here, we really don't want to loop forever in migration code but rather fail earlier and try unplug of another memory block. So as long as page pinning is triggered from user context where the user can simply abort the process (e.g., kill the process), sleep+retry on ZONE_MOVABLE + MIGRATE_CMA sounds reasonable. > > This is an unhappy story right now: the pin_user_pages*() APIs are > significantly worse than before the "migrate pages away automatically" > upgrade, from a user point of view. Because now, the APIs fail > intermittently for callers who follow the rules--because > pin_user_pages() is not fully working yet, basically. > > Other ideas, large or small, about how to approach a fix? What Jason says makes sense to me: sleep+retry. My only concern is when pin_user_pages_*() is called from non-killable context where failing at some point might be more reasonable. But maybe that use case doesn't really exist? -- Cheers, David / dhildenb