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 D91A6C43334 for ; Thu, 7 Jul 2022 11:44:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 460536B0072; Thu, 7 Jul 2022 07:44:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E86E6B0073; Thu, 7 Jul 2022 07:44:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 289696B0074; Thu, 7 Jul 2022 07:44:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 14F766B0072 for ; Thu, 7 Jul 2022 07:44:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id E002C80E68 for ; Thu, 7 Jul 2022 11:44:37 +0000 (UTC) X-FDA: 79660121394.25.8E8F955 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf30.hostedemail.com (Postfix) with ESMTP id 75A648005E for ; Thu, 7 Jul 2022 11:44:37 +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 9B686B82139; Thu, 7 Jul 2022 11:44:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EE3CC3411E; Thu, 7 Jul 2022 11:44:32 +0000 (UTC) Date: Thu, 7 Jul 2022 12:44:29 +0100 From: Catalin Marinas To: Will Deacon 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: References: <20220610152141.2148929-1-catalin.marinas@arm.com> <20220610152141.2148929-2-catalin.marinas@arm.com> <20220707092236.GB4133@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220707092236.GB4133@willie-the-truck> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657194277; 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; bh=wyhNe3mfr/pF43Nxat/aKYEI3d0n5RzaEwenkSVEsGU=; b=Y/PSgPtPoBPTc8lyyXDoMU4iiMAKxYtgPv4lndEqa4Y35VxDdk94Gf0nA9QDElu1Wj5ocz Jk3Ogw4EfwB2uSzJKk79Xv4JVJXnWuUxvPIKa50hS3AJKbdoikhxTvvlwlOxd5v8IpN3Di lSM26ZP+HB0ZbrBxudO1p4T0/ukjcYk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657194277; a=rsa-sha256; cv=none; b=4h8YkbxtF+ELlgftVUhUeQ2a9asJ1HZygfbuQfW4ieJeShwJoGvEEbzCrG6heKEl3kNenf 3pdIrJ9J/yZ4Ch3mcd8GSDem60q0tU89FQIlLUqLUTCQ3gFqhxOIeNZqfCbyTEr4Nl1D03 hjrzvCGEPPDvs/VY1TkHyn4ZPi19lwU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 75A648005E X-Stat-Signature: ceku5d8nfqaef6s1wz3pxtcektddew6t X-HE-Tag: 1657194277-244783 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 Thu, Jul 07, 2022 at 10:22:37AM +0100, Will Deacon wrote: > 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? I think it can be a try_cmpxchg_release() (I did not realise we have one). I'll post a patch later today. -- Catalin