From patchwork Mon Jan 27 23:21:43 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: 13951844 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 49A56C0218C for ; Mon, 27 Jan 2025 23:22:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 773202801C1; Mon, 27 Jan 2025 18:22:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FBF82801BC; Mon, 27 Jan 2025 18:22:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5746F2801C1; Mon, 27 Jan 2025 18:22:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2E8F32801BC for ; Mon, 27 Jan 2025 18:22:32 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CC5D61A06F6 for ; Mon, 27 Jan 2025 23:22:31 +0000 (UTC) X-FDA: 83054808102.23.8BC5D45 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 03373C0006 for ; Mon, 27 Jan 2025 23:22:29 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=w7RN6P6Y; spf=pass (imf22.hostedemail.com: domain of 3NBWYZwQKCAMiygojrrjoh.frpolqx0-ppnydfn.ruj@flex--fvdl.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3NBWYZwQKCAMiygojrrjoh.frpolqx0-ppnydfn.ruj@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=1738020150; 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=Tm2j+PHhIqi8zEYhmrbERS5xxoCaozlHGC7XJJeCFEnd/I5ejiVCZ/An3ON50AZWF4WPZy eiYMxpJiDUzb4Z4Tc2cuMrDl7CRXHoxGkVou3sNWeHuBIZ4tZXT0Bpi+hjmrmCjaHWy0Y1 J1zg4T/u6pqIeKecuvBXnN/GYQOBkdw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738020150; a=rsa-sha256; cv=none; b=vgFlrTi+mtRk27vCW3sEZZiG39FkUliwDHeMKMZ7JsNfkVeIBt4JnTkgqnx2HFvwMjTgsw zlVKqZdxrCP2738VvZ9LpOlo74ct5NpaA9NkAHyHsp4gscX5T/DqPjooZ1bEVo2FgqHA7R 2n6gJnv+qArl4x0tAfj1+FjzH07iAbU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=w7RN6P6Y; spf=pass (imf22.hostedemail.com: domain of 3NBWYZwQKCAMiygojrrjoh.frpolqx0-ppnydfn.ruj@flex--fvdl.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3NBWYZwQKCAMiygojrrjoh.frpolqx0-ppnydfn.ruj@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-216728b170cso96103785ad.2 for ; Mon, 27 Jan 2025 15:22:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738020149; x=1738624949; 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=w7RN6P6Y03QP6Izs8a6fNIidHveP2iukpXBrn3UUxALB7tusgbUz3BlKGA78n6Fn1B Ug/QvdJOwzcOx2DjgielCIWkj+vIm5gAnzlrxJl2KQFRjxhOn8F51JyuAmHUPvjjpElW Felf18SZni6MznVc3Mtr9t7kXApyuTf7Bv5wf+AT36ZQTIRXn8W7a1VaHvekwsUA0xGJ kigk9jKDqpiE1nYgkxZgFSxAi+wj/CWvCIDrLZNdbzyTFFdsMNhxDiKwAeKS9Vs3hnqO rKTLzmOQ3IEUjxTYnuvg7xz/viLdaK9bXj6aZUwW0FQ6npDWRW4ZEp/lzzSb6VWZ87U0 Lp6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020149; x=1738624949; 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=b1651qsSTJNC4crm7bL4u6BO9WZEPdkRS0HBvGdUZV7wDstn2OnAc4J3L9UDv1Kf6s 9XEHdmU0ShGktI0IuWP6qNLrSw08hgSbuGCarqFzxn3mQsZdWzC2XvgzcjI9eBHdE5mR QqcqXccrp/cOenbB8+PA2PM0yNrm8XDnvnNmveMYC2USHOjQerLrykS2F4J1aG1Wv/UG sG0aBaNrllrpKHjn9SxOaGptAMS86DIT/hRfocIURZf9p61qS/t24fxNu6PJTvFlZCha q5MluGoDWDJJhlOS8SZIeMf4Q90wLNzQ0rYnQUTeXPvmmCRY2X/srHqL+wjd2FDGzlVg ni9w== X-Forwarded-Encrypted: i=1; AJvYcCXrLWFcowreOtmxyFaSkQ5HJRctDCj3xCXVOzivFFTI6haiMv0MTVWGBmRCWlV995Bo/vCPXsGtXQ==@kvack.org X-Gm-Message-State: AOJu0YzWKGfvlIzmFD5Rf3RbsVnpyUchl+TzFQLkC+x9bM/DuH/KMBtb XHINoC1pceVpS3MwV60uaGzhy77toTBCcERToWyjCPb8GHF+wswS+kjtrxDSVE+mhy9KdQ== X-Google-Smtp-Source: AGHT+IHacT0c2glOz6iHxFPEkg2efzrTP0CNHsnhpI9lKFAWHWkywal7QfbYZsPNCZVylM+1koVThcNB X-Received: from pfbcg7.prod.google.com ([2002:a05:6a00:2907:b0:728:aad0:33a4]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:8411:b0:1e7:6f82:3217 with SMTP id adf61e73a8af0-1eb21465271mr67484709637.3.1738020148864; Mon, 27 Jan 2025 15:22:28 -0800 (PST) Date: Mon, 27 Jan 2025 23:21:43 +0000 In-Reply-To: <20250127232207.3888640-1-fvdl@google.com> Mime-Version: 1.0 References: <20250127232207.3888640-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127232207.3888640-4-fvdl@google.com> Subject: [PATCH 03/27] 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, usama.arif@bytedance.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-Stat-Signature: o6x4owgjneeg9ftnr6m98z8tzg3wyp51 X-Rspamd-Queue-Id: 03373C0006 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738020149-322394 X-HE-Meta: U2FsdGVkX19wbJe2IpsPl3Rqn/nAHNuUqCcSosjoCZtvEFNqsIz2Y4SSQ/S3+u3q0oEKRJXGEt94tPjn7gvxgI156oXapuRq0T+M7lXYnEsOVYlhOxhcSIaQjmSz1iFLyw/MSQUhCRm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IPAUFg+/G4kH5u8R4ALEUJbKUyTk8/XL0GMayVM8CMVMbfZP1RLzlhMY95Et3ua8gK596lnhYG0pfJTEz8E96VtHGD8TSGEqlQeAz9vxjKLK+lAm0uguYQ4hPyJXje5RuR1a1Uad96bKqdhyy6GMxJPPoG6La3n1+OSyJ6kSIPYubaub6vhnup3QKQFQBrVlsGMJpor9+gTJN+Z8eJwaAWpOtAuzzZlZYZiZb8cJqIbO5DMZ7LVU9YEGSNpGeMn/ccOK7oa0YZbI9ERtretzl/2Nh0NOk1DmDBxWLV+OSXpixa7ZRTjSm/XNoYPEiofT9od/qYqV4279wiCqQtHfOjHb+YyAIXrG/nKkqlV+LwbNazTa+/4Mup9Q8AESynxkQMto9IeemPc6JIHA6xg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000505, 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; +}