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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DE32C433FE for ; Thu, 3 Nov 2022 15:50:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB00D6B0072; Thu, 3 Nov 2022 11:50:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E392E6B0073; Thu, 3 Nov 2022 11:50:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD9376B0074; Thu, 3 Nov 2022 11:50:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B95256B0072 for ; Thu, 3 Nov 2022 11:50:19 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5B3051613E4 for ; Thu, 3 Nov 2022 15:50:19 +0000 (UTC) X-FDA: 80092567758.01.E54276F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id BB9E5180003 for ; Thu, 3 Nov 2022 15:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667490617; 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=/Kf9rvim63yuVg7xQXPf25qL1fvNeKXI/1pKoooV9l0=; b=EXFY43vz/vEWBS02r7l6eTcOTdBAwSKi2r+6CeogwLUbrmycz/RcA0JbLSNpREQxtGRC3U rvcm+mdtPZRyDs/vjGFPpxEZUrZ5ZmEOGzVINLXUvq3tij1AlgF4G/aCQLib9uAbCPdDLz qn8noheYzMJW42z5HGO4kBWogwFtaxw= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-18-p9m34locOwq54AZGOn2Qvw-1; Thu, 03 Nov 2022 11:50:15 -0400 X-MC-Unique: p9m34locOwq54AZGOn2Qvw-1 Received: by mail-qk1-f197.google.com with SMTP id bm2-20020a05620a198200b006fa6eeee4a9so2260812qkb.14 for ; Thu, 03 Nov 2022 08:50:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/Kf9rvim63yuVg7xQXPf25qL1fvNeKXI/1pKoooV9l0=; b=U6fGDa3xUL2ccaIIkkIFq5tY7lL6O45dEWMvvHjIai6eMFGvLXzP4vZf+ECcGwdgXT E/9bM3NGtH98CgsKlC4wpItbf8x9AtF5f86Oc9iclxsJg8dhvaA95sIHFNz/SZ6Hu+5l uTj4XwLhmVW91DjyOaSVcuyAHDO1KDjyvYXLffEN6lON25hrcKYrTO+1vgFHofNPzaG8 NR6yB8dBmEpCr5zRPtwd8pJSz5VJPzjElD+1Wm/YbxYJcr6mzDtN8UzpfcoU88VCW5tp X4sF1KRi07yrVgEmLEAcMArccEgkYyUpkCcuoHM3+sa/h4qqpavaKCzI4TLl/RLW6FkD gv2w== X-Gm-Message-State: ACrzQf0x60NAldDaEafubxHtKmL1wCXBvKsM4+AWnm8o0/dAGJuYB4Gc KHJoa4SN4rD3azxlI72r0Ad6dU+EWK6OSV/34QNZPhy31aI0+HiO7OULZdFmvAuMNqzA4iHdQ7A CvD1E1ps5ju8= X-Received: by 2002:a05:6214:238e:b0:4b4:3392:ced6 with SMTP id fw14-20020a056214238e00b004b43392ced6mr26580269qvb.38.1667490608512; Thu, 03 Nov 2022 08:50:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/UckPGDZ8wo2iosYYoH1J3/hz8LOZ3kGO84B6ybEZcp6AooCtTlIRzEq1qK9gh1+opKmHbA== X-Received: by 2002:a05:6214:238e:b0:4b4:3392:ced6 with SMTP id fw14-20020a056214238e00b004b43392ced6mr26580247qvb.38.1667490608300; Thu, 03 Nov 2022 08:50:08 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id f21-20020ac87f15000000b003a5430ee366sm732000qtk.60.2022.11.03.08.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 08:50:07 -0700 (PDT) Date: Thu, 3 Nov 2022 11:50:06 -0400 From: Peter Xu To: James Houghton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Miaohe Lin , David Hildenbrand , Muchun Song , Andrea Arcangeli , Nadav Amit , Mike Kravetz , Rik van Riel Subject: Re: [PATCH RFC 07/10] mm/hugetlb: Make hugetlb_follow_page_mask() RCU-safe Message-ID: References: <20221030212929.335473-1-peterx@redhat.com> <20221030212929.335473-8-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EXFY43vz; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667490618; a=rsa-sha256; cv=none; b=u64eXWylzsWBfUCWCO2OolyMRhvZPuwaDJ5/JzV09O6M46shhi+zQpMWNBuISsdon5LJtf 30y3wURBxSYcYzl4Nfx4lkcaxLte9BManDQa6+GmmTpmoiD1DHtxGkSlAHv5zkZDkT14xf 4DxoTcJ0SwZ6sxeIE2a2Q+jiIXSrGcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667490618; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/Kf9rvim63yuVg7xQXPf25qL1fvNeKXI/1pKoooV9l0=; b=neLHck7fx63G7+ZzeXwbYwRIJpoogNZInooCN+P/xm/U4FiUgPUY3wvRuU3yNGo/uP9ZBJ DyP/8sOOKYNRqP7kPXIb4h4z+CEuNobvm9+WOvhSmK77ncnPLhETnhWe+b5om/7R0+U1fF JM+C6s6Zt23qJfh9G5DPRaiGYKNOjXs= X-Stat-Signature: wr88ciukcj8qc58e9erbozrs17w35iia X-Rspamd-Queue-Id: BB9E5180003 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EXFY43vz; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1667490618-420753 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 Wed, Nov 02, 2022 at 11:24:57AM -0700, James Houghton wrote: > On Sun, Oct 30, 2022 at 2:29 PM Peter Xu wrote: > > > > RCU makes sure the pte_t* won't go away from under us. Please refer to the > > comment above huge_pte_offset() for more information. > > > > Signed-off-by: Peter Xu > > --- > > mm/hugetlb.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 9869c12e6460..85214095fb85 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -6229,10 +6229,12 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, > > if (WARN_ON_ONCE(flags & FOLL_PIN)) > > return NULL; > > > > + /* For huge_pte_offset() */ > > + rcu_read_lock(); > > retry: > > pte = huge_pte_offset(mm, haddr, huge_page_size(h)); > > if (!pte) > > - return NULL; > > + goto out_rcu; > > > > ptl = huge_pte_lock(h, mm, pte); > > Just to make sure -- this huge_pte_lock doesn't count as "blocking" > (for the purposes of what is allowed in an RCU read-side critical > section), right? If so, great! Yeah I think spinlock should be fine, iiuc it'll be fine as long as we don't proactively yield with any form of sleeping locks. For RT sleepable spinlock should also be fine in this case, as explicitly mentioned in the RCU docs: b. What about the -rt patchset? If readers would need to block in an non-rt kernel, you need SRCU. If readers would block in a -rt kernel, but not in a non-rt kernel, SRCU is not necessary. (The -rt patchset turns spinlocks into sleeplocks, hence this distinction.) > But I think we need to call `rcu_read_unlock` before entering > `__migration_entry_wait_huge`, as that function really can block. Right, let me revisit this after I figure out how to do with the hugetlb_fault() path first, as you commented in the other patch. Actually here I really think we should just remove the migration chunk and return with page==NULL, since I really don't think follow_page_mask should block at all.. then for !sleep cases (FOLL_NOWAIT) or follow_page we'll return the NULL upwards early, while for generic GUP (__get_user_pages) we'll just wait in the upcoming faultin_page(). That's afaict what we do with non-hugetlb memories too (after the recent removal of FOLL_MIGRATE in 4a0499782a). -- Peter Xu