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 2AAD4C4167B for ; Thu, 7 Dec 2023 21:05:19 +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=ug9bh7jcgvWprNRoj+vjelcfSr2rzROACeeOfgqwNf0=; b=Yq3+yJ02msJNyb eYMuq+BeesBoeMxTXk/LEr5k7gQ7ySfizubXsOUHGlkVI5o/L2v7PRfaLQX6/Ve0nBNKeOoE3YP/j tCgszOyzbJPET2+s3nK25cqs0QpZ9sbzhbuoa/DF91MVdlgx1RkArxD14beeszd1kmmzkZE1X6Wjh wRy0OdPf0/6+WxT9NsKZb7P5tuyJ8P+/IIFjd4guQgEV2YkYLS9by71vaaLYjh53Lkumd4ZUOAqYx 6BXMH5PA3gPPONDXBTDiwZawpUbuGg024wFL1YjYqUp2CyvJq/tXNqaYBQ5eakkrm2oJu2Ikk91ko BxsQJnNeI0gOVE8TGavw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBLY5-00Dujn-1Q; Thu, 07 Dec 2023 21:04:45 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBLY2-00DuiR-2h for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2023 21:04:44 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2851a2b30a2so1194968a91.3 for ; Thu, 07 Dec 2023 13:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701983081; x=1702587881; 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=P1df2F2aMLldf9qn7FPBt3am2yl+mT6QC0UrRj9+Dnw=; b=AqD62xgKL7cfp/y+T10vWEG2HlLq9DXxL/FZjSiRjnqn1C4ivxqZn16wRj9dFDMWbT K7Z5XLusthhFbtYC6JcyT1jYvPHrixOfpHwfozyUffg730vFmbtguiMl8O/37SlabxbN XSWM0zvi7YKnF7qVHwOkP2i9NZ4mPMGw3qYhU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701983081; x=1702587881; 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=P1df2F2aMLldf9qn7FPBt3am2yl+mT6QC0UrRj9+Dnw=; b=xGA4OxRakMkP46EOAhDJLAxpS1s6RjRosPpmNity5hV2a5GWHkFHB7zy30Obkwt1D1 ewlt8ZmnCgW9O81OLgPdMmzt/MDqOojQzFbcB5vNEwsNsRDKkCMEeQEkAsOrwvnC/fQh 1d3aL8nf5Ml+XYpTh98qrWtpgwujDxl39/rhBrwXPv4WJIJ774g2pQqDryZgjoPbk+WA qU61I96HcP7GJxr91Vf/wEdjYtRKbrRA9pvh/7RjXTlimTN2Rn8Jj6YHNU+dmK/oswld zNtPjaA/wkZ2ETIdXkhOfnS49cnLCRyxy036cey1IB4ZoYlF8+O2y30rhQTEnePUGqT9 ZaOQ== X-Gm-Message-State: AOJu0Yx8zX1HkjXAZjVPE+8bxTDNEVac3kCWRL1GhYhIGAFzHrDFWxev 1tmW22NwwRVZbFDq3XHYTTIkMA== X-Google-Smtp-Source: AGHT+IF4dR+ozEHEoTeZ5KlcYJqBauEZDgcWSu4X4MZ186gCsrYPLTr0XOCn3gkc/RW+9rLwjr8oiw== X-Received: by 2002:a17:90b:350a:b0:285:b3a8:40ac with SMTP id ls10-20020a17090b350a00b00285b3a840acmr2717736pjb.19.1701983080991; Thu, 07 Dec 2023 13:04:40 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id sc4-20020a17090b510400b002868d090c27sm354680pjb.25.2023.12.07.13.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:04:40 -0800 (PST) Date: Thu, 7 Dec 2023 13:04:39 -0800 From: Kees Cook To: "Liam R. Howlett" Cc: Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mark Brown , Naresh Kamboju , linux-kselftest@vger.kernel.org, Linux ARM , kft-triage@lists.linaro.org, regressions@lists.linux.dev, Will Deacon , Catalin Marinas , Dan Carpenter , Eric Biederman , linux-next@vger.kernel.org Subject: Re: [PATCH] maple_tree: Fix mas_prev() state separation code Message-ID: <202312071302.99D5B1BB76@keescook> References: <20231207014104.n6vul2ylgqjnsfia@revolve> <20231207193319.4025462-1-Liam.Howlett@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231207193319.4025462-1-Liam.Howlett@oracle.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_130442_879393_BDA7A25D X-CRM114-Status: GOOD ( 26.38 ) 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 07, 2023 at 02:33:19PM -0500, Liam R. Howlett wrote: > mas_prev() was setting the ma_underflow condition when the limit was > reached and not when the limit was attempting to go lower. This > resulted in the incorrect behaviour on subsequent actions. > > This commit fixes the status setting to only set ma_underflow when the > lower limit is attempted to be decremented, and modifies the testing to > ensure that's the case. > > Signed-off-by: Liam R. Howlett Is this is related to the report[1] I forwarded? If so, please add these tags too: Reported-by: Linux Kernel Functional Testing Closes: https://lore.kernel.org/all/CA+G9fYs-j2FYZSFSVZj48mgoM9gQd4-7M2mu2Ez3D1DqDdW2bQ@mail.gmail.com/ [1] Thanks either way! -Kees > --- > > Andrew, > > This should be clean to squash into 7f79fdb1d94d7 ("maple_tree: separate > ma_state node from status.") which is currently in your mm-unstable > branch. > > Thanks, > Liam > > > lib/maple_tree.c | 16 ++++++++++++---- > lib/test_maple_tree.c | 9 +++++++-- > 2 files changed, 19 insertions(+), 6 deletions(-) > > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > index 89f8d21602774..47f2a7a973852 100644 > --- a/lib/maple_tree.c > +++ b/lib/maple_tree.c > @@ -4432,6 +4432,9 @@ static void *mas_prev_slot(struct ma_state *mas, unsigned long min, bool empty) > mas->last = mas->index - 1; > mas->index = mas_safe_min(mas, pivots, mas->offset); > } else { > + if (mas->index <= min) > + goto underflow; > + > if (mas_prev_node(mas, min)) { > mas_rewalk(mas, save_point); > goto retry; > @@ -4452,15 +4455,15 @@ static void *mas_prev_slot(struct ma_state *mas, unsigned long min, bool empty) > if (unlikely(mas_rewalk_if_dead(mas, node, save_point))) > goto retry; > > - if (mas->index <= min) > - mas->status = ma_underflow; > > if (likely(entry)) > return entry; > > if (!empty) { > - if (mas_is_underflow(mas)) > + if (mas->index <= min) { > + mas->status = ma_underflow; > return NULL; > + } > > goto again; > } > @@ -4596,7 +4599,7 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty) > if (unlikely(mas_rewalk_if_dead(mas, node, save_point))) > goto retry; > > - if (pivot >= max) { > + if (pivot >= max) { /* Was at the limit, next will extend beyond */ > mas->status = ma_overflow; > return NULL; > } > @@ -4611,6 +4614,11 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty) > else > mas->last = mas->max; > } else { > + if (mas->last >= max) { > + mas->status = ma_overflow; > + return NULL; > + } > + > if (mas_next_node(mas, node, max)) { > mas_rewalk(mas, save_point); > goto retry; > diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c > index 15fbeb788f3ac..29185ac5c727f 100644 > --- a/lib/test_maple_tree.c > +++ b/lib/test_maple_tree.c > @@ -3294,8 +3294,8 @@ static noinline void __init check_state_handling(struct maple_tree *mt) > MT_BUG_ON(mt, mas.last != 0x1500); > MT_BUG_ON(mt, !mas_is_active(&mas)); > > - /* next:active ->active */ > - entry = mas_next(&mas, ULONG_MAX); > + /* next:active ->active (spanning limit) */ > + entry = mas_next(&mas, 0x2100); > MT_BUG_ON(mt, entry != ptr2); > MT_BUG_ON(mt, mas.index != 0x2000); > MT_BUG_ON(mt, mas.last != 0x2500); > @@ -3360,6 +3360,11 @@ static noinline void __init check_state_handling(struct maple_tree *mt) > MT_BUG_ON(mt, entry != ptr); > MT_BUG_ON(mt, mas.index != 0x1000); > MT_BUG_ON(mt, mas.last != 0x1500); > + MT_BUG_ON(mt, !mas_is_active(&mas)); /* spanning limit */ > + entry = mas_prev(&mas, 0x1200); /* underflow */ > + MT_BUG_ON(mt, entry != NULL); > + MT_BUG_ON(mt, mas.index != 0x1000); > + MT_BUG_ON(mt, mas.last != 0x1500); > MT_BUG_ON(mt, !mas_is_underflow(&mas)); > > /* prev:underflow -> underflow (lower limit) spanning end range */ > -- > 2.40.1 > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel