Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp54055pxp; Fri, 4 Mar 2022 21:12:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjnYFlGRFNtRP8uu6aUUZ4hmGfWzoqiOxEEZFi5XepWnTpxddFTwo5NNFDVHfAXDFTb1ui X-Received: by 2002:a17:902:eb8f:b0:151:63fa:f59b with SMTP id q15-20020a170902eb8f00b0015163faf59bmr1796604plg.93.1646457175896; Fri, 04 Mar 2022 21:12:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646457175; cv=none; d=google.com; s=arc-20160816; b=DNiMgCHcNoIlfiVn4hUaWt1VRuyK+ONm0KziTNMa5m9XQFwFoyOTyyASFccXMe9E/e pOwtgzSgJCtAiWhEGL5V6QR5FsJPI5NxNw3o1MkIlWdS65p87YoSOxvRe/NbgAKUhNEj tKzXNOQrC/XpM2AFeVyctvjWyBPh5LML6ysPoaOYpHrRBrlxDkd7HMiZcs8zHHPSLcvO ppPqmgv5P9hcpxd4e184MlBbZzmn+0JNmrFRqHyPrR27q974f5SqY88GXHFDTVY/X4Mz oHFJD98lOZbcIBnzWFQ67zM4BF1nlAvwnjEPu+2MIjN9+QeBInyurVxYdzBdsRDie209 hasw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wM3eFqrqM0GuC7lgIlL7krmA9FgA7rdYgF/tZhSxxr4=; b=bbSj0UUIsDsQlPk+dgUri9OJdO2RWT3xK8GekLa/dJYaI9xaOrpYq7nE23RZL1uHmV PAESRn1YLzJ/TN2mW+RK4XsSvxLkqz9L22gUmxPJyxCekiOsexaNLQDpW13bpklES7/y OlCiqMdwgs1wWPubZl6FX1k3KwF+Xhob8waxfoph6qQIOIyoQ4wBTCKTExbLkICaQdKy P4Eg4d8W4fozbVm58Oprh4rMkJ1v7NFG9zvmL1oQ9eGmPXAq8Q7NDt0r/nQw5X64JG24 FCVqxuY240sIAw/I3/0V3CYZJt+hSYEFaMTcD3y5Du9vimMYkYIOaKpGq6rHyWTJ1UzD HI8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=In5oS8yg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx12-20020a17090afd8c00b001bedf836c6csi1312590pjb.30.2022.03.04.21.12.37; Fri, 04 Mar 2022 21:12:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=In5oS8yg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbiCEEBJ (ORCPT + 99 others); Fri, 4 Mar 2022 23:01:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbiCEEBG (ORCPT ); Fri, 4 Mar 2022 23:01:06 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4655574E for ; Fri, 4 Mar 2022 20:00:17 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id m2so3446242pll.0 for ; Fri, 04 Mar 2022 20:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wM3eFqrqM0GuC7lgIlL7krmA9FgA7rdYgF/tZhSxxr4=; b=In5oS8ygv57WDqgGEdEWpKehvtF7uZ27kO3NGv3dlP4/E/E2DaYZQRx6Ha3xK+E/Og YSkO2MSNpHGFHOeoIdTaAv7AhTHBAoQYFI4O7F9IsrMZxureqz4q7PzfLn4U4MOEAiQQ IQ9vTyjcu+ZbfsLHmj/dgIcYOhqtYlIydl+vjoY4bQQ7EZenHuXt7K3arMXa36g+1ZRk j2TQDJ4bkTa74hsjvyjuju2SW2RL7AaRltSEagPZycctrsf8ht0VxF2uU+IWCL9PYuY2 9O63QUbtMZSOcp4Yi4MhDFliU6r+UJMvLOwdCGLyMIENzAJOYWlsu81zRub3E5Xi8luE 502w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wM3eFqrqM0GuC7lgIlL7krmA9FgA7rdYgF/tZhSxxr4=; b=nV64BPU7pg1hJcA1JLtAV/FnSpekIOjGfP1yXOWfRrYcUMCWxRWt0fMIL+J7idJPHa J5L9CeehHmIUimgQ18O/PVuEaV5/qveJmsJzmNRHyNlgNU3N68NXu1tFRA1TTlysFzUf WiiwLICVGs40ZLNflupaC2hVlVPNA19SC2MfdA2ikXng9bqaD2bOWXI9N3UtgRtaPT6L uqPUrw0yfHEPW9eib4swvovUsiOccMmUrdG8AdYzzGDVtyMOeui7F6umB5EwWBx9Gmw6 CoEii/7EdyQMKqL/izhkM9rRLIBEQXNKZz/pzTLSOfBPYrGr1Tn8HeN52TGB8se8nW/R p+wQ== X-Gm-Message-State: AOAM532UZMqwM+62xxWxRxDHoK4LtJz2VX+oV5Q2F/TbAgR8owMN3shS Ac4223Bo/efAeeWrniO5w64= X-Received: by 2002:a17:902:f70b:b0:14d:643d:9c99 with SMTP id h11-20020a170902f70b00b0014d643d9c99mr1867666plo.18.1646452817035; Fri, 04 Mar 2022 20:00:17 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id 132-20020a62168a000000b004f40e8b3133sm7961872pfw.188.2022.03.04.20.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 20:00:16 -0800 (PST) Date: Sat, 5 Mar 2022 04:00:12 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Marco Elver Cc: linux-mm@kvack.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Matthew WilCox , Roman Gushchin , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/5] slab cleanups Message-ID: References: <20220304063427.372145-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 04, 2022 at 02:11:50PM +0100, Marco Elver wrote: > On Fri, 4 Mar 2022 at 13:02, Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > > > On Fri, Mar 04, 2022 at 12:50:21PM +0100, Marco Elver wrote: > > > On Fri, 4 Mar 2022 at 07:34, Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > > > > > > > Changes from v1: > > > > Now SLAB passes requests larger than order-1 page > > > > to page allocator. > > > > > > > > Adjusted comments from Matthew, Vlastimil, Rientjes. > > > > Thank you for feedback! > > > > > > > > BTW, I have no idea what __ksize() should return when an object that > > > > is not allocated from slab is passed. both 0 and folio_size() > > > > seems wrong to me. > > > > > > Didn't we say 0 would be the safer of the two options? > > > https://lkml.kernel.org/r/0e02416f-ef43-dc8a-9e8e-50ff63dd3c61@suse.cz > > > > > > > Oh sorry, I didn't understand why 0 was safer when I was reading it. > > > > Reading again, 0 is safer because kasan does not unpoison for > > wrongly passed object, right? > > Not quite. KASAN can tell if something is wrong, i.e. invalid object. > Similarly, if you are able to tell if the passed pointer is not a > valid object some other way, you can do something better - namely, > return 0. > > The intuition here is that the caller has a pointer to an > invalid object, and wants to use ksize() to determine its size, and > most likely access all those bytes. Arguably, at that point the kernel > is already in a degrading state. But we can try to not let things get > worse by having ksize() return 0, in the hopes that it will stop > corrupting more memory. It won't work in all cases, but should avoid > things like "s = ksize(obj); touch_all_bytes(obj, s)" where the size > bounds the memory accessed corrupting random memory. Oh, it's to prevent to corrupt memory further in failure case, like memset(obj, 0, s); > The other reason is that a caller could actually check the size, and > if 0, do something else. Few callers will do so, because nobody > expects that their code has a bug. :-) and making it able to check errors by caller. Thank you so much for kind explanation. I'll add what Vlastimil suggested in next series. Thanks! -- Thank you, You are awesome! Hyeonggon :-)