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 AA6FEC636CC for ; Thu, 16 Feb 2023 14:29:03 +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=AbQcvzH1+lULGO7Z4tBTWGRiUCgdc+XoXQpzMpAosR0=; b=1wM++6ULWU00Pq rvE3+mRU4E4DkfOjPZc/3R/RwNpnm2EJr/VMLCEPZ4+ggT4OfFkPowOgC5Ykzha74s7f6/+B80+SN urL6dN0Drw4d7LKvD1BjOy+Y83ucBKO8C1zCPDUpUGV5FjPda0ZuQJg/MKX1NHhSnQsvyZxGZjSxB l5roEi2MrxCHCWkfpwuwJMMknNTPhZ4Wd7qTdHPf8TmY0u3JiHv4CPErviS7Q6X2UKqivx8+Rw+nA nfRJdtMMjdiZko+LIIiYjlXKFxapr/hnk01B8tgfKKRavwLxtFd6/q4eCXqNh9vZQX044FSQwU0D9 d3iNWBcgLcpRkHhtzF3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSfEx-00AcTl-M4; Thu, 16 Feb 2023 14:28:04 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSfEn-00AcQh-NI for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2023 14:27:55 +0000 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7DAE160EC0; Thu, 16 Feb 2023 14:27:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D8B5C433D2; Thu, 16 Feb 2023 14:27:50 +0000 (UTC) Date: Thu, 16 Feb 2023 14:27:47 +0000 From: Catalin Marinas To: Peter Collingbourne Cc: andreyknvl@gmail.com, linux-mm@kvack.org, kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com Subject: Re: [PATCH] kasan: call clear_page with a match-all tag instead of changing page tag Message-ID: References: <20230216064726.2724268-1-pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230216064726.2724268-1-pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230216_062753_850852_8C02E6AC X-CRM114-Status: GOOD ( 19.73 ) 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 Wed, Feb 15, 2023 at 10:47:26PM -0800, Peter Collingbourne wrote: > Instead of changing the page's tag solely in order to obtain a pointer > with a match-all tag and then changing it back again, just convert the > pointer that we get from kmap_atomic() into one with a match-all tag > before passing it to clear_page(). > > On a certain microarchitecture, this has been observed to cause a > measurable improvement in microbenchmark performance, presumably as a > result of being able to avoid the atomic operations on the page tag. Yeah, this would likely break the write streaming mode on some ARM CPUs. > Signed-off-by: Peter Collingbourne > Link: https://linux-review.googlesource.com/id/I0249822cc29097ca7a04ad48e8eb14871f80e711 > --- > include/linux/highmem.h | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/include/linux/highmem.h b/include/linux/highmem.h > index 44242268f53b..bbfa546dd602 100644 > --- a/include/linux/highmem.h > +++ b/include/linux/highmem.h > @@ -245,12 +245,10 @@ static inline void clear_highpage(struct page *page) > > static inline void clear_highpage_kasan_tagged(struct page *page) > { > - u8 tag; > + void *kaddr = kmap_atomic(page); > > - tag = page_kasan_tag(page); > - page_kasan_tag_reset(page); > - clear_highpage(page); > - page_kasan_tag_set(page, tag); > + clear_page(kasan_reset_tag(kaddr)); > + kunmap_atomic(kaddr); > } Please don't add kmap_atomic() back. See commit d2c20e51e396 ("mm/highmem: remove deprecated kmap_atomic"). I'd duplicate the clear_highpage() logic in here and call clear_page() directly on the address with the kasan tag reset. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 7DEB1C61DA4 for ; Thu, 16 Feb 2023 14:27:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8DA6B0074; Thu, 16 Feb 2023 09:27:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 968486B0075; Thu, 16 Feb 2023 09:27:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 856866B0078; Thu, 16 Feb 2023 09:27:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 784226B0074 for ; Thu, 16 Feb 2023 09:27:55 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4703B801BB for ; Thu, 16 Feb 2023 14:27:55 +0000 (UTC) X-FDA: 80473384110.05.FB12F25 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 8DF4A40010 for ; Thu, 16 Feb 2023 14:27:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676557673; 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=48fO3JbsEc3aZalpD8wObnGiS7gasR3PAA5gkMgL9tA=; b=FboXVsDDUN/P4GripEr/7ZEkqHnQBRM+NCnami/VveVrh+zfSBSxLbHuL/FAmFQ2afG79u HOMQ4kzn9jdkeNIZDYvGKZ/3RbncXSbC1x0QCFJiDzw0JWSRUfSMdndcAZ5FBekv91RusN RNAQwZMZMt+YTnDIFYx2Yan5EsCVBGM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676557673; a=rsa-sha256; cv=none; b=MMA6dLVpucMBnUxDzsIAyv1wGNJnAL2wC83E7AZikryZ1IpKN5ZYdEV4SyyCxCLHPoeGU4 74nOfn5S7qeZmPF42fB/HXl/2kCN50mY5wTuF9pcejmFbjh5a+qWJkcYd8+1rZIRwv35o/ 7xZfQYuNuhNOz/g28rzC5uMGZaXXb2M= 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7DAE160EC0; Thu, 16 Feb 2023 14:27:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D8B5C433D2; Thu, 16 Feb 2023 14:27:50 +0000 (UTC) Date: Thu, 16 Feb 2023 14:27:47 +0000 From: Catalin Marinas To: Peter Collingbourne Cc: andreyknvl@gmail.com, linux-mm@kvack.org, kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com Subject: Re: [PATCH] kasan: call clear_page with a match-all tag instead of changing page tag Message-ID: References: <20230216064726.2724268-1-pcc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230216064726.2724268-1-pcc@google.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8DF4A40010 X-Stat-Signature: xagtuu3nhb394mo8hdy18nx6c1rkrumj X-Rspam-User: X-HE-Tag: 1676557673-73005 X-HE-Meta: U2FsdGVkX1/Q5P0lVI5RbT6UK1k+O+xYWn6u8W6fWnPUxAGr4gjRqFLUPX+c94mewAV6KqNYA/4Vy8LtGn69Gv6oCBe/2iuZHEEF2S6mRd/b3s3hKdiq8zGTrwOMXwcV+FZxNj9oRUc53/+m5jmUoIS2e4sPIYhulQxmmUfjNehjCOkD5gZH3A4dLOX0PA7MGIx+BsymPY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KO6WtiMcJy2u8+FSZpGjrjjenPuEB0i9FmOMSqe0E5eHyYROOUET0lJS3cyZzNyi5PxR1KRO9U8oVZMB+d/lqIV4Pa2c8u0QO/GXMzlKmnTr923DKVRb9u2VgOdaP4FZT6B+sVlZ0t3Z/RlZldRnd1XSWhKmOdbXHLdI28iBwL1RVSjFeedr7Q75915OX2Qj+i7V5vyZRy93hhYXRpDTSXFDek/L2RNOdmlbO9wN1j49XXHe8M53zk67m3aOiSLA4GDpzzRLJyOhGIFsar3l3+IJkS7TvXZRiX3N/zMzzGTS4C56Fx47kZOwIriLJ1m0QfbDwydl0sCgXHIJQriSJuWcnw8gXxK0HYfiiAsK+N 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 Wed, Feb 15, 2023 at 10:47:26PM -0800, Peter Collingbourne wrote: > Instead of changing the page's tag solely in order to obtain a pointer > with a match-all tag and then changing it back again, just convert the > pointer that we get from kmap_atomic() into one with a match-all tag > before passing it to clear_page(). > > On a certain microarchitecture, this has been observed to cause a > measurable improvement in microbenchmark performance, presumably as a > result of being able to avoid the atomic operations on the page tag. Yeah, this would likely break the write streaming mode on some ARM CPUs. > Signed-off-by: Peter Collingbourne > Link: https://linux-review.googlesource.com/id/I0249822cc29097ca7a04ad48e8eb14871f80e711 > --- > include/linux/highmem.h | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/include/linux/highmem.h b/include/linux/highmem.h > index 44242268f53b..bbfa546dd602 100644 > --- a/include/linux/highmem.h > +++ b/include/linux/highmem.h > @@ -245,12 +245,10 @@ static inline void clear_highpage(struct page *page) > > static inline void clear_highpage_kasan_tagged(struct page *page) > { > - u8 tag; > + void *kaddr = kmap_atomic(page); > > - tag = page_kasan_tag(page); > - page_kasan_tag_reset(page); > - clear_highpage(page); > - page_kasan_tag_set(page, tag); > + clear_page(kasan_reset_tag(kaddr)); > + kunmap_atomic(kaddr); > } Please don't add kmap_atomic() back. See commit d2c20e51e396 ("mm/highmem: remove deprecated kmap_atomic"). I'd duplicate the clear_highpage() logic in here and call clear_page() directly on the address with the kasan tag reset. -- Catalin