From patchwork Wed Jan 29 22:41:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 13954200 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 CF24DC0218D for ; Wed, 29 Jan 2025 22:42:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4814D280095; Wed, 29 Jan 2025 17:42:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BB6B280091; Wed, 29 Jan 2025 17:42:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D48D280095; Wed, 29 Jan 2025 17:42:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DBB17280091 for ; Wed, 29 Jan 2025 17:42:24 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 97AC81C7029 for ; Wed, 29 Jan 2025 22:42:24 +0000 (UTC) X-FDA: 83061964608.18.3F001CF Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf12.hostedemail.com (Postfix) with ESMTP id C58E740006 for ; Wed, 29 Jan 2025 22:42:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="swBA/M54"; spf=pass (imf12.hostedemail.com: domain of 3za6aZwQKCNg9P7FAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--fvdl.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3za6aZwQKCNg9P7FAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738190542; 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=dXf4/6vVFsOQWOL4yP6AMC2Up5+2J9mezQuBbeYawcA=; b=uHHQq525Sxi5V/29uMVY1FYACI3xGIDUkiwyJ5vilf10H9jWMJqo4WhdzIQvqzN7Fyy9Tr jOvx9Kfh7zGSlPU8YTCQSTmmBWb0k4pnT8PLwaUtxJs5ugMb1QPcLiTgPdO6RV+BSNEHos hjXCNjzOpa/4qgKtdAzHdPY1iq9+dNY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="swBA/M54"; spf=pass (imf12.hostedemail.com: domain of 3za6aZwQKCNg9P7FAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--fvdl.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3za6aZwQKCNg9P7FAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738190542; a=rsa-sha256; cv=none; b=m6sRyxZ4aqo6RPZa9e1dl534hYRAhjZJerFKbsHSZmIh3Zv4FiJT1WvPZKrIppPEMKbzBg NM2f+DH0bHW6SVXGwXSjaNlquwvbavb+I+y4m0bzv7kA2RD5PYDIAbogJGr7NR1u2JSXT1 2XKSqCxlPghnayPrNrUvzVcP7VcczS8= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2163c2f32fdso4074515ad.2 for ; Wed, 29 Jan 2025 14:42:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738190541; x=1738795341; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dXf4/6vVFsOQWOL4yP6AMC2Up5+2J9mezQuBbeYawcA=; b=swBA/M54Fpp1GdOmf95GcDO1tprWPREZsey0qtHBSB4UcqRi59Nhr+3//bfdEzZGWQ FsOQMQrnGfVgnJtSjAX0bnefEpEC5cXJLAaGpG13Q6VK/IcC8CzadSadJb/kQ7bGkNTd H4Slt3Fntq/ApXUVhwUU2BatwX1cXzFXXrw6+8sM+63hdVtMNY2PLZdFn7QS8WDlivc+ sXEH8nDsQK/pULQcUSNj+W2XmEpKysVfsQb8O2+AztNVI7X0kLIydZ/mZkDYGyy825SE aNh+XQeUW5qFWAmtB5hy2KhXIrONIv9hFeWBody1d0hwsyjOUwuem5M89loMdtZ1PGpc e7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738190541; x=1738795341; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dXf4/6vVFsOQWOL4yP6AMC2Up5+2J9mezQuBbeYawcA=; b=tYE+7VmkgGu5tXlTJO3YptZhtLUHvjUh1wWAN2oBrszrZmO/g83vXtTfpMx5wYo//u Ud48xRl5iQM/4D8W1YdqC3k9f6YiDpSJUKtGhVkrnMEsz0ELtwCM3Q1Nl/nEPUSlQvc/ qmyPiGT8iFcsgIhJD7u7GaxDCab7OXiglEc2Kx5Wi3crjBW/Bbi28gNuaN3Q1X+qnvBi m6a3dvmbexHf7FdzRZ/Lt3cvQIXQ1Iq2/JBFL6Tlu7MSjli7JsPQgl5ptSrg/INCVnF9 qsfyxalGqrBHD0ffiF38ry+R5Uv4CLf1sAsNmRKfZtOlxHpbomrgDLOv0NZwGKUiE8Ls mkrg== X-Forwarded-Encrypted: i=1; AJvYcCUKnabHUcCoQxx78DLFitpGl6mvKZEHKoZnDvOGBnPnuON6d5ti9Ni4MpulaB9r6ziYrr/zPumXEw==@kvack.org X-Gm-Message-State: AOJu0Yx3yu0Xa4y7a94nKTG7tMXLXxBMaRXLEBJ0VdIBegDC8tl7FdG5 yiSxsLjn9AfxjUlmAnnuiG27urCaT6hx3geMy4Zp2wNeLzul684Gepv4MSC3PkCt0Saofg== X-Google-Smtp-Source: AGHT+IFtjyy0fiL5jPCk8tJl4v0XKuHY7KQNCKtXfPi9xeiKgYj5YSOrbzBr7gtJ/uGT4M5R65Qgn0uu X-Received: from pfwy16.prod.google.com ([2002:a05:6a00:1c90:b0:725:e46a:4fdd]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:458a:b0:1e4:8fdd:8c77 with SMTP id adf61e73a8af0-1ed7a479222mr8328798637.8.1738190541605; Wed, 29 Jan 2025 14:42:21 -0800 (PST) Date: Wed, 29 Jan 2025 22:41:32 +0000 In-Reply-To: <20250129224157.2046079-1-fvdl@google.com> Mime-Version: 1.0 References: <20250129224157.2046079-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129224157.2046079-4-fvdl@google.com> Subject: [PATCH v2 03/28] mm/cma: introduce cma_intersects function From: Frank van der Linden To: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yuzhao@google.com, usamaarif642@gmail.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , linux-s390@vger.kernel.org X-Rspamd-Queue-Id: C58E740006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: jzbar17gsybge9fky1rwgr1fu3rdjr1m X-HE-Tag: 1738190542-53581 X-HE-Meta: U2FsdGVkX1+d538m7uRxJSbPDUzmIFNDa7NqhBGRbaLSXTJi2nNt4JjGd5nyrCtHVLsJpF3et6tMbZ3eeymCanZ7y08o10HDOQzzDdYr2jDbr07MOcSqJ87tU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JSq6DJSmZhw1TtYemTYpFpMhDZZzdyrgC13qyZY0VvvGqFk6kRFoCmFemItngdcBa7G5AZZbXZvAldCMCxh9cZpLtHc+p3PGFg0PdzeMcNENZLgIxi+6ouZx7N7oNmFzQdevn6qmXR1nJhX7n990LsjDhy5csfgxk2e5L8viqAtAK7HETH6o1YKotgI/C648udzK3dVuOKJ037Yk0Cy5ucKg6ptBia3DlGcRvShYkDzZp/oH0Zaubj5RDNmYoPxfEvXYlouT/B9SZgS7dgpEgUl9jbVlxe33irkCQlrqSMlwQxgqnnnYEcQbI7fBK51ntHZEsSWhsqy5tJfKfFsMQG+MlRW1BbZny7lPOTnz6HB/BDL9qPU9TCOJ3dO0MW5p1DG6XrgE4hSDRtOQfbECOdIpY1jBGsVXVH4h7hehTfIQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.031173, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that CMA areas can have multiple physical ranges, code can't assume a CMA struct represents a base_pfn plus a size, as returned from cma_get_base. Most cases are ok though, since they all explicitly refer to CMA areas that were created using existing interfaces (cma_declare_contiguous_nid or cma_init_reserved_mem), which guarantees they have just one physical range. An exception is the s390 code, which walks all CMA ranges to see if they intersect with a range of memory that is about to be hotremoved. So, in the future, it might run in to multi-range areas. To keep this check working, define a cma_intersects function. This just checks if a physaddr range intersects any of the ranges. Use it in the s390 check. Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: linux-s390@vger.kernel.org Signed-off-by: Frank van der Linden --- arch/s390/mm/init.c | 13 +++++-------- include/linux/cma.h | 1 + mm/cma.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index f2298f7a3f21..d88cb1c13f7d 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -239,16 +239,13 @@ struct s390_cma_mem_data { static int s390_cma_check_range(struct cma *cma, void *data) { struct s390_cma_mem_data *mem_data; - unsigned long start, end; mem_data = data; - start = cma_get_base(cma); - end = start + cma_get_size(cma); - if (end < mem_data->start) - return 0; - if (start >= mem_data->end) - return 0; - return -EBUSY; + + if (cma_intersects(cma, mem_data->start, mem_data->end)) + return -EBUSY; + + return 0; } static int s390_cma_mem_notifier(struct notifier_block *nb, diff --git a/include/linux/cma.h b/include/linux/cma.h index 863427c27dc2..03d85c100dcc 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -53,6 +53,7 @@ extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count); extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); +extern bool cma_intersects(struct cma *cma, unsigned long start, unsigned long end); extern void cma_reserve_pages_on_error(struct cma *cma); diff --git a/mm/cma.c b/mm/cma.c index c20255161642..1704d5be6a07 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -988,3 +988,24 @@ int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data) return 0; } + +bool cma_intersects(struct cma *cma, unsigned long start, unsigned long end) +{ + int r; + struct cma_memrange *cmr; + unsigned long rstart, rend; + + for (r = 0; r < cma->nranges; r++) { + cmr = &cma->ranges[r]; + + rstart = PFN_PHYS(cmr->base_pfn); + rend = PFN_PHYS(cmr->base_pfn + cmr->count); + if (end < rstart) + continue; + if (start >= rend) + continue; + return true; + } + + return false; +}