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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C21EC4332F for ; Thu, 14 Dec 2023 11:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ra+4EP4o92yhI4KYq4jnoWLskRKr+fSpVqS8UthZVjk=; b=QkqPgIgld7XPvG KnSjaksDVZkmTeHmKw3upgGJ9Ozlo5tHsqpgHfdfWAw1z2uEYk+hFVTIoVPlL73JED5h/3zb26Q4K dwrTC8ZpaaQDz4r3pBSxIjt8b5DQXuM+kgzcq9ZVhLjY8Ga4Ez+kG3z09hj9/9k4KuIIfcK1v+nU0 VzonSJxcf8v8WuAKdCGjbkV1JoPHrg7wxXVTFxOp3032Xdi3HGlLawEEYhnoutzV//5j8RUwADNkn C7IakLWQT+kUSdEju23ue28ScZL2GarUcAynWUVK3UGJSqrKrPk7CHK/uGnNbulxusjs4ju4ynLMU tUxK9ahvKxL6Nqii4GCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rDjvX-0007nS-2X; Thu, 14 Dec 2023 11:30:51 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rDjvU-0007h9-1m for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2023 11:30:50 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-336417c565eso1259941f8f.3 for ; Thu, 14 Dec 2023 03:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702553443; x=1703158243; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZGyR5IM589pNwJshXT2QlygyEFYgsSWq45p1PM9PHw8=; b=iYxZ5PVACkuC9cdTW1NoBxJO+QxXGyag86UWVGGiXp/K86+RixuFKKzp3XKPioAyxq iD0bhH7okV7NxnUgZxBk/vmt3XYcgnaneFiI+gT3rXCJZP5ugGIqMIkPyrmcVb86qz/U k/HEapflQPeDazM4wDm0XXvnjdMNY7cmopY6fPcNymIZIP231ggH9u1yiKSGLFQhSMrE To1b3s97ff2BlQkoXK8/KXUFJaLQInfiDYpV1UvzFb9EWZlQSHb5FME6N+koz8ASY4tG /xfrQVRuBoNSzB2Hg43g7XiNGgxZEkw9wrZ0tyMstvZyFttU3W+Q2eCoki7eGDlmQGJc GLkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702553443; x=1703158243; 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=ZGyR5IM589pNwJshXT2QlygyEFYgsSWq45p1PM9PHw8=; b=mHLiPXuZBFOX51DYqi25TMN426KeUoN7bDXb9aOkk+BNkpnevZArJHSxfsqCaJTyGU LhWnaQXcPIS5ZRpP3psXzRJdh6FHbN/l2B9PNiA4mkitW+8HOj7TdXGsCKqibUpeSKBp x9Lj3Po+JotlXQf+3YlQNukhqA259huFb0M5BIza9x2kw2IDe9/1Pb1ZaRd8nA9YJm08 9AIMnYdHQkbvlDtGbhCbbmC9blxUFFgjH+lYXF84BBYPCgxpBP3FD2fujRW6ubzQynGM 3miutIVVaSNR3r3vwVbQZasc5az2E8cPthrOAIr64yG3IW+eNF2iiB6X/FVywUjPWKyP iIfw== X-Gm-Message-State: AOJu0Yw0Gx+ut3/LEzc4rtJp+XTP/IySg40rbcXfa5u3TNBvhocwrtgu p4priS1iHKhb9PtxT2xAQqVdDg== X-Google-Smtp-Source: AGHT+IGlunMuhMf+wJNo9In2hayzFruWkeU7cG8jgxWDtUBf1ufk3oh/44gl3xD2yS1qQogfw0HhwQ== X-Received: by 2002:a05:6000:11c4:b0:333:2fd2:3be2 with SMTP id i4-20020a05600011c400b003332fd23be2mr3801476wrx.155.1702553443052; Thu, 14 Dec 2023 03:30:43 -0800 (PST) Received: from localhost ([102.140.209.237]) by smtp.gmail.com with ESMTPSA id a4-20020a056000100400b00333371c7382sm15875496wrx.72.2023.12.14.03.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 03:30:42 -0800 (PST) Date: Thu, 14 Dec 2023 14:30:39 +0300 From: Dan Carpenter To: Ryan Roberts Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , David Hildenbrand , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 04/10] mm: thp: Support allocation of anonymous multi-size THP Message-ID: References: <20231207161211.2374093-1-ryan.roberts@arm.com> <20231207161211.2374093-5-ryan.roberts@arm.com> <43a8bfff-f939-4f2d-a8cd-97306d5e44c9@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <43a8bfff-f939-4f2d-a8cd-97306d5e44c9@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231214_033048_589082_6AE193F5 X-CRM114-Status: GOOD ( 30.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Dec 14, 2023 at 10:54:19AM +0000, Ryan Roberts wrote: > On 13/12/2023 07:21, Dan Carpenter wrote: > > On Thu, Dec 07, 2023 at 04:12:05PM +0000, Ryan Roberts wrote: > >> @@ -4176,10 +4260,15 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > >> /* Allocate our own private page. */ > >> if (unlikely(anon_vma_prepare(vma))) > >> goto oom; > >> - folio = vma_alloc_zeroed_movable_folio(vma, vmf->address); > >> + folio = alloc_anon_folio(vmf); > >> + if (IS_ERR(folio)) > >> + return 0; > >> if (!folio) > >> goto oom; > > > > Returning zero is weird. I think it should be a vm_fault_t code. > > It's the same pattern that the existing code a little further down this function > already implements: > > vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); > if (!vmf->pte) > goto release; > > If we fail to map/lock the pte (due to a race), then we return 0 to allow user > space to rerun the faulting instruction and cause the fault to happen again. The > above code ends up calling "return ret;" and ret is 0. > Ah, okay. Thanks! > > > > This mixing of error pointers and NULL is going to cause problems. > > Normally when we have a mix of error pointers and NULL then the NULL is > > not an error but instead means that the feature has been deliberately > > turned off. I'm unable to figure out what the meaning is here. > > There are 3 conditions that the function can return: > > - folio successfully allocated > - folio failed to be allocated due to OOM > - fault needs to be tried again due to losing race > > Previously only the first 2 conditions were possible and they were indicated by > NULL/not-NULL. The new 3rd condition is only possible when THP is compile-time > enabled. So it keeps the logic simpler to keep the NULL/not-NULL distinction for > the first 2, and use the error code for the final one. > > There are IS_ERR() and IS_ERR_OR_NULL() variants so I assume a pattern where you > can have pointer, error or NULL is somewhat common already? People are confused by this a lot so I have written a blog about it: https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/ The IS_ERR_OR_NULL() function should be used like this: int blink_leds() { led = get_leds(); if (IS_ERR_OR_NULL(led)) return PTR_ERR(led); <-- NULL means zero/success return led->blink(); } In the case of alloc_anon_folio(), I would be tempted to create a wrapper around it where NULL becomes ERR_PTR(-ENOMEM). But this is obviously fast path code and I haven't benchmarked it. Adding a comment is the other option. regards, dan carpenter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel