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 X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B59AC2D0E2 for ; Tue, 22 Sep 2020 15:29:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0F603214F1 for ; Tue, 22 Sep 2020 15:29:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FUNEOPnf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F603214F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 89B2190006D; Tue, 22 Sep 2020 11:29:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8546E90000F; Tue, 22 Sep 2020 11:29:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7396990006D; Tue, 22 Sep 2020 11:29:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0001.hostedemail.com [216.40.44.1]) by kanga.kvack.org (Postfix) with ESMTP id 5AC1190000F for ; Tue, 22 Sep 2020 11:29:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 06670362E for ; Tue, 22 Sep 2020 15:29:40 +0000 (UTC) X-FDA: 77291082120.13.judge67_4c0dd8a2714e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 7BF2018140B67 for ; Tue, 22 Sep 2020 15:29:39 +0000 (UTC) X-HE-Tag: judge67_4c0dd8a2714e X-Filterd-Recvd-Size: 7490 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 15:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600788576; 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=y+znqq/1mdsi7wOUB/8AcbZc8vzFFeZcv/UVcyJu8ZE=; b=FUNEOPnf4JQTrEekjAWb57AsaynA2pEZFMFEPyrguwGGhXINADY8wJQrXqr9enc0LHHQMq ZHPCsU5L9zeWuiujUmcV92UwtzCglJ3Qpafb7DKa8BDJx9xS0XxrhH2NGi0wxHXG4l0Irk 8GxZb82pGiNBY7Jeme4n/fw1uxeQno8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-Op1QHYb4Ocaw7nxX5iiodg-1; Tue, 22 Sep 2020 11:29:35 -0400 X-MC-Unique: Op1QHYb4Ocaw7nxX5iiodg-1 Received: by mail-qt1-f200.google.com with SMTP id b18so16320288qto.4 for ; Tue, 22 Sep 2020 08:29:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=y+znqq/1mdsi7wOUB/8AcbZc8vzFFeZcv/UVcyJu8ZE=; b=bC8UQXNe74/NIx9XVpl+i7is0ijxqyOLiZOIvCDdnj93KbtV2MMseCSmNioK415Qpo J20PtuUzaFL6hgi1LsD5bsAgFYTm6jrzagnrK+n7wNzbYwVlgDU1lA4Nm5DEzffx4uVa 3SOJCujOQSyNfs9T0bgbWYAq1qGFj/el+gF0TjwBraWbK6ywRoxRuSNw25Yf8/UYhK4/ iZDFROtaq7tm6AR0MnM4dypYDfxxvuuRhKq5O3PSRLl8GgbB6eGeSVq4hgnUgXu4+jnp 4rF1qKsVDJ5F54p3G5yUKWtK2pxG8nov9ulpLwVccdSra2ByZLzfUjR+yuQEKSUIZByk x5ZQ== X-Gm-Message-State: AOAM5317afuIoiDpgMuek8LWNY91fPb423V48rlT4jS6n/q63vp1R2x2 3CyrEClNgN7+ZtAjdn3J4I/AM2Se1QKWX1wi40yMpzflxzMMzru+dXq55J4g7BEcbYjnVV+udvl mvKXovN7trnM= X-Received: by 2002:a05:620a:221:: with SMTP id u1mr480397qkm.373.1600788572568; Tue, 22 Sep 2020 08:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy78sB2fCJXkx7JWis5bFj8k3gO7iGE2Cn/wwM0esofmNDTI3P/csuC3u41DGDIn6gRsT7+gw== X-Received: by 2002:a05:620a:221:: with SMTP id u1mr480354qkm.373.1600788572230; Tue, 22 Sep 2020 08:29:32 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id r24sm12379264qtm.70.2020.09.22.08.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 08:29:31 -0700 (PDT) Date: Tue, 22 Sep 2020 11:29:29 -0400 From: Peter Xu To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jason Gunthorpe , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 3/5] mm: Rework return value for copy_one_pte() Message-ID: <20200922152929.GE19098@xz-x1> References: <20200921211744.24758-1-peterx@redhat.com> <20200921211744.24758-4-peterx@redhat.com> <6eb46d4d-8267-4e10-0157-e2ce2be2850d@nvidia.com> MIME-Version: 1.0 In-Reply-To: <6eb46d4d-8267-4e10-0157-e2ce2be2850d@nvidia.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 Tue, Sep 22, 2020 at 12:11:29AM -0700, John Hubbard wrote: > On 9/21/20 2:17 PM, Peter Xu wrote: > > There's one special path for copy_one_pte() with swap entries, in which > > add_swap_count_continuation(GFP_ATOMIC) might fail. In that case we'll return > > I might be looking at the wrong place, but the existing code seems to call > add_swap_count_continuation(GFP_KERNEL), not with GFP_ATOMIC? Ah, I wanted to reference the one in swap_duplicate(). > > > the swp_entry_t so that the caller will release the locks and redo the same > > thing with GFP_KERNEL. > > > > It's confusing when copy_one_pte() must return a swp_entry_t (even if all the > > ptes are non-swap entries). More importantly, we face other requirement to > > extend this "we need to do something else, but without the locks held" case. > > > > Rework the return value into something easier to understand, as defined in enum > > copy_mm_ret. We'll pass the swp_entry_t back using the newly introduced union > > I like the documentation here, but it doesn't match what you did in the patch. > Actually, the documentation had the right idea (enum, rather than #define, for > COPY_MM_* items). Below... Yeah actually my very initial version has it as an enum, then I changed it to macros because I started to want it return negative as errors. However funnily in the current version copy_one_pte() won't return an error anymore... So probably, yes, it should be a good idea to get the enum back. Also we should be able to drop the negative handling too with copy_ret, though it should be in the next patch. > > > copy_mm_data parameter. > > > > Another trivial change is to move the reset of the "progress" counter into the > > retry path, so that we'll reset it for other reasons too. > > > > This should prepare us with adding new return codes, very soon. > > > > Signed-off-by: Peter Xu > > --- > > mm/memory.c | 42 +++++++++++++++++++++++++++++------------- > > 1 file changed, 29 insertions(+), 13 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 7525147908c4..1530bb1070f4 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -689,16 +689,24 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, > > } > > #endif > > +#define COPY_MM_DONE 0 > > +#define COPY_MM_SWAP_CONT 1 > > Those should be enums, so as to get a little type safety and other goodness from > using non-macro items. > > ... > > @@ -866,13 +877,18 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, > > pte_unmap_unlock(orig_dst_pte, dst_ptl); > > cond_resched(); > > - if (entry.val) { > > - if (add_swap_count_continuation(entry, GFP_KERNEL) < 0) > > + switch (copy_ret) { > > + case COPY_MM_SWAP_CONT: > > + if (add_swap_count_continuation(data.entry, GFP_KERNEL) < 0) > > return -ENOMEM; > > - progress = 0; > > Yes. Definitely a little cleaner to reset this above, instead of here. > > > + break; > > + default: > > + break; > > I assume this no-op noise is to placate the compiler and/or static checkers. :) This is (so far) for COPY_MM_DONE. I normally will cover all cases in a "switch()" and here "default" is for it. Even if I covered all the possibilities, I may still tend to keep one "default" and a WARN_ON_ONCE(1) to make sure nothing I've missed. Not sure whether that's the ideal way, though. Thanks, -- Peter Xu