Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp906996ybz; Wed, 29 Apr 2020 11:29:53 -0700 (PDT) X-Google-Smtp-Source: APiQypLxWY8AmZGh/nq0x/NTid9eX45xoQHyRwXvjI1Rdgpl7GtxWwVJ7hBNayW+SPd4MTpKYe0q X-Received: by 2002:a05:6402:1b91:: with SMTP id cc17mr3638381edb.46.1588184992992; Wed, 29 Apr 2020 11:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588184992; cv=none; d=google.com; s=arc-20160816; b=jhPxGObk8oZ5iN/fKVAkgCvCjq2AV0KvBANww0yAfy75ku+lDWA/IT4smBp5SLiDj4 4LY6glG9LyyalNzjjxixGGLrmySQFus+terSNIcbw+WzUJMEvs4FoxzBe22KDCIQiTa7 EH0FTskaycD8YAF5zLZ99abSfZga5gfdVK+kGMLaWoqaz+ccOnLHNb3g6S9UG5987jUv rnsdELZ1UNlMq7XhJr2GMh6puHKSibwpR0x1ZCt2uCVhDhV65+hotEHt8CzyHFXs6qad kHtK9UvUyN88Yww+gEav2XS3DD1CtVn+ql7xOwDMFMFyWSDVkk2g4qP67CAkSHoVaYqu VkNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=mk8Z9sCY0AhAexl6PYPVinqKRa9QYElOCdGLIqmtc8Y=; b=ffchEfRUKcMKOC1gx3ujIiV37QblMsfAOmVnpQ0sUjO5WsjDzYWZCDB6xiemCJNgNs Dtal9YYpaac77EvnN8mt9pBk4unOWqRZ99xsu6g0KcMlMSRZEMXtAZtnbJE/2OMmNZH7 rwbsMeZB9nGc1WbcBHKWGWhbokO4ZmGSG8422qNhH+5beqFDuhEOr07AVZ5TVqn+xdVC A+BSh6VWTv4d7/JXzmqKlmCx7HAXeIKIjdp+znMgDqbSC46NfaQICNZW2cX/q3JtNm5H qJou3ikCEBKPKYpxdsWtjp+l7ua8QatMSamh6T8gpThQIQs69L1uo21JENlD2TAh7GW3 HUQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=h0NgVJZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s8si3561055edw.484.2020.04.29.11.29.28; Wed, 29 Apr 2020 11:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=h0NgVJZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbgD2SZW (ORCPT + 99 others); Wed, 29 Apr 2020 14:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726456AbgD2SZV (ORCPT ); Wed, 29 Apr 2020 14:25:21 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A388EC03C1AE for ; Wed, 29 Apr 2020 11:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mk8Z9sCY0AhAexl6PYPVinqKRa9QYElOCdGLIqmtc8Y=; b=h0NgVJZnMQxSMXEuqfJICAC3T9 DVTnQvYxycKsv119y9J9+OnK1xPBqKoOR2PzIMa+JPHZwiYWXb4EMkeDgGRU2AX5x0vdOMVmgOmSE 8eWtvR4CrHy/U2yEyWpy2SBgyZ/tKI2xbT7qpHjwOT3x+1mXJLdnuBHtSnaiVPx3lnW7fL0HLCoer 29gnZMWOkrivqfvC//UzEW8RHJmYHhDxbsAYgo35Goc1Khg5XZ9dIfEOm24XjJVFDS02HP8OFBot/ wvNgnzAQtcHCHkX4ANTRtpwbAjyrfCGobZGvRfPs5bApZTRz1dot8UtI4KoccJkt/8ho14puFjqGZ /VKECLDw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrOO-0006rY-LW; Wed, 29 Apr 2020 18:25:08 +0000 Date: Wed, 29 Apr 2020 11:25:08 -0700 From: Matthew Wilcox To: Markus Elfring Cc: Waiman Long , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Kees Cook , Changbin Du , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm/slub: Fix incorrect interpretation of s->offset Message-ID: <20200429182508.GU29705@bombadil.infradead.org> References: <20200429135328.26976-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 29, 2020 at 06:42:55PM +0200, Markus Elfring wrote: > > In a couple of places in the slub memory allocator, the code uses > > "s->offset" as a check to see if the free pointer is put right after the > > object. That check is no longer true with commit 3202fa62fb43 ("slub: > > relocate freelist pointer to middle of object"). > > Will any further collateral evolution become interesting? What do you mean by this question? > > +static inline unsigned int get_info_end(struct kmem_cache *s) > > +{ > > + if (freeptr_outside_object(s)) > > + return s->inuse + sizeof(void *); > > + else > > + return s->inuse; > > +} > > How do you think about the following source code variants? > > + return freeptr_outside_object(s) > + ? s->inuse + sizeof(void *) > + : s->inuse; That is less clear than the version Wayman posted. > > static struct track *get_track(struct kmem_cache *s, void *object, > > enum track_item alloc) > > { > > struct track *p; > > > > - if (s->offset) > > - p = object + s->offset + sizeof(void *); > > - else > > - p = object + s->inuse; > > + p = object + get_info_end(s); > > > > return p + alloc; > > } > > + struct track *p = object + get_info_end(s); > > return p + alloc; Yes, I think that's an improvement.