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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F11AFC433EF for ; Thu, 7 Jul 2022 09:22:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64D836B0072; Thu, 7 Jul 2022 05:22:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FD4D6B0073; Thu, 7 Jul 2022 05:22:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F9EB6B0074; Thu, 7 Jul 2022 05:22:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3FD896B0072 for ; Thu, 7 Jul 2022 05:22:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1F55160E1C for ; Thu, 7 Jul 2022 09:22:46 +0000 (UTC) X-FDA: 79659763932.26.B511D46 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf08.hostedemail.com (Postfix) with ESMTP id A9374160015 for ; Thu, 7 Jul 2022 09:22:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C816EB81990; Thu, 7 Jul 2022 09:22:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F313DC3411E; Thu, 7 Jul 2022 09:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657185762; bh=rUyiF49pZcPs1vPkVplvtBCMf33Tk6W3yTVktVfelqM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GL63VyMrzJ0jJLrMYM+6E4jvwMAN7McUDLwCZupNvgtpYNP4W9yfNKeyiW54O1J40 9GwFyXZq7okUhkFo4s2OgeAmEXs8SGO8gJU4BQzAuJl0Va+UwIsvB+L+EE8dIKpeTp vjm+uK0dilucCiaFC3xbZqzzJYlzZbodtUjYFswmYtibSXVBT2QszHijnthBFCfwjn avbVR/uSn04Hp6EYk5DLogYiJ6D6O4S3VEzs3xifqVXYyMu/fb4u6GccNw99ND4TYK iObV3zdHnSiw5aUUD+qVJsJuARmGYVB2E9rr+Y+geGr6E8IkJ5hiFtD3snUt2RoQzf ExQTuaneLtOyw== Date: Thu, 7 Jul 2022 10:22:37 +0100 From: Will Deacon To: Catalin Marinas Cc: Andrey Ryabinin , Andrey Konovalov , Vincenzo Frascino , Peter Collingbourne , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 1/4] mm: kasan: Ensure the tags are visible before the tag in page->flags Message-ID: <20220707092236.GB4133@willie-the-truck> References: <20220610152141.2148929-1-catalin.marinas@arm.com> <20220610152141.2148929-2-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220610152141.2148929-2-catalin.marinas@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657185765; a=rsa-sha256; cv=none; b=dY+EryR33XdkiB7sEy32HefDCXrJ0dh9S5lEG66CPVJxCwmEGlIEvJK6mwH6FAFk2amGfq TpqI4Pxtq3GAKyAzy+FxYyxA1Ra+vtYAgNuyPgjCaFPFwXekvex0W+70snTjAPrTh4aHQ4 n17jxCLNlya76eJB5szdoLHbnG0ir+c= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GL63VyMr; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of will@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=will@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657185765; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=z9GxHCih9xdUkN3bEI0ym+gczVQ8oNvHCNw1GBSJlno=; b=48DpdYVHSjI3WZkT1AgwpxaJiga73Z2LDoj9WwYF061Dae3YySfGz/VPKV3pRBP/dVnGhE NaIc4aiUfodM5mW5BELfYwKbI/rvWdQA5D7fbF0cETucZaZ7OEJlDwDl6PXnttaCuyjw1S 3Je5jLT1hrLv1llP0bLEt7bTg1R+rvo= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A9374160015 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GL63VyMr; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of will@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=will@kernel.org X-Stat-Signature: oh6ay4y7y8ssx4a9fw46kdzczh16mrhu X-HE-Tag: 1657185765-902531 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 Fri, Jun 10, 2022 at 04:21:38PM +0100, Catalin Marinas wrote: > __kasan_unpoison_pages() colours the memory with a random tag and stores > it in page->flags in order to re-create the tagged pointer via > page_to_virt() later. When the tag from the page->flags is read, ensure > that the in-memory tags are already visible by re-ordering the > page_kasan_tag_set() after kasan_unpoison(). The former already has > barriers in place through try_cmpxchg(). On the reader side, the order > is ensured by the address dependency between page->flags and the memory > access. > > Signed-off-by: Catalin Marinas > Reviewed-by: Andrey Konovalov > Cc: Andrey Ryabinin > Cc: Vincenzo Frascino > --- > mm/kasan/common.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index c40c0e7b3b5f..78be2beb7453 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -108,9 +108,10 @@ void __kasan_unpoison_pages(struct page *page, unsigned int order, bool init) > return; > > tag = kasan_random_tag(); > + kasan_unpoison(set_tag(page_address(page), tag), > + PAGE_SIZE << order, init); > for (i = 0; i < (1 << order); i++) > page_kasan_tag_set(page + i, tag); > - kasan_unpoison(page_address(page), PAGE_SIZE << order, init); This looks good to me, but after reading the cover letter I'm wondering whether the try_cmpxchg() in page_kasan_tag_set() could be relaxed to try_cmpxchg_release() as a separate optimisation? Will