From patchwork Thu Jun 30 07:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 12901314 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 ABB9FC433EF for ; Thu, 30 Jun 2022 07:48:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6F568E0002; Thu, 30 Jun 2022 03:48:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1DD28E0001; Thu, 30 Jun 2022 03:48:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0C528E0002; Thu, 30 Jun 2022 03:48:07 -0400 (EDT) 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 C39B08E0001 for ; Thu, 30 Jun 2022 03:48:07 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 97B9B610E7 for ; Thu, 30 Jun 2022 07:48:07 +0000 (UTC) X-FDA: 79634123814.08.8227441 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 30D1410002F for ; Thu, 30 Jun 2022 07:48:07 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-31797057755so148321637b3.16 for ; Thu, 30 Jun 2022 00:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=XzzQ2qeoRIHvL3OIKjNQCubCMmqjty1j1wRkBLGrTgU=; b=Cd/RaHs88ciLdA0+wMopNk5kjW44si1O/9QcrziajxdH20xK3UlUrP0+vLXx20MY1D RUAPNooz1wh14yhNsjZ2DPh04r1TSjAWbZGLdxIfADNCLsKIMVoe0rCwGDelPXBS/q07 bfBF8ggVR84eJmwoJcidKJXXyP0skwxvM4oMo5jDBjsdLzw0hq+urk9Vt1El1I0pNXOY Ui9qvmcqqGBAUjeUZNZ2TMfeCjGGtWzShSjtdHoo+rJ8+Q89q47gWg1OYS6AOODEA8yv r7cKAeIge6MraBq4l/vTR1evClWD+lPEjdb8uPAySVuqmLU0+iIs7L3MgEN1SzQNTG1I CBDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=XzzQ2qeoRIHvL3OIKjNQCubCMmqjty1j1wRkBLGrTgU=; b=44++Vr/lNWD+q8WMu6rhjrIjgRwQPTIobY2GZIZPUOLsh3D6t4YWeyi0vYPaPuhA6L n9Tz/Jjf526Id0RizbHUPtU8qqJr+t7f8cKdrjp0baHxr/wnqjmJoPqdHVU5sTCXHwXO rTS9G2ZNSvrZ4RUn0aTMmwLeN1rFxoMwkoXWRpCqTBn2yc049+jItekMr2dFA9ja3c9x R4OzWBRPJE65uxAGuqckvqdOvbrtUlvrG/xYyFsakdw9kIXW6jHWWXSzFCBtyub0tovd 5FWkO8PXQDUN0M7d2cchOPJ9IchCmSRM0F1RVfAE3GZ0O5XBGWwf7SjXTiynHFoOUdJS I3Bg== X-Gm-Message-State: AJIora8wnBo/WQwalhjf6J9V4WiVQOBGkar5sPFu2wMA6zuJeMFNAnIw ZTyxg0ObLbv6rflv8zDI8nmNGy/CdQWg5A== X-Google-Smtp-Source: AGRyM1vSiWG5UsJn1FGs8y/l+5be4umvT4PkYpnDFc4Cbi+MLFCVLCTtuQ8PN01k8FUWH9WOK1+ovGD2Wp1BOA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:2f81:0:b0:66d:9a86:f6de with SMTP id v123-20020a252f81000000b0066d9a86f6demr3315237ybv.590.1656575286295; Thu, 30 Jun 2022 00:48:06 -0700 (PDT) Date: Thu, 30 Jun 2022 15:47:56 +0800 Message-Id: <20220630074757.2739000-1-davidgow@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v3 1/2] mm: Add PAGE_ALIGN_DOWN macro From: David Gow To: Vincent Whitchurch , Johannes Berg , Patricia Alfonso , Jeff Dike , Richard Weinberger , anton.ivanov@cambridgegreys.com, Dmitry Vyukov , Brendan Higgins , Andrew Morton , Andrey Konovalov , Andrey Ryabinin Cc: David Gow , kasan-dev , linux-um@lists.infradead.org, LKML , Daniel Latypov , linux-mm@kvack.org, kunit-dev@googlegroups.com ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Cd/RaHs8"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3NlW9YggKCPEWTobWZhpZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--davidgow.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3NlW9YggKCPEWTobWZhpZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--davidgow.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656575287; a=rsa-sha256; cv=none; b=hlX6S50m4OcsMBVJS0jCrnIpiNKEHRu99vV1oBc+Y7ao94+wIwj8V66JcREmI4LMsk9zn2 DDH58RSlFKe6ItO/xG7g8V1jN/jl4G4Z3reVeuB/s2c11Hh8jVSQD9A9cI2CHYfXNwUHY/ SLCeaCh0EH3NDKqXuIokh9dIq7OMNRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656575287; 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: references:dkim-signature; bh=XzzQ2qeoRIHvL3OIKjNQCubCMmqjty1j1wRkBLGrTgU=; b=YV1IUDlVQPGiHiqZUTOhOGsvBHgqYWE9De5teY6dKf8gbtdMMzXHdg5ZYQbcPJVfN8/v/b hD1qpjKJL1UQTzX7lXfbUz3mCFMejG6zS0CszArrsIoD7X/v6/X2fqgoZ1Va+2xFK/Ewxj ts86Je79QCxAZDfN5l5+25jV1prDGkY= X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Cd/RaHs8"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3NlW9YggKCPEWTobWZhpZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--davidgow.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3NlW9YggKCPEWTobWZhpZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--davidgow.bounces.google.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 30D1410002F X-Stat-Signature: bwo8yks7ajdjdgkeq69e6i7ues8d18ce X-HE-Tag: 1656575287-325614 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000027, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is just the same as PAGE_ALIGN(), but rounds the address down, not up. Suggested-by: Dmitry Vyukov Signed-off-by: David Gow Acked-by: Andrew Morton --- Please take this patch as part of the UML tree, along with patch #2, thanks! Changes since v2: https://lore.kernel.org/lkml/20220527185600.1236769-1-davidgow@google.com/ - Add Andrew's Acked-by tag. v2 was the first version of this patch (it having been introduced as part of v2 of the UML/KASAN series). There are almost certainly lots of places where this macro should be used: just look for ALIGN_DOWN(..., PAGE_SIZE). I haven't gone through to try to replace them all. --- include/linux/mm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9f44254af8ce..9abe5975ad11 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -221,6 +221,9 @@ int overcommit_policy_handler(struct ctl_table *, int, void *, size_t *, /* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) +/* to align the pointer to the (prev) page boundary */ +#define PAGE_ALIGN_DOWN(addr) ALIGN_DOWN(addr, PAGE_SIZE) + /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */ #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE)