From patchwork Tue Mar 28 09:58:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 13190792 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 68E46C761A6 for ; Tue, 28 Mar 2023 09:59:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E4936B007E; Tue, 28 Mar 2023 05:59:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06EE36B0080; Tue, 28 Mar 2023 05:59:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E296E6B0081; Tue, 28 Mar 2023 05:59:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D2E756B007E for ; Tue, 28 Mar 2023 05:59:02 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 971D41C319D for ; Tue, 28 Mar 2023 09:59:02 +0000 (UTC) X-FDA: 80617858524.29.23559C0 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf23.hostedemail.com (Postfix) with ESMTP id BC84B14000C for ; Tue, 28 Mar 2023 09:59:00 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VsNWH6wb; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679997540; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a9z+2OKezgBl6Xq8s4/uft3FH4lHgs0F/FglMYKuxZE=; b=eT5XWJtRSIij+Gmq8AalfrLotkG4OuIoZQDSrPSlVRZbzvRXgBr2r5Mnvn8I6C0a4HjBFf LXY43U/Ehw4SgfjyQ08vNTzCGab17BERlfLW4fWBMgYSv28NfAS3+YoJZ4b8AZY2ZBrMNa oFaKVAh8bTpeZ+i1c32SumgFHyJXxUg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VsNWH6wb; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679997540; a=rsa-sha256; cv=none; b=hD3YDhfDlehmxSBmAPB5jTL/JJI2wROLR4DHi8gs/6WVIbl5y3YHfx/Pt+8HQQMCPZ0GcG h7EeNpz8h1ZautIqWzYqemdJiv5S1DfNVD6dzDQhDeGHbksZwGIgFPKVD2AG/3CKdl2JcH kFFd0dtQ7JVeCBMs6LUnV3M3RcWQSYw= Received: by mail-pj1-f47.google.com with SMTP id mp3-20020a17090b190300b0023fcc8ce113so14560189pjb.4 for ; Tue, 28 Mar 2023 02:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679997539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a9z+2OKezgBl6Xq8s4/uft3FH4lHgs0F/FglMYKuxZE=; b=VsNWH6wbabZBW09E5p1rywOaT5p8dwv3DVQF4JxvKy8pAkOwOWTmSR3v5YYbHdOVIH o9LpPW7UeEmwFT8bwKYV0uifRm0n7p6iEYBMeiwyTvcS/TasidJuyj7P88eL57v1KTDd tI7u4PDJStX8H8gJLJrbqJ2Kof9xiRkHbs+wEsWSrPnUYYMPFzysTbud6J24HgyFWNpP x/6rvB/nHTaJWJCevltlgD8XQOccc/yfD7VHMVUS6y71oqY16doN1wfGwwkfO74aIK1P TXfWcZDvSIRMhEA4BilI3L6ew7QAaPregsJwYg77jDT/Rie9uRJd+pu1GfBpPZf028JJ BL6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679997539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a9z+2OKezgBl6Xq8s4/uft3FH4lHgs0F/FglMYKuxZE=; b=hE5ON2QLzNz2nlZVMVNawYCpB7U5kndfeRuDW8pn9I/f5CZaPZYK2qIIRPiecfcixI G6P4dBywY0yAs8sRom63p7WerJ4UrbDN/osFtX3a42t7HTDFTNkHQF5hjdVDfCf0At/U xCQICbKbTqo2TgN2T5CxGFc9beBYhIaXL7waEvDz0Rb8mn3Fk2U1j3XFNUM4DJY+TSJj 2ewJz7jzME9qSSdTMZ31DGofPQ1ZKB/73WdyzyxlwOQ7NSV11u2GxJwx1XsQgttLSWvP b2VBN7lzpTl1GMuhC05EfgIZwajgwaN4q+tdqBMAvBOslwWKpD65hqOZ9C9+dJ3frvje ishQ== X-Gm-Message-State: AO0yUKUmcFLvSk+xBI5c/m9MKqoxdU7ZX0eZb4jIvTncE0eoKVCR8T9z dTsne2P7tsS+uaXGQG1y+5TD7w== X-Google-Smtp-Source: AK7set+sSOqvm7BhrGFyb5OKdu0ZTvBWUBOT2Bfsk23ttc/ateaVqwe3xWklthmOX72MppMUmuO5pA== X-Received: by 2002:a05:6a20:6aa0:b0:d9:2d4e:c08c with SMTP id bi32-20020a056a206aa000b000d92d4ec08cmr12797492pzb.61.1679997539764; Tue, 28 Mar 2023 02:58:59 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id m26-20020aa78a1a000000b005a8a5be96b2sm17207556pfa.104.2023.03.28.02.58.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Mar 2023 02:58:59 -0700 (PDT) From: Muchun Song To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, jannh@google.com, sjpark@amazon.de, muchun.song@linux.dev Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH 6/6] mm: kfence: replace ALIGN_DOWN(x, PAGE_SIZE) with PAGE_ALIGN_DOWN(x) Date: Tue, 28 Mar 2023 17:58:07 +0800 Message-Id: <20230328095807.7014-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230328095807.7014-1-songmuchun@bytedance.com> References: <20230328095807.7014-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BC84B14000C X-Stat-Signature: fdibim8i7mip3pcs4iq16kjnhafs3i7s X-HE-Tag: 1679997540-426727 X-HE-Meta: U2FsdGVkX19e90WuUUk0vHIVi/ksVClmFfxqX4Jxoggg9nBB/+ToxI+gDKRQwinPxPQ265rkd6mKjKSMmZgFwvi0zmBcwRbaeeJu2NIMNx8bZdbKuodHL639Shkxk+tk8s3pyRyoxX2rUnW3PEvdBnr8MgQXNnJ2XQwiisQwHKUj05Pvlq5OwjvEaXrCx0Ic6xkUXKnDyGZuGx8ENZ8aSEWwcdqxXpEjN/9qJlPHyNqRaABwBtn1edP4wV8ywidklC6e+wWAG+sil+MaSSfaNFBJ8jPPlNjZh1nfW79R93z6fZQF5WJk/HgWrATIYhrVearrVsgELWFd9C+f8CSGLNr8WfwfRc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w4eG0BNIN7pCTmajv83v/VolN4aSBkiqGgLKBWUHen8bg9eBWZl0u 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: Replace ALIGN_DOWN(x, PAGE_SIZE) with PAGE_ALIGN_DOWN(x) to simplify the code a bit. Signed-off-by: Muchun Song Reviewed-by: Marco Elver --- mm/kfence/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index f205b860f460..dbfb79a4d624 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -230,17 +230,17 @@ static bool alloc_covered_contains(u32 alloc_stack_hash) static inline void kfence_protect(unsigned long addr) { - kfence_protect_page(ALIGN_DOWN(addr, PAGE_SIZE), true); + kfence_protect_page(PAGE_ALIGN_DOWN(addr), true); } static inline void kfence_unprotect(unsigned long addr) { - kfence_protect_page(ALIGN_DOWN(addr, PAGE_SIZE), false); + kfence_protect_page(PAGE_ALIGN_DOWN(addr), false); } static inline unsigned long metadata_to_pageaddr(const struct kfence_metadata *meta) { - return ALIGN_DOWN(meta->addr, PAGE_SIZE); + return PAGE_ALIGN_DOWN(meta->addr); } /* @@ -308,7 +308,7 @@ static inline bool check_canary_byte(u8 *addr) /* __always_inline this to ensure we won't do an indirect call to fn. */ static __always_inline void for_each_canary(const struct kfence_metadata *meta, bool (*fn)(u8 *)) { - const unsigned long pageaddr = ALIGN_DOWN(meta->addr, PAGE_SIZE); + const unsigned long pageaddr = PAGE_ALIGN_DOWN(meta->addr); unsigned long addr; /* @@ -455,7 +455,7 @@ static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z } /* Detect racy use-after-free, or incorrect reallocation of this page by KFENCE. */ - kcsan_begin_scoped_access((void *)ALIGN_DOWN((unsigned long)addr, PAGE_SIZE), PAGE_SIZE, + kcsan_begin_scoped_access((void *)PAGE_ALIGN_DOWN((unsigned long)addr), PAGE_SIZE, KCSAN_ACCESS_SCOPED | KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT, &assert_page_exclusive); @@ -464,7 +464,7 @@ static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z /* Restore page protection if there was an OOB access. */ if (meta->unprotected_page) { - memzero_explicit((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), PAGE_SIZE); + memzero_explicit((void *)PAGE_ALIGN_DOWN(meta->unprotected_page), PAGE_SIZE); kfence_protect(meta->unprotected_page); meta->unprotected_page = 0; }